Sign in to follow this  
Arte2

Pipe mesh generation from Lines

Recommended Posts

Hi, I have generatad a crystal using lines. Now this looks boring and i would like to replace those lines with pipes or bars. So i would need a function that would look like: void GeneratePipeVerticesFromLine(Vector linestart,Vector lineend,float verts[somenumber][3]) { ... } Now i have tried to do it by trans nad Normilize the line and then create a pipe. But i have failed. The glut Mesh generation stuff wont help me becuase they dont return and vertices, they just paint them. Any tips or suggestions??

Share this post


Link to post
Share on other sites
If you just want a straight pipe (i.e. a cylinder), it's pretty easy. I don't have time to hammer out the psuedocode right now, but the general idea is:

1. Create an orthonormal basis with the line as the z axis.

2. Iterate from 0 to 2pi by some step.

3. At each step find a point as a combination of the line start point, the local basis x axis * sin(angle) * radius, and the local basis y axis * cos(angle) * radius. This gives you the points for the 'circle' at one end of the cylinder.

4. Add the line direction vector to each of those points to get the points for the circle at the other end of the cylinder.

5. Triangulate.

If that's not clear or you have questions, just ask.

Share this post


Link to post
Share on other sites
Quote:
Original post by jyk

1. Create an orthonormal basis with the line as the z axis.


If that's not clear or you have questions, just ask.


I dont get how to do this. There is no problem for me to create a pipe (cylinder) around any of the axis. But my problem is how i should rotate and transform so it can replace my line.

Share this post


Link to post
Share on other sites
You want two vectors ('up' and 'right') which are orthogonal to your initial line ('forwards').

The easiest way to do it is to cross the forwards vector with some other vector guaranteed not to be parallel to the forward vector to get the right vector, and then cross the right vector with the forwards vector to get the up vector. (Normalise them all at the end, of course).

'Up' and 'Right' then become 'local x axis' and 'local y axis' in step 3 of jyk's solution.

It may be worth keeping in mind that you could draw the open cylinder as a triangle strip. You'll be generating points at angle=0 twice (both at the beginning and at the end), unless you use an index buffer.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this