0
\$\begingroup\$

Thanks again for reading!

So following on from my last question, I have my fully working isosurface terrain and now its time to add my trees and grass and whatever to the world.

The old way I was doing it was to cast rays in a grid faceing down over the terrain, I would then read the normal from the ray hit and place things if the normal was < as value.

I would do this at different grid resolutions for each plant\tree\grass time and offset there x, z and scale by some random value then adding the object to my 2d BV tree because I was only working with height map terrain so I only had one row of bounding volumes for the tree.

I can still use the above method but as you know it will only place objects on parts of the terrain that can see the sky.

Part of building my new terrain system involved making a real octree so I no that I will use that to store my objects but what is the best way to generate my object positons.

From what I have read around I should somehow use the voxels I build but I'm not really sure how I would go about it.

\$\endgroup\$
1
\$\begingroup\$

You should have the vertex positions for the terrain and some information about how they make up the triangles (like indices), and you also know the normals for each triangle.

With this data you can select a random triangle from the mesh, check if the normal is mainly pointing up (you should use dot product for this) and if it does, then that triangle is facing upwards, thus you can place something on it.

Now, choose a random point inside the triangle to place the object at.

(Depending on how small your triangles are, you may skip the next part as it makes no visible effect with small polygons.)

To make your objects seem like they are really attached to the ground you could get each vertices' height, and by using weighted average you can get the y position of that position on the triangle.

Take the distance of the random point to each vertex (here, d1, d2 abd d3) and do (y1, y2 and y3 are the height of the 3 vertex.

sum := d1 + d2 + d3
height := (y1 * d1 + y2 * d2 + y3 * d3) / sum

(If you want, you can add a random value to it)

Abd with this, you have the x, y and z coordinate if the object.

| improve this answer | |
\$\endgroup\$
  • \$\begingroup\$ Thank you very much! I have ended up using my octree and when I get down to 64x64(size of a voxel) I just do a raycast using the center of the box with some y offset so its not inside the voxel physics mesh and if I get a hit I add a bounding box and then do what u talked about above with selecting random points but not on the triangle level. Right now poly count is to low to do the triangle thing but I'm looking into it \$\endgroup\$ – Justin William Stanley Bryant Sep 22 '16 at 0:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.