# Triangulating a 3D "polygon"

## Recommended Posts

Hi everyone, I'm new to DirectX development and 3D graphics programming in general, so hopefully this is just a very simple question for most of you. Basically, I need to render a filled 3D polygonal shape that's specified as follows: Start vertex: (x, y, z) coordinates Vector list: A list of (deltaX, deltaY, deltaZ) offsets from each vertex to the next vertex in the shape. The final vector will always end up back at the start vertex. Example: The following corresponds to a 3D "L" shape consisting of two orthogonal rectangles: Start vertex: { 5, 1, -2 } Vector list: { { 0, 10, 0 }, { 0, 0, -10 }, { 0, -10, 0 }, { 10, 0, 0 }, { 0, 0, -10 }, { -10, 0, 0 } } Obviously, the above is an extremely simple case. I need to be able to handle much more complex and general cases, including non-convex shapes (although I've some flexibility in how I choose to interpret degenerate or self-intersecting cases). Unfortunately, I cannot change or augment the input format, as this is all I'm getting from an external component. My question: what would be some good ways to triangulate such a shape so that I can render it using a single DrawPrimitives call? I've spent a lot of time googling this topic. While I've been able to implement a decent solution for drawing these shapes in 2D (i.e. input cases where the z values are always zero), I currently can't figure out how to handle the more general 3D case. *Any* help or pointers to relevant resources will be extremely appreciated! Thanks a lot in advance!

##### Share on other sites
Let's not forget that triangles are not the only shapes DrawPrimitive call understands. Why not just draw the lines as a line list? Is it really that necessary to triangulate?

##### Share on other sites
Here's the thing.. The app needs to know all the details about the body, in which order are the vertices set. Not that no one knows how to solve this, far from that, no one wants to deal with it.. Either you:
A) Draw Primitives without index
B) Specify indices yourself
C) Use a modeling tool, export to a file type that you can later just import/translate inside app. (which is the most common method)

##### Share on other sites
Quote:
 Original post by tokaplanLet's not forget that triangles are not the only shapes DrawPrimitive call understands. Why not just draw the lines as a line list? Is it really that necessary to triangulate?

Thanks for your reply! I apologize for not being clear enough in my original post; I have no problems drawing the input as a polyline, but what I'm stuck on is figuring out how to draw a filled polygonal shape within the bounds defined by that outline. Any ideas?

##### Share on other sites
Quote:
 Original post by experimentHere's the thing.. The app needs to know all the details about the body, in which order are the vertices set. Not that no one knows how to solve this, far from that, no one wants to deal with it.. Either you:A) Draw Primitives without indexB) Specify indices yourselfC) Use a modeling tool, export to a file type that you can later just import/translate inside app. (which is the most common method)

Thanks very much for your guidance! Unfortunately, approach C isn't a viable option for me, because I'm receiving my input dynamically and continously from an external component, and I need to render this input in real time.

Are you able to point me to some resources that can help me compute the order of the vertices, given the input format that I'm forced to work with? Even a relatively inefficient algorithm would be useful--while I do ultimately need good performance, right now I'm at a stage where it's more important just to get the required functionality up somehow, by hook or by crook!

Right now, I'm a complete novice when it comes to computer graphics, so once again I apologize if my questions are really basic. But I do have a Computer Science degree from my good old college days, so hopefully I'll be able to handle the learning curve and get up to speed with a little bit of help and advice from the good folks here! :)

Thanks again for all the help so far!

##### Share on other sites
I dont believe this is a trivial problem in 3D in general, because u can, for example, have a spiral shape and how do u triangulate that? you can look into 'delaunay triangulation' and see if it fits u.

##### Share on other sites
As the list of vertices ends up at the start again i would (initially at least) simply render a triangle fan.

This would assume A lOT about the shape being rendered. As mentioned before if this shape can be anything then you do have a problem.

You could draw a 'ribbon' by rendering a triangle from each vertex and the the two before it in the list. But again its all about the data. Are there ANY restrictions - likely outputs to expect - as the more i think about it the less i realise you can render a random shape - you need a analysis stage.

Where is this data coming from?

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
628348
• Total Posts
2982208

• 10
• 9
• 24
• 11
• 9