Showing results for 
Search instead for 
Did you mean: 

3D Object - Draw Cylinder from array data

Go to solution

Alright! So I got it to work after doing some more fancy footwork with how the points are stored in the array. Now "Triangle Strip" produces a wonderful surface.


Only question now is, how do I get it to show shading? I added a light source to the model, but it doesn't seem to make a difference.

0 Kudos
Message 11 of 27

I haven't played with lighting much, I think that there is an example in the example finder that has some good examples of light sources. 

0 Kudos
Message 12 of 27
Accepted by topic author RyanLC

For the shading to work, you have to provide an array of normal for your surfaces. Notice that you will get consistent results only if each normal is normalized.


Have a look at this post. It might give you an idea on how to proceed.

Marc Dubois
0 Kudos
Message 13 of 27

Is there a good way of creating normals? I cant say I am very familiar with this. Is there an example of how to make normals? How do you normalize normals?

0 Kudos
Message 14 of 27

Sorry, I edited my post to add the information probably after you read it. You can find an example here.

Marc Dubois
Message 15 of 27

From what I understand, normals are the vector perpendicular with each of the surfaces you are drawing and are probably used when labview has to decide what to do with the light. I have never attempted it in labview. I came close when I was writing this code for the first time. It should be similar to how other programs do it and you might be able to find a good explanation online somewhere. I ended up just drawing a point cloud as it was good enough for what we are doing.

0 Kudos
Message 16 of 27

@MarcDub wrote:

Sorry, I edited my post to add the information probably after you read it. You can find an example here.

That is a huge help! Thank you.

Is there a change I need to make to the normals if the drawing mode is set to triangle strips? Triangles gives me a terrible render.


EDIT: Maybe my current methodology would be helpful.

Because I have an even number of points in each "slice" I interleaved the data to allow points to create triangles.


In the picture example, each "slice" has eight points. I append the first point of each array onto the end of the array so that the circle actually wraps back onto itself. My algorithm currently interleaves slice A with slice B, then interleaves slice B with Slice C and appends the two interleaved arrays onto each other. So your array ends up being A1,B1,A2,B2,...A8,B8,A1,B1,B1,C1,B2,C2...B8,C8,B1,C1. I do this for (number of slices - 1) to get a full meshed model. Correct me if I am wrong, but to make the "triangles" draw style work the array would need to look more like A1,B1A2,A2,B1,B2,A2,B2,A3....etc. correct? Where each triangle has three points to themselves.

0 Kudos
Message 17 of 27

You are correct. You can use triangles instead of strips by using 3 indices for each triangle.


Looking at your rendering using strips, I think that you have an issue of "flipping" normals. Depending on how you select you points to calculate each normal, the normal can be either up or down (or outward or inward). You need to find a way to make the normal consistently in the same direction (outward would probably provide the best appearance).


If you provide your code, I could try to have a look.

Marc Dubois
0 Kudos
Message 18 of 27

Here is the code I am currently using.

I modified Jake's code to use point clouds rather than an STL file. The case structure to the left of the VI allows you to choose between an STL file, passing a point cloud array, or using the generated data. I went ahead and made constants of the test data I am using in both forms, triangle strips and triangles. I can also post the code that makes those point cloud arrays if needed, but it should be following the algorithm I mentioned above.

Message 19 of 27

Awesome, it looks like you have made good progress. What did you learn when you did your "fancy footwork" to make you triangles work? I'd be curious to see if I can get to the point where I can turn any model into something that has correct normals that I can display.

0 Kudos
Message 20 of 27