public static byte[] GetBytes(Data.RendererCommonValues value, Dictionary<string, int> texture_and_index, Dictionary<string, int> distortionTexture_and_index) { List<byte[]> data = new List<byte[]>(); var texInfo = new TextureInformation(); var hasTexture = true; // テクスチャ番号 if (value.Distortion.Value) { if (value.ColorTexture.RelativePath != string.Empty && distortionTexture_and_index.ContainsKey(value.ColorTexture.RelativePath) && texInfo.Load(value.ColorTexture.AbsolutePath)) { data.Add(distortionTexture_and_index[value.ColorTexture.RelativePath].GetBytes()); hasTexture = true; } else { data.Add((-1).GetBytes()); hasTexture = false; } } else { if (value.ColorTexture.RelativePath != string.Empty && texture_and_index.ContainsKey(value.ColorTexture.RelativePath) && texInfo.Load(value.ColorTexture.AbsolutePath)) { data.Add(texture_and_index[value.ColorTexture.RelativePath].GetBytes()); hasTexture = true; } else { data.Add((-1).GetBytes()); hasTexture = false; } } data.Add(value.AlphaBlend); data.Add(value.Filter); data.Add(value.Wrap); if (value.ZTest.GetValue()) { data.Add((1).GetBytes()); } else { data.Add((0).GetBytes()); } if (value.ZWrite.GetValue()) { data.Add((1).GetBytes()); } else { data.Add((0).GetBytes()); } data.Add(value.FadeInType); if (value.FadeInType.Value == Data.RendererCommonValues.FadeType.Use) { data.Add(value.FadeIn.Frame.GetBytes()); var easing = Utl.MathUtl.Easing((float)value.FadeIn.StartSpeed.Value, (float)value.FadeIn.EndSpeed.Value); data.Add(BitConverter.GetBytes(easing[0])); data.Add(BitConverter.GetBytes(easing[1])); data.Add(BitConverter.GetBytes(easing[2])); } data.Add(value.FadeOutType); if (value.FadeOutType.Value == Data.RendererCommonValues.FadeType.Use) { data.Add(value.FadeOut.Frame.GetBytes()); var easing = Utl.MathUtl.Easing((float)value.FadeOut.StartSpeed.Value, (float)value.FadeOut.EndSpeed.Value); data.Add(BitConverter.GetBytes(easing[0])); data.Add(BitConverter.GetBytes(easing[1])); data.Add(BitConverter.GetBytes(easing[2])); } if (hasTexture) { var width = (float)texInfo.Width; var height = (float)texInfo.Height; data.Add(value.UV); if (value.UV.Value == Data.RendererCommonValues.UVType.Default) { } else if (value.UV.Value == Data.RendererCommonValues.UVType.Fixed) { var value_ = value.UVFixed; data.Add((value_.Start.X / width).GetBytes()); data.Add((value_.Start.Y / height).GetBytes()); data.Add((value_.Size.X / width).GetBytes()); data.Add((value_.Size.Y / height).GetBytes()); } else if (value.UV.Value == Data.RendererCommonValues.UVType.Animation) { var value_ = value.UVAnimation; data.Add((value_.Start.X / width).GetBytes()); data.Add((value_.Start.Y / height).GetBytes()); data.Add((value_.Size.X / width).GetBytes()); data.Add((value_.Size.Y / height).GetBytes()); data.Add(value_.FrameLength.Value.GetBytes()); data.Add(value_.FrameCountX.Value.GetBytes()); data.Add(value_.FrameCountY.Value.GetBytes()); data.Add(value_.LoopType); } else if (value.UV.Value == Data.RendererCommonValues.UVType.Scroll) { var value_ = value.UVScroll; data.Add((value_.Start.X / width).GetBytes()); data.Add((value_.Start.Y / height).GetBytes()); data.Add((value_.Size.X / width).GetBytes()); data.Add((value_.Size.Y / height).GetBytes()); data.Add((value_.Speed.X / width).GetBytes()); data.Add((value_.Speed.Y / height).GetBytes()); } } else { data.Add(((int)Data.RendererCommonValues.UVType.Default).GetBytes()); } // 歪み if (value.Distortion.GetValue()) { data.Add((1).GetBytes()); } else { data.Add((0).GetBytes()); } data.Add(value.DistortionIntensity.GetBytes()); return data.ToArray().ToArray(); }
public bool Load(byte[] file) { var br = new System.IO.BinaryReader(new System.IO.MemoryStream(file)); var buf = new byte[1024]; if (br.Read(buf, 0, 16) != 16) { br.Close(); return(false); } if (buf[0] != 'E' || buf[1] != 'F' || buf[2] != 'K' || buf[3] != 'M') { return(false); } int version = BitConverter.ToInt32(buf, 4); if (version > (int)LatestSupportVersion) { return(false); } GUID = BitConverter.ToUInt64(buf, 8); while (true) { if (br.Read(buf, 0, 8) != 8) { br.Close(); break; } if (buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'S' && buf[3] == 'C') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Names.Add((Language)lang, name); Descriptions.Add((Language)lang, desc); } } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '_') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); reader.Get(ref ShadingModel); reader.Get(ref HasNormal); reader.Get(ref HasRefraction); reader.Get(ref CustomData1Count); reader.Get(ref CustomData2Count); int textureCount = 0; reader.Get(ref textureCount); List <TextureInformation> textures = new List <TextureInformation>(); for (int i = 0; i < textureCount; i++) { TextureInformation info = new TextureInformation(); reader.Get(ref info.Name, Encoding.UTF8); // name is for human, uniformName is a variable name after 3 if (version >= 3) { reader.Get(ref info.UniformName, Encoding.UTF8); } else { info.UniformName = info.Name; } reader.Get(ref info.DefaultPath, Encoding.UTF8); reader.Get(ref info.Index); reader.Get(ref info.Priority); reader.Get(ref info.IsParam); int textureType = 0; reader.Get(ref textureType); info.Type = (TextureType)textureType; reader.Get(ref info.Sampler); // convert a path into absolute if (string.IsNullOrEmpty(info.DefaultPath)) { info.DefaultPath = string.Empty; } textures.Add(info); } Textures = textures.ToArray(); int uniformCount = 0; reader.Get(ref uniformCount); List <UniformInformation> uniforms = new List <UniformInformation>(); for (int i = 0; i < uniformCount; i++) { UniformInformation info = new UniformInformation(); reader.Get(ref info.Name, Encoding.UTF8); // name is for human, uniformName is a variable name after 3 if (version >= 3) { reader.Get(ref info.UniformName, Encoding.UTF8); } else { info.UniformName = info.Name; } reader.Get(ref info.Offset); reader.Get(ref info.Priority); reader.Get(ref info.Type); reader.Get(ref info.DefaultValues[0]); reader.Get(ref info.DefaultValues[1]); reader.Get(ref info.DefaultValues[2]); reader.Get(ref info.DefaultValues[3]); uniforms.Add(info); } Uniforms = uniforms.ToArray(); } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '2') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); if (version >= 2) { int customDataCount = 0; reader.Get(ref customDataCount); AllocateCustomData(customDataCount); for (int j = 0; j < customDataCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); CustomData[j].Summaries.Add((Language)lang, name); CustomData[j].Descriptions.Add((Language)lang, desc); } } } int textureCount = 0; reader.Get(ref textureCount); for (int j = 0; j < textureCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Textures[j].Summaries.Add((Language)lang, name); Textures[j].Descriptions.Add((Language)lang, desc); } } int uniformCount = 0; reader.Get(ref uniformCount); for (int j = 0; j < uniformCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Uniforms[j].Summaries.Add((Language)lang, name); Uniforms[j].Descriptions.Add((Language)lang, desc); } } } if (buf[0] == 'E' && buf[1] == '_' && buf[2] == 'C' && buf[3] == 'D') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int customDataCount = 0; reader.Get(ref customDataCount); AllocateCustomData(customDataCount); for (int j = 0; j < customDataCount; j++) { reader.Get(ref CustomData[j].DefaultValues[0]); reader.Get(ref CustomData[j].DefaultValues[1]); reader.Get(ref CustomData[j].DefaultValues[2]); reader.Get(ref CustomData[j].DefaultValues[3]); } } if (buf[0] == 'G' && buf[1] == 'E' && buf[2] == 'N' && buf[3] == 'E') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); reader.Get(ref Code, Encoding.UTF8); } if (buf[0] == 'D' && buf[1] == 'A' && buf[2] == 'T' && buf[3] == 'A') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } string jsonText = Encoding.UTF8.GetString(temp); EditorData = JsonConvert.DeserializeObject <JObject>(jsonText); } } return(true); }
public bool Load(string path) { if (string.IsNullOrEmpty(path)) { return(false); } System.IO.FileStream fs = null; if (!System.IO.File.Exists(path)) { return(false); } try { fs = System.IO.File.Open(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); } catch (System.IO.FileNotFoundException e) { return(false); } var br = new System.IO.BinaryReader(fs); var buf = new byte[1024]; if (br.Read(buf, 0, 16) != 16) { fs.Dispose(); br.Close(); return(false); } if (buf[0] != 'e' || buf[1] != 'f' || buf[2] != 'k' || buf[3] != 'M') { return(false); } int version = BitConverter.ToInt32(buf, 4); UInt64 guid = BitConverter.ToUInt64(buf, 8); while (true) { if (br.Read(buf, 0, 8) != 8) { fs.Dispose(); br.Close(); break; } if (buf[0] == 'p' && buf[1] == 'a' && buf[2] == 'r' && buf[3] == 'a') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int shadingModel = 0; reader.Get(ref shadingModel); bool hasNormal = false; reader.Get(ref hasNormal); bool hasReflection = false; reader.Get(ref hasReflection); int textureCount = 0; reader.Get(ref textureCount); List <TextureInformation> textures = new List <TextureInformation>(); for (int i = 0; i < textureCount; i++) { TextureInformation info = new TextureInformation(); reader.Get(ref info.Name); reader.Get(ref info.DefaultPath); reader.Get(ref info.Index); reader.Get(ref info.IsParam); int textureType = 0; reader.Get(ref textureType); info.Type = (TextureType)textureType; // convert a path into absolute if (string.IsNullOrEmpty(info.DefaultPath)) { info.DefaultPath = string.Empty; } else { Func <string, string> escape = (string s) => { return(s.Replace("%", "%25")); }; Func <string, string> unescape = (string s) => { return(s.Replace("%25", "%")); }; Uri basePath = new Uri(path); Uri targetPath = new Uri(basePath, info.DefaultPath); info.DefaultPath = targetPath.AbsolutePath; } textures.Add(info); } Textures = textures.ToArray(); int uniformCount = 0; reader.Get(ref uniformCount); List <UniformInformation> uniforms = new List <UniformInformation>(); for (int i = 0; i < uniformCount; i++) { UniformInformation info = new UniformInformation(); reader.Get(ref info.Name); reader.Get(ref info.Offset); reader.Get(ref info.Type); reader.Get(ref info.DefaultValues[0]); reader.Get(ref info.DefaultValues[1]); reader.Get(ref info.DefaultValues[2]); reader.Get(ref info.DefaultValues[3]); uniforms.Add(info); } Uniforms = uniforms.ToArray(); } } return(true); }
public bool Load(string path) { if (string.IsNullOrEmpty(path)) { return(false); } System.IO.FileStream fs = null; if (!System.IO.File.Exists(path)) { return(false); } try { fs = System.IO.File.Open(path, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.Read); } catch (System.IO.FileNotFoundException e) { return(false); } var br = new System.IO.BinaryReader(fs); var buf = new byte[1024]; if (br.Read(buf, 0, 16) != 16) { fs.Dispose(); br.Close(); return(false); } if (buf[0] != 'E' || buf[1] != 'F' || buf[2] != 'K' || buf[3] != 'M') { return(false); } int version = BitConverter.ToInt32(buf, 4); GUID = BitConverter.ToUInt64(buf, 8); while (true) { if (br.Read(buf, 0, 8) != 8) { fs.Dispose(); br.Close(); break; } if (buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'S' && buf[3] == 'C') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Names.Add((Language)lang, name); Descriptions.Add((Language)lang, desc); } } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '_') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int shadingModel = 0; reader.Get(ref shadingModel); bool hasNormal = false; reader.Get(ref hasNormal); bool hasReflection = false; reader.Get(ref hasReflection); int customData1Count = 0; reader.Get(ref customData1Count); int customData2Count = 0; reader.Get(ref customData2Count); int textureCount = 0; reader.Get(ref textureCount); List <TextureInformation> textures = new List <TextureInformation>(); for (int i = 0; i < textureCount; i++) { TextureInformation info = new TextureInformation(); reader.Get(ref info.Name, Encoding.UTF8); reader.Get(ref info.DefaultPath, Encoding.UTF8); reader.Get(ref info.Index); reader.Get(ref info.Priority); reader.Get(ref info.IsParam); int textureType = 0; reader.Get(ref textureType); info.Type = (TextureType)textureType; int sampler = 0; reader.Get(ref sampler); // convert a path into absolute if (string.IsNullOrEmpty(info.DefaultPath)) { info.DefaultPath = string.Empty; } else { Func <string, string> escape = (string s) => { return(s.Replace("%", "%25")); }; Func <string, string> unescape = (string s) => { return(s.Replace("%25", "%")); }; Uri basePath = new Uri(path); Uri targetPath = new Uri(basePath, info.DefaultPath); info.DefaultPath = targetPath.AbsolutePath; } textures.Add(info); } Textures = textures.ToArray(); int uniformCount = 0; reader.Get(ref uniformCount); List <UniformInformation> uniforms = new List <UniformInformation>(); for (int i = 0; i < uniformCount; i++) { UniformInformation info = new UniformInformation(); reader.Get(ref info.Name, Encoding.UTF8); reader.Get(ref info.Offset); reader.Get(ref info.Priority); reader.Get(ref info.Type); reader.Get(ref info.DefaultValues[0]); reader.Get(ref info.DefaultValues[1]); reader.Get(ref info.DefaultValues[2]); reader.Get(ref info.DefaultValues[3]); uniforms.Add(info); } Uniforms = uniforms.ToArray(); } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '2') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int textureCount = 0; reader.Get(ref textureCount); for (int j = 0; j < textureCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Textures[j].Names.Add((Language)lang, name); Textures[j].Descriptions.Add((Language)lang, desc); } } int uniformCount = 0; reader.Get(ref uniformCount); for (int j = 0; j < uniformCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Uniforms[j].Names.Add((Language)lang, name); Uniforms[j].Descriptions.Add((Language)lang, desc); } } } } return(true); }
public bool Load(string path) { if (string.IsNullOrEmpty(path)) { return(false); } byte[] file = null; if (Core.OnFileLoaded != null) { file = Core.OnFileLoaded(path); if (file == null) { return(false); } } else { if (!System.IO.File.Exists(path)) { return(false); } try { file = System.IO.File.ReadAllBytes(path); } catch { return(false); } } var br = new System.IO.BinaryReader(new System.IO.MemoryStream(file)); var buf = new byte[1024]; if (br.Read(buf, 0, 16) != 16) { br.Close(); return(false); } if (buf[0] != 'E' || buf[1] != 'F' || buf[2] != 'K' || buf[3] != 'M') { return(false); } int version = BitConverter.ToInt32(buf, 4); GUID = BitConverter.ToUInt64(buf, 8); while (true) { if (br.Read(buf, 0, 8) != 8) { br.Close(); break; } if (buf[0] == 'D' && buf[1] == 'E' && buf[2] == 'S' && buf[3] == 'C') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Names.Add((Language)lang, name); Descriptions.Add((Language)lang, desc); } } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '_') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); int shadingModel = 0; reader.Get(ref shadingModel); bool hasNormal = false; reader.Get(ref hasNormal); bool hasReflection = false; reader.Get(ref hasReflection); int customData1Count = 0; reader.Get(ref customData1Count); int customData2Count = 0; reader.Get(ref customData2Count); int textureCount = 0; reader.Get(ref textureCount); List <TextureInformation> textures = new List <TextureInformation>(); for (int i = 0; i < textureCount; i++) { TextureInformation info = new TextureInformation(); reader.Get(ref info.Name, Encoding.UTF8); // name is for human, uniformName is a variable name after 3 if (version >= 3) { reader.Get(ref info.UniformName, Encoding.UTF8); } else { info.UniformName = info.Name; } reader.Get(ref info.DefaultPath, Encoding.UTF8); reader.Get(ref info.Index); reader.Get(ref info.Priority); reader.Get(ref info.IsParam); int textureType = 0; reader.Get(ref textureType); info.Type = (TextureType)textureType; int sampler = 0; reader.Get(ref sampler); // convert a path into absolute if (string.IsNullOrEmpty(info.DefaultPath)) { info.DefaultPath = string.Empty; } else { info.DefaultPath = Utils.Misc.GetAbsolutePath(path, info.DefaultPath); } textures.Add(info); } Textures = textures.ToArray(); int uniformCount = 0; reader.Get(ref uniformCount); List <UniformInformation> uniforms = new List <UniformInformation>(); for (int i = 0; i < uniformCount; i++) { UniformInformation info = new UniformInformation(); reader.Get(ref info.Name, Encoding.UTF8); // name is for human, uniformName is a variable name after 3 if (version >= 3) { reader.Get(ref info.UniformName, Encoding.UTF8); } else { info.UniformName = info.Name; } reader.Get(ref info.Offset); reader.Get(ref info.Priority); reader.Get(ref info.Type); reader.Get(ref info.DefaultValues[0]); reader.Get(ref info.DefaultValues[1]); reader.Get(ref info.DefaultValues[2]); reader.Get(ref info.DefaultValues[3]); uniforms.Add(info); } Uniforms = uniforms.ToArray(); } if (buf[0] == 'P' && buf[1] == 'R' && buf[2] == 'M' && buf[3] == '2') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); if (version >= 2) { int customDataCount = 0; reader.Get(ref customDataCount); CustomData = new CustomDataInformation[customDataCount]; for (int j = 0; j < customDataCount; j++) { CustomData[j] = new CustomDataInformation(); int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); CustomData[j].Summaries.Add((Language)lang, name); CustomData[j].Descriptions.Add((Language)lang, desc); } } } int textureCount = 0; reader.Get(ref textureCount); for (int j = 0; j < textureCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Textures[j].Summaries.Add((Language)lang, name); Textures[j].Descriptions.Add((Language)lang, desc); } } int uniformCount = 0; reader.Get(ref uniformCount); for (int j = 0; j < uniformCount; j++) { int count = 0; reader.Get(ref count); for (int i = 0; i < count; i++) { int lang = 0; string name = null; string desc = null; reader.Get(ref lang); reader.Get(ref name, Encoding.UTF8); reader.Get(ref desc, Encoding.UTF8); Uniforms[j].Summaries.Add((Language)lang, name); Uniforms[j].Descriptions.Add((Language)lang, desc); } } } if (buf[0] == 'G' && buf[1] == 'E' && buf[2] == 'N' && buf[3] == 'E') { var temp = new byte[BitConverter.ToInt32(buf, 4)]; if (br.Read(temp, 0, temp.Length) != temp.Length) { return(false); } var reader = new BinaryReader(temp); reader.Get(ref Code, Encoding.UTF8); } } return(true); }