void usdWriteJob::endJob() { mJobCtx.processInstances(); UsdPrimSiblingRange usdRootPrims = mJobCtx.mStage->GetPseudoRoot().GetChildren(); // Write Variants (to first root prim path) UsdPrim usdRootPrim; TfToken defaultPrim; if (!usdRootPrims.empty()) { usdRootPrim = *usdRootPrims.begin(); defaultPrim = usdRootPrim.GetName(); } if (usdRootPrim && mRenderLayerObjs.length() > 1 && !mJobCtx.mArgs.usdModelRootOverridePath.IsEmpty()) { // Get RenderLayers // mArgs.usdModelRootOverridePath: // Require mArgs.usdModelRootOverridePath to be set so that // the variants are put under a UsdPrim that references a BaseModel // prim that has all of the geometry, transforms, and other details. // This needs to be done since "local" values have stronger precedence // than "variant" values, but "referencing" will cause the variant values // to take precedence. defaultPrim = writeVariants(usdRootPrim); } // Restoring the currentRenderLayer MFnRenderLayer currentLayer(MFnRenderLayer::currentLayer()); if (currentLayer.name() != mCurrentRenderLayerName) { MGlobal::executeCommand(MString("editRenderLayerGlobals -currentRenderLayer ")+ mCurrentRenderLayerName, false, false); } postCallback(); // Unfortunately, MGlobal::isZAxisUp() is merely session state that does // not get recorded in Maya files, so we cannot rely on it being set // properly. Since "Y" is the more common upAxis, we'll just use // isZAxisUp as an override to whatever our pipeline is configured for. TfToken upAxis = UsdGeomGetFallbackUpAxis(); if (MGlobal::isZAxisUp()){ upAxis = UsdGeomTokens->z; } UsdGeomSetStageUpAxis(mJobCtx.mStage, upAxis); if (usdRootPrim){ // We have already decided above that 'usdRootPrim' is the important // prim for the export... usdVariantRootPrimPath mJobCtx.mStage->GetRootLayer()->SetDefaultPrim(defaultPrim); } if (mJobCtx.mStage->GetRootLayer()->PermissionToSave()) { mJobCtx.mStage->GetRootLayer()->Save(); } mJobCtx.mStage->Close(); mJobCtx.mMayaPrimWriterList.clear(); // clear this so that no stage references are left around MGlobal::displayInfo("usdWriteJob::endJob Saving Stage"); }
bool AbcWriteJob::eval(double iFrame) { if (iFrame == mFirstFrame) { // check if the shortnames of any two nodes are the same // if so, exit here hasDuplicates(mArgs.dagPaths, mArgs.stripNamespace); std::string appWriter = "Maya "; appWriter += MGlobal::mayaVersion().asChar(); appWriter += " AbcExport v"; appWriter += ABCEXPORT_VERSION; std::string userInfo = "Exported from: "; userInfo += MFileIO::currentFile().asChar(); // these symbols can't be in the meta data if (userInfo.find('=') != std::string::npos || userInfo.find(';') != std::string::npos) { userInfo = ""; } #ifdef ALEMBIC_WITH_HDF5 if (mAsOgawa) { mRoot = CreateArchiveWithInfo(Alembic::AbcCoreOgawa::WriteArchive(), mFileName, appWriter, userInfo, Alembic::Abc::ErrorHandler::kThrowPolicy); } else { mRoot = CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(), mFileName, appWriter, userInfo, Alembic::Abc::ErrorHandler::kThrowPolicy); } #else // just write it out as Ogawa mRoot = CreateArchiveWithInfo(Alembic::AbcCoreOgawa::WriteArchive(), mFileName, appWriter, userInfo, Alembic::Abc::ErrorHandler::kThrowPolicy); #endif mShapeTimeIndex = mRoot.addTimeSampling(*mShapeTime); mTransTimeIndex = mRoot.addTimeSampling(*mTransTime); mBoxProp = Alembic::AbcGeom::CreateOArchiveBounds(mRoot, mTransTimeIndex); if (!mRoot.valid()) { std::string theError = "Unable to create abc file"; throw std::runtime_error(theError); } mArgs.setFirstAnimShape = (iFrame == *mShapeFrames.begin()); util::ShapeSet::const_iterator end = mArgs.dagPaths.end(); GetMembersMap gmMap; for (util::ShapeSet::const_iterator it = mArgs.dagPaths.begin(); it != end; ++it) { mCurDag = *it; setup(iFrame * util::spf(), MayaTransformWriterPtr(), gmMap); } perFrameCallback(iFrame); } else { std::set<double>::iterator checkFrame = mShapeFrames.find(iFrame); bool foundShapeFrame = false; if (checkFrame != mShapeFrames.end()) { assert(mRoot != NULL); foundShapeFrame = true; mShapeSamples ++; double curTime = iFrame * util::spf(); std::vector< MayaCameraWriterPtr >::iterator camIt, camEnd; camEnd = mCameraList.end(); for (camIt = mCameraList.begin(); camIt != camEnd; camIt++) { (*camIt)->write(); } std::vector< MayaMeshWriterPtr >::iterator meshIt, meshEnd; meshEnd = mMeshList.end(); for (meshIt = mMeshList.begin(); meshIt != meshEnd; meshIt++) { (*meshIt)->write(); if ((*meshIt)->isSubD()) { mStats.mSubDAnimCVs += (*meshIt)->getNumCVs(); } else { mStats.mPolyAnimCVs += (*meshIt)->getNumCVs(); } } std::vector< MayaNurbsCurveWriterPtr >::iterator curveIt, curveEnd; curveEnd = mCurveList.end(); for (curveIt = mCurveList.begin(); curveIt != curveEnd; curveIt++) { (*curveIt)->write(); mStats.mCurveAnimCVs += (*curveIt)->getNumCVs(); } std::vector< MayaNurbsSurfaceWriterPtr >::iterator nurbsIt,nurbsEnd; nurbsEnd = mNurbsList.end(); for (nurbsIt = mNurbsList.begin(); nurbsIt != nurbsEnd; nurbsIt++) { (*nurbsIt)->write(); mStats.mNurbsAnimCVs += (*nurbsIt)->getNumCVs(); } std::vector< MayaLocatorWriterPtr >::iterator locIt, locEnd; locEnd = mLocatorList.end(); for (locIt = mLocatorList.begin(); locIt != locEnd; locIt++) { (*locIt)->write(); } std::vector< MayaPointPrimitiveWriterPtr >::iterator ptIt, ptEnd; ptEnd = mPointList.end(); for (ptIt = mPointList.begin(); ptIt != ptEnd; ptIt++) { (*ptIt)->write(curTime); mStats.mPointAnimCVs += (*ptIt)->getNumCVs(); } std::vector< AttributesWriterPtr >::iterator sattrCur = mShapeAttrList.begin(); std::vector< AttributesWriterPtr >::iterator sattrEnd = mShapeAttrList.end(); for(; sattrCur != sattrEnd; sattrCur++) { (*sattrCur)->write(); } } checkFrame = mTransFrames.find(iFrame); bool foundTransFrame = false; if (checkFrame != mTransFrames.end()) { assert(mRoot.valid()); foundTransFrame = true; mTransSamples ++; std::vector< MayaTransformWriterPtr >::iterator tcur = mTransList.begin(); std::vector< MayaTransformWriterPtr >::iterator tend = mTransList.end(); for (; tcur != tend; tcur++) { (*tcur)->write(); } std::vector< AttributesWriterPtr >::iterator tattrCur = mTransAttrList.begin(); std::vector< AttributesWriterPtr >::iterator tattrEnd = mTransAttrList.end(); for(; tattrCur != tattrEnd; tattrCur++) { (*tattrCur)->write(); } } if (foundTransFrame || foundShapeFrame) perFrameCallback(iFrame); } if (iFrame == mLastFrame) { postCallback(iFrame); return true; } return false; }
bool AbcWriteJob::eval(double iFrame) { if (iFrame == mFirstFrame) { // check if the shortnames of any two nodes are the same // if so, exit here hasDuplicates(mArgs.dagPaths, mArgs.stripNamespace); std::string appWriter = "Maya "; appWriter += MGlobal::mayaVersion().asChar(); appWriter += " AbcBullet v"; appWriter += ABCBULLET_VERSION; std::string userInfo = "Exported from: "; userInfo += MFileIO::currentFile().asChar(); // these symbols can't be in the meta data if (userInfo.find('=') != std::string::npos || userInfo.find(';') != std::string::npos) { userInfo = ""; } mRoot = CreateArchiveWithInfo(Alembic::AbcCoreHDF5::WriteArchive(), mFileName, appWriter, userInfo, Alembic::Abc::ErrorHandler::kThrowPolicy); mTransTimeIndex = mRoot.addTimeSampling(*mTransTime); mBoxProp = Alembic::AbcGeom::CreateOArchiveBounds(mRoot, mTransTimeIndex); if (!mRoot.valid()) { std::string theError = "Unable to create abc file"; throw std::runtime_error(theError); } util::ShapeSet::const_iterator end = mArgs.dagPaths.end(); util::GetMembersMap gmMap; for (util::ShapeSet::const_iterator it = mArgs.dagPaths.begin(); it != end; ++it) { mCurDag = *it; setup(iFrame * util::spf(), MayaTransformWriterPtr(), gmMap); } perFrameCallback(iFrame); } else { std::set<double>::iterator checkFrame = mTransFrames.find(iFrame); bool foundTransFrame = false; if (checkFrame != mTransFrames.end()) { assert(mRoot.valid()); foundTransFrame = true; mTransSamples ++; // write out transforms { std::vector< MayaTransformWriterPtr >::iterator tcur = mTransList.begin(); std::vector< MayaTransformWriterPtr >::iterator tend = mTransList.end(); for (; tcur != tend; tcur++) { (*tcur)->write(); } std::vector< AttributesWriterPtr >::iterator tattrCur = mTransAttrList.begin(); std::vector< AttributesWriterPtr >::iterator tattrEnd = mTransAttrList.end(); for(; tattrCur != tattrEnd; tattrCur++) { (*tattrCur)->write(); } } // write out transform collections { std::vector< MayaTransformCollectionWriterPtr >::iterator tcur = mTransColList.begin(); std::vector< MayaTransformCollectionWriterPtr >::iterator tend = mTransColList.end(); for (; tcur != tend; tcur++) { (*tcur)->write(iFrame); } std::vector< AttributesWriterPtr >::iterator tattrCur = mTransColAttrList.begin(); std::vector< AttributesWriterPtr >::iterator tattrEnd = mTransColAttrList.end(); for(; tattrCur != tattrEnd; tattrCur++) { (*tattrCur)->write(); } } } if (foundTransFrame) perFrameCallback(iFrame); } if (iFrame == mLastFrame) { postCallback(iFrame); return true; } return false; }