I am interested in taking the translate, rotate, and scale numbers, copying them, and applying them to prefab components once in Unity. I was wondering if there was an easy way to do this for a few thousand objects.
The particular application is a treegen script from Maya, which places leaves quite well. I have around 1500 leaves, all identical, sharing the same texture, and could be made prefabs–if I could copy the data quickly.
I’m thinking of bringing in one prefab, then instantiating based on a spreadsheet table, which, hopefully i can figure out how to export to from maya (any help appreciated).
Ideas? :?
EDIT: I guess it makes more sense to bring them into unity, then write a script to strip the data from there, and instantiate based on the previous objects. I am no scripting genius, If anyone can think of anything that’s great, otherwise Ill give it a shot.
I was intending to apply a mesh combiner script (combine at runtime).
Does that nullify the effects of the prefabs (i.e. memory savings)?
Or would even a mesh combiner script deteriorate performance to an unwanted degree?
Obviously, otherwise I would just merge them in Maya, which is what I had done previously–but I’m looking to reduce project file size as much as possible–while keeping reasonable performance.
I might be misunderstanding the meshcombiner function, it kinda feels like I’m trying to get something for nothing.
The problem with performance here is 1500 draw calls. If you combine a bunch of meshes as the scene loads that means a lot longer load time. Seems like one tree mesh is not going to hurt the file size that much.
General rule then, at what point does it make sense to start using prefabs? Only above the 1500-4000 poly ‘sweet spot?’
We are working on web downloaded material–and need to seriously optimize downloads with a secondary focus on speed.
I guess if the average (broadband) download speed is around 100kb/s–that has to balance with load time
so if a mesh combine script takes 10 seconds to run, but only saves 50kb, it’s not worth it, but one can envision a scenario where the script runs in 5 seconds, but saves a few Mb
The leaves were an extreme case
–this is where I am coming from.
There two things to optimize for. File size and Performance.
When optimizing for Performance what matters is that when Unity renders the object you have as few objects as possible with a good amount of polys eg. 1500-4000 polygons.
For file size, having lots of objects which are instantiated is best since it will share the meshes, thus there is one mesh and only the additional game objects transforms need to be stored but not the actual vertex data.
Combining objects at load time gives you the best of both at the cost of increased load time. So in a web player this is the best solution.
Now what would be most efficient would be to generate the positions/rotations/scale for the 1500 objects from a script procedurally. This way you don’t need to store any data per instance.
There are some script examples in the documentation that show how to do exactly this. At the bottom of the page there are two examples. One placing a bunch of objects in a ring and one placing them in a grid.
Start with those and once you got it to generate the right pattern of instantiated objects, start plugging in the mesh combiner in order to optimize for speed.
Thanks, we talked about this in SF, but after thinking about it, I wasn’t totally clear on where the performance/speed trade off hit in terms of running a mesh combine script.
Once load time came into play, it made a lot more sense. Thanks for clearing that up. I’m looking into dynamically generating leaf position based on branching–but I’ve put it off, mostly because the branches I generate in Maya are far too complex for games, and i usually delete them after the leaves are completed.
So my script will be something like
-figure out where branches would go-if they existed
-place leaves according to invisible branches
Just FYI, try taking a look at the (currently) latest post in the “Procedural Trees” thread under “ShowCase”. I just updated my trees with leaves and support for texturing.
It still has a way to go, before it looks realistic, but maybe you can use the script for inspiration.
And when I crank up the recursion on the trees, it demonstrates the increased load time quite nicely
Not combining meshes; I’m not sure how to use that script with instantiated prefabs.
As Higgy said, I’d love to see all the L-System variables in this script, not that I have a clue about the math…
It’s an interesting exercise to setup and tweak something like this, to get a sense of the tradeoff between polygon count for individual objects and overall object count.
I was going to explain to you how to use prefabs, but then I just went ahead, and did it.
The new script can now take a prefab as argument, and will generate that instead of leaves.
In the example below, I simply took the default box from the standard assets, and made a prefab where it was scaled down a bit. It looks like that because the leaves on each branch are actually placed at the same point, just rotated differently.
No, the code is not very efficient right now. But maybe an enterprising soul can figure out how to run the meshcombiner on this.