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 vixo_visImport::connectionBroken(const MPlug& plug,const MPlug& otherPlug,bool asSrc) { if(plug.array()==this->vis) { mapObjName.erase(plug.logicalIndex()); return MS::kSuccess; } return MPxNode::connectionMade( plug, otherPlug, asSrc ); }
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 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 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 ); }
void getDirectConnectedPlugs(const char *attrName, MFnDependencyNode& depFn, bool dest, MPlugArray& thisNodePlugs, MPlugArray& otherSidePlugs) { MPlug thisPlug = depFn.findPlug(attrName); if (!thisPlug.array()) { 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 (attrName == "colorEntryList") { if (thisPlug.child(0).isConnected()) { MPlug connectedPlug = thisPlug.child(0); thisNodePlugs.append(connectedPlug); otherSidePlugs.append(getDirectConnectedPlug(connectedPlug, dest)); } if (thisPlug.child(1).isConnected()) { MPlug connectedPlug = thisPlug.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)); } } }
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; }
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; }
MStatus vixo_visImport::connectionMade(const MPlug& plug,const MPlug& otherPlug,bool asSrc) { if(plug.array()==this->vis) { //cout<<plug.info().asChar()<<" "<<plug.array().name().asChar()<<" "<<plug.logicalIndex()<<endl; MPlugArray arr; plug.connectedTo(arr,false,true); MFnDagNode dagNodeFn(arr[0].node()); if(dagNodeFn.parentCount()<=0) return MS::kSuccess; //MFnDagNode transformFn(dagNodeFn.parent(0)); MStringArray tempArray; dagNodeFn.name().split(':',tempArray); if(tempArray.length()<2) return MS::kSuccess; //cout<<tempArray[tempArray.length()-1].asChar()<<endl; mapObjName.insert(pair<int,string>(plug.logicalIndex(),tempArray[tempArray.length()-1].asChar())); return MS::kSuccess; } return MPxNode::connectionMade( plug, otherPlug, asSrc ); }
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 HesMeshNode::compute( const MPlug& plug, MDataBlock& data ) { MStatus stat; MPlug pnames(thisMObject(), ameshname); const unsigned numMeshes = pnames.numElements(); MString cacheName = data.inputValue( input ).asString(); std::string substitutedCacheName(cacheName.asChar()); EnvVar::replace(substitutedCacheName); MArrayDataHandle meshNameArray = data.inputArrayValue( ameshname ); MArrayDataHandle meshArry = data.outputArrayValue(outMesh, &stat); bool hesStat = false; if( plug.array() == outMesh ) { const unsigned idx = plug.logicalIndex(); if(BaseUtil::IsImporting) hesStat = true; else { if(idx == 0) AHelper::Info<std::string>(" hes mesh open file ", substitutedCacheName ); hesStat = BaseUtil::OpenHes(substitutedCacheName, HDocument::oReadOnly); } if(!hesStat) { AHelper::Info<std::string >("hes mesh cannot open file ", substitutedCacheName); return MS::kFailure; } meshNameArray.jumpToElement(idx); const MString meshName = meshNameArray.inputValue().asString(); if(!BaseUtil::HesDoc->find(meshName.asChar())) { AHelper::Info<MString>(" hes cannot find mesh ", meshName ); return MS::kFailure; } meshArry.jumpToElement(idx); MDataHandle hmesh = meshArry.outputValue(); HPolygonalMesh entryMesh(meshName.asChar() ); APolygonalMesh dataMesh; entryMesh.load(&dataMesh); entryMesh.close(); MFnMeshData dataCreator; MObject outMeshData = dataCreator.create(&stat); if( !stat ) { MGlobal::displayWarning("hes mesh cannot create " + meshName); return MS::kFailure; } AHelper::Info<MString>(" hes init mesh ", meshName); HesperisPolygonalMeshCreator::create(&dataMesh, outMeshData); hmesh.set(outMeshData); data.setClean(plug); if( (idx+1)>=numMeshes ) { if(!BaseUtil::IsImporting) { AHelper::Info<std::string>(" hes mesh close file ", substitutedCacheName ); BaseUtil::CloseHes(); } } } else { return MS::kUnknownParameter; } return MS::kSuccess; }
MStatus vixo_visImport::compute( const MPlug& plug, MDataBlock& data ) { MStatus stat=MS::kSuccess; if(plug.array()!=vis) return MS::kSuccess; //cout<<plug.info().asChar()<<endl; int objIdx=plug.logicalIndex(); MDataHandle file_handle=data.inputValue(file); MString filename=file_handle.asString(); MDataHandle timeHandle=data.inputValue(time); int t=timeHandle.asTime().as(MTime::Unit::kFilm); if(mapObjName.count(objIdx)<=0) return MS::kSuccess; //cout<<"test"<<endl; MString objNameValue(mapObjName.find(objIdx)->second.c_str()); bool res=true; ifstream fin(filename.asChar(),ios_base::in|ios_base::binary); if(fin.fail()) { MDataHandle eleHandle=data.outputValue(plug); eleHandle.set(res); data.setClean(plug); return MS::kSuccess; } int objNum=0; fin.read((char*)&objNum,sizeof(int)); vector<struct_visBasicInfo> objIndexes(objNum); fin.read((char*)&objIndexes[0],sizeof(struct_visBasicInfo)*objNum); int fileObjIndex=-1; for(int i=0;i<objNum;i++) { MStringArray tempArr; MString tempStr(objIndexes[i].objName); tempStr.split(':',tempArr); if(tempArr[tempArr.length()-1]==objNameValue) { fileObjIndex=i; break; } } if(fileObjIndex==-1) { MDataHandle eleHandle=data.outputValue(plug); eleHandle.set(res); data.setClean(plug); fin.close(); return MS::kSuccess; } //cout<<"test1"<<endl; if(t<objIndexes[fileObjIndex].startFrame||t>objIndexes[fileObjIndex].endFrame) { fin.close(); MDataHandle eleHandle=data.outputValue(plug); eleHandle.set(res); data.setClean(plug); return MS::kSuccess; } //cout<<"test2"<<endl; fin.seekg(objIndexes[fileObjIndex].visBegin.operator+(sizeof(char)*(t-objIndexes[fileObjIndex].startFrame))); char value; fin.read((char *)&value,sizeof(char)); fin.close(); //cout<<t<<" "<<(int)value<<endl; if(value==0) res=0; MDataHandle eleHandle=data.outputValue(plug); eleHandle.set(res); data.setClean(plug); return MS::kSuccess; }