void maxPluginTest::Export(INode* pNode, int iTreeDepth /* = 0 */)
{
// First step to export: What are we exporting?
// Here we are going to export the basic scene tree,
// identifying each node by name.
MCHAR* pNodeName = pNode->GetName();
int nChildren = pNode->NumberOfChildren();
// Write out this node as [NodeName] : XX Children
Write(iTreeDepth, "[%s] : %i children", pNodeName, nChildren);
// Write out this nodes object properties
ExportObject(pNode, iTreeDepth);
// Recursively call the children
iTreeDepth++;
for (int i = 0; i < nChildren; i++)
{
Export(pNode->GetChildNode(i), iTreeDepth);
}
}
void maxPluginTest::ExportObject(INode* pNode, int iTreeDepth)
{
// Get a pointer to this nodes object reference
Object* pObject = pNode->GetObjectRef();
// the root node for example, doesnt have an object
if (pObject != NULL)
{
SClass_ID lSuperID = pObject->SuperClassID();
Class_ID lClassID = pObject->ClassID();
// Write out our class types
// See also SDK documentation for "list of Super Class IDs"
Write(iTreeDepth, "Obj SuperclassID : %X", lSuperID);
Write(iTreeDepth, "Obj ClassID : (%X, %X)", lClassID.PartA(), lClassID.PartB());
// Is it possible that we can convert this object to
// something we understand? Here we try converting
// to a TriObject, using its Class_ID
if (pObject->CanConvertToType(triObjectClassID))
{
TriObject* pTriObject = (TriObject*)pObject->ConvertToType(0, triObjectClassID);
if (pTriObject != NULL)
{
// Write out the mesh indented
ExportObject(pTriObject, iTreeDepth + 1);
// Note that if the TriObject pointer does not
// point to the the original object, it is a new
// instance that we are now responsible for
if (pTriObject != pObject)
{
// Never call delete directly on any max class
pTriObject->DeleteMe();
}
}
}
}
}
void maxPluginTest::ExportObject(TriObject* pTriObj, int iTreeDepth)
{
// See the SDK Documentation for "PG: Working With Meshes"
// Get the data container
Mesh& lMesh = pTriObj->GetMesh();
// How many vertices?
int nVerts = lMesh.getNumVerts();
Write(iTreeDepth, "Number of Vertices: %i", nVerts);
// Write the vertices positions
for (int i = 0; i < nVerts; i++)
{
Point3& vtx = lMesh.getVert(i);
Write(iTreeDepth, "Vertex[%02i] : (%f,\t%f,\t%f)", i, vtx.x, vtx.y, vtx.z);
}
// Write out our triangle indices
int nTris = lMesh.getNumFaces();
Write(iTreeDepth, "Number of Triangles : %i", nTris);
for (int i = 0; i < nTris; i++)
{
// Mesh has a public property, lFace,
// that we use to access face data
Face& lFace = lMesh.faces[i];
// Retrieves a pointer to the index array
DWORD* pIndices = lFace.getAllVerts();
Write(iTreeDepth, "Face[%02i], Vertex IDs : (%u, %u, %u)",
i, pIndices[0], pIndices[1], pIndices[2]);
}
}