如何从实例化的GeomObject获取网格物体?
在maxscript中我做:
gsphere = createInstance geosphere radius:1 segs:4
gsphere_mesh = gsphere.mesh
以下是转换为C ++的maxscript的第一行:
GeomObject *GSphere = (GeomObject*)ip->CreateInstance(GEOMOBJECT_CLASS_ID, GSPHERE_CLASS_ID);
GSphere->GetParamBlockByID(2)->SetValue(0, 0, 1);
GSphere->GetParamBlockByID(2)->SetValue(1, 0, 4);
现在,我需要获得网格,但我无法弄清楚如何。没有" GetMesh()"或" GetTriMesh()"功能
感谢您的帮助。
答案 0 :(得分:1)
要访问节点的网格,您可以使用以下内容:
for (int t = 0; maxscene->NumChildren() > t; t++)
{
INode* currNode = maxscene->GetChildNode(t);
Object* obj;
ObjectState os = currNode->EvalWorldState(GetCOREInterface()->GetTime());
obj = os.obj;
switch (os.obj->SuperClassID())
{
case GEOMOBJECT_CLASS_ID:
TriObject *p_triobj = NULL;
BOOL fConvertedToTriObject = obj->CanConvertToType(triObjectClassID) && (p_triobj = (TriObject*)obj->ConvertToType(0, triObjectClassID)) != NULL;
if (!fConvertedToTriObject)
{
mprintf(L"Error: Could not triangulate object.);
return false;
}
Mesh *p_trimesh = &p_triobj->mesh;
int faceCount = p_trimesh->getNumFaces();
//work with the mesh here.
}
}