Max SDK (Export all faces to .txt file)

Started by
1 comment, last by zny_sssa2000 16 years, 11 months ago
Hello. I have some problem: I can`t to get position(x,y,z) of faces:confused: How to get it? I do: ofstream pathfile; pathfile.open("C:\\123.txt"); for (i = 0; i < TObj->mesh.numFaces; i++) { pathfile<<&TObj->mesh.faces.v[0]; pathfile<<&TObj->mesh.faces.v[1]; pathfile<<&TObj->mesh.faces.v[2]; } pathfile.close();
Advertisement
I don't know the SDK at all but I am learning Maxscript and I'm pretty sure the interface will be similar.

A face won't have an XYZ value. A face has 3 indices (integers). These integers are the indexes into the vertex array.
These might be represented as XYZ on the face object (not sure but seems more likely that it would be something like face._0, face._1 and face._2 or similar (unless the SDK represents a face as a single Vector3 type object).

Anyway, what you are outputting there are the vertex indexes. If you want the XYZ positions for each vertex of each face then do something like this.

ofstream pathfile;
pathfile.open("C:\\123.txt");
for (i = 0; i < TObj->mesh.numFaces; i++)
{
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[0]].X;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[0]].Y;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[0]].Z;

pathfile<<&TObj->mesh.vertexes[mesh.faces.v[1]].X;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[1]].Y;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[1]].Z;

pathfile<<&TObj->mesh.vertexes[mesh.faces.v[2]].X;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[2]].Y;
pathfile<<&TObj->mesh.vertexes[mesh.faces.v[2]].Z;

}
pathfile.close();

Actual syntax may be different but that's the general idea. Hope this helps.

Webby

face do not have any pos information
All the pos infomation are in the vertex data,
the face in Max only have the index infomation about the vertex and the visible infomation about the edge,so if you wanted export these infomation just like this:

TriObject * tri = NULL;
tri = (TriObject *) obj->ConvertToType(0, Class_ID(TRIOBJ_CLASS_ID, 0));
Mesh * mesh = &(tri->GetMesh());
assert(mesh);
mesh->buildNormals();
::fprintf(m_fileStream, "BEGIN MESH NumVerts:<%d> NumFaces:<%d>\n",mesh->getNumVerts(),mesh->getNumFaces());

// Export the vertices
for (i = 0; i < mesh->getNumVerts(); i++)
{
vert = tm * mesh->verts;
::fprintf(m_fileStream, " vertex %d:<%f,%f,%f>\n", i, vert.x, vert.y, vert.z);
}

// export faces
for (i = 0; i < mesh->getNumFaces(); i++)
{
::fprintf(m_fileStream, " face %d -- verts:<%d,%d,%d> edgevis:<%d,%d,%d> smoothgrp:<0x%x> matid:<%d>\n", i,
mesh->faces.v[0],
mesh->faces.v[1],
mesh->faces.v[2],
mesh->faces.getEdgeVis(0) ? 1 : 0,
mesh->faces.getEdgeVis(1) ? 1 : 0,
mesh->faces.getEdgeVis(2) ? 1 : 0,
mesh->faces.getSmGroup(),
mesh->faces.getMatID());
}


this is not all the code for export vertex and face,
i hope this can help you.

This topic is closed to new replies.

Advertisement