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
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
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
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
return true;\r
}\r
\r
- private bool DoWriteTextures()\r
+ bool DoWriteTextures()\r
{\r
bw.Write(textures.Count);\r
\r
return true;\r
}\r
\r
- private bool DoWriteEffects()\r
+ bool DoWriteEffects()\r
{\r
bw.Write(ii.effects.Count);\r
\r
return true;\r
}\r
\r
- private bool DoWriteMaterials()\r
+ bool DoWriteMaterials()\r
{\r
bw.Write(mqo.Materials.Count);\r
\r
return true;\r
}\r
\r
- private bool DoWriteMeshes()\r
+ bool DoWriteMeshes()\r
{\r
bw.Write(meshes.Count);\r
\r
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
\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
{\r
dir = null;\r
tsoref = null;\r
- nodes = null;\r
meshes = null;\r
mqo = null;\r
ii = null;\r
}\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
{
}
- 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;
}
// ボーン情報作成
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>();
Console.WriteLine(" vertices bone_indices");
Console.WriteLine(" -------- ------------");
- for (int mtl = 0; mtl < materials.Count; ++mtl)
+ for (int mtl = 0; mtl < nummaterials; ++mtl)
{
indices.Clear();
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;
+ }
}
}