Пример #1
0
        public static SkeletalAnim FromStruct(SkeletalAnimHelper skelAnim)
        {
            SkeletalAnim anim = new SkeletalAnim();

            FromStruct(anim, skelAnim);
            return(anim);
        }
Пример #2
0
        public static string ToJson(SkeletalAnim anim)
        {
            SkeletalAnimHelper animConv = new SkeletalAnimHelper();

            animConv.Name        = anim.Name;
            animConv.Path        = anim.Path;
            animConv.Loop        = anim.Loop;
            animConv.Baked       = anim.Baked;
            animConv.FrameCount  = anim.FrameCount;
            animConv.FlagsScale  = anim.FlagsScale;
            animConv.FlagsRotate = anim.FlagsRotate;
            animConv.BoneAnims   = new List <BoneAnimHelper>();

            foreach (var boneAnim in anim.BoneAnims)
            {
                BoneAnimHelper boneAnimConv = new BoneAnimHelper();
                boneAnimConv.Curves = new List <CurveAnimHelper>();
                boneAnimConv.Name   = boneAnim.Name;
                Vector4F rotation = boneAnim.BaseData.Rotate;
                if (animConv.UseDegrees && animConv.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                {
                    rotation = new Vector4F(
                        rotation.X * CurveAnimHelper.Rad2Deg,
                        rotation.Y * CurveAnimHelper.Rad2Deg,
                        rotation.Z * CurveAnimHelper.Rad2Deg,
                        rotation.W);
                }

                boneAnimConv.BaseData = new BaseDataHelper()
                {
                    Flags     = boneAnim.BaseData.Flags,
                    Rotate    = rotation,
                    Translate = boneAnim.BaseData.Translate,
                    Scale     = boneAnim.BaseData.Scale,
                };
                boneAnimConv.SegmentScaleCompensate = boneAnim.ApplySegmentScaleCompensate;
                boneAnimConv.UseBaseTranslation     = boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Translate);
                boneAnimConv.UseBaseRotation        = boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Rotate);
                boneAnimConv.UseBaseScale           = boneAnim.FlagsBase.HasFlag(BoneAnimFlagsBase.Scale);
                animConv.BoneAnims.Add(boneAnimConv);

                foreach (var curve in boneAnim.Curves)
                {
                    string target    = ((AnimTarget)curve.AnimDataOffset).ToString();
                    var    convCurve = CurveAnimHelper.FromCurve(curve, target,
                                                                 target.Contains("Rotate") && animConv.UseDegrees);
                    boneAnimConv.Curves.Add(convCurve);
                }
            }

            foreach (var param in anim.UserData.Values)
            {
                animConv.UserData.Add($"{param.Type}|{param.Name}", param.GetData());
            }

            JsonConvert.DefaultSettings = () =>
            {
                var settings = new JsonSerializerSettings();
                return(settings);
            };

            return(JsonConvert.SerializeObject(animConv, Formatting.Indented));
        }
Пример #3
0
        public static void FromStruct(SkeletalAnim anim, SkeletalAnimHelper animJson)
        {
            anim.Name        = animJson.Name;
            anim.Baked       = animJson.Baked;
            anim.Loop        = animJson.Loop;
            anim.FrameCount  = animJson.FrameCount;
            anim.Baked       = animJson.Baked;
            anim.FlagsRotate = animJson.FlagsRotate;
            anim.FlagsScale  = animJson.FlagsScale;
            anim.BoneAnims   = new List <BoneAnim>();
            anim.BindIndices = new ushort[animJson.BoneAnims.Count];
            anim.UserData    = UserDataConvert.Convert(animJson.UserData);

            foreach (var boneAnimJson in animJson.BoneAnims)
            {
                BoneAnim boneAnim = new BoneAnim();
                anim.BoneAnims.Add(boneAnim);

                //Always these indices
                boneAnim.Name               = boneAnimJson.Name;
                boneAnim.BeginRotate        = 3;
                boneAnim.BeginTranslate     = 6;
                boneAnim.BeginBaseTranslate = 7;
                Vector4F rotation = boneAnimJson.BaseData.Rotate;
                if (animJson.UseDegrees && animJson.FlagsRotate == SkeletalAnimFlagsRotate.EulerXYZ)
                {
                    rotation = new Vector4F(
                        rotation.X * CurveAnimHelper.Deg2Rad,
                        rotation.Y * CurveAnimHelper.Deg2Rad,
                        rotation.Z * CurveAnimHelper.Deg2Rad,
                        rotation.W);
                }
                boneAnim.BaseData = new BoneAnimData()
                {
                    Flags     = boneAnimJson.BaseData.Flags,
                    Rotate    = rotation,
                    Translate = boneAnimJson.BaseData.Translate,
                    Scale     = boneAnimJson.BaseData.Scale,
                };

                boneAnim.FlagsTransform |= BoneAnimFlagsTransform.Identity;
                if (boneAnimJson.UseBaseTranslation)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Translate;
                }
                if (boneAnimJson.UseBaseRotation)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Rotate;
                }
                if (boneAnimJson.UseBaseScale)
                {
                    boneAnim.FlagsBase |= BoneAnimFlagsBase.Scale;
                }
                foreach (var curveJson in boneAnimJson.Curves)
                {
                    var target = (AnimTarget)Enum.Parse(typeof(AnimTarget), curveJson.Target);

                    var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target,
                                                              curveJson.Target.Contains("Rotate") && animJson.UseDegrees);
                    boneAnim.Curves.Add(curve);
                    boneAnim.FlagsCurve = SetCurveTarget(target);
                }
                boneAnim.CalculateTransformFlags();
                boneAnim.ApplySegmentScaleCompensate = boneAnimJson.SegmentScaleCompensate;
            }
        }