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 void FromJson(VisibilityAnim anim, string json) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); return(settings); }; var animJson = JsonConvert.DeserializeObject <BoneVisibilityAnimStruct>(json); anim.Name = animJson.Name; anim.Baked = animJson.Baked; anim.Loop = animJson.Loop; anim.FrameCount = animJson.FrameCount; anim.Baked = animJson.Baked; anim.BindIndices = new ushort[animJson.Groups.Count]; anim.UserData = UserDataConvert.Convert(animJson.UserData); foreach (var groupAnimJson in animJson.Groups) { var curve = groupAnimJson.Curves; } }
public static List <MeshMetaInfo> FromJson(Material mat, string json) { JsonConvert.DefaultSettings = () => { var settings = new JsonSerializerSettings(); return(settings); }; var matJson = JsonConvert.DeserializeObject <MaterialStruct>(json); mat.Name = matJson.Name; mat.Visible = matJson.Visible; mat.ShaderAssign = ConvertShaderAssign(matJson.ShaderAssign); mat.TextureRefs = new List <TextureRef>(); mat.Samplers = new ResDict <Sampler>(); mat.ShaderParams = new ResDict <ShaderParam>(); mat.UserData = new ResDict <UserData>(); mat.RenderInfos = new ResDict <RenderInfo>(); mat.ShaderParamData = new byte[0]; mat.VolatileFlags = new byte[0]; if (matJson.RenderState != null) { mat.RenderState = matJson.RenderState; } foreach (var tex in matJson.Textures) { mat.TextureRefs.Add(new TextureRef() { Name = tex }); } foreach (var sampler in matJson.Samplers) { mat.Samplers.Add(sampler.Name, sampler); } mat.TextureSlotArray = new long[matJson.Textures.Count]; mat.SamplerSlotArray = new long[matJson.Textures.Count]; mat.VolatileFlags = matJson.VolatileFlags; foreach (var param in matJson.Parameters) { string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; ShaderParam shaderParam = new ShaderParam(); shaderParam.Name = name; var dataType = (ShaderParamType)Enum.Parse(typeof(ShaderParamType), type); object value = null; switch (dataType) { case ShaderParamType.Float: value = Convert.ToSingle(param.Value); break; case ShaderParamType.UInt: value = Convert.ToUInt32(param.Value); break; case ShaderParamType.Int: value = Convert.ToInt32(param.Value); break; case ShaderParamType.Bool: value = Convert.ToBoolean(param.Value); break; case ShaderParamType.Srt2D: value = ((JObject)param.Value).ToObject <Srt2D>(); break; case ShaderParamType.Srt3D: value = ((JObject)param.Value).ToObject <Srt3D>(); break; case ShaderParamType.TexSrt: value = ((JObject)param.Value).ToObject <TexSrt>(); break; case ShaderParamType.TexSrtEx: value = ((JObject)param.Value).ToObject <TexSrt>(); break; case ShaderParamType.Float2: case ShaderParamType.Float2x2: case ShaderParamType.Float2x3: case ShaderParamType.Float2x4: case ShaderParamType.Float3: case ShaderParamType.Float3x2: case ShaderParamType.Float3x3: case ShaderParamType.Float3x4: case ShaderParamType.Float4: case ShaderParamType.Float4x2: case ShaderParamType.Float4x3: case ShaderParamType.Float4x4: value = ((JArray)param.Value).ToObject <float[]>(); break; case ShaderParamType.Bool2: case ShaderParamType.Bool3: case ShaderParamType.Bool4: value = ((JArray)param.Value).ToObject <bool>(); break; case ShaderParamType.Int2: case ShaderParamType.Int3: case ShaderParamType.Int4: value = ((JArray)param.Value).ToObject <int[]>(); break; case ShaderParamType.UInt2: case ShaderParamType.UInt3: case ShaderParamType.UInt4: value = ((JArray)param.Value).ToObject <uint[]>(); break; default: throw new Exception($"Unsupported parameter type! {type}"); } mat.SetShaderParameter(name, dataType, value); } foreach (var param in matJson.RenderInfo) { string type = param.Key.Split('|')[0]; string name = param.Key.Split('|')[1]; RenderInfoType dataType = (RenderInfoType)Enum.Parse(typeof(RenderInfoType), type); if (dataType == RenderInfoType.Single) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <float[]>()); } if (dataType == RenderInfoType.Int32) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <int[]>()); } if (dataType == RenderInfoType.String) { mat.SetRenderInfo(name, ((JArray)param.Value).ToObject <string[]>()); } } mat.UserData = UserDataConvert.Convert(matJson.UserData); return(matJson.MeshInfo); }
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); } } }