Esempio n. 1
0
        private void lvTSOFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvTSOFiles.SelectedItems.Count == 0)
            {
                return;
            }
            ListViewItem li  = lvTSOFiles.SelectedItems[0];
            TSOFile      tso = li.Tag as TSOFile;

            SetTSOFile(tso);
        }
Esempio n. 2
0
        public TSOFile GetSelectedTSOFile()
        {
            if (lvTSOFiles.SelectedItems.Count == 0)
            {
                return(null);
            }

            ListViewItem li  = lvTSOFiles.SelectedItems[0];
            TSOFile      tso = li.Tag as TSOFile;

            return(tso);
        }
Esempio n. 3
0
        public int Extract(string source_file, string dest_path)
        {
            try
            {
                Directory.CreateDirectory(dest_path);
            }
            catch (Exception)
            {
                Console.WriteLine("Error: Cannot prepare destination directory for file writing.");
                return(-1);
            }
            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            foreach (TSOTex tex in tso.textures)
            {
                string name = tex.Name;
                string file = tex.FileName.Trim('"');
                Console.WriteLine(file);
                using (BinaryWriter bw = new BinaryWriter(File.Create(Path.Combine(dest_path, file))))
                {
                    switch (Path.GetExtension(file).ToLower())
                    {
                    case ".bmp":
                        tex.SaveBMP(bw);
                        break;

                    case ".tga":
                        tex.SaveTGA(bw);
                        break;
                    }
                }
            }

            foreach (TSOScript scr in tso.scripts)
            {
                string name = scr.Name;
                Console.WriteLine(name);
                scr.Save(Path.Combine(dest_path, name));
            }

            foreach (TSOSubScript scr in tso.sub_scripts)
            {
                string name = scr.Name;
                string file = scr.FileName.Trim('"');
                Console.WriteLine(name);
                scr.Save(Path.Combine(dest_path, name));
            }

            return(0);
        }
Esempio n. 4
0
        private void lvTSOFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvTSOFiles.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem li  = lvTSOFiles.SelectedItems[0];
            TSOFile      tso = li.Tag as TSOFile;

            viewer.SelectedTSOFile = tso;
            Invalidate(false);
        }
Esempio n. 5
0
 /// <summary>
 /// tsoをUIに設定します。
 /// </summary>
 /// <param name="tso">tso</param>
 public void SetTSOFile(TSOFile tso)
 {
     this.tso = tso;
     lvSubScripts.Items.Clear();
     foreach (TSOSubScript sub_script in tso.sub_scripts)
     {
         ListViewItem li = new ListViewItem(sub_script.Name);
         li.SubItems.Add(sub_script.FileName);
         li.Tag = sub_script;
         lvSubScripts.Items.Add(li);
     }
     lvSubScripts.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
 }
Esempio n. 6
0
 void AssignMeshes(TSOFile tso)
 {
     lvMeshes.BeginUpdate();
     lvMeshes.Items.Clear();
     foreach (TSOMesh mesh in tso.meshes)
     {
         ListViewItem li = new ListViewItem(mesh.Name);
         li.Tag = mesh;
         lvMeshes.Items.Add(li);
     }
     lvMeshes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
     lvMeshes.EndUpdate();
 }
Esempio n. 7
0
 void AssignNodes(TSOFile tso)
 {
     lvNodes.BeginUpdate();
     lvNodes.Items.Clear();
     foreach (TSONode node in tso.nodes)
     {
         ListViewItem li = new ListViewItem(node.Name);
         li.Tag = node;
         lvNodes.Items.Add(li);
     }
     lvNodes.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
     lvNodes.EndUpdate();
 }
Esempio n. 8
0
 void AssignTextures(TSOFile tso)
 {
     lvTextures.BeginUpdate();
     lvTextures.Items.Clear();
     foreach (TSOTex texture in tso.textures)
     {
         ListViewItem li = new ListViewItem(texture.Name);
         li.SubItems.Add(texture.FileName);
         li.Tag = texture;
         lvTextures.Items.Add(li);
     }
     lvTextures.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
     lvTextures.EndUpdate();
 }
