int CMayaNode::GetChildCount() { MStatus status; MFnDagNode dagNode (m_dagPath, &status); if (status != MS::kSuccess) return 0; return dagNode.childCount(); }
void Exporter::createSceneGraph(MFnDagNode& path, int parentIndex) { Node output; std::vector<std::string> pathparts; output.name = path.fullPathName().asChar(); splitStringToVector(output.name, pathparts, "|"); output.name = pathparts[pathparts.size() - 1]; if (!strcmp(output.name.c_str(), "persp")) return; else if (!strcmp(output.name.c_str(), "top")) return; else if (!strcmp(output.name.c_str(), "side")) return; else if (!strcmp(output.name.c_str(), "front")) return; output.parent = parentIndex; output.transform = path.transformationMatrix().matrix; scene_.sceneGraph.push_back(output); int children = path.childCount(); int parent = scene_.sceneGraph.size() - 1; for (int i = 0; i < children; i++) { cout << path.child(i).apiTypeStr() << endl; if (!strcmp(path.child(i).apiTypeStr(), "kMesh")){ scene_.sceneGraph[parent].type = 1; MFnMesh mesh(path.child(i)); MDagPath dag_path; MItDag dag_iter(MItDag::kBreadthFirst, MFn::kMesh); int y = 0; while (!dag_iter.isDone()) { if (dag_iter.getPath(dag_path)) { MFnDagNode dag_node = dag_path.node(); if (!dag_node.isIntermediateObject()) { if (!strcmp(mesh.partialPathName().asChar(), dag_node.partialPathName().asChar())) scene_.sceneGraph[parent].mesh = y; y++; } } dag_iter.next(); } } // else if (!strcmp(path.child(i).apiTypeStr(), "kCamera")); kan l�gga till fler typer h�r else createSceneGraph(MFnDagNode(path.child(i)), parent); } }
void IterateSelection() { unsigned int i; MSelectionList list; MDagPath dagpath; MFnDagNode fnnode; MGlobal::getActiveSelectionList(list); for(i = 0; i < list.length(); i++) { list.getDagPath(i, dagpath); fnnode.setObject(dagpath); cout << fnnode.name().asChar() << " of type " << fnnode.typeName().asChar() << " is selected" << endl; cout << "has " << fnnode.childCount() << " children" << endl; //Iterate the children for(int j = 0; j < fnnode.childCount(); j++) { MObject childobj; MFnDagNode fnchild; childobj = fnnode.child(j); fnchild.setObject(childobj); cout << "child " << j << " is a " << fnchild.typeName().asChar() << endl; //MFn::Type type = fnchild.type() //if(fnchild.type() == MFn::kMesh) //DumpMesh(dagpath); //DumpMesh2(dagpath); IterateWorldMeshesInSelection(); } } }
// ------------------------------------------------------------ bool SceneGraph::createChildSceneElements ( SceneElement* sceneElement ) { // Get the current path MDagPath dagPath = sceneElement->getPath(); // Now, whip through this node's DAG children MFnDagNode dagFn ( dagPath ); uint childCount = dagFn.childCount(); for ( uint i = 0; i < childCount; ++i ) { MObject child = dagFn.child ( i ); MDagPath childDagPath = dagPath; childDagPath.push ( child ); SceneElement* childSceneElement = createSceneElement ( childDagPath, sceneElement ); // Recursive call to take the children createChildSceneElements ( childSceneElement ); } return true; }
// -------------------------------------------------------------------------------------------- MStatus polyModifierCmd::processUpstreamNode( modifyPolyData& data ) // -------------------------------------------------------------------------------------------- { MStatus status = MS::kSuccess; // Declare our function sets - Although dagNodeFn derives from depNodeFn, we need // both since dagNodeFn can only refer to DAG objects. // We will use depNodeFn for all times other when dealing // with the DAG. // MFnDependencyNode depNodeFn; MFnDagNode dagNodeFn; // Use the selected node's plug connections to find the upstream plug. // Since we are looking at the selected node's inMesh attribute, it will // always have only one connection coming in if it has history, and none // otherwise. // // If there is no history, copy the selected node and place it ahead of the // modifierNode as the new upstream node so that the modifierNode has an // input mesh to operate on. // //save the meshDagPath for later use MDagPath::getAPathTo(data.meshNodeShape,myMeshPath); MPlugArray tempPlugArray; if( fHasHistory ) { // Since we have history, look for what connections exist on the // meshNode "inMesh" plug. "inMesh" plugs should only ever have one // connection. // data.meshNodeDestPlug.connectedTo( tempPlugArray, true, false); // ASSERT: Only one connection should exist on meshNodeShape.inMesh! // MStatusAssert( (tempPlugArray.length() == 1), "tempPlugArray.length() == 1 -- 0 or >1 connections on meshNodeShape.inMesh" ); data.upstreamNodeSrcPlug = tempPlugArray[0]; // Construction history only deals with shapes, so we can grab the // upstreamNodeShape off of the source plug. // // Dieser Bereich muss bleiben, weil diese Attribute noch bentigt werden data.upstreamNodeShape = data.upstreamNodeSrcPlug.node(); depNodeFn.setObject( data.upstreamNodeShape ); data.upstreamNodeSrcAttr = data.upstreamNodeSrcPlug.attribute(); // Disconnect the upstream node and the selected node, so we can // replace them with our own connections below. // MPlug nodePlug(data.meshNodeShape,data.meshNodeDestAttr ) ; INVIS(cout<<data.upstreamNodeSrcPlug.name().asChar()<<" --|-- "<<nodePlug.name().asChar()<<endl); status = fDGModifier.disconnect( data.upstreamNodeSrcPlug, nodePlug ); MCheckStatus( status, "Disconnect Upstream mit meshNode" ); } else // No History (!fHasHistory) { // Use the DAG node function set to duplicate the shape of the meshNode. // The duplicate method will return an MObject handle to the transform // of the duplicated shape, so traverse the dag to locate the shape. Store // this duplicate shape as our "upstream" node to drive the input for the // modifierNode. // depNodeFn.setObject( data.meshNodeShape ); data.upstreamNodeTransform = createDuplicate.createNode("mesh"); createDuplicate.doIt(); dagNodeFn.setObject( data.upstreamNodeTransform ); // Ensure that our upstreamNode is pointing to a shape. // MStatusAssert( (0 < dagNodeFn.childCount()), "0 < dagNodeFn.childCount() -- Duplicate meshNode transform has no shape." ); data.upstreamNodeShape = dagNodeFn.child(0); MPlug outMeshPlug = depNodeFn.findPlug("outMesh"); depNodeFn.setObject(data.upstreamNodeShape); //jetzt inMesh upstreamNodeShape mit outMesh meshShape füllen MDGModifier tempMod; tempMod.connect(outMeshPlug,depNodeFn.findPlug("inMesh")); tempMod.doIt(); //force DGEVAL MString cmd = "dgeval -src "; cmd += depNodeFn.name(); cmd += ".outMesh"; MGlobal::executeCommand(cmd,false,false); tempMod.undoIt(); // Re-parent the upstreamNodeShape under our original transform // reparentDuplicate.reparentNode( data.upstreamNodeShape, data.meshNodeTransform ); reparentDuplicate.doIt(); deleteDuplicate.deleteNode( data.upstreamNodeTransform ); deleteDuplicate.doIt(); /* status = fDagModifier.reparentNode( data.upstreamNodeShape, data.meshNodeTransform ); MCheckStatus( status, "reparentNode" ); // Perform the DAG re-parenting // // Note: This reparent must be performed before the deleteNode() is called. // See polyModifierCmd.h (see definition of fDagModifier) for more details. // status = fDagModifier.doIt(); MCheckStatus( status, "fDagModifier.doIt()" ); */ // Mark the upstreamNodeShape (the original shape) as an intermediate object // (making it invisible to the user) // dagNodeFn.setObject( data.upstreamNodeShape ); dagNodeFn.setIntermediateObject( true ); // Get the upstream node source attribute // data.upstreamNodeSrcAttr = dagNodeFn.attribute( "outMesh" ); data.upstreamNodeSrcPlug = MPlug(data.upstreamNodeShape, data.upstreamNodeSrcAttr); /* // Remove the duplicated transform node (clean up) // status = fDagModifier.deleteNode( data.upstreamNodeTransform ); MCheckStatus( status, "deleteNode" ); // Perform the DAG delete node // // Note: This deleteNode must be performed after the reparentNode() method is // completed. See polyModifierCmd.h (see definition of fDagModifier) for // details. // status = fDagModifier.doIt(); MCheckStatus( status, "fDagModifier.doIt()" ); */ // Cache the DAG path to the duplicate shape // dagNodeFn.getPath( fDuplicateDagPath ); //finally delete the tweaks to avoid double transformation deleteTweaks(); } return status; }
MStatus polyModifierCmd::processUpstreamNode( modifyPolyData& data ) { MStatus status = MS::kSuccess; // Declare our function sets - Although dagNodeFn derives from depNodeFn, we need // both since dagNodeFn can only refer to DAG objects. // We will use depNodeFn for all times other when dealing // with the DAG. // MFnDependencyNode depNodeFn; MFnDagNode dagNodeFn; // Use the selected node's plug connections to find the upstream plug. // Since we are looking at the selected node's inMesh attribute, it will // always have only one connection coming in if it has history, and none // otherwise. // // If there is no history, copy the selected node and place it ahead of the // modifierNode as the new upstream node so that the modifierNode has an // input mesh to operate on. // MPlugArray tempPlugArray; if( fHasHistory ) { // Since we have history, look for what connections exist on the // meshNode "inMesh" plug. "inMesh" plugs should only ever have one // connection. // data.meshNodeDestPlug.connectedTo( tempPlugArray, true, false); // ASSERT: Only one connection should exist on meshNodeShape.inMesh! // MStatusAssert( (tempPlugArray.length() == 1), "tempPlugArray.length() == 1 -- 0 or >1 connections on meshNodeShape.inMesh" ); data.upstreamNodeSrcPlug = tempPlugArray[0]; // Construction history only deals with shapes, so we can grab the // upstreamNodeShape off of the source plug. // data.upstreamNodeShape = data.upstreamNodeSrcPlug.node(); depNodeFn.setObject( data.upstreamNodeShape ); data.upstreamNodeSrcAttr = data.upstreamNodeSrcPlug.attribute(); // Disconnect the upstream node and the selected node, so we can // replace them with our own connections below. // fDGModifier.disconnect( data.upstreamNodeShape, data.upstreamNodeSrcAttr, data.meshNodeShape, data.meshNodeDestAttr ); } else // No History (!fHasHistory) { // Use the DAG node function set to duplicate the shape of the meshNode. // The duplicate method will return an MObject handle to the transform // of the duplicated shape, so traverse the dag to locate the shape. Store // this duplicate shape as our "upstream" node to drive the input for the // modifierNode. // dagNodeFn.setObject( data.meshNodeShape ); data.upstreamNodeTransform = dagNodeFn.duplicate( false, false ); dagNodeFn.setObject( data.upstreamNodeTransform ); // Ensure that our upstreamNode is pointing to a shape. // MStatusAssert( (0 < dagNodeFn.childCount()), "0 < dagNodeFn.childCount() -- Duplicate meshNode transform has no shape." ); data.upstreamNodeShape = dagNodeFn.child(0); // Re-parent the upstreamNodeShape under our original transform // status = fDagModifier.reparentNode( data.upstreamNodeShape, data.meshNodeTransform ); MCheckStatus( status, "reparentNode" ); // Perform the DAG re-parenting // // Note: This reparent must be performed before the deleteNode() is called. // See polyModifierCmd.h (see definition of fDagModifier) for more details. // status = fDagModifier.doIt(); MCheckStatus( status, "fDagModifier.doIt()" ); // Mark the upstreamNodeShape (the original shape) as an intermediate object // (making it invisible to the user) // dagNodeFn.setObject( data.upstreamNodeShape ); dagNodeFn.setIntermediateObject( true ); // Get the upstream node source attribute // data.upstreamNodeSrcAttr = dagNodeFn.attribute( "outMesh" ); // Remove the duplicated transform node (clean up) // status = fDagModifier.deleteNode( data.upstreamNodeTransform ); MCheckStatus( status, "deleteNode" ); // Perform the DAG delete node // // Note: This deleteNode must be performed after the reparentNode() method is // completed. See polyModifierCmd.h (see definition of fDagModifier) for // details. // status = fDagModifier.doIt(); MCheckStatus( status, "fDagModifier.doIt()" ); // Cache the DAG path to the duplicate shape // dagNodeFn.getPath( fDuplicateDagPath ); } return status; }
void EntityNode::LoadArt() { MStatus stat; bool callbackRemoved = false; if( s_EditNodeAddedCBId != -1 ) { MDGMessage::removeCallback( s_EditNodeAddedCBId ); s_EditNodeAddedCBId = -1; callbackRemoved = true; } UnloadArt(); MString artFilePath; GetArtFilePath( artFilePath ); std::cout << "Importing from: " << artFilePath.asTChar() << "..." << std::endl; // add the callback to catch all the imported objects MObjectArray objectArrays[NodeArrays::Count]; s_ImportNodeAddedCBId = MDGMessage::addNodeAddedCallback( ImportNodeAddedCallback, kDefaultNodeType, &objectArrays ); // import stuff MFileIO::import( artFilePath, NULL, false ); // remove the callback MDGMessage::removeCallback( s_ImportNodeAddedCBId ); // add all imported stuff under this guy's transform MFnDagNode nodeFn( thisMObject() ); for( u32 i=0; i<objectArrays[NodeArrays::KeepNodes].length(); ++i ) { if( objectArrays[NodeArrays::KeepNodes][i].isNull() ) { continue; } MObjectHandle handle( objectArrays[NodeArrays::KeepNodes][i] ); if ( !handle.isValid() ) { continue; } // We should be getting only MFnDagNode in here, but just in case MFnDagNode dagFn( objectArrays[NodeArrays::KeepNodes][i], &stat ); if ( stat == MStatus::kSuccess ) { stat = dagFn.setDoNotWrite( true ); } else { MFnDependencyNode depNodeFn( objectArrays[NodeArrays::KeepNodes][i], &stat ); stat = depNodeFn.setDoNotWrite( true ); } #ifdef _DEBUG MString name = dagFn.name(); MString type = dagFn.typeName(); std::string nodeTypeStr( objectArrays[NodeArrays::KeepNodes][i].apiTypeStr() ); if ( name.length() ) { std::cout << " - Importing Child: " << name.asTChar() << " " << type.asTChar() << "(" << nodeTypeStr << ")" << std::endl; } #endif AddImportNode( objectArrays[NodeArrays::KeepNodes][i] ); nodeFn.addChild( objectArrays[NodeArrays::KeepNodes][i] ); } for( u32 i=0; i<objectArrays[NodeArrays::DeleteNodes].length(); ++i ) { MGlobal::deleteNode( objectArrays[NodeArrays::DeleteNodes][i] ); } MFnDagNode otherFn; for( u32 i=0 ; i<nodeFn.childCount(); ++i ) { MObject child = nodeFn.child( i ); if( !child.hasFn( MFn::kDagNode ) ) { continue; } otherFn.setObject( child ); if( otherFn.typeId() == EntityNode::s_TypeID ) { MDagModifier mod; u32 numChild = otherFn.childCount(); for( u32 j = 0; j < numChild; ++j ) { stat = mod.reparentNode( otherFn.child( j ), thisMObject() ); } mod.doIt(); MGlobal::deleteNode( child ); break; } } std::cout << "Done" << std::endl; }