2 using System.Collections.Generic;
8 public unsafe class TSOGeneratorMqxBone : TSOGenerator
10 public TSOGeneratorMqxBone(TSOGeneratorConfig config)
15 protected override bool DoLoadRefTSO(string path)
20 protected override bool DoGenerateMeshes()
22 meshes = new List<TSOMesh>();
24 foreach (MqoObject obj in mqo.Objects)
26 if (obj.name.ToLower() == "bone")
29 Console.WriteLine("object:" + obj.name);
31 int object_id = obj.id;
35 List<int> faces_1 = new List<int>();
36 List<int> faces_2 = new List<int>();
37 Heap<int> bh = new Heap<int>();
38 Heap<Vertex> vh = new Heap<Vertex>();
39 Vertex[] refvs = new Vertex[3];
40 List<ushort> vert_indices = new List<ushort>();
41 Dictionary<int, bool> adding_bone_indices = new Dictionary<int, bool>();
42 List<TSOSubMesh> subs = new List<TSOSubMesh>();
44 for (int i = 0, n = obj.faces.Count; i < n; ++i)
48 Console.WriteLine(" vertices bone_indices");
49 Console.WriteLine(" -------- ------------");
51 while (faces_1.Count != 0)
53 int spec = obj.faces[faces_1[0]].spec;
58 foreach (int f in faces_1)
60 MqoFace face = obj.faces[f];
62 if (face.spec != spec)
68 for (int k = 0; k < 3; ++k)
70 refvs[k] = new Vertex();
73 adding_bone_indices.Clear();
75 for (int k = 0; k < 3; ++k)
77 UInt32 idx0 = refvs[k].Idx;
78 Point4 wgt0 = refvs[k].Wgt;
79 byte* idx = (byte*)(&idx0);
80 float* wgt = (float*)(&wgt0);
82 int vertex_id = obj.vertices[face.vert_indices[k]].id;
83 //Console.WriteLine("v.{0} oi:{1} vi:{2}", k, object_id, vertex_id);
84 mqx.UpdateWeits(object_id, vertex_id);
85 for (int l = 0; l < 4; ++l)
87 idx[l] = (byte)mqx.weits[l].node_id;
88 wgt[l] = mqx.weits[l].weit;
89 //Console.WriteLine(" w.{0} i:{1} w:{2}", l, idx[l], wgt[l]);
94 for (int l = 0; l < 4; ++l)
96 if (wgt[l] <= float.Epsilon)
98 if (bh.map.ContainsKey(idx[l]))
101 adding_bone_indices[idx[l]] = true;
105 if (bh.Count + adding_bone_indices.Count > 16)
111 foreach (int i in adding_bone_indices.Keys)
116 for (int k = 0; k < 3; ++k)
118 UInt32 idx0 = refvs[k].Idx;
119 Point4 wgt0 = refvs[k].Wgt;
120 byte* idx = (byte*)(&idx0);
121 float* wgt = (float*)(&wgt0);
123 for (int l = 0; l < 4; ++l)
125 if (wgt[l] <= float.Epsilon)
128 idx[l] = (byte)bh[idx[l]];
134 Vertex va = new Vertex(obj.vertices[face.a].Pos, refvs[0].Wgt, refvs[0].Idx, obj.vertices[face.a].Nrm, new Point2(face.ta.x, 1 - face.ta.y));
135 Vertex vb = new Vertex(obj.vertices[face.b].Pos, refvs[1].Wgt, refvs[1].Idx, obj.vertices[face.b].Nrm, new Point2(face.tb.x, 1 - face.tb.y));
136 Vertex vc = new Vertex(obj.vertices[face.c].Pos, refvs[2].Wgt, refvs[2].Idx, obj.vertices[face.c].Nrm, new Point2(face.tc.x, 1 - face.tc.y));
138 vert_indices.Add(vh.Add(va));
139 vert_indices.Add(vh.Add(vc));
140 vert_indices.Add(vh.Add(vb));
143 ushort[] optimized_indices = NvTriStrip.Optimize(vert_indices.ToArray());
145 TSOSubMesh sub = new TSOSubMesh();
147 sub.numbones = bh.Count;
148 sub.bones = bh.ary.ToArray();
150 sub.numvertices = optimized_indices.Length;
151 Vertex[] vertices = new Vertex[optimized_indices.Length];
152 for (int i = 0; i < optimized_indices.Length; ++i)
154 vertices[i] = vh.ary[optimized_indices[i]];
156 sub.vertices = vertices;
158 Console.WriteLine(" {0,8} {1,12}", sub.vertices.Length, sub.bones.Length);
162 List<int> faces_tmp = faces_1;
168 TSOMesh mesh = new TSOMesh();
169 mesh.name = obj.name;
170 mesh.numsubs = subs.Count;
171 mesh.sub_meshes = subs.ToArray();
172 mesh.matrix = Matrix44.Identity;