Easy question about SPODMesh and sFaces

This topic contains 4 replies, has 2 voices, and was last updated by  fwalker 7 years, 7 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #30062

    fwalker
    Member

    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.

    #33732

    Scott
    Moderator
    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
    #33733

    fwalker
    Member

    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.

    #33734

    Scott
    Moderator
    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).
    #33735

    fwalker
    Member

    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

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.