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; }
void AbcWriteJob::setup(double iFrame, MayaTransformWriterPtr iParent, GetMembersMap& gmMap) { MStatus status; // short-circuit if selection flag is on but this node isn't actively // selected if (mArgs.useSelectionList && !mSList.hasItem(mCurDag)) return; MObject ob = mCurDag.node(); // skip all intermediate nodes (and their children) if (util::isIntermediate(ob)) { return; } // skip nodes that aren't renderable (and their children) if (mArgs.excludeInvisible && !util::isRenderable(ob)) { return; } // look for riCurves flag for flattening all curve objects to a curve group MFnDependencyNode fnDepNode(ob, &status); MPlug riCurvesPlug = fnDepNode.findPlug("riCurves", &status); bool riCurvesVal = riCurvesPlug.asBool(); bool writeOutAsGroup = false; if (riCurvesVal) { writeOutAsGroup = checkCurveGrp(); if (writeOutAsGroup == false) { MString msg = "Curves have different degrees or close "; msg += "states, not writing out as curve group"; MGlobal::displayWarning(msg); } } if ( status == MS::kSuccess && riCurvesVal && writeOutAsGroup) { MayaNurbsCurveWriterPtr nurbsCurve; if (iParent == NULL) { Alembic::Abc::OObject obj = mRoot.getTop(); nurbsCurve = MayaNurbsCurveWriterPtr(new MayaNurbsCurveWriter( mCurDag, obj, mShapeTimeIndex, true, mArgs)); } else { Alembic::Abc::OObject obj = iParent->getObject(); nurbsCurve = MayaNurbsCurveWriterPtr(new MayaNurbsCurveWriter( mCurDag, obj, mShapeTimeIndex, true, mArgs)); } if (nurbsCurve->isAnimated() && mShapeTimeIndex != 0) { mCurveList.push_back(nurbsCurve); mStats.mCurveAnimNum++; mStats.mCurveAnimCurves += nurbsCurve->getNumCurves(); mStats.mCurveAnimCVs += nurbsCurve->getNumCVs(); } else { mStats.mCurveStaticNum++; mStats.mCurveStaticCurves += nurbsCurve->getNumCurves(); mStats.mCurveStaticCVs += nurbsCurve->getNumCVs(); } AttributesWriterPtr attrs = nurbsCurve->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else if (ob.hasFn(MFn::kTransform)) { MFnTransform fnTrans(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize transform node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } MayaTransformWriterPtr trans; // parented to the root case if (iParent == NULL) { Alembic::Abc::OObject obj = mRoot.getTop(); trans = MayaTransformWriterPtr(new MayaTransformWriter( obj, mCurDag, mTransTimeIndex, mArgs)); } else { trans = MayaTransformWriterPtr(new MayaTransformWriter( *iParent, mCurDag, mTransTimeIndex, mArgs)); } if (trans->isAnimated() && mTransTimeIndex != 0) { mTransList.push_back(trans); mStats.mTransAnimNum++; } else mStats.mTransStaticNum++; AttributesWriterPtr attrs = trans->getAttrs(); if (mTransTimeIndex != 0 && attrs->isAnimated()) mTransAttrList.push_back(attrs); // loop through the children, making sure to push and pop them // from the MDagPath unsigned int numChild = mCurDag.childCount(); for (unsigned int i = 0; i < numChild; ++i) { if (mCurDag.push(mCurDag.child(i)) == MS::kSuccess) { setup(iFrame, trans, gmMap); mCurDag.pop(); } } } else if (ob.hasFn(MFn::kLocator)) { MFnDependencyNode fnLocator(ob, & status); if (status != MS::kSuccess) { MString msg = "Initialize locator node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaLocatorWriterPtr locator(new MayaLocatorWriter( mCurDag, obj, mShapeTimeIndex, mArgs)); if (locator->isAnimated() && mShapeTimeIndex != 0) { mLocatorList.push_back(locator); mStats.mLocatorAnimNum++; } else { mStats.mLocatorStaticNum++; } AttributesWriterPtr attrs = locator->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += fnLocator.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else if (ob.hasFn(MFn::kParticle)) { MFnParticleSystem mFnParticle(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize particle system "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaPointPrimitiveWriterPtr particle(new MayaPointPrimitiveWriter( iFrame, mCurDag, obj, mShapeTimeIndex, mArgs)); if (particle->isAnimated() && mShapeTimeIndex != 0) { mPointList.push_back(particle); mStats.mPointAnimNum++; mStats.mPointAnimCVs += particle->getNumCVs(); } else { mStats.mPointStaticNum++; mStats.mPointStaticCVs += particle->getNumCVs(); } AttributesWriterPtr attrs = particle->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += mFnParticle.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else if (ob.hasFn(MFn::kMesh)) { MFnMesh fnMesh(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize mesh node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaMeshWriterPtr mesh(new MayaMeshWriter(mCurDag, obj, mShapeTimeIndex, mArgs, gmMap)); if (mesh->isAnimated() && mShapeTimeIndex != 0) { mMeshList.push_back(mesh); if (mesh->isSubD()) { mStats.mSubDAnimNum++; mStats.mSubDAnimCVs += mesh->getNumCVs(); mStats.mSubDAnimFaces += mesh->getNumFaces(); } else { mStats.mPolyAnimNum++; mStats.mPolyAnimCVs += mesh->getNumCVs(); mStats.mPolyAnimFaces += mesh->getNumFaces(); } } else { if (mesh->isSubD()) { mStats.mSubDStaticNum++; mStats.mSubDStaticCVs += mesh->getNumCVs(); mStats.mSubDStaticFaces += mesh->getNumFaces(); } else { mStats.mPolyStaticNum++; mStats.mPolyStaticCVs += mesh->getNumCVs(); mStats.mPolyStaticFaces += mesh->getNumFaces(); } } AttributesWriterPtr attrs = mesh->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += fnMesh.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else if (ob.hasFn(MFn::kCamera)) { MFnCamera fnCamera(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize camera node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaCameraWriterPtr camera(new MayaCameraWriter( mCurDag, obj, mShapeTimeIndex, mArgs)); if (camera->isAnimated() && mShapeTimeIndex != 0) { mCameraList.push_back(camera); mStats.mCameraAnimNum++; } else mStats.mCameraStaticNum++; AttributesWriterPtr attrs = camera->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += fnCamera.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else if (ob.hasFn(MFn::kNurbsSurface)) { MFnNurbsSurface fnNurbsSurface(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize nurbs surface "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaNurbsSurfaceWriterPtr nurbsSurface(new MayaNurbsSurfaceWriter( mCurDag, obj, mShapeTimeIndex, mArgs)); if (nurbsSurface->isAnimated() && mShapeTimeIndex != 0) { mNurbsList.push_back(nurbsSurface); mStats.mNurbsAnimNum++; mStats.mNurbsAnimCVs += nurbsSurface->getNumCVs(); } else { mStats.mNurbsStaticNum++; mStats.mNurbsStaticCVs += nurbsSurface->getNumCVs(); } AttributesWriterPtr attrs = nurbsSurface->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += fnNurbsSurface.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else if (ob.hasFn(MFn::kNurbsCurve)) { MFnNurbsCurve fnNurbsCurve(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize curve node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } if (iParent != NULL) { Alembic::Abc::OObject obj = iParent->getObject(); MayaNurbsCurveWriterPtr nurbsCurve(new MayaNurbsCurveWriter( mCurDag, obj, mShapeTimeIndex, false, mArgs)); if (nurbsCurve->isAnimated() && mShapeTimeIndex != 0) { mCurveList.push_back(nurbsCurve); mStats.mCurveAnimNum++; mStats.mCurveAnimCurves++; mStats.mCurveAnimCVs += nurbsCurve->getNumCVs(); } else { mStats.mCurveStaticNum++; mStats.mCurveStaticCurves++; mStats.mCurveStaticCVs += nurbsCurve->getNumCVs(); } AttributesWriterPtr attrs = nurbsCurve->getAttrs(); if (mShapeTimeIndex != 0 && attrs->isAnimated()) mShapeAttrList.push_back(attrs); } else { MString err = "Can't translate "; err += fnNurbsCurve.name() + " since it doesn't have a parent."; MGlobal::displayError(err); } } else { MString warn = mCurDag.fullPathName() + " is an unsupported type of "; warn += ob.apiTypeStr(); MGlobal::displayWarning(warn); } }
void AbcWriteJob::setup(double iFrame, MayaTransformWriterPtr iParent, util::GetMembersMap& gmMap) { MStatus status; // short-circuit if selection flag is on but this node isn't actively // selected if (mArgs.useSelectionList && !mSList.hasItem(mCurDag)) return; MObject ob = mCurDag.node(); MFnDependencyNode fnDepNode(ob, &status); bool bSolvedState = fnDepNode.typeName() == "bulletRigidCollection"; // skip all intermediate nodes (and their children) if (util::isIntermediate(ob)) { if (!bSolvedState) { return; } } // skip nodes that aren't renderable (and their children) if (mArgs.excludeInvisible && !util::isRenderable(ob)) { return; } if ( bSolvedState ) { // the motionstates are held on the initialstate node at the moment if (status != MS::kSuccess) { MString msg = "Initialize transform collection node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } MayaTransformCollectionWriterPtr transCol; // transformcollections always parented to the root case Alembic::Abc::OObject obj = mRoot.getTop(); transCol = MayaTransformCollectionWriterPtr(new MayaTransformCollectionWriter( obj, mCurDag, mTransTimeIndex, mArgs)); mTransColList.push_back(transCol); mStats.mTransColNum++; AttributesWriterPtr attrs = transCol->getAttrs(); if (attrs) { if (mTransTimeIndex != 0 && attrs->isAnimated()) mTransColAttrList.push_back(attrs); } } else if (ob.hasFn(MFn::kTransform)) { MFnTransform fnTrans(ob, &status); if (status != MS::kSuccess) { MString msg = "Initialize transform node "; msg += mCurDag.fullPathName(); msg += " failed, skipping."; MGlobal::displayWarning(msg); return; } MayaTransformWriterPtr trans; // parented to the root case if (iParent == NULL) { Alembic::Abc::OObject obj = mRoot.getTop(); trans = MayaTransformWriterPtr(new MayaTransformWriter( obj, mCurDag, mTransTimeIndex, mArgs)); } else { trans = MayaTransformWriterPtr(new MayaTransformWriter( *iParent, mCurDag, mTransTimeIndex, mArgs)); } if (trans->isAnimated() && mTransTimeIndex != 0) { mTransList.push_back(trans); mStats.mTransAnimNum++; } else mStats.mTransStaticNum++; AttributesWriterPtr attrs = trans->getAttrs(); if (mTransTimeIndex != 0 && attrs->isAnimated()) mTransAttrList.push_back(attrs); // loop through the children, making sure to push and pop them // from the MDagPath unsigned int numChild = mCurDag.childCount(); for (unsigned int i = 0; i < numChild; ++i) { mCurDag.push(mCurDag.child(i)); setup(iFrame, trans, gmMap); mCurDag.pop(); } } else { MString warn = mCurDag.fullPathName() + " is an unsupported type of "; warn += ob.apiTypeStr(); MGlobal::displayWarning(warn); } }