示例#1
0
        private static BoneAnim Chr0Entry2BoneAnim(CHR0EntryNode entry)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = entry.Name;

            if (entry.UseModelTranslate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
            }
            if (entry.UseModelRotate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
            }
            if (entry.UseModelScale)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            }

            var baseData = new BoneAnimData();

            baseData.Translate = new Vector3F();
            baseData.Rotate    = new Vector4F();
            baseData.Scale     = new Vector3F();
            baseData.Flags     = 0;
            boneAnim.BaseData  = baseData;

            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginRotate        = 0;
            boneAnim.BeginTranslate     = 0;
            boneAnim.FlagsTransform     = 0;

            KeyframeCollection c = entry.Keyframes;

            for (int index = 0; index < 9; index++)
            {
            }

            if (entry.UseModelTranslate)
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
            }
            if (entry.UseModelRotate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
            }
            if (entry.UseModelScale)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            }

            return(boneAnim);
        }
    public void Populate(AnimationClip c, Transform tr)
    {
        name = "anim_" + c.name + "_" + GlTF_Writer.GetNameFromObject(tr, true);
        //	AnimationUtility.GetCurveBindings(c);
        // look at each curve
        // if position, rotation, scale detected for first time
        //  create channel, sampler, param for it
        //  populate this curve into proper component
        AnimationClipCurveData[] curveDatas = AnimationUtility.GetAllCurves(c, true);

        // Find curve which has most keyframes for time reference
        Keyframe[] refKeyFrames = null;
        for (int i = 0; i < curveDatas.Length; ++i)
        {
            var cd = curveDatas[i];
            if (refKeyFrames == null || cd.curve.keys.Length > refKeyFrames.Length)
            {
                refKeyFrames = cd.curve.keys;
            }
        }
        PopulateTime(c.name, refKeyFrames);

        for (int i = 0; i < curveDatas.Length; i++)
        {
            var    cd            = curveDatas[i];
            string propName      = cd.propertyName;
            var    boneTransform = GetTransformFromPath(cd.path, tr);
            if (boneTransform == null)
            {
                continue;
            }

            var          boneName = GlTF_Node.GetNameFromObject(boneTransform);
            BoneAnimData bad;
            if (boneAnimData.ContainsKey(boneName))
            {
                bad = boneAnimData[boneName];
            }
            else
            {
                bad = new BoneAnimData(c.name, boneName);
                boneAnimData[boneName] = bad;
            }
            bad.PopulateAccessor(cd, refKeyFrames);
        }
    }