Esempio n. 9
0
 void AssignSubScripts(TSOFile tso)
 {
     lvSubScripts.BeginUpdate();
     lvSubScripts.Items.Clear();
     foreach (TSOSubScript sub_script in tso.sub_scripts)
     {
         ListViewItem li = new ListViewItem(sub_script.Name);
         li.SubItems.Add(sub_script.FileName);
         li.Tag = sub_script;
         lvSubScripts.Items.Add(li);
     }
     lvSubScripts.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
     lvSubScripts.EndUpdate();
 }
Esempio n. 10
0
 void AssignTSOFiles(Figure fig)
 {
     lvTSOFiles.BeginUpdate();
     lvTSOFiles.Items.Clear();
     for (int i = 0; i < fig.TSOList.Count; i++)
     {
         TSOFile      tso = fig.TSOList[i];
         ListViewItem li  = new ListViewItem(tso.FileName ?? "TSO #" + i.ToString());
         li.Tag = tso;
         lvTSOFiles.Items.Add(li);
     }
     lvTSOFiles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
     lvTSOFiles.EndUpdate();
 }
Esempio n. 11
0
        private void lvTSOFiles_SelectedIndexChanged(object sender, EventArgs e)
        {
            TSOFile tso = GetSelectedTSOFile();

            if (tso == null)
            {
                return;
            }

            AssignNodes(tso);
            AssignTextures(tso);
            AssignSubScripts(tso);
            AssignMeshes(tso);
            viewer.SelectedTSOFile = tso;
        }
Esempio n. 12
0
        private void btnTSOSave_Click(object sender, EventArgs e)
        {
            TSOFile tso = GetSelectedTSOFile();

            if (tso == null)
            {
                return;
            }

            saveFileDialog1.FileName = "out.tso";
            saveFileDialog1.Filter   = "TSO files (*.tso)|*.tso|All files (*.*)|*.*";
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                tso.Save(saveFileDialog1.OpenFile());
            }
        }
Esempio n. 13
0
        static Dictionary <int, int> create_oppnode_idmap(TSOFile tso)
        {
            Dictionary <string, TSONode> nodemap = new Dictionary <string, TSONode>();

            foreach (TSONode node in tso.nodes)
            {
                nodemap.Add(node.Name, node);
            }

            Dictionary <int, int> oppnode_idmap = new Dictionary <int, int>();

            char[] delim = { ' ' };
            using (StreamReader source = new StreamReader(File.OpenRead(GetFlipNodesPath())))
            {
                string line;
                while ((line = source.ReadLine()) != null)
                {
                    string[] tokens = line.Split(delim);
                    string   op     = tokens[0];
                    if (op == "flip")
                    {
                        Debug.Assert(tokens.Length == 2, "tokens length should be 2: " + line);
                        string cnode_name = tokens[1];
                        int    cnode_id   = nodemap[cnode_name].Id;

                        oppnode_idmap[cnode_id] = cnode_id;
                    }
                    else
                    if (op == "swap")
                    {
                        Debug.Assert(tokens.Length == 3, "tokens length should be 3: " + line);
                        string lnode_name = tokens[1];
                        string rnode_name = tokens[2];
                        int    lnode_id   = nodemap[lnode_name].Id;
                        int    rnode_id   = nodemap[rnode_name].Id;

                        oppnode_idmap[lnode_id] = rnode_id;
                        oppnode_idmap[rnode_id] = lnode_id;
                    }
                }
            }

            return(oppnode_idmap);
        }
Esempio n. 14
0
        public int Extract(string source_file, string dest_path)
        {
            try
            {
                Directory.CreateDirectory(dest_path);
            }
            catch (Exception)
            {
                Console.WriteLine("Error: Cannot prepare destination directory for file writing.");
                return(-1);
            }
            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            foreach (TSOTex tex in tso.textures)
            {
                string name = tex.Name;
                string file = Path.ChangeExtension(tex.FileName.Trim('"'), ".png");
                Console.WriteLine(file);
                string path = Path.Combine(dest_path, file);
                tex.SavePngFile(path);
            }

            foreach (TSOScript scr in tso.scripts)
            {
                string name = scr.Name;
                Console.WriteLine(name);
                scr.Save(Path.Combine(dest_path, name));
            }

            foreach (TSOSubScript scr in tso.sub_scripts)
            {
                string name = scr.Name;
                string file = scr.FileName.Trim('"');
                Console.WriteLine(name);
                scr.Save(Path.Combine(dest_path, name));
            }

            return(0);
        }
