本文整理汇总了C++中MFnDagNode::duplicate方法的典型用法代码示例。如果您正苦于以下问题:C++ MFnDagNode::duplicate方法的具体用法?C++ MFnDagNode::duplicate怎么用?C++ MFnDagNode::duplicate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MFnDagNode
的用法示例。
在下文中一共展示了MFnDagNode::duplicate方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cacheMeshData
MStatus polyModifierCmd::cacheMeshData()
{
MStatus status = MS::kSuccess;
MFnDependencyNode depNodeFn;
MFnDagNode dagNodeFn;
MObject meshNode = fDagPath.node();
MObject dupMeshNode;
MPlug dupMeshNodeOutMeshPlug;
// Duplicate the mesh
//
dagNodeFn.setObject( meshNode );
dupMeshNode = dagNodeFn.duplicate();
MDagPath dupMeshDagPath;
MDagPath::getAPathTo( dupMeshNode, dupMeshDagPath );
dupMeshDagPath.extendToShape();
depNodeFn.setObject( dupMeshDagPath.node() );
dupMeshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status );
MCheckStatus( status, "Could not retrieve outMesh" );
// Retrieve the meshData
//
status = dupMeshNodeOutMeshPlug.getValue( fMeshData );
MCheckStatus( status, "Could not retrieve meshData" );
// Delete the duplicated node
//
MGlobal::deleteNode( dupMeshNode );
return status;
}
示例2: undoDirectModifier
// --------------------------------------------------------------------------------------------
MStatus polyModifierCmd::undoDirectModifier()
// --------------------------------------------------------------------------------------------
{
MStatus status;
MFnDependencyNode depNodeFn;
MFnDagNode dagNodeFn;
MObject meshNode = fDagPath.node();
depNodeFn.setObject( meshNode );
// For the case with tweaks, we cannot write the mesh directly back onto
// the cachedInMesh, since the shape can have out of date information from the
// cachedInMesh. Thus we temporarily create an duplicate mesh, place our
// old mesh on the outMesh attribute of our duplicate mesh, connect the
// duplicate mesh shape to the mesh shape, and force a DG evaluation.
//
// For the case without tweaks, we can simply write onto the outMesh, since
// the shape relies solely on an outMesh when there is no history nor tweaks.
//
if( fHasTweaks )
{
// Retrieve the inMesh and name of our mesh node (for the DG eval)
//
depNodeFn.setObject( meshNode );
MPlug meshNodeInMeshPlug = depNodeFn.findPlug( "inMesh", &status );
MCheckStatus( status, "Could not retrieve inMesh" );
MString meshNodeName = depNodeFn.name();
// Duplicate our current mesh
//
dagNodeFn.setObject( meshNode );
MObject dupMeshNode = dagNodeFn.duplicate();
// The dagNodeFn::duplicate() returns a transform, but we need a shape
// so retrieve the DAG path and extend it to the shape.
//
MDagPath dupMeshDagPath;
MDagPath::getAPathTo( dupMeshNode, dupMeshDagPath );
dupMeshDagPath.extendToShape();
// Retrieve the outMesh of the duplicate mesh and set our mesh data back
// on it.
//
depNodeFn.setObject( dupMeshDagPath.node() );
MPlug dupMeshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status );
MCheckStatus( status, "Could not retrieve outMesh" );
status = dupMeshNodeOutMeshPlug.setValue( fMeshData );
// Temporarily connect the duplicate mesh node to our mesh node
//
MDGModifier dgModifier;
dgModifier.connect( dupMeshNodeOutMeshPlug, meshNodeInMeshPlug );
status = dgModifier.doIt();
MCheckStatus( status, "Could not connect dupMeshNode -> meshNode" );
// Need to force a DG evaluation now that the input has been changed.
//
MString cmd("dgeval -src ");
cmd += meshNodeName;
cmd += ".inMesh";
status = MGlobal::executeCommand( cmd, false, false );
MCheckStatus( status, "Could not force DG eval" );
// Disconnect and delete the duplicate mesh node now
//
dgModifier.undoIt();
MGlobal::deleteNode( dupMeshNode );
// Restore the tweaks on the mesh
//
status = undoTweakProcessing();
}
else
{
// Restore the original mesh by writing the old mesh data (fMeshData) back
// onto the outMesh of our meshNode
//
depNodeFn.setObject( meshNode );
MPlug meshNodeOutMeshPlug = depNodeFn.findPlug( "outMesh", &status );
MCheckStatus( status, "Could not retrieve outMesh" );
status = meshNodeOutMeshPlug.setValue( fMeshData );
MCheckStatus( status, "Could not set meshData" );
}
return status;
}
示例3: processUpstreamNode
MStatus polyModifierCmd::processUpstreamNode( modifyPolyData& data )
{
MStatus status = MS::kSuccess;
// Declare our function sets - Although dagNodeFn derives from depNodeFn, we need
// both since dagNodeFn can only refer to DAG objects.
// We will use depNodeFn for all times other when dealing
// with the DAG.
//
MFnDependencyNode depNodeFn;
MFnDagNode dagNodeFn;
// Use the selected node's plug connections to find the upstream plug.
// Since we are looking at the selected node's inMesh attribute, it will
// always have only one connection coming in if it has history, and none
// otherwise.
//
// If there is no history, copy the selected node and place it ahead of the
// modifierNode as the new upstream node so that the modifierNode has an
// input mesh to operate on.
//
MPlugArray tempPlugArray;
if( fHasHistory )
{
// Since we have history, look for what connections exist on the
// meshNode "inMesh" plug. "inMesh" plugs should only ever have one
// connection.
//
data.meshNodeDestPlug.connectedTo( tempPlugArray, true, false);
// ASSERT: Only one connection should exist on meshNodeShape.inMesh!
//
MStatusAssert( (tempPlugArray.length() == 1),
"tempPlugArray.length() == 1 -- 0 or >1 connections on meshNodeShape.inMesh" );
data.upstreamNodeSrcPlug = tempPlugArray[0];
// Construction history only deals with shapes, so we can grab the
// upstreamNodeShape off of the source plug.
//
data.upstreamNodeShape = data.upstreamNodeSrcPlug.node();
depNodeFn.setObject( data.upstreamNodeShape );
data.upstreamNodeSrcAttr = data.upstreamNodeSrcPlug.attribute();
// Disconnect the upstream node and the selected node, so we can
// replace them with our own connections below.
//
fDGModifier.disconnect( data.upstreamNodeShape,
data.upstreamNodeSrcAttr,
data.meshNodeShape,
data.meshNodeDestAttr );
}
else // No History (!fHasHistory)
{
// Use the DAG node function set to duplicate the shape of the meshNode.
// The duplicate method will return an MObject handle to the transform
// of the duplicated shape, so traverse the dag to locate the shape. Store
// this duplicate shape as our "upstream" node to drive the input for the
// modifierNode.
//
dagNodeFn.setObject( data.meshNodeShape );
data.upstreamNodeTransform = dagNodeFn.duplicate( false, false );
dagNodeFn.setObject( data.upstreamNodeTransform );
// Ensure that our upstreamNode is pointing to a shape.
//
MStatusAssert( (0 < dagNodeFn.childCount()),
"0 < dagNodeFn.childCount() -- Duplicate meshNode transform has no shape." );
data.upstreamNodeShape = dagNodeFn.child(0);
// Re-parent the upstreamNodeShape under our original transform
//
status = fDagModifier.reparentNode( data.upstreamNodeShape, data.meshNodeTransform );
MCheckStatus( status, "reparentNode" );
// Perform the DAG re-parenting
//
// Note: This reparent must be performed before the deleteNode() is called.
// See polyModifierCmd.h (see definition of fDagModifier) for more details.
//
status = fDagModifier.doIt();
MCheckStatus( status, "fDagModifier.doIt()" );
// Mark the upstreamNodeShape (the original shape) as an intermediate object
// (making it invisible to the user)
//
dagNodeFn.setObject( data.upstreamNodeShape );
dagNodeFn.setIntermediateObject( true );
// Get the upstream node source attribute
//
data.upstreamNodeSrcAttr = dagNodeFn.attribute( "outMesh" );
// Remove the duplicated transform node (clean up)
//
status = fDagModifier.deleteNode( data.upstreamNodeTransform );
MCheckStatus( status, "deleteNode" );
//.........这里部分代码省略.........
示例4: extractFaces_Func
bool tm_polyExtract::extractFaces_Func( MSelectionList &selectionList, MStringArray &node_names)
{
MStatus status;
MObject meshObj;
status = selectionList.getDependNode( 0, meshObj);
if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Can't find object !");return false;}
MFnMesh meshFn( meshObj, &status);
if(!status){MGlobal::displayError("tm_polyExtract::extractFaces_Func: Non mesh object founded !");return false;}
MDagPath meshDagPath_first, meshDagPath;
selectionList.getDagPath( 0, meshDagPath_first);
MObject multiFaceComponent;
MIntArray inputFacesArray;
inputFacesArray.clear();
inputFacesArray.setSizeIncrement( 4096);
MFnComponentListData compListFn;
compListFn.create();
for (MItSelectionList faceComponentIter(selectionList, MFn::kMeshPolygonComponent); !faceComponentIter.isDone(); faceComponentIter.next())
{
faceComponentIter.getDagPath(meshDagPath, multiFaceComponent);
if(!(meshDagPath_first == meshDagPath))
{
MGlobal::displayError("tm_polyExtract::extractFaces_Func: Different meshes faces founded !");
return false;
}
if (!multiFaceComponent.isNull())
{
for (MItMeshPolygon faceIter(meshDagPath, multiFaceComponent); !faceIter.isDone(); faceIter.next())
{
int faceIndex = faceIter.index();
#ifdef _DEBUG
infoMStr += faceIndex;
infoMStr += " ";
#endif
inputFacesArray.append( faceIndex);
compListFn.add( multiFaceComponent );
}
}
}
if( inputFacesArray.length() == 0)
{
MGlobal::displayError("tm_polyExtract::extractFaces_Func: No faces founded !");
return false;
}
#ifdef _DEBUG
MGlobal::displayInfo( infoMStr);
#endif
meshFn.setObject( meshDagPath_first);
meshObj = meshFn.object();
// MDagModifier dagModifier;
MFnDagNode meshDagNodeFn;
MFnDependencyNode depNodeFn;
meshDagNodeFn.setObject( meshDagPath_first);
MString meshName = meshDagNodeFn.name();
MObject outMesh_attrObject = meshDagNodeFn.attribute( "outMesh");
// ----------------------------------- duplicate shape
MObject duplicated_meshObjectA;
MObject duplicated_meshObjectB;
MObject inMesh_attrObjectA;
MObject inMesh_attrObjectB;
/*
MStringArray commandResult;
MSelectionList selList;
MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
selList.add( commandResult[0]);
selList.getDependNode( 0, duplicated_meshObjectA);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_tA");
duplicated_meshObjectA = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_sA");
inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");
meshDagNodeFn.setObject( meshDagPath_first);
selList.clear();
MGlobal::executeCommand( "duplicate " + meshDagNodeFn.name(), commandResult, 1, 1);
selList.add( commandResult[0]);
selList.getDependNode( 0, duplicated_meshObjectB);
meshDagNodeFn.setObject( duplicated_meshObjectB);
meshDagNodeFn.setName( meshName + "_tB");
duplicated_meshObjectB = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectB);
meshDagNodeFn.setName( meshName + "_sB");
inMesh_attrObjectB = meshDagNodeFn.attribute( "inMesh");
*/
duplicated_meshObjectA = meshDagNodeFn.duplicate();
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_tA");
duplicated_meshObjectA = meshDagNodeFn.child(0);
meshDagNodeFn.setObject( duplicated_meshObjectA);
meshDagNodeFn.setName( meshName + "_sA");
inMesh_attrObjectA = meshDagNodeFn.attribute( "inMesh");
meshDagNodeFn.setObject( meshDagPath_first);
//.........这里部分代码省略.........