/* static */ bool UsdMayaTranslatorCamera::Read( const UsdGeomCamera& usdCamera, MObject parentNode, const UsdMayaPrimReaderArgs& args, UsdMayaPrimReaderContext* context) { if (!usdCamera) { return false; } const UsdPrim& prim = usdCamera.GetPrim(); const SdfPath primPath = prim.GetPath(); MStatus status; // Create the transform node for the camera. MObject transformObj; if (!UsdMayaTranslatorUtil::CreateTransformNode(prim, parentNode, args, context, &status, &transformObj)) { return false; } // Create the camera shape node. MDagModifier dagMod; MObject cameraObj = dagMod.createNode(_tokens->MayaCameraTypeName.GetText(), transformObj, &status); CHECK_MSTATUS_AND_RETURN(status, false); status = dagMod.doIt(); CHECK_MSTATUS_AND_RETURN(status, false); TF_VERIFY(!cameraObj.isNull()); MFnCamera cameraFn(cameraObj, &status); CHECK_MSTATUS_AND_RETURN(status, false); const std::string cameraShapeName = prim.GetName().GetString() + _tokens->MayaCameraShapeNameSuffix.GetString(); cameraFn.setName(cameraShapeName.c_str(), &status); CHECK_MSTATUS_AND_RETURN(status, false); if (context) { const SdfPath shapePrimPath = primPath.AppendChild(TfToken(cameraShapeName)); context->RegisterNewMayaNode(shapePrimPath.GetString(), cameraObj); } return _ReadToCamera(usdCamera, cameraFn, args, context); }
// Method for iterating over nodes in a dependency graph from top to bottom MStatus OgreExporter::translateNode(MDagPath& dagPath) { if (m_params.exportAnimCurves) { MObject dagPathNode = dagPath.node(); MItDependencyGraph animIter( dagPathNode, MFn::kAnimCurve, MItDependencyGraph::kUpstream, MItDependencyGraph::kDepthFirst, MItDependencyGraph::kNodeLevel, &stat ); if (stat) { for (; !animIter.isDone(); animIter.next()) { MObject anim = animIter.thisNode(&stat); MFnAnimCurve animFn(anim,&stat); std::cout << "Found animation curve: " << animFn.name().asChar() << "\n"; std::cout << "Translating animation curve: " << animFn.name().asChar() << "...\n"; std::cout.flush(); stat = writeAnim(animFn); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } } if (dagPath.hasFn(MFn::kMesh)&&(m_params.exportMesh||m_params.exportMaterial||m_params.exportSkeleton) && (dagPath.childCount() == 0)) { // we have found a mesh shape node, it can't have any children, and it contains // all the mesh geometry data MDagPath meshDag = dagPath; MFnMesh meshFn(meshDag); if (!meshFn.isIntermediateObject()) { std::cout << "Found mesh node: " << meshDag.fullPathName().asChar() << "\n"; std::cout << "Loading mesh node " << meshDag.fullPathName().asChar() << "...\n"; std::cout.flush(); stat = m_pMesh->load(meshDag,m_params); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, mesh skipped\n"; std::cout.flush(); } } } else if (dagPath.hasFn(MFn::kCamera)&&(m_params.exportCameras) && (!dagPath.hasFn(MFn::kShape))) { // we have found a camera shape node, it can't have any children, and it contains // all information about the camera MFnCamera cameraFn(dagPath); if (!cameraFn.isIntermediateObject()) { std::cout << "Found camera node: "<< dagPath.fullPathName().asChar() << "\n"; std::cout << "Translating camera node: "<< dagPath.fullPathName().asChar() << "...\n"; std::cout.flush(); stat = writeCamera(cameraFn); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } else if ( ( dagPath.apiType() == MFn::kParticle ) && m_params.exportParticles ) { // we have found a set of particles MFnDagNode fnNode(dagPath); if (!fnNode.isIntermediateObject()) { std::cout << "Found particles node: "<< dagPath.fullPathName().asChar() << "\n"; std::cout << "Translating particles node: "<< dagPath.fullPathName().asChar() << "...\n"; std::cout.flush(); Particles particles; particles.load(dagPath,m_params); stat = particles.writeToXML(m_params); if (MS::kSuccess == stat) { std::cout << "OK\n"; std::cout.flush(); } else { std::cout << "Error, Aborting operation\n"; std::cout.flush(); return MS::kFailure; } } } // look for meshes and cameras within the node's children for (uint i=0; i<dagPath.childCount(); i++) { MObject child = dagPath.child(i); MDagPath childPath = dagPath; stat = childPath.push(child); if (MS::kSuccess != stat) { std::cout << "Error retrieving path to child " << i << " of: " << dagPath.fullPathName().asChar(); std::cout.flush(); return MS::kFailure; } stat = translateNode(childPath); if (MS::kSuccess != stat) return MS::kFailure; } return MS::kSuccess; }