Exemple #1
0
        public H3DMaterialAnim ToH3DAnimation(GFMotion Motion)
        {
            H3DMaterialAnim Output = new H3DMaterialAnim()
            {
                Name           = "GFMotion",
                FramesCount    = Motion.FramesCount,
                AnimationType  = H3DAnimationType.Material,
                AnimationFlags = Motion.IsLooping ? H3DAnimationFlags.IsLooping : 0
            };

            foreach (GFMotUVTransform Mat in Materials)
            {
                ushort Unit = (ushort)(Mat.UnitIndex * 3);

                if ((Mat.ScaleX.Count | Mat.ScaleY.Count) > 0)
                {
                    Output.Elements.Add(new H3DAnimationElement()
                    {
                        Name          = Mat.Name,
                        Content       = GetAnimVector2D(Mat.ScaleX, Mat.ScaleY, Motion.FramesCount),
                        TargetType    = H3DTargetType.MaterialTexCoord0Scale + Unit,
                        PrimitiveType = H3DPrimitiveType.Vector2D
                    });
                }

                if (Mat.Rotation.Count > 0)
                {
                    Output.Elements.Add(new H3DAnimationElement()
                    {
                        Name          = Mat.Name,
                        Content       = GetAnimFloat(Mat.Rotation, Motion.FramesCount),
                        TargetType    = H3DTargetType.MaterialTexCoord0Rot + Unit,
                        PrimitiveType = H3DPrimitiveType.Float
                    });
                }

                if ((Mat.TranslationX.Count | Mat.TranslationY.Count) > 0)
                {
                    Output.Elements.Add(new H3DAnimationElement()
                    {
                        Name          = Mat.Name,
                        Content       = GetAnimVector2D(Mat.TranslationX, Mat.TranslationY, Motion.FramesCount),
                        TargetType    = H3DTargetType.MaterialTexCoord0Trans + Unit,
                        PrimitiveType = H3DPrimitiveType.Vector2D
                    });
                }
            }

            return(Output);
        }
Exemple #2
0
        public H3DAnimation ToH3DAnimation(GFMotion Motion)
        {
            H3DAnimation Output = new H3DAnimation()
            {
                Name           = "GFMotion",
                FramesCount    = Motion.FramesCount,
                AnimationType  = H3DAnimationType.Visibility,
                AnimationFlags = Motion.IsLooping ? H3DAnimationFlags.IsLooping : 0
            };

            ushort Index = 0;

            foreach (GFMotBoolean Vis in Visibilities)
            {
                H3DAnimBoolean Anim = new H3DAnimBoolean();

                Anim.StartFrame = 0;
                Anim.EndFrame   = Motion.FramesCount;
                Anim.CurveIndex = Index++;

                foreach (bool Visibility in Vis.Values)
                {
                    Anim.Values.Add(Visibility);
                }

                Output.Elements.Add(new H3DAnimationElement()
                {
                    Name          = Vis.Name,
                    PrimitiveType = H3DPrimitiveType.Boolean,
                    TargetType    = H3DTargetType.MeshNodeVisibility,
                    Content       = Anim
                });
            }

            return(Output);
        }
Exemple #3
0
        public H3DAnimation ToH3DAnimation(List <GFBone> Skeleton, GFMotion Motion)
        {
            H3DAnimation Output = new H3DAnimation()
            {
                Name           = "GFMotion",
                FramesCount    = Motion.FramesCount,
                AnimationType  = H3DAnimationType.Skeletal,
                AnimationFlags = Motion.IsLooping ? H3DAnimationFlags.IsLooping : 0
            };

            foreach (GFMotBoneTransform Bone in Bones)
            {
                H3DAnimQuatTransform QuatTransform = new H3DAnimQuatTransform();

                int BoneIndex = Skeleton.FindIndex(x => x.Name == Bone.Name);

                if (BoneIndex == -1)
                {
                    continue;
                }

                for (float Frame = 0; Frame < Motion.FramesCount; Frame++)
                {
                    Vector3 Scale       = Skeleton[BoneIndex].Scale;
                    Vector3 Rotation    = Skeleton[BoneIndex].Rotation;
                    Vector3 Translation = Skeleton[BoneIndex].Translation;

                    GFMotBoneTransform.SetFrameValue(Bone.ScaleX, Frame, ref Scale.X);
                    GFMotBoneTransform.SetFrameValue(Bone.ScaleY, Frame, ref Scale.Y);
                    GFMotBoneTransform.SetFrameValue(Bone.ScaleZ, Frame, ref Scale.Z);

                    GFMotBoneTransform.SetFrameValue(Bone.RotationX, Frame, ref Rotation.X);
                    GFMotBoneTransform.SetFrameValue(Bone.RotationY, Frame, ref Rotation.Y);
                    GFMotBoneTransform.SetFrameValue(Bone.RotationZ, Frame, ref Rotation.Z);

                    GFMotBoneTransform.SetFrameValue(Bone.TranslationX, Frame, ref Translation.X);
                    GFMotBoneTransform.SetFrameValue(Bone.TranslationY, Frame, ref Translation.Y);
                    GFMotBoneTransform.SetFrameValue(Bone.TranslationZ, Frame, ref Translation.Z);

                    /*
                     * gdkchan Note:
                     * When the game uses Axis Angle for rotation,
                     * I believe that the original Euler rotation can be ignored,
                     * because otherwise we would need to either convert Euler to Axis Angle or Axis to Euler,
                     * and both conversions are pretty expensive.
                     * The vector is already halved as a optimization (needs * 2).
                     */
                    Quaternion QuatRotation;

                    if (Bone.IsAxisAngle)
                    {
                        float Angle = Rotation.Length() * 2;

                        QuatRotation = Angle > 0
                            ? Quaternion.CreateFromAxisAngle(Vector3.Normalize(Rotation), Angle)
                            : Quaternion.Identity;
                    }
                    else
                    {
                        QuatRotation =
                            Quaternion.CreateFromAxisAngle(Vector3.UnitZ, Rotation.Z) *
                            Quaternion.CreateFromAxisAngle(Vector3.UnitY, Rotation.Y) *
                            Quaternion.CreateFromAxisAngle(Vector3.UnitX, Rotation.X);
                    }

                    QuatTransform.Scales.Add(Scale);
                    QuatTransform.Rotations.Add(QuatRotation);
                    QuatTransform.Translations.Add(Translation);
                }

                Output.Elements.Add(new H3DAnimationElement()
                {
                    Name          = Bone.Name,
                    Content       = QuatTransform,
                    TargetType    = H3DTargetType.Bone,
                    PrimitiveType = H3DPrimitiveType.QuatTransform
                });
            }

            return(Output);
        }