How can i take a tree model and procedurally place it INTO the terrain
by this my question is
how do i take a tree GO and add it to the terrain data
so that its rendered as part of the terrain rendering system
I cant figure out how to use addTreeInstance()
I posted this question in the ask area and so far no one knows
id really would not to want to have to reverse engineer the terrain optimization algorithms if possible
I’d love to just hack in my own trees procedurally and just use the terrains rendering algorithms
That other thread you linked has the answer… It is indeed Terrain.AddTreeInstance that will get your trees into the terrain system.
Setup your tree in the terrain system the same way you would were to to paint trees on the terrain. (Basically drag drop tree model to Terrain Tool tree section).
Once your tree model works OK with the terrain you can then fill out a TreeInstance structure and call Terrain.AddTreeInstance to create new trees (copies of one of the base terrain prototype trees that you setup earlier)
@BPP no it flipping doesnt, AddTree instance does not work as easily as you seem to think
@Gabo yeah I found that too after a lot more searching
I did get it to place a black version of the tree
however for some reason it only places trees along an edge
I tried (.5,0,.5)
which i would have thought would have placed it in the center of the map
but it just placed it center of an edge ’
the tree instance position is a vector3 position in world data (from what i interpret) so if your terrain base is at 0, 0. Seting the position to .5, .5 would be pretty much at the center of the scene. i haven’t done it yet. But im working in terrain generation from script so if you found something out about it i’d be glad if you can share.
my theory is that it isnt world position because if it were it wouldnt use decimals
no I suspect its done this way in case terrain is scaled
so .5 would always be 1/2
0 would always be bottom and 1 would be always top
yet still I have no idea why it will only spawn along an edge
the x value works
but it seems whatever i put in for z doesnt do anything
I suspect that the y value is more of a vertical offset from the terrain normal, and so should always be 0
making a system to find where to put the tree is the easy part
even converting the world vector to this decimal ratio seems easy in comparison
getting the damned thing there is a pain in the ass
because whatever i try to do this silly ass thing doesnt follow logic
You are right. position goes from 0 to 1. Also aparently you shouldn’t left any atribute of the tree instance unasigned. like color, lightmap, etc. At least that’s all i could google. When i get home i’ll try placing some trees and see what happen since i need this too.
oh yeah thats how i got it to place the black trees, you have to declare all the values
oh i should warn you this gets a little crash prone so save
and tree additions made to the data during runtime remained saved in the terraindata after runtime
so you have to manually delete the trees with the brush every now and then.
You wouldn’t have to manually delete trees if you’d backup the tree instances array and restore it on application exit when you’re testing in the editor.