Exemple #1
0
        /// <summary>
        /// 面リストを生成します。
        /// </summary>
        /// <returns>面リスト</returns>
        public static List <TSOFace> CreateFaces(TSOMesh mesh)
        {
            List <TSOFace> faces = new List <TSOFace>();

            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], sub.bone_indices, sub.spec);
                }
                for (int i = 2; i < vertices.Length; i++)
                {
                    UnifiedPositionVertex a, b, c;
                    if (i % 2 != 0)
                    {
                        a = vertices[i - 2];
                        b = vertices[i - 0];
                        c = vertices[i - 1];
                    }
                    else
                    {
                        a = vertices[i - 2];
                        b = vertices[i - 1];
                        c = vertices[i - 0];
                    }
                    if (!a.Equals(b) && !b.Equals(c) && !c.Equals(a))
                    {
                        faces.Add(new TSOFace(a, b, c));
                    }
                }
            }
            return(faces);
        }
Exemple #2
0
        /// <summary>
        /// 面リストを生成します。
        /// </summary>
        public static List <TSOFace> CreateFaces(TSOMesh mesh)
        {
            unified_position_vert_heap = new Heap <UnifiedPositionVertex>();
            List <TSOFace> faces = new List <TSOFace>();

            foreach (TSOSubMesh sub in mesh.sub_meshes)
            {
                ushort[] vert_indices = new ushort[sub.vertices.Length];
                for (int i = 0; i < vert_indices.Length; i++)
                {
                    UnifiedPositionVertex v = new UnifiedPositionVertex(sub.vertices[i], sub.bone_indices, sub.spec);
                    if (!unified_position_vert_heap.ContainsKey(v))
                    {
                        unified_position_vert_heap.Add(v);
                    }
                    vert_indices[i] = unified_position_vert_heap[v];
                }
                for (int i = 2; i < vert_indices.Length; i++)
                {
                    FaceVertex a, b, c;
                    if (i % 2 != 0)
                    {
                        a.i = vert_indices[i - 2];
                        b.i = vert_indices[i - 0];
                        c.i = vert_indices[i - 1];
                    }
                    else
                    {
                        a.i = vert_indices[i - 2];
                        b.i = vert_indices[i - 1];
                        c.i = vert_indices[i - 0];
                    }
                    if (a.i != b.i && b.i != c.i && c.i != a.i)
                    {
                        if (i % 2 != 0)
                        {
                            a.u = sub.vertices[i - 2].u;
                            a.v = sub.vertices[i - 2].v;
                            b.u = sub.vertices[i - 0].u;
                            b.v = sub.vertices[i - 0].v;
                            c.u = sub.vertices[i - 1].u;
                            c.v = sub.vertices[i - 1].v;
                        }
                        else
                        {
                            a.u = sub.vertices[i - 2].u;
                            a.v = sub.vertices[i - 2].v;
                            b.u = sub.vertices[i - 1].u;
                            b.v = sub.vertices[i - 1].v;
                            c.u = sub.vertices[i - 0].u;
                            c.v = sub.vertices[i - 0].v;
                        }
                        faces.Add(new TSOFace(a, b, c, sub.spec));
                    }
                }
            }
            return(faces);
        }
Exemple #3
0
        public static void RebuildMesh(TSOMesh mesh, int max_palettes)
        {
            List <TSOFace> faces = CreateFaces(mesh);
            //Console.WriteLine("#uniq faces:{0}", faces.Count);
            List <TSOSubMesh> sub_meshes = CreateSubMeshes(faces, max_palettes);

            //Console.WriteLine("#subs:{0}", sub_meshes.Count);
            mesh.sub_meshes = sub_meshes.ToArray();
        }
Exemple #4
0
        private void lvMeshes_SelectedIndexChanged(object sender, EventArgs e)
        {
            TSOMesh mesh = GetSelectedMesh();

            if (mesh == null)
            {
                return;
            }

            Debug.WriteLine("selected " + mesh.Name);
        }
Exemple #5
0
        public TSOMesh GetSelectedMesh()
        {
            if (lvMeshes.SelectedItems.Count == 0)
            {
                return(null);
            }

            ListViewItem li   = lvMeshes.SelectedItems[0];
            TSOMesh      mesh = li.Tag as TSOMesh;

            return(mesh);
        }
Exemple #6
0
        public static TSOSubMesh[] CreateSubMeshes(TSOMesh mesh, int max_palettes)
        {
            List <TSOFace> faces = CreateFaces(mesh);

            //Console.WriteLine("#uniq faces:{0}", faces.Count);

            Smooth();

            TSOSubMesh[] sub_meshes = CreateSubMeshes(faces, max_palettes);
            //Console.WriteLine("#subs:{0}", sub_meshes.Length);
            return(sub_meshes);
        }
Exemple #7
0
        private void lvMeshes_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (lvMeshes.SelectedItems.Count == 0)
            {
                return;
            }

            ListViewItem li   = lvMeshes.SelectedItems[0];
            TSOMesh      mesh = li.Tag as TSOMesh;

            viewer.SelectedMesh = mesh;
            Invalidate(false);
        }
Exemple #8
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);
        }
Exemple #9
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);
        }
Exemple #10
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);
        }
Exemple #11
0
 public static void RebuildMesh(TSOMesh mesh, int max_palettes)
 {
     mesh.sub_meshes = CreateSubMeshes(mesh, max_palettes);
 }