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; } } } } }
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(); }
static bool isCompound(const MPlug& plgInShape) { MPlugArray plgaConnectedTo; plgInShape.connectedTo(plgaConnectedTo, true, true); int numSelectedShapes = plgaConnectedTo.length(); if(numSelectedShapes > 0) { MObject node = plgaConnectedTo[0].node(); MDagPath dagPath; MDagPath::getAPathTo(node, dagPath); int numChildren = dagPath.childCount(); if (node.hasFn(MFn::kTransform)) { MFnTransform trNode(dagPath); const char* name = trNode.name().asChar(); printf("name = %s\n", name); for (int i=0;i<numChildren;i++) { MObject child = dagPath.child(i); if(child.hasFn(MFn::kMesh)) { return false; } if(child.hasFn(MFn::kTransform)) { MDagPath dagPath; MDagPath::getAPathTo(child, dagPath); MFnTransform trNode(dagPath); const char* name = trNode.name().asChar(); printf("name = %s\n", name); int numGrandChildren = dagPath.childCount(); { for (int i=0;i<numGrandChildren;i++) { MObject grandchild = dagPath.child(i); if(grandchild.hasFn(MFn::kMesh)) { return true; } } } } } } } return false; }
MStatus CBPoseSpaceCmd::doIt( const MArgList& args ) { MStatus status = parseArgs( args ); if( status != MS::kSuccess ) return status; ASearchHelper finder; MObject poseMesh; finder.getObjByFullName(_poseName.asChar(), poseMesh); if(poseMesh == MObject::kNullObj) { MGlobal::displayWarning(_poseName+" doesn't exist, skipped."); return MS::kFailure; } if(!poseMesh.hasFn(MFn::kMesh)) return MS::kFailure; if(_operation == tCreate) { MObject bindMesh; finder.getObjByFullName(_bindName.asChar(), bindMesh); if(bindMesh == MObject::kNullObj) { MGlobal::displayWarning(_bindName+" doesn't exist, skipped."); return MS::kFailure; } if(!bindMesh.hasFn(MFn::kMesh)) return MS::kFailure; calculateVertexPoseSpace(poseMesh, bindMesh); } else { if(!is_regular_file( _cacheName.asChar())) { MGlobal::displayInfo(MString("corrective blendshape cannot open pose cache file: ") + _cacheName); return MS::kFailure; } if(_operation == tLoad) setCachedVertexPosition(poseMesh); else if(_operation == tSavePose) saveVertexPosition(poseMesh); else if(_operation == tLoadPose) loadVertexPosition(poseMesh); } return MS::kSuccess; }
std::string make_material_name(const MObject& src_node) { std::string candidate("Unknown"); if (src_node.hasFn(MFn::kLambert)) { MFnLambertShader shader(src_node); candidate = shader.name().asChar(); } else if (src_node.hasFn(MFn::kBlinn)) { MFnBlinnShader shader(src_node); candidate = shader.name().asChar(); } else if (src_node.hasFn(MFn::kPhong)) { MFnPhongShader shader(src_node); candidate = shader.name().asChar(); } return sanitize_name(candidate); }
ENTER_NAMESPACE_STOKES_MAYA NurbsCurveEmitter::NurbsCurveEmitter(const MObject& object) : ObjectEmitter(object) { assert(object.hasFn(MFn::kNurbsCurve)); }
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; }
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; }
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; }
// ------------------------------------------------------------ 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 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; }
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(); }
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 ShaderFXShaderExporter::exportSamplerAndSurface(const MFnDependencyNode & node, const MObject & attr) { MStatus status; if (!attr.hasFn(MFn::kTypedAttribute)) return; MFnTypedAttribute fnTypedAttr(attr, &status); if (!status) return; MFnData::Type type = fnTypedAttr.attrType(&status); if (!status) return; if (type != MFnData::kString) return; MPlug plug = node.findPlug(attr, &status); MString value; status = plug.getValue(value); if (!status) return; if (value.length() == 0) return; bool isUsedAsFilename = MFnAttribute(attr).isUsedAsFilename(&status); if (!status) return; // Filename are treated as texture filenames. if (!isUsedAsFilename) return; exportSamplerAndSurfaceInner(value); }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::IsSkinnerNode( const MObject &iObject ) { if ( iObject.hasFn( MFn::kPluginShape ) && MFnDependencyNode( iObject ).typeName() == "vsSkinner" ) return MS::kSuccess; return MS::kFailure; }
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; }
// If a problem occurs, this function returns an empty string. MString getNameFromObj(MObject obj) { MString nodeName; // If this object is a MFnDagNode, we should store the dag name. // Otherwise, use the MFnDependencyNode name. if (obj.hasFn(MFn::kDagNode)) { MFnDagNode dagNode(obj); nodeName = dagNode.fullPathName(); } else if (obj.hasFn(MFn::kDependencyNode)) { MFnDependencyNode node(obj); nodeName = node.name(); } return nodeName; }
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; }
bool tm_polygon_edgestoring::setMesh( MObject object) { if(!(object.hasFn( MFn::kMesh))) { MGlobal::displayError("tm_polygon_selectring::setMesh - Object is not a mesh."); return false; } meshObject = object; objectIsSet = true; return true; }
//--------------------------------------------------------------- String EffectTextureExporter::exportImage ( const MObject &texture ) { // Retrieve the texture filename MFnDependencyNode textureNode ( texture ); MString mayaName = textureNode.name(); MPlug filenamePlug = textureNode.findPlug ( ATTR_FILE_TEXTURE_NAME ); // Get the maya image id. String mayaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() ); // Generate a COLLADA id for the new light object String colladaImageId; // Check if there is an extra attribute "colladaId" and use this as export id. MString attributeValue; DagHelper::getPlugValue ( texture, COLLADA_ID_ATTRIBUTE_NAME, attributeValue ); if ( attributeValue != EMPTY_CSTRING ) { // Generate a valid collada name, if necessary. colladaImageId = mDocumentExporter->mayaNameToColladaName ( attributeValue, false ); } else { // Generate a COLLADA id for the new light object colladaImageId = DocumentExporter::mayaNameToColladaName ( textureNode.name() ); } // Make the id unique and store it in a map for refernences. colladaImageId = mImageIdList.addId ( colladaImageId ); mMayaIdColladaImageId [mayaImageId] = colladaImageId; // Get the maya filename with the path to the file. MString mayaFileName; filenamePlug.getValue ( mayaFileName ); if ( mayaFileName.length () == 0 ) return NULL; String sourceFile = mayaFileName.asChar (); COLLADASW::URI sourceFileUri ( COLLADASW::URI::nativePathToUri ( sourceFile ) ); if ( sourceFileUri.getScheme ().empty () ) sourceFileUri.setScheme ( COLLADASW::URI::SCHEME_FILE ); COLLADASW::Image* colladaImage = exportImage ( mayaImageId, colladaImageId, sourceFileUri ); if ( colladaImage == NULL ) return NULL; // Export the node type, because PSD textures don't behave the same as File textures. String nodeType = texture.hasFn ( MFn::kPsdFileTexture ) ? MAYA_TEXTURE_PSDTEXTURE : MAYA_TEXTURE_FILETEXTURE; colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_NODETYPE, nodeType ); // Export whether this image is in fact an image sequence MPlug imgSeqPlug = textureNode.findPlug ( ATTR_IMAGE_SEQUENCE ); bool isImgSeq = false; imgSeqPlug.getValue ( isImgSeq ); colladaImage->addExtraTechniqueParameter ( PROFILE_MAYA, MAYA_TEXTURE_IMAGE_SEQUENCE, isImgSeq ); return colladaImage->getImageId(); }
// ------------------------------------------- AnimationResult AnimationHelper::isAnimated ( AnimationSampleCache* cache, const MPlug& plug ) { // First check for sampling in our cache -- if this exists, it overrides // all other considerations. We could have sampling on a node without any // connections (for example, IK driven nodes). bool animated; if ( cache->findCachePlug ( plug, animated ) ) { return ( !animated ) ? kISANIM_None : kISANIM_Sample; } else { // Get the connected animating object MObject connectedNode = getAnimatingNode ( plug ); if ( connectedNode == MObject::kNullObj ) return kISANIM_None; else if ( connectedNode.hasFn ( MFn::kAnimCurve ) ) { MFnAnimCurve curveFn ( connectedNode ); AnimationResult result = curveFn.numKeys() >= 1 ? kISANIM_Curve : kISANIM_None; // The animCurve is considered to be static if it would return // the same value regardless of the evaluation time. // This basically means that the values of all the keys are // the same and the y component of all the tangents is 0. if ( ExportOptions::removeStaticCurves() ) { if ( result == kISANIM_Curve && curveFn.isStatic() ) result = kISANIM_None; } return result; } else if ( connectedNode.hasFn ( MFn::kCharacter ) ) { return kISANIM_Character; } } return kISANIM_None; }
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() }
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"); } } } } }
TransformNode::TransformNode(MObject node) : ContainerNode(node) { _isSkeleton = false; _isMesh = false; MFnDependencyNode fnDependencyNode(node); MPlugArray plugArray; fnDependencyNode.getConnections(plugArray); for (int i = 0; i < plugArray.length(); i++) { MPlug& plug = plugArray[i]; bool isArray = plug.isArray(); MPlugArray connectedDstPlugins, connectedSrcPlugins; if (plug.connectedTo(connectedDstPlugins, true, false) == true) { for (int i = 0; i < connectedDstPlugins.length(); i++) { MPlug& plug = connectedDstPlugins[i]; MObject node = plug.node(); MFnDependencyNode fnPlugNode(node); MString name = fnPlugNode.name(); } } } MFnDagNode fnDagNode(node); int childCount = fnDagNode.childCount(); for (int i = 0; i < childCount; i++) { MObject child = fnDagNode.child(i); if (child.hasFn(MFn::kMesh)) { _isMesh = true; break; } else if (child.hasFn(MFn::kJoint)) { _isSkeleton = true; break; } } }
// ------------------------------------------- bool AnimationHelper::isPhysicsAnimation ( const MObject& o ) { if ( o.hasFn ( MFn::kChoice ) ) { MFnDependencyNode n ( o ); MPlug p = n.findPlug ( "input" ); uint choiceCount = p.numElements(); for ( uint i = 0; i < choiceCount; ++i ) { MPlug child = p.elementByPhysicalIndex ( i ); MObject connection = DagHelper::getSourceNodeConnectedTo ( child ); if ( !connection.isNull() && connection != o ) if ( isPhysicsAnimation ( connection ) ) return true; } } else if ( o.hasFn ( MFn::kRigidSolver ) || o.hasFn ( MFn::kRigid ) ) return true; return false; }
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; }
bool getConnectedFileTexturePath(MString& plugName, MString& nodeName, MString& value, MObject& outFileNode) { MStatus stat; MObject obj = objectFromName(nodeName); if( obj == MObject::kNullObj) return false; MFnDependencyNode depFn(obj); MPlug plug = depFn.findPlug(plugName, &stat); if( !stat ) return false; //MGlobal::displayInfo(MString("is plug connected: ") + plug.name()); if( !plug.isConnected()) { //MGlobal::displayInfo(MString("plug is NOT connected: ") + plug.name()); return false; } MPlugArray parray; plug.connectedTo(parray, true, false, &stat); if( !stat ) return false; if( parray.length() == 0 ) return false; MPlug destPlug = parray[0]; MObject fileNode = destPlug.node(); std::cout << "filenode: " << getObjectName(fileNode).asChar() << " plug name " << destPlug.name() << "\n"; if( !fileNode.hasFn(MFn::kFileTexture) ) { std::cout << "node is not from type fileTexture.\n"; return false; } MFnDependencyNode fileDepFn(fileNode); MPlug ftn = fileDepFn.findPlug("fileTextureName", &stat); if(!stat) { std::cout << "fileTextureName not found at fileTexNode.\n"; return false; } MString fileTextureName = ftn.asString(); std::cout << "fileTextureName value: " << fileTextureName.asChar() <<"\n"; value = fileTextureName; outFileNode = fileNode; return true; }
// ------------------------------------------- MObject AnimationHelper::getAnimatingNode ( const MPlug& plug ) { // Early withdrawal: check for no direct connections on plug MObject animating = DagHelper::getSourceNodeConnectedTo ( plug ); if ( animating.isNull() ) return animating; // By-pass any unit conversion nodes while ( animating.hasFn ( MFn::kUnitConversion ) ) { animating = DagHelper::getSourceNodeConnectedTo ( animating, ATTR_INPUt ); } return animating; }
void EntityNode::ImportNodeAddedCallback( MObject &addedNode, void* param ) { MAYA_START_EXCEPTION_HANDLING(); MObjectArray (*nodeArrays)[NodeArrays::Count] = (MObjectArray (*)[NodeArrays::Count])param; MObjectHandle handle( addedNode ); if( !handle.isValid() ) { return; } MFnDependencyNode nodeFn( addedNode ); nodeFn.setDoNotWrite( true ); // don't gather certain nodes if( addedNode.hasFn( MFn::kReference ) || addedNode.hasFn( MFn::kPartition ) || addedNode.hasFn( MFn::kDisplayLayerManager ) || addedNode.hasFn( MFn::kDisplayLayer ) || addedNode.hasFn( MFn::kRenderLayerManager ) || addedNode.hasFn( MFn::kRenderLayer ) || addedNode.hasFn( MFn::kScript ) || addedNode.hasFn( MFn::kLightLink ) ) { return; } // don't gather reference objects if( nodeFn.isFromReferencedFile() ) { return; } // don't gather maya-designated "shared" nodes if( nodeFn.isShared() ) { return; } #ifdef _DEBUG MString name = nodeFn.name(); MString type = nodeFn.typeName(); std::cout << " - Importing: " << name.asTChar() << " " << type.asTChar() << std::endl; #endif nodeArrays[ NodeArrays::KeepNodes ]->append( addedNode ); MAYA_FINISH_EXCEPTION_HANDLING(); }