Sign in to follow this  

Calculate number of sides

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i want to calculate the number of sides in the meshes I load, is there any way i could do it, i know the number of verts in a mesh but i can't figure out how to get the sides. And I want to do it manually, meaning without using one of D3D functions. Thnx

Share this post


Link to post
Share on other sites
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
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
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
ok this is what I do, I load a mesh with LoadMeshFromX D3D Function, which loads my mesh and gets the number of verts in it, i can later call GetIndexBuffer from the mesh (or GetVertexBuffer) to get those buffers, but how do I figure out if its a triangle strip/fan/ or else?

Share this post


Link to post
Share on other sites
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

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
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
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

This topic is 4021 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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