bool isConnected(const char *attrName, MFnDependencyNode& depFn, bool dest, bool primaryChild = false) { MStatus stat; MPlugArray pa; depFn.getConnections(pa); for (uint pId = 0; pId < pa.length(); pId++) { if (dest) { if (!pa[pId].isDestination()) continue; } else{ if (!pa[pId].isSource()) continue; } MPlug plug = pa[pId]; if (primaryChild) while (plug.isChild()) plug = plug.parent(); if (plug.isElement()) plug = plug.array(); if ((getAttributeNameFromPlug(plug) == attrName)) return true; } return false; }
void ShadingNode::getConnectedInputObjects(MObjectArray& objectArray) { MStatus stat; MFnDependencyNode depFn(this->mobject); MStringArray aliasArray; depFn.getAliasList(aliasArray); MObjectArray objectList; MPlugArray connections; depFn.getConnections(connections); for (uint connId = 0; connId < connections.length(); connId++) { MPlug p = connections[connId]; if (!p.isDestination()) continue; // a connection can be a direct connection or a child connection e.g. colorR, colorG... // but in a shader description file only the main attribute is listed so we go up until we have the main plug MPlug mainPlug = p; while (mainPlug.isChild()) mainPlug = mainPlug.parent(); if (mainPlug.isElement()) mainPlug = mainPlug.array(); MStringArray stringArray; // name contains node.attributeName, so we have to get rid of the nodeName mainPlug.name().split('.', stringArray); MString plugName = stringArray[stringArray.length() - 1]; if (!this->isAttributeValid(plugName)) continue; getConnectedInNodes(p, objectList); makeUniqueArray(objectList); } objectArray = objectList; }
MStatus HesMeshNode::connectionMade(const MPlug &plug, const MPlug &otherPlug, bool asSrc) { if ( plug.isElement() ) { if( plug.array() == outMesh) { } } return MPxNode::connectionMade( plug, otherPlug, asSrc ); }
// ---------------------------------------------------------- int AnimationClip::findPlug ( const MPlug& p ) { uint count = plugs.length(); for ( uint i = 0; i < count; ++i ) { if ( p == plugs[i] ) { if ( !p.isElement() || p.logicalIndex() == plugs[i].logicalIndex() ) { return i; } } } return -1; }
MStatus ParameterisedHolder<B>::setDependentsDirty( const MPlug &plug, MPlugArray &plugArray ) { if( plug==aParameterisedClassName || plug==aParameterisedVersion || plug==aParameterisedSearchPathEnvVar ) { // if the held class changes in any way then we ditch it so we're forced to reload // in getParameterised(). m_parameterised = 0; m_failedToLoad = false; } else { // if the plug represents a parameter then we add that parameter to a list // of dirty parameters. this lets us optimise setParameterisedValues so we only // set the values of parameters whose plugs have changed since last time. // we only bother doing this if we've loaded the class already, as calling plugParameter() // would otherwise cause a premature loading of the class. when we load the class all parameters // are marked as dirty anyway so there's no point worrying about it here. if( m_parameterised ) { MPlug p = plug; ParameterPtr parameter = 0; do { parameter = plugParameter( p ); if( p.isChild() ) { p = p.parent(); } else if( p.isElement() ) { p = p.array(); } else { p = MPlug(); } } while( !parameter && !p.isNull() ); if( parameter ) { m_dirtyParameters.insert( parameter ); } } } return B::setDependentsDirty( plug, plugArray ); }
MStatus nailConstraintNode::compute(const MPlug& plug, MDataBlock& data) { //std::cout << "nailConstraintNode::compute: " << plug.name() << std::endl; //MTime time = data.inputValue( nailConstraintNode::inTime ).asTime(); if(plug == ca_constraint) { computeConstraint(plug, data); } else if(plug == ca_constraintParam) { computeConstraintParam(plug, data); } else if(plug.isElement()) { if(plug.array() == worldMatrix && plug.logicalIndex() == 0) { computeWorldMatrix(plug, data); } else { return MStatus::kUnknownParameter; } } else { return MStatus::kUnknownParameter; } return MStatus::kSuccess; }
bool isConnected(const char *attrName, MFnDependencyNode& depFn, bool dest, bool primaryChild = false) { MStatus stat; MPlugArray pa; depFn.getConnections(pa); std::vector<std::string> stringParts; pystring::split(attrName, stringParts, "."); MString attName = attrName; if (stringParts.size() > 1) attName = stringParts.back().c_str(); if (pystring::endswith(attrName, "]")) { int found = attName.rindex('['); if (found >= 0) attName = attName.substring(0, found-1); } for (uint pId = 0; pId < pa.length(); pId++) { if (dest) { if (!pa[pId].isDestination()) continue; } else { if (!pa[pId].isSource()) continue; } MPlug plug = pa[pId]; if (primaryChild) while (plug.isChild()) plug = plug.parent(); MString plugName = plug.name(); if (plug.isElement()) plug = plug.array(); MString attNameFromPlug = getAttributeNameFromPlug(plug); if ((attNameFromPlug == attName)) return true; } return false; }
int physicalIndex(MPlug& p) { MPlug parent = p; while (parent.isChild()) parent = parent.parent(); if (!parent.isElement()) return -1; if (!parent.array()) return - 1; MPlug arrayPlug = parent.array(); for (uint i = 0; i < arrayPlug.numElements(); i++) if (arrayPlug[i].logicalIndex() == parent.logicalIndex()) return i; return -1; }
MStatus rigidBodyNode::compute(const MPlug& plug, MDataBlock& data) { // std::cout << "rigidBodyNode::compute | plug " << plug.name() << std::endl; //MTime time = data.inputValue( rigidBodyNode::inTime ).asTime(); if(plug == ca_rigidBody) { computeRigidBody(plug, data); } else if(plug == ca_rigidBodyParam) { computeRigidBodyParam(plug, data); } else if(plug == ca_solver) { data.inputValue(ia_solver).asBool(); } else if(plug.isElement()) { if(plug.array() == worldMatrix && plug.logicalIndex() == 0) { computeWorldMatrix(plug, data); } else { return MStatus::kUnknownParameter; } } else { return MStatus::kUnknownParameter; } return MStatus::kSuccess; }
bool ShadingNode::isOutPlugValid(MPlug plug) { MPlug tmpPlug = plug; if (!tmpPlug.isSource()) return false; while (tmpPlug.isChild()) tmpPlug = tmpPlug.parent(); // if we have an array, check the main plug if (tmpPlug.isElement()) tmpPlug = tmpPlug.array(); MString plugName = getAttributeNameFromPlug(tmpPlug); for (size_t attrId = 0; attrId < this->outputAttributes.size(); attrId++) { if (plugName == outputAttributes[attrId].name.c_str()) return true; } return false; }
bool ShadingNode::isInPlugValid(const MPlug& plug) const { MPlug tmpPlug = plug; if (!tmpPlug.isDestination()) return false; while (tmpPlug.isChild()) tmpPlug = tmpPlug.parent(); // if we have an array, check the main plug if (tmpPlug.isElement()) tmpPlug = tmpPlug.array(); const MString& plugName = getAttributeNameFromPlug(tmpPlug); for (size_t inattrId = 0; inattrId < inputAttributes.size(); inattrId++) { if (plugName == inputAttributes[inattrId].name.c_str()) return true; } return false; }
MStatus weightControllerNode::compute( const MPlug& plug, MDataBlock& dataBlock){ MObject thisNode = thisMObject(); MStatus status; if(plug != aOutputs || ! plug.isElement()){ return MS::kSuccess; } float3 &uu = dataBlock.inputValue(aLocator).asFloat3(); Vector3f loc(uu[0],uu[1],uu[2]); MArrayDataHandle hVertices=dataBlock.inputArrayValue(aVertices); int num=hVertices.elementCount(); if(num==0){return MS::kSuccess; } // compute the weight std::vector< Vector3f > v(num); std::vector< float > r(num); for(int i=0;i<num;i++){ float3 &uu=hVertices.inputValue().asFloat3(); Vector3f u(uu[0],uu[1],uu[2]); v[i] = u-loc; r[i] = v[i].norm(); if(i<num-1){ hVertices.next(); } } std::vector<float> w(num, 0.0f), A(num), D(num); for(int i=0;i<num;i++){ int j=(i+1)% num; A[i]=(v[i].cross(v[j])).norm(); D[i]=v[i].dot(v[j]); } bool flag=true; // check if it is on the boundary for(int i=0;i<num;i++){ if(r[i]<EPSILON){ // at a vertex w[i]=1.0; flag=false; break; }else if(abs(A[i])<EPSILON && D[i] < 0){ // on an edge int j=(i+1) % num; w[i]=r[j]; w[j]=r[i]; flag=false; break; } } // if it is not on the boundary if(flag){ for(int i=0;i<num;i++){ int k=(i-1+num)% num; if(fabs(A[k])>EPSILON) w[i]+=(r[k]-D[k]/r[i])/A[k]; if(fabs(A[i])>EPSILON) w[i]+=(r[(i+1)% num]-D[i]/r[i])/A[i]; } } float sum=0.0; for(unsigned int i=0;i<num;i++) sum += w[i]; for(unsigned int i=0;i<num;i++) w[i] /= sum; // writing output MPlug wPlug(thisNode, aOutputs); MDataHandle wHandle = wPlug.constructHandle(dataBlock); MArrayDataHandle arrayHandle(wHandle, &status); CHECK_MSTATUS_AND_RETURN_IT(status); MArrayDataBuilder arrayBuilder = arrayHandle.builder(&status); CHECK_MSTATUS_AND_RETURN_IT(status); for(unsigned int i = 0; i < num; i++) { MDataHandle handle = arrayBuilder.addElement(i,&status); CHECK_MSTATUS_AND_RETURN_IT(status); handle.set(w[i]); } status = arrayHandle.set(arrayBuilder); CHECK_MSTATUS_AND_RETURN_IT(status); wPlug.setValue(wHandle); dataBlock.setClean(plug); return MS::kSuccess; }