Imagination PowerVR SDK Blog

extracting vertex data from a pod-scene


#1

Hello,

While attempting to retrieve the 3 vertices for each polygon in a scene I always get a SIGSEGV on the indicated line. How does one correctly retrievev such information ?

Code:

VERTTYPE vtPlane[4];            // 4 coefs in a*x +b*y +c*z + d = 0
    VERTTYPE vtFace[3][3];            // 3 points each having 3 coords
    unsigned short usI[3];            // indices in the vertices array for one point
    bool bExistentPlane = false;
    short i = 0;

    __bInterleaved = scene.pMesh[0].pInterleaved != NULL;

    for (unsigned int nm = 0; nm < scene.nNumMesh; nm++)            // each mesh in the scene
    {
        SPODMesh& currentMesh = scene.pMesh[nm];

        if (currentMesh.ePrimitiveType == ePODLines)
            continue;                                        // we do not fear intersection with .. lines

        for (unsigned int nf = 0; nf < currentMesh.nNumFaces; nf++)        // each poly in the mesh
        {
            CPODData& currentFaces = currentMesh.sFaces;

            // assuming nStride = 2 and the type is indeed unsigned short;
            if (currentFaces.eType != EPODDataUnsignedShort)
                return false;

            // same for the vertex array - assume floats
            if (currentMesh.sVertex.eType != EPODDataFloat)
                return false;

            for (char nv = 0; nv < 3; nv++)        // for all 3 vertices of this face
            {
                usI[0] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 0];
                usI[1] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 1];
                usI[2] = ((unsigned short*) currentFaces.pData)[nf + nv*3 + 2];

                // line below fails with SIGSEGV as the usI[] contains trash
                vtFace[nv][0] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[0]] : ((float*) currentMesh.sVertex.pData)[usI[0]];     
                // I have noticed it fails for the same nv = 2 (3rd vertex), nf = 0 (first face) but nm can be anything (?). Noticed this behaviour for the 10th, 9th and 7th meshes (nm = mesh number). Never worked for all meshes without error.
                vtFace[nv][1] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[1]] : ((float*) currentMesh.sVertex.pData)[usI[1]];
                vtFace[nv][2] = __bInterleaved ? ((float*) currentMesh.pInterleaved)[usI[2]] : ((float*) currentMesh.sVertex.pData)[usI[2]];

            }

...
...


Thank you


#2

I have been staring at PVRTModelPOD.cpp for hints but no luck … :frowning:


#3

aleluia

https://www.imgtec.com/forum/forum_posts.asp?TID=653&KW=interleaved



#4

You might also want to take a look at the PVRTVertexRead functions (used by a couple of functions in PVRTModelPOD.cpp as well) stored in PVRTVertex.cpp. I used it for reading vertex info here.


#5

I managed that part,

Cheers