本文整理汇总了C++中MDagPath::instanceNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ MDagPath::instanceNumber方法的具体用法?C++ MDagPath::instanceNumber怎么用?C++ MDagPath::instanceNumber使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDagPath
的用法示例。
在下文中一共展示了MDagPath::instanceNumber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getObjectShadingGroups
bool getObjectShadingGroups(const MDagPath& shapeObjectDP, MObject& shadingGroup)
{
// if obj is a light, simply return the mobject
if (shapeObjectDP.hasFn(MFn::kLight))
shadingGroup = shapeObjectDP.node();
if (shapeObjectDP.hasFn(MFn::kMesh))
{
// Find the Shading Engines Connected to the SourceNode
MFnMesh fnMesh(shapeObjectDP.node());
// A ShadingGroup will have a MFnSet
MObjectArray sets, comps;
fnMesh.getConnectedSetsAndMembers(shapeObjectDP.instanceNumber(), sets, comps, true);
// Each set is a Shading Group. Loop through them
for (unsigned int i = 0; i < sets.length(); ++i)
{
shadingGroup = sets[i];
return true;
}
}
if (shapeObjectDP.hasFn(MFn::kNurbsSurface)||shapeObjectDP.hasFn(MFn::kParticle)||shapeObjectDP.hasFn(MFn::kNParticle))
{
MObject instObjGroupsAttr;
if (shapeObjectDP.hasFn(MFn::kNurbsSurface))
{
MFnNurbsSurface fnNurbs(shapeObjectDP.node());
instObjGroupsAttr = fnNurbs.attribute("instObjGroups");
}
if (shapeObjectDP.hasFn(MFn::kParticle)||shapeObjectDP.hasFn(MFn::kNParticle))
{
MFnParticleSystem fnPart(shapeObjectDP.node());
instObjGroupsAttr = fnPart.attribute("instObjGroups");
}
MPlug instPlug(shapeObjectDP.node(), instObjGroupsAttr);
// Get the instance that our node is referring to;
// In other words get the Plug for instObjGroups[intanceNumber];
MPlug instPlugElem = instPlug.elementByLogicalIndex(shapeObjectDP.instanceNumber());
// Find the ShadingGroup plugs that we are connected to as Source
MPlugArray SGPlugArray;
instPlugElem.connectedTo(SGPlugArray, false, true);
// Loop through each ShadingGroup Plug
for (unsigned int i=0; i < SGPlugArray.length(); ++i)
{
shadingGroup = SGPlugArray[i].node();
return true;
}
}
return false;
}
示例2: DoConnectGeometry
//-----------------------------------------------------------------------------
// This is here for reference. It isn't currently used
//-----------------------------------------------------------------------------
void CVsSkinnerCmd::DoConnectGeometry(
const MDagPath &skinnerPath,
const MDagPath &gDagPath )
{
MObject skinnerObj( skinnerPath.node() );
const MFnDependencyNode vsSkinnerFn( skinnerObj );
const MFnMesh meshFn( gDagPath );
// Connect things up
MPlug sP;
MPlug dP;
MDagModifier &mDagModifier( m_undo.DagModifier() );
// Connect mesh.worldMatrix[#] vsSkinner.geometryWorldMatrix
sP = meshFn.findPlug( "worldMatrix" );
sP = sP.elementByLogicalIndex( gDagPath.instanceNumber() );
dP = vsSkinnerFn.findPlug( "geometryWorldMatrix" );
mDagModifier.connect( sP, dP );
sP = meshFn.findPlug( "outMesh" );
dP = vsSkinnerFn.findPlug( "inputGeometry" );
mDagModifier.connect( sP, dP );
mDagModifier.doIt();
// Add the default volume
MSelectionList emptyList;
MGlobal::setActiveSelectionList( DoNewVolumes( skinnerPath, emptyList ), MGlobal::kReplaceList );
}
示例3: ConnectIntWeld
//-----------------------------------------------------------------------------
//
//-----------------------------------------------------------------------------
void ConnectIntWeld( vm::CUndo &undo, const MObject &weldNodeObj, const MDagPath &toWeldPath, int nType, int nIntValue, const MMatrix &offsetMatrix )
{
MFnDependencyNode weldFn( weldNodeObj );
MFnDagNode toWeldFn( toWeldPath );
MPlug wiAP = weldFn.findPlug( CVstWeldNode::m_iaWeldInput );
const uint nWeldIndex = vm::NextAvailable( wiAP );
MPlug wiP = wiAP.elementByLogicalIndex( nWeldIndex );
undo.SetAttr( wiP.child( CVstWeldNode::m_iaType ), nType );
undo.SetAttr( wiP.child( CVstWeldNode::m_iaInt ), nIntValue );
MFnMatrixData dFn;
MObject mdObj = dFn.create( offsetMatrix );
undo.SetAttr( wiP.child( CVstWeldNode::m_iaOffsetMatrix ), mdObj );
undo.Connect( toWeldFn.findPlug( "parentInverseMatrix" ).elementByLogicalIndex( toWeldPath.instanceNumber() ), wiP.child( CVstWeldNode::m_iaInverseParentSpace ), true );
undo.Connect( toWeldFn.findPlug( "rotateOrder" ), wiP.child( CVstWeldNode::m_iaRotateOrder ), true );
MPlug woAP = weldFn.findPlug( CVstWeldNode::m_oaWeldOutput );
MPlug woP = woAP.elementByLogicalIndex( nWeldIndex );
MPlug tP = woP.child( CVstWeldNode::m_oaTranslate );
undo.Connect( tP.child( CVstWeldNode::m_oaTranslateX ), toWeldFn.findPlug( "translateX" ) );
undo.Connect( tP.child( CVstWeldNode::m_oaTranslateY ), toWeldFn.findPlug( "translateY" ) );
undo.Connect( tP.child( CVstWeldNode::m_oaTranslateZ ), toWeldFn.findPlug( "translateZ" ) );
MPlug rP = woP.child( CVstWeldNode::m_oaRotate );
undo.Connect( rP.child( CVstWeldNode::m_oaRotateX ), toWeldFn.findPlug( "rotateX" ) );
undo.Connect( rP.child( CVstWeldNode::m_oaRotateY ), toWeldFn.findPlug( "rotateY" ) );
undo.Connect( rP.child( CVstWeldNode::m_oaRotateZ ), toWeldFn.findPlug( "rotateZ" ) );
}
示例4: addInstancedDagPaths
// --------------------------------------------------------------------
MStatus SceneGraph::addInstancedDagPaths ( MSelectionList& selectionList )
{
MStatus status;
int length = selectionList.length ( &status );
if ( status != MStatus::kSuccess ) return MStatus::kFailure;
for ( int i=0; i<length; i++ )
{
MDagPath dagPath;
if ( selectionList.getDagPath ( i, dagPath ) != MStatus::kSuccess ) return MStatus::kFailure;
if ( dagPath.isInstanced() )
{
int includedInstance=dagPath.instanceNumber ( &status );
if ( status != MStatus::kSuccess ) return MStatus::kFailure;
MObject object=dagPath.node ( &status );
if ( status != MStatus::kSuccess ) return MStatus::kFailure;
MDagPathArray paths;
if ( MDagPath::getAllPathsTo ( object, paths ) != MStatus::kSuccess ) return MStatus::kFailure;
int numPaths=paths.length();
for ( int p=0; p<numPaths; p++ )
if ( p!=includedInstance )
selectionList.add ( paths[p] );
}
}
return MStatus::kSuccess;
}
示例5: printMaterials
void printMaterials(const MDagPath& dagPath) {
MFnMesh fnMesh(dagPath);
unsigned instanceNumber = dagPath.instanceNumber();
MObjectArray sets;
MObjectArray comps;
fnMesh.getConnectedSetsAndMembers( instanceNumber, sets, comps, true );
// Print Material Names
for(unsigned int i = 0; i < sets.length(); ++i)
{
MFnDependencyNode fnDepSGNode(sets[i]);
std::cout << fnDepSGNode.name() << std::endl;
}
}
示例6: joint
// In order to correctly extract skinweights we first
// need to go into bindpose. (and we need to remember the current
// pose, to be able to undo it).
//
// I know: nearly no error-checking.
void
BindPoseTool::GoIntoBindPose()
{
MStatus status;
std::cout << " Going into bindpose ";
// == turn IK off
// save current state
undoInfo.ikSnap = MIkSystem::isGlobalSnap(&status);
undoInfo.ikSolve = MIkSystem::isGlobalSolve();
// turn it off
MIkSystem::setGlobalSnap(false);
MIkSystem::setGlobalSolve(false);
// == put joints into bindPose
for (MItDag dagIt(MItDag::kDepthFirst, MFn::kJoint);
!dagIt.isDone();
dagIt.next())
{
std::cout << ".";
MDagPath jointPath;
dagIt.getPath(jointPath);
if (jointPath.isInstanced())
{ // we only work on the first instance of an instanced joint.
if (jointPath.instanceNumber() != 0)
continue;
}
BindPoseUndoInformation::JointMatrixVector::value_type joint2transform;
MFnIkJoint joint(jointPath.node());
MTransformationMatrix currentTransform = joint.transformation(&status);
joint2transform.first = jointPath.node();
joint2transform.second = currentTransform;
undoInfo.savedTransforms.push_back(joint2transform);
MMatrix bindPoseMatrix = getBindPoseMatrix(joint);
joint.set(bindPoseMatrix);
}
std::cout << std::endl;
//cout << "bindPose end" << endl;
// don't know, if this is really necessary, but MS xporttranslator
// does it...
syncMeshes();
// remember the change
inBindPose = true;
}
示例7: doConversion
IECore::ObjectPtr FromMayaTransformConverter::doConversion( const MDagPath &dagPath, IECore::ConstCompoundObjectPtr operands ) const
{
MTransformationMatrix transform;
if( m_spaceParameter->getNumericValue()==Local )
{
MFnTransform fnT( dagPath );
transform = fnT.transformation();
}
else
{
unsigned instIndex = dagPath.instanceNumber();
MObject dagNode = dagPath.node();
MFnDependencyNode fnN( dagNode );
MPlug plug = fnN.findPlug( "worldMatrix" );
MPlug instPlug = plug.elementByLogicalIndex( instIndex );
MObject matrix;
instPlug.getValue( matrix );
MFnMatrixData fnM( matrix );
transform = fnM.transformation();
if ( m_spaceParameter->getNumericValue() == Custom )
{
// multiply world transform by the inverse of the custom space matrix.
transform = transform.asMatrix() * IECore::convert< MMatrix, Imath::M44f >( operands->member< IECore::M44fData >("customSpace", true)->readable().inverse() );
}
}
if( m_zeroPivotsParameter->getTypedValue() )
{
transform.setScalePivot( MPoint( 0, 0, 0 ), MSpace::kTransform, true );
transform.setRotatePivot( MPoint( 0, 0, 0 ), MSpace::kTransform, true );
}
if( m_eulerFilterParameter->getTypedValue() && m_lastRotationValid )
{
transform.rotateTo( transform.eulerRotation().closestSolution( m_lastRotation ) );
}
m_lastRotation = transform.eulerRotation();
m_lastRotationValid = true;
return new IECore::TransformationMatrixdData( IECore::convert<IECore::TransformationMatrixd, MTransformationMatrix>( transform ) );
}
示例8: exportConnectedMaterials
//------------------------------
void MaterialExporter::exportConnectedMaterials ( SceneElement* sceneElement )
{
// If we have a external reference, we don't need to export the data here.
if ( !sceneElement->getIsLocal() ) return;
if ( !sceneElement->getIsExportNode () ) return;
// Check if it is a mesh object and an export node
if ( sceneElement->getType() == SceneElement::MESH )
{
MDagPath dagPath = sceneElement->getPath();
// Attach a function set
MStatus status;
MFnMesh fnMesh ( dagPath.node(), &status );
if ( status != MStatus::kSuccess ) return;
// Find how many shaders are used by this instance of the mesh
MObjectArray shaders;
MIntArray shaderIndices;
unsigned instanceNumber = dagPath.instanceNumber();
fnMesh.getConnectedShaders ( instanceNumber, shaders, shaderIndices );
// Find the polygons that correspond to each materials and export them
uint realShaderCount = ( uint ) shaders.length();
uint numShaders = ( uint ) std::max ( ( size_t ) 1, ( size_t ) shaders.length() );
for ( uint shaderPosition = 0; shaderPosition < numShaders; ++shaderPosition )
{
if ( shaderPosition < realShaderCount )
{
// Add shader-specific parameters (TexCoords sets).
// Add symbolic name for the material used on this polygon set.
MObject shadingEngine = shaders[shaderPosition];
exportMaterial ( shadingEngine );
}
}
}
// recursive call for all the child elements
for ( uint i=0; i<sceneElement->getChildCount(); ++i )
{
SceneElement* childElement = sceneElement->getChild ( i );
exportConnectedMaterials ( childElement );
}
}
示例9: GetSelectedMesh
MFnMesh* GDExporter::GetSelectedMesh(void)
{
MSelectionList currSelection;
MGlobal::getActiveSelectionList(currSelection);
unsigned int selectionCount = currSelection.length();
MFnMesh* exportingMesh = 0;
for(unsigned int selectionIndex = 0; selectionIndex < selectionCount; ++selectionIndex )
{
MDagPath currPath;
currSelection.getDagPath(selectionIndex, currPath);
if( currPath.apiType() != MFn::kTransform )
continue;
MFnTransform currTransform(currPath);
unsigned int childCount = currTransform.childCount();
for(unsigned int childIndex = 0; childIndex < childCount; ++childIndex)
{
MObject childObject = currTransform.child(childIndex);
if( childObject.apiType() == MFn::kMesh )
{
MFnDagNode dagNode;
dagNode.setObject(childObject);
MDagPath childPath;
dagNode.getPath(childPath);
MFnMesh* pChildMesh = new MFnMesh(childPath);
if( pChildMesh->isIntermediateObject() )
continue;
bool bExportMesh = true;
if( pChildMesh->isInstanced(false) )
if( childPath.instanceNumber() != 0 )
bExportMesh = false;
if( bExportMesh )
{
if( exportingMesh != 0 )
{
delete exportingMesh;
delete pChildMesh;
MGlobal::displayError(MString("GDExporter - More than one mesh object selected."));
return 0;
}
exportingMesh = pChildMesh;
}
}
}
}
if( exportingMesh == 0 )
{
MGlobal::displayError(MString("GDExporter - No mesh objects currently selected."));
return 0;
}
return exportingMesh;
}
示例10: doIt
MStatus findTexturesPerPolygon::doIt( const MArgList& )
//
// Description:
// Find the texture files that apply to the color of each polygon of
// a selected shape if the shape has its polygons organized into sets.
//
{
// Get the selection and choose the first path on the selection list.
//
MStatus status;
MDagPath path;
MObject cmp;
MSelectionList slist;
MGlobal::getActiveSelectionList(slist);
slist.getDagPath(0, path, cmp);
// Have to make the path include the shape below it so that
// we can determine if the underlying shape node is instanced.
// By default, dag paths only include transform nodes.
//
path.extendToShape();
// If the shape is instanced then we need to determine which
// instance this path refers to.
//
int instanceNum = 0;
if (path.isInstanced())
instanceNum = path.instanceNumber();
// Get a list of all sets pertaining to the selected shape and the
// members of those sets.
//
MFnMesh fnMesh(path);
MObjectArray sets;
MObjectArray comps;
if (!fnMesh.getConnectedSetsAndMembers(instanceNum, sets, comps, true))
cerr << "ERROR: MFnMesh::getConnectedSetsAndMembers\n";
// Loop through all the sets. If the set is a polygonal set, find the
// shader attached to the and print out the texture file name for the
// set along with the polygons in the set.
//
for ( unsigned i=0; i<sets.length(); i++ ) {
MObject set = sets[i];
MObject comp = comps[i];
MFnSet fnSet( set, &status );
if (status == MS::kFailure) {
cerr << "ERROR: MFnSet::MFnSet\n";
continue;
}
// Make sure the set is a polygonal set. If not, continue.
MItMeshPolygon piter(path, comp, &status);
if ((status == MS::kFailure) || comp.isNull())
continue;
// Find the texture that is applied to this set. First, get the
// shading node connected to the set. Then, if there is an input
// attribute called "color", search upstream from it for a texture
// file node.
//
MObject shaderNode = findShader(set);
if (shaderNode == MObject::kNullObj)
continue;
MPlug colorPlug = MFnDependencyNode(shaderNode).findPlug("color", &status);
if (status == MS::kFailure)
continue;
MItDependencyGraph dgIt(colorPlug, MFn::kFileTexture,
MItDependencyGraph::kUpstream,
MItDependencyGraph::kBreadthFirst,
MItDependencyGraph::kNodeLevel,
&status);
if (status == MS::kFailure)
continue;
dgIt.disablePruningOnFilter();
// If no texture file node was found, just continue.
//
if (dgIt.isDone())
continue;
// Print out the texture node name and texture file that it references.
//
MObject textureNode = dgIt.thisNode();
MPlug filenamePlug = MFnDependencyNode(textureNode).findPlug("fileTextureName");
MString textureName;
filenamePlug.getValue(textureName);
cerr << "Set: " << fnSet.name() << endl;
cerr << "Texture Node Name: " << MFnDependencyNode(textureNode).name() << endl;
cerr << "Texture File Name: " << textureName.asChar() << endl;
// Print out the set of polygons that are contained in the current set.
//
for ( ; !piter.isDone(); piter.next() )
cerr << " poly component: " << piter.index() << endl;
//.........这里部分代码省略.........
示例11: getIsExportNode
// --------------------------------------------------------------------
bool SceneGraph::getIsExportNode (
const MDagPath& dagPath,
bool& isForced,
bool& isVisible )
{
// Does this dagPath already exist? If so, only recurse if FollowInstancedChildren() is set.
MFnDagNode dagFn ( dagPath );
String dagNodeName = dagFn.name().asChar();
bool isSceneRoot = dagPath.length() == 0;
// Ignore default and intermediate nodes (history items)
bool isIntermediateObject = dagFn.isIntermediateObject();
if ( ( dagFn.isDefaultNode() && !isSceneRoot ) || isIntermediateObject )
{
return false;
}
MString nodeName = dagPath.partialPathName();
if ( nodeName == MString ( NIMA_INTERNAL_PHYSIKS ) )
{
// Skip this node, which is only used
// by Nima as a work-around for a Maya bug.
return false;
}
// If we are not already forcing this node, its children
// check whether we should be forcing it (skinning of hidden joints).
isForced = isForcedNode ( dagPath );
DagHelper::getPlugValue ( dagPath.node(), ATTR_VISIBILITY, isVisible );
bool isInstanced = dagPath.isInstanced();
uint instanceNumber = dagPath.instanceNumber();
if ( !isForced )
{
// Check for visibility
if ( !ExportOptions::exportInvisibleNodes() && !isVisible )
{
// Check if the visibility of the element is animated.
AnimationSampleCache* animationCache = mDocumentExporter->getAnimationCache();
if ( !AnimationHelper::isAnimated ( animationCache, dagPath.node(), ATTR_VISIBILITY ) )
{
return false;
}
}
else if ( !isVisible && !ExportOptions::exportDefaultCameras() )
{
// Check for the default camera transform names.
if ( nodeName == CAMERA_PERSP || nodeName == CAMERA_TOP || nodeName == CAMERA_SIDE || nodeName == CAMERA_FRONT ||
nodeName == CAMERA_PERSP_SHAPE || nodeName == CAMERA_TOP_SHAPE || nodeName == CAMERA_SIDE_SHAPE || nodeName == CAMERA_FRONT_SHAPE )
return false;
}
}
isForced &= !isVisible;
if ( !isForced )
{
// We don't want to process manipulators
if ( dagPath.hasFn ( MFn::kManipulator ) || dagPath.hasFn ( MFn::kViewManip ) ) return false;
// Check for constraints which are not exported
//if ( !ExportOptions::exportConstraints() && dagPath.hasFn ( MFn::kConstraint ) ) return false;
if ( dagPath.hasFn ( MFn::kConstraint ) ) return false;
// Check set membership exclusion/inclusion
if ( SetHelper::isExcluded ( dagPath ) ) return false;
}
return true;
}
示例12: extractPolygons
void extractPolygons(Model* model) {
MStatus stat;
MItDag dagIter(MItDag::kBreadthFirst, MFn::kInvalid);
for (; !dagIter.isDone(); dagIter.next()) {
MDagPath dagPath;
stat = dagIter.getPath(dagPath);
if (!stat) { continue; };
MFnDagNode dagNode(dagPath, &stat);
if (dagNode.isIntermediateObject()) continue;
if (!dagPath.hasFn( MFn::kMesh )) continue;
if (dagPath.hasFn( MFn::kTransform)) continue;
if (!dagPath.isVisible()) continue;
MFnMesh fnMesh(dagPath);
MStringArray UVSets;
stat = fnMesh.getUVSetNames( UVSets );
// Get all UVs for the first UV set.
MFloatArray u, v;
fnMesh.getUVs(u, v, &UVSets[0]);
MPointArray vertexList;
fnMesh.getPoints(vertexList, MSpace::kObject);
MFloatVectorArray meshNormals;
fnMesh.getNormals(meshNormals);
unsigned instanceNumber = dagPath.instanceNumber();
MObjectArray sets;
MObjectArray comps;
fnMesh.getConnectedSetsAndMembers( instanceNumber, sets, comps, true );
//printMaterials(dagPath);
unsigned int comlength = comps.length();
for (unsigned int compi = 0; compi < comlength; compi++) {
SubMesh submesh;
MItMeshPolygon itPolygon(dagPath, comps[compi]);
unsigned int polyCount = 0;
for (; !itPolygon.isDone(); itPolygon.next()) {
polyCount++;
MIntArray polygonVertices;
itPolygon.getVertices(polygonVertices);
int count;
itPolygon.numTriangles(count);
for (; count > -1; count--) {
MPointArray nonTweaked;
MIntArray triangleVertices;
MIntArray localIndex;
MStatus status;
status = itPolygon.getTriangle(count, nonTweaked, triangleVertices, MSpace::kObject);
if (status == MS::kSuccess) {
VertexDefinition vertex1;
VertexDefinition vertex2;
VertexDefinition vertex3;
{ // vertices
int vertexCount = vertexList.length();
{
int vertexIndex0 = triangleVertices[0];
MPoint point0 = vertexList[vertexIndex0];
vertex1.vertex.x = (float)point0.x;
vertex1.vertex.y = (float)point0.y;
vertex1.vertex.z = (float)point0.z;
}
{
int vertexIndex0 = triangleVertices[1];
MPoint point0 = vertexList[vertexIndex0];
vertex2.vertex.x = (float)point0.x;
vertex2.vertex.y = (float)point0.y;
vertex2.vertex.z = (float)point0.z;
}
{
int vertexIndex0 = triangleVertices[2];
MPoint point0 = vertexList[vertexIndex0];
vertex3.vertex.x = (float)point0.x;
vertex3.vertex.y = (float)point0.y;
//.........这里部分代码省略.........
示例13: redoIt
//.........这里部分代码省略.........
{
MPlug mP( toAimFn.findPlug( "rotateAxis" ) );
if ( !mP.isNull() )
{
MAngle rx, ry, rz;
mP.child( 0 ).getValue( rx );
mP.child( 1 ).getValue( ry );
mP.child( 2 ).getValue( rz );
if ( abs( rx.value() ) > FLT_EPSILON || abs( ry.value() ) > FLT_EPSILON || abs( rz.value() ) > FLT_EPSILON )
{
mwarn << "Rotate Axis on node being constrained is non-zero ( " << rx.asDegrees() << " " << ry.asDegrees() << " " << rz.asDegrees() << " ), setting to 0" << std::endl;
mP.child( 0 ).setValue( MAngle( 0.0 ) );
mP.child( 1 ).setValue( MAngle( 0.0 ) );
mP.child( 2 ).setValue( MAngle( 0.0 ) );
}
}
}
MDagPath aimAt;
optSelectionList.getDagPath( 0, aimAt );
const MFnDagNode aimAtFn( aimAt );
// toAim.rotateOrder -> vstAim.rotateOrder
sP = toAimFn.findPlug( "rotateOrder" );
dP = vstAimFn.findPlug( "rotateOrder" );
m_mDagModifier->connect( sP, dP );
// toAim.translate -> vstAim.translate
sP = toAimFn.findPlug( "translate" );
dP = vstAimFn.findPlug( "translate" );
m_mDagModifier->connect( sP, dP );
// toAim.parentMatrix[ instance ] -> vstAim.parentSpace
sP = toAimFn.findPlug( "parentMatrix" );
sP = sP.elementByLogicalIndex( toAim.instanceNumber() );
dP = vstAimFn.findPlug( "parentSpace" );
m_mDagModifier->connect( sP, dP );
// aimAt.worldMatrix[ instance ] -> vstAim.aimSpace
sP = aimAtFn.findPlug( "worldMatrix" );
sP = sP.elementByLogicalIndex( aimAt.instanceNumber() );
dP = vstAimFn.findPlug( "aimSpace" );
m_mDagModifier->connect( sP, dP );
// vstAim.rotation -> toAim.rotation
// These have to be connected individually because Maya plays stupid tricks
// with rotateOrder if they aren't
sP = vstAimFn.findPlug( "rotateX" );
dP = toAimFn.findPlug( "rotateX" );
m_mDagModifier->connect( sP, dP );
sP = vstAimFn.findPlug( "rotateY" );
dP = toAimFn.findPlug( "rotateY" );
m_mDagModifier->connect( sP, dP );
sP = vstAimFn.findPlug( "rotateZ" );
dP = toAimFn.findPlug( "rotateZ" );
m_mDagModifier->connect( sP, dP );
if ( m_mDagModifier->doIt() != MS::kSuccess )
{
displayWarning( MString( GetName() ) + ": Couldn't connect everything when creating" );
}
// Save the current selection just in case we want to undo stuff
MGlobal::getActiveSelectionList( m_mSelectionList );
MGlobal::select( vstAimObj, MGlobal::kReplaceList );
setResult( vstAimFn.name() );
}
else if ( m_mArgDatabase->isFlagSet( "select" ) )
{
MSelectionList mSelectionList;
MDagPath mDagPath;
for ( MItDag dagIt; !dagIt.isDone(); dagIt.next() )
{
if ( MFnDependencyNode( dagIt.item() ).typeName() == GetName() )
{
dagIt.getPath( mDagPath );
mSelectionList.add( mDagPath, MObject::kNullObj, true );
}
}
if ( mSelectionList.length() )
{
m_undoable = true;
// Save the current selection just in case we want to undo stuff
MGlobal::getActiveSelectionList( m_mSelectionList );
MGlobal::setActiveSelectionList( mSelectionList, MGlobal::kReplaceList );
}
}
else
{
displayError( GetName() + ": No valid operation specified via command line arguments\n" );
}
}
return MS::kSuccess;
}
示例14: GetShapeInstanceShader
// Get shading engine
//
void CScriptedShapeTranslator::GetShapeInstanceShader(MDagPath& dagPath, MFnDependencyNode &shadingEngineNode)
{
// Get instance shadingEngine
shadingEngineNode.setObject(MObject::kNullObj);
// First try the usual way
MPlug shadingGroupPlug = GetNodeShadingGroup(dagPath.node(), (dagPath.isInstanced() ? dagPath.instanceNumber() : 0));
if (!shadingGroupPlug.isNull())
{
shadingEngineNode.setObject(shadingGroupPlug.node());
return;
}
char buffer[64];
// Check connection from any shadingEngine on shape
MStringArray connections;
MGlobal::executeCommand("listConnections -s 1 -d 0 -c 1 -type shadingEngine "+dagPath.fullPathName(), connections);
MSelectionList sl;
if (connections.length() == 0)
{
// Check for direct surface shader connection
MGlobal::executeCommand("listConnections -s 1 -d 0 -c 1 "+dagPath.fullPathName(), connections);
for (unsigned int cidx=0; cidx<connections.length(); cidx+=2)
{
MString srcNode = connections[cidx+1];
// Get node classification, if can find arnold/shader/surface -> got it
MStringArray rv;
MGlobal::executeCommand("getClassification `nodeType "+srcNode+"`", rv);
if (rv.length() > 0 && rv[0].indexW("arnold/shader/surface") != -1)
{
connections.clear();
MGlobal::executeCommand("listConnections -s 0 -d 1 -c 1 -type shadingEngine "+srcNode, connections);
if (connections.length() == 2)
{
sl.add(connections[1]);
}
break;
}
}
}
else if (connections.length() == 2)
{
// Single connection, use same shader for all instances
sl.add(connections[1]);
}
else if (connections.length() > 2)
{
// Many connections, expects the destination plug in shape to be an array
// Use instance number as logical index, if this fails, use first shadingEngine in list
bool found = false;
sprintf(buffer, "[%d]", dagPath.instanceNumber());
MString iidx = buffer;
for (unsigned int cidx = 0; cidx < connections.length(); cidx += 2)
{
MString conn = connections[cidx];
if (conn.length() < iidx.length())
{
continue;
}
if (conn.substring(conn.length() - iidx.length(), conn.length() - 1) != iidx)
{
continue;
}
sl.add(connections[cidx+1]);
found = true;
break;
}
if (!found)
{
MGlobal::displayWarning("[mtoaScriptedTranslators] Instance shader plug not found, use first found shadingEngine \"" + connections[1] + "\"");
sl.add(connections[1]);
}
}
if (sl.length() == 1)
{
MObject shadingEngineObj;
if (sl.getDependNode(0, shadingEngineObj) == MS::kSuccess && shadingEngineObj.apiType() == MFn::kShadingEngine)
{
shadingEngineNode.setObject(shadingEngineObj);
}
//.........这里部分代码省略.........
示例15: ExportPart
MStatus CXRayObjectExport::ExportPart(CEditableObject* O, MDagPath& mdagPath, MObject& mComponent)
{
MStatus stat = MS::kSuccess;
MSpace::Space space = MSpace::kWorld;
MFnMesh fnMesh( mdagPath, &stat );
if ( MS::kSuccess != stat) {
fprintf(stderr,"Failure in MFnMesh initialization.\n");
return MS::kFailure;
}
MString mdagPathNodeName = fnMesh.name();
MFnDagNode dagNode1(mdagPath);
u32 pc = dagNode1.parentCount();
for(u32 ip=0;ip<pc;++ip)
{
MObject object_parent = dagNode1.parent(ip, &stat);
if(object_parent.hasFn(MFn::kTransform))
{
MFnTransform parent_transform(object_parent,&stat);
if ( MS::kSuccess == stat)
{
mdagPathNodeName = parent_transform.name();
break;
}
}
}
MItMeshPolygon meshPoly( mdagPath, mComponent, &stat );
if ( MS::kSuccess != stat) {
fprintf(stderr,"Failure in MItMeshPolygon initialization.\n");
return MS::kFailure;
}
MItMeshVertex vtxIter( mdagPath, mComponent, &stat );
if ( MS::kSuccess != stat) {
fprintf(stderr,"Failure in MItMeshVertex initialization.\n");
return MS::kFailure;
}
// If the shape is instanced then we need to determine which
// instance this path refers to.
//
int instanceNum = 0;
if (mdagPath.isInstanced())
instanceNum = mdagPath.instanceNumber();
// Get a list of all shaders attached to this mesh
MObjectArray rgShaders;
MIntArray texMap;
MStatus status;
status = fnMesh.getConnectedShaders (instanceNum, rgShaders, texMap);
if (status == MStatus::kFailure)
{
Log("! Unable to load shaders for mesh");
return (MStatus::kFailure);
}
XRShaderDataVec xr_data;
{
for ( int i=0; i<(int)rgShaders.length(); i++ ) {
MObject shader = rgShaders[i];
xr_data.push_back(SXRShaderData());
SXRShaderData& D = xr_data.back();
status = parseShader(shader, D);
if (status == MStatus::kFailure) {
status.perror ("Unable to retrieve filename of texture");
continue;
}
}
}
CEditableMesh* MESH = new CEditableMesh(O);
MESH->SetName(mdagPathNodeName.asChar());
O->AppendMesh(MESH);
int objectIdx, length;
// Find i such that objectGroupsTablePtr[i] corresponds to the
// object node pointed to by mdagPath
length = objectNodeNamesArray.length();
{
for( int i=0; i<length; i++ ) {
if( objectNodeNamesArray[i] == mdagPathNodeName ) {
objectIdx = i;
break;
}
}
}
// Reserve uv table
{
VMapVec& _vmaps = MESH->m_VMaps;
_vmaps.resize (1);
st_VMap*& VM = _vmaps.back();
VM = new st_VMap("Texture",vmtUV,false);
}
//.........这里部分代码省略.........