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 void FromJson(MaterialAnim anim, string json) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); return(settings); }; var animJson = JsonConvert.DeserializeObject <MaterialAnimStuct>(json); anim.Name = animJson.Name; anim.MaterialAnimDataList = new List <MaterialAnimData>(); anim.UserData = UserDataConvert.Convert(animJson.UserData); anim.FrameCount = animJson.FrameCount; if (animJson.Loop) { anim.Flags |= MaterialAnim.MaterialAnimFlags.Looping; } if (animJson.Baked) { anim.Flags |= MaterialAnim.MaterialAnimFlags.BakedCurve; } foreach (var matAnimJson in animJson.MaterialAnims) { MaterialAnimData matAnim = new MaterialAnimData(); anim.MaterialAnimDataList.Add(matAnim); matAnim.Name = matAnimJson.Name; matAnim.PatternAnimInfos = matAnimJson.PatternAnimInfos; matAnim.ParamAnimInfos = matAnimJson.ParameterInfos; matAnim.Constants = matAnimJson.Constants; matAnim.BaseDataList = matAnimJson.BaseDataList.ToArray(); foreach (var curveJson in matAnimJson.Curves) { var target = uint.Parse(curveJson.Target); var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target, false); matAnim.Curves.Add(curve); } } }
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)); }
public static void FromStruct(MaterialAnim anim, MaterialAnimHelper animJson) { anim.TextureNames = new ResDict <TextureRef>(); foreach (var tex in animJson.TextureList) { anim.TextureNames.Add(tex, new TextureRef() { Name = tex }); } anim.Name = animJson.Name; anim.Baked = animJson.Baked; anim.Loop = animJson.Loop; anim.FrameCount = animJson.FrameCount; anim.Baked = animJson.Baked; anim.MaterialAnimDataList = new List <MaterialAnimData>(); anim.BindIndices = new ushort[animJson.MaterialAnims.Count]; for (int i = 0; i < anim.BindIndices.Length; i++) { anim.BindIndices[i] = 65535; } anim.UserData = UserDataConvert.Convert(animJson.UserData); foreach (var matAnimJson in animJson.MaterialAnims) { MaterialAnimData matAnim = new MaterialAnimData(); anim.MaterialAnimDataList.Add(matAnim); matAnim.Name = matAnimJson.Name; matAnim.ParamAnimInfos = new List <ParamAnimInfo>(); matAnim.PatternAnimInfos = new List <PatternAnimInfo>(); matAnim.ShaderParamCurveIndex = 0; List <ushort> texturePatternBase = new List <ushort>(); foreach (var samplerInfo in matAnimJson.Samplers) { var info = new PatternAnimInfo(); info.Name = samplerInfo.Name; info.CurveIndex = -1; if (samplerInfo.Curve != null) { info.CurveIndex = (short)matAnim.Curves.Count; } matAnim.PatternAnimInfos.Add(info); texturePatternBase.Add(samplerInfo.Constant); if (samplerInfo.Curve != null) { matAnim.Curves.Add(CurveAnimHelper.GenerateCurve(samplerInfo.Curve, 0, false)); } } ushort curveIndex = 0; ushort constantIndex = 0; foreach (var paramInfo in matAnimJson.Params) { var info = new ParamAnimInfo(); info.BeginCurve = curveIndex; info.BeginConstant = constantIndex; info.ConstantCount = (ushort)paramInfo.Constants.Count; info.FloatCurveCount = (ushort)paramInfo.Curves.Count(); info.IntCurveCount = 0; info.Name = paramInfo.Name; matAnim.ParamAnimInfos.Add(info); if (paramInfo.Curves.Count > 0) { matAnim.VisualConstantIndex = 0; } foreach (var curveJson in paramInfo.Curves) { uint target = uint.Parse(curveJson.Target); matAnim.Curves.Add(CurveAnimHelper.GenerateCurve(curveJson, target, false)); } foreach (var constJson in paramInfo.Constants) { matAnim.Constants.Add(constJson); } curveIndex += (ushort)matAnim.Curves.Count; constantIndex += (ushort)matAnim.Constants.Count; } matAnim.BaseDataList = texturePatternBase.ToArray(); } }
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)); }
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; } }
public static void FromJson(SceneAnim anim, string json) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); return(settings); }; var animJson = JsonConvert.DeserializeObject <SceneAnimStuct>(json); anim.Name = animJson.Name; anim.CameraAnims = new ResDict <CameraAnim>(); anim.LightAnims = new ResDict <LightAnim>(); anim.FogAnims = new ResDict <FogAnim>(); anim.UserData = UserDataConvert.Convert(animJson.UserData); foreach (var camAnimJson in animJson.CameraAnims) { CameraAnim camAnim = new CameraAnim(); camAnim.Flags = 0; anim.CameraAnims.Add(camAnimJson.Name, camAnim); if (camAnimJson.Loop) { camAnim.Flags |= CameraAnimFlags.Looping; } if (camAnimJson.Baked) { camAnim.Flags |= CameraAnimFlags.BakedCurve; } if (camAnimJson.Perspective) { camAnim.Flags |= CameraAnimFlags.Perspective; } if (camAnimJson.EulerRotation) { camAnim.Flags |= CameraAnimFlags.EulerZXY; } camAnim.Name = camAnimJson.Name; camAnim.FrameCount = camAnimJson.FrameCount; camAnim.BaseData = camAnimJson.BaseData; foreach (var curveJson in camAnimJson.Curves) { var target = (CameraAnimDataOffset)Enum.Parse(typeof(CameraAnimDataOffset), curveJson.Target); var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target, false); camAnim.Curves.Add(curve); } } foreach (var lightAnimJson in animJson.LightAnims) { LightAnim lightAnim = new LightAnim(); lightAnim.Flags = 0; anim.LightAnims.Add(lightAnimJson.Name, lightAnim); if (lightAnimJson.Loop) { lightAnim.Flags |= LightAnimFlags.Looping; } if (lightAnimJson.Baked) { lightAnim.Flags |= LightAnimFlags.BakedCurve; } if (lightAnimJson.BaseAngleAttn) { lightAnim.Flags |= LightAnimFlags.BaseAngleAttn; } if (lightAnimJson.BaseColor0) { lightAnim.Flags |= LightAnimFlags.BaseColor0; } if (lightAnimJson.BaseColor1) { lightAnim.Flags |= LightAnimFlags.BaseColor1; } if (lightAnimJson.BaseDir) { lightAnim.Flags |= LightAnimFlags.BaseDir; } if (lightAnimJson.BaseDistAttn) { lightAnim.Flags |= LightAnimFlags.BaseDistAttn; } if (lightAnimJson.BasePos) { lightAnim.Flags |= LightAnimFlags.BasePos; } lightAnim.Name = lightAnimJson.Name; lightAnim.FrameCount = lightAnimJson.FrameCount; lightAnim.BaseData = lightAnimJson.BaseData; if (lightAnim.BaseData.Enable == 1) { lightAnim.Flags |= LightAnimFlags.BaseEnable; } foreach (var curveJson in lightAnimJson.Curves) { var target = (CameraAnimDataOffset)Enum.Parse(typeof(CameraAnimDataOffset), curveJson.Target); var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target, false); lightAnim.Curves.Add(curve); } } foreach (var fogAnimJson in animJson.FogAnims) { FogAnim fogAnim = new FogAnim(); fogAnim.Flags = 0; anim.CameraAnims.Add(fogAnimJson.Name, fogAnim); if (fogAnimJson.Loop) { fogAnim.Flags |= FogAnimFlags.Looping; } if (fogAnimJson.Baked) { fogAnim.Flags |= FogAnimFlags.BakedCurve; } fogAnim.Name = fogAnimJson.Name; fogAnim.FrameCount = fogAnimJson.FrameCount; fogAnim.DistanceAttnFuncIndex = fogAnimJson.DistanceAttnFuncIndex; fogAnim.DistanceAttnFuncName = fogAnimJson.DistanceAttnFuncName; fogAnim.BaseData = fogAnimJson.BaseData; foreach (var curveJson in fogAnimJson.Curves) { var target = (CameraAnimDataOffset)Enum.Parse(typeof(CameraAnimDataOffset), curveJson.Target); var curve = CurveAnimHelper.GenerateCurve(curveJson, (uint)target, false); fogAnim.Curves.Add(curve); } } }
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)); }