Exemplo n.º 1
0
//-----------------------------------------------------------------------------
// 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;
}
Exemplo n.º 2
0
/* 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;
}
Exemplo n.º 3
0
	// 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();
			}
		}
	}
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;
}
Exemplo n.º 5
0
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();

}
Exemplo n.º 6
0
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]);
			}
		}
	}
}
Exemplo n.º 7
0
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;
}
Exemplo n.º 8
0
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;
}
Exemplo n.º 9
0
MStatus CVstAimCmd::redoIt()
{
	MStatus mStatus;

	if ( !mStatus )
	{
		setResult( MString( "Cannot parse command line" ) + mStatus.errorString() );
		return MS::kFailure;
	}

	if ( m_mArgDatabase->isFlagSet( kHelp ) )
	{
		PrintHelp();
	}
	else
	{
		// See if there are two object specified

		MDagPath mDagPath;
		MSelectionList optSelectionList;

		// Validate specified items to whole dag nodes
		{
			MSelectionList tmpSelectionList;
			m_mArgDatabase->getObjects( tmpSelectionList );
			for ( MItSelectionList sIt( tmpSelectionList, MFn::kDagNode ); !sIt.isDone(); sIt.next() )
			{
				if ( sIt.getDagPath( mDagPath ) )
				{
					optSelectionList.add( mDagPath, MObject::kNullObj, true );
				}
			}
		}

		if ( m_mArgDatabase->isFlagSet( "create" ) || optSelectionList.length() >= 2 && m_mArgDatabase->numberOfFlagsUsed() == 0 )
		{
			// Error if there aren't at least two
			if ( optSelectionList.length() < 2 )
			{
				displayError( GetName() + " needs at least two objects specified or selected when -create is used" );
				return MS::kFailure;
			}

			// Get name command line arg
			MString optName;
			if ( m_mArgDatabase->isFlagSet( "name" ) )
			{
				m_mArgDatabase->getFlagArgument( "name", 0, optName );
			}

			m_undoable = true;
			m_mDagModifier = new MDagModifier;

			MObject vstAimObj( m_mDagModifier->MDGModifier::createNode( GetName() ) );
			if ( m_mDagModifier->doIt() != MS::kSuccess )
			{
				displayError( MString( "Couldn't create " ) + GetName() + " node" );
				m_mDagModifier->undoIt();
				delete m_mDagModifier;
				m_mDagModifier = NULL;
				m_undoable = false;

				return MS::kFailure;
			}

			m_mDagModifier->renameNode( vstAimObj, optName.length() ? optName : GetName() );
			if ( m_mDagModifier->doIt() != MS::kSuccess )
			{
				if ( optName.length() )
				{
					displayWarning( MString( "Couldn't rename newly created vstNode \"" ) + optName + "\"" );
				}
			}

			// Set options on the newly create vstAim node

			MFnDependencyNode vstAimFn( vstAimObj );

			MPlug sP;
			MPlug dP;

			if ( m_mArgDatabase->isFlagSet( kAim ) )
			{
				MVector aim;
				m_mArgDatabase->getFlagArgument( kAim, 0, aim.x );
				m_mArgDatabase->getFlagArgument( kAim, 1, aim.y );
				m_mArgDatabase->getFlagArgument( kAim, 2, aim.z );

				sP = vstAimFn.findPlug( "aimX" );
				sP.setValue( aim.x );

				sP = vstAimFn.findPlug( "aimY" );
				sP.setValue( aim.y );

				sP = vstAimFn.findPlug( "aimZ" );
				sP.setValue( aim.z );
			}

			if ( m_mArgDatabase->isFlagSet( kUp ) )
			{
				MVector up;
				m_mArgDatabase->getFlagArgument( kUp, 0, up.x );
				m_mArgDatabase->getFlagArgument( kUp, 1, up.y );
				m_mArgDatabase->getFlagArgument( kUp, 2, up.z );

				sP = vstAimFn.findPlug( "upX" );
				sP.setValue( up.x );

				sP = vstAimFn.findPlug( "upY" );
				sP.setValue( up.y );

				sP = vstAimFn.findPlug( "upZ" );
				sP.setValue( up.z );
			}

			// Now connect up the newly created vstAim node

			MDagPath toAim;
			optSelectionList.getDagPath( 1, toAim );
			const MFnDagNode toAimFn( toAim );

			if ( toAim.hasFn( MFn::kJoint ) )
			{
				MPlug joP( toAimFn.findPlug( "jointOrient" ) );
				if ( !joP.isNull() )
				{
					MAngle jox, joy, joz;
					joP.child( 0 ).getValue( jox );
					joP.child( 1 ).getValue( joy );
					joP.child( 2 ).getValue( joz );
					if ( abs( jox.value() ) > FLT_EPSILON || abs( joy.value() ) > FLT_EPSILON || abs( joz.value() ) > FLT_EPSILON )
					{
						mwarn << "Joint orient on node being constrained is non-zero ( " << jox.asDegrees() << " " << joy.asDegrees() << " " << joz.asDegrees() << " ), setting to 0" << std::endl;
						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 );

			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;
}