本文整理汇总了C++中MDagModifier类的典型用法代码示例。如果您正苦于以下问题:C++ MDagModifier类的具体用法?C++ MDagModifier怎么用?C++ MDagModifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了MDagModifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TF_VERIFY
/* static */
bool
PxrUsdMayaTranslatorUtil::CreateNode(
const MString& nodeName,
const MString& nodeTypeName,
MObject& parentNode,
MStatus* status,
MObject* mayaNodeObj)
{
// XXX:
// Using MFnDagNode::create() results in nodes that are not properly
// registered with parent scene assemblies. For now, just massaging the
// transform code accordingly so that child scene assemblies properly post
// their edits to their parents-- if this is indeed the best pattern for
// this, all Maya*Reader node creation needs to be adjusted accordingly (for
// much less trivial cases like MFnMesh).
MDagModifier dagMod;
*mayaNodeObj = dagMod.createNode(nodeTypeName, parentNode, status);
CHECK_MSTATUS_AND_RETURN(*status, false);
*status = dagMod.renameNode(*mayaNodeObj, nodeName);
CHECK_MSTATUS_AND_RETURN(*status, false);
*status = dagMod.doIt();
CHECK_MSTATUS_AND_RETURN(*status, false);
return TF_VERIFY(not mayaNodeObj->isNull());
}
示例2: fnLoc
/* override */
MStatus
offset::accessoryNodeSetup(MDagModifier& cmd)
//
// Description:
// This method is called when the deformer is created by the
// "deformer" command. You can add to the cmds in the MDagModifier
// cmd in order to hook up any additional nodes that your node needs
// to operate.
//
// In this example, we create a locator and attach its matrix attribute
// to the matrix input on the offset node. The locator is used to
// set the direction and scale of the random field.
//
// Description:
// This method is optional.
//
{
MStatus result;
// hook up the accessory node
//
MObject objLoc = cmd.createNode(MString("locator"),
MObject::kNullObj,
&result);
if (MS::kSuccess == result) {
MFnDependencyNode fnLoc(objLoc);
MString attrName;
attrName.set("matrix");
MObject attrMat = fnLoc.attribute(attrName);
result = cmd.connect(objLoc,attrMat,this->thisMObject(),offset::offsetMatrix);
}
return result;
}
示例3: MyCheckStatusReturn
MStatus lrutils::makeHomeNull(MObject obj, MFnTransform& transformFn, MObject& groupObj) {
MStatus status = MS::kFailure;
status = transformFn.setObject(obj);
MyCheckStatusReturn(status, "invalid MObject provided for MFnTransform.setObject()");
if( status == MS::kSuccess ) {
MDagModifier dagMod;
groupObj = dagMod.createNode( "transform", MObject::kNullObj, &status );
MyCheckStatusReturn(status, "MDagModifier.createNode() failed");
dagMod.doIt();
MFnTransform groupFn;
groupFn.setObject(groupObj);
groupFn.set(transformFn.transformation());
groupFn.addChild(obj);
MString groupName = transformFn.name();
groupName = groupName.substring(0, groupName.numChars() - 4);
groupName += "GRP";
groupFn.setName(groupName);
}
return status;
}
示例4: MyCheckStatus
MObject lrutils::createJointFromLocation(MVectorArray location, MString prefix, unsigned int num, MObject parent) {
MStatus status = MS::kFailure;
MObject jointObj;
//make joint object
MDagModifier dagMod;
jointObj = dagMod.createNode( "joint", MObject::kNullObj, &status );
MyCheckStatus(status, "MDagModifier.createNode() failed");
dagMod.doIt();
//set position
lrutils::setLocation(jointObj, location, MFnTransform::MFnTransform(), true, false, false);
//set name
MString jointName = prefix + "_Skel" + boost::lexical_cast<string>(num).c_str() + "_JNT";
dagMod.renameNode(jointObj, jointName);
dagMod.doIt();
MFnTransform jointFn(jointObj);
//parent the joint to its parent, if not null
if(parent != MObject::kNullObj) {
MFnTransform parentFn(parent);
MGlobal::executeCommand("parent " + jointFn.fullPathName() + " " + parentFn.fullPathName() + ";");
}
return jointObj;
}
示例5: doIt
MStatus DDConvexHullCmd::doIt(const MArgList& args)
{
if (args.length() != 1)
{
MGlobal::displayError("Needs at least 2 args");
return MS::kFailure;
}
MString input = args.asString(0);
MString output = args.asString(1);
// Get the mObject for the input
MSelectionList selList;
selList.add(input);
MDagPath inputMesh;
selList.getDagPath(0, inputMesh);
// Ensure we're looking at the shape
inputMesh.extendToShape();
// Create output object
MDagModifier dm;
MObject outMeshNode = dm.createNode(MFn::kMesh);
MFnDependencyNode outMeshDag(outMeshNode);
outMeshDag.setName("poopShape#");
DDConvexHullUtils::hullOpts hullOptions;
return DDConvexHullUtils::generateMayaHull(outMeshNode,
inputMesh.node(), hullOptions);
}
示例6: AddColorSetToMesh
//-----------------------------------------------------------------------------
// Adds a color set to the input history of the passed mesh
//-----------------------------------------------------------------------------
MObject ValveMaya::AddColorSetToMesh(
const MString &colorSetName,
const MDagPath &mDagPath,
MDagModifier &mDagModifier )
{
if ( !mDagPath.hasFn( MFn::kMesh ) )
return MObject::kNullObj;
MFnMesh meshFn( mDagPath );
MString uniqueColorSetName;
{
MStringArray colorSetNames;
meshFn.getColorSetNames( colorSetNames );
const uint nColorSets( colorSetNames.length() );
for ( int i( 0 ); uniqueColorSetName.length() == 0; ++i )
{
uniqueColorSetName = colorSetName;
if ( i > 0 )
{
uniqueColorSetName += i;
}
for ( uint j( 0U ); j != nColorSets; ++j )
{
if ( uniqueColorSetName == colorSetNames[ j ] )
{
uniqueColorSetName.clear();
break;
}
}
}
}
// Create a 'createColorSet' node
MObject ccsObj( mDagModifier.MDGModifier::createNode( "createColorSet" ) );
mDagModifier.doIt();
const MFnDependencyNode ccsFn( ccsObj );
MPlug csnP( ccsFn.findPlug( "colorSetName" ) );
csnP.setValue( uniqueColorSetName );
// Insert it in the history of the mesh
MPlug inMeshP( meshFn.findPlug( "inMesh" ) );
MPlugArray mPlugArray;
if ( inMeshP.connectedTo( mPlugArray, true, false ) && mPlugArray.length() )
{
mDagModifier.disconnect( mPlugArray[ 0 ], inMeshP );
mDagModifier.connect( mPlugArray[ 0 ], ccsFn.findPlug( "inputGeometry" ) );
}
mDagModifier.connect( ccsFn.findPlug( "outputGeometry" ), inMeshP );
mDagModifier.doIt();
return ccsObj;
}
示例7: cameraFn
/* static */
bool
UsdMayaTranslatorCamera::Read(
const UsdGeomCamera& usdCamera,
MObject parentNode,
const UsdMayaPrimReaderArgs& args,
UsdMayaPrimReaderContext* context)
{
if (!usdCamera) {
return false;
}
const UsdPrim& prim = usdCamera.GetPrim();
const SdfPath primPath = prim.GetPath();
MStatus status;
// Create the transform node for the camera.
MObject transformObj;
if (!UsdMayaTranslatorUtil::CreateTransformNode(prim,
parentNode,
args,
context,
&status,
&transformObj)) {
return false;
}
// Create the camera shape node.
MDagModifier dagMod;
MObject cameraObj = dagMod.createNode(_tokens->MayaCameraTypeName.GetText(),
transformObj,
&status);
CHECK_MSTATUS_AND_RETURN(status, false);
status = dagMod.doIt();
CHECK_MSTATUS_AND_RETURN(status, false);
TF_VERIFY(!cameraObj.isNull());
MFnCamera cameraFn(cameraObj, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
const std::string cameraShapeName = prim.GetName().GetString() +
_tokens->MayaCameraShapeNameSuffix.GetString();
cameraFn.setName(cameraShapeName.c_str(), &status);
CHECK_MSTATUS_AND_RETURN(status, false);
if (context) {
const SdfPath shapePrimPath = primPath.AppendChild(TfToken(cameraShapeName));
context->RegisterNewMayaNode(shapePrimPath.GetString(), cameraObj);
}
return _ReadToCamera(usdCamera, cameraFn, args, context);
}
示例8: accessoryNodeSetup
MStatus SwirlDeformer::accessoryNodeSetup( MDagModifier &dagMod )
{
MStatus stat;
MObject locObj = dagMod.createNode( "locator", MObject::kNullObj, &stat );
if( !stat )
return stat;
dagMod.renameNode( locObj, "swirlHandle" );
MFnDependencyNode locFn( locObj );
MObject attrMat = locFn.attribute( "matrix" );
stat = dagMod.connect( locObj, attrMat, thisMObject(), deformSpace );
return stat;
}
示例9: breakConnections
// Break connections to this blendshape
void BlendShape::breakConnections()
{
MStatus stat;
MDagModifier dagModifier;
// Clear the stored connections
m_weightConnections.clear();
// Save node connections and break them
MPlug weightsPlug = m_pBlendShapeFn->findPlug("weight",true);
for (int i=0; i<weightsPlug.evaluateNumElements(); i++)
{
MPlug wPlug = weightsPlug.elementByPhysicalIndex(i);
MPlugArray srcConnections;
MPlugArray dstConnections;
wPlug.connectedTo(srcConnections,false,true);
wPlug.connectedTo(dstConnections,true,false);
weightConnections wcon;
for (int j=0; j<srcConnections.length(); j++)
{
wcon.srcConnections.append(srcConnections[j]);
dagModifier.disconnect(wPlug,srcConnections[j]);
dagModifier.doIt();
}
for (int j=0; j<dstConnections.length(); j++)
{
wcon.dstConnections.append(dstConnections[j]);
stat = dagModifier.disconnect(dstConnections[j],wPlug);
if (MS::kSuccess != stat)
{
std::cout << "Error trying to disconnect plug " << wPlug.name().asChar() << " and plug " << dstConnections[j].name().asChar() << "\n";
std::cout << stat.errorString().asChar() << "\n";
std::cout.flush();
}
stat = dagModifier.doIt();
if (MS::kSuccess != stat)
{
std::cout << "Error trying to disconnect plug " << wPlug.name().asChar() << " and plug " << dstConnections[j].name().asChar() << "\n";
std::cout << stat.errorString().asChar() << "\n";
std::cout.flush();
}
}
m_weightConnections.push_back(wcon);
}
}
示例10: fn
void MVGMesh::setIsActive(const bool isActive) const
{
MStatus status;
// Check is flag exists
MFnMesh fn(_dagpath);
MPlug mvgPlug = fn.findPlug(_MVG, false, &status);
if(!status && !isActive)
return;
if(!status && isActive)
{
// Create MayaMVG attribute
MDagModifier dagModifier;
MFnNumericAttribute nAttr;
MObject mvgAttr = nAttr.create(_MVG, "mvg", MFnNumericData::kBoolean);
status = dagModifier.addAttribute(_object, mvgAttr);
CHECK(status)
dagModifier.doIt();
mvgPlug = fn.findPlug(_MVG, false, &status);
}
status = mvgPlug.setValue(isActive);
CHECK(status)
if(isActive)
{
status = MGlobal::executePythonCommand("from mayaMVG import scale");
CHECK(status)
MString cmd;
// Retrieve transform node
cmd.format("scale.getParent(\"^1s\")", _dagpath.fullPathName());
MString transform;
status = MGlobal::executePythonCommand(cmd, transform);
// Freeze transform mesh
cmd.format("makeIdentity -apply true \"^1s\"", transform);
status = MGlobal::executeCommand(cmd);
CHECK(status)
// Lock node
cmd.format("scale.lockNode(\"^1s\", True)", transform);
status = MGlobal::executePythonCommand(cmd);
CHECK(status)
}
else
{
示例11: reportError
void MeshGitCmd::connectNodes(MString nodeName, MString locatorName){
MGlobal::displayInfo("Connecting " + nodeName + " and " + locatorName);
MStatus status;
//Get Node Object
MSelectionList nodeList;
status = nodeList.add(nodeName);
MObject nodeObject;
status = nodeList.getDependNode(0, nodeObject);
reportError(status);
//Get Viz Object
MSelectionList vizList;
status = vizList.add(locatorName);
MObject vizObject;
status = vizList.getDependNode(0, vizObject);
reportError(status);
//Create Node Fn
MeshGitFn mgFn;
status = mgFn.setObject(nodeObject);
reportError(status);
//Create viz fn
MFnDependencyNode vizFn(vizObject, &status);
//Get the node plug
MPlug nodePlug = mgFn.findPlug("message", true, &status);
reportError(status);
//Get the viz plug
MPlug vizPlug = vizFn.findPlug(MeshGitLocatorNode::meshGitNodeConnection, true,
&status);
//Connect the plugs
MDagModifier modifier;
status = modifier.connect(nodePlug,vizPlug);
reportError(status);
status = modifier.doIt();
}
示例12: restoreConnections
// Restore connections on this blendshape
void BlendShape::restoreConnections()
{
MDagModifier dagModifier;
// Recreate stored connections on the weight attributes
MPlug weightsPlug = m_pBlendShapeFn->findPlug("weight",true);
for (int i=0; i<weightsPlug.evaluateNumElements(); i++)
{
MPlug wPlug = weightsPlug.elementByPhysicalIndex(i);
weightConnections& wcon = m_weightConnections[i];
for (int j=0; j<wcon.srcConnections.length(); j++)
{
dagModifier.connect(wPlug,wcon.srcConnections[j]);
dagModifier.doIt();
}
for (int j=0; j<wcon.dstConnections.length(); j++)
{
dagModifier.connect(wcon.dstConnections[j],wPlug);
dagModifier.doIt();
}
}
}
示例13: getAssembly
//------------------------------------------------------------------------------
//
bool CacheRepresentation::activate()
{
AssemblyDefinition* const assembly =
dynamic_cast< AssemblyDefinition* >( getAssembly() );
if ( assembly == 0 ) {
return false;
}
// Create a gpuCache node, and parent it to our container.
MDagModifier dagMod;
MStatus status;
MObject cacheObj = dagMod.createNode(
MString("gpuCache"), assembly->thisMObject(), &status);
if (status != MStatus::kSuccess) {
int isLoaded = false;
// Validate that the gpuCache plugin is loaded.
MGlobal::executeCommand( "pluginInfo -query -loaded gpuCache", isLoaded );
if(!isLoaded){
MString errorString = MStringResource::getString(rCreateGPUCacheNodeError, status);
MGlobal::displayError(errorString);
}
return false;
}
status = dagMod.doIt();
if (status != MStatus::kSuccess) {
return false;
}
// Set the cache attribute to point to our Alembic file.
MFnDependencyNode cache(cacheObj);
MPlug fileName = cache.findPlug(MString("cacheFileName"), true, &status);
if (status != MStatus::kSuccess) {
return false;
}
fileName.setValue(assembly->getRepData(getName()));
return status == MStatus::kSuccess;
}
示例14: DoCreate
//-----------------------------------------------------------------------------
// Creates a vstAttachment Locator
//-----------------------------------------------------------------------------
MStatus CVstAttachmentCmd::DoCreate()
{
MDagModifier *mDagModifier( new MDagModifier );
if ( !mDagModifier )
{
merr << "Can't create new MDagModifier" << std::endl;
return MS::kFailure;
}
MString optName( "vstAttachment" );
if ( m_mArgDatabase->isFlagSet( kOptName ) )
{
m_mArgDatabase->getFlagArgument( kOptName, 0, optName );
}
// Create the helper bone locator's transform
MObject xObj = mDagModifier->createNode( "transform" );
mDagModifier->doIt();
if ( xObj.isNull() )
{
merr << "Can't create new transform node" << std::endl;
return MS::kFailure;
}
// name the shape & the transform the same thing
mDagModifier->renameNode( xObj, optName );
mDagModifier->doIt();
MObject vstAttachmentObj = mDagModifier->createNode( "vstAttachment", xObj );
if ( vstAttachmentObj.isNull() )
{
merr << "Can't create new vstAttachment node" << std::endl;
mDagModifier->undoIt();
return MS::kFailure;
}
// name the shape & the transform the same thing
mDagModifier->renameNode( vstAttachmentObj, MFnDependencyNode( xObj ).name() );
mDagModifier->doIt();
m_undoable = true;
m_mDagModifier = mDagModifier;
if ( m_mArgDatabase->isFlagSet( kOptParent ) )
{
MSelectionList mSelectionList;
m_mArgDatabase->getObjects( mSelectionList );
for ( MItSelectionList sIt( mSelectionList, MFn::kDagNode ); !sIt.isDone(); sIt.next() )
{
MDagPath mDagPath;
if ( sIt.getDagPath( mDagPath ) )
{
m_mDagModifier->reparentNode( xObj, mDagPath.node() );
m_mDagModifier->doIt();
break;
}
}
}
// Save the current selection just in case we want to undo stuff
MGlobal::getActiveSelectionList( m_mSelectionList );
MDagPath xDagPath;
MDagPath::getAPathTo( xObj, xDagPath );
MGlobal::select( xDagPath, MObject::kNullObj, MGlobal::kReplaceList );
setResult( xDagPath.partialPathName() );
return MS::kSuccess;
}
示例15: shapeNodeFn
MStatus CmpMeshModifierCmd::transferTweaks( const MDagPath &shapePath,
MObject &tweakNode,
MDagModifier &dagMod )
{
// Get the tweaks from the mesh shape and apply them to the
// to the tweak node
MFnDagNode shapeNodeFn( shapePath );
MPlug srcTweaksPlug = shapeNodeFn.findPlug( "pnts" );
MFnDependencyNode tweakNodeFn( tweakNode );
MPlug dstTweaksPlug = tweakNodeFn.findPlug( "tweak" );
//MGlobal::displayInfo( MString( "storing tweaks from " ) + shapePath.fullPathName() + "\n" );
MPlugArray plugs;
MPlug srcTweakPlug;
MPlug dstTweakPlug;
MObject dataObj;
MFloatVector tweak;
unsigned int nTweaks = srcTweaksPlug.numElements();
unsigned int i, j, ci, logicalIndex;
for( i=0; i < nTweaks; i++ )
{
srcTweakPlug = srcTweaksPlug.elementByPhysicalIndex( i );
if( !srcTweakPlug.isNull() )
{
logicalIndex = srcTweakPlug.logicalIndex();
// Set tweak node tweak element
srcTweakPlug.getValue( dataObj );
MFnNumericData numDataFn( dataObj );
numDataFn.getData( tweak[0], tweak[1], tweak[2] );
dagMod.commandToExecute( MString( "setAttr " ) + tweakNodeFn.name() + ".tweak[" + logicalIndex + "] " +
tweak[0] + " " + tweak[1] + " " + tweak[2] );
// Handle transfer of incoming and outgoing connections to "pnts" elements
dstTweakPlug = dstTweaksPlug.elementByLogicalIndex(logicalIndex);
if( srcTweakPlug.isConnected() )
{
// As source, transfer source to tweak node tweak
srcTweakPlug.connectedTo( plugs, false, true );
for( j=0; j < plugs.length(); j++ )
{
dagMod.disconnect( srcTweakPlug, plugs[j] );
dagMod.connect( dstTweakPlug, plugs[j] );
}
// As destination, transfer destination to tweak node tweak
srcTweakPlug.connectedTo( plugs, true, false );
if( plugs.length() == 1 ) // There can only be one input connection
{
dagMod.disconnect( plugs[0], srcTweakPlug );
dagMod.connect( plugs[0], dstTweakPlug );
}
}
else // Check children
{
MPlug srcTweakChildPlug;
MPlug dstTweakChildPlug;
for( ci=0; ci < srcTweakPlug.numChildren(); ci++ )
{
srcTweakChildPlug = srcTweakPlug.child(ci);
dstTweakChildPlug = dstTweakPlug.child(ci);
if( srcTweakChildPlug.isConnected() )
{
// As souce, transfer source to tweak node tweak
srcTweakChildPlug.connectedTo( plugs, false, true );
for( j=0; j < plugs.length(); j++ )
{
dagMod.disconnect( srcTweakChildPlug, plugs[j] );
dagMod.connect( dstTweakChildPlug, plugs[j] );
}
// As destination, transfer destination to tweak node tweak
srcTweakChildPlug.connectedTo( plugs, true, false );
if( plugs.length() == 1 ) // There can only be one input connection
{
dagMod.disconnect( plugs[0], srcTweakChildPlug );
dagMod.connect( plugs[0], dstTweakChildPlug );
}
}
}
}
// With the tweak values and any connections now transferred to
// the tweak node's tweak element, this source element can be reset
dagMod.commandToExecute( MString( "setAttr " ) + shapePath.fullPathName() + ".pnts[" + logicalIndex + "] 0 0 0" );
//MGlobal::displayInfo( MString(" tweak: ") + tweakIndices[i] + ": " + tweaks[i].x + ", " + tweaks[i].y + ", " + tweaks[i].z + "\n" );
}
}
return MS::kSuccess;
}