Esempio n. 15
0
        /// <summary>
        /// フィギュアをUIに設定します。
        /// </summary>
        /// <param name="fig">フィギュア</param>
        public void SetFigure(Figure fig)
        {
            this.fig = fig;

            this.tbSlideArm.Value   = (int)(fig.slide_matrices.ArmRatio * (float)tbSlideArm.Maximum);
            this.tbSlideLeg.Value   = (int)(fig.slide_matrices.LegRatio * (float)tbSlideLeg.Maximum);
            this.tbSlideWaist.Value = (int)(fig.slide_matrices.WaistRatio * (float)tbSlideWaist.Maximum);
            this.tbSlideBust.Value  = (int)(fig.slide_matrices.BustRatio * (float)tbSlideBust.Maximum);
            this.tbSlideTall.Value  = (int)(fig.slide_matrices.TallRatio * (float)tbSlideTall.Maximum);
            this.tbSlideEye.Value   = (int)(fig.slide_matrices.EyeRatio * (float)tbSlideEye.Maximum);

            lvTSOFiles.Items.Clear();
            for (int i = 0; i < fig.TSOList.Count; i++)
            {
                TSOFile      tso = fig.TSOList[i];
                ListViewItem li  = new ListViewItem("TSO #" + i.ToString());
                li.Tag = tso;
                lvTSOFiles.Items.Add(li);
            }
            lvTSOFiles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
        }
Esempio n. 16
0
 /// <summary>
 /// フィギュアをUIに設定します。
 /// </summary>
 /// <param name="fig">フィギュア</param>
 public void SetFigure(Figure fig)
 {
     this.fig = fig;
     if (fig.slider_matrix != null)
     {
         this.tbSlideArm.Value   = (int)(fig.slider_matrix.ArmRatio * (float)tbSlideArm.Maximum);
         this.tbSlideLeg.Value   = (int)(fig.slider_matrix.LegRatio * (float)tbSlideLeg.Maximum);
         this.tbSlideWaist.Value = (int)(fig.slider_matrix.WaistRatio * (float)tbSlideWaist.Maximum);
         this.tbSlideOppai.Value = (int)(fig.slider_matrix.OppaiRatio * (float)tbSlideOppai.Maximum);
         this.tbSlideAge.Value   = (int)(fig.slider_matrix.AgeRatio * (float)tbSlideAge.Maximum);
         this.tbSlideEye.Value   = (int)(fig.slider_matrix.EyeRatio * (float)tbSlideEye.Maximum);
     }
     lvTSOFiles.Items.Clear();
     for (int i = 0; i < fig.TsoList.Count; i++)
     {
         TSOFile      tso = fig.TsoList[i];
         ListViewItem li  = new ListViewItem(tso.FileName ?? "TSO #" + i.ToString());
         li.Tag = tso;
         lvTSOFiles.Items.Add(li);
     }
     lvTSOFiles.AutoResizeColumns(ColumnHeaderAutoResizeStyle.HeaderSize);
 }
Esempio n. 17
0
        public int Extract(string source_file, string dest_path)
        {
            Directory.CreateDirectory(dest_path);

            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            foreach (TSOTex tex in tso.textures)
            {
                string name = tex.Name;
                string file = tex.FileName.Trim('"');
                file = Path.GetFileNameWithoutExtension(file) + ".bmp";
                Console.WriteLine("tex name:{0} file:{1}", name, file);
                string dest_file = Path.Combine(dest_path, file);
                using (BinaryWriter bw = new BinaryWriter(File.Create(dest_file)))
                    tex.SaveBMP(bw);
            }

            foreach (TSOSubScript sub in tso.sub_scripts)
            {
                string name = sub.Name;
                string file = sub.FileName;
                Console.WriteLine("sub name:{0} file:{1}", name, file);
                string dest_file = Path.Combine(dest_path, name);
                sub.Save(dest_file);
            }

            {
                string name      = dest_path + ".mqo";
                string dest_file = Path.Combine(dest_path, name);
                Console.WriteLine("Save File: " + dest_file);
                using (TextWriter tw = new StreamWriter(File.Create(dest_file)))
                    SaveToMqo(tw, tso);
            }

            return(0);
        }