示例#3
0
        private BoneAnim GenericBoneAnimToBfresBoneAnim(Animation.KeyNode boneNode, int index)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = boneNode.Text;
            var posx = boneNode.XPOS.GetValue(0);
            var posy = boneNode.YPOS.GetValue(0);
            var posz = boneNode.ZPOS.GetValue(0);
            var scax = boneNode.XSCA.GetValue(0);
            var scay = boneNode.YSCA.GetValue(0);
            var scaz = boneNode.ZSCA.GetValue(0);
            var rotx = boneNode.XROT.GetValue(0);
            var roty = boneNode.YROT.GetValue(0);
            var rotz = boneNode.ZROT.GetValue(0);
            var rotw = boneNode.WROT.GetValue(0);

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginTranslate     = 6;
            boneAnim.BeginRotate        = 3;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;

            if (boneBaseData.Rotate == new Syroot.Maths.Vector4F(0, 0, 0, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.RotateZero;
            }
            if (boneBaseData.Translate == new Syroot.Maths.Vector3F(0, 0, 0))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.TranslateZero;
            }
            if (boneBaseData.Scale == new Syroot.Maths.Vector3F(1, 1, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleOne;
            }
            if (IsUniform(boneBaseData.Scale))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleUniform;
            }
            if (index != 0) //root bone
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.SegmentScaleCompensate;
            }

            if (boneNode.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                var curve = SetAnimationCurve(boneNode.XSCA, (uint)FSKA.TrackType.XSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                var curve = SetAnimationCurve(boneNode.YSCA, (uint)FSKA.TrackType.YSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                var curve = SetAnimationCurve(boneNode.ZSCA, (uint)FSKA.TrackType.ZSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                var curve = SetAnimationCurve(boneNode.XROT, (uint)FSKA.TrackType.XROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                var curve = SetAnimationCurve(boneNode.YROT, (uint)FSKA.TrackType.YROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                var curve = SetAnimationCurve(boneNode.ZROT, (uint)FSKA.TrackType.ZROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                var curve = SetAnimationCurve(boneNode.WROT, (uint)FSKA.TrackType.WROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                var curve = SetAnimationCurve(boneNode.XPOS, (uint)FSKA.TrackType.XPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                var curve = SetAnimationCurve(boneNode.YPOS, (uint)FSKA.TrackType.YPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                var curve = SetAnimationCurve(boneNode.ZPOS, (uint)FSKA.TrackType.ZPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }

            return(boneAnim);
        }
示例#4
0
        private BoneAnim GenericBoneAnimToBfresBoneAnim(Animation.KeyNode boneNode)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = boneNode.Text;
            var posx = boneNode.XPOS.GetValue(0);
            var posy = boneNode.YPOS.GetValue(0);
            var posz = boneNode.ZPOS.GetValue(0);
            var scax = boneNode.XSCA.GetValue(0);
            var scay = boneNode.YSCA.GetValue(0);
            var scaz = boneNode.ZSCA.GetValue(0);
            var rotx = boneNode.XROT.GetValue(0);
            var roty = boneNode.YROT.GetValue(0);
            var rotz = boneNode.ZROT.GetValue(0);
            var rotw = boneNode.WROT.GetValue(0);

            var Value3One  = Syroot.Maths.Vector3F.One;
            var Value3Zero = Syroot.Maths.Vector3F.Zero;
            var Value4Zero = Syroot.Maths.Vector4F.Zero;

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginTranslate     = 6;
            boneAnim.BeginRotate        = 3;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;
            boneAnim.FlagsTransform     = BoneAnimFlagsTransform.Identity;

            if (boneNode.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                var curve = SetAnimationCurve(boneNode.XPOS, (uint)FSKA.TrackType.XPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                var curve = SetAnimationCurve(boneNode.YPOS, (uint)FSKA.TrackType.YPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                var curve = SetAnimationCurve(boneNode.ZPOS, (uint)FSKA.TrackType.ZPOS);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                var curve = SetAnimationCurve(boneNode.XSCA, (uint)FSKA.TrackType.XSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                var curve = SetAnimationCurve(boneNode.YSCA, (uint)FSKA.TrackType.YSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                var curve = SetAnimationCurve(boneNode.ZSCA, (uint)FSKA.TrackType.ZSCA);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                var curve = SetAnimationCurve(boneNode.XROT, (uint)FSKA.TrackType.XROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                var curve = SetAnimationCurve(boneNode.YROT, (uint)FSKA.TrackType.YROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                var curve = SetAnimationCurve(boneNode.ZROT, (uint)FSKA.TrackType.ZROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }
            if (boneNode.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                var curve = SetAnimationCurve(boneNode.WROT, (uint)FSKA.TrackType.WROT);
                if (curve != null)
                {
                    boneAnim.Curves.Add(curve);
                }
            }

            return(boneAnim);
        }
示例#5
0
        public void FromSeanim(string FileName)
        {
            SEAnim anim = SEAnim.Read(FileName);

            if (GetResFileU() != null)
            {
                SkeletalAnimU             = new ResU.SkeletalAnim();
                SkeletalAnimU.FrameCount  = anim.FrameCount;
                SkeletalAnimU.FlagsScale  = ResU.SkeletalAnimFlagsScale.Maya;
                SkeletalAnimU.FlagsRotate = ResU.SkeletalAnimFlagsRotate.EulerXYZ;
                SkeletalAnimU.Loop        = anim.Looping;
                SkeletalAnimU.Name        = System.IO.Path.GetFileNameWithoutExtension(FileName);
                SkeletalAnimU.Path        = "";
            }
            else
            {
                SkeletalAnim             = new SkeletalAnim();
                SkeletalAnim.FrameCount  = anim.FrameCount;
                SkeletalAnim.FlagsScale  = SkeletalAnimFlagsScale.Maya;
                SkeletalAnim.FlagsRotate = SkeletalAnimFlagsRotate.EulerXYZ;
                SkeletalAnim.Loop        = anim.Looping;
                SkeletalAnim.Name        = System.IO.Path.GetFileNameWithoutExtension(FileName);
                SkeletalAnim.Path        = "";
            }

            for (int i = 0; i < anim.Bones.Count; i++)
            {
                if (GetResFileU() != null)
                {
                    var BoneAnimU = new ResU.BoneAnim();
                    BoneAnimU.Name = anim.Bones[i];
                    SkeletalAnimU.BoneAnims.Add(BoneAnimU);
                    SkeletalAnimU.BindIndices[i] = ushort.MaxValue;
                    bool IsRoot = false;

                    if (!IsRoot)
                    {
                        BoneAnimU.ApplyIdentity               = false;
                        BoneAnimU.ApplyRotateTranslateZero    = false;
                        BoneAnimU.ApplyRotateZero             = false;
                        BoneAnimU.ApplyScaleOne               = true;
                        BoneAnimU.ApplyScaleVolumeOne         = true;
                        BoneAnimU.ApplyScaleUniform           = true;
                        BoneAnimU.ApplySegmentScaleCompensate = true;
                        BoneAnimU.ApplyTranslateZero          = false;
                    }
                    else
                    {
                        BoneAnimU.ApplyIdentity               = true;
                        BoneAnimU.ApplyRotateTranslateZero    = true;
                        BoneAnimU.ApplyRotateZero             = true;
                        BoneAnimU.ApplyScaleOne               = true;
                        BoneAnimU.ApplyScaleVolumeOne         = true;
                        BoneAnimU.ApplyScaleUniform           = true;
                        BoneAnimU.ApplySegmentScaleCompensate = false;
                        BoneAnimU.ApplyTranslateZero          = true;
                    }
                }
                else
                {
                    var BoneAnim = new BoneAnim();
                    BoneAnim.Name = anim.Bones[i];
                    SkeletalAnim.BoneAnims.Add(BoneAnim);
                    SkeletalAnim.BindIndices[i] = ushort.MaxValue;

                    //Set base data and curves
                    var baseData = new BoneAnimData();
                    if (anim.AnimationPositionKeys.ContainsKey(anim.Bones[i]) &&
                        anim.AnimationPositionKeys[anim.Bones[i]].Count > 0)
                    {
                        BoneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
                        var keys = anim.AnimationPositionKeys[anim.Bones[i]];
                        var data = (SELib.Utilities.Vector3)keys[0].Data;

                        baseData.Translate = new Syroot.Maths.Vector3F((float)data.X, (float)data.Y, (float)data.Z);

                        if (keys.Count > 1)
                        {
                            AnimCurve curve = new AnimCurve();
                            BoneAnim.Curves.Add(curve);
                            CreateCurveData(curve, keys);
                        }
                    }
                    if (anim.AnimationRotationKeys.ContainsKey(anim.Bones[i]) &&
                        anim.AnimationRotationKeys[anim.Bones[i]].Count > 0)
                    {
                        BoneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
                        var keys = anim.AnimationPositionKeys[anim.Bones[i]];
                        var data = (SELib.Utilities.Quaternion)keys[0].Data;

                        baseData.Rotate = new Syroot.Maths.Vector4F((float)data.X, (float)data.Y, (float)data.Z, (float)data.W);

                        if (keys.Count > 1)
                        {
                            AnimCurve curve = new AnimCurve();
                            BoneAnim.Curves.Add(curve);
                            CreateCurveData(curve, keys);
                        }
                    }
                    if (anim.AnimationScaleKeys.ContainsKey(anim.Bones[i]) &&
                        anim.AnimationScaleKeys[anim.Bones[i]].Count > 0)
                    {
                        BoneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
                        var keys = anim.AnimationPositionKeys[anim.Bones[i]];
                        var data = (SELib.Utilities.Vector3)keys[0].Data;

                        baseData.Scale = new Syroot.Maths.Vector3F((float)data.X, (float)data.Y, (float)data.Z);

                        if (keys.Count > 1)
                        {
                            AnimCurve curve = new AnimCurve();
                            BoneAnim.Curves.Add(curve);
                            CreateCurveData(curve, keys);
                        }
                    }


                    //Set transforms
                    bool IsRoot = false;
                    if (!IsRoot)
                    {
                        BoneAnim.ApplyIdentity               = false;
                        BoneAnim.ApplyRotateTranslateZero    = false;
                        BoneAnim.ApplyRotateZero             = false;
                        BoneAnim.ApplyScaleOne               = true;
                        BoneAnim.ApplyScaleVolumeOne         = true;
                        BoneAnim.ApplyScaleUniform           = true;
                        BoneAnim.ApplySegmentScaleCompensate = true;
                        BoneAnim.ApplyTranslateZero          = false;
                    }
                    else
                    {
                        BoneAnim.ApplyIdentity               = true;
                        BoneAnim.ApplyRotateTranslateZero    = true;
                        BoneAnim.ApplyRotateZero             = true;
                        BoneAnim.ApplyScaleOne               = true;
                        BoneAnim.ApplyScaleVolumeOne         = true;
                        BoneAnim.ApplyScaleUniform           = true;
                        BoneAnim.ApplySegmentScaleCompensate = false;
                        BoneAnim.ApplyTranslateZero          = true;
                    }
                }
            }

            for (int frame = 0; frame < anim.FrameCount; frame++)
            {
            }
        }
        private static BoneAnim createBoneAnim(Animation.KeyNode bone, BfresSkeletonAnim anim)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = bone.Name;
            var posx = bone.XPOS.GetValue(0);
            var posy = bone.YPOS.GetValue(0);
            var posz = bone.ZPOS.GetValue(0);
            var scax = bone.XSCA.GetValue(0);
            var scay = bone.YSCA.GetValue(0);
            var scaz = bone.ZSCA.GetValue(0);
            var rotx = bone.XROT.GetValue(0);
            var roty = bone.YROT.GetValue(0);
            var rotz = bone.ZROT.GetValue(0);
            var rotw = bone.WROT.GetValue(0);

            BoneAnimData boneBaseData = new BoneAnimData();

            boneBaseData.Translate      = new Syroot.Maths.Vector3F(posx, posy, posz);
            boneBaseData.Scale          = new Syroot.Maths.Vector3F(scax, scay, scaz);
            boneBaseData.Rotate         = new Syroot.Maths.Vector4F(rotx, roty, rotz, rotw);
            boneAnim.BaseData           = boneBaseData;
            boneAnim.BeginBaseTranslate = 0;
            boneAnim.BeginRotate        = 0;
            boneAnim.BeginTranslate     = 0;
            boneAnim.Curves             = new List <AnimCurve>();
            boneAnim.FlagsBase          = BoneAnimFlagsBase.Translate | BoneAnimFlagsBase.Scale | BoneAnimFlagsBase.Rotate;
            boneAnim.FlagsTransform     = BoneAnimFlagsTransform.Identity;

            if (bone.XPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XPOS));
            }
            if (bone.YPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YPOS));
            }
            if (bone.ZPOS.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZPOS));
            }
            if (bone.XSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XSCA));
            }
            if (bone.YSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YSCA));
            }
            if (bone.ZSCA.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZSCA));
            }
            if (bone.XROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                boneAnim.Curves.Add(SetAnimationCurve(bone.XROT));
            }
            if (bone.YROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                boneAnim.Curves.Add(SetAnimationCurve(bone.YROT));
            }
            if (bone.ZROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                boneAnim.Curves.Add(SetAnimationCurve(bone.ZROT));
            }
            if (bone.WROT.HasAnimation())
            {
                boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateW;
                boneAnim.Curves.Add(SetAnimationCurve(bone.WROT));
            }

            return(boneAnim);
        }
示例#7
0
        private static BoneAnim Chr0Entry2BoneAnim(CHR0EntryNode entry)
        {
            BoneAnim boneAnim = new BoneAnim();

            boneAnim.Name = entry.Name;
            //   boneAnim.Name = NameConverterMkWii2Mk8(boneAnim.Name);

            if (entry.UseModelTranslate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
            }
            if (entry.UseModelRotate)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
            }
            if (entry.UseModelScale)
            {
                boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            }

            var baseData = new BoneAnimData();

            var FirstFrame = entry.GetAnimFrame(0);

            if (FirstFrame.HasKeys)
            {
                float xRadian = FirstFrame.Rotation._x * Deg2Rad;
                float yRadian = FirstFrame.Rotation._y * Deg2Rad;
                float zRadian = FirstFrame.Rotation._z * Deg2Rad;

                baseData.Translate = new Vector3F(FirstFrame.Translation._x, FirstFrame.Translation._y, FirstFrame.Translation._z);
                baseData.Rotate    = new Vector4F(xRadian, yRadian, zRadian, 1);
                baseData.Scale     = new Vector3F(FirstFrame.Scale._x, FirstFrame.Scale._y, FirstFrame.Scale._z);
                baseData.Flags     = 0;
                boneAnim.BaseData  = baseData;
            }
            else
            {
                baseData.Translate = new Vector3F(0, 0, 0);
                baseData.Rotate    = new Vector4F(0, 0, 0, 1);
                baseData.Scale     = new Vector3F(1, 1, 1);
                baseData.Flags     = 0;
                boneAnim.BaseData  = baseData;
            }


            boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
            boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
            boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;

            if (baseData.Rotate == new Vector4F(0, 0, 0, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.RotateZero;
            }
            if (baseData.Translate == new Vector3F(0, 0, 0))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.TranslateZero;
            }
            if (baseData.Scale == new Vector3F(1, 1, 1))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleOne;
            }
            if (IsUniform(baseData.Scale))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.ScaleUniform;
            }
            if (!IsRoot(boneAnim))
            {
                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.SegmentScaleCompensate;
            }

            boneAnim.BeginTranslate = 6;
            boneAnim.BeginRotate    = 3;

            if (FirstFrame.HasKeys)
            {
                var AnimFrame = entry.GetAnimFrame(0);
                if (AnimFrame.hasTx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateX;
                    var curve = GenerateCurve(0x10, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasTy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateY;
                    var curve = GenerateCurve(0x14, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasTz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.TranslateZ;
                    var curve = GenerateCurve(0x18, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateX;
                    var curve = GenerateCurve(0x20, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateY;
                    var curve = GenerateCurve(0x24, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasRz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.RotateZ;
                    var curve = GenerateCurve(0x28, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSx)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleX;
                    var curve = GenerateCurve(0x4, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSy)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleY;
                    var curve = GenerateCurve(0x8, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
                if (AnimFrame.hasSz)
                {
                    boneAnim.FlagsCurve |= BoneAnimFlagsCurve.ScaleZ;
                    var curve = GenerateCurve(0xC, entry);
                    if (curve != null)
                    {
                        boneAnim.Curves.Add(curve);
                    }
                }
            }

            return(boneAnim);
        }