예제 #1
0
        private void ExportGroupAnimation(CSGGroup group, FBXAnimLayer animationLayer, float keyFramesPerSecond, FBXNode node)
        {
            CSGAnimationKey[] animationKeyList = null;
            int keyListCount = 0;

            group.GetAnimationKeys(0, 999999, ref animationKeyList, ref keyListCount);
            int translationAnimationKeyCount = 0;
            int rotationAnimationKeyCount    = 0;

            foreach (var animationKey in animationKeyList)
            {
                if (animationKey.Type == CSGAnimationKeyType.CSGAnimationPositionKey)
                {
                    translationAnimationKeyCount++;
                }

                if (animationKey.Type == CSGAnimationKeyType.CSGAnimationOrientationKey)
                {
                    rotationAnimationKeyCount++;
                }
            }

            if (translationAnimationKeyCount > 1)
            {
                FBXAnimCurveNode myTranslationAnimCurveNode = node.LclTranslationGetCurveNode(animationLayer);

                FBXAnimCurve myTranXCurve = node.LclTranslationGetCurve(animationLayer, "X");
                FBXAnimCurve myTranYCurve = node.LclTranslationGetCurve(animationLayer, "Y");
                FBXAnimCurve myTranZCurve = node.LclTranslationGetCurve(animationLayer, "Z");

                myTranXCurve.KeyModifyBegin();
                myTranYCurve.KeyModifyBegin();
                myTranZCurve.KeyModifyBegin();

                foreach (var animationKey in animationKeyList)
                {
                    if (animationKey.Type == CSGAnimationKeyType.CSGAnimationPositionKey)
                    {
                        myTranXCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, animationKey.V.X);  // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant);
                        myTranYCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, animationKey.V.Y);  // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant);
                        myTranZCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, -animationKey.V.Z); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationConstant);
                    }
                }

                myTranXCurve.KeyModifyEnd();
                myTranYCurve.KeyModifyEnd();
                myTranZCurve.KeyModifyEnd();
            }

            if (rotationAnimationKeyCount > 1)
            {
                FBXAnimCurveNode myRotationAnimCurveNode = node.LclRotationGetCurveNode(animationLayer);

                FBXAnimCurve myRotXCurve = node.LclRotationGetCurve(animationLayer, "X");
                FBXAnimCurve myRotYCurve = node.LclRotationGetCurve(animationLayer, "Y");
                FBXAnimCurve myRotZCurve = node.LclRotationGetCurve(animationLayer, "Z");

                myRotXCurve.KeyModifyBegin();
                myRotYCurve.KeyModifyBegin();
                myRotZCurve.KeyModifyBegin();

                foreach (var animationKey in animationKeyList)
                {
                    if (animationKey.Type == CSGAnimationKeyType.CSGAnimationOrientationKey)
                    {
                        FBXVector eulerXYZ = this.GetEulerXYZ(group, animationKey.Time);

                        myRotXCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.x); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear);
                        myRotYCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.y); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear);
                        myRotZCurve.KeyAddSet(animationKey.Time / keyFramesPerSecond, (float)eulerXYZ.z); // , ArcManagedFBX.Types.EInterpolationType.eInterpolationLinear);
                    }
                }

                myRotXCurve.KeyModifyEnd();
                myRotYCurve.KeyModifyEnd();
                myRotZCurve.KeyModifyEnd();
            }
        }