Esempio n. 18
0
        public void SaveToMqo(TextWriter tw, TSOFile tso)
        {
            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("}");

            tw.WriteLine("Material {0} {{", tso.sub_scripts.Length);

            Dictionary <string, TSOTex> texmap = new Dictionary <string, TSOTex>();

            foreach (TSOTex tex in tso.textures)
            {
                texmap[tex.Name] = tex;
            }

            foreach (TSOSubScript sub in tso.sub_scripts)
            {
                TSOTex tex      = texmap[sub.shader.ColorTexName];
                string tex_file = tex.FileName.Trim('"');
                tex_file = Path.GetFileNameWithoutExtension(tex_file) + ".bmp";
                tw.WriteLine(
                    "\t\"{0}\" shader(3) col(1.00 1.00 1.00 1.00) dif(0.800) amb(0.600) emi(0.000) spc(0.000) power(5.00) tex(\"{1}\")",
                    sub.Name, tex_file);
            }

            tw.WriteLine("}");

            foreach (TSOMesh mesh in tso.meshes)
            {
                tw.WriteLine("Object \"{0}\" {{", mesh.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} {1} {2}", 0.898f, 0.498f, 0.698f);
                tw.WriteLine("\tcolor_type {0}", 0);

                Heap <UnifiedPositionVertex> vh = new Heap <UnifiedPositionVertex>();
                List <MqoFace> faces            = new List <MqoFace>();
                foreach (TSOSubMesh sub in mesh.sub_meshes)
                {
                    UnifiedPositionVertex[] vertices = new UnifiedPositionVertex[sub.vertices.Length];
                    for (int i = 0; i < vertices.Length; i++)
                    {
                        vertices[i] = new UnifiedPositionVertex(sub.vertices[i]);
                    }
                    for (int i = 2; i < vertices.Length; i++)
                    {
                        UnifiedPositionVertex va, vb, vc;
                        if (i % 2 == 0)
                        {
                            va = vertices[i - 2];
                            vb = vertices[i - 0];
                            vc = vertices[i - 1];
                        }
                        else
                        {
                            va = vertices[i - 2];
                            vb = vertices[i - 1];
                            vc = vertices[i - 0];
                        }

                        ushort a, b, c;
                        a = vh.Add(va);
                        b = vh.Add(vb);
                        c = vh.Add(vc);

                        if (a != b && b != c && c != a)
                        {
                            MqoFace f = new MqoFace();
                            f.a   = a;
                            f.b   = b;
                            f.c   = c;
                            f.ta  = new Vector2(va.u, 1 - va.v);
                            f.tb  = new Vector2(vb.u, 1 - vb.v);
                            f.tc  = new Vector2(vc.u, 1 - vc.v);
                            f.mtl = (ushort)sub.spec;
                            faces.Add(f);
                        }
                    }
                }
                tw.WriteLine("\tvertex {0} {{", vh.Count);
                foreach (UnifiedPositionVertex v in vh.ary)
                {
                    tw.WriteLine("\t\t{0:F6} {1:F6} {2:F6}", v.position.X, v.position.Y, v.position.Z);
                }
                tw.WriteLine("\t}");
                tw.WriteLine("\tface {0} {{", faces.Count);
                foreach (MqoFace f in faces)
                {
                    tw.WriteLine("\t\t{0} V({1} {2} {3}) M({10}) UV({4} {5} {6} {7} {8} {9})", 3, f.a, f.b, f.c, f.ta.X, f.ta.Y, f.tb.X, f.tb.Y, f.tc.X, f.tc.Y, f.mtl);
                }
                tw.WriteLine("\t}");
                tw.WriteLine("}");
            }
        }
