void ReadAll() { byte[] magic = r.ReadBytes(4); if (magic[0] != (byte)'T' || magic[1] != (byte)'S' || magic[2] != (byte)'O' || magic[3] != (byte)'1') { throw new Exception("File is not TSO"); } //----- ノード ------------------------------------------------- nodemap = new Dictionary <string, TSONode>(); int count = r.ReadInt32(); nodes = new TSONode[count]; for (int i = 0; i < count; ++i) { nodes[i] = new TSONode(); nodes[i].id = i; nodes[i].path = ReadString(); nodes[i].name = nodes[i].path.Substring(nodes[i].path.LastIndexOf('|') + 1); nodemap.Add(nodes[i].path, nodes[i]); } for (int i = 0; i < count; ++i) { int index = nodes[i].path.LastIndexOf('|'); if (index <= 0) { continue; } string pname = nodes[i].path.Substring(0, index); nodes[i].parent = nodemap[pname]; nodes[i].parent.children.Add(nodes[i]); } count = r.ReadInt32(); // Node Matrix for (int i = 0; i < count; ++i) { nodes[i].matrix = ReadMatrix(); } //----- テクスチャ --------------------------------------------- count = r.ReadInt32(); textures = new TSOTex[count]; texturemap = new Dictionary <string, TSOTex>(); for (int i = 0; i < count; ++i) { textures[i] = new TSOTex(); textures[i].id = i; textures[i].name = ReadString(); textures[i].File = ReadString(); textures[i].width = r.ReadInt32(); textures[i].height = r.ReadInt32(); textures[i].depth = r.ReadInt32(); textures[i].data = r.ReadBytes(textures[i].width * textures[i].height * textures[i].depth); texturemap.Add(textures[i].name, textures[i]); ExchangeChannel(textures[i].data, textures[i].depth); } //----- エフェクト --------------------------------------------- count = r.ReadInt32(); effects = new TSOEffect[count]; for (int i = 0; i < count; ++i) { StringBuilder sb = new StringBuilder(); effects[i] = new TSOEffect(); effects[i].name = ReadString(); effects[i].line = r.ReadInt32(); for (int j = 0; j < effects[i].line; ++j) { sb.Append(ReadString()).Append('\n'); } effects[i].code = sb.ToString(); } //----- マテリアル --------------------------------------------- count = r.ReadInt32(); materials = new TSOMaterial[count]; for (int i = 0; i < count; ++i) { StringBuilder sb = new StringBuilder(); materials[i] = new TSOMaterial(); materials[i].id = i; materials[i].name = ReadString(); materials[i].file = ReadString(); materials[i].line = r.ReadInt32(); for (int j = 0; j < materials[i].line; ++j) { sb.Append(ReadString()).Append('\n'); } materials[i].code = sb.ToString(); materials[i].ParseParameters(); } //----- メッシュ ----------------------------------------------- count = r.ReadInt32(); meshes = new TSOMesh[count]; for (int i = 0; i < count; ++i) { meshes[i] = new TSOMesh(); meshes[i].file = this; meshes[i].name = ReadString(); meshes[i].matrix = ReadMatrix(); meshes[i].effect = r.ReadInt32(); meshes[i].numsubs = r.ReadInt32(); meshes[i].sub_meshes = new TSOSubMesh[meshes[i].numsubs]; for (int j = 0; j < meshes[i].numsubs; ++j) { meshes[i].sub_meshes[j] = new TSOSubMesh(); meshes[i].sub_meshes[j].owner = meshes[i]; meshes[i].sub_meshes[j].spec = r.ReadInt32(); meshes[i].sub_meshes[j].numbones = r.ReadInt32(); meshes[i].sub_meshes[j].bones = new int[meshes[i].sub_meshes[j].numbones]; for (int k = 0; k < meshes[i].sub_meshes[j].numbones; ++k) { meshes[i].sub_meshes[j].bones[k] = r.ReadInt32(); } meshes[i].sub_meshes[j].numvertices = r.ReadInt32(); Vertex[] v = new Vertex[meshes[i].sub_meshes[j].numvertices]; meshes[i].sub_meshes[j].vertices = v; for (int k = 0; k < meshes[i].sub_meshes[j].numvertices; ++k) { ReadVertex(ref v[k]); } } } }
public ImportMaterialInfo(TSOMaterial mtl) { Name = mtl.Name; File = mtl.File.Trim('"'); }
public ImportMaterialInfo(TSOMaterial mat) { Name = mat.Name; File = mat.File.Trim('"'); }
public void ReadAll() { byte[] magic = r.ReadBytes(4); if (magic[0] != (byte)'T' || magic[1] != (byte)'S' || magic[2] != (byte)'O' || magic[3] != (byte)'1') { throw new Exception("File is not TSO"); } //----- ノード ------------------------------------------------- nodemap = new Dictionary <string, TSONode>(); int count = r.ReadInt32(); nodes = new TSONode[count]; for (int i = 0; i < count; ++i) { nodes[i] = new TSONode(); nodes[i].id = i; nodes[i].name = ReadString(); nodes[i].sname = nodes[i].name.Substring(nodes[i].name.LastIndexOf('|') + 1); nodemap.Add(nodes[i].name, nodes[i]); WriteLine(i + ": " + nodes[i].name); } for (int i = 0; i < count; ++i) { int index = nodes[i].name.LastIndexOf('|'); if (index <= 0) { continue; } string pname = nodes[i].name.Substring(0, index); WriteLine(pname); nodes[i].parent = nodemap[pname]; nodes[i].parent.children.Add(nodes[i]); } WriteLine(r.BaseStream.Position.ToString("X")); count = r.ReadInt32(); // Node Matrix for (int i = 0; i < count; ++i) { nodes[i].matrix = ReadMatrix(); } WriteLine(r.BaseStream.Position.ToString("X")); //----- テクスチャ --------------------------------------------- count = r.ReadInt32(); textures = new TSOTex[count]; texturemap = new Dictionary <string, TSOTex>(); for (int i = 0; i < count; ++i) { textures[i] = new TSOTex(); textures[i].id = i; textures[i].name = ReadString(); textures[i].File = ReadString(); textures[i].width = r.ReadInt32(); textures[i].height = r.ReadInt32(); textures[i].depth = r.ReadInt32(); textures[i].data = r.ReadBytes(textures[i].width * textures[i].height * textures[i].depth); texturemap.Add(textures[i].name, textures[i]); ExchangeChannel(textures[i].data, textures[i].depth); WriteLine(r.BaseStream.Position.ToString("X")); } //----- エフェクト --------------------------------------------- count = r.ReadInt32(); effects = new TSOEffect[count]; for (int i = 0; i < count; ++i) { StringBuilder sb = new StringBuilder(); effects[i] = new TSOEffect(); effects[i].name = ReadString(); effects[i].line = r.ReadInt32(); for (int j = 0; j < effects[i].line; ++j) { sb.Append(ReadString()).Append('\n'); } effects[i].code = sb.ToString(); WriteLine(r.BaseStream.Position.ToString("X")); } //----- マテリアル --------------------------------------------- count = r.ReadInt32(); materials = new TSOMaterial[count]; for (int i = 0; i < count; ++i) { StringBuilder sb = new StringBuilder(); materials[i] = new TSOMaterial(); materials[i].id = i; materials[i].name = ReadString(); materials[i].file = ReadString(); materials[i].line = r.ReadInt32(); for (int j = 0; j < materials[i].line; ++j) { sb.Append(ReadString()).Append('\n'); } materials[i].code = sb.ToString(); materials[i].ParseParameters(); WriteLine(r.BaseStream.Position.ToString("X")); } //----- メッシュ ----------------------------------------------- count = r.ReadInt32(); meshes = new TSOMesh[count]; int check = 0; for (int i = 0; i < count; ++i) { meshes[i] = new TSOMesh(); meshes[i].file = this; meshes[i].name = ReadString(); meshes[i].matrix = ReadMatrix(); meshes[i].effect = r.ReadInt32(); meshes[i].numsubs = r.ReadInt32(); meshes[i].sub = new TSOSubMesh[meshes[i].numsubs]; for (int j = 0; j < meshes[i].numsubs; ++j) { meshes[i].sub[j] = new TSOSubMesh(); meshes[i].sub[j].owner = meshes[i]; meshes[i].sub[j].spec = r.ReadInt32(); meshes[i].sub[j].numbones = r.ReadInt32(); meshes[i].sub[j].bones = new int[meshes[i].sub[j].numbones]; meshes[i].sub[j].ink = materials[meshes[i].sub[j].spec].technique.ToUpper().IndexOf("INKOFF") < 0; //meshes[i].sub[j].shadow = specs[meshes[i].sub[j].spec].technique.ToUpper().IndexOf(Shadow for (int k = 0; k < meshes[i].sub[j].numbones; ++k) { meshes[i].sub[j].bones[k] = r.ReadInt32(); } meshes[i].sub[j].numvertices = r.ReadInt32(); Vertex[] v = new Vertex[meshes[i].sub[j].numvertices]; meshes[i].sub[j].vertices = v; for (int k = 0; k < meshes[i].sub[j].numvertices; ++k) { ReadVertex(ref v[k]); } WriteLine(r.BaseStream.Position.ToString("X")); System.Diagnostics.Debug.WriteLine(r.BaseStream.Position.ToString("X")); } } WriteLine(r.BaseStream.Position.ToString("X")); WriteLine(check.ToString("X")); r.BaseStream.Dispose(); }
public static void Write(BinaryWriter bw, TSOMaterial item) { Write(bw, item.Name); Write(bw, item.File); Write(bw, item.Code.Split('\n')); }
private void btnMerge_Click(object sender, EventArgs e) { Color c = tabPage2.BackColor; try { tabPage2.BackColor = Color.Tomato; List <TSOMesh> meshes = new List <TSOMesh>(); Dictionary <string, KeyValuePair <TSOMaterial, int> > materialmap = new Dictionary <string, KeyValuePair <TSOMaterial, int> >(); Dictionary <string, TSOTex> textures = new Dictionary <string, TSOTex>(); TSOFile last = null; foreach (TreeNode node in tvMerge.Nodes) { TSOFile tso = new TSOFile(); last = tso; ulong mtls = 0; ulong mask = 1; tso.Load(node.Text); foreach (TSOMesh mesh in tso.meshes) { TreeNode[] found = node.Nodes.Find(mesh.Name, false); if (found.Length == 0 || !found[0].Checked) { continue; } foreach (TSOSubMesh k in mesh.sub_meshes) { mtls |= 1ul << k.spec; } meshes.Add(mesh); } foreach (TSOMaterial mat in tso.materials) { if ((mask & mtls) != 0) { if (!materialmap.ContainsKey(mat.Name)) { materialmap.Add(mat.Name, new KeyValuePair <TSOMaterial, int>(mat, materialmap.Count)); if (!textures.ContainsKey(mat.ColorTex)) { TSOTex tex = tso.texturemap[mat.ColorTex]; textures.Add(tex.Name, tex); } if (!textures.ContainsKey(mat.ShadeTex)) { TSOTex tex = tso.texturemap[mat.ShadeTex]; textures.Add(tex.Name, tex); } } } mask <<= 1; } } using (FileStream fs = File.OpenWrite(tbMergeTso.Text)) { fs.SetLength(0); List <TSOTex> texlist = new List <TSOTex>(textures.Values); TSOMaterial[] mtllist = new TSOMaterial[materialmap.Count]; foreach (var i in materialmap.Values) { mtllist[i.Value] = i.Key; } foreach (TSOMesh mesh in meshes) { foreach (TSOSubMesh sub in mesh.sub_meshes) { TSOMaterial spec = mesh.file.materials[sub.spec]; sub.spec = materialmap[spec.Name].Value; } } foreach (TSOTex tex in texlist) { TSOFile.ExchangeChannel(tex.data, tex.depth); } BinaryWriter bw = new BinaryWriter(fs); TSOWriter.WriteHeader(bw); TSOWriter.Write(bw, last.nodes); TSOWriter.Write(bw, texlist.ToArray()); TSOWriter.Write(bw, last.effects); TSOWriter.Write(bw, mtllist); TSOWriter.Write(bw, meshes.ToArray()); } } catch (Exception exception) { Util.ProcessError(exception); } finally { tabPage2.BackColor = c; } }