void Loader::loadAnimation(const aiNode *pNode,int index,CMC_AnimateData * animate) { std::string NodeName(pNode->mName.data); if(!m_pScene->HasAnimations ()) { m_model->m_hasAnimation = false; return ; } const aiAnimation* pAnimation = m_pScene->mAnimations[index]; const aiNodeAnim * pNodeAnim = findNodeAnim(pAnimation, NodeName); if(pNodeAnim)//that node is a animation bone. { auto animateBone = new CMC_AnimateBone(); animateBone->m_boneName = NodeName; //load position key. for(int i =0;i<pNodeAnim->mNumPositionKeys;i++) { auto v = pNodeAnim->mPositionKeys[i]; CMC_TranslateKey key; key.time = v.mTime; key.trans = QVector3D (v.mValue.x,v.mValue.y,v.mValue.z); animateBone->addTranslate (key); } //load scale key for(int i =0;i<pNodeAnim->mNumScalingKeys;i++) { auto v = pNodeAnim->mScalingKeys[i]; CMC_ScaleKey key; key.time = v.mTime; key.scale = QVector3D (v.mValue.x,v.mValue.y,v.mValue.z); animateBone->addScale (key); } //load rotation key for(int i =0;i<pNodeAnim->mNumPositionKeys;i++) { auto v = pNodeAnim->mRotationKeys[i]; CMC_RotateKey key; key.time = v.mTime; key.rotate = QQuaternion(v.mValue.w,v.mValue.x,v.mValue.y,v.mValue.z); animateBone->addRotate (key); } animate->addAnimateBone (animateBone); animate->m_ticksPerSecond = pAnimation->mTicksPerSecond; animate->m_duration = pAnimation->mDuration; } for (uint i = 0 ; i < pNode->mNumChildren ; i++) { loadAnimation( pNode->mChildren[i],index,animate); } }
void MayaTransformWriter::pushTransformStack(const MFnTransform & iTrans, bool iForceStatic) { // inspect the translate addTranslate(iTrans, "translate", "translateX", "translateY", "translateZ", Alembic::AbcGeom::kTranslateHint, false, iForceStatic, false, mSample, mAnimChanList); // inspect the rotate pivot translate addTranslate(iTrans, "rotatePivotTranslate", "rotatePivotTranslateX", "rotatePivotTranslateY", "rotatePivotTranslateZ", Alembic::AbcGeom::kRotatePivotTranslationHint, false, iForceStatic, false, mSample, mAnimChanList); // inspect the rotate pivot addTranslate(iTrans, "rotatePivot", "rotatePivotX", "rotatePivotY", "rotatePivotZ", Alembic::AbcGeom::kRotatePivotPointHint, false, iForceStatic, false, mSample, mAnimChanList); // inspect rotate names MString rotateNames[3]; rotateNames[0] = "rotateX"; rotateNames[1] = "rotateY"; rotateNames[2] = "rotateZ"; unsigned int rotOrder[3]; // if this returns false then the rotation order was kInvalid or kLast MTransformationMatrix::RotationOrder eRotOrder(iTrans.rotationOrder()); if (util::getRotOrder(eRotOrder, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iTrans, "rotate", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, iForceStatic, false, mSample, mAnimChanList, mRotateOpIndex); } // now look at the rotation orientation, aka rotate axis rotateNames[0] = "rotateAxisX"; rotateNames[1] = "rotateAxisY"; rotateNames[2] = "rotateAxisZ"; rotOrder[0] = 0; rotOrder[1] = 1; rotOrder[2] = 2; addRotate(iTrans, "rotateAxis", rotateNames, rotOrder, Alembic::AbcGeom::kRotateOrientationHint, iForceStatic, false, mSample, mAnimChanList, mRotateAxisOpIndex); // invert the rotate pivot if necessary addTranslate(iTrans, "rotatePivot", "rotatePivotX", "rotatePivotY", "rotatePivotZ", Alembic::AbcGeom::kRotatePivotPointHint, true, iForceStatic, false, mSample, mAnimChanList); // inspect the scale pivot translation addTranslate(iTrans, "scalePivotTranslate", "scalePivotTranslateX", "scalePivotTranslateY", "scalePivotTranslateZ", Alembic::AbcGeom::kScalePivotTranslationHint, false, iForceStatic, false, mSample, mAnimChanList); // inspect the scale pivot point addTranslate(iTrans, "scalePivot", "scalePivotX", "scalePivotY", "scalePivotZ", Alembic::AbcGeom::kScalePivotPointHint, false, iForceStatic, false, mSample, mAnimChanList); // inspect the shear addShear(iTrans, iForceStatic, mSample, mAnimChanList); // add the scale addScale(iTrans, "scale", "scaleX", "scaleY", "scaleZ", false, iForceStatic, false, mSample, mAnimChanList); // inverse the scale pivot point if necessary addTranslate(iTrans, "scalePivot", "scalePivotX", "scalePivotY", "scalePivotZ", Alembic::AbcGeom::kScalePivotPointHint, true, iForceStatic, false, mSample, mAnimChanList); // remember current rotation if (mFilterEulerRotations) { double xx(0), yy(0), zz(0); // there are 2 rotation order enum definitions: // MEulerRotation::RotationOrder = MTransformationMatrix::RotationOrder-1 if (getSampledRotation( mSample, mRotateOpIndex, xx, yy, zz )) { mPrevRotateSolution.setValue(xx, yy, zz, (MEulerRotation::RotationOrder)(eRotOrder-1)); } if (getSampledRotation( mSample, mRotateAxisOpIndex, xx, yy, zz )) { mPrevRotateAxisSolution.setValue(xx, yy, zz, MEulerRotation::kXYZ); } } }
void MayaTransformWriter::pushTransformStack(double iFrame, const MFnIkJoint & iJoint) { bool forceStatic = (iFrame == DBL_MAX); // inspect the translate addTranslate(iJoint, "translate", "translateX", "translateY", "translateZ", Alembic::AbcGeom::kTranslateHint, false, forceStatic, mSample, mAnimChanList); // inspect the inverseParent scale addScale(iJoint, "inverseScale", "inverseScaleX", "inverseScaleY", "inverseScaleZ", forceStatic, mSample, mAnimChanList); MTransformationMatrix::RotationOrder order; double vals[3]; // for reordering rotate names MString rotateNames[3]; unsigned int rotOrder[3]; // now look at the joint orientation rotateNames[0] = "jointOrientX"; rotateNames[1] = "jointOrientY"; rotateNames[2] = "jointOrientZ"; iJoint.getOrientation(vals, order); if (util::getRotOrder(order, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "jointOrient", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, forceStatic, true, mSample, mAnimChanList); } rotateNames[0] = "rotateX"; rotateNames[1] = "rotateY"; rotateNames[2] = "rotateZ"; // if this returns false then the rotation order was kInvalid or kLast if (util::getRotOrder(iJoint.rotationOrder(), rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "rotate", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, forceStatic, true, mSample, mAnimChanList); } // now look at the rotation orientation, aka rotate axis rotateNames[0] = "rotateAxisX"; rotateNames[1] = "rotateAxisY"; rotateNames[2] = "rotateAxisZ"; iJoint.getScaleOrientation(vals, order); if (util::getRotOrder(order, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "rotateAxis", rotateNames, rotOrder, Alembic::AbcGeom::kRotateOrientationHint, forceStatic, true, mSample, mAnimChanList); } // inspect the scale addScale(iJoint, "scale", "scaleX", "scaleY", "scaleZ", forceStatic, mSample, mAnimChanList); }
void MayaTransformWriter::pushTransformStack(const MFnIkJoint & iJoint, bool iForceStatic) { // check joints that are driven by Maya FBIK // Maya FBIK has no connection to joints' TRS plugs // but TRS of joints are driven by FBIK, they are not static // Maya 2012's new HumanIK has connections to joints. // FBIK is a special case. bool forceAnimated = false; MStatus status = MS::kSuccess; if (iJoint.hikJointName(&status).length() > 0 && status) { forceAnimated = true; } // inspect the translate addTranslate(iJoint, "translate", "translateX", "translateY", "translateZ", Alembic::AbcGeom::kTranslateHint, false, iForceStatic, forceAnimated, mSample, mAnimChanList); // inspect the inverseParent scale // [IS] is ignored when Segment Scale Compensate is false MPlug scaleCompensatePlug = iJoint.findPlug("segmentScaleCompensate"); if (scaleCompensatePlug.asBool()) { addScale(iJoint, "inverseScale", "inverseScaleX", "inverseScaleY", "inverseScaleZ", true, iForceStatic, forceAnimated, mSample, mAnimChanList); } MTransformationMatrix::RotationOrder eJointOrientOrder, eRotOrder, eRotateAxisOrder; double vals[3]; // for reordering rotate names MString rotateNames[3]; unsigned int rotOrder[3]; // now look at the joint orientation rotateNames[0] = "jointOrientX"; rotateNames[1] = "jointOrientY"; rotateNames[2] = "jointOrientZ"; iJoint.getOrientation(vals, eJointOrientOrder); if (util::getRotOrder(eJointOrientOrder, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "jointOrient", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, iForceStatic, true, mSample, mAnimChanList, mJointOrientOpIndex); } rotateNames[0] = "rotateX"; rotateNames[1] = "rotateY"; rotateNames[2] = "rotateZ"; // if this returns false then the rotation order was kInvalid or kLast eRotOrder = iJoint.rotationOrder(); if (util::getRotOrder(eRotOrder, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "rotate", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, iForceStatic, true, mSample, mAnimChanList, mRotateOpIndex); } // now look at the rotation orientation, aka rotate axis rotateNames[0] = "rotateAxisX"; rotateNames[1] = "rotateAxisY"; rotateNames[2] = "rotateAxisZ"; iJoint.getScaleOrientation(vals, eRotateAxisOrder); if (util::getRotOrder(eRotateAxisOrder, rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iJoint, "rotateAxis", rotateNames, rotOrder, Alembic::AbcGeom::kRotateOrientationHint, iForceStatic, true, mSample, mAnimChanList, mRotateAxisOpIndex); } // inspect the scale addScale(iJoint, "scale", "scaleX", "scaleY", "scaleZ", false, iForceStatic, forceAnimated, mSample, mAnimChanList); // remember current rotation if (mFilterEulerRotations) { double xx(0), yy(0), zz(0); // there are 2 rotation order enum definitions: // MEulerRotation::RotationOrder = MTransformationMatrix::RotationOrder-1 if (getSampledRotation( mSample, mJointOrientOpIndex, xx, yy, zz )) { mPrevJointOrientSolution.setValue(xx, yy, zz, (MEulerRotation::RotationOrder)(eJointOrientOrder-1)); } if (getSampledRotation( mSample, mRotateOpIndex, xx, yy, zz )) { mPrevRotateSolution.setValue(xx, yy, zz, (MEulerRotation::RotationOrder)(eRotOrder-1)); } if (getSampledRotation( mSample, mRotateAxisOpIndex, xx, yy, zz )) { mPrevRotateAxisSolution.setValue(xx, yy, zz, (MEulerRotation::RotationOrder)(eRotateAxisOrder-1)); } } }
void MayaTransformWriter::pushTransformStack(double iFrame, const MFnTransform & iTrans) { bool forceStatic = (iFrame == DBL_MAX); // inspect the translate addTranslate(iTrans, "translate", "translateX", "translateY", "translateZ", Alembic::AbcGeom::kTranslateHint, false, forceStatic, mSample, mAnimChanList); // inspect the rotate pivot translate addTranslate(iTrans, "rotatePivotTranslate", "rotatePivotTranslateX", "rotatePivotTranslateY", "rotatePivotTranslateZ", Alembic::AbcGeom::kRotatePivotTranslationHint, false, forceStatic, mSample, mAnimChanList); // inspect the rotate pivot addTranslate(iTrans, "rotatePivot", "rotatePivotX", "rotatePivotY", "rotatePivotZ", Alembic::AbcGeom::kRotatePivotPointHint, false, forceStatic, mSample, mAnimChanList); // inspect rotate names MString rotateNames[3]; rotateNames[0] = "rotateX"; rotateNames[1] = "rotateY"; rotateNames[2] = "rotateZ"; unsigned int rotOrder[3]; // if this returns false then the rotation order was kInvalid or kLast if (util::getRotOrder(iTrans.rotationOrder(), rotOrder[0], rotOrder[1], rotOrder[2])) { addRotate(iTrans, "rotate", rotateNames, rotOrder, Alembic::AbcGeom::kRotateHint, forceStatic, false, mSample, mAnimChanList); } // now look at the rotation orientation, aka rotate axis rotateNames[0] = "rotateAxisX"; rotateNames[1] = "rotateAxisY"; rotateNames[2] = "rotateAxisZ"; rotOrder[0] = 0; rotOrder[1] = 1; rotOrder[2] = 2; addRotate(iTrans, "rotateAxis", rotateNames, rotOrder, Alembic::AbcGeom::kRotateOrientationHint, forceStatic, false, mSample, mAnimChanList); // invert the rotate pivot if necessary addTranslate(iTrans, "rotatePivot", "rotatePivotX", "rotatePivotY", "rotatePivotZ", Alembic::AbcGeom::kRotatePivotPointHint, true, forceStatic, mSample, mAnimChanList); // inspect the scale pivot translation addTranslate(iTrans, "scalePivotTranslate", "scalePivotTranslateX", "scalePivotTranslateY", "scalePivotTranslateZ", Alembic::AbcGeom::kScalePivotTranslationHint, false, forceStatic, mSample, mAnimChanList); // inspect the scale pivot point addTranslate(iTrans, "scalePivot", "scalePivotX", "scalePivotY", "scalePivotZ", Alembic::AbcGeom::kScalePivotPointHint, false, forceStatic, mSample, mAnimChanList); // inspect the shear addShear(iTrans, forceStatic, mSample, mAnimChanList); // add the scale addScale(iTrans, "scale", "scaleX", "scaleY", "scaleZ", forceStatic, mSample, mAnimChanList); // inverse the scale pivot point if necessary addTranslate(iTrans, "scalePivot", "scalePivotX", "scalePivotY", "scalePivotZ", Alembic::AbcGeom::kScalePivotPointHint, true, forceStatic, mSample, mAnimChanList); }