bool getDagPathByChildName(MDagPath & ioDagPath, const std::string & iChildName) { unsigned int numChildren = ioDagPath.childCount(); std::string strippedName = stripPathAndNamespace(iChildName); MObject closeMatch; for (unsigned int i = 0; i < numChildren; ++i) { MObject child = ioDagPath.child(i); MFnDagNode dagChild(child); std::string name = dagChild.partialPathName().asChar(); if (name == iChildName) { ioDagPath.push(child); return true; } if (closeMatch.isNull()) { if (strippedName == stripPathAndNamespace(name)) { closeMatch = child; } } } if (!closeMatch.isNull()) { ioDagPath.push(closeMatch); return true; } return false; }
void geometryReplicatorGeometryOverride::updateDG() { if (!fPath.isValid()) { MFnDependencyNode fnThisNode(fThisNode); MObject messageAttr = fnThisNode.attribute("message"); MPlug messagePlug(fThisNode, messageAttr); MPlugArray connections; if (messagePlug.connectedTo(connections, false, true)) { for (unsigned int i = 0; i < connections.length(); ++i) { MObject node = connections[i].node(); if (node.hasFn(MFn::kMesh) || node.hasFn(MFn::kNurbsSurface) || node.hasFn(MFn::kNurbsCurve) || node.hasFn(MFn::kBezierCurve)) { MDagPath path; MDagPath::getAPathTo(node, path); fPath = path; fType = path.apiType(); break; } } } } }
bool PxrUsdMayaWriteUtil::ReadMayaAttribute( const MFnDependencyNode& depNode, const MString& name, VtVec3fArray* val) { MStatus status; depNode.attribute(name, &status); if (status == MS::kSuccess) { MPlug plug = depNode.findPlug(name); MObject dataObj; if ( (plug.getValue(dataObj) == MS::kSuccess) && (dataObj.hasFn(MFn::kVectorArrayData)) ) { MFnVectorArrayData dData(dataObj, &status); if (status == MS::kSuccess) { MVectorArray arrayValues = dData.array(); size_t numValues = arrayValues.length(); val->resize(numValues); for (size_t i = 0; i < numValues; ++i) { (*val)[i].Set( arrayValues[i][0], arrayValues[i][1], arrayValues[i][2]); } return true; } } } return false; }
void UsdMayaGLSoftSelectHelper::_PopulateWeights() { // we don't want to fallback to the active selection if there is no sot // select bool defaultToActiveSelection = false; MRichSelection softSelect; MGlobal::getRichSelection(softSelect, defaultToActiveSelection); MSelectionList selection; softSelect.getSelection(selection); for (MItSelectionList iter( selection, MFn::kInvalid); !iter.isDone(); iter.next() ) { MDagPath dagPath; MObject component; iter.getDagPath(dagPath, component); // component.isNull() indcates that we're selecting a whole object, as // opposed to a component. if (!component.isNull()) { continue; } float weight = 0.0f; _dagPathsToWeight[dagPath] = weight; } }
// -------------------------------------------------------------------------------------------- MStatus polyModifierCmd::createModifierNode( MObject& modifierNode ) // -------------------------------------------------------------------------------------------- { MStatus status = MS::kFailure; if( fModifierNodeTypeInitialized || fModifierNodeNameInitialized ) { if( fModifierNodeTypeInitialized ) { modifierNode = fDGModifier.MDGModifier::createNode( fModifierNodeType, &status ); myModifierNode = modifierNode; } else if( fModifierNodeNameInitialized ) { modifierNode = fDGModifier.MDGModifier::createNode( fModifierNodeName, &status ); } // Check to make sure that we have a modifier node of the appropriate type. // Requires an inMesh and outMesh attribute. // MFnDependencyNode depNodeFn( modifierNode ); MObject inMeshAttr; MObject outMeshAttr; inMeshAttr = depNodeFn.attribute( "inMesh" ); outMeshAttr = depNodeFn.attribute( "outMesh" ); if( inMeshAttr.isNull() || outMeshAttr.isNull() ) { displayError( "Invalid Modifier Node: inMesh and outMesh attributes are required." ); status = MS::kFailure; } } return status; }
MObject getConnectedFileTextureObject(MString& plugName, MFnDependencyNode& depFn) { MStatus stat; MString path = ""; MPlug plug = depFn.findPlug(plugName, &stat); if( !stat ) return MObject::kNullObj; if( plug.isConnected()) { MPlugArray parray; plug.connectedTo(parray, true, false, &stat); if( !stat ) return MObject::kNullObj; if( parray.length() == 0 ) return MObject::kNullObj; MPlug destPlug = parray[0]; MObject fileNode = destPlug.node(); if( !fileNode.hasFn(MFn::kFileTexture) ) { return MObject::kNullObj; }else{ return fileNode; } } return MObject::kNullObj; }
MStatus particleSystemInfoCmd::parseArgs( const MArgList& args ) { // Parse the arguments. MStatus stat = MS::kSuccess; if( args.length() > 1 ) { MGlobal::displayError( "Too many arguments." ); return MS::kFailure; } if( args.length() == 1 ) { MString particleName = args.asString( 0, &stat ); CHECKRESULT(stat, "Failed to parse particle node name argument." ); nodeFromName( particleName, particleNode ); if( !particleNode.isNull() && !particleNode.hasFn( MFn::kParticle ) ) { MGlobal::displayError( "The named node is not a particle system." ); return MS::kFailure; } } return MS::kSuccess; }
void colorTransformDataTranslator::writeColorSpaceForNodes(fstream& f) { MItDependencyNodes nodeIter; f << "====================== Nodes with color space attribute =======================\n"; for (; !nodeIter.isDone(); nodeIter.next()) { MObject node = nodeIter.item(); if(!node.isNull() && ( (node.apiType()==MFn::kFileTexture) || (node.apiType()==MFn::kImagePlane) ) ) { MString inputColorSpace = getInputColorSpace(node); MString transformId; f << "Found node with colorspace " << inputColorSpace.asUTF8(); if(MColorManagementUtilities::getColorTransformCacheIdForInputSpace( inputColorSpace, transformId)) { f << ", its corresponding transform id: " << transformId.asUTF8() << std::endl; } else { f << ", no corresponding transform id found.\n"; } } } }
// // This method allows the custom transform to apply its own locking // mechanism to rotation. Standard dependency graph attribute locking // happens automatically and cannot be modified by custom nodes. // If the plug should not be changed, then the value from the passed savedR // argument should be return to be used in the transformation matrix. // MEulerRotation rockingTransformCheckNode::applyRotationLocks(const MEulerRotation &toTest, const MEulerRotation &savedRotation, MStatus *ReturnStatus ) { #ifdef ALLOW_DG_TO_HANDLE_LOCKS // Allow the DG to handle locking. return toTest; #else // // Implement a simple lock by checking for an existing attribute // Use the following MEL to add the attribute: // addAttr -ln "rotateLockPlug" // MStatus status; MObject object = thisMObject(); MFnDependencyNode depNode( object ); MObject rotateLockPlug = depNode.findPlug( "rotateLockPlug", &status ); // If the lock does not exist that we return the updated value that has // been passed in if ( rotateLockPlug.isNull() ) return toTest; // We have a lock. Returned the original saved value of the // rotation. return savedRotation; #endif }
PXR_NAMESPACE_OPEN_SCOPE /* static */ MObject UsdMayaTranslatorMaterial::Read( const TfToken& shadingMode, const UsdShadeMaterial& shadeMaterial, const UsdGeomGprim& boundPrim, UsdMayaPrimReaderContext* context) { if (shadingMode == UsdMayaShadingModeTokens->none) { return MObject(); } UsdMayaShadingModeImportContext c(shadeMaterial, boundPrim, context); MObject shadingEngine; if (c.GetCreatedObject(shadeMaterial.GetPrim(), &shadingEngine)) { return shadingEngine; } if (UsdMayaShadingModeImporter importer = UsdMayaShadingModeRegistry::GetImporter(shadingMode)) { shadingEngine = importer(&c); } if (!shadingEngine.isNull()) { c.AddCreatedObject(shadeMaterial.GetPrim(), shadingEngine); } return shadingEngine; }
//--------------------------------------------------- // Retrieve the bind pose for a controller/joint std::pair // MMatrix DagHelper::getBindPoseInverse ( const MObject& controller, const MObject& influence ) { MStatus status; if ( controller.apiType() == MFn::kSkinClusterFilter ) { MFnSkinCluster controllerFn ( controller ); // Find the correct index for the pre-bind matrix uint index = controllerFn.indexForInfluenceObject ( MDagPath::getAPathTo ( influence ), &status ); if ( status != MStatus::kSuccess ) return MMatrix::identity; MPlug preBindMatrixPlug = controllerFn.findPlug ( "bindPreMatrix", &status ); preBindMatrixPlug = preBindMatrixPlug.elementByLogicalIndex ( index, &status ); if ( status != MStatus::kSuccess ) return MMatrix::identity; // Get the plug's matrix MMatrix ret; if ( !DagHelper::getPlugValue ( preBindMatrixPlug, ret ) ) return MMatrix::identity; return ret; } else if ( controller.apiType() == MFn::kJointCluster ) { MMatrix ret; DagHelper::getPlugValue ( influence, "bindPose", ret ); return ret.inverse(); } else return MMatrix::identity; }
MStatus GetMetaNodeConnectionCmd::doIt ( const MArgList &args ) { MStatus status; MStatus paramStatus = parseArgs(args); MObject metaNodeObj; status = lrutils::getObjFromName(this->m_metaNodeName, metaNodeObj); MyCheckStatus(status, "lrutils::getObjFromName() failed"); MObject connectedObj; status = lrutils::getMetaNodeConnection(metaNodeObj, connectedObj, this->m_connectionName); MyCheckStatus(status, "lrutils::getMetaNodeConnection() failed"); if( connectedObj.hasFn(MFn::kDagNode) ) { MFnDagNode connectedFn(connectedObj); MString dagPath = connectedFn.fullPathName(); setResult(dagPath); } else { MFnDependencyNode connectedFn(connectedObj); MString name = connectedFn.name(); setResult(name); } return redoIt(); }
bool AbcWriteJob::checkCurveGrp() { MItDag itDag(MItDag::kBreadthFirst, MFn::kNurbsCurve); itDag.reset(mCurDag, MItDag::kBreadthFirst, MFn::kNurbsCurve); bool init = false; int degree = 0; MFnNurbsCurve::Form form = MFnNurbsCurve::kInvalid; for (; !itDag.isDone(); itDag.next()) { MDagPath curvePath; if (itDag.getPath(curvePath) == MS::kSuccess) { MObject curve = curvePath.node(); if (!util::isIntermediate(curve) && curve.hasFn(MFn::kNurbsCurve)) { MFnNurbsCurve fn(curvePath); if (!init) { degree = fn.degree(); form = fn.form(); init = true; } else { if (degree != fn.degree() || form != fn.form()) return false; } } } } return true; }
MStatus createClip::parseArgs( const MArgList& args ) // // No arguments to parse. // { MStatus stat = MS::kSuccess; MString arg; MSelectionList list; bool charNameUsed = 0; MString charName; const MString charFlag ("-c"); const MString charFlagLong ("-char"); // Parse the arguments. for ( unsigned int i = 0; i < args.length(); i++ ) { arg = args.asString( i, &stat ); if (!stat) continue; if ( arg == charFlag || arg == charFlagLong ) { // get the char name // if (i == args.length()-1) { arg += ": must specify a character name"; displayError(arg); return MS::kFailure; } i++; args.get(i, charName); list.add(charName); charNameUsed = 1; } else { arg += ": unknown argument"; displayError(arg); return MS::kFailure; } } if (charNameUsed) { // get the character corresponding to the node name // MItSelectionList iter (list); for ( /* nothing */ ; !iter.isDone(); iter.next() ) { MObject node; iter.getDependNode(node); if (node.apiType() == MFn::kCharacter) { fCharacter = node; break; } } if (fCharacter.isNull()) { MString errMsg("Character flag must specify a character node."); displayError(errMsg); return MS::kFailure; } } return stat; }
MMatrix GetGlobalMMatrix(const MObject & in_Ref) { MMatrix result; result.setToIdentity(); MFnDagNode node(in_Ref); MDagPathArray paths; node.getAllPaths(paths); MDagPath path = paths[0]; MString typeStr = in_Ref.apiTypeStr(); if(typeStr == "kTransform") { result = path.inclusiveMatrix(); } else { for(unsigned int i=0;i<node.parentCount();i++) { MObject parent = node.parent(i); typeStr = parent.apiTypeStr(); if(typeStr == "kTransform") { result = GetGlobalMMatrix(parent); //break; } } } return result; }
ATTR_TYPE getPlugAttrType(const char *plugName, MFnDependencyNode& dn) { MDGContext ctx = MDGContext::fsNormal; MStatus stat = MS::kSuccess; MPlug plug = dn.findPlug(plugName, &stat); if( !stat ) return ATTR_TYPE::ATTR_TYPE_NONE; MObject attObj = plug.attribute(&stat); MFnAttribute att(attObj); if( !stat ) return ATTR_TYPE::ATTR_TYPE_NONE; if(att.isUsedAsColor()) return ATTR_TYPE::ATTR_TYPE_COLOR; if( attObj.apiType() == MFn::kNumericAttribute) { MFnNumericAttribute na(attObj, &stat); if( !stat ) return ATTR_TYPE::ATTR_TYPE_NONE; if( na.unitType() == MFnNumericData::Type::kFloat ) return ATTR_TYPE::ATTR_TYPE_FLOAT; } return ATTR_TYPE::ATTR_TYPE_NONE; }
AlembicObject::AlembicObject(SceneNodePtr eNode, AlembicWriteJob* in_Job, Abc::OObject oParent) : mExoSceneNode(eNode), mJob(in_Job), mMyParent(oParent), mNumSamples(0), nodeName(eNode->dccIdentifier.c_str()), mHasParent(false) { MSelectionList sl; sl.add(nodeName); MDagPath dagPath; sl.getDagPath(0, dagPath); MObject in_Ref = dagPath.node(); AddRef(in_Ref); MFnDagNode dag(in_Ref); for (unsigned int i = 0; i < dag.parentCount(); ++i) { MObject parentRef = dag.parent(i); if (!parentRef.isNull()) { mHasParent = in_Job->ObjectExists(parentRef); if (mHasParent) { break; } } } }
//----------------------------------------------------------------------------- // Returns the vsSkinner node if the passed node is connected to a vsSkinner node //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::ConnectedToMesh( const MDagPath &iDagPath, MDagPath &oDagPath ) { MPlugArray pA; MPlugArray pA1; if ( MFnDagNode( iDagPath ).getConnections( pA ) && pA.length() ) { MObject mObj; const uint np( pA.length() ); for ( uint i( 0U ); i != np; ++i ) { if ( pA[ i ].connectedTo( pA1, true, true ) && pA1.length() ) { const uint np1( pA1.length() ); for ( uint j( 0U ); j != np1; ++j ) { mObj = pA1[ j ].node(); if ( mObj.apiType() == MFn::kMesh ) { MDagPath::getAPathTo( mObj, oDagPath ); return MS::kSuccess; } } } } } return MS::kFailure; }
// ------------------------------------------------------------ void EffectTextureExporter::add2DPlacement ( COLLADASW::Texture* colladaTexture, MObject texture ) { // Is there a texture placement applied to this texture? MObject placementNode = DagHelper::getSourceNodeConnectedTo ( texture, ATTR_UV_COORD ); if ( placementNode.hasFn ( MFn::kPlace2dTexture ) ) { MFnDependencyNode placement2d ( placementNode ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_WRAPU_PARAMETER, placement2d ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_WRAPV_PARAMETER, placement2d ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_MIRRORU_PARAMETER, placement2d ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_MIRRORV_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_COVERAGEU_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_COVERAGEV_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_TRANSFRAMEU_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_TRANSFRAMEV_PARAMETER, placement2d ); addAngleParameter ( colladaTexture, MAYA_TEXTURE_ROTFRAME_PARAMETER, placement2d ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_STAGGER_PARAMETER, placement2d ); addBoolParameter ( colladaTexture, MAYA_TEXTURE_FAST_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_REPEATU_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_REPEATV_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_OFFSETU_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_OFFSETV_PARAMETER, placement2d ); addAngleParameter ( colladaTexture, MAYA_TEXTURE_ROTATEUV_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_NOISEU_PARAMETER, placement2d ); addFloatParameter ( colladaTexture, MAYA_TEXTURE_NOISEV_PARAMETER, placement2d ); } }
bool usdWriteJob::needToTraverse(const MDagPath& curDag) { MObject ob = curDag.node(); // NOTE: Already skipping all intermediate objects // skip all intermediate nodes (and their children) if (PxrUsdMayaUtil::isIntermediate(ob)) { return false; } // skip nodes that aren't renderable (and their children) if (mJobCtx.mArgs.excludeInvisible && !PxrUsdMayaUtil::isRenderable(ob)) { return false; } if (!mJobCtx.mArgs.exportDefaultCameras && ob.hasFn(MFn::kTransform)) { // Ignore transforms of default cameras MString fullPathName = curDag.fullPathName(); if (fullPathName == "|persp" || fullPathName == "|top" || fullPathName == "|front" || fullPathName == "|side") { return false; } } return true; }
MString getConnectedFileTexturePath(const MString& plugName, MFnDependencyNode& depFn) { MStatus stat; MString path = ""; MPlug plug = depFn.findPlug(plugName, &stat); if (!stat) return path; if (plug.isConnected()) { MPlugArray parray; plug.connectedTo(parray, true, false, &stat); if (!stat) return path; if (parray.length() == 0) return path; MPlug destPlug = parray[0]; MObject fileNode = destPlug.node(); if (!fileNode.hasFn(MFn::kFileTexture)) { return path; } MFnDependencyNode fileDepFn(fileNode); MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat); if (!stat) { return path; } path = ftn.asString(); } return path; }
MStatus HelloWorld::doIt(const MArgList& argList) { MGlobal::displayInfo("Hello World!"); //Get list of selected items MSelectionList selectedItem; //Get list of selected items for realsies MGlobal::getActiveSelectionList(selectedItem); MStatus stat; //Iterate through them. MItSelectionList it(selectedItem); while (!it.isDone() ) { MDagPath dagPath; //Will hold a path to the indexed object MObject component; //List of selected components it.getDagPath(dagPath, component); MFnDependencyNode fn(dagPath.node()); MString status = "OBJECT: "; status += fn.name().asChar(); MGlobal::displayInfo(status); if (!component.isNull()) { MGlobal::displayInfo("Is not null!"); MItMeshVertex itVert(dagPath, component, &stat); if (stat == MS::kSuccess) { while (!itVert.isDone()) { MPoint point = itVert.position(MSpace::kWorld); MString pointStr; pointStr += itVert.index(); pointStr += "\t"; pointStr += point.x; point.x += 10; pointStr += "\t"; pointStr += point.y; pointStr += "\t"; pointStr += point.z; MGlobal::displayInfo(pointStr); itVert.setPosition(point, MSpace::kWorld); itVert.next(); } } } else{ MGlobal::displayInfo("Is null.. :("); } it.next(); } return MS::kSuccess; }
osg::ref_ptr<osg::Node> Group::exporta(MDagPath &dp) { osg::ref_ptr<osg::Group> osggroup; // Get the node of this path MObject node = dp.node(); // 1. Create the adequate type of node if( node.hasFn(MFn::kEmitter) ) { // Emitters are subclasses of Transform // We build the transform and then add the emitter as a child osggroup = Transform::exporta(node); osggroup->addChild( PointEmitter::exporta(node).get() ); } else if( node.hasFn(MFn::kTransform) ){ osggroup = Transform::exporta(node); } else { // Generic group (kWorld) osggroup = new osg::Group(); } // 2. Process and add children for(int i=0; i<dp.childCount(); i++){ // Add child to the path and recursively call the exportation function MDagPath dpc(dp); dpc.push(dp.child(i)); osg::ref_ptr<osg::Node> child = DAGNode::exporta(dpc); if(child.valid()){ // ** Check ** If any children is a LightSource, deactivate culling // for this group in order to apply the light even though it is not // directly visible if( dynamic_cast<osg::LightSource *>(child.get()) != NULL ) osggroup->setCullingActive(false); osggroup->addChild(child.get()); } } // 3. If there are no children, the node is ignored if( osggroup->getNumChildren() == 0 ){ // Buuuuuuut, if there is an animation, it is saved to disk // because it can be a useful camera animation osg::AnimationPathCallback *cb = dynamic_cast< osg::AnimationPathCallback * >(osggroup->getUpdateCallback()); if(cb){ MFnDependencyNode dn(node); std::cout << "EXPORTING CAMERA ANIMATION: " << dn.name().asChar() << std::endl; CameraAnimation::save(cb->getAnimationPath(), Config::instance()->getSceneFilePath().getDirectory() + "/" + Config::instance()->getSceneFilePath().getFileBaseName() + "_" + std::string(dn.name().asChar()) + ".path" ); } return NULL; } // Name the node (mesh) MFnDependencyNode dnodefn(node); osggroup->setName( dnodefn.name().asChar() ); return (osg::Node *)osggroup.get(); }
MStatus particlePathsCmd::parseArgs( const MArgList& args ) { MArgDatabase argData(syntax(), args); // // Parse the time flags // if (argData.isFlagSet(startFlag)) { argData.getFlagArgument(startFlag, 0, start); } if (argData.isFlagSet(finishFlag)) { argData.getFlagArgument(finishFlag, 0, finish); } if (argData.isFlagSet(incrementFlag)) { argData.getFlagArgument(incrementFlag, 0, increment); } if (finish <= start || increment <= 0.0) { MGlobal::displayError( "Invalid time arguments." ); return MS::kFailure; } // // Get the particle system object // MSelectionList selectList; argData.getObjects(selectList); if( selectList.length() < 1 ) { MGlobal::displayError( "Missing particle node name argument." ); return MS::kFailure; } else if( selectList.length() > 1 ) { MGlobal::displayError( "Too many particle nodes given." ); return MS::kFailure; } selectList.getDependNode(0,particleNode); if (particleNode.isNull() || !particleNode.hasFn(MFn::kParticle)) { MGlobal::displayError( "Invalid node argument." ); return MS::kFailure; } return MS::kSuccess; }
bool atomImport::replaceNameAndFindPlug(const MString& origName, atomNodeNameReplacer& replacer, MPlug& replacedPlug) { bool rtn = false; // get the node name // MStringArray nameParts; origName.split('.', nameParts); // Perform any necessary replacement // MString tmpName(nameParts[0]); // TODO: type & hierarchy info -- does the replacer store enough info // to help us find that out since in the case of export edits we don't // have that info for sources // if (replacer.findNode(atomNodeNameReplacer::eDag,tmpName,0,0)) { MString newName(tmpName); newName += ("."); // add the attribute name(s) back on again // unsigned int ii; MString attrName; for (ii = 1; ii < nameParts.length(); ++ii) { if (ii > 1) { attrName += ("."); } attrName += nameParts[ii]; } newName += attrName; MSelectionList tmpList; if (MS::kSuccess == tmpList.add(newName)) { tmpList.getPlug(0,replacedPlug); rtn = !replacedPlug.isNull(); if (!rtn) { // test for the special case of the pivot component // MDagPath path; MObject component; if (MS::kSuccess == tmpList.getDagPath(0,path,component) && component.apiType() == MFn::kPivotComponent) { MObject node; tmpList.getDependNode(0,node); MFnDependencyNode fnNode(node); replacedPlug = fnNode.findPlug(attrName,false); rtn = !replacedPlug.isNull(); } } } } return rtn; }
MStatus fluidInfoCmd::parseArgs( const MArgList& args ) { // Parse the arguments. MStatus stat = MS::kSuccess; // some defaults for the number of voxels we might want to print requestedVoxels = -1; if( args.length() < 1 ) { MGlobal::displayError( "Missing fluid node name argument." ); return MS::kFailure; } else if( args.length() > 2 ) { MGlobal::displayError( "Too many arguments." ); return MS::kFailure; } fluidName = args.asString( 0, &stat ); if (stat != MS::kSuccess) { MGlobal::displayError( "Failed to parse fluid node name argument." ); return MS::kFailure; } if(args.length() == 1) { // assume that the user wants to print all the voxels // they probably won't do this more than once requestedVoxels = -1; } else { requestedVoxels = args.asInt( 1, &stat ); if (stat != MS::kSuccess) { MGlobal::displayError( "Failed to parse num voxels to pribt argument." ); return MS::kFailure; } } nodeFromName( fluidName, fluidNode ); if( fluidNode.isNull() ) { MGlobal::displayError( "There is no fluid node with the given name." ); return MS::kFailure; } if( ! fluidNode.hasFn( MFn::kFluid ) ) { MGlobal::displayError( "The named node is not a fluid." ); return MS::kFailure; } return MS::kSuccess; }
void ComponentScaleContext::updateManipulators(void * data) { MStatus stat = MStatus::kSuccess; ComponentScaleContext * ctxPtr = (ComponentScaleContext *) data; ctxPtr->deleteManipulators(); MSelectionList list; stat = MGlobal::getActiveSelectionList(list); MItSelectionList iter(list, MFn::kInvalid, &stat); if (MS::kSuccess == stat) { for (; !iter.isDone(); iter.next()) { // Make sure the selection list item is a dag path with components // before attaching the manipulator to it. // MDagPath dagPath; MObject components; iter.getDagPath(dagPath, components); if (components.isNull() || !components.hasFn(MFn::kComponent)) { MGlobal::displayWarning("Object in selection list is not " "a component."); continue; } // Add manipulator to the selected object // MString manipName ("componentScaleManip"); MObject manipObject; componentScaleManip* manipulator = (componentScaleManip *) componentScaleManip::newManipulator(manipName, manipObject); if (NULL != manipulator) { // Add the manipulator // ctxPtr->addManipulator(manipObject); // Connect the manipulator to the object in the selection list. // manipulator->setSurfaceDagPath(dagPath); manipulator->setComponentObject(components); if (!manipulator->connectToDependNode(dagPath.node())) { MGlobal::displayWarning("Error connecting manipulator to" " object"); } } } } }
void liqRibData::parseVectorAttributes( MFnDependencyNode & nodeFn, MStringArray & strArray, ParameterType pType ) { int i; MStatus status; if ( strArray.length() > 0 ) { for ( i = 0; i < strArray.length(); i++ ) { liqTokenPointer tokenPointerPair; MString cutString = strArray[i].substring(5, strArray[i].length()); MPlug vPlug = nodeFn.findPlug( strArray[i] ); MObject plugObj; status = vPlug.getValue( plugObj ); if ( plugObj.apiType() == MFn::kVectorArrayData ) { MFnVectorArrayData fnVectorArrayData( plugObj ); MVectorArray vectorArrayData = fnVectorArrayData.array( &status ); tokenPointerPair.set( cutString.asChar(), pType, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, true, false, vectorArrayData.length() ); for ( int kk = 0; kk < vectorArrayData.length(); kk++ ) { tokenPointerPair.setTokenFloat( kk, vectorArrayData[kk].x, vectorArrayData[kk].y, vectorArrayData[kk].z ); } // should it be per vertex or face-varying if ( ( ( type() == MRT_Mesh ) || ( type() == MRT_Subdivision ) ) && ( vectorArrayData.length() == faceVaryingCount ) ) { tokenPointerPair.setDetailType( rFaceVarying); } else { tokenPointerPair.setDetailType( rVertex ); } // store it all tokenPointerArray.push_back( tokenPointerPair ); } else { // Hmmmm float ? double ? float x, y, z; tokenPointerPair.set( cutString.asChar(), pType, ( type() == MRT_Nurbs || type() == MRT_NuCurve ) ? true : false, false, false, 0 ); vPlug.child(0).getValue( x ); vPlug.child(1).getValue( y ); vPlug.child(2).getValue( z ); tokenPointerPair.setTokenFloat( 0, x, y, z ); tokenPointerPair.setDetailType( rConstant ); tokenPointerArray.push_back( tokenPointerPair ); } } } }
void tLocatorMgr::scanScene(const float lframe__, const int sample__, boost::shared_ptr< liqRibHT > &htable__, int &count__, MStatus &returnStatus__) { CM_TRACE_FUNC("tLocatorMgr::scanScene("<<lframe__<<","<<sample__<<",htable__,count__,returnStatus__)"); //[refactor 10] beg from scanScene() MItDag dagCoordSysIterator( MItDag::kDepthFirst, MFn::kLocator, &returnStatus__); for (; !dagCoordSysIterator.isDone(); dagCoordSysIterator.next()) { #if (Refactoring == 0) LIQ_CHECK_CANCEL_REQUEST; #endif MDagPath path; MObject currentNode; currentNode = dagCoordSysIterator.item(); MFnDagNode dagNode; dagCoordSysIterator.getPath( path ); if(MS::kSuccess != returnStatus__) continue; if(!currentNode.hasFn(MFn::kDagNode)) continue; returnStatus__ = dagNode.setObject( currentNode ); if(MS::kSuccess != returnStatus__) continue; // scanScene: if it's a coordinate system then insert it into the hash table if( dagNode.typeName() == "liquidCoordSys" ) { int coordType = 0; MPlug typePlug = dagNode.findPlug( "type", &returnStatus__ ); if( MS::kSuccess == returnStatus__ ) typePlug.getValue( coordType ); bool useSamples( ( sample__ > 0 ) && isObjectMotionBlur( path ) ); ObjectType mrttype = getMRTType(currentNode, coordType); ObjectType mrttype_shouldbe = ( coordType == 5 )? MRT_ClipPlane : MRT_Coord; if( mrttype != mrttype_shouldbe ){ liquidMessage2(messageError, "mrttype[%d] should be %d", mrttype_shouldbe); } htable__->insert( path, lframe__, ( useSamples )? sample__ : 0, mrttype, //( coordType == 5 )? MRT_ClipPlane : MRT_Coord, count__++ ); continue; } } //[refactor 10] end from scanScene() }
bool ik2Bsolver::findFirstJointChild(const MDagPath & root, MDagPath & result) { const unsigned count = root.childCount(); unsigned i; for(i=0; i<count; i++) { MObject c = root.child(i); if(c.hasFn(MFn::kJoint)) { MDagPath::getAPathTo(c, result); return 1; } } return 0; }