Easy question about SPODMesh and sFaces

How can I obtain the faces that make up a mesh?


I know I have to use sFaces. This is a list on indexes to sVertex ?..


Is there an example on how I can get these faces?


Are the face normals calculated and stored by any chance?





I need this for collision detection.





Thank you.

Hi,

 

fwalker wrote:

How can I obtain the faces that make up a mesh?
I know I have to use sFaces. This is a list on indexes to sVertex ?...
Is there an example on how I can get these faces?


 

Assuming your data is indexed then as you say you need to use sFaces which is a list of indices into pInterleaved or sVertex etc.

 

The only example I can find in the SDK is the PVRTModelPODDeIndex function in the tools code which takes an interleaved indexed mesh and removes the indices. The important part to look at is

Code:
(char*)mesh.pInterleaved + ((unsigned short*)mesh.sFaces.pData)[ i] * mesh.sVertex.nStride

which calculates the start of vertex i in pInterleaved. To get a particular element of the vertex e.g. normal just add onto this the sVertex, sNormal etc. offset (pData).

 

fwalker wrote:

Are the face normals calculated and stored by any chance?

 

I'm afraid the POD format stores normals per-vertex not per-face so these will need to be calculated.

 

Thanks,

 

Scott

Scott,





Thank you very much for your help. I am still trying to figure this out. Please forgive my rookie question I am obviously missing something here. Please enlighten me. How is it that the following line from OGLESIntroducingPOD in the “void OGLESIntroducingPOD::DrawMesh(unsigned int ui32MeshID)” function works?





// Setup pointers


glVertexPointer(Mesh.sVertex.n, VERTTYPEENUM, Mesh.sVertex.nStride, Mesh.sVertex.pData);





According to my debugger Mesh.sVertex.pData is nil !!!





How is this possible? I am confused. Please help.

fwalker wrote:

According to my debugger Mesh.sVertex.pData is nil !!!!

How is this possible? I am confused. Please help.


 

When the mesh data is interleaved Mesh.sVertex.pData becomes an offset to the start of the first vertex position in Mesh.pInterleaved. For IntroducingPOD the position is the first part of the vertex so pData is 0 (i.e. no offset). The normals are the second part so have an offset of 12 (3 x sizeof(float) i.e. the size of the position). The UVs are the third part so their offset is 24 (6 x sizeof(float) i.e. the size of the position and normal).

Thanks so much Scott, that all makes sense. Right after I got it working, by coincidence, I found that you guys have a file in your SDK that does BoundingBox calculations. You do not use it in your demos that I can tell. But its exactly what i needed.





PVRTTrans.cpp


PVRTBoundingBoxComputeInterleaved





So I verified my code and things look good.





I am mentioning this in case this helps someone else.





Thanks so much ! fwalker2010-03-02 20:02:15