Esempio n. 19
0
        public int Compose(string dest_path)
        {
            string source_file = dest_path + @".tso";

            if (!File.Exists(source_file))
            {
                Console.WriteLine("File not found: " + source_file);
                return(-1);
            }
            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            foreach (TSOTex tex in tso.textures)
            {
                string name = tex.Name;
                string file = tex.FileName.Trim('"');
                string path = Path.Combine(dest_path, file);

                path = Path.ChangeExtension(path, ".bmp");

                if (!File.Exists(path))
                {
                    path = Path.ChangeExtension(path, ".tga");
                }

                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(file);
                using (BinaryReader br = new BinaryReader(File.OpenRead(path)))
                {
                    switch (Path.GetExtension(path).ToLower())
                    {
                    case ".bmp":
                        tex.LoadBMP(br);
                        break;

                    case ".tga":
                        tex.LoadTGA(br);
                        break;
                    }
                }
            }

            foreach (TSOScript scr in tso.scripts)
            {
                string name = scr.Name;
                string path = Path.Combine(dest_path, name);
                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(name);
                scr.Load(path);
            }

            foreach (TSOSubScript scr in tso.sub_scripts)
            {
                string name = scr.Name;
                string file = scr.FileName.Trim('"');
                string path = Path.Combine(dest_path, name);
                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(name);
                scr.Load(path);
            }

            string dest_file = Path.ChangeExtension(dest_path, @".new" + Path.GetExtension(dest_path) + @".tso");

            Console.WriteLine("Save File: " + dest_file);
            tso.Save(dest_file);

            return(0);
        }
Esempio n. 20
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("TSOWeightCopy.exe <tso file>");
                return;
            }
            string source_file = args[0];

            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            UniqueVertex.nodes         = tso.nodes;
            UniqueVertex.oppnode_idmap = create_oppnode_idmap(tso);

            Console.WriteLine("メッシュ:");
            int i = 0;

            foreach (TSOMesh mesh in tso.meshes)
            {
                Console.WriteLine("{0} {1}", i, mesh.Name);
                i++;
            }

            Console.Write("メッシュを選択 (0-{0}): ", tso.meshes.Length - 1);
            int mesh_idx = 0;

            try
            {
                mesh_idx = int.Parse(Console.ReadLine());
            }
            catch (System.FormatException e)
            {
                Console.WriteLine(e);
                return;
            }

            TSOMesh selected_mesh = null;

            try
            {
                selected_mesh = tso.meshes[mesh_idx];
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e);
                return;
            }

            Vector3 min       = Vector3.Empty;
            Vector3 max       = Vector3.Empty;
            int     nvertices = 0;

            foreach (TSOSubMesh sub in selected_mesh.sub_meshes)
            {
                foreach (Vertex v in sub.vertices)
                {
                    float x = v.position.X;
                    float y = v.position.Y;
                    float z = v.position.Z;

                    if (min.X > x)
                    {
                        min.X = x;
                    }
                    if (min.Y > y)
                    {
                        min.Y = y;
                    }
                    if (min.Z > z)
                    {
                        min.Z = z;
                    }

                    if (max.X < x)
                    {
                        max.X = x;
                    }
                    if (max.Y < y)
                    {
                        max.Y = y;
                    }
                    if (max.Z < z)
                    {
                        max.Z = z;
                    }

                    nvertices++;
                }
            }
            Console.WriteLine("頂点数:{0}", nvertices);
            Console.WriteLine("min:{0}", UniqueVertex.ToString(min));
            Console.WriteLine("max:{0}", UniqueVertex.ToString(max));

            Cluster cluster = new Cluster(min, max);

            foreach (TSOSubMesh sub in selected_mesh.sub_meshes)
            {
                foreach (Vertex v in sub.vertices)
                {
                    cluster.Push(v, sub);
                }
            }

            Console.WriteLine("同一視頂点数:{0}", cluster.vertices.Count);
            Console.WriteLine();

            Console.WriteLine("方向:");
            Console.WriteLine("0 左から右");
            Console.WriteLine("1 右から左");
            Console.Write("方向を選択 (0-1): ");
            int copy_dir = 0;

            try
            {
                copy_dir = int.Parse(Console.ReadLine());
            }
            catch (System.FormatException e)
            {
                Console.WriteLine(e);
                return;
            }
            switch (copy_dir)
            {
            case 0:
                cluster.dir = CopyDirection.LtoR;
                break;

            case 1:
                cluster.dir = CopyDirection.RtoL;
                break;
            }

            cluster.AssignOppositeCells();
            cluster.AssignOppositeVertices();
            //cluster.Dump();
            cluster.CopyOppositeWeights();

            string dest_path = Path.GetDirectoryName(source_file);
            string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.tso";

            dest_path = Path.Combine(dest_path, dest_file);
            Console.WriteLine("Save File: " + dest_path);
            tso.Save(dest_path);
        }
