private void BuildBoneTree(TreeNodeCollection nodes, TSONode node) { TreeNode tn = nodes.Add(node.Name); tn.Tag = node; if (node.children != null) { foreach (TSONode i in node.children) { BuildBoneTree(tn.Nodes, i); } } }
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 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, TSONode item) { Write(bw, item.Name); }