OSDN Git Service

TSOGeneratorOneBone#CreateNodeMap
authornomeu <nomeu@nomeu.org>
Sun, 25 Jan 2015 14:28:10 +0000 (23:28 +0900)
committernomeu <nomeu@nomeu.org>
Sun, 25 Jan 2015 14:30:51 +0000 (23:30 +0900)
refactor.

MqxWriter.cs
TSOGenerator.cs
TSOGeneratorOneBone.cs
TSOGeneratorRefBone.cs

index fb90228..4c753c6 100644 (file)
@@ -6,10 +6,22 @@ using System.Xml;
 
 namespace Tso2MqoGui
 {
+    /// MqxFileを書き出します。
     public class MqxWriter
     {
+        // mqo path
+        //todo: rename to MqoPath
         public string MqoFile;
 
+        // MqxFileを書き出す。
+        //
+        // bones:
+        // ボーン配列
+        // numobjects:
+        // オブジェクトの総数
+        // スキン設定の対象オブジェクトは全てのオブジェクトとする。
+        //
+        // todo: oids
         public void Write(MqoBone[] bones, int numobjects)
         {
             XmlWriterSettings settings = new XmlWriterSettings();
index 2342483..bbeae84 100644 (file)
@@ -5,23 +5,22 @@ using System.IO;
 using System.Text;\r
 using System.Runtime.InteropServices;\r
 using System.ComponentModel;\r
-using System.Windows.Forms;\r
 using System.Windows.Forms.Design;\r
 \r
 namespace Tso2MqoGui\r
 {\r
     public abstract class TSOGenerator\r
     {\r
-        private string dir;\r
-        private TSOGeneratorConfig config;\r
+        string dir;\r
+        TSOGeneratorConfig config;\r
         protected MqoReader mqo;\r
         protected TSOFile tsoref;\r
-        protected Dictionary<string, TSONode> nodes;\r
         protected List<TSOMesh> meshes;\r
-        private ImportInfo ii;\r
-        private BinaryWriter bw;\r
-        protected Dictionary<string, MaterialInfo> materials;\r
-        private Dictionary<string, TextureInfo> textures;\r
+        ImportInfo ii;\r
+        BinaryWriter bw;\r
+        Dictionary<string, MaterialInfo> materials;\r
+        protected int nummaterials { get { return materials.Count; } }\r
+        Dictionary<string, TextureInfo> textures;\r
 \r
         public TSOGenerator(TSOGeneratorConfig config)\r
         {\r
@@ -35,14 +34,14 @@ namespace Tso2MqoGui
             return tso;\r
         }\r
 \r
-        private bool SetCurrentDirectory(string dir)\r
+        bool SetCurrentDirectory(string dir)\r
         {\r
             this.dir = dir;\r
             Environment.CurrentDirectory = dir;\r
             return true;\r
         }\r
 \r
-        private bool DoLoadMQO(string mqo_file)\r
+        bool DoLoadMQO(string mqo_file)\r
         {\r
             // MQO読み込み\r
             mqo = new MqoReader();\r
@@ -50,7 +49,7 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoLoadXml(string importinfo_file)\r
+        bool DoLoadXml(string importinfo_file)\r
         {\r
             // XML読み込み\r
             ii = ImportInfo.Load(importinfo_file);\r
@@ -97,28 +96,25 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoWriteHeader()\r
+        bool DoWriteHeader()\r
         {\r
             bw.Write(0x314F5354);\r
             return true;\r
         }\r
 \r
-        private bool DoWriteNodeNames()\r
+        bool DoWriteNodeNames()\r
         {\r
             bw.Write(tsoref.nodes.Length);\r
 \r
-            nodes = new Dictionary<string, TSONode>();\r
-\r
             foreach (TSONode i in tsoref.nodes)\r
             {\r
                 WriteString(bw, i.Name);\r
-                nodes.Add(i.ShortName, i);\r
             }\r
 \r
             return true;\r
         }\r
 \r
-        private bool DoWriteNodeMatrices()\r
+        bool DoWriteNodeMatrices()\r
         {\r
             bw.Write(tsoref.nodes.Length);\r
 \r
@@ -128,7 +124,7 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoWriteTextures()\r
+        bool DoWriteTextures()\r
         {\r
             bw.Write(textures.Count);\r
 \r
@@ -165,7 +161,7 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoWriteEffects()\r
+        bool DoWriteEffects()\r
         {\r
             bw.Write(ii.effects.Count);\r
 \r
@@ -184,7 +180,7 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoWriteMaterials()\r
+        bool DoWriteMaterials()\r
         {\r
             bw.Write(mqo.Materials.Count);\r
 \r
@@ -212,7 +208,7 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoWriteMeshes()\r
+        bool DoWriteMeshes()\r
         {\r
             bw.Write(meshes.Count);\r
 \r
@@ -241,13 +237,13 @@ namespace Tso2MqoGui
             return true;\r
         }\r
 \r
-        private bool DoOutput(string tsoout_file)\r
+        bool DoOutput(string path)\r
         {\r
             //----- 出力処理 -----------------------------------------------\r
             ii.materials.Clear();\r
             ii.textures.Clear();\r
 \r
-            using (FileStream fs = File.OpenWrite(tsoout_file))\r
+            using (FileStream fs = File.OpenWrite(path))\r
             {\r
                 fs.SetLength(0);\r
                 bw = new BinaryWriter(fs);\r
@@ -264,9 +260,12 @@ namespace Tso2MqoGui
 \r
             return true;\r
         }\r
+\r
+        //メッシュリストを生成する。\r
+        //メッシュリストはthis.meshesに保持する。\r
         protected abstract bool DoGenerateMeshes();\r
 \r
-        private bool DoSaveXml(string importinfo_file)\r
+        bool DoSaveXml(string importinfo_file)\r
         {\r
             // 結果を保存しておく\r
             ImportInfo.Save(importinfo_file, ii);\r
@@ -277,7 +276,6 @@ namespace Tso2MqoGui
         {\r
             dir = null;\r
             tsoref = null;\r
-            nodes = null;\r
             meshes = null;\r
             mqo = null;\r
             ii = null;\r
@@ -309,7 +307,9 @@ namespace Tso2MqoGui
             }\r
         }\r
 \r
-        protected abstract bool DoLoadRefTSO(string tsoref);\r
+        // 参照tsoを読み込む。\r
+        // 参照tsoはthis.tsorefに保持する。\r
+        protected abstract bool DoLoadRefTSO(string path);\r
 \r
         #region ユーティリティ\r
         public void WriteString(BinaryWriter bw, string s)\r
index 1b0a62a..854998e 100644 (file)
@@ -14,10 +14,24 @@ namespace Tso2MqoGui
         {
         }
 
-        protected override bool DoLoadRefTSO(string tsoref_file)
+        //ボーンの名称からidを得る辞書
+        protected Dictionary<string, int> node_idmap;
+
+        //ボーンの名称からidを得る辞書を生成する。参照tsoを基にする。
+        void CreateNodeMap()
         {
-            // 参照TSOロード
-            tsoref = LoadTSO(tsoref_file);
+            node_idmap = new Dictionary<string, int>();
+
+            foreach (TSONode i in tsoref.nodes)
+            {
+                node_idmap.Add(i.ShortName, i.ID);
+            }
+        }
+
+        protected override bool DoLoadRefTSO(string path)
+        {
+            tsoref = LoadTSO(path);
+            CreateNodeMap();
             return true;
         }
 
@@ -37,17 +51,7 @@ namespace Tso2MqoGui
                 // ボーン情報作成
                 uint idx = 0x00000000;
                 Point4 wgt = new Point4(1, 0, 0, 0);
-                int[] bones = new int[1];
-                string bone;
-                try
-                {
-                    bone = ObjectBoneNames[obj.name];
-                }
-                catch (KeyNotFoundException)
-                {
-                    throw new KeyNotFoundException(string.Format("ボーン指定に誤りがあります。オブジェクト {0} にボーンを割り当てる必要があります。", obj.name));
-                }
-                bones[0] = nodes[bone].ID;
+                int[] bones = CreateBones(obj);
 
                 // マテリアル別に処理を実行
                 List<ushort> indices = new List<ushort>();
@@ -57,7 +61,7 @@ namespace Tso2MqoGui
                 Console.WriteLine("  vertices bone_indices");
                 Console.WriteLine("  -------- ------------");
 
-                for (int mtl = 0; mtl < materials.Count; ++mtl)
+                for (int mtl = 0; mtl < nummaterials; ++mtl)
                 {
                     indices.Clear();
 
@@ -110,5 +114,22 @@ namespace Tso2MqoGui
 
             return true;
         }
+
+        // objに対応するボーンid配列を生成する。
+        int[] CreateBones(MqoObject obj)
+        {
+            int[] bones = new int[1];
+            string name;
+            try
+            {
+                name = ObjectBoneNames[obj.name];
+            }
+            catch (KeyNotFoundException)
+            {
+                throw new KeyNotFoundException(string.Format("ボーン指定に誤りがあります。オブジェクト {0} にボーンを割り当てる必要があります。", obj.name));
+            }
+            bones[0] = node_idmap[name];
+            return bones;
+        }
     }
 }
index dcbb0a1..ba10167 100644 (file)
@@ -31,10 +31,9 @@ namespace Tso2MqoGui
             pc.Clustering();
         }
 
-        protected override bool DoLoadRefTSO(string tsoref_file)
+        protected override bool DoLoadRefTSO(string path)
         {
-            // 参照TSOロード
-            tsoref = LoadTSO(tsoref_file);
+            tsoref = LoadTSO(path);
             tsoref.SwitchBoneIndicesOnMesh();
             CreatePointCluster(tsoref);
             return true;