本文整理汇总了C++中MDagModifier::connect方法的典型用法代码示例。如果您正苦于以下问题:C++ MDagModifier::connect方法的具体用法?C++ MDagModifier::connect怎么用?C++ MDagModifier::connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MDagModifier
的用法示例。
在下文中一共展示了MDagModifier::connect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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;
}
示例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: 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();
}
}
}
示例4: 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;
}
示例5: connectNodes
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();
}
示例6: connectionFailedCallback
void atomImport::connectionFailedCallback(MPlug& srcPlug,
MPlug& dstPlug,
const MString& srcName,
const MString& dstName,
void* clientData)
{
// MString output = "Connection failed callback: ";
// output += srcName; output += " "; output += dstName;
// MGlobal::displayInfo(output);
atomEditsHelper* helper = (NULL != clientData) ? (atomEditsHelper*)clientData : NULL;
atomNodeNameReplacer* replacer = (NULL != helper) ? helper->fReplacer : NULL;
atomTemplateReader* templateReader = (NULL != helper) ? helper->fTemplateReader : NULL;
if (NULL != replacer && srcPlug.isNull()) {
// Import of the edits didn't find a match for the source name, use the
// replacer and see if that helps
//
if (replaceNameAndFindPlug(srcName,*replacer,srcPlug)) {
if (!dstPlug.isNull()) {
// we've found the proper source plug to use and we already
// had a dest, so connect them up and we're done
//
MDagModifier mod;
mod.connect(srcPlug,dstPlug);
return;
}
}
}
if (NULL != replacer && dstPlug.isNull()) {
// Import of the edits didn't find a match for the dest name, use the
// replacer and see if that helps
//
if (replaceNameAndFindPlug(dstName,*replacer,dstPlug)) {
MStringArray dstParts;
dstName.split('.', dstParts);
if (!checkPlugAgainstTemplate(dstParts[0],dstPlug,templateReader))
return;
if (!srcPlug.isNull()) {
// we've found the proper dest plug to use and we already
// had a source, so connect them up and we're done
//
MDagModifier mod;
mod.connect(srcPlug,dstPlug);
return;
}
}
}
if (!dstPlug.isNull()) {
MObject dstNode = dstPlug.node();
// Check whether the failed connection was to a setDrivenKey curve
//
if (dstNode.hasFn(MFn::kAnimCurveUnitlessToAngular) ||
dstNode.hasFn(MFn::kAnimCurveUnitlessToDistance) ||
dstNode.hasFn(MFn::kAnimCurveUnitlessToTime) ||
dstNode.hasFn(MFn::kAnimCurveUnitlessToUnitless)) {
// If so, create a stand-in driver for that curve
//
MDagModifier mod;
MObject locator = mod.createNode( "locator", MObject::kNullObj );
MFnDependencyNode fnLoc(locator);
MStringArray nameParts;
srcName.split('.', nameParts);
MString leafAttr(nameParts[nameParts.length()-1]);
MPlug leafPlug = fnLoc.findPlug(leafAttr);
if (!leafPlug.isNull()) {
mod.connect(leafPlug,dstPlug);
// rename the locator to the name of the original source
// so that any subsequent connections will work
//
fnLoc.setName(nameParts[0]);
}
}
}
}
示例7: attachSelected
MStatus HesperisCmd::attachSelected(const Vector3F & offsetV)
{
MGlobal::displayInfo(MString(" attach to grow mesh ") + m_growMeshName);
MSelectionList selList;
MGlobal::getActiveSelectionList(selList);
MItSelectionList iter( selList );
MDagPath apath;
iter.getDagPath( apath );
MObject otrans = apath.node();
if(!otrans.hasFn(MFn::kTransform)) {
MGlobal::displayWarning("must select a transform/group to attach to grow mesh");
return MS::kFailure;
}
ASearchHelper searcher;
MDagPath meshGrp;
if(!searcher.dagByFullName(m_growMeshName.asChar(), meshGrp)) {
MGlobal::displayWarning(MString("cannot find grow mesh by name ")+m_growMeshName);
return MS::kFailure;
}
MObject ogrow = meshGrp.node();
if(!ogrow.hasFn(MFn::kTransform)) {
MGlobal::displayWarning("-gm must be a transform/group");
return MS::kFailure;
}
MStatus stat;
MDGModifier modif;
MDagModifier dmodif;
MObject hestranslate = modif.createNode("hesperisTranslateNode", &stat);
modif.doIt();
if(hestranslate.isNull()) {
MGlobal::displayWarning("cannot create hes translate node");
return MS::kFailure;
}
MFnDependencyNode fhest(hestranslate);
MFnDependencyNode fgrow(ogrow);
modif.connect(fgrow.findPlug("boundingBoxMinX", true), fhest.findPlug("bBoxMinX", true));
modif.connect(fgrow.findPlug("boundingBoxMinY", true), fhest.findPlug("bBoxMinY", true));
modif.connect(fgrow.findPlug("boundingBoxMinZ", true), fhest.findPlug("bBoxMinZ", true));
modif.connect(fgrow.findPlug("boundingBoxMaxX", true), fhest.findPlug("bBoxMaxX", true));
modif.connect(fgrow.findPlug("boundingBoxMaxY", true), fhest.findPlug("bBoxMaxY", true));
modif.connect(fgrow.findPlug("boundingBoxMaxZ", true), fhest.findPlug("bBoxMaxZ", true));
MPlug psrcwpmat = fgrow.findPlug("parentMatrix", true, &stat);
if(!stat) MGlobal::displayInfo("cannot find plug worldParentMatrix");
modif.connect(psrcwpmat, fhest.findPlug("inParentMatrix", true));
modif.doIt();
MFnDependencyNode ftrans(otrans);
dmodif.connect(fhest.findPlug("outTranslateX", true), ftrans.findPlug("translateX", true));
dmodif.connect(fhest.findPlug("outTranslateY", true), ftrans.findPlug("translateY", true));
dmodif.connect(fhest.findPlug("outTranslateZ", true), ftrans.findPlug("translateZ", true));
stat = dmodif.doIt();
if(!stat) MGlobal::displayInfo(MString("cannot make some connections to ")+ftrans.name());
fhest.findPlug("offsetX").setValue((double)-offsetV.x);
fhest.findPlug("offsetY").setValue((double)-offsetV.y);
fhest.findPlug("offsetZ").setValue((double)-offsetV.z);
return MS::kSuccess;
}
示例8: 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;
}
示例9: redoIt
//.........这里部分代码省略.........
joP.child( 0 ).setValue( MAngle( 0.0 ) );
joP.child( 1 ).setValue( MAngle( 0.0 ) );
joP.child( 2 ).setValue( MAngle( 0.0 ) );
}
}
}
if ( toAim.hasFn( MFn::kTransform ) )
{
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 );