Sign in to follow this  
VanillaSnake21

Calculate number of sides

Recommended Posts

jollyjeffers    1570
Quote:
I want to do it manually, meaning without using one of D3D functions.
Well if you don't want to use the D3D API I'll push this over to the GP&T forum - the 'DirectX' forum is more for specifics of the API and technology than, as you request, general graphics algorithms [wink]


I'd personally step through each face and do a dot-product between neighbours using a threshold function to determine which were different "sides". You need to define "different sides" really.

Two triangles that are coplanar will have equal normals, that is, their dot product will be 1.0 - as the dot-product decreases (from 1.0 through to -1.0) you're getting triangles with increasingly different angles between their surfaces.

A similar technique can be used to determine the sillhouette edges for shadow-volume extrusion - there will be plenty of material on this subject so go make friends with your favourite search engine [wink]

hth
Jack

Share this post


Link to post
Share on other sites
AndyTX    806
For triangle lists, and assuming no degenerate triangles:
# faces (triangles) = # indices / 3

This is a pretty simple formula since each triangle has exactly three indices. Similar formulae exist for triangle strips and fans.

Share this post


Link to post
Share on other sites
xycsoscyx    1149
There is no way to know, if you only know the number of vertices. You at least need to know what type of primitives it contains (triangle list, strip, fan, soup, etc). If it's just a list of triangles, then it's (Size / 3), if it's a strip, it's (Size - 2), and if it's a fan, it's (Size - 2) as well. If it's a soup, well then there has to be some other method of determining faces, like a list of indices. If you are using an index array with a soup of vertex, then you can use the same formulas as above, just using the size of the index array instead.

Share this post


Link to post
Share on other sites
xycsoscyx    1149
Sadly, I've never worked much with the D3DXMesh class, can you tell us what exactly you're trying to do? If you just want the number of faces, you can call pkMesh->GetNumFaces(). Are you trying to rip the data out into your own class, though, so you can render things manually (basically just using the LoadMesh function as a decoder for the X files)?

Share this post


Link to post
Share on other sites
jbarcz1    265

If the mesh is a closed manifold, then there's a fixed mathematical relationship that gives the number of faces in terms of the number of vertices. I can't remember what it is off the top of my head.

JB

Share this post


Link to post
Share on other sites
Zipster    2359
Are you referring to Euler's formula, which gives the relationship between the number of of faces, vertices, and edges: F+V-E=2? You'd need some way to determine the number of edges, which you might be able to induce from the types of primitives.

Share this post


Link to post
Share on other sites
VanillaSnake21    175
Thanks xycsoscyx, I should have figured out that if there is a GetNumVertices() function there must also be a GetNumFaces(), anyways that solves my problems, thanks for the replies, and btw i just needed the NumFaces so I get the damned vertex normals set up for my lighting, ThanKs for all replies

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