• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision681 (tree)
Zeit2011-02-21 03:00:04
Autorwilfrem

Log Message

CPUModelサンプルに生じていた無駄な頂点を整理するルーチンの追加

Ändern Zusammenfassung

Diff

--- branches/XNA4/MMDPipeline/Model/MMDMeshHelper.cs (nonexistent)
+++ branches/XNA4/MMDPipeline/Model/MMDMeshHelper.cs (revision 681)
@@ -0,0 +1,55 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
6+
7+namespace MikuMikuDance.XNA.Model
8+{
9+ static class MMDMeshHelper
10+ {
11+
12+ internal static void FixVertexIndices<T>(IndexCollection index, ref MMDVertexContent[] vertices, VertexChannel<int> positionIndices)
13+ where T : MMDVertexContent
14+ {
15+ T[] index2 = vertices as T[];
16+ if (index2 == null)
17+ throw new ArgumentException("verticesとTの型が一致しません");
18+ int[] IndexMap = new int[vertices.Length];
19+ for (int i = 0; i < index.Count-1; i++)
20+ {
21+ for (int j = i + 1; j < index.Count; j++)
22+ {
23+ if (positionIndices[i] == positionIndices[j])
24+ {
25+ index2[j] = null;
26+ index[j] = index[i];
27+ }
28+ }
29+ }
30+ int newIndex = 0;
31+ for (int i = 0; i < index.Count; i++)
32+ {
33+ if (index2[i] == null)
34+ {
35+ IndexMap[i] = -1;
36+ }
37+ else
38+ {
39+ IndexMap[i] = newIndex;
40+ ++newIndex;
41+ }
42+ }
43+ List<T> result = new List<T>();
44+ for (int i = 0; i < index.Count; i++)
45+ {
46+ if (IndexMap[i] != -1)
47+ {
48+ result.Add(index2[i]);
49+ }
50+ index[i] = IndexMap[index[i]];
51+ }
52+ vertices = result.ToArray();
53+ }
54+ }
55+}
--- branches/XNA4/MMDPipeline/Model/MMDModelProcessor.cs (revision 680)
+++ branches/XNA4/MMDPipeline/Model/MMDModelProcessor.cs (revision 681)
@@ -85,9 +85,7 @@
8585 MeshContent mesh = input as MeshContent;
8686 if (mesh != null)
8787 {
88- //なるべくPMDのそのままにしたいので、PMDがベースの場合はOptimizeしない
89- if (mmdScene == null)
90- MeshHelper.OptimizeForCache(mesh);
88+ MeshHelper.OptimizeForCache(mesh);
9189 //メッシュ内のジオメトリ処理
9290 foreach (var geometry in mesh.Geometry)
9391 {
@@ -249,6 +247,43 @@
249247 //マテリアルの変換
250248 MaterialContent material = ProcessMaterial(geometry.Material);
251249
250+
251+ //頂点インデックスの整理(geometryでは頂点インデックスが崩れているため)
252+ //にしても、このコード汚いなぁ……なんとかならんかな……
253+ if (normals != null)
254+ {
255+ if (texCoords != null)
256+ {
257+ if (vcolors != null)
258+ MMDMeshHelper.FixVertexIndices<MMDVertexNmTxVcContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
259+ else
260+ MMDMeshHelper.FixVertexIndices<MMDVertexNmTxContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
261+ }
262+ else
263+ {
264+ if (vcolors != null)
265+ MMDMeshHelper.FixVertexIndices<MMDVertexNmVcContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
266+ else
267+ MMDMeshHelper.FixVertexIndices<MMDVertexNmContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
268+ }
269+ }
270+ else
271+ {
272+ if (texCoords != null)
273+ {
274+ if (vcolors != null)
275+ MMDMeshHelper.FixVertexIndices<MMDVertexTxVcContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
276+ else
277+ MMDMeshHelper.FixVertexIndices<MMDVertexTxContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
278+ }
279+ else
280+ {
281+ if (vcolors != null)
282+ MMDMeshHelper.FixVertexIndices<MMDVertexVcContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
283+ else
284+ MMDMeshHelper.FixVertexIndices<MMDVertexContent>(geometry.Indices, ref vertices, geometry.Vertices.PositionIndices);
285+ }
286+ }
252287 //処理済みのジオメトリを返却用モデルに追加
253288 resultModel.AddModelPart(triangleCount, geometry.Indices, vertices, material as BasicMaterialContent);
254289
--- branches/XNA4/MMDPipeline/Model/MMDMeshBuilder.cs (revision 680)
+++ branches/XNA4/MMDPipeline/Model/MMDMeshBuilder.cs (revision 681)
@@ -87,7 +87,9 @@
8787 FaceIndex += model.Materials[i].FaceVertCount;
8888 }
8989 //重複頂点データのマージ
90+ MeshHelper.MergeDuplicatePositions(buildingMesh, 0);
9091 MeshHelper.MergeDuplicateVertices(buildingMesh);
92+
9193 //メッシュ出来たので返却
9294 return buildingMesh;
9395 }
Show on old repository browser