From: nomeu Date: Sun, 25 Jan 2015 14:28:10 +0000 (+0900) Subject: TSOGeneratorOneBone#CreateNodeMap X-Git-Tag: v0.37-rc2~30 X-Git-Url: http://git.osdn.net/view?p=tdcgexplorer%2Ftso2mqo.git;a=commitdiff_plain;h=e9eafbea8f4ba16c7b8d8a7c2b95e38a82267e3e TSOGeneratorOneBone#CreateNodeMap refactor. --- diff --git a/MqxWriter.cs b/MqxWriter.cs index fb90228..4c753c6 100644 --- a/MqxWriter.cs +++ b/MqxWriter.cs @@ -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(); diff --git a/TSOGenerator.cs b/TSOGenerator.cs index 2342483..bbeae84 100644 --- a/TSOGenerator.cs +++ b/TSOGenerator.cs @@ -5,23 +5,22 @@ using System.IO; using System.Text; using System.Runtime.InteropServices; using System.ComponentModel; -using System.Windows.Forms; using System.Windows.Forms.Design; namespace Tso2MqoGui { public abstract class TSOGenerator { - private string dir; - private TSOGeneratorConfig config; + string dir; + TSOGeneratorConfig config; protected MqoReader mqo; protected TSOFile tsoref; - protected Dictionary nodes; protected List meshes; - private ImportInfo ii; - private BinaryWriter bw; - protected Dictionary materials; - private Dictionary textures; + ImportInfo ii; + BinaryWriter bw; + Dictionary materials; + protected int nummaterials { get { return materials.Count; } } + Dictionary textures; public TSOGenerator(TSOGeneratorConfig config) { @@ -35,14 +34,14 @@ namespace Tso2MqoGui return tso; } - private bool SetCurrentDirectory(string dir) + bool SetCurrentDirectory(string dir) { this.dir = dir; Environment.CurrentDirectory = dir; return true; } - private bool DoLoadMQO(string mqo_file) + bool DoLoadMQO(string mqo_file) { // MQO読み込み mqo = new MqoReader(); @@ -50,7 +49,7 @@ namespace Tso2MqoGui return true; } - private bool DoLoadXml(string importinfo_file) + bool DoLoadXml(string importinfo_file) { // XML読み込み ii = ImportInfo.Load(importinfo_file); @@ -97,28 +96,25 @@ namespace Tso2MqoGui return true; } - private bool DoWriteHeader() + bool DoWriteHeader() { bw.Write(0x314F5354); return true; } - private bool DoWriteNodeNames() + bool DoWriteNodeNames() { bw.Write(tsoref.nodes.Length); - nodes = new Dictionary(); - foreach (TSONode i in tsoref.nodes) { WriteString(bw, i.Name); - nodes.Add(i.ShortName, i); } return true; } - private bool DoWriteNodeMatrices() + bool DoWriteNodeMatrices() { bw.Write(tsoref.nodes.Length); @@ -128,7 +124,7 @@ namespace Tso2MqoGui return true; } - private bool DoWriteTextures() + bool DoWriteTextures() { bw.Write(textures.Count); @@ -165,7 +161,7 @@ namespace Tso2MqoGui return true; } - private bool DoWriteEffects() + bool DoWriteEffects() { bw.Write(ii.effects.Count); @@ -184,7 +180,7 @@ namespace Tso2MqoGui return true; } - private bool DoWriteMaterials() + bool DoWriteMaterials() { bw.Write(mqo.Materials.Count); @@ -212,7 +208,7 @@ namespace Tso2MqoGui return true; } - private bool DoWriteMeshes() + bool DoWriteMeshes() { bw.Write(meshes.Count); @@ -241,13 +237,13 @@ namespace Tso2MqoGui return true; } - private bool DoOutput(string tsoout_file) + bool DoOutput(string path) { //----- 出力処理 ----------------------------------------------- ii.materials.Clear(); ii.textures.Clear(); - using (FileStream fs = File.OpenWrite(tsoout_file)) + using (FileStream fs = File.OpenWrite(path)) { fs.SetLength(0); bw = new BinaryWriter(fs); @@ -264,9 +260,12 @@ namespace Tso2MqoGui return true; } + + //メッシュリストを生成する。 + //メッシュリストはthis.meshesに保持する。 protected abstract bool DoGenerateMeshes(); - private bool DoSaveXml(string importinfo_file) + bool DoSaveXml(string importinfo_file) { // 結果を保存しておく ImportInfo.Save(importinfo_file, ii); @@ -277,7 +276,6 @@ namespace Tso2MqoGui { dir = null; tsoref = null; - nodes = null; meshes = null; mqo = null; ii = null; @@ -309,7 +307,9 @@ namespace Tso2MqoGui } } - protected abstract bool DoLoadRefTSO(string tsoref); + // 参照tsoを読み込む。 + // 参照tsoはthis.tsorefに保持する。 + protected abstract bool DoLoadRefTSO(string path); #region ユーティリティ public void WriteString(BinaryWriter bw, string s) diff --git a/TSOGeneratorOneBone.cs b/TSOGeneratorOneBone.cs index 1b0a62a..854998e 100644 --- a/TSOGeneratorOneBone.cs +++ b/TSOGeneratorOneBone.cs @@ -14,10 +14,24 @@ namespace Tso2MqoGui { } - protected override bool DoLoadRefTSO(string tsoref_file) + //ボーンの名称からidを得る辞書 + protected Dictionary node_idmap; + + //ボーンの名称からidを得る辞書を生成する。参照tsoを基にする。 + void CreateNodeMap() { - // 参照TSOロード - tsoref = LoadTSO(tsoref_file); + node_idmap = new Dictionary(); + + 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 indices = new List(); @@ -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; + } } } diff --git a/TSOGeneratorRefBone.cs b/TSOGeneratorRefBone.cs index dcbb0a1..ba10167 100644 --- a/TSOGeneratorRefBone.cs +++ b/TSOGeneratorRefBone.cs @@ -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;