2 using System.Collections.Generic;
8 public class TSOGeneratorOneBone : TSOGenerator
10 public TSOGeneratorOneBone(TSOGeneratorConfig config)
16 protected Dictionary<string, int> node_idmap;
18 //ボーンの名称からidを得る辞書を生成する。参照tsoを基にする。
21 node_idmap = new Dictionary<string, int>();
23 foreach (TSONode i in tsoref.nodes)
25 node_idmap.Add(i.ShortName, i.ID);
29 protected override bool DoLoadRefTSO(string path)
31 tsoref = LoadTSO(path);
36 protected override bool DoGenerateMeshes()
38 meshes = new List<TSOMesh>();
40 foreach (MqoObject obj in mqo.Objects)
42 if (obj.name.ToLower() == "bone")
45 Console.WriteLine("object:" + obj.name);
50 uint idx = 0x00000000;
51 Point4 wgt = new Point4(1, 0, 0, 0);
52 int[] bones = CreateBones(obj);
55 List<ushort> indices = new List<ushort>();
56 VertexHeap<Vertex> vh = new VertexHeap<Vertex>();
57 List<TSOSubMesh> subs = new List<TSOSubMesh>();
59 Console.WriteLine(" vertices bone_indices");
60 Console.WriteLine(" -------- ------------");
62 for (int mtl = 0; mtl < nummaterials; ++mtl)
66 foreach (MqoFace face in obj.faces)
71 Vertex va = new Vertex(obj.vertices[face.a].Pos, wgt, idx, obj.vertices[face.a].Nrm, new Point2(face.ta.x, 1 - face.ta.y));
72 Vertex vb = new Vertex(obj.vertices[face.b].Pos, wgt, idx, obj.vertices[face.b].Nrm, new Point2(face.tb.x, 1 - face.tb.y));
73 Vertex vc = new Vertex(obj.vertices[face.c].Pos, wgt, idx, obj.vertices[face.c].Nrm, new Point2(face.tc.x, 1 - face.tc.y));
75 indices.Add(vh.Add(va));
76 indices.Add(vh.Add(vc));
77 indices.Add(vh.Add(vb));
80 if (indices.Count == 0)
84 ushort[] nidx = NvTriStrip.Optimize(indices.ToArray());
87 Vertex[] verts = vh.verts.ToArray();
88 TSOSubMesh sub = new TSOSubMesh();
90 sub.numbones = bones.Length;
92 sub.numvertices = nidx.Length;
93 sub.vertices = new Vertex[nidx.Length];
95 for (int i = 0; i < nidx.Length; ++i)
96 sub.vertices[i] = verts[nidx[i]];
98 Console.WriteLine(" {0,8} {1,12}", sub.vertices.Length, sub.bones.Length);
104 TSOMesh mesh = new TSOMesh();
105 mesh.name = obj.name;
106 mesh.numsubs = subs.Count;
107 mesh.sub_meshes = subs.ToArray();
108 mesh.matrix = Matrix44.Identity;
116 public Dictionary<string, string> ObjectBoneNames = new Dictionary<string, string>();
118 // objに対応するボーンid配列を生成する。
119 int[] CreateBones(MqoObject obj)
121 int[] bones = new int[1];
125 name = ObjectBoneNames[obj.name];
127 catch (KeyNotFoundException)
129 throw new KeyNotFoundException(string.Format("ボーン指定に誤りがあります。オブジェクト {0} にボーンを割り当てる必要があります。", obj.name));
131 bones[0] = node_idmap[name];