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.Name, 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> vert_indices = new List<ushort>();
56 Heap<Vertex> vh = new Heap<Vertex>();
57 List<TSOSubMesh> subs = new List<TSOSubMesh>();
59 Console.WriteLine(" vertices bone_indices");
60 Console.WriteLine(" -------- ------------");
62 for (int spec = 0; spec < nummaterials; ++spec)
66 foreach (MqoFace face in obj.faces)
68 if (face.spec != spec)
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 vert_indices.Add(vh.Add(va));
76 vert_indices.Add(vh.Add(vc));
77 vert_indices.Add(vh.Add(vb));
80 if (vert_indices.Count == 0)
83 ushort[] optimized_indices = NvTriStrip.Optimize(vert_indices.ToArray());
85 TSOSubMesh sub = new TSOSubMesh();
87 sub.numbones = bones.Length;
90 sub.numvertices = optimized_indices.Length;
91 Vertex[] vertices = new Vertex[optimized_indices.Length];
92 for (int i = 0; i < optimized_indices.Length; ++i)
94 vertices[i] = vh.ary[optimized_indices[i]];
96 sub.vertices = vertices;
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];