Calculate number of sides

Started by
9 comments, last by VanillaSnake21 17 years, 4 months ago
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

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

Advertisement
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

<hr align="left" width="25%" />
Jack Hoxley <small>[</small><small> Forum FAQ | Revised FAQ | MVP Profile | Developer Journal ]</small>

when i said sides i actually meant faces, how do you find how many faces a mesh has if you know how meny verts it has.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

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

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

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

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
Joshua Barczak3D Application Research GroupAMD
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.

Yes, euler's formula is what I was thinking of.

JB
Joshua Barczak3D Application Research GroupAMD

This topic is closed to new replies.

Advertisement