Sign in to follow this  

Max SDK (Export all faces to .txt file)

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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[i].v[0]; pathfile<<&TObj->mesh.faces[i].v[1]; pathfile<<&TObj->mesh.faces[i].v[2]; } pathfile.close();

Share this post


Link to post
Share on other sites
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[i].v[0]].X;
pathfile<<&TObj->mesh.vertexes[mesh.faces[i].v[0]].Y;
pathfile<<&TObj->mesh.vertexes[mesh.faces[i].v[0]].Z;

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

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

}
pathfile.close();

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

Webby

Share this post


Link to post
Share on other sites

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[i];
::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[i].v[0],
mesh->faces[i].v[1],
mesh->faces[i].v[2],
mesh->faces[i].getEdgeVis(0) ? 1 : 0,
mesh->faces[i].getEdgeVis(1) ? 1 : 0,
mesh->faces[i].getEdgeVis(2) ? 1 : 0,
mesh->faces[i].getSmGroup(),
mesh->faces[i].getMatID());
}


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

Share this post


Link to post
Share on other sites

This topic is 3864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this