void getConnectedChildPlugs(const MPlug& plug, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs) { if (plug.numConnectedChildren() == 0) return; for (uint chId = 0; chId < plug.numChildren(); chId++) if (plug.child(chId).isConnected()) { if ((plug.child(chId).isDestination() && dest) || (plug.child(chId).isSource() && !dest)) { thisNodePlugs.append(plug.child(chId)); otherSidePlugs.append(getDirectConnectedPlug(plug, dest)); } } }
MStatus AlembicCurvesDeformNode::setDependentsDirty(const MPlug &plugBeingDirtied, MPlugArray &affectedPlugs) { if (plugBeingDirtied == mFileNameAttr || plugBeingDirtied == mIdentifierAttr || plugBeingDirtied == mTimeAttr) { for (unsigned int i = 0; i < mGeomParamPlugs.length(); i++) { affectedPlugs.append(mGeomParamPlugs[i]); } for (unsigned int i = 0; i < mUserAttrPlugs.length(); i++) { affectedPlugs.append(mUserAttrPlugs[i]); } } return MStatus::kSuccess; }
bool getConnectedInPlugs(MObject& thisObject, MPlugArray& inPlugs, MPlugArray& otherSidePlugs) { MStatus stat; bool result = false; MFnDependencyNode depFn(thisObject, &stat); if (stat != MStatus::kSuccess) return result; MPlugArray pa; depFn.getConnections(pa); for (uint i = 0; i < pa.length(); i++) if (pa[i].isDestination()) inPlugs.append(pa[i]); for (uint i = 0; i < inPlugs.length(); i++) { MPlug p = inPlugs[i]; p.connectedTo(pa, true, false); otherSidePlugs.append(pa[0]); } return true; }
//get the attribute plugs for a specific layer void atomAnimLayers::collectAnimLayerPlugs(MFnDependencyNode &layer, MStringArray &attributes, MPlugArray &plugs) { MStatus status = MS::kSuccess; for(unsigned int i = 0; i < attributes.length(); ++i) { MPlug plug = layer.findPlug(attributes[i],false, &status); if(status== MS::kSuccess) { plugs.append(plug); } } }
bool getConnectedOutPlugs(MObject& thisObject, MPlugArray& outPlugs) { MStatus stat; bool result = false; MFnDependencyNode depFn(thisObject, &stat); if( stat != MStatus::kSuccess) return result; MPlugArray pa; depFn.getConnections(pa); for( uint i = 0; i < pa.length(); i++) if( pa[i].isSource() ) outPlugs.append(pa[i]); return true; }
void getDirectConnectedPlugs(const char *attrName, MFnDependencyNode& depFn, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs) { MPlug thisPlug = depFn.findPlug(attrName); if (!thisPlug.isArray()) { if (thisPlug.isConnected()) { thisNodePlugs.append(thisPlug); otherSidePlugs.append(getDirectConnectedPlug(thisPlug, dest)); } return; } for (uint i = 0; i < thisPlug.numElements(); i++) { if (thisPlug.isCompound()) { // we only support simple compounds like colorListEntry if (MString(attrName) == MString("colorEntryList")) { MPlug element = thisPlug[i]; if (element.child(0).isConnected()) { MPlug connectedPlug = element.child(0); thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } if (element.child(1).isConnected()) { MPlug connectedPlug = element.child(1); thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } } } else{ if (!thisPlug[i].isConnected()) { continue; } MPlug connectedPlug = thisPlug[i]; thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } } }
void findConnectedNodeTypes(uint nodeId, MObject thisObject, MObjectArray& connectedElements, MPlugArray& completeList, bool upstream) { MGlobal::displayInfo(MString("thisNode: ") + getObjectName(thisObject)); MString name = getObjectName(thisObject); MFnDependencyNode depFn(thisObject); if(depFn.typeId().id() == nodeId) { connectedElements.append(thisObject); MGlobal::displayInfo(MString("found object with correct id: ") + depFn.name()); return; } bool downstream = !upstream; MPlugArray plugArray; depFn.getConnections(plugArray); int numc = plugArray.length(); for( uint plugId = 0; plugId < plugArray.length(); plugId++) { MPlug plug = plugArray[plugId]; if( isPlugInList(plug, completeList)) continue; completeList.append(plug); MString pn = plug.name(); if( upstream && plug.isDestination()) continue; if( downstream && plug.isSource()) continue; MPlugArray otherSidePlugs; bool asDest = plug.isDestination(); bool asSrc = plug.isSource(); MGlobal::displayInfo(MString("findConnectedNodeTypes: checking plug ") + plug.name()); plug.connectedTo(otherSidePlugs, asDest, asSrc); for( uint cplugId = 0; cplugId < otherSidePlugs.length(); cplugId++) { findConnectedNodeTypes(nodeId, otherSidePlugs[cplugId].node(), connectedElements, completeList, upstream); } } }
MStatus vixo_visImport::setDependentsDirty( const MPlug &plugBeingDirtied,MPlugArray &affectedPlugs ) { MStatus status; MObject thisNode = thisMObject(); if ( plugBeingDirtied.partialName() == "t" || plugBeingDirtied.partialName() == "f") { MPlug arrayVis(thisNode,this->vis); //affectedPlugs.append(arrayVis); //cout<<"idr"<<arrayVis.numElements()<<endl; for(int i=0;i<arrayVis.numElements();i++) { affectedPlugs.append(arrayVis.elementByLogicalIndex(i)); } } return( MS::kSuccess ); }
MStatus OpHolder<B>::setDependentsDirty( const MPlug &plug, MPlugArray &plugArray ) { /// This isn't the best way of doing it, but at this point we can't even be sure that the Op has been loaded, /// so calling plugParameter() may not work. We can't call getOp() or getParameterised() here, as it seems /// we can't do things such as adding/removing attributes within this function if( std::string( plug.partialName().substring( 0, 4 ).asChar() ) == ParameterisedHolder<B>::g_attributeNamePrefix || plug==aResultDependency ) { MFnDependencyNode fnDN( B::thisMObject() ); MStatus s; MPlug resultPlug = fnDN.findPlug( "result" , &s); if ( s && !resultPlug.isNull() ) { plugArray.append( resultPlug ); } } return ParameterisedHolder<B>::setDependentsDirty( plug, plugArray ); }
//setDependentsDirty //----------------------------------------------- MStatus Ocio_test::setDependentsDirty(const MPlug& plugBeingDirtied, MPlugArray& affectedPlugs) { MStatus status; MObject node = thisMObject(); MFnDependencyNode fn_dep_node(node); if(plugBeingDirtied.partialName() == "input_colorspace") { MPlug p_output = fn_dep_node.findPlug( "output_color", &status ); if(MStatus::kSuccess == status) { CHECK_MSTATUS(affectedPlugs.append(p_output)); MGlobal::displayInfo("Plug output appended"); } } return MStatus::kSuccess; };
// The setDependentsDirty() method allows attributeAffects relationships // in a much more general way than via MPxNode::attributeAffects // which is limited to static attributes only. // The setDependentsDirty() method allows relationships to be established // between any combination of dynamic and static attributes. // // Within a setDependentsDirty() implementation you get passed in the // plug which is being set dirty, and then, based upon which plug it is, // you may choose to dirty any other plugs by adding them to the // affectedPlugs list. // // In almost all cases, the relationships you set up will be fixed for // the duration of Maya, such as "A affects B". However, you can also // set up relationships which depend upon some external factor, such // as the current frame number, the time of day, if maya was invoked in // batch mode, etc. These sorts of relationships are straightforward to // implement in your setDependentsDirty() method. // // There may also be situations where you need to look at values in the // dependency graph. It is VERY IMPORTANT that when accessing DG values // you do not cause a DG evaluation. This is because your setDependentsDirty() // method is called during dirty processing and causing an evalutaion could // put Maya into an infinite loop. The only safe way to look at values // on plugs is via the MDataBlock::outputValue() which does not trigger // an evaluation. It is recommeneded that you only look at plugs whose // values are constant or you know have already been computed. // // For this example routine, we will only implement the simplest case // of a relationship. // MStatus affects::setDependentsDirty( const MPlug &plugBeingDirtied, MPlugArray &affectedPlugs ) { MStatus status; MObject thisNode = thisMObject(); MFnDependencyNode fnThisNode( thisNode ); if ( plugBeingDirtied.partialName() == "A" ) { // "A" is dirty, so mark "B" dirty if "B" exists. // This implements the relationship "A affects B". // fprintf(stderr,"affects::setDependentsDirty, \"A\" being dirtied\n"); MPlug pB = fnThisNode.findPlug( "B", &status ); if ( MStatus::kSuccess == status ) { fprintf(stderr,"\t\t... dirtying \"B\"\n"); CHECK_MSTATUS( affectedPlugs.append( pB ) ); } } return( MS::kSuccess ); }
// -------------------------------------------------------------------------------------------- MStatus polyModifierCmd::processTweaks( modifyPolyData& data ) // -------------------------------------------------------------------------------------------- { MStatus status = MS::kSuccess; // Clear tweak undo information (to be rebuilt) // fTweakIndexArray.clear(); fTweakVectorArray.clear(); // Extract the tweaks and place them into a polyTweak node. This polyTweak node // will be placed ahead of the modifier node to maintain the order of operations. // Special care must be taken into recreating the tweaks: // // 1) Copy tweak info (including connections!) // 2) Remove tweak info from both meshNode and a duplicate meshNode (if applicable) // 3) Cache tweak info for undo operations // //if( fHasTweaks && fHasHistory && !speedupTweakProcessing()) if( fHasTweaks && fHasHistory ) { // Declare our function sets // MFnDependencyNode depNodeFn; // Declare our attributes and plugs // MPlug meshTweakPlug; MPlug upstreamTweakPlug; MObject tweakNodeTweakAttr; // Declare our tweak processing variables // MPlug tweak; MPlug tweakChild; MObject tweakData; MObjectArray tweakDataArray; MFloatVector tweakVector; MIntArray tweakSrcConnectionCountArray; MPlugArray tweakSrcConnectionPlugArray; MIntArray tweakDstConnectionCountArray; MPlugArray tweakDstConnectionPlugArray; MPlugArray tempPlugArray; unsigned i; unsigned j; unsigned k; // Create the tweak node and get its attributes // data.tweakNode = fDGModifier.MDGModifier::createNode( "polyTweak" ); depNodeFn.setObject( data.tweakNode ); data.tweakNodeSrcAttr = depNodeFn.attribute( "output" ); data.tweakNodeDestAttr = depNodeFn.attribute( "inputPolymesh" ); tweakNodeTweakAttr = depNodeFn.attribute( "tweak" ); depNodeFn.setObject( data.meshNodeShape ); meshTweakPlug = depNodeFn.findPlug( "pnts" ); // ASSERT: meshTweakPlug should be an array plug! // MStatusAssert( (meshTweakPlug.isArray()), "meshTweakPlug.isArray() -- meshTweakPlug is not an array plug" ); unsigned numElements = meshTweakPlug.numElements(); // Gather meshTweakPlug data // for( i = 0; i < numElements; i++ ) { // MPlug::numElements() only returns the number of physical elements // in the array plug. Thus we must use elementByPhysical index when using // the index i. // tweak = meshTweakPlug.elementByPhysicalIndex(i); // If the method fails, the element is NULL. Only append the index // if it is a valid plug. // if( !tweak.isNull() ) { // Cache the logical index of this element plug // unsigned logicalIndex = tweak.logicalIndex(); // Collect tweak data and cache the indices and float vectors // tweak.getValue( tweakData ); tweakDataArray.append( tweakData ); getFloat3PlugValue( tweak, tweakVector ); fTweakIndexArray.append( logicalIndex ); fTweakVectorArray.append( tweakVector ); // Collect tweak connection data // // Parse down to the deepest level of the plug tree and check // for connections - look at the child nodes of the element plugs. // If any connections are found, record the connection and disconnect // it. // // ASSERT: The element plug should be compound! // MStatusAssert( (tweak.isCompound()), "tweak.isCompound() -- Element tweak plug is not compound" ); unsigned numChildren = tweak.numChildren(); for( j = 0; j < numChildren; j++ ) { tweakChild = tweak.child(j); if( tweakChild.isConnected() ) { // Get all connections with this plug as source, if they exist // tempPlugArray.clear(); if( tweakChild.connectedTo( tempPlugArray, false, true ) ) { unsigned numSrcConnections = tempPlugArray.length(); tweakSrcConnectionCountArray.append( numSrcConnections ); for( k = 0; k < numSrcConnections; k++ ) { tweakSrcConnectionPlugArray.append( tempPlugArray[k] ); fDGModifier.disconnect( tweakChild, tempPlugArray[k] ); } } else { tweakSrcConnectionCountArray.append(0); } // Get the connection with this plug as destination, if it exists // tempPlugArray.clear(); if( tweakChild.connectedTo( tempPlugArray, true, false ) ) { // ASSERT: tweakChild should only have one connection as destination! // MStatusAssert( (tempPlugArray.length() == 1), "tempPlugArray.length() == 1 -- 0 or >1 connections on tweakChild" ); tweakDstConnectionCountArray.append(1); tweakDstConnectionPlugArray.append( tempPlugArray[0] ); fDGModifier.disconnect( tempPlugArray[0], tweakChild ); } else { tweakDstConnectionCountArray.append(0); } } else { tweakSrcConnectionCountArray.append(0); tweakDstConnectionCountArray.append(0); } } } } // Apply meshTweakPlug data to our polyTweak node // MPlug polyTweakPlug( data.tweakNode, tweakNodeTweakAttr ); unsigned numTweaks = fTweakIndexArray.length(); int srcOffset = 0; int dstOffset = 0; //Progress initialisieren progressBar progress("Processing Tweaks", numTweaks); for( i = 0; i < numTweaks; i++ ) { // Apply tweak data // tweak = polyTweakPlug.elementByLogicalIndex( fTweakIndexArray[i] ); tweak.setValue( tweakDataArray[i] ); // ASSERT: Element plug should be compound! // MStatusAssert( (tweak.isCompound()), "tweak.isCompound() -- Element plug, 'tweak', is not compound" ); unsigned numChildren = tweak.numChildren(); for( j = 0; j < numChildren; j++ ) { tweakChild = tweak.child(j); // Apply tweak source connection data // if( 0 < tweakSrcConnectionCountArray[i*numChildren + j] ) { for( k = 0; k < (unsigned) tweakSrcConnectionCountArray[i*numChildren + j]; k++ ) { fDGModifier.connect( tweakChild, tweakSrcConnectionPlugArray[srcOffset] ); srcOffset++; } } // Apply tweak destination connection data // if( 0 < tweakDstConnectionCountArray[i*numChildren + j] ) { fDGModifier.connect( tweakDstConnectionPlugArray[dstOffset], tweakChild ); dstOffset++; } } if(i%50 == 0) { progress.set(i); } } // Now, set the tweak values on the meshNode(s) to zero (History dependent) // MFnNumericData numDataFn; MObject nullVector; // Create a NULL vector (0,0,0) using MFnNumericData to pass into the plug // numDataFn.create( MFnNumericData::k3Float ); numDataFn.setData( 0, 0, 0 ); nullVector = numDataFn.object(); for( i = 0; i < numTweaks; i++ ) { // Access using logical indices since they are the only plugs guaranteed // to hold tweak data. // tweak = meshTweakPlug.elementByLogicalIndex( fTweakIndexArray[i] ); tweak.setValue( nullVector ); } // Only have to clear the tweaks off the duplicate mesh if we do not have history // and we want history. // if( !fHasHistory && fHasRecordHistory ) { depNodeFn.setObject( data.upstreamNodeShape ); upstreamTweakPlug = depNodeFn.findPlug( "pnts" ); if( !upstreamTweakPlug.isNull() ) { for( i = 0; i < numTweaks; i++ ) { tweak = meshTweakPlug.elementByLogicalIndex( fTweakIndexArray[i] ); tweak.setValue( nullVector ); } } } } else fHasTweaks = false; return status; }
MStatus sgBDataCmd_key::setObjectKeyDataDefault( sgObject_keyData& objectKeyData, const MDagPath& dagPathTarget, bool bMatrixType ) { MStatus status; objectKeyData.oTargetNode = dagPathTarget.node(); objectKeyData.numAttr = 0; objectKeyData.namesAttribute.clear(); objectKeyData.lengthTime = 0; objectKeyData.dArrTime.clear(); objectKeyData.dArrValuesArray.clear(); MFnDagNode fnDagNode = dagPathTarget; MPlugArray plugArrTransform; MPlugArray plugArrVis; plugArrTransform.append( fnDagNode.findPlug( "tx" ) ); plugArrTransform.append( fnDagNode.findPlug( "ty" ) ); plugArrTransform.append( fnDagNode.findPlug( "tz" ) ); plugArrTransform.append( fnDagNode.findPlug( "rx" ) ); plugArrTransform.append( fnDagNode.findPlug( "ry" ) ); plugArrTransform.append( fnDagNode.findPlug( "rz" ) ); plugArrTransform.append( fnDagNode.findPlug( "sx" ) ); plugArrTransform.append( fnDagNode.findPlug( "sy" ) ); plugArrTransform.append( fnDagNode.findPlug( "sz" ) ); plugArrVis.append( fnDagNode.findPlug( "v" ) ); if( bMatrixType ) { if( plugsHasConnection( plugArrVis ) ) { objectKeyData.numAttr++; objectKeyData.namesAttribute.append( "visibility" ); } if( plugsHasConnection( plugArrTransform ) ) { objectKeyData.numAttr += 9; objectKeyData.namesAttribute.append( "translateX" ); objectKeyData.namesAttribute.append( "translateY" ); objectKeyData.namesAttribute.append( "translateZ" ); objectKeyData.namesAttribute.append( "rotateX" ); objectKeyData.namesAttribute.append( "rotateY" ); objectKeyData.namesAttribute.append( "rotateZ" ); objectKeyData.namesAttribute.append( "scaleX" ); objectKeyData.namesAttribute.append( "scaleY" ); objectKeyData.namesAttribute.append( "scaleZ" ); } } else { MPlugArray plugArr; for( unsigned int j=0; j< plugArrTransform.length(); j++ ) { MPlug& plug = plugArrTransform[j]; plug.connectedTo( plugArr, true, false ); if( !plugArr.length() ) { MPlug plugParent = plug.parent( &status ); if( !status ) continue; plugParent.connectedTo( plugArr, true, false ); if( !plugArr.length() ) continue; } objectKeyData.numAttr++; objectKeyData.namesAttribute.append( MFnAttribute( plug.attribute() ).name() ); } plugArrVis[0].connectedTo( plugArr, true, false ); if( plugArr.length() ) { objectKeyData.numAttr++; objectKeyData.namesAttribute.append( MFnAttribute( plugArrVis[0].attribute() ).name() ); } } objectKeyData.dArrValuesArray.clear(); return MS::kSuccess; }