void printAllInstancesUsingIterator() { // // Just use the MItInstancer iterator to enumerate all particles in // all instancers in the scene. // MItInstancer it; while( !it.isDone() ) { MObject instancerNode = it.instancer(); MDagPath instancerPath = it.instancerPath(); MDagPath instancePath = it.path(); MMatrix instanceMatrix = it.matrix(); MString instancerNodeName = MFnDependencyNode(instancerNode).name(); MString instancerPathName = instancerPath.fullPathName(); MString instancePathName = instancePath.fullPathName(); MMatrix pathMatrix = instancePath.inclusiveMatrix(); MMatrix finalMatrixForPath = pathMatrix * instanceMatrix; MPoint pos = MPoint::origin * finalMatrixForPath; char str[512]; sprintf( str, "Instancer node %s, instancer path %s, instancing path %s at position (%lf,%lf,%lf)", instancerNodeName.asChar(), instancerPathName.asChar(), instancePathName.asChar(), pos.x, pos.y, pos.z ); MGlobal::displayInfo( MString(str) ); it.next(); } }
void TestDeformer::__debugMeshInfo(const char* msg, MObject &meshMobj) { #ifdef _DEBUG MStatus status; MFnMesh fnMesh(meshMobj, &status); CHECK_MSTATUS(status); __debug("%s(), fnMesh.fullPathName=%s", msg, fnMesh.fullPathName().asChar()); __debug("%s(), fnMesh.name=%s", msg, fnMesh.name().asChar()); MDagPath path; CHECK_MSTATUS(fnMesh.getPath(path)); __debug("%s(), path=%s", msg, path.fullPathName().asChar()); MDagPath dagpath = fnMesh.dagPath(&status); CHECK_MSTATUS(status); __debug("%s(), dagpath=%s", msg, dagpath.fullPathName().asChar()); MFnDependencyNode fnDNode(meshMobj, &status); CHECK_MSTATUS(status);// __debug("%s(), name=%s", msg, fnDNode.name().asChar()); MFnDagNode fnDagNode(meshMobj, &status); CHECK_MSTATUS(status);// MDagPath path2; CHECK_MSTATUS(fnDagNode.getPath(path2));// __debug("%s(), path2=%s", msg, path2.fullPathName().asChar()); MDagPath dagpath2 = fnDagNode.dagPath(&status); CHECK_MSTATUS(status);// __debug("%s(), dagpath2=%s", msg, dagpath2.fullPathName().asChar()); #endif }
void userDAGGenericCB(MDagMessage::DagMessage msg, MDagPath &child, MDagPath &parent, void *) { MString dagStr("DAG Changed - "); switch (msg) { case MDagMessage::kParentAdded: dagStr += "Parent Added: "; break; case MDagMessage::kParentRemoved: dagStr += "Parent Removed: "; break; case MDagMessage::kChildAdded: dagStr += "Child Added: "; break; case MDagMessage::kChildRemoved: dagStr += "Child Removed: "; break; case MDagMessage::kChildReordered: dagStr += "Child Reordered: "; break; default: dagStr += "Unknown Type: "; break; } dagStr += "child = "; dagStr += child.fullPathName(); dagStr += ", parent = "; dagStr += parent.fullPathName(); // Check to see if the parent is the world object. // MStatus pStat; parent.transform(&pStat); if (MS::kInvalidParameter == pStat) { dagStr += "(WORLD)"; } // Install callbacks if node is not in the model. // Callback is for node added to model. bool incomplete = false; if ( dagNotInModel( child ) ) { installNodeAddedCallback( child ); incomplete = true; } if ( dagNotInModel( parent ) ) { installNodeAddedCallback( parent); incomplete = true; } // Warn user that dag path info may be // incomplete if (incomplete) dagStr += "\t// May be incomplete!"; MGlobal::displayInfo(dagStr); }
bool HesperisPolygonalMeshIO::CreateMeshData(APolygonalMesh * data, const MDagPath & path) { MGlobal::displayInfo(MString("todo poly mesh write ")+path.fullPathName()); MStatus stat; MFnMesh fmesh(path.node(), &stat); if(!stat) { MGlobal::displayInfo(MString(" not a mesh ") + path.fullPathName()); return false; } unsigned np = fmesh.numVertices(); unsigned nf = fmesh.numPolygons(); unsigned ni = fmesh.numFaceVertices(); data->create(np, ni, nf); Vector3F * pnts = data->points(); unsigned * inds = data->indices(); unsigned * cnts = data->faceCounts(); MPointArray ps; MPoint wp; MMatrix worldTm; worldTm = GetWorldTransform(path); fmesh.getPoints(ps, MSpace::kObject); unsigned i = 0; for(;i<np;i++) { wp = ps[i] * worldTm; pnts[i].set((float)wp.x, (float)wp.y, (float)wp.z); } unsigned j; unsigned acc = 0; MIntArray vertices; MItMeshPolygon faceIt(path); for(i=0; !faceIt.isDone(); faceIt.next(), i++) { cnts[i] = faceIt.polygonVertexCount(); faceIt.getVertices(vertices); for(j = 0; j < vertices.length(); j++) { inds[acc] = vertices[j]; acc++; } } data->computeFaceDrift(); return true; }
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; }
void LiveScene::getChildDags( const MDagPath& dagPath, MDagPathArray& paths ) const { for( unsigned i=0; i < dagPath.childCount(); ++i ) { MDagPath childPath = dagPath; childPath.push( dagPath.child( i ) ); if( dagPath.length() == 0 ) { // bizarrely, this iterates through things like the translate manipulator and // the view cube too, so lets skip them so they don't show up: if( childPath.node().hasFn( MFn::kManipulator3D ) ) { continue; } // looks like it also gives us the ground plane, so again, lets skip that: if( childPath.fullPathName() == "|groundPlane_transform" ) { continue; } } paths.append( childPath ); } }
void liqIPRNodeMessage::onOtherNode(const MString &node, std::vector<MString> &updateObjectName) { MStringArray descendents; MString cmd("listRelatives -allDescendents "+node); MGlobal::executeCommand(cmd, descendents); for(int i=0; i<descendents.length(); ++i) { addUpdateObject(updateObjectName, descendents[i]);//record descendents[i] MDagPath dagPath; getDagPathByName(dagPath, descendents[i].asChar()); if( dagPath.node().hasFn(MFn::kTransform) ) { onOtherNode(descendents[i], updateObjectName);//visit descendents[i] } else if( dagPath.node().hasFn(MFn::kMesh) ) { std::vector<std::string> shaderPlugs; liquid::RendererMgr::getInstancePtr()-> getRenderer()->getValidShaderPlugsInShadingGroup(shaderPlugs); IfMErrorWarn(dagPath.extendToShape());//extend to shape std::vector<std::string> shadingGroups; getShadingGroups(dagPath.fullPathName(), shadingGroups); for(std::size_t j=0; j<shadingGroups.size(); ++j)//for each shading group { MString shadingGroup(shadingGroups[j].c_str()); for(std::size_t k=0; k<shaderPlugs.size(); ++k)//for each shader plug { MString shaderPlug(shaderPlugs[k].c_str()); int isShaderPlugExist; cmd = "attributeQuery -node \""+shadingGroup+"\" -ex \""+shaderPlug+"\""; IfMErrorMsgWarn(MGlobal::executeCommand( cmd, isShaderPlugExist), cmd); if( isShaderPlugExist ) { //get the source shade node of $shadingGroup.$shaderPlug MStringArray shaders; cmd = "listConnections -s true -d false -plugs false (\""+shadingGroup+"\" + \"."+shaderPlug+"\")"; IfMErrorMsgWarn(MGlobal::executeCommand( cmd, shaders), cmd); if( shaders.length() > 0 )//has source shader node { onShaderNode(shaders[0], updateObjectName); }//if( shaders.length() > 0 )//has source shader node }//if( isShaderPlugExist ) }//for each shader plug }//for each shading group }//kMesh }//for(int i=0; i<descendents.length(); ++i) }
bool HesperisCurveCreator::CheckExistingCurves(CurveGroup * geos, MObject &target) { MDagPath root; MDagPath::getAPathTo(target, root); std::map<std::string, MDagPath > existing; ASearchHelper::AllTypedPaths(existing, root, MFn::kNurbsCurve); const unsigned ne = existing.size(); if(ne < 1) return false; if(ne != geos->numCurves()) return false; unsigned n = 0; std::map<std::string, MDagPath >::const_iterator it = existing.begin(); for(;it!=existing.end();++it) { MFnNurbsCurve fcurve(it->second.node()); n += fcurve.numCVs(); } if(n!=geos->numPoints()) { AHelper::Info<MString>("existing curves nv don't match cached data ", root.fullPathName()); return false; } MGlobal::displayInfo(" existing curves matched"); return true; }
/** * Find the hash table entry for the given object. */ liqRibNodePtr liqRibHT::find( MString nodeName, MDagPath path, ObjectType objType /*objType = MRT_Unknown*/ ) { CM_TRACE_FUNC("liqRibHT::find("<<nodeName.asChar()<<","<<path.fullPathName().asChar()<<","<<objType<<")"); LIQDEBUGPRINTF( "-> finding node in hash table using object, %s\n", nodeName.asChar() ); liqRibNodePtr result; ulong hc; for( unsigned index( 0 ); index < RibHashVec.size(); index++ ) if( RibHashVec[ index ] == nodeName.asChar() && objTypeVec[ index ] == objType ) { hc = index; break; } LIQDEBUGPRINTF( "-> Done\n" ); RNMAP::iterator iter( RibNodeMap.find( hc ) ); while( ( iter != RibNodeMap.end() ) && ( (*iter).first == hc ) ) { if( (*iter).second->path() == path ) { result = (*iter).second; iter = RibNodeMap.end(); } else iter++; } LIQDEBUGPRINTF( "-> finished finding node in hash table using object\n" ); return result; }
// -------------------------------------- MString ReferenceManager::getReferenceFilename ( const MDagPath& path ) { MString command = MString("reference -q -f ") + path.fullPathName(); MString filename; MGlobal::executeCommand(command, filename); return filename; }
//----------------------------------------------------------------------------- // //----------------------------------------------------------------------------- MStatus CVsSkinnerCmd::DoLs() { MSelectionList tmpList; if ( m_undo.ArgDatabase().isFlagSet( kOptSelected ) ) { MSelectionList skinnerNodes; m_undo.ArgDatabase().getObjects( skinnerNodes ); GetSpecifiedSkinnerNodes( skinnerNodes, tmpList ); } else { MDagPath eDagPath; FindSkinnerNodesInHierarchy( eDagPath, tmpList ); } const bool longPath( m_undo.ArgDatabase().isFlagSet( kOptLong ) ); MStringArray result; MDagPath mDagPath; for ( MItSelectionList sIt( tmpList ); !sIt.isDone(); sIt.next() ) { if ( sIt.getDagPath( mDagPath ) ) { result.append( longPath ? mDagPath.fullPathName() : mDagPath.partialPathName() ); } } setResult( result ); return MS::kSuccess; }
MStatus exampleCameraSetViewCmd::testResults(MPx3dModelView &view) { MObject cstObj = MObject::kNullObj; MStatus stat = view.getCameraSet(cstObj); if (stat != MS::kSuccess) return stat; cout << "fCameraList.length() = " << fCameraList.length() << endl; cout << "fCameraList = " << fCameraList << endl; MFnCameraSet cstFn(cstObj); unsigned int numLayers = cstFn.getNumLayers(); cout << "view.cameraSet.numLayers = " << numLayers << endl; cout << "Cameras:" << endl; for (unsigned int i=0; i<numLayers; i++) { MDagPath camPath; cstFn.getLayerCamera(i, camPath); camPath.extendToShape(); cout << " " << camPath.fullPathName() << endl; } return MS::kSuccess; }
//--------------------------- String DocumentExporter::dagPathToColladaId(const MDagPath& dagPath, bool removeFirstNamespace) { // Make an unique COLLADA Id from a dagPath. // We are free to use anything we want for Ids. For now use // full path name to ensure id uniqueness. DagPath partial name can not be used // because it can lead to issues when referencing nodes sharing the same name. return mayaNameToColladaName(dagPath.fullPathName(), false, removeFirstNamespace); }
bool CacheMeshSampler::addSampleFromMesh(MFnMesh& mesh) { MDagPath dagPath; mesh.getPath(dagPath); MString path = dagPath.fullPathName(); return fAttributeSet.updateAnimatedChannels( fIsAnimated, AttributeSet(mesh, fNeedUVs, fUseBaseTessellation), path); }
void liqWriteArchive::outputObjectName(const MDagPath &objDagPath) { MString name = objDagPath.fullPathName(); RiArchiveRecord(RI_VERBATIM, "\n"); outputIndentation(); RtString ribname = const_cast< char* >( name.asChar() ); RiAttribute( "identifier", "name", &ribname, RI_NULL ); }
bool HesperisIO::AddTransform(const MDagPath & path, HesperisFile * file, const std::string & beheadName) { MFnDagNode fdg(path); if(fdg.parentCount() < 1) return false; MGlobal::displayInfo(MString("hes io add transform ")+path.fullPathName()); MObject oparent = fdg.parent(0); MFnDagNode fp(oparent); MDagPath pp; fp.getPath(pp); AddTransform(pp, file, beheadName); std::string nodeName = path.fullPathName().asChar(); if(beheadName.size() > 1) SHelper::behead(nodeName, beheadName); // todo extract tm file->addTransform(nodeName, new BaseTransform); return true; }
bool operator() ( const MDagPath &dagPath, const IECore::SceneInterface::Name &tag, int filter ) { MString p = dagPath.fullPathName(); IECorePython::ScopedGILLock gilLock; try { return m_has( p.asChar(), tag, filter ); } catch ( error_already_set ) { PyErr_Print(); throw IECore::Exception( std::string( "Python exception while checking IECoreMaya::LiveScene tag " + tag.string() ) ); } }
IECore::ConstObjectPtr operator() ( const MDagPath &dagPath, const IECore::SceneInterface::Name &attr ) { MString p = dagPath.fullPathName(); IECorePython::ScopedGILLock gilLock; try { return extract<IECore::ConstObjectPtr>(m_read( p.asChar(), attr )); } catch ( error_already_set ) { PyErr_Print(); throw IECore::Exception( std::string( "Python exception while evaluating IECoreMaya::LiveScene attribute " + attr.string() ) ); } }
bool HesperisIO::IsCurveValid(const MDagPath & path) { MStatus stat; MFnNurbsCurve fcurve(path.node(), &stat); if(!stat) { // MGlobal::displayInfo(path.fullPathName() + " is not a curve!"); return false; } if(fcurve.numCVs() < 4) { MGlobal::displayInfo(path.fullPathName() + " has less than 4 cvs!"); return false; } return true; }
MStatus meshInfo3::doIt( const MArgList& args ) { MStatus stat = MS::kSuccess; MSelectionList selection; MGlobal::getActiveSelectionList( selection ); MDagPath dagPath; MObject component; int i, polyCount, polyIndex, vertCount; MPoint p; MString txt; MItSelectionList iter( selection ); for ( ; !iter.isDone(); iter.next() ) { iter.getDagPath( dagPath, component ); MItMeshPolygon polyIter( dagPath, component, &stat ); if( stat == MS::kSuccess ) { txt += MString( "Object: " ) + dagPath.fullPathName() + "\n"; polyCount = polyIter.count(); txt += MString("# Polygons: ") + polyCount + "\n"; for( ; !polyIter.isDone(); polyIter.next() ) { polyIndex = polyIter.index(); txt += MString("Poly ") + polyIndex + "\n"; vertCount = polyIter.polygonVertexCount(); txt += MString(" # Verts: ") + vertCount + "\n"; for( i=0; i < vertCount; i++ ) { p = polyIter.point( i, MSpace::kWorld ); txt += MString(" (") + p.x + ", " + p.y + ", " + p.z + ")"; } txt += "\n"; } } } MGlobal::displayInfo( txt ); return MS::kSuccess; }
void EntityInstanceNode::AllDagChangesCallback( MDagMessage::DagMessage dagMsg, MDagPath& child, MDagPath &parent, void* clientData ) { MAYA_START_EXCEPTION_HANDLING(); MString message; switch( dagMsg ) { case MDagMessage::kParentAdded: message += "kParentAdded --"; break; case MDagMessage::kParentRemoved: message += "kParentRemoved --"; break; case MDagMessage::kChildAdded: message += "kChildAdded --"; break; case MDagMessage::kChildRemoved: message += "kChildRemoved --"; break; case MDagMessage::kChildReordered: message += "kChildReordered --"; break; case MDagMessage::kInstanceRemoved: message += "kInstanceRemoved --"; break; default: message += "Some crap --"; } message += " parent: "; message += parent.fullPathName(); message += " child: "; message += child.fullPathName(); MGlobal::displayInfo( message ); MAYA_FINISH_EXCEPTION_HANDLING(); }
MStatus ReferenceManager::getTopLevelReferenceNode(const MDagPath & dagPath, MObject & outReferenceNode) { MStatus status; MFnDagNode fnDagNode(dagPath, &status); if (!status) return status; bool isFromReferencedFile = fnDagNode.isFromReferencedFile(&status); if (!status) return status; if (!isFromReferencedFile) { // dagPath is not a reference return MS::kFailure; } // Get full dag path MString fullPathName; fullPathName = dagPath.fullPathName(&status); if (!status) return status; // Get nearest reference node MString RNPath; MString command = MString("referenceQuery -referenceNode ") + fullPathName; status = MGlobal::executeCommand(command, RNPath); if (!status) return status; MObject RN = DagHelper::getNode(RNPath); if (RN.isNull()) return MS::kFailure; MFnReference fnRN(RN, &status); if (!status) return status; // Get parent most reference node MObject parentRN = fnRN.parentReference(&status); if (!status) return status; while (!parentRN.isNull()) { RN = parentRN; status = fnRN.setObject(parentRN); if (!status) return status; parentRN = fnRN.parentReference(&status); if (!status) return status; } outReferenceNode = RN; return MS::kSuccess; }
bool util::isAncestorDescendentRelationship(const MDagPath & path1, const MDagPath & path2) { unsigned int length1 = path1.length(); unsigned int length2 = path2.length(); unsigned int diff; if (length1 == length2 && !(path1 == path2)) return false; MDagPath ancestor, descendent; if (length1 > length2) { ancestor = path2; descendent = path1; diff = length1 - length2; } else { ancestor = path1; descendent = path2; diff = length2 - length1; } descendent.pop(diff); bool ret = (ancestor == descendent); if (ret) { MString err = path1.fullPathName() + " and "; err += path2.fullPathName() + " have parenting relationships"; MGlobal::displayError(err); } return ret; }
bool operator() ( const MDagPath &dagPath, const IECore::SceneInterface::Name &attr ) { // Use with care when registering a Python function. // MDagPath::fullPathName() is a slow API. We allow registering the "might have" callback from Python // for compatibility with IECoreMaya C++ API but registering a Python "might have" function may spoil the efficiency. MString p = dagPath.fullPathName(); IECorePython::ScopedGILLock gilLock; try { return m_mightHave( p.asChar(), attr ); } catch ( error_already_set ) { PyErr_Print(); throw IECore::Exception( std::string( "Python exception while evaluating IECoreMaya::LiveScene attribute " + attr.string() ) ); } }
MStatus InstanceCallbackCmd::doIt( const MArgList& args ) { MStatus status = MS::kSuccess; // Draw a circle and get its dagPath // using an iterator MGlobal::executeCommand("circle"); MFnNurbsCurve circle; MDagPath dagPath; MItDependencyNodes iter( MFn::kNurbsCurve , &status); for(iter.reset(); !iter.isDone() ; iter.next()) { MObject item = iter.item(); if(item.hasFn(MFn::kNurbsCurve)) { circle.setObject(item); circle.getPath(dagPath); MGlobal::displayInfo("DAG_PATH is " + dagPath.fullPathName()); if(dagPath.isValid()) { // register callback for instance add AND remove // MDagMessage::addInstanceAddedCallback ( dagPath,addCallbackFunc, NULL, &status); MDagMessage::addInstanceRemovedCallback ( dagPath,remCallbackFunc, NULL, &status); MGlobal::displayInfo("CALLBACK ADDED FOR INSTANCE ADD/REMOVE"); } } } if (status != MS::kSuccess) { MGlobal::displayInfo("STATUS RETURNED IS NOT SUCCESS"); } return status; }
void VertexPolyColourCommand::AddJob(MDagPath& dagPath, MObject& component) { // Add mesh to list of unique meshes MeshData* meshData = NULL; for (size_t i = 0; i < m_meshes.size(); i++) { if (dagPath.fullPathName() == m_meshes[i]->dagPath.fullPathName()) { meshData = m_meshes[i]; break; } } if (meshData == NULL) { meshData = new MeshData(dagPath); m_meshes.push_back(meshData); } #if MAYA_API_VERSION >= 700 // If a read or write colour set is forced, check whether the mesh contains this set, // if not, skip the operation if (m_forceReadColourSetName.length() > 0) { if (MeshHasColourSet(*meshData->mesh, m_forceReadColourSetName)) meshData->readColorSetName = m_forceReadColourSetName; else return; } if (m_forceWriteColourSetName.length() > 0) { if (MeshHasColourSet(*meshData->mesh, m_forceWriteColourSetName)) meshData->writeColorSetName = m_forceWriteColourSetName; else return; } #endif VertexColourJob* job = new VertexColourJob(meshData); job->components = component; m_jobs.push_back(job); meshData->jobs.push_back(job); }
bool findCamera(MDagPath& dagPath) { if (dagPath.node().hasFn(MFn::kCamera)) return true; uint numChilds = dagPath.childCount(); for (uint chId = 0; chId < numChilds; chId++) { MDagPath childPath = dagPath; MStatus stat = childPath.push(dagPath.child(chId)); if (!stat) { continue; } MString childName = childPath.fullPathName(); return findCamera(childPath); } return false; }
// Node added to model callback. static void userNodeAddedCB(MObject& node,void *clientData) { MStatus status; if (! node.isNull()) { bool doDisplay = true; MDagPath path; status = MDagPath::getAPathTo(node,path); if ( status.error() ) { doDisplay = false; MGlobal::displayInfo("Error: failed to get dag path to node."); } if ( doDisplay ) { MString s = path.fullPathName(); MString info("DAG Model - Node added: "); info+= s; path.transform(&status); if (MS::kInvalidParameter == status) { info += "(WORLD)"; } MGlobal::displayInfo(info); } } // remove the callback MCallbackId id = MMessage::currentCallbackId(); MMessage::removeCallback(id); // listen for removal message /* MCallbackId id = */ MModelMessage::addNodeRemovedFromModelCallback( node, userNodeRemovedCB, 0, &status ); if ( status.error() ) { MGlobal::displayError("Failed to install node removed from model callback.\n"); return; } }
void operator() ( const MDagPath &dagPath, IECore::SceneInterface::NameList &tags, int filter ) { MString p = dagPath.fullPathName(); IECorePython::ScopedGILLock gilLock; object o; try { o = m_read( p.asChar(), filter ); } catch ( error_already_set ) { PyErr_Print(); throw IECore::Exception( std::string( "Python exception while evaluating IECoreMaya::LiveScene tags" ) ); } extract<list> l( o ); if ( !l.check() ) { throw IECore::InvalidArgumentException( std::string( "Invalid value! Expecting a list of strings." ) ); } IECorePython::listToSceneInterfaceNameList( l(), tags ); }
void DMPDSExporter::traverseSubSkeleton( DMPParameters* param, const MDagPath& dagPath ) { MStatus stat; fillSubSkeleton(param, dagPath); // look for meshes and cameras within the node's children for (unsigned int i=0; i<dagPath.childCount(); i++) { MObject child = dagPath.child(i); MDagPath childPath = dagPath; stat = childPath.push(child); if (MStatus::kSuccess != stat) { std::cout << "Error retrieving path to child " << i << " of: " << dagPath.fullPathName().asChar(); std::cout.flush(); return; } fillSubSkeleton(param, childPath); if (MStatus::kSuccess != stat) { return; } } }