2 using System.Collections.Generic;
8 public unsafe class TSOGeneratorMqxBone : TSOGenerator
10 public TSOGeneratorMqxBone(TSOGeneratorConfig config)
19 weits = new MqoWeit[4];
20 for (int i = 0; i < 4; ++i)
22 weits[i] = new MqoWeit();
26 protected override bool DoLoadRefTSO(string path)
28 tsoref = LoadTSO(path);
33 void UpdateWeits(int object_id, int vertex_id)
37 for (int i = 0; i < 4; ++i)
45 protected override bool DoGenerateMeshes()
47 meshes = new List<TSOMesh>();
49 foreach (MqoObject obj in mqo.Objects)
51 if (obj.name.ToLower() == "bone")
54 Console.WriteLine("object:" + obj.name);
56 int object_id = obj.id;
60 List<int> faces_1 = new List<int>();
61 List<int> faces_2 = new List<int>();
62 Heap<int> bh = new Heap<int>();
63 Heap<Vertex> vh = new Heap<Vertex>();
64 Vertex[] refvs = new Vertex[3];
65 List<ushort> vert_indices = new List<ushort>();
66 Dictionary<int, bool> adding_bone_indices = new Dictionary<int, bool>();
67 List<TSOSubMesh> subs = new List<TSOSubMesh>();
69 for (int i = 0, n = obj.faces.Count; i < n; ++i)
73 Console.WriteLine(" vertices bone_indices");
74 Console.WriteLine(" -------- ------------");
76 while (faces_1.Count != 0)
78 int spec = obj.faces[faces_1[0]].spec;
83 foreach (int f in faces_1)
85 MqoFace face = obj.faces[f];
87 if (face.spec != spec)
93 for (int k = 0; k < 3; ++k)
95 refvs[k] = new Vertex();
98 adding_bone_indices.Clear();
100 for (int k = 0; k < 3; ++k)
102 UInt32 idx0 = refvs[k].Idx;
103 Point4 wgt0 = refvs[k].Wgt;
104 byte* idx = (byte*)(&idx0);
105 float* wgt = (float*)(&wgt0);
107 int vertex_id = obj.vertices[face.vert_indices[k]].id;
108 UpdateWeits(object_id, vertex_id);
110 for (int l = 0; l < 4; ++l)
112 idx[l] = (byte)(weits[l].bone_id-1);
113 wgt[l] = weits[l].weit;
118 for (int l = 0; l < 4; ++l)
120 if (wgt[l] <= float.Epsilon)
122 if (bh.map.ContainsKey(idx[l]))
125 adding_bone_indices[idx[l]] = true;
129 if (bh.Count + adding_bone_indices.Count > 16)
135 foreach (int i in adding_bone_indices.Keys)
140 for (int k = 0; k < 3; ++k)
142 UInt32 idx0 = refvs[k].Idx;
143 Point4 wgt0 = refvs[k].Wgt;
144 byte* idx = (byte*)(&idx0);
145 float* wgt = (float*)(&wgt0);
147 for (int l = 0; l < 4; ++l)
149 if (wgt[l] <= float.Epsilon)
152 idx[l] = (byte)bh[idx[l]];
158 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));
159 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));
160 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));
162 vert_indices.Add(vh.Add(va));
163 vert_indices.Add(vh.Add(vc));
164 vert_indices.Add(vh.Add(vb));
167 ushort[] optimized_indices = NvTriStrip.Optimize(vert_indices.ToArray());
169 TSOSubMesh sub = new TSOSubMesh();
171 sub.numbones = bh.Count;
172 sub.bones = bh.ary.ToArray();
174 sub.numvertices = optimized_indices.Length;
175 Vertex[] vertices = new Vertex[optimized_indices.Length];
176 for (int i = 0; i < optimized_indices.Length; ++i)
178 vertices[i] = vh.ary[optimized_indices[i]];
180 sub.vertices = vertices;
182 Console.WriteLine(" {0,8} {1,12}", sub.vertices.Length, sub.bones.Length);
186 List<int> faces_tmp = faces_1;
192 TSOMesh mesh = new TSOMesh();
193 mesh.name = obj.name;
194 mesh.numsubs = subs.Count;
195 mesh.sub_meshes = subs.ToArray();
196 mesh.matrix = Matrix44.Identity;