void CreateRefVerts(TSOFile tso) { refverts = new List <Vertex>(); foreach (TSOMesh i in tso.meshes) { foreach (TSOSubMesh j in i.sub_meshes) { refverts.AddRange(j.vertices); } } }
protected virtual bool DoCleanup() { dir = null; tsoref = null; meshes = null; mqo = null; ii = null; bw = null; materials = null; textures = null; System.GC.Collect(); return(true); }
private void btnRefresh_Click(object sender, EventArgs e) { try { // 一旦現状を保存 SaveAssign(); // オブジェクト MqoReader mqo = new MqoReader(); mqo.Load(tbMqoFile.Text); lvObjects.Items.Clear(); foreach (MqoObject obj in mqo.Objects) { ListViewItem item = lvObjects.Items.Add(obj.name); item.Tag = obj; string bone; if (Config.Instance.object_bone_map.TryGetValue(obj.name, out bone)) { item.SubItems.Add(bone); } else { item.SubItems.Add(""); } } // ボーン構造 TSOFile tso = new TSOFile(); tso.Load(tbTsoFileRef.Text); tvBones.Visible = false; tvBones.Nodes.Clear(); BuildBoneTree(tvBones.Nodes, tso.nodes[0]); tvBones.ExpandAll(); tvBones.Nodes[0].EnsureVisible(); } catch (Exception exception) { Util.ProcessError(exception); } finally { tvBones.Visible = true; } }
public void SetValue(string type, string name, string value) { switch (name) { case "description": description = GetString(value); break; // = "TA ToonShader v0.50" case "shader": shader = GetString(value); break; // = "TAToonshade_050.cgfx" case "technique": technique = GetString(value); break; // = "ShadowOn" case "LightDirX": lightDirX = GetFloat(value); break; // = [-0.00155681] case "LightDirY": lightDirY = GetFloat(value); break; // = [-0.0582338] case "LightDirZ": lightDirZ = GetFloat(value); break; // = [-0.998302] case "LightDirW": lightDirW = GetFloat(value); break; // = [0] case "ShadowColor": shadowColor = GetPoint4(value); break; // = [0, 0, 0, 1] case "ShadeTex": shadeTex = GetTexture(value); break; // = Ninjya_Ribbon_Toon_Tex case "HighLight": highLight = GetFloat(value); break; // = [0] case "ColorBlend": colorBlend = GetFloat(value); break; // = [10] case "HighLightBlend": highLightBlend = GetFloat(value); break; // = [10] case "PenColor": penColor = GetPoint4(value); break; // = [0.166, 0.166, 0.166, 1] case "Ambient": ambient = GetFloat(value); break; // = [38] case "ColorTex": colorTex = GetTexture(value); break; // = file24 case "Thickness": thickness = GetFloat(value); break; // = [0.018] case "ShadeBlend": shadeBlend = GetFloat(value); break; // = [10] case "HighLightPower": highLightPower = GetFloat(value); break; // = [100] default: TSOFile.WriteLine("Unknown parameter. type=" + type + ", name=" + name + ", value=" + value); break; } }
public void Generate(string tso_file, string out_path, bool mqx_enabled) { string tso_filename = Path.GetFileName(tso_file); string mqo_file = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".mqo")); string xml_file = Path.Combine(out_path, Path.ChangeExtension(tso_filename, ".xml")); // モデル、テクスチャの作成 using (MqoWriter mqo = new MqoWriter(mqo_file)) { TSOFile tso = LoadTSO(tso_file); tso.SwitchBoneIndicesOnMesh(); mqo.MqxEnabled = mqx_enabled; mqo.Write(tso); mqo.Close(); ImportInfo ii = new ImportInfo(); // テクスチャ情報 foreach (TSOTex tex in tso.textures) { ii.textures.Add(new ImportTextureInfo(tex)); } // エフェクトの作成 foreach (TSOEffect effect in tso.effects) { ii.effects.Add(new ImportEffectInfo(effect)); File.WriteAllText(Path.Combine(out_path, effect.Name), effect.code, Encoding.Default); } // マテリアルの作成 foreach (TSOMaterial mat in tso.materials) { ii.materials.Add(new ImportMaterialInfo(mat)); File.WriteAllText(Path.Combine(out_path, mat.Name), mat.code, Encoding.Default); } ImportInfo.Save(xml_file, ii); } }
private void CreatePointCluster(TSOFile tso) { vlst = new List <Vertex>(); foreach (TSOMesh i in tso.meshes) { foreach (TSOSubMesh j in i.sub) { vlst.AddRange(j.vertices); } } pc = new PointCluster(vlst.Count); foreach (Vertex i in vlst) { pc.Add(i.Pos.x, i.Pos.y, i.Pos.z); } pc.Clustering(); }
MqoBone[] CreateBones(TSOFile tso) { MqoBone[] bones = new MqoBone[tso.nodes.Length]; tso.UpdateNodesWorld(); foreach (TSONode node in tso.nodes) { MqoBone bone = new MqoBone(node.id); bone.id = node.id + 1; bone.name = node.Name; bone.tail = node.children.Count == 0; if (node.parent == null) { bone.pid = 0; } else { bone.pid = node.parent.id + 1; bones[node.parent.id].cids.Add(bone.id); } //根本 bone.q = node.world.Translation; //先端 if (!bone.tail) { bone.p = node.children[0].world.Translation; } else { bone.p = node.world.Translation; } bones[node.id] = bone; } return(bones); }
public void Write(TSOFile tso) { tw.WriteLine("Metasequoia Document"); tw.WriteLine("Format Text Ver 1.0"); tw.WriteLine(""); if (MqxEnabled) { tw.WriteLine("IncludeXml \"{0}\"", Path.ChangeExtension(Path.GetFileName(OutFile), ".mqx")); tw.WriteLine(""); } tw.WriteLine("Scene {"); tw.WriteLine("\tpos -7.0446 4.1793 1541.1764"); tw.WriteLine("\tlookat 11.8726 193.8590 0.4676"); tw.WriteLine("\thead 0.8564"); tw.WriteLine("\tpich 0.1708"); tw.WriteLine("\tortho 0"); tw.WriteLine("\tzoom2 31.8925"); tw.WriteLine("\tamb 0.250 0.250 0.250"); tw.WriteLine("}"); foreach (TSOTex tex in tso.textures) { CreateTextureFile(tex); } tw.WriteLine("Material {0} {{", tso.materials.Length); foreach (TSOMaterial mat in tso.materials) { TSOTex tex = null; if (tso.texturemap.TryGetValue(mat.ColorTex, out tex)) { tw.WriteLine( "\t\"{0}\" col(1.000 1.000 1.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00) tex(\"{1}\")", mat.name, tex.GetFileName()); } else { tw.WriteLine( "\t\"{0}\" col(1.000 1.000 1.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00))", mat.name); } } tw.WriteLine("}"); MqoBone[] bones = null; if (MqxEnabled) { bones = CreateBones(tso); } MqoObjectGen.uid_enabled = MqxEnabled; MqoObjectGen obj = new MqoObjectGen(); ushort object_id = 0; foreach (TSOMesh mesh in tso.meshes) { obj.id = ++object_id; obj.name = mesh.Name; obj.Update(mesh); obj.Write(tw); if (MqxEnabled) { obj.AddWeits(bones); } } if (MqxEnabled) { MqxWriter writer = new MqxWriter(); writer.MqoFile = OutFile; writer.Write(bones, object_id /* eq numobjects */); } tw.WriteLine("Eof"); }
public void Write(TSOFile file) { tw.WriteLine("Metasequoia Document"); tw.WriteLine("Format Text Ver 1.0"); tw.WriteLine(""); tw.WriteLine("Scene {"); tw.WriteLine("\tpos -7.0446 4.1793 1541.1764"); tw.WriteLine("\tlookat 11.8726 193.8590 0.4676"); tw.WriteLine("\thead 0.8564"); tw.WriteLine("\tpich 0.1708"); tw.WriteLine("\tortho 0"); tw.WriteLine("\tzoom2 31.8925"); tw.WriteLine("\tamb 0.250 0.250 0.250"); tw.WriteLine("}"); VertexHeap <UVertex> vh = new VertexHeap <UVertex>(); List <ushort> face = new List <ushort>(2048 * 3); List <float> uv = new List <float>(2048 * 3 * 2); List <int> mtl = new List <int>(2048); foreach (TSOTex tex in file.textures) { CreateTextureFile(tex); } tw.WriteLine("Material {0} {{", file.materials.Length); foreach (TSOMaterial mat in file.materials) { if (mat.ColorTex != null) { TSOTex tex = file.texturemap[mat.ColorTex]; tw.WriteLine( "\t\"{0}\" col(1.000 1.000 1.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00) tex(\"{1}\")", mat.name, GetTexturePath(tex)); } else { tw.WriteLine( "\t\"{0}\" col(1.000 1.000 1.000 1.000) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00))", mat.name); } } tw.WriteLine("}"); foreach (TSOMesh i in file.meshes) { vh.Clear(); face.Clear(); uv.Clear(); mtl.Clear(); foreach (TSOSubMesh j in i.sub) { int cnt = 0; ushort a = 0, b = 0, c = 0; Vertex va = new Vertex(), vb = new Vertex(), vc = new Vertex(); foreach (Vertex k in j.vertices) { ++cnt; va = vb; a = b; vb = vc; b = c; vc = k; c = vh.Add(new UVertex(k.Pos, k.Nrm, k.Tex, j.spec)); if (cnt < 3) { continue; } if (a == b || b == c || c == a) { continue; } if ((cnt & 1) == 0) { face.Add(a); uv.Add(va.Tex.x); uv.Add(1 - va.Tex.y); face.Add(b); uv.Add(vb.Tex.x); uv.Add(1 - vb.Tex.y); face.Add(c); uv.Add(vc.Tex.x); uv.Add(1 - vc.Tex.y); mtl.Add(j.spec); } else { face.Add(a); uv.Add(va.Tex.x); uv.Add(1 - va.Tex.y); face.Add(c); uv.Add(vc.Tex.x); uv.Add(1 - vc.Tex.y); face.Add(b); uv.Add(vb.Tex.x); uv.Add(1 - vb.Tex.y); mtl.Add(j.spec); } } } tw.WriteLine("Object \"{0}\" {{", i.Name); tw.WriteLine("\tvisible {0}", 15); tw.WriteLine("\tlocking {0}", 0); tw.WriteLine("\tshading {0}", 1); tw.WriteLine("\tfacet {0}", 59.5); tw.WriteLine("\tcolor {0:F3} {1:F3} {2:F3}", 0.898f, 0.498f, 0.698f); tw.WriteLine("\tcolor_type {0}", 0); // tw.WriteLine("\tvertex {0} {{", vh.Count); foreach (UVertex j in vh.verts) { WriteVertex(j.Pos.x, j.Pos.y, j.Pos.z); } tw.WriteLine("\t}"); // tw.WriteLine("\tface {0} {{", face.Count / 3); System.Diagnostics.Debug.Assert(face.Count * 2 == uv.Count); System.Diagnostics.Debug.Assert(face.Count == mtl.Count * 3); for (int j = 0, n = face.Count; j < n; j += 3) { WriteFace(face[j + 0], face[j + 1], face[j + 2], uv[j * 2 + 0], uv[j * 2 + 1], uv[j * 2 + 2], uv[j * 2 + 3], uv[j * 2 + 4], uv[j * 2 + 5], mtl[j / 3]); } tw.WriteLine("\t}"); tw.WriteLine("}"); } // ボーンを出す switch (BoneMode) { case MqoBoneMode.None: break; case MqoBoneMode.RokDeBone: { // マトリクス計算 foreach (TSONode i in file.nodes) { if (i.parent == null) { i.world = i.Matrix; } else { i.world = Matrix44.Mul(i.Matrix, i.parent.World); } } List <Point3> points = new List <Point3>(); List <int> bones = new List <int>(); tw.WriteLine("Object \"{0}\" {{", "Bone"); tw.WriteLine("\tvisible {0}", 15); tw.WriteLine("\tlocking {0}", 0); tw.WriteLine("\tshading {0}", 1); tw.WriteLine("\tfacet {0}", 59.5); tw.WriteLine("\tcolor {0} {1} {2}", 1, 0, 0); tw.WriteLine("\tcolor_type {0}", 0); foreach (TSONode i in file.nodes) { if (i.children.Count == 0) { continue; } Point3 q = new Point3(i.world.M41, i.world.M42, i.world.M43); Point3 p = new Point3(); foreach (TSONode j in i.children) { p.x += j.world.M41; p.y += j.world.M42; p.z += j.world.M43; } p.x /= i.children.Count; p.y /= i.children.Count; p.z /= i.children.Count; bones.Add(points.Count); points.Add(q); bones.Add(points.Count); points.Add(p); } tw.WriteLine("\tvertex {0} {{", points.Count); foreach (Point3 j in points) { WriteVertex(j.x, j.y, j.z); } tw.WriteLine("\t}"); // tw.WriteLine("\tface {0} {{", bones.Count / 2); for (int j = 0, n = bones.Count; j < n; j += 2) { tw.WriteLine(string.Format("\t\t2 V({0} {1})", bones[j + 0], bones[j + 1])); } tw.WriteLine("\t}"); tw.WriteLine("}"); } break; case MqoBoneMode.Mikoto: { } break; } tw.WriteLine("Eof"); }
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; } }
private void OpenTSOFile(string file) { string dir = OutPath; if (cbMakeSub.Checked) { dir = Path.Combine(dir, Path.GetFileNameWithoutExtension(file)); if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } } string mqo_path = Path.Combine(dir, Path.ChangeExtension(Path.GetFileName(file), ".mqo")); string importinfo_path = Path.Combine(dir, Path.ChangeExtension(Path.GetFileName(file), ".xml")); try { label2.BackColor = Color.Tomato; label2.ForeColor = Color.White; label2.Text = "Processing"; label2.Invalidate(); label2.Update(); // モデル、テクスチャの作成 using (MqoWriter mqo = new MqoWriter(mqo_path)) { TSOFile tso = new TSOFile(file); tso.ReadAll(); if (rbBoneRokDeBone.Checked) { mqo.BoneMode = MqoBoneMode.RokDeBone; } mqo.Write(tso); mqo.Close(); ImportInfo ii = new ImportInfo(); // テクスチャ情報 foreach (TSOTex i in tso.textures) { ii.textures.Add(new ImportTextureInfo(i)); } // エフェクトの作成 foreach (TSOEffect i in tso.effects) { ii.effects.Add(new ImportEffectInfo(i)); File.WriteAllText(Path.Combine(dir, i.Name), i.code, Encoding.Default); } // マテリアルの作成 foreach (TSOMaterial i in tso.materials) { ii.materials.Add(new ImportMaterialInfo(i)); File.WriteAllText(Path.Combine(dir, i.Name), i.code, Encoding.Default); } ImportInfo.Save(importinfo_path, ii); } if (cbCopyTSO.Checked) { string tso_path = Path.Combine(dir, Path.GetFileName(file)); if (file != tso_path) { File.Copy(file, tso_path, true); } } } finally { label2.BackColor = SystemColors.Control; label2.BackColor = label2.Parent.BackColor; label2.ForeColor = SystemColors.ControlText; label2.Text = "Drop TSO File Here!"; } }