public static string ToJson(MaterialAnim anim)
        {
            MaterialAnimStuct animConv = new MaterialAnimStuct();

            animConv.Name          = anim.Name;
            animConv.Path          = anim.Path;
            animConv.MaterialAnims = new List <MaterialAnimGroupStruct>();
            animConv.FrameCount    = anim.FrameCount;
            animConv.Loop          = anim.Flags.HasFlag(MaterialAnim.MaterialAnimFlags.Looping);
            animConv.Baked         = anim.Flags.HasFlag(MaterialAnim.MaterialAnimFlags.BakedCurve);

            foreach (var matAnim in anim.MaterialAnimDataList)
            {
                MaterialAnimGroupStruct matAnimConv = new MaterialAnimGroupStruct();
                animConv.MaterialAnims.Add(matAnimConv);

                matAnimConv.Curves = new List <CurveAnimHelper>();
                matAnimConv.Name   = matAnim.Name;
                if (matAnim.Constants != null)
                {
                    matAnimConv.Constants = matAnim.Constants.ToList();
                }
                if (matAnim.BaseDataList != null)
                {
                    matAnimConv.BaseDataList = matAnim.BaseDataList.ToList();
                }
                if (matAnim.ParamAnimInfos != null)
                {
                    matAnimConv.ParameterInfos = matAnim.ParamAnimInfos.ToList();
                }
                if (matAnim.PatternAnimInfos != null)
                {
                    matAnimConv.PatternAnimInfos = matAnim.PatternAnimInfos.ToList();
                }

                foreach (var curve in matAnim.Curves)
                {
                    string target = curve.AnimDataOffset.ToString();

                    var convCurve = CurveAnimHelper.FromCurve(curve, target, false);
                    matAnimConv.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));
        }
        public static string ToJson(VisibilityAnim anim)
        {
            BoneVisibilityAnimStruct animConv = new BoneVisibilityAnimStruct();

            animConv.Name       = anim.Name;
            animConv.Path       = anim.Path;
            animConv.Loop       = anim.Loop;
            animConv.Baked      = anim.Baked;
            animConv.FrameCount = anim.FrameCount;
            animConv.Groups     = new List <VisAnimGroupStruct>();

            for (int i = 0; i < anim.Names?.Count; i++)
            {
                VisAnimGroupStruct groupConv = new VisAnimGroupStruct();
                groupConv.Curves      = new List <CurveAnimHelper>();
                groupConv.BaseVisible = anim.BaseDataList[i];
                groupConv.Name        = anim.Names[i];
                animConv.Groups.Add(groupConv);

                foreach (var curve in anim.Curves)
                {
                    if (curve.AnimDataOffset == i)
                    {
                        groupConv.Curves.Add(CurveAnimHelper.FromCurve(curve, "", false));
                    }
                }
            }

            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));
        }
Ejemplo n.º 3
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));
        }
Ejemplo n.º 4
0
        public static string ToJson(SceneAnim anim)
        {
            SceneAnimStuct animConv = new SceneAnimStuct();

            animConv.Name        = anim.Name;
            animConv.Path        = anim.Path;
            animConv.CameraAnims = new List <CameraAnimStruct>();
            animConv.LightAnims  = new List <LightAnimStruct>();
            animConv.FogAnims    = new List <FogAnimStruct>();

            foreach (var camAnim in anim.CameraAnims.Values)
            {
                CameraAnimStruct camAnimConv = new CameraAnimStruct();
                camAnimConv.Curves        = new List <CurveAnimHelper>();
                camAnimConv.Name          = camAnim.Name;
                camAnimConv.FrameCount    = camAnim.FrameCount;
                camAnimConv.Loop          = camAnim.Flags.HasFlag(CameraAnimFlags.Looping);
                camAnimConv.Baked         = camAnim.Flags.HasFlag(CameraAnimFlags.BakedCurve);
                camAnimConv.BaseData      = camAnim.BaseData;
                camAnimConv.EulerRotation = camAnim.Flags.HasFlag(CameraAnimFlags.EulerZXY);
                camAnimConv.Perspective   = camAnim.Flags.HasFlag(CameraAnimFlags.Perspective);

                animConv.CameraAnims.Add(camAnimConv);
                foreach (var curve in camAnim.Curves)
                {
                    string target = ((CameraAnimDataOffset)curve.AnimDataOffset).ToString();

                    bool isDegrees = target.Contains("Rotation") && animConv.UseDegrees && camAnimConv.EulerRotation;
                    var  convCurve = CurveAnimHelper.FromCurve(curve, target, isDegrees);
                    camAnimConv.Curves.Add(convCurve);
                }
            }
            foreach (var lightAnim in anim.LightAnims.Values)
            {
                LightAnimStruct lightAnimConv = new LightAnimStruct();
                lightAnimConv.Curves        = new List <CurveAnimHelper>();
                lightAnimConv.Name          = lightAnim.Name;
                lightAnimConv.FrameCount    = lightAnim.FrameCount;
                lightAnimConv.Loop          = lightAnim.Flags.HasFlag(LightAnimFlags.Looping);
                lightAnimConv.Baked         = lightAnim.Flags.HasFlag(LightAnimFlags.BakedCurve);
                lightAnimConv.BaseAngleAttn = lightAnim.Flags.HasFlag(LightAnimFlags.BaseAngleAttn);
                lightAnimConv.BaseColor0    = lightAnim.Flags.HasFlag(LightAnimFlags.BaseColor0);
                lightAnimConv.BaseColor1    = lightAnim.Flags.HasFlag(LightAnimFlags.BaseColor1);
                lightAnimConv.BaseDir       = lightAnim.Flags.HasFlag(LightAnimFlags.BaseDir);
                lightAnimConv.BaseDistAttn  = lightAnim.Flags.HasFlag(LightAnimFlags.BaseDistAttn);
                lightAnimConv.BasePos       = lightAnim.Flags.HasFlag(LightAnimFlags.BasePos);
                if (lightAnim.Flags.HasFlag(LightAnimFlags.BaseEnable))
                {
                    lightAnimConv.BaseData = lightAnim.BaseData;
                }

                animConv.LightAnims.Add(lightAnimConv);
                foreach (var curve in lightAnim.Curves)
                {
                    string target    = ((LightAnimDataOffset)curve.AnimDataOffset).ToString();
                    var    convCurve = CurveAnimHelper.FromCurve(curve, target, false);
                    lightAnimConv.Curves.Add(convCurve);
                }
            }
            foreach (var fogAnim in anim.FogAnims.Values)
            {
                FogAnimStruct fogAnimConv = new FogAnimStruct();
                fogAnimConv.Curves                = new List <CurveAnimHelper>();
                fogAnimConv.Name                  = fogAnim.Name;
                fogAnimConv.FrameCount            = fogAnim.FrameCount;
                fogAnimConv.Loop                  = fogAnim.Flags.HasFlag(FogAnimFlags.Looping);
                fogAnimConv.Baked                 = fogAnim.Flags.HasFlag(FogAnimFlags.BakedCurve);
                fogAnimConv.BaseData              = fogAnim.BaseData;
                fogAnimConv.DistanceAttnFuncIndex = fogAnim.DistanceAttnFuncIndex;
                fogAnimConv.DistanceAttnFuncName  = fogAnim.DistanceAttnFuncName;

                animConv.FogAnims.Add(fogAnimConv);
                foreach (var curve in fogAnim.Curves)
                {
                    string target    = ((FogAnimDataOffset)curve.AnimDataOffset).ToString();
                    var    convCurve = CurveAnimHelper.FromCurve(curve, target, false);
                    fogAnimConv.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));
        }