Appending Shapes to a TriangleBuffer?

xtitus

15-08-2014 13:32:05

I have program generating 3D trees. I'm using the OgreProcedural to draw my 3D representation of the tree. Trunk and branches are drawing fine. I extrude a circular shape per branch and append the trianglebuffer to a manual object. So, in the end, I have a manualobject with all branches represented as a single submesh.

So, now for the leaves. I want to represent the leaves as a quad to start, but would like to use different shapes (including custom) later. To start simply, if I do:

Procedural::Shape s = Procedural::RectangleShape().setHeight(0.5f).setWidth(0.5f).realizeShape();

how do I get a trianglebuffer from this and set position? I basically want to realize the rectangle and set UV texture coordinates on BOTH sides. Is there a way to do this? I'm hoping I can find a way to do this, and then have a loop with varied position and rotation to add replicates of the leaves around the tree. In the end, I think if all the leaves could be added in my manualobject as a one new submesh (as leaves will have a different material) it's work out well.

Any help or hints would be great. :) I can do this manually drawing, but it would be nice to continue to use ogreprocedural as I'm using it for the rest of the generation. Thanks!

mikachu

17-08-2014 21:03:01

Hi,

You can use the triangulator, once for each side. (http://docs.ogreprocedural.org/classProcedural_1_1Triangulator.html)

If you always use the same shape for each leaf, maybe caching the result of triangulator to a temporary trianglebuffer, then copying this trianglebuffer to the destination would probably give better performance.

xtitus

18-08-2014 13:16:05

Perfect. Thanks mikachu! :D