Esempio n. 21
0
        public static void Main(string[] args)
        {
            if (args.Length < 2)
            {
                Console.WriteLine("TSODeform.exe <tso file> <tmo file> [fig file]");
                return;
            }
            string tso_file = args[0];
            string tmo_file = args[1];

            string fig_file = null;

            if (args.Length > 2)
            {
                fig_file = args[2];
            }

            TSOFile tso = new TSOFile();

            tso.Load(tso_file);

            TMOFile tmo = new TMOFile();

            tmo.Load(tmo_file);

            Figure fig = new Figure();

            fig.TSOList.Add(tso);
            fig.Tmo = tmo;

            if (fig_file != null)
            {
                List <float> ratios = ReadFloats(fig_file);

                /*
                 * ◆FIGU
                 * スライダの位置。値は float型で 0.0 .. 1.0
                 *  0: 姉妹
                 *  1: うで
                 *  2: あし
                 *  3: 胴まわり
                 *  4: おっぱい
                 *  5: つり目たれ目
                 *  6: やわらか
                 */
                fig.slider_matrix.TallRatio  = ratios[0];
                fig.slider_matrix.ArmRatio   = ratios[1];
                fig.slider_matrix.LegRatio   = ratios[2];
                fig.slider_matrix.WaistRatio = ratios[3];
                fig.slider_matrix.BustRatio  = ratios[4];
                fig.slider_matrix.EyeRatio   = ratios[5];
            }
            fig.UpdateNodeMap();
            if (fig_file != null)
            {
                fig.UpdateBoneMatrices(true);
            }
            else
            {
                fig.UpdateBoneMatricesWithoutSlider(true);
            }

            foreach (TSOMesh mesh in tso.meshes)
            {
                foreach (TSOSubMesh sub in mesh.sub_meshes)
                {
                    Matrix[] clipped_boneMatrices = fig.ClipBoneMatrices(sub);

                    for (int i = 0; i < sub.vertices.Length; i++)
                    {
                        CalcSkindeform(ref sub.vertices[i], clipped_boneMatrices);
                    }
                }
            }

            foreach (TSONode tso_node in tso.nodes)
            {
                TMONode tmo_node;
                if (fig.nodemap.TryGetValue(tso_node, out tmo_node))
                {
                    tso_node.TransformationMatrix = tmo_node.matrices[0].m;
                }
            }

            tso.Save(@"out.tso");
        }
Esempio n. 22
0
        public int Compose(string dest_path)
        {
            string source_file = dest_path + @".tso";

            if (!File.Exists(source_file))
            {
                Console.WriteLine("File not found: " + source_file);
                return(-1);
            }
            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            foreach (TSOTex tex in tso.textures)
            {
                string name = tex.Name;
                string file = tex.FileName.Trim('"');
                string path = Path.Combine(dest_path, file);

                path = Path.ChangeExtension(path, ".png");

                if (!File.Exists(path))
                {
                    path = Path.ChangeExtension(path, ".bmp");
                }

                if (!File.Exists(path))
                {
                    path = Path.ChangeExtension(path, ".tga");
                }

                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(file);
                tex.Load(path);
            }

            foreach (TSOScript scr in tso.scripts)
            {
                string name = scr.Name;
                string path = Path.Combine(dest_path, name);
                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(name);
                scr.Load(path);
            }

            foreach (TSOSubScript scr in tso.sub_scripts)
            {
                string name = scr.Name;
                string file = scr.FileName.Trim('"');
                string path = Path.Combine(dest_path, name);
                if (!File.Exists(path))
                {
                    Console.WriteLine("File not found: " + path);
                    continue;
                }
                Console.WriteLine(name);
                scr.Load(path);
            }

            string dest_file = Path.ChangeExtension(dest_path, @".new" + Path.GetExtension(dest_path) + @".tso");

            Console.WriteLine("Save File: " + dest_file);
            tso.Save(dest_file);

            return(0);
        }
