How do I instantiate a 3D game object around line renderer(for an L system)

146 Views Asked by At

I'm working on a 3D tree generation using l systems. I got my L system to generate trees using line renderers. But I don't know how to generate it as a 3D mesh. I tried taking the transform.position of each line and instantiating a mesh in their place, but that doesn't seem to be working. I've been told that this is because a line renderer doesn't have a trasform.position in the same way as a game object.

How should I go about doing this?

1

There are 1 best solutions below

0
On

Yes, the line renderer component doesn't have a transform to get a position from, but you can access its vertices' positions using GetPosition() GetPosition documentation. You would need to pass in the index of the specific vertex you want to find, depending on where on the line you're looking to put your vertex.

I am unfamiliar with L-systems, but I imagine that in order to draw your lines you're already feeding each line renderer positional data? In that case, you would just use that information to calculate your mesh vertices instead. Not sure about the triangle winding, however.