我得到所有材料,然后我得到当前材料中的所有多边形:
MStatus stat = MStatus::kSuccess;
MSpace::Space space = MSpace::kWorld;
MFnSet fnSet(set, &stat);
if (stat == MS::kFailure)
{
MStreamUtils::stdErrorStream() << "ERROR: MFnSet::MFnSet\n";
return MStatus::kNotImplemented;
}
MItMeshPolygon polyIter(mdagPath, comp, &stat); // iterator on vertex
if ((stat == MS::kFailure))
{
MStreamUtils::stdErrorStream() << "ERROR: Can't create poly iterator!\n";
return MStatus::kNotImplemented;
}
MFnDependencyNode fnNode(set);
MPlug shaderPlug = fnNode.findPlug("surfaceShader");
MPlugArray connectedPlugs;
if (shaderPlug.isNull())
{
MStreamUtils::stdErrorStream() << "ERROR: Can't find material!\n";
return MStatus::kNotImplemented;
}
shaderPlug.connectedTo(connectedPlugs, true, false);
MFnDependencyNode fnDN(connectedPlugs[0].node());
MItDependencyGraph dgIt(shaderPlug, MFn::kFileTexture,
MItDependencyGraph::kUpstream,
MItDependencyGraph::kBreadthFirst,
MItDependencyGraph::kNodeLevel,
&stat);
if (stat == MS::kFailure)
{
MStreamUtils::stdErrorStream() << "ERROR: Can't load graph textures\n";
return MStatus::kNotImplemented;
}
dgIt.disablePruningOnFilter();
if (dgIt.isDone())
{
MStreamUtils::stdErrorStream() << "Warning: Material " << fnDN.name().asChar() << " not textured\n";
//return MStatus::kNotImplemented;
}
// no need, here we get the texture
MObject textureNode = dgIt.thisNode();
MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName");
MString textureName; // name texture + path
filenamePlug.getValue(textureName);
(; !polyIter.isDone(); polyIter.next())
{
// here get poly and perform actions on it
}