表情頂点計算方法を調整
@@ -28,7 +28,7 @@ | ||
28 | 28 | /// <param name="vertices">頂点配列</param> |
29 | 29 | /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param> |
30 | 30 | /// <param name="indexBuffer">インデックスバッファ</param> |
31 | - public MMDGPUModelPartPNm(int triangleCount, MMDVertexNm[] vertices, int[] vertMap, IndexBuffer indexBuffer) | |
31 | + public MMDGPUModelPartPNm(int triangleCount, MMDVertexNm[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer) | |
32 | 32 | : base(triangleCount, vertices.Length, vertMap, indexBuffer) |
33 | 33 | { |
34 | 34 | this.vertices = vertices; |
@@ -93,7 +93,7 @@ | ||
93 | 93 | /// <param name="vertices">頂点配列</param> |
94 | 94 | /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param> |
95 | 95 | /// <param name="indexBuffer">インデックスバッファ</param> |
96 | - public MMDGPUModelPartPNmVc(int triangleCount, MMDVertexNmVc[] vertices, int[] vertMap, IndexBuffer indexBuffer) | |
96 | + public MMDGPUModelPartPNmVc(int triangleCount, MMDVertexNmVc[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer) | |
97 | 97 | : base(triangleCount, vertices.Length, vertMap, indexBuffer) |
98 | 98 | { |
99 | 99 | this.vertices = vertices; |
@@ -159,7 +159,7 @@ | ||
159 | 159 | /// <param name="vertices">頂点配列</param> |
160 | 160 | /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param> |
161 | 161 | /// <param name="indexBuffer">インデックスバッファ</param> |
162 | - public MMDGPUModelPartPNmTx(int triangleCount, MMDVertexNmTx[] vertices, int[] vertMap, IndexBuffer indexBuffer) | |
162 | + public MMDGPUModelPartPNmTx(int triangleCount, MMDVertexNmTx[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer) | |
163 | 163 | : base(triangleCount, vertices.Length, vertMap, indexBuffer) |
164 | 164 | { |
165 | 165 | this.vertices = vertices; |
@@ -225,7 +225,7 @@ | ||
225 | 225 | /// <param name="vertices">頂点配列</param> |
226 | 226 | /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param> |
227 | 227 | /// <param name="indexBuffer">インデックスバッファ</param> |
228 | - public MMDGPUModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, int[] vertMap, IndexBuffer indexBuffer) | |
228 | + public MMDGPUModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer) | |
229 | 229 | : base(triangleCount, vertices.Length, vertMap, indexBuffer) |
230 | 230 | { |
231 | 231 | this.vertices = vertices; |
@@ -38,7 +38,7 @@ | ||
38 | 38 | /// <summary> |
39 | 39 | /// 元の頂点番号との対応表 |
40 | 40 | /// </summary> |
41 | - protected int[] VertMap; | |
41 | + protected Dictionary<long, int[]> VertMap; | |
42 | 42 | /// <summary> |
43 | 43 | /// エフェクト |
44 | 44 | /// </summary> |
@@ -80,7 +80,7 @@ | ||
80 | 80 | /// <param name="vertexCount">頂点数</param> |
81 | 81 | /// <param name="vertMap">モデルの頂点とMMD頂点の対応</param> |
82 | 82 | /// <param name="indexBuffer">インデックスバッファ</param> |
83 | - public MMDModelPart(int triangleCount, int vertexCount, int[] vertMap, IndexBuffer indexBuffer) | |
83 | + public MMDModelPart(int triangleCount, int vertexCount, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer) | |
84 | 84 | { |
85 | 85 | this.triangleCount = triangleCount; |
86 | 86 | this.vertexCount = vertexCount; |
@@ -24,7 +24,7 @@ | ||
24 | 24 | //モデルパーツの読み込み |
25 | 25 | int triangleCount = input.ReadInt32(); |
26 | 26 | MMDVertexNm[] Vertices = input.ReadObject<MMDVertexNm[]>(); |
27 | - int[] VertMap = input.ReadObject<int[]>(); | |
27 | + Dictionary<long, int[]> VertMap = input.ReadObject<Dictionary<long, int[]>>(); | |
28 | 28 | IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>(); |
29 | 29 | |
30 | 30 | // create the model part from this data |
@@ -16,7 +16,7 @@ | ||
16 | 16 | IndexBuffer indexBuffer = null; |
17 | 17 | if (OpaqueData.ContainsKey("IndexBuffer")) |
18 | 18 | indexBuffer = OpaqueData["IndexBuffer"] as IndexBuffer; |
19 | - int[] VertMap = OpaqueData["VertMap"] as int[]; | |
19 | + Dictionary<long, int[]> VertMap = OpaqueData["VertMap"] as Dictionary<long, int[]>; | |
20 | 20 | if (indexBuffer == null) |
21 | 21 | throw new ArgumentException("MMDModelPartFactoryのOpaqueDataには\"IndexBuffer\"キーとIndexBufferオブジェクトが必要です。", "OpaqueData"); |
22 | 22 | if (Vertices is MMDVertexNmTx[]) |
@@ -100,7 +100,7 @@ | ||
100 | 100 | /// </summary> |
101 | 101 | /// <param name="vert">頂点</param> |
102 | 102 | /// <param name="indices">PMDとMMDとの頂点変換マップ</param> |
103 | - public void ApplyToVertex(MMDVertexNm[] vert, int[] indices | |
103 | + public void ApplyToVertex(MMDVertexNm[] vert, Dictionary<long,int[]> indices | |
104 | 104 | #if !XBOX |
105 | 105 | = null |
106 | 106 | #endif |
@@ -131,21 +131,23 @@ | ||
131 | 131 | else |
132 | 132 | { |
133 | 133 | #if !XBOX |
134 | - Parallel.For(0,vert.LongLength, (i) => | |
134 | + Parallel.ForEach(vertData,(it)=> | |
135 | 135 | #else |
136 | - for (int i = 0; i < vert.Length; ++i ) | |
136 | + foreach(var it in vertData) | |
137 | 137 | #endif |
138 | 138 | { |
139 | - long index = indices[i]; | |
140 | - if (vertData.ContainsKey(index)) | |
139 | + if (indices.ContainsKey(it.Key)) | |
141 | 140 | { |
142 | - //baseで初期化 | |
143 | - vert[i].Position = vertData[index][0].vector; | |
144 | - for (int j = 1; j < vertData[index].Length; ++j) | |
141 | + foreach (var i in indices[it.Key]) | |
145 | 142 | { |
146 | - Vector3 temp; | |
147 | - Vector3.Multiply(ref vertData[index][j].vector, FaceRates[vertData[index][j].FaceName], out temp); | |
148 | - vert[i].Position += temp; | |
143 | + //baseで初期化 | |
144 | + vert[i].Position = it.Value[0].vector; | |
145 | + for (int j = 1; j < it.Value.Length; ++j) | |
146 | + { | |
147 | + Vector3 temp; | |
148 | + Vector3.Multiply(ref it.Value[j].vector, FaceRates[it.Value[j].FaceName], out temp); | |
149 | + vert[i].Position += temp; | |
150 | + } | |
149 | 151 | } |
150 | 152 | } |
151 | 153 | } |
@@ -31,6 +31,6 @@ | ||
31 | 31 | /// <summary> |
32 | 32 | /// 元の頂点番号対応 |
33 | 33 | /// </summary> |
34 | - public int[] VertMap; | |
34 | + public Dictionary<long, int[]> VertMap; | |
35 | 35 | } |
36 | 36 | } |
@@ -54,7 +54,7 @@ | ||
54 | 54 | /// <param name="vertMap">元の頂点番号との対応表</param> |
55 | 55 | /// <param name="vertices">頂点データ</param> |
56 | 56 | /// <param name="material">マテリアルデータ</param> |
57 | - public void AddModelPart(int triangleCount, IndexCollection indexCollection, int[] vertMap, MMDVertexNmContent[] vertices, MaterialContent material) | |
57 | + public void AddModelPart(int triangleCount, IndexCollection indexCollection, Dictionary<long, int[]> vertMap, MMDVertexNmContent[] vertices, MaterialContent material) | |
58 | 58 | { |
59 | 59 | if (material == null) |
60 | 60 | throw new ArgumentNullException("material"); |
@@ -233,8 +233,21 @@ | ||
233 | 233 | //マテリアルの変換 |
234 | 234 | MaterialContent material = ProcessMaterial(geometry.Material, ShaderIndex); |
235 | 235 | |
236 | + //頂点マップの作成 | |
237 | + Dictionary<long, int[]> vertMap = new Dictionary<long, int[]>(); | |
238 | + Dictionary<long, List<int>> vertMapTemp = new Dictionary<long, List<int>>(); | |
239 | + for (int i = 0; i < geometry.Vertices.PositionIndices.Count; ++i) | |
240 | + { | |
241 | + if (!vertMapTemp.ContainsKey(geometry.Vertices.PositionIndices[i])) | |
242 | + { | |
243 | + vertMapTemp.Add(geometry.Vertices.PositionIndices[i], new List<int>()); | |
244 | + } | |
245 | + vertMapTemp[geometry.Vertices.PositionIndices[i]].Add(i); | |
246 | + } | |
247 | + foreach (var it in vertMapTemp) | |
248 | + vertMap.Add(it.Key, it.Value.ToArray()); | |
236 | 249 | //処理済みのジオメトリを返却用モデルに追加 |
237 | - resultModel.AddModelPart(triangleCount, geometry.Indices, geometry.Vertices.PositionIndices.ToArray(), vertices, material); | |
250 | + resultModel.AddModelPart(triangleCount, geometry.Indices, vertMap, vertices, material); | |
238 | 251 | |
239 | 252 | } |
240 | 253 | //BoneWeightCollectionの変換 |