void DoFilename() { MString filename; MCommandResult result; MGlobal::executeCommand("fileDialog -m 1", result); result.getResult(filename); cout << "filename is: " << filename.asChar() << endl; }
IECore::DataPtr convert( const MCommandResult &result ) { MStatus s; switch (result.resultType()) { case MCommandResult::kInvalid: { // No result return 0; } case MCommandResult::kInt: { int i; s = result.getResult(i); assert(s); IECore::IntDataPtr data = new IECore::IntData(); data->writable() = i; return data; } case MCommandResult::kIntArray: { MIntArray v; s = result.getResult(v); assert(s); unsigned sz = v.length(); IECore::IntVectorDataPtr data = new IECore::IntVectorData(); data->writable().resize(sz); for (unsigned i = 0; i < sz; i++) { (data->writable())[i] = v[i]; } return data; } case MCommandResult::kDouble: { double d; s = result.getResult(d); assert(s); IECore::FloatDataPtr data = new IECore::FloatData(); data->writable() = static_cast<float>(d); return data; } case MCommandResult::kDoubleArray: { MDoubleArray v; s = result.getResult(v); assert(s); unsigned sz = v.length(); IECore::DoubleVectorDataPtr data = new IECore::DoubleVectorData(); data->writable().resize(sz); for (unsigned i = 0; i < sz; i++) { data->writable()[i] = v[i]; } return data; } case MCommandResult::kString: { MString str; s = result.getResult(str); assert(s); IECore::StringDataPtr data = new IECore::StringData(); data->writable() = std::string(str.asChar()); return data; } case MCommandResult::kStringArray: { MStringArray v; s = result.getResult(v); assert(s); unsigned sz = v.length(); IECore::StringVectorDataPtr data = new IECore::StringVectorData(); data->writable().resize(sz); for (unsigned i = 0; i < sz; i++) { data->writable()[i] = std::string(v[i].asChar()); } return data; } case MCommandResult::kVector: { MVector v; s = result.getResult(v); assert(s); IECore::V3fDataPtr data = new IECore::V3fData(); data->writable() = Imath::V3f(v.x, v.y, v.z); return data; } case MCommandResult::kVectorArray: { MVectorArray v; s = result.getResult(v); assert(s); unsigned sz = v.length(); IECore::V3fVectorDataPtr data = new IECore::V3fVectorData(); data->writable().resize(sz); for (unsigned i = 0; i < sz; i++) { data->writable()[i] = Imath::V3f(v[i].x, v[i].y, v[i].z); } return data; } case MCommandResult::kMatrix: { MDoubleArray v; int numRows, numColumns; s = result.getResult(v, numRows, numColumns); assert(s); if (numRows > 4 || numColumns > 4) { throw IECoreMaya::StatusException( MS::kFailure ); } IECore::M44fDataPtr data = new IECore::M44fData(); for (int i = 0; i < numColumns; i++) { for (int j = 0; j < numRows; j++) { (data->writable())[i][j] = v[i*numRows+j]; } } return data; } case MCommandResult::kMatrixArray: { return 0; } default: assert( false ); return 0; } }
MObject GlobalComponent::loadComponent(MDGModifier & dgMod) { MStatus status = MS::kFailure; this->m_metaDataNode = dgMod.createNode( "MDGlobalNode", &status ); MyCheckStatus(status, "createNode failed"); MString metaNodeName = "MGN_"; metaNodeName += this->m_rigName + "_"; metaNodeName += this->m_pCompGuide->getName(); dgMod.renameNode(this->m_metaDataNode, metaNodeName); MFnDependencyNode depMetaDataNodeFn(this->m_metaDataNode); status = dgMod.newPlugValueFloat( depMetaDataNodeFn.findPlug("version"), this->m_pCompGuide->getVersion() ); MyCheckStatus(status, "newPlugValueFloat() failed"); status = dgMod.newPlugValueString( depMetaDataNodeFn.findPlug("rigId"), this->m_pCompGuide->getRigId() ); MyCheckStatus(status, "newPlugValueInt() failed"); GlobalComponentGuidePtr globalGuide = boost::dynamic_pointer_cast<GlobalComponentGuide>(this->m_pCompGuide); MString ctlColor = globalGuide->getColor(); MString ctlIcon = globalGuide->getIcon(); status = MGlobal::executeCommand( "python(\"control = rig101().rig101WCGetByName('" + ctlIcon + "')\");" ); status = MGlobal::executeCommand( "python(\"Utils.setControllerColor(control, '" + ctlColor + "')\");" ); MCommandResult res; status = MGlobal::executeCommand( MString("python(\"control.fullPath()\");"), res ); int resType = res.resultType(); if( resType == MCommandResult::kString ) { MString sResult; res.getResult(sResult); MObject ctlObj; status = lrutils::getObjFromName(sResult, ctlObj); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MVectorArray ctlLocation = this->m_pCompGuide->getLocation(0); MFnTransform transformFn( ctlObj ); lrutils::setLocation(ctlObj, ctlLocation, MFnTransform::MFnTransform(), false, false, true); MString ctlName = this->m_rigName + "_" + this->m_pCompGuide->getName() + "_CTL"; dgMod.renameNode(ctlObj, ctlName); dgMod.doIt(); //add the metaParent attribute to the controller MFnMessageAttribute mAttr; MObject transformAttr = mAttr.create("metaParent", "metaParent"); transformFn.addAttribute(transformAttr); //connect the controller's metaParent to the MDGlobal node status = dgMod.connect( depMetaDataNodeFn.findPlug("controller"), transformFn.findPlug("metaParent") ); MObject ctlGroupObj; lrutils::makeHomeNull(ctlObj, MFnTransform(), ctlGroupObj); lrutils::setLocation(ctlGroupObj, ctlLocation, MFnTransform::MFnTransform(), true, true, false); MFnTransform ctlGroupFn( ctlGroupObj ); //add the metaParent attribute to the controller group ctlGroupFn.addAttribute(mAttr.create("metaParent", "metaParent")); //connect the controller group's metaParent to the MDGlobal node status = dgMod.connect( depMetaDataNodeFn.findPlug("controllerGroup"), ctlGroupFn.findPlug("metaParent") ); MyCheckStatus(status, "connect failed"); MObject metaRootObj; status = lrutils::getMetaRootByName(metaRootObj, this->m_rigName); MyCheckStatus(status, "lrutils::getMetaRootByName() failed"); MObject rigCtlGroupObj; status = lrutils::getMetaNodeConnection(metaRootObj, rigCtlGroupObj, "ctlGroup"); MyCheckStatus(status, "lrutils::getMetaNodeConnection() failed"); MFnTransform rigCtlGroupFn( rigCtlGroupObj ); rigCtlGroupFn.addChild( ctlGroupObj ); //add controller to controller display layer MObject controlLayerObj; status = lrutils::getMetaNodeConnection(metaRootObj, controlLayerObj, "ctlLayer"); MyCheckStatus(status, "lrutils::getMetaNodeConnection() failed"); MFnDependencyNode controlLayerFn(controlLayerObj); MString controlLayerName = controlLayerFn.name(); MGlobal::executeCommand("editDisplayLayerMembers -noRecurse "+controlLayerName+" "+rigCtlGroupFn.name()+";"); //create parent constraints from the global controller to the rig group MObject rigRigGroupObj; status = lrutils::getMetaNodeConnection(metaRootObj, rigRigGroupObj, "rigGroup"); MFnTransform rigRigGroupFn( rigRigGroupObj ); MGlobal::executeCommand("parentConstraint -mo "+transformFn.name()+" "+rigRigGroupFn.name()+";", res); //connect the parent constraint object to the component's metadata node MStringArray sResults; res.getResult(sResults); status = lrutils::getObjFromName(sResults[0], this->m_rigParentConstraint); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MFnTransform rigParentConstraintFn( this->m_rigParentConstraint); rigParentConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent")); status = dgMod.connect( depMetaDataNodeFn.findPlug("rigParentConstraint"), rigParentConstraintFn.findPlug("metaParent")); //create the scale constraint from the global controller to the rig group MGlobal::executeCommand("scaleConstraint -mo "+transformFn.name()+" "+rigRigGroupFn.name()+";", res); //connect the scale constraint object to the component's metadata node res.getResult(sResults); status = lrutils::getObjFromName(sResults[0], this->m_rigScaleConstraint); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MFnTransform rigScaleConstraintFn( this->m_rigScaleConstraint ); rigScaleConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent")); status = dgMod.connect( depMetaDataNodeFn.findPlug("rigScaleConstraint"), rigScaleConstraintFn.findPlug("metaParent")); //create scale constraint from the global controller to the noTransform group MObject rigNoTransformGroupObj; status = lrutils::getMetaNodeConnection(metaRootObj, rigNoTransformGroupObj, "noTransformGroup"); MFnTransform rigNoTransformGroupFn( rigNoTransformGroupObj ); MGlobal::executeCommand("scaleConstraint -mo "+transformFn.name()+" "+rigNoTransformGroupFn.name()+";", res); //connect the scale constraint object to the component's metadata node res.getResult(sResults); status = lrutils::getObjFromName(sResults[0], this->m_noTransformScaleConstraint); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MFnTransform noTransformScaleConstraintFn( this->m_noTransformScaleConstraint); noTransformScaleConstraintFn.addAttribute(mAttr.create("metaParent", "metaParent")); status = dgMod.connect( depMetaDataNodeFn.findPlug("noTransformScaleConstraint"), noTransformScaleConstraintFn.findPlug("metaParent")); } return this->m_metaDataNode; }
void GlobalComponent::updateComponent(MDGModifier & dgMod,bool forceUpdate, bool globalPos) { MStatus status; if( !this->m_metaDataNode.isNull() ) { //get the rig name MFnDependencyNode metaDataNodeFn( m_metaDataNode ); MString metaNodeName = metaDataNodeFn.name(); MStringArray nameArray; metaNodeName.split('_', nameArray); MString rigName = nameArray[1]; //get the controller name MString controllerName = nameArray[2]; MString compXmlName = this->m_pCompGuide->getName(); //update names of component objects if( rigName != this->m_rigName || controllerName != compXmlName ) { //set the metadata node name lrutils::stringReplaceAll(metaNodeName, rigName, this->m_rigName); lrutils::stringReplaceAll(metaNodeName, controllerName, this->m_pCompGuide->getName()); metaDataNodeFn.setName(metaNodeName); //set controller object name MObject globalCtlObj; lrutils::getMetaNodeConnection(this->m_metaDataNode, globalCtlObj, "controller"); MFnDependencyNode globalCtlFn( globalCtlObj ); MString globalCtlName = globalCtlFn.name(); lrutils::stringReplaceAll(globalCtlName, rigName, this->m_rigName); lrutils::stringReplaceAll(globalCtlName, controllerName, this->m_pCompGuide->getName()); globalCtlFn.setName(globalCtlName); //set controller group object name MObject globalCtlGroupObj; lrutils::getMetaNodeConnection(this->m_metaDataNode, globalCtlGroupObj, "controllerGroup"); MFnDependencyNode globalCtlGroupFn( globalCtlGroupObj ); MString globalCtlGroupName = globalCtlGroupFn.name(); lrutils::stringReplaceAll(globalCtlGroupName, rigName, this->m_rigName); lrutils::stringReplaceAll(globalCtlGroupName, controllerName, this->m_pCompGuide->getName()); globalCtlGroupFn.setName(globalCtlGroupName); //set rigParentConstraint object name MObject rigParentConstraintObj; lrutils::getMetaNodeConnection(this->m_metaDataNode, rigParentConstraintObj, "rigParentConstraint"); MFnDependencyNode rigParentConstraintFn( rigParentConstraintObj ); MString rigParentConstraintName = rigParentConstraintFn.name(); lrutils::stringReplaceAll(rigParentConstraintName, rigName, this->m_rigName); lrutils::stringReplaceAll(rigParentConstraintName, controllerName, this->m_pCompGuide->getName()); rigParentConstraintFn.setName(rigParentConstraintName); //set rigScaleConstraint object name MObject rigScaleConstraintObj; lrutils::getMetaNodeConnection(this->m_metaDataNode, rigScaleConstraintObj, "rigScaleConstraint"); MFnDependencyNode rigScaleConstraintFn( rigScaleConstraintObj ); MString rigScaleConstraintName = rigScaleConstraintFn.name(); lrutils::stringReplaceAll(rigScaleConstraintName, rigName, this->m_rigName); lrutils::stringReplaceAll(rigScaleConstraintName, controllerName, this->m_pCompGuide->getName()); rigScaleConstraintFn.setName(rigScaleConstraintName); //set noTransformScaleConstraint object name MObject noTransformScaleConstraintObj; lrutils::getMetaNodeConnection(this->m_metaDataNode, noTransformScaleConstraintObj, "noTransformScaleConstraint"); MFnDependencyNode noTransformScaleConstraintFn( noTransformScaleConstraintObj ); MString noTransformScaleConstraintName = noTransformScaleConstraintFn.name(); lrutils::stringReplaceAll(noTransformScaleConstraintName, rigName, this->m_rigName); lrutils::stringReplaceAll(noTransformScaleConstraintName, controllerName, this->m_pCompGuide->getName()); noTransformScaleConstraintFn.setName(noTransformScaleConstraintName); } //update component settings, if the version increment is raised //or force update is true MPlug versionPlug = metaDataNodeFn.findPlug( "version" ); float nodeVersion; versionPlug.getValue(nodeVersion); if( (this->m_pCompGuide->getVersion() > nodeVersion) || forceUpdate ) { versionPlug.setValue( this->m_pCompGuide->getVersion() ); //make a new controller object based upon the xml settings GlobalComponentGuidePtr globalGuide = boost::dynamic_pointer_cast<GlobalComponentGuide>(this->m_pCompGuide); MString ctlColor = globalGuide->getColor(); MString ctlIcon = globalGuide->getIcon(); MGlobal::executeCommand( "python(\"control = rig101().rig101WCGetByName('" + ctlIcon + "')\");" ); MGlobal::executeCommand( "python(\"Utils.setControllerColor(control, '" + ctlColor + "')\");" ); MCommandResult res; MGlobal::executeCommand( MString("python(\"control.fullPath()\");"), res ); MString sResult; res.getResult(sResult); MObject ctlObj; MStatus status = lrutils::getObjFromName(sResult, ctlObj); MyCheckStatus(status, "lrutils::getObjFromName() failed"); //apply the scale of the controller location to the new shape MVectorArray ctlLocation = this->m_pCompGuide->getLocation(0); MFnTransform ctlFn( ctlObj ); lrutils::setLocation(ctlObj, ctlLocation, MFnTransform::MFnTransform(), false, false, true); //get the global transforms of the controller for all keyframes and save them for later use MObject oldCtlObj; status = lrutils::getMetaNodeConnection( this->m_metaDataNode, oldCtlObj, "controller" ); MyCheckStatus(status, "getMetaNodeConnection() failed"); MFnTransform oldCtlFn( oldCtlObj ); std::map<double, MMatrix> oldCtlWorldMatrices; if(globalPos) { status = lrutils::getAllWorldTransforms(oldCtlObj, oldCtlWorldMatrices); MyCheckStatus(status, "lrutils::getAllWorldTransforms() failed"); } //get the shape node of the original controller object MStringArray sResults; MGlobal::executeCommand( "listRelatives -s -fullPath "+oldCtlFn.name()+";", sResults ); MString oldCtlShapePath = sResults[0]; MGlobal::executeCommand( "listRelatives -s -path "+oldCtlFn.name()+";", sResults ); MString oldCtlShapeName = sResults[0]; MObject oldCtlShapeObj; lrutils::getObjFromName(oldCtlShapePath, oldCtlShapeObj); //delete the old shape node MGlobal::deleteNode( oldCtlShapeObj ); //get the new shape node MGlobal::executeCommand( "listRelatives -s -fullPath "+ctlFn.name()+";", sResults ); MString ctlShapePath = sResults[0]; MObject ctlShapeObj; lrutils::getObjFromName(ctlShapePath, ctlShapeObj); //instance the new shape node under the old controller node MString command = "parent -s -add " + ctlShapePath + " " + oldCtlFn.name() + ";"; MGlobal::executeCommand( command ); MFnDependencyNode ctlShapeFn( ctlShapeObj ); ctlShapeFn.setName( oldCtlShapeName ); //set the old controller group translation to the new location MObject oldCtlGroupObj; lrutils::getMetaNodeConnection( this->m_metaDataNode, oldCtlGroupObj, "controllerGroup" ); MFnTransform oldCtlGroupFn( oldCtlGroupObj ); //save the original old controller position MTransformationMatrix oldXForm = oldCtlGroupFn.transformation(); lrutils::setLocation(oldCtlGroupObj, ctlLocation, oldCtlGroupFn, true, true, false); //compute the inverse transformation matrix of the old control group MTransformationMatrix oldCtlGrpXform = oldCtlGroupFn.transformation(); MTransformationMatrix inverseXform = MTransformationMatrix(oldCtlGrpXform.asMatrixInverse()); //set the target offset for the rigParentConstraint node lrutils::getMetaNodeConnection(this->m_metaDataNode, this->m_rigParentConstraint, "rigParentConstraint"); lrutils::setParentConstraintOffset( this->m_rigParentConstraint, inverseXform ); //delete the new controller transform MGlobal::deleteNode( ctlObj ); //find the global transformation matrix of the controller group MDagPath groupPath; status = oldCtlGroupFn.getPath(groupPath); MyCheckStatus(status, "MFnDagNode.getPath() failed"); MMatrix oldCtlGroupWorldMatrix = groupPath.inclusiveMatrix(&status); MyCheckStatus(status, "MDagPath.inclusiveMatrix() failed"); if(globalPos) { //update the animation curves attached to the old controller lrutils::updateAnimCurves(oldCtlObj, oldCtlWorldMatrices, oldCtlGroupWorldMatrix); } } } }
MStatus puttyNode::deform( MDataBlock& block, MItGeometry& iter, const MMatrix& worldMatrix, unsigned int multiIndex) { // MGlobal::displayInfo("deform"); MStatus status = MS::kSuccess; ///////////////////////////////////////////////////////////////////////////////////////////////// // // get inputs // // get the node ready flag MDataHandle dh = block.inputValue(aScriptSourced,&status); SYS_ERROR_CHECK(status, "Error getting aScriptSourced data handle\n"); bool scriptSourced = dh.asBool(); if (!scriptSourced) return MS::kSuccess; dh = block.inputValue(aNodeReady,&status); SYS_ERROR_CHECK(status, "Error getting node ready data handle\n"); bool nodeReady = dh.asBool(); // if it's not ready, don't do anything if (!nodeReady) return MS::kSuccess; dh = block.inputValue(aDefSpace,&status); SYS_ERROR_CHECK(status, "Error getting defSpace data handle\n"); short defSpace = dh.asShort(); dh = block.inputValue(aDefWeights,&status); SYS_ERROR_CHECK(status, "Error getting defWeights data handle\n"); short defWeights = dh.asShort(); dh = block.inputValue(aDefEnvelope,&status); SYS_ERROR_CHECK(status, "Error getting defEnvelope data handle\n"); short defEnvelope = dh.asShort(); // get the command dh = block.inputValue(aCmdBaseName,&status); SYS_ERROR_CHECK(status, "Error getting aCmdBaseName handle\n"); MString script = dh.asString(); /* if (script == "") { status = MS::kFailure; USER_ERROR_CHECK(status, "no script provided!\n"); } */ ///////////////////////////////////////////////////////////////////////////////////////////////// // // build mel cmd string // // check if it's a valid cmd // get the envelope // double env = 1; if (defEnvelope == MSD_ENVELOPE_AUTO) { dh = block.inputValue(envelope,&status); SYS_ERROR_CHECK(status, "Error getting envelope data handle\n"); env = double(dh.asFloat()); // early stop 'cause there is nothing more to do if (env == 0.0) return MS::kSuccess; } // get the points, transform them into the right space if needed // int count = iter.count(); MVectorArray points(count); for ( ; !iter.isDone(); iter.next()) points[iter.index()] = iter.position(); if ( defSpace == MSD_SPACE_WORLD ) { for (int i = 0;i<count;i++) points[i] = MPoint(points[i]) * worldMatrix; } // get the weights // MDoubleArray weights; if ( defWeights == MSD_WEIGHTS_AUTO) { weights.setLength(count); for (int i = 0;i<count;i++) weights[i] = weightValue(block,multiIndex,i); } // get the object name and type // get the input geometry, traverse through the data handles MArrayDataHandle adh = block.outputArrayValue( input, &status ); SYS_ERROR_CHECK(status,"error getting input array data handle.\n"); status = adh.jumpToElement( multiIndex ); SYS_ERROR_CHECK(status, "input jumpToElement failed.\n"); // compound data MDataHandle cdh = adh.inputValue( &status ); SYS_ERROR_CHECK(status, "error getting input inputValue\n"); // input geometry child dh = cdh.child( inputGeom ); MObject dInputGeometry = dh.data(); // get the type MString geometryType = dInputGeometry.apiTypeStr(); // get the name // MFnDagNode dagFn( dInputGeometry, &status); // SYS_ERROR_CHECK(status, "error converting geometry obj to dag node\n"); // MString geometryName = dagFn.fullPathName(&status); // SYS_ERROR_CHECK(status, "error getting full path name \n"); // MString geometryType = ""; // MString geometryName = ""; ///////////////////////////////////////////////////////////////////////////////////////////////// // // set the current values on the temp plugs for the script to be picked up // // the position MObject thisNode = thisMObject(); MPlug currPlug(thisNode,aCurrPosition); MFnVectorArrayData vecD; MObject currObj = vecD.create(points,&status); currPlug.setValue(currObj); SYS_ERROR_CHECK(status, "error setting currPosPlug value\n"); // the weights currPlug =MPlug(thisNode,aCurrWeight); MFnDoubleArrayData dblD; currObj = dblD.create(weights,&status); currPlug.setValue(currObj); SYS_ERROR_CHECK(status, "error setting currWeightsPlug value\n"); // world matrix currPlug =MPlug(thisNode,aCurrWorldMatrix); MFnMatrixData matD; currObj = matD.create(worldMatrix,&status); currPlug.setValue(currObj); SYS_ERROR_CHECK(status, "error setting currWorldMatrixPlug value\n"); // the multi index currPlug =MPlug(thisNode,aCurrMultiIndex); currPlug.setValue(int(multiIndex)); SYS_ERROR_CHECK(status, "error setting currMultiIndexPlug value\n"); // geometry name/type // currPlug =MPlug(thisNode,aCurrGeometryName); // currPlug.setValue(geometryName); // SYS_ERROR_CHECK(status, "error setting aCurrGeometryName value\n"); currPlug =MPlug(thisNode,aCurrGeometryType); currPlug.setValue(geometryType); SYS_ERROR_CHECK(status, "error setting aCurrGeometryType value\n"); ///////////////////////////////////////////////////////////////////////////////////////////////// // // execute the mel script // MString melCmd = script+"(\"" +name()+"\","+count+")"; MCommandResult melResult; status = MGlobal::executeCommand(melCmd,melResult); // if the command did not work, then try to resource the script // (might have been that we were in a fresh scene and nothing was ready yet if (status != MS::kSuccess) { dh = block.inputValue(aScript,&status); SYS_ERROR_CHECK(status, "Error getting aCmdBaseName handle\n"); MString scriptFile = dh.asString(); // try to source the script MString cmd = "source \"" + scriptFile+"\""; MCommandResult melResult; status = MGlobal::executeCommand(cmd,melResult); // if successfull, retry the command if (!status.error()) { status = MGlobal::executeCommand(melCmd,melResult); } } USER_ERROR_CHECK(status, "Error executing mel command, please check the function you provided is valid, error free and has the appropriate parameters!"); // check the result type if ((melResult.resultType()) != (MCommandResult::kDoubleArray)) { USER_ERROR_CHECK(MS::kFailure, "result of mel command has wrong type, should be doubleArray (which will be interpreted as vectorArray)!"); } // get the result as a double array MDoubleArray newP; status = melResult.getResult(newP); USER_ERROR_CHECK(status, "Error getting result of mel command!"); int newCount = newP.length()/3; // size check if (newCount != count) { USER_ERROR_CHECK(MS::kFailure, "the size of the result does not match the size of the input!"); } // convert the double array into a vector array MPointArray newPoints(newCount); for(int i=0;i<newCount;i++) newPoints[i]=MPoint(newP[i*3],newP[i*3+1],newP[i*3+2]); ///////////////////////////////////////////////////////////////////////////////////////////////// // // interprete and apply the result // // do the envelope and weights if ((defEnvelope == MSD_ENVELOPE_AUTO)||((defWeights == MSD_WEIGHTS_AUTO))) { MDoubleArray envPP(count, env); if (defWeights == MSD_WEIGHTS_AUTO) { for (int i = 0;i<count;i++) envPP[i] *= weights[i]; } // linear interpolation between old and new points for (int i = 0;i<count;i++) newPoints[i] = (points[i] * (1-envPP[i])) + (newPoints[i] * envPP[i]); } // retransform the result if it was in world space if ( defSpace == MSD_SPACE_WORLD ) { MMatrix worldMatrixInv = worldMatrix.inverse(); for (int i = 0;i<count;i++) newPoints[i] *= worldMatrixInv; } // set the points iter.reset(); for ( ; !iter.isDone(); iter.next()) iter.setPosition(newPoints[iter.index()]); return status; }
MStatus puttyNode::compute( const MPlug& plug, MDataBlock& block ) { MStatus status; if ( plug == aNodeReady ) { // MGlobal::displayInfo("compute"); bool result =false; MString cmdBaseName; // get the source flag MDataHandle dh = block.inputValue(aSource,&status); SYS_ERROR_CHECK(status, "Error getting source data handle\n"); bool source = dh.asBool(); // get the command dh = block.inputValue(aScript,&status); SYS_ERROR_CHECK(status, "Error getting reload script handle\n"); MString script = dh.asString(); if (script == "") { MGlobal::displayError("no script provided!\n"); } else { // chech if script is sourced dh = block.inputValue(aScriptSourced,&status); SYS_ERROR_CHECK(status, "Error getting aScriptSourced data handle\n"); bool scriptSourced = dh.asBool(); // if it's not ready, don't do anything if (!scriptSourced) return MS::kSuccess; else { MCommandResult melResult; // now get the real name of the function and store it in a separate attribute MString cmd="basenameEx \"" + script+"\""; status = MGlobal::executeCommand(cmd,melResult); melResult.getResult(cmdBaseName); result = true; MDataHandle dhCBN = block.outputValue(aCmdBaseName,&status); SYS_ERROR_CHECK(status, "Error getting aCmdBaseName data handle\n"); dhCBN.set(cmdBaseName); dhCBN.setClean(); // see if an interface function is present, if yes, execute it cmd= "if(exists(\"" + cmdBaseName +".interface\")) {"; cmd+= "string $attr[] = `deleteAttr -q " +name()+"`; string $a;"; cmd+="for($a in $attr) deleteAttr (\""+name()+".\"+$a);"; cmd+= cmdBaseName +".interface(\"" +name()+"\");}"; status = MGlobal::executeCommand(cmd); } } // check the current status // set the result MDataHandle dhNodeReady = block.outputValue(aNodeReady,&status); SYS_ERROR_CHECK(status, "Error getting reload data handle\n"); dhNodeReady.set(result); dhNodeReady.setClean(); return MS::kSuccess; } else if (plug==aScriptSourced) { // this part of the function sources the script // try to source the script // cerr << "\nsource"; MStatus status; bool result = true; // get the source flag MDataHandle dh = block.inputValue(aSource,&status); SYS_ERROR_CHECK(status, "Error getting source data handle\n"); bool source = dh.asBool(); // get the script dh = block.inputValue(aScript,&status); SYS_ERROR_CHECK(status, "Error getting reload script handle\n"); MString script = dh.asString(); MString cmd = "source \"" + script+"\""; MCommandResult melResult; status = MGlobal::executeCommand(cmd,melResult); if (status.error()) { MGlobal::displayError( "Error sourcing mel script, please check the function you provided is valid!"); result = false; } // set the result MDataHandle dhScriptSourced = block.outputValue(aScriptSourced,&status); SYS_ERROR_CHECK(status, "Error getting ScriptSourced data handle\n"); dhScriptSourced.set(result); dhScriptSourced.setClean(); return MS::kSuccess; } return MS::kUnknownParameter; }