• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision685 (tree)
Zeit2011-03-07 01:26:35
Autorwilfrem

Log Message

ファクトリーの分離

Ändern Zusammenfassung

Diff

--- branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPartFactory.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPartFactory.cs (revision 685)
@@ -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.Graphics;
6+
7+namespace MikuMikuDance.XNA.Model
8+{
9+ class MMDModelPartFactory : IMMDModelPartFactory
10+ {
11+ //ファクトリー関数
12+ public IMMDModelPart Create(int triangleCount, MMDVertex[] Vertices, Dictionary<string, object> OpaqueData)
13+ {
14+ IndexBuffer indexBuffer = null;
15+ if (OpaqueData.ContainsKey("IndexBuffer"))
16+ indexBuffer = OpaqueData["IndexBuffer"] as IndexBuffer;
17+ if (indexBuffer == null)
18+ throw new ArgumentException("MMDModelPartFactoryのOpaqueDataには\"IndexBuffer\"キーとIndexBufferオブジェクトが必要です。", "OpaqueData");
19+ if (Vertices is MMDVertexNm[])
20+ {
21+ if (Vertices is MMDVertexNmTx[])
22+ {
23+ if (Vertices is MMDVertexNmTxVc[])
24+ return new MMDModelPartPNmTxVc(triangleCount, (MMDVertexNmTxVc[])Vertices, indexBuffer);
25+ else
26+ return new MMDModelPartPNmTx(triangleCount, (MMDVertexNmTx[])Vertices, indexBuffer);
27+ }
28+ else
29+ {
30+ if (Vertices is MMDVertexNmVc[])
31+ return new MMDModelPartPNmVc(triangleCount, (MMDVertexNmVc[])Vertices, indexBuffer);
32+ else
33+ return new MMDModelPartPNm(triangleCount, (MMDVertexNm[])Vertices, indexBuffer);
34+ }
35+ }
36+ else
37+ {
38+ if (Vertices is MMDVertexTx[])
39+ {
40+ if (Vertices is MMDVertexTxVc[])
41+ return new MMDModelPartPTxVc(triangleCount, (MMDVertexTxVc[])Vertices, indexBuffer);
42+ else
43+ return new MMDModelPartPTx(triangleCount, (MMDVertexTx[])Vertices, indexBuffer);
44+ }
45+ else
46+ {
47+ if (Vertices is MMDVertexVc[])
48+ return new MMDModelPartPVc(triangleCount, (MMDVertexVc[])Vertices, indexBuffer);
49+ else
50+ return new MMDModelPartP(triangleCount, Vertices, indexBuffer);
51+ }
52+ }
53+ }
54+ }
55+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPart.cs (revision 684)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPart.cs (revision 685)
@@ -125,44 +125,7 @@
125125 graphics.SetVertexBuffer(null);
126126 }
127127
128- //ファクトリー関数
129- internal static MMDModelPart Create(int triangleCount, MMDVertex[] Vertices, IndexBuffer indexBuffer)
130- {
131- if (Vertices is MMDVertexNm[])
132- {
133- if (Vertices is MMDVertexNmTx[])
134- {
135- if (Vertices is MMDVertexNmTxVc[])
136- return new MMDModelPartPNmTxVc(triangleCount, (MMDVertexNmTxVc[])Vertices, indexBuffer);
137- else
138- return new MMDModelPartPNmTx(triangleCount, (MMDVertexNmTx[])Vertices, indexBuffer);
139- }
140- else
141- {
142- if (Vertices is MMDVertexNmVc[])
143- return new MMDModelPartPNmVc(triangleCount, (MMDVertexNmVc[])Vertices, indexBuffer);
144- else
145- return new MMDModelPartPNm(triangleCount, (MMDVertexNm[])Vertices, indexBuffer);
146- }
147- }
148- else
149- {
150- if (Vertices is MMDVertexTx[])
151- {
152- if (Vertices is MMDVertexTxVc[])
153- return new MMDModelPartPTxVc(triangleCount, (MMDVertexTxVc[])Vertices, indexBuffer);
154- else
155- return new MMDModelPartPTx(triangleCount, (MMDVertexTx[])Vertices, indexBuffer);
156- }
157- else
158- {
159- if (Vertices is MMDVertexVc[])
160- return new MMDModelPartPVc(triangleCount, (MMDVertexVc[])Vertices, indexBuffer);
161- else
162- return new MMDModelPartP(triangleCount, Vertices, indexBuffer);
163- }
164- }
165- }
128+
166129
167130 /// <summary>
168131 /// ボーンの設定
--- branches/XNA4/MikuMikuDanceXNA/Model/IMMDModelPartFactory.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/IMMDModelPartFactory.cs (revision 685)
@@ -0,0 +1,19 @@
1+using System;
2+using System.Collections.Generic;
3+namespace MikuMikuDance.XNA.Model
4+{
5+ /// <summary>
6+ /// モデルパーツのアブストラクトファクトリー
7+ /// </summary>
8+ public interface IMMDModelPartFactory
9+ {
10+ /// <summary>
11+ /// モデルパーツの作成
12+ /// </summary>
13+ /// <param name="triangleCount">ポリゴン数</param>
14+ /// <param name="Vertices">頂点一覧</param>
15+ /// <param name="OpaqueData">不透明データ。インデックスバッファなどが含まれる</param>
16+ /// <returns>モデルパーツ</returns>
17+ IMMDModelPart Create(int triangleCount, MMDVertex[] Vertices, Dictionary<string, object> OpaqueData);
18+ }
19+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPartReader.cs (revision 684)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPartReader.cs (revision 685)
@@ -23,8 +23,14 @@
2323 IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>();
2424
2525 // create the model part from this data
26- MMDModelPart modelPart = MMDModelPart.Create(triangleCount, Vertices, indexBuffer);
27-
26+ Dictionary<string, object> OpaqueData = new Dictionary<string, object>();
27+ OpaqueData.Add("IndexBuffer", indexBuffer);
28+ MMDModelPart modelPart = null;
29+ modelPart = MMDXCore.Instance.ModelPartFactory.Create(triangleCount, Vertices, OpaqueData) as MMDModelPart;
30+ if (modelPart == null)
31+ {
32+ throw new ContentLoadException("MMDXCore.ModelPartFactoryがMMDModelPart以外を返すファクトリーになっています。XNAのコンテンツパイプラインを使用する場合はMMDModelPartを返すファクトリーをセットする必要があります");
33+ }
2834 // read in the BasicEffect as a shared resource
2935 input.ReadSharedResource<Effect>(fx => modelPart.Effect = fx);
3036
--- branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 684)
+++ branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 685)
@@ -38,6 +38,10 @@
3838 /// </summary>
3939 public IIKLimitter IKLimitter { get; set; }
4040 /// <summary>
41+ /// モデルパーツファクトリー
42+ /// </summary>
43+ public IMMDModelPartFactory ModelPartFactory { get; set; }
44+ /// <summary>
4145 /// コンストラクタ
4246 /// </summary>
4347 protected MMDXCore()
@@ -46,6 +50,13 @@
4650 //IKソルバとリミッター
4751 IKSolver = new CCDSolver();
4852 IKLimitter = new DefaltIKLimitter();
53+ //デフォルトパーツファクトリー
54+#if XNA
55+ ModelPartFactory = new MMDModelPartFactory();
56+#else
57+ ModelPartFactory = null;
58+#endif
59+
4960 }
5061
5162 #if XNA
Show on old repository browser