reading vertex data from a model

Hey guys,

I am trying to load vertex data from an imported egg file. I have something like below:

    for i in range(0, primitive.getNumFaces()):
        v1 = primitive.getVertex(j+0)
        v2 = primitive.getVertex(j+1)
        v3 = primitive.getVertex(j+2)
        tri = makeTriangle(v1,v2,v3)

In some cases tho, there are more triangles than there are vertices. Am i not reading this correctly?


If the particular type of primitive object you are walking through happens to be a GeomTriangles, then this code is correct. But if you have some other kind of object, such as a GeomTristrips, you will need to use a more complicated logic path to extract out the individual triangles.

One easy thing to do is start out with primitive = primitive.decompose(), which will decompose a GeomTristrips into its individual triangles for you, and return the corresponding GeomTriangles object. If the object is already a GeomTriangles, it will leave it alone.

Of course, you might still run into trouble if your object happens to be, say, a GeomPoints or GeomLines object. But as long as you know you are only loading polygon data from your egg files, you should be OK.


Here might be an example:

An octahedron is an eight sided polyhedron that uses six vertices. When unmapped into two dimensions, there will look like some ‘extra’ vertices are actually references to the same vertex. It would appear as though there are too many triangles for the number of vertices in the 3 dimensional model. But the nember of vertices is actually correct for the number of triangles