Esempio n. 23
0
        public void Process(TSOFile tso, string col)
        {
            Dictionary <string, TSOTex> texmap = new Dictionary <string, TSOTex>();

            foreach (TSOTex tex in tso.textures)
            {
                texmap[tex.Name] = tex;
            }

            foreach (TSOSubScript sub in tso.sub_scripts)
            {
                Console.WriteLine("  sub name {0} file {1}", sub.Name, sub.FileName);
                TSOHairPart detected_part = null;

                Shader shader         = sub.shader;
                string color_tex_name = shader.ColorTexName;
                string shade_tex_name = shader.ShadeTexName;

                foreach (TSOHairPart part in parts)
                {
                    if (part.GetTextRegex().IsMatch(sub.Name))
                    {
                        detected_part = part;
                        break;
                    }
                }

                if (detected_part == null)
                {
                    TSOTex colorTex;
                    if (texmap.TryGetValue(color_tex_name, out colorTex))
                    {
                        string file = colorTex.FileName.Trim('"');

                        foreach (TSOHairPart part in parts)
                        {
                            if (part.GetTextRegex().IsMatch(file))
                            {
                                detected_part = part;
                                break;
                            }
                        }
                    }
                }

                Console.WriteLine("    : type {0}", (detected_part != null) ? detected_part.Name : "Unknown");

                if (detected_part != null)
                {
                    if (detected_part.SubPath != null)
                    {
                        sub.Load(Path.Combine(KitRoot, string.Format(detected_part.SubPath, col)));
                    }

                    if (detected_part.TexPath != null)
                    {
                        TSOTex colorTex;
                        if (texmap.TryGetValue(color_tex_name, out colorTex))
                        {
                            colorTex.Load(Path.Combine(KitRoot, string.Format(detected_part.TexPath, col)));
                        }
                    }
                }

                sub.GenerateShader();
                Shader new_shader = sub.shader;
                new_shader.ColorTexName = color_tex_name;
                new_shader.ShadeTexName = shade_tex_name;
                sub.SaveShader();

                Console.WriteLine("    shader color tex name {0}", color_tex_name);
                Console.WriteLine("    shader shade tex name {0}", shade_tex_name);
            }

            foreach (TSOTex tex in tso.textures)
            {
                Console.WriteLine("  tex name {0} file {1}", tex.Name, tex.FileName);
            }
        }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("TSOMeshOptimize.exe <tso file>");
                return;
            }
            string source_file = args[0];

            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            Console.WriteLine("メッシュ:");
            int i = 0;

            foreach (TSOMesh mesh in tso.meshes)
            {
                Console.WriteLine("{0} {1}", i, mesh.Name);
                i++;
            }

            Console.Write("メッシュを選択 (0-{0}): ", tso.meshes.Length - 1);
            int mesh_idx = 0;
            {
                string line = Console.ReadLine();
                if (line.Length != 0)
                {
                    try
                    {
                        mesh_idx = int.Parse(line);
                    }
                    catch (System.FormatException e)
                    {
                        Console.WriteLine(e);
                        return;
                    }
                }
            }

            TSOMesh selected_mesh = null;

            try
            {
                selected_mesh = tso.meshes[mesh_idx];
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e);
                return;
            }

            Console.WriteLine("サブメッシュ:");
            Console.WriteLine("  vertices bone_indices");
            Console.WriteLine("  -------- ------------");
            foreach (TSOSubMesh sub in selected_mesh.sub_meshes)
            {
                Console.WriteLine("  {0,8} {1,12}", sub.vertices.Length, sub.bone_indices.Length);
            }

            Console.Write("最大パレット長: ");
            int max_palettes = 16;

            {
                string line = Console.ReadLine();
                if (line.Length != 0)
                {
                    try
                    {
                        max_palettes = int.Parse(line);
                    }
                    catch (System.FormatException e)
                    {
                        Console.WriteLine(e);
                        return;
                    }
                }
            }

            RebuildMesh(selected_mesh, max_palettes);

            string dest_path = Path.GetDirectoryName(source_file);
            string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.tso";

            dest_path = Path.Combine(dest_path, dest_file);
            Console.WriteLine("Save File: " + dest_path);
            tso.Save(dest_path);
        }
