Just realized maybe this doesn't fit in this sub-forum but oh well
I'm making an exporter plugin for Maya and I want to export a non-triangulated mesh, while still outputting triangle data, not quad/n-gon data.
Using MItMeshPolygon, I am doing the following:
for (; !polyIter.isDone(); polyIter.next())
{
//Get points and normals from current polygon
MPointArray vts;
polyIter.getPoints(vts);
MVectorArray nmls;
polyIter.getNormals(nmls);
//Get number of triangles in current polygon
int numberOfTriangles;
polyIter.numTriangles(numberOfTriangles);
//Loop through all triangles
for (int i = 0; i < numberOfTriangles; i++)
{
//Get points and vertexList for this triangle.
//vertexList is used to index into the polygon verts and normals.
MPointArray points = {};
MIntArray vertexList = {};
polyIter.getTriangle(i, points, vertexList, MSpace::kObject);
//For each vertex in this triangle
for (int v = 0; v < 3; v++)
{
//Get point and normal
UINT vi = polyIter.vertexIndex(vertexList[v]);
UINT ni = polyIter.normalIndex(vertexList[v]);
MPoint _v = vts[vi];
MFloatVector _n = nmls[ni];
//Create vertex
Vertex_pos3nor3uv2 vert = {};
vert.posX = _v.x;
vert.posY = _v.y;
vert.posZ = _v.z * -1.0;
vert.norX = _n.x;
vert.norY = _n.y;
vert.norZ = _n.z * -1.0;
vert.u = 0.0;
very.v = 0.0;
verts.push_back(vert);
}
}
}
Doing this only gives me half the triangles I'm supposed to get and the result is very distorted.
Link above is a picture of a cube exported this way.
Edit: I've also tried indexing into the entire mesh vertex array like this:
MPointArray vts;
meshFn.getPoints(vts);
MFloatVectorArray nmls;
meshFn.getNormals(nmls);
//....
UINT vi = polyIter.vertexIndex(vertexList[v]);
UINT ni = polyIter.normalIndex(vertexList[v]);
MPoint _v = vts[vi];
MFloatVector _n = nmls[vi];
I can't figure out what's wrong with my code.
Any ideas?