2 using System.Collections.Generic;
8 public unsafe class TSOGeneratorRefBone : TSOGenerator
10 public TSOGeneratorRefBone(TSOGeneratorConfig config)
16 List<Vertex> refverts;
20 void CreateRefVerts(TSOFile tso)
22 refverts = new List<Vertex>();
24 foreach (TSOMesh i in tso.meshes)
25 foreach (TSOSubMesh j in i.sub_meshes)
26 refverts.AddRange(j.vertices);
29 void CreatePointCluster()
31 pc = new PointCluster(refverts.Count);
33 foreach (Vertex i in refverts)
39 protected override bool DoLoadRefTSO(string path)
41 tsoref = LoadTSO(path);
42 tsoref.SwitchBoneIndicesOnMesh();
43 CreateRefVerts(tsoref);
48 protected override bool DoGenerateMeshes()
50 meshes = new List<TSOMesh>();
52 foreach (MqoObject obj in mqo.Objects)
54 if (obj.name.ToLower() == "bone")
57 Console.WriteLine("object:" + obj.name);
60 List<int> vref = new List<int>(obj.vertices.Count);
62 foreach (UVertex j in obj.vertices)
63 vref.Add(pc.NearestIndex(j.Pos.x, j.Pos.y, j.Pos.z));
68 List<int> faces1 = new List<int>();
69 List<int> faces2 = new List<int>();
70 //int[] bonecnv = new int[tsor.nodes.Length]; // ボーン変換テーブル
71 VertexHeap<Vertex> vh = new VertexHeap<Vertex>();
72 Vertex[] v = new Vertex[3];
73 List<int> bones = new List<int>(16);
74 List<ushort> indices = new List<ushort>();
75 Dictionary<int, int> selected = new Dictionary<int, int>();
76 Dictionary<int, int> work = new Dictionary<int, int>();
77 List<TSOSubMesh> subs = new List<TSOSubMesh>();
79 for (int j = 0, n = obj.faces.Count; j < n; ++j)
83 Console.WriteLine(" vertices bone_indices");
84 Console.WriteLine(" -------- ------------");
86 while (faces1.Count > 0)
88 int mtl = obj.faces[faces1[0]].mtl;
94 foreach (int j in faces1)
96 MqoFace f = obj.faces[j];
104 v[0] = refverts[vref[f.a]];
105 v[1] = refverts[vref[f.b]];
106 v[2] = refverts[vref[f.c]];
110 for (int k = 0; k < 3; ++k)
113 UInt32 idx0 = vv.Idx;
114 Point4 wgt0 = vv.Wgt;
115 byte* idx = (byte*)(&idx0);
116 float* wgt = (float*)(&wgt0);
118 for (int l = 0; l < 4; ++l)
120 if (wgt[l] <= float.Epsilon) continue;
121 if (selected.ContainsKey(idx[l])) continue;
123 if (!work.ContainsKey(idx[l]))
128 if (selected.Count + work.Count > 16)
135 foreach (KeyValuePair<int, int> l in work)
137 selected.Add(l.Key, selected.Count); // ボーンテーブルに追加
142 Vertex va = new Vertex(obj.vertices[f.a].Pos, v[0].Wgt, v[0].Idx, obj.vertices[f.a].Nrm, new Point2(f.ta.x, 1 - f.ta.y));
143 Vertex vb = new Vertex(obj.vertices[f.b].Pos, v[1].Wgt, v[1].Idx, obj.vertices[f.b].Nrm, new Point2(f.tb.x, 1 - f.tb.y));
144 Vertex vc = new Vertex(obj.vertices[f.c].Pos, v[2].Wgt, v[2].Idx, obj.vertices[f.c].Nrm, new Point2(f.tc.x, 1 - f.tc.y));
146 indices.Add(vh.Add(va));
147 indices.Add(vh.Add(vc));
148 indices.Add(vh.Add(vb));
152 ushort[] nidx = NvTriStrip.Optimize(indices.ToArray());
155 Vertex[] verts = vh.verts.ToArray();
157 for (int j = 0; j < verts.Length; ++j)
159 uint idx0 = verts[j].Idx;
160 byte* idx = (byte*)(&idx0);
161 Point4 wgt0 = verts[j].Wgt;
162 float* wgt = (float*)(&wgt0);
164 for (int k = 0; k < 4; ++k)
165 if (wgt[k] > float.Epsilon)
166 idx[k] = (byte)selected[idx[k]];
172 TSOSubMesh sub = new TSOSubMesh();
174 sub.numbones = bones.Count;
175 sub.bones = bones.ToArray();
176 sub.numvertices = nidx.Length;
177 sub.vertices = new Vertex[nidx.Length];
179 for (int j = 0; j < nidx.Length; ++j)
180 sub.vertices[j] = verts[nidx[j]];
182 Console.WriteLine(" {0,8} {1,12}", sub.vertices.Length, sub.bones.Length);
187 List<int> t = faces1;
194 TSOMesh mesh = new TSOMesh();
195 mesh.name = obj.name;
196 mesh.numsubs = subs.Count;
197 mesh.sub_meshes = subs.ToArray();
198 mesh.matrix = Matrix44.Identity;
206 protected override bool DoCleanup()
210 return base.DoCleanup();