Esempio n. 25
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                Console.WriteLine("TSOSmooth.exe <tso file>");
                return;
            }
            string source_file = args[0];

            TSOFile tso = new TSOFile();

            tso.Load(source_file);

            Dictionary <string, TSONode> nodemap = new Dictionary <string, TSONode>();

            foreach (TSONode node in tso.nodes)
            {
                nodemap.Add(node.Name, node);
            }

            string[] nodesets = GetSetsNames().ToArray();

            Console.WriteLine("nodesets:");
            {
                int i = 0;
                foreach (string name in nodesets)
                {
                    Console.WriteLine("{0} {1}", i, name);
                    i++;
                }
            }
            Console.Write("nodesetsを選択 (0-{0}): ", nodesets.Length - 1);
            int sets_idx = 0;

            {
                string line = Console.ReadLine();
                if (line.Length != 0)
                {
                    try
                    {
                        sets_idx = int.Parse(line);
                    }
                    catch (System.FormatException e)
                    {
                        Console.WriteLine(e);
                        return;
                    }
                }
            }
            setsname = nodesets[sets_idx];

            char[] delim = { ' ' };
            using (StreamReader source = new StreamReader(File.OpenRead(GetSetsPath())))
            {
                string line;
                while ((line = source.ReadLine()) != null)
                {
                    string[] tokens = line.Split(delim);
                    string   op     = tokens[0];
                    if (op == "node")
                    {
                        Debug.Assert(tokens.Length == 2, "tokens length should be 2: " + line);
                        string  cnode_name = tokens[1];
                        TSONode cnode      = nodemap[cnode_name];

                        use_nodes.Add(cnode);
                    }
                }
            }

            Console.WriteLine("メッシュ:");
            {
                int i = 0;
                foreach (TSOMesh mesh in tso.meshes)
                {
                    Console.WriteLine("{0} {1}", i, mesh.Name);
                    i++;
                }
            }

            Console.Write("メッシュを選択 (0-{0}): ", tso.meshes.Length - 1);
            int mesh_idx = 0;
            {
                string line = Console.ReadLine();
                if (line.Length != 0)
                {
                    try
                    {
                        mesh_idx = int.Parse(line);
                    }
                    catch (System.FormatException e)
                    {
                        Console.WriteLine(e);
                        return;
                    }
                }
            }

            TSOMesh selected_mesh = null;

            try
            {
                selected_mesh = tso.meshes[mesh_idx];
            }
            catch (IndexOutOfRangeException e)
            {
                Console.WriteLine(e);
                return;
            }

            Console.WriteLine("サブメッシュ:");
            Console.WriteLine("  vertices bone_indices");
            Console.WriteLine("  -------- ------------");
            foreach (TSOSubMesh sub in selected_mesh.sub_meshes)
            {
                Console.WriteLine("  {0,8} {1,12}", sub.vertices.Length, sub.bone_indices.Length);
            }

            int max_palettes = 16;

            RebuildMesh(selected_mesh, max_palettes);

            string dest_path = Path.GetDirectoryName(source_file);
            string dest_file = Path.GetFileNameWithoutExtension(source_file) + @".new.tso";

            dest_path = Path.Combine(dest_path, dest_file);
            Console.WriteLine("Save File: " + dest_path);
            tso.Save(dest_path);
        }