• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision846 (tree)
Zeit2011-06-12 14:40:12
Autorwilfrem

Log Message

XBox向けチューニング中……

Ändern Zusammenfassung

Diff

--- branches/XNA4/MikuMikuDanceXNA/Model/MMDXBoxModelPartFactory.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDXBoxModelPartFactory.cs (revision 846)
@@ -0,0 +1,48 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using MikuMikuDance.Core.Model;
6+using MikuMikuDance.Core.Misc;
7+using Microsoft.Xna.Framework.Graphics;
8+using Microsoft.Xna.Framework;
9+
10+namespace MikuMikuDance.XNA.Model
11+{
12+#if XBOX
13+ class MMDXBoxModelPartFactory : IMMDModelPartFactory
14+ {
15+ #region IMMDModelPartFactory メンバー
16+
17+ public IMMDModelPart Create(int triangleCount, MMDVertexNm[] Vertices, Dictionary<string, object> OpaqueData)
18+ {
19+ IndexBuffer indexBuffer = null;
20+ if (OpaqueData.ContainsKey("IndexBuffer"))
21+ indexBuffer = OpaqueData["IndexBuffer"] as IndexBuffer;
22+ Vector2[] extVert = null;
23+ if (OpaqueData.ContainsKey("VerticesExtention"))
24+ extVert = OpaqueData["VerticesExtention"] as Vector2[];
25+ if (indexBuffer == null)
26+ throw new ArgumentException("MMDModelPartXBoxFactoryのOpaqueDataには\"IndexBuffer\"キーとIndexBufferオブジェクトが必要です。", "OpaqueData");
27+ if (extVert == null)
28+ throw new ArgumentException("MMDModelPartXboxFactoryのOpaqueDataには\"VerticesExtention\"キーが必要です。", "OpaqueData");
29+ if (Vertices is MMDVertexNmTx[])
30+ {
31+ if (Vertices is MMDVertexNmTxVc[])
32+ return new MMDXBoxModelPartPNmTxVc(triangleCount, (MMDVertexNmTxVc[])Vertices, extVert, indexBuffer);
33+ else
34+ return new MMDXBoxModelPartPNmTx(triangleCount, (MMDVertexNmTx[])Vertices, extVert, indexBuffer);
35+ }
36+ else
37+ {
38+ if (Vertices is MMDVertexNmVc[])
39+ return new MMDXBoxModelPartPNmVc(triangleCount, (MMDVertexNmVc[])Vertices, extVert, indexBuffer);
40+ else
41+ return new MMDXBoxModelPartPNm(triangleCount, (MMDVertexNm[])Vertices, extVert, indexBuffer);
42+ }
43+ }
44+
45+ #endregion
46+ }
47+#endif
48+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPartReader.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPartReader.cs (revision 846)
@@ -0,0 +1,46 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using Microsoft.Xna.Framework;
5+using Microsoft.Xna.Framework.Content;
6+using Microsoft.Xna.Framework.Graphics;
7+using MikuMikuDance.Core.Model;
8+using MikuMikuDance.Core.Misc;
9+
10+namespace MikuMikuDance.XNA.Model
11+{
12+ /// <summary>
13+ /// ModelPartの読み込み用タイプリーダ
14+ /// </summary>
15+ public class MMDGPUModelPartReader : ContentTypeReader<MMDModelPart>
16+ {
17+ /// <summary>
18+ /// モデルパーツの読み込み
19+ /// </summary>
20+ /// <param name="input">コンテンツリーダ</param>
21+ /// <param name="existingInstance">既存オブジェクト</param>
22+ protected override MMDModelPart Read(ContentReader input, MMDModelPart existingInstance)
23+ {
24+ //モデルパーツの読み込み
25+ int triangleCount = input.ReadInt32();
26+ MMDVertexNm[] Vertices = input.ReadObject<MMDVertexNm[]>();
27+ Dictionary<long, int[]> VertMap = input.ReadObject<Dictionary<long, int[]>>();
28+ IndexBuffer indexBuffer = input.ReadObject<IndexBuffer>();
29+
30+ // create the model part from this data
31+ Dictionary<string, object> OpaqueData = new Dictionary<string, object>();
32+ OpaqueData.Add("VertMap", VertMap);
33+ OpaqueData.Add("IndexBuffer", indexBuffer);
34+ MMDModelPart modelPart = null;
35+ modelPart = MMDXCore.Instance.ModelPartFactory.Create(triangleCount, Vertices, OpaqueData) as MMDModelPart;
36+ if (modelPart == null)
37+ {
38+ throw new ContentLoadException("MMDXCore.ModelPartFactoryがMMDModelPart以外を返すファクトリーになっています。XNAのコンテンツパイプラインを使用する場合はMMDModelPartを返すファクトリーをセットする必要があります");
39+ }
40+ // read in the BasicEffect as a shared resource
41+ input.ReadSharedResource<Effect>(fx => modelPart.Effect = fx);
42+
43+ return modelPart;
44+ }
45+ }
46+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDCPUModelPartFactory.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDCPUModelPartFactory.cs (revision 846)
@@ -0,0 +1,60 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework.Graphics;
6+using MikuMikuDance.Core.Model;
7+using MikuMikuDance.Core.Misc;
8+
9+namespace MikuMikuDance.XNA.Model
10+{
11+#if false//WP7対応時に復活
12+ class MMDModelPartCPUFactory : IMMDModelPartFactory
13+ {
14+ //ファクトリー関数
15+ public IMMDModelPart Create(int triangleCount, MMDVertex[] Vertices, Dictionary<string, object> OpaqueData)
16+ {
17+ IndexBuffer indexBuffer = null;
18+ if (OpaqueData.ContainsKey("IndexBuffer"))
19+ indexBuffer = OpaqueData["IndexBuffer"] as IndexBuffer;
20+ int[] VertMap = OpaqueData["VertMap"] as int[];
21+ if (indexBuffer == null)
22+ throw new ArgumentException("MMDModelPartFactoryのOpaqueDataには\"IndexBuffer\"キーとIndexBufferオブジェクトが必要です。", "OpaqueData");
23+ if (Vertices is MMDVertexNm[])
24+ {
25+ if (Vertices is MMDVertexNmTx[])
26+ {
27+ if (Vertices is MMDVertexNmTxVc[])
28+ return new MMDCPUModelPartPNmTxVc(triangleCount, (MMDVertexNmTxVc[])Vertices, VertMap, indexBuffer);
29+ else
30+ return new MMDCPUModelPartPNmTx(triangleCount, (MMDVertexNmTx[])Vertices, VertMap, indexBuffer);
31+ }
32+ else
33+ {
34+ if (Vertices is MMDVertexNmVc[])
35+ return new MMDCPUModelPartPNmVc(triangleCount, (MMDVertexNmVc[])Vertices, VertMap, indexBuffer);
36+ else
37+ return new MMDCPUModelPartPNm(triangleCount, (MMDVertexNm[])Vertices, VertMap, indexBuffer);
38+ }
39+ }
40+ else
41+ {
42+ if (Vertices is MMDVertexTx[])
43+ {
44+ if (Vertices is MMDVertexTxVc[])
45+ return new MMDCPUModelPartPTxVc(triangleCount, (MMDVertexTxVc[])Vertices, VertMap, indexBuffer);
46+ else
47+ return new MMDCPUModelPartPTx(triangleCount, (MMDVertexTx[])Vertices, VertMap, indexBuffer);
48+ }
49+ else
50+ {
51+ if (Vertices is MMDVertexVc[])
52+ return new MMDCPUModelPartPVc(triangleCount, (MMDVertexVc[])Vertices, VertMap, indexBuffer);
53+ else
54+ return new MMDCPUModelPartP(triangleCount, Vertices, VertMap, indexBuffer);
55+ }
56+ }
57+ }
58+ }
59+#endif
60+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPart.cs (revision 845)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDModelPart.cs (revision 846)
@@ -54,8 +54,12 @@
5454
5555 static BlendState ModelBlendState = BlendState.AlphaBlend;
5656 static BlendState EdgeBlendState = BlendState.Opaque;
57-
58- static void SetUpRenderState(MMDDrawingMode mode, GraphicsDevice GraphicsDevice)
57+ /// <summary>
58+ /// レンダリングモード設定
59+ /// </summary>
60+ /// <param name="mode">描画モード</param>
61+ /// <param name="GraphicsDevice">グラフィックデバイス</param>
62+ protected static void SetUpRenderState(MMDDrawingMode mode, GraphicsDevice GraphicsDevice)
5963 {
6064 switch (mode)
6165 {
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDXBoxModelPart.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDXBoxModelPart.cs (revision 846)
@@ -0,0 +1,343 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework;
6+using MikuMikuDance.Core.Model;
7+using MikuMikuDance.Core.Misc;
8+using Microsoft.Xna.Framework.Graphics;
9+using MikuMikuDance.XNA.Misc;
10+
11+namespace MikuMikuDance.XNA.Model
12+{
13+#if XBOX
14+ /// <summary>
15+ /// XBox用モデルパーツ(法線あり)
16+ /// </summary>
17+ public class MMDXBoxModelPartPNm : MMDModelPart
18+ {
19+ VertexPositionNormal[] mainVertices;
20+ VertexXBoxExtend[] extVertices;
21+ //箱ではこれらの頂点の変更は行わない
22+ VertexBuffer mainVertexBuffer;
23+ VertexBuffer externaiVertexBuffer;
24+
25+ VertexBufferBinding[] bindings = new VertexBufferBinding[2];
26+ /// <summary>
27+ /// コンストラクタ
28+ /// </summary>
29+ /// <param name="triangleCount">ポリゴン数</param>
30+ /// <param name="vertices">頂点データ</param>
31+ /// <param name="extvert">XBox用拡張頂点</param>
32+ /// <param name="indexBuffer">インデックスバッファ</param>
33+ public MMDXBoxModelPartPNm(int triangleCount, MMDVertexNm[] vertices, Vector2[] extvert, IndexBuffer indexBuffer)
34+ : base(triangleCount, vertices.Length, null, indexBuffer)
35+ {
36+ if (vertices.Length != extvert.Length)
37+ throw new MMDXException("標準頂点と拡張頂点の長さが一致しない");
38+ //頂点配列を作成
39+ mainVertices = new VertexPositionNormal[vertices.Length];
40+ extVertices = new VertexXBoxExtend[extvert.Length];
41+ //配列にデータを入れる
42+ for (int i = 0; i < mainVertices.Length; ++i)
43+ {
44+ mainVertices[i].Position = vertices[i].Position;
45+ mainVertices[i].Normal = vertices[i].Normal;
46+ extVertices[i].BlendIndices = new Vector2(vertices[i].BlendIndexX, vertices[i].BlendIndexY);
47+ extVertices[i].BlendWeight = vertices[i].BlendWeights;
48+ extVertices[i].FacePtr = extvert[i];
49+ }
50+ //頂点バッファ作成
51+ mainVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
52+ externaiVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexXBoxExtend), extVertices.Length, BufferUsage.WriteOnly);
53+ //頂点バッファにデータを流しこみ
54+ mainVertexBuffer.SetData(mainVertices);
55+ externaiVertexBuffer.SetData(extVertices);
56+ //頂点バッファをバインドしておく
57+ bindings[0] =new VertexBufferBinding(mainVertexBuffer);
58+ bindings[1] = new VertexBufferBinding(externaiVertexBuffer);
59+ }
60+ /// <summary>
61+ /// スキニング行列の適用
62+ /// </summary>
63+ /// <param name="skinTransforms">スキニング行列</param>
64+ public override void SetSkinMatrix(Matrix[] skinTransforms)
65+ {
66+
67+ }
68+ /// <summary>
69+ /// 表情の適用
70+ /// </summary>
71+ /// <param name="faceManager">表情マネージャ</param>
72+ public override void SetFace(IMMDFaceManager faceManager)
73+ {
74+
75+ }
76+ public override void Draw(MMDDrawingMode mode)
77+ {
78+ GraphicsDevice graphics = Effect.GraphicsDevice;
79+ //レンダーステートセットアップ
80+ SetUpRenderState(mode, graphics);
81+ //バッファセット
82+ graphics.Indices = indexBuffer;
83+ graphics.SetVertexBuffers(bindings);
84+
85+ foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
86+ {
87+ pass.Apply();
88+ graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, triangleCount);
89+ }
90+
91+ graphics.Indices = null;
92+ graphics.SetVertexBuffer(null);
93+ }
94+ }
95+ /// <summary>
96+ /// XBox用モデルパーツ(法線、頂点色あり)
97+ /// </summary>
98+ public class MMDXBoxModelPartPNmVc : MMDModelPart
99+ {
100+ VertexPositionNormalColor[] mainVertices;
101+ VertexXBoxExtend[] extVertices;
102+ //箱ではこれらの頂点の変更は行わない
103+ VertexBuffer mainVertexBuffer;
104+ VertexBuffer externaiVertexBuffer;
105+
106+ VertexBufferBinding[] bindings = new VertexBufferBinding[2];
107+ /// <summary>
108+ /// コンストラクタ
109+ /// </summary>
110+ /// <param name="triangleCount">ポリゴン数</param>
111+ /// <param name="vertices">頂点データ</param>
112+ /// <param name="extvert">XBox用拡張頂点</param>
113+ /// <param name="indexBuffer">インデックスバッファ</param>
114+ public MMDXBoxModelPartPNmVc(int triangleCount, MMDVertexNmVc[] vertices, Vector2[] extvert, IndexBuffer indexBuffer)
115+ : base(triangleCount, vertices.Length, null, indexBuffer)
116+ {
117+ if (vertices.Length != extvert.Length)
118+ throw new MMDXException("標準頂点と拡張頂点の長さが一致しない");
119+ //頂点配列を作成
120+ mainVertices = new VertexPositionNormalColor[vertices.Length];
121+ extVertices = new VertexXBoxExtend[extvert.Length];
122+ //配列にデータを入れる
123+ for (int i = 0; i < mainVertices.Length; ++i)
124+ {
125+ mainVertices[i].Position = vertices[i].Position;
126+ mainVertices[i].Normal = vertices[i].Normal;
127+ mainVertices[i].Color = new Color(vertices[i].VertexColor);
128+ extVertices[i].BlendIndices = new Vector2(vertices[i].BlendIndexX, vertices[i].BlendIndexY);
129+ extVertices[i].BlendWeight = vertices[i].BlendWeights;
130+ extVertices[i].FacePtr = extvert[i];
131+ }
132+ //頂点バッファ作成
133+ mainVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
134+ externaiVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexXBoxExtend), extVertices.Length, BufferUsage.WriteOnly);
135+ //頂点バッファにデータを流しこみ
136+ mainVertexBuffer.SetData(mainVertices);
137+ externaiVertexBuffer.SetData(extVertices);
138+ //頂点バッファをバインドしておく
139+ bindings[0] = new VertexBufferBinding(mainVertexBuffer);
140+ bindings[1] = new VertexBufferBinding(externaiVertexBuffer);
141+ }
142+ /// <summary>
143+ /// スキニング行列の適用
144+ /// </summary>
145+ /// <param name="skinTransforms">スキニング行列</param>
146+ public override void SetSkinMatrix(Matrix[] skinTransforms)
147+ {
148+
149+ }
150+ /// <summary>
151+ /// 表情の適用
152+ /// </summary>
153+ /// <param name="faceManager">表情マネージャ</param>
154+ public override void SetFace(IMMDFaceManager faceManager)
155+ {
156+
157+ }
158+ public override void Draw(MMDDrawingMode mode)
159+ {
160+ GraphicsDevice graphics = Effect.GraphicsDevice;
161+ //レンダーステートセットアップ
162+ SetUpRenderState(mode, graphics);
163+ //バッファセット
164+ graphics.Indices = indexBuffer;
165+ graphics.SetVertexBuffers(bindings);
166+
167+ foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
168+ {
169+ pass.Apply();
170+ graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, triangleCount);
171+ }
172+
173+ graphics.Indices = null;
174+ graphics.SetVertexBuffer(null);
175+ }
176+ }
177+ /// <summary>
178+ /// XBox用モデルパーツ(法線、テクスチャあり)
179+ /// </summary>
180+ public class MMDXBoxModelPartPNmTx : MMDModelPart
181+ {
182+ VertexPositionNormalTexture[] mainVertices;
183+ VertexXBoxExtend[] extVertices;
184+ //箱ではこれらの頂点の変更は行わない
185+ VertexBuffer mainVertexBuffer;
186+ VertexBuffer externaiVertexBuffer;
187+
188+ VertexBufferBinding[] bindings = new VertexBufferBinding[2];
189+ /// <summary>
190+ /// コンストラクタ
191+ /// </summary>
192+ /// <param name="triangleCount">ポリゴン数</param>
193+ /// <param name="vertices">頂点データ</param>
194+ /// <param name="extvert">XBox用拡張頂点</param>
195+ /// <param name="indexBuffer">インデックスバッファ</param>
196+ public MMDXBoxModelPartPNmTx(int triangleCount, MMDVertexNmTx[] vertices, Vector2[] extvert, IndexBuffer indexBuffer)
197+ : base(triangleCount, vertices.Length, null, indexBuffer)
198+ {
199+ if (vertices.Length != extvert.Length)
200+ throw new MMDXException("標準頂点と拡張頂点の長さが一致しない");
201+ //頂点配列を作成
202+ mainVertices = new VertexPositionNormalTexture[vertices.Length];
203+ extVertices = new VertexXBoxExtend[extvert.Length];
204+ //配列にデータを入れる
205+ for (int i = 0; i < mainVertices.Length; ++i)
206+ {
207+ mainVertices[i].Position = vertices[i].Position;
208+ mainVertices[i].Normal = vertices[i].Normal;
209+ mainVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
210+ extVertices[i].BlendIndices = new Vector2(vertices[i].BlendIndexX, vertices[i].BlendIndexY);
211+ extVertices[i].BlendWeight = vertices[i].BlendWeights;
212+ extVertices[i].FacePtr = extvert[i];
213+ }
214+ //頂点バッファ作成
215+ mainVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
216+ externaiVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexXBoxExtend), extVertices.Length, BufferUsage.WriteOnly);
217+ //頂点バッファにデータを流しこみ
218+ mainVertexBuffer.SetData(mainVertices);
219+ externaiVertexBuffer.SetData(extVertices);
220+ //頂点バッファをバインドしておく
221+ bindings[0] = new VertexBufferBinding(mainVertexBuffer);
222+ bindings[1] = new VertexBufferBinding(externaiVertexBuffer);
223+ }
224+ /// <summary>
225+ /// スキニング行列の適用
226+ /// </summary>
227+ /// <param name="skinTransforms">スキニング行列</param>
228+ public override void SetSkinMatrix(Matrix[] skinTransforms)
229+ {
230+
231+ }
232+ /// <summary>
233+ /// 表情の適用
234+ /// </summary>
235+ /// <param name="faceManager">表情マネージャ</param>
236+ public override void SetFace(IMMDFaceManager faceManager)
237+ {
238+
239+ }
240+ public override void Draw(MMDDrawingMode mode)
241+ {
242+ GraphicsDevice graphics = Effect.GraphicsDevice;
243+ //レンダーステートセットアップ
244+ SetUpRenderState(mode, graphics);
245+ //バッファセット
246+ graphics.Indices = indexBuffer;
247+ graphics.SetVertexBuffers(bindings);
248+
249+ foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
250+ {
251+ pass.Apply();
252+ graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, triangleCount);
253+ }
254+
255+ graphics.Indices = null;
256+ graphics.SetVertexBuffer(null);
257+ }
258+ }
259+ /// <summary>
260+ /// XBox用モデルパーツ(法線、頂点色、テクスチャあり)
261+ /// </summary>
262+ public class MMDXBoxModelPartPNmTxVc : MMDModelPart
263+ {
264+ VertexPositionNormalTextureColor[] mainVertices;
265+ VertexXBoxExtend[] extVertices;
266+ //箱ではこれらの頂点の変更は行わない
267+ VertexBuffer mainVertexBuffer;
268+ VertexBuffer externaiVertexBuffer;
269+
270+ VertexBufferBinding[] bindings = new VertexBufferBinding[2];
271+ /// <summary>
272+ /// コンストラクタ
273+ /// </summary>
274+ /// <param name="triangleCount">ポリゴン数</param>
275+ /// <param name="vertices">頂点データ</param>
276+ /// <param name="extvert">XBox用拡張頂点</param>
277+ /// <param name="indexBuffer">インデックスバッファ</param>
278+ public MMDXBoxModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, Vector2[] extvert, IndexBuffer indexBuffer)
279+ : base(triangleCount, vertices.Length, null, indexBuffer)
280+ {
281+ if (vertices.Length != extvert.Length)
282+ throw new MMDXException("標準頂点と拡張頂点の長さが一致しない");
283+ //頂点配列を作成
284+ mainVertices = new VertexPositionNormalTextureColor[vertices.Length];
285+ extVertices = new VertexXBoxExtend[extvert.Length];
286+ //配列にデータを入れる
287+ for (int i = 0; i < mainVertices.Length; ++i)
288+ {
289+ mainVertices[i].Position = vertices[i].Position;
290+ mainVertices[i].Normal = vertices[i].Normal;
291+ mainVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
292+ mainVertices[i].Color = new Color(vertices[i].VertexColor);
293+ extVertices[i].BlendIndices = new Vector2(vertices[i].BlendIndexX, vertices[i].BlendIndexY);
294+ extVertices[i].BlendWeight = vertices[i].BlendWeights;
295+ extVertices[i].FacePtr = extvert[i];
296+ }
297+ //頂点バッファ作成
298+ mainVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
299+ externaiVertexBuffer = new VertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexXBoxExtend), extVertices.Length, BufferUsage.WriteOnly);
300+ //頂点バッファにデータを流しこみ
301+ mainVertexBuffer.SetData(mainVertices);
302+ externaiVertexBuffer.SetData(extVertices);
303+ //頂点バッファをバインドしておく
304+ bindings[0] = new VertexBufferBinding(mainVertexBuffer);
305+ bindings[1] = new VertexBufferBinding(externaiVertexBuffer);
306+ }
307+ /// <summary>
308+ /// スキニング行列の適用
309+ /// </summary>
310+ /// <param name="skinTransforms">スキニング行列</param>
311+ public override void SetSkinMatrix(Matrix[] skinTransforms)
312+ {
313+
314+ }
315+ /// <summary>
316+ /// 表情の適用
317+ /// </summary>
318+ /// <param name="faceManager">表情マネージャ</param>
319+ public override void SetFace(IMMDFaceManager faceManager)
320+ {
321+
322+ }
323+ public override void Draw(MMDDrawingMode mode)
324+ {
325+ GraphicsDevice graphics = Effect.GraphicsDevice;
326+ //レンダーステートセットアップ
327+ SetUpRenderState(mode, graphics);
328+ //バッファセット
329+ graphics.Indices = indexBuffer;
330+ graphics.SetVertexBuffers(bindings);
331+
332+ foreach (EffectPass pass in Effect.CurrentTechnique.Passes)
333+ {
334+ pass.Apply();
335+ graphics.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, vertexCount, 0, triangleCount);
336+ }
337+
338+ graphics.Indices = null;
339+ graphics.SetVertexBuffer(null);
340+ }
341+ }
342+#endif
343+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPartFactory.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPartFactory.cs (revision 846)
@@ -0,0 +1,40 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework.Graphics;
6+using MikuMikuDance.Core.Model;
7+using MikuMikuDance.Core.Misc;
8+
9+namespace MikuMikuDance.XNA.Model
10+{
11+#if WINDOWS
12+ class MMDGPUModelPartFactory : IMMDModelPartFactory
13+ {
14+ //ファクトリー関数
15+ public IMMDModelPart Create(int triangleCount, MMDVertexNm[] Vertices, Dictionary<string, object> OpaqueData)
16+ {
17+ IndexBuffer indexBuffer = null;
18+ if (OpaqueData.ContainsKey("IndexBuffer"))
19+ indexBuffer = OpaqueData["IndexBuffer"] as IndexBuffer;
20+ Dictionary<long, int[]> VertMap = OpaqueData["VertMap"] as Dictionary<long, int[]>;
21+ if (indexBuffer == null)
22+ throw new ArgumentException("MMDModelPartGPUFactoryのOpaqueDataには\"IndexBuffer\"キーとIndexBufferオブジェクトが必要です。", "OpaqueData");
23+ if (Vertices is MMDVertexNmTx[])
24+ {
25+ if (Vertices is MMDVertexNmTxVc[])
26+ return new MMDGPUModelPartPNmTxVc(triangleCount, (MMDVertexNmTxVc[])Vertices, VertMap, indexBuffer);
27+ else
28+ return new MMDGPUModelPartPNmTx(triangleCount, (MMDVertexNmTx[])Vertices, VertMap, indexBuffer);
29+ }
30+ else
31+ {
32+ if (Vertices is MMDVertexNmVc[])
33+ return new MMDGPUModelPartPNmVc(triangleCount, (MMDVertexNmVc[])Vertices, VertMap, indexBuffer);
34+ else
35+ return new MMDGPUModelPartPNm(triangleCount, (MMDVertexNm[])Vertices, VertMap, indexBuffer);
36+ }
37+ }
38+ }
39+#endif
40+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDCPUModelPart.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDCPUModelPart.cs (revision 846)
@@ -0,0 +1,529 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework;
6+using Microsoft.Xna.Framework.Graphics;
7+using MikuMikuDance.Core.Model;
8+using MikuMikuDance.Core.Misc;
9+using MikuMikuDance.XNA.Misc;
10+
11+namespace MikuMikuDance.XNA.Model
12+{
13+#if false//CPUスキニング用。WP7対応とかするときに復活?
14+ /// <summary>
15+ /// モデルパーツ(頂点のみ)
16+ /// </summary>
17+ public class MMDCPUModelPartP : MMDModelPart
18+ {
19+ readonly VertexPosition[] gpuVertices;
20+ /// <summary>
21+ /// 頂点配列
22+ /// </summary>
23+ protected MMDVertex[] vertices;
24+
25+ /// <summary>
26+ /// コンストラクタ
27+ /// </summary>
28+ /// <param name="triangleCount">三角形の個数</param>
29+ /// <param name="vertices">頂点配列</param>
30+ /// <param name="indexBuffer">インデックスバッファ</param>
31+ public MMDCPUModelPartP(int triangleCount, MMDVertex[] vertices,int[] vertMap, IndexBuffer indexBuffer)
32+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
33+ {
34+ this.vertices = vertices;
35+ //GPUリソース作成
36+ gpuVertices = new VertexPosition[vertices.Length];
37+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPosition), vertices.Length, BufferUsage.WriteOnly);
38+ //初期値代入
39+ for (int i = 0; i < vertices.Length; i++)
40+ {
41+ gpuVertices[i].Position = vertices[i].Position;
42+ }
43+ // put the vertices into our vertex buffer
44+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
45+ }
46+ /// <summary>
47+ /// ボーンの設定
48+ /// </summary>
49+ /// <param name="bones">ボーン配列</param>
50+ public override void SetSkinMatrix(Matrix[] bones)
51+ {
52+ //頂点位置の計算
53+#if !XBOX
54+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
55+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position));
56+#else
57+ throw new NotImplementedException();
58+#endif
59+ /*for (int i = 0; i < vertices.Length; i++)
60+ {
61+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position);
62+ }*/
63+ //GPUバッファへの書き込み
64+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
65+ }
66+ /// <summary>
67+ /// 表情の設定
68+ /// </summary>
69+ /// <param name="faceManager"></param>
70+ public override void SetFace(MMDFaceManager faceManager)
71+ {
72+ faceManager.ApplyToVertex(vertices, VertMap);
73+ }
74+
75+ }
76+ /// <summary>
77+ /// モデルパーツ(頂点+色)
78+ /// </summary>
79+ public class MMDCPUModelPartPVc : MMDModelPart
80+ {
81+ readonly VertexPositionColor[] gpuVertices;
82+ /// <summary>
83+ /// 頂点配列
84+ /// </summary>
85+ protected MMDVertexVc[] vertices;
86+
87+ /// <summary>
88+ /// コンストラクタ
89+ /// </summary>
90+ /// <param name="triangleCount">三角形の個数</param>
91+ /// <param name="vertices">頂点配列</param>
92+ /// <param name="indexBuffer">インデックスバッファ</param>
93+ public MMDCPUModelPartPVc(int triangleCount, MMDVertexVc[] vertices, int[] vertMap, IndexBuffer indexBuffer)
94+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
95+ {
96+ this.vertices = vertices;
97+ //GPUリソース作成
98+ gpuVertices = new VertexPositionColor[vertices.Length];
99+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionColor), vertices.Length, BufferUsage.WriteOnly);
100+ //初期値代入
101+ for (int i = 0; i < vertices.Length; i++)
102+ {
103+ gpuVertices[i].Position = vertices[i].Position;
104+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
105+ }
106+ // put the vertices into our vertex buffer
107+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
108+ }
109+ /// <summary>
110+ /// ボーンの設定
111+ /// </summary>
112+ /// <param name="bones">ボーン配列</param>
113+ public override void SetSkinMatrix(Matrix[] bones)
114+ {
115+#if !XBOX
116+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
117+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position));
118+#else
119+ throw new NotImplementedException();
120+#endif
121+ //頂点位置の計算
122+ /*for (int i = 0; i < vertices.Length; i++)
123+ {
124+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position);
125+ }*/
126+ //GPUバッファへの書き込み
127+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
128+ }
129+ /// <summary>
130+ /// 表情の設定
131+ /// </summary>
132+ /// <param name="faceManager"></param>
133+ public override void SetFace(MMDFaceManager faceManager)
134+ {
135+ faceManager.ApplyToVertex(vertices, VertMap);
136+ }
137+
138+ }
139+ /// <summary>
140+ /// モデルパーツ(頂点+法線)
141+ /// </summary>
142+ public class MMDCPUModelPartPNm : MMDModelPart
143+ {//スフィアマップだけ貼りつけている物はこれになる……
144+ readonly VertexPositionNormal[] gpuVertices;
145+ /// <summary>
146+ /// 頂点配列
147+ /// </summary>
148+ protected MMDVertexNm[] vertices;
149+
150+ /// <summary>
151+ /// コンストラクタ
152+ /// </summary>
153+ /// <param name="triangleCount">三角形の個数</param>
154+ /// <param name="vertices">頂点配列</param>
155+ /// <param name="indexBuffer">インデックスバッファ</param>
156+ public MMDCPUModelPartPNm(int triangleCount, MMDVertexNm[] vertices, int[] vertMap, IndexBuffer indexBuffer)
157+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
158+ {
159+ this.vertices = vertices;
160+ //GPUリソース作成
161+ gpuVertices = new VertexPositionNormal[vertices.Length];
162+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
163+ //初期値代入
164+ for (int i = 0; i < vertices.Length; i++)
165+ {
166+ gpuVertices[i].Position = vertices[i].Position;
167+ gpuVertices[i].Normal = vertices[i].Normal;
168+ }
169+ // put the vertices into our vertex buffer
170+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
171+ }
172+ /// <summary>
173+ /// ボーンの設定
174+ /// </summary>
175+ /// <param name="bones">ボーン配列</param>
176+ public override void SetSkinMatrix(Matrix[] bones)
177+ {
178+#if !XBOX
179+ //頂点と法線位置の計算
180+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
181+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
182+#else
183+ throw new NotImplementedException();
184+#endif
185+
186+ /*for (int i = 0; i < vertices.Length; i++)
187+ {
188+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal);
189+ }*/
190+ //GPUバッファへの書き込み
191+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
192+ }
193+ /// <summary>
194+ /// 表情の設定
195+ /// </summary>
196+ /// <param name="faceManager"></param>
197+ public override void SetFace(MMDFaceManager faceManager)
198+ {
199+ faceManager.ApplyToVertex(vertices, VertMap);
200+ }
201+
202+ }
203+ /// <summary>
204+ /// モデルパーツ(頂点+テクスチャー)
205+ /// </summary>
206+ public class MMDCPUModelPartPTx : MMDModelPart
207+ {
208+ readonly VertexPositionTexture[] gpuVertices;
209+ /// <summary>
210+ /// 頂点配列
211+ /// </summary>
212+ protected MMDVertexTx[] vertices;
213+
214+ /// <summary>
215+ /// コンストラクタ
216+ /// </summary>
217+ /// <param name="triangleCount">三角形の個数</param>
218+ /// <param name="vertices">頂点配列</param>
219+ /// <param name="indexBuffer">インデックスバッファ</param>
220+ public MMDCPUModelPartPTx(int triangleCount, MMDVertexTx[] vertices, int[] vertMap, IndexBuffer indexBuffer)
221+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
222+ {
223+ this.vertices = vertices;
224+ //GPUリソース作成
225+ gpuVertices = new VertexPositionTexture[vertices.Length];
226+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionTexture), vertices.Length, BufferUsage.WriteOnly);
227+ //初期値代入
228+ for (int i = 0; i < vertices.Length; i++)
229+ {
230+ gpuVertices[i].Position = vertices[i].Position;
231+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
232+ }
233+ // put the vertices into our vertex buffer
234+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
235+ }
236+ /// <summary>
237+ /// ボーンの設定
238+ /// </summary>
239+ /// <param name="bones">ボーン配列</param>
240+ public override void SetSkinMatrix(Matrix[] bones)
241+ {
242+#if !XBOX
243+ //頂点位置の計算
244+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
245+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position));
246+#else
247+ throw new NotImplementedException();
248+#endif
249+
250+ /*for (int i = 0; i < vertices.Length; i++)
251+ {
252+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position);
253+ }*/
254+ //GPUバッファへの書き込み
255+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
256+ }
257+ /// <summary>
258+ /// 表情の設定
259+ /// </summary>
260+ /// <param name="faceManager"></param>
261+ public override void SetFace(MMDFaceManager faceManager)
262+ {
263+ faceManager.ApplyToVertex(vertices, VertMap);
264+ }
265+
266+ }
267+
268+ /// <summary>
269+ /// モデルパーツ(頂点+法線+色)
270+ /// </summary>
271+ public class MMDCPUModelPartPNmVc : MMDModelPart
272+ {
273+ readonly VertexPositionNormalColor[] gpuVertices;
274+ /// <summary>
275+ /// 頂点配列
276+ /// </summary>
277+ protected MMDVertexNmVc[] vertices;
278+
279+ /// <summary>
280+ /// コンストラクタ
281+ /// </summary>
282+ /// <param name="triangleCount">三角形の個数</param>
283+ /// <param name="vertices">頂点配列</param>
284+ /// <param name="indexBuffer">インデックスバッファ</param>
285+ public MMDCPUModelPartPNmVc(int triangleCount, MMDVertexNmVc[] vertices, int[] vertMap, IndexBuffer indexBuffer)
286+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
287+ {
288+ this.vertices = vertices;
289+ //GPUリソース作成
290+ gpuVertices = new VertexPositionNormalColor[vertices.Length];
291+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalColor), vertices.Length, BufferUsage.WriteOnly);
292+ //初期値代入
293+ for (int i = 0; i < vertices.Length; i++)
294+ {
295+ gpuVertices[i].Position = vertices[i].Position;
296+ gpuVertices[i].Normal = vertices[i].Normal;
297+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
298+ }
299+ // put the vertices into our vertex buffer
300+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
301+ }
302+ /// <summary>
303+ /// ボーンの設定
304+ /// </summary>
305+ /// <param name="bones">ボーン配列</param>
306+ public override void SetSkinMatrix(Matrix[] bones)
307+ {
308+#if !XBOX
309+ //頂点と法線位置の計算
310+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
311+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
312+#else
313+ throw new NotImplementedException();
314+#endif
315+
316+ /*for (int i = 0; i < vertices.Length; i++)
317+ {
318+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal);
319+ }*/
320+ //GPUバッファへの書き込み
321+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
322+ }
323+ /// <summary>
324+ /// 表情の設定
325+ /// </summary>
326+ /// <param name="faceManager"></param>
327+ public override void SetFace(MMDFaceManager faceManager)
328+ {
329+ faceManager.ApplyToVertex(vertices, VertMap);
330+ }
331+
332+ }
333+ /// <summary>
334+ /// モデルパーツ(頂点+テクスチャー+カラー)
335+ /// </summary>
336+ public class MMDCPUModelPartPTxVc : MMDModelPart
337+ {
338+ readonly VertexPositionColorTexture[] gpuVertices;
339+ /// <summary>
340+ /// 頂点配列
341+ /// </summary>
342+ protected MMDVertexTxVc[] vertices;
343+
344+ /// <summary>
345+ /// コンストラクタ
346+ /// </summary>
347+ /// <param name="triangleCount">三角形の個数</param>
348+ /// <param name="vertices">頂点配列</param>
349+ /// <param name="indexBuffer">インデックスバッファ</param>
350+ public MMDCPUModelPartPTxVc(int triangleCount, MMDVertexTxVc[] vertices, int[] vertMap, IndexBuffer indexBuffer)
351+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
352+ {
353+ this.vertices = vertices;
354+ //GPUリソース作成
355+ gpuVertices = new VertexPositionColorTexture[vertices.Length];
356+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionColorTexture), vertices.Length, BufferUsage.WriteOnly);
357+ //初期値代入
358+ for (int i = 0; i < vertices.Length; i++)
359+ {
360+ gpuVertices[i].Position = vertices[i].Position;
361+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
362+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
363+ }
364+ // put the vertices into our vertex buffer
365+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
366+ }
367+ /// <summary>
368+ /// ボーンの設定
369+ /// </summary>
370+ /// <param name="bones">ボーン配列</param>
371+ public override void SetSkinMatrix(Matrix[] bones)
372+ {
373+#if !XBOX
374+ //頂点位置の計算
375+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
376+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position));
377+#else
378+ throw new NotImplementedException();
379+#endif
380+
381+ /*for (int i = 0; i < vertices.Length; i++)
382+ {
383+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position);
384+ }*/
385+ //GPUバッファへの書き込み
386+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
387+ }
388+ /// <summary>
389+ /// 表情の設定
390+ /// </summary>
391+ /// <param name="faceManager"></param>
392+ public override void SetFace(MMDFaceManager faceManager)
393+ {
394+ faceManager.ApplyToVertex(vertices, VertMap);
395+ }
396+
397+ }
398+ /// <summary>
399+ /// モデルパーツ(頂点+法線+テクスチャー)
400+ /// </summary>
401+ public class MMDCPUModelPartPNmTx : MMDModelPart
402+ {
403+ readonly VertexPositionNormalTexture[] gpuVertices;
404+ /// <summary>
405+ /// 頂点配列
406+ /// </summary>
407+ protected MMDVertexNmTx[] vertices;
408+
409+ /// <summary>
410+ /// コンストラクタ
411+ /// </summary>
412+ /// <param name="triangleCount">三角形の個数</param>
413+ /// <param name="vertices">頂点配列</param>
414+ /// <param name="indexBuffer">インデックスバッファ</param>
415+ public MMDCPUModelPartPNmTx(int triangleCount, MMDVertexNmTx[] vertices, int[] vertMap, IndexBuffer indexBuffer)
416+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
417+ {
418+ this.vertices = vertices;
419+ //GPUリソース作成
420+ gpuVertices = new VertexPositionNormalTexture[vertices.Length];
421+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.WriteOnly);
422+ //初期値代入
423+ for (int i = 0; i < vertices.Length; i++)
424+ {
425+ gpuVertices[i].Position = vertices[i].Position;
426+ gpuVertices[i].Normal = vertices[i].Normal;
427+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
428+ }
429+ // put the vertices into our vertex buffer
430+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
431+ }
432+ /// <summary>
433+ /// ボーンの設定
434+ /// </summary>
435+ /// <param name="bones">ボーン配列</param>
436+ public override void SetSkinMatrix(Matrix[] bones)
437+ {
438+#if !XBOX
439+ //頂点と法線位置の計算
440+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
441+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
442+#else
443+ throw new NotImplementedException();
444+#endif
445+ /*for (int i = 0; i < vertices.Length; i++)
446+ {
447+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal);
448+ }*/
449+ //GPUバッファへの書き込み
450+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
451+ }
452+ /// <summary>
453+ /// 表情の設定
454+ /// </summary>
455+ /// <param name="faceManager"></param>
456+ public override void SetFace(MMDFaceManager faceManager)
457+ {
458+ faceManager.ApplyToVertex(vertices, VertMap);
459+ }
460+
461+ }
462+ /// <summary>
463+ /// モデルパーツ(頂点+法線+テクスチャー+カラー)
464+ /// </summary>
465+ public class MMDCPUModelPartPNmTxVc : MMDModelPart
466+ {
467+ readonly VertexPositionNormalTextureColor[] gpuVertices;
468+ /// <summary>
469+ /// 頂点配列
470+ /// </summary>
471+ protected MMDVertexNmTxVc[] vertices;
472+
473+ /// <summary>
474+ /// コンストラクタ
475+ /// </summary>
476+ /// <param name="triangleCount">三角形の個数</param>
477+ /// <param name="vertices">頂点配列</param>
478+ /// <param name="indexBuffer">インデックスバッファ</param>
479+ public MMDCPUModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, int[] vertMap, IndexBuffer indexBuffer)
480+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
481+ {
482+ this.vertices = vertices;
483+ //GPUリソース作成
484+ gpuVertices = new VertexPositionNormalTextureColor[vertices.Length];
485+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalTextureColor), vertices.Length, BufferUsage.WriteOnly);
486+ //初期値代入
487+ for (int i = 0; i < vertices.Length; i++)
488+ {
489+ gpuVertices[i].Position = vertices[i].Position;
490+ gpuVertices[i].Normal = vertices[i].Normal;
491+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
492+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
493+ }
494+ // put the vertices into our vertex buffer
495+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
496+ }
497+ /// <summary>
498+ /// ボーンの設定
499+ /// </summary>
500+ /// <param name="bones">ボーン配列</param>
501+ public override void SetSkinMatrix(Matrix[] bones)
502+ {
503+#if !XBOX
504+ //頂点と法線位置の計算
505+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
506+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
507+#else
508+ throw new NotImplementedException();
509+#endif
510+
511+ /*for (int i = 0; i < vertices.Length; i++)
512+ {
513+ SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal);
514+ }*/
515+ //GPUバッファへの書き込み
516+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
517+ }
518+ /// <summary>
519+ /// 表情の設定
520+ /// </summary>
521+ /// <param name="faceManager"></param>
522+ public override void SetFace(MMDFaceManager faceManager)
523+ {
524+ faceManager.ApplyToVertex(vertices, VertMap);
525+ }
526+
527+ }
528+#endif
529+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPart.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDGPUModelPart.cs (revision 846)
@@ -0,0 +1,244 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using Microsoft.Xna.Framework;
6+using Microsoft.Xna.Framework.Graphics;
7+using MikuMikuDance.Core.Model;
8+using MikuMikuDance.Core.Misc;
9+using MikuMikuDance.XNA.Misc;
10+
11+namespace MikuMikuDance.XNA.Model
12+{
13+#if WINDOWS
14+ /// <summary>
15+ /// モデルパーツ(頂点+法線)
16+ /// </summary>
17+ public class MMDGPUModelPartPNm : MMDModelPart
18+ {//スフィアマップだけ貼りつけている物はこれになる……
19+ readonly VertexPositionNormal[] gpuVertices;
20+ /// <summary>
21+ /// 頂点配列
22+ /// </summary>
23+ protected MMDVertexNm[] vertices;
24+
25+ /// <summary>
26+ /// コンストラクタ
27+ /// </summary>
28+ /// <param name="triangleCount">三角形の個数</param>
29+ /// <param name="vertices">頂点配列</param>
30+ /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param>
31+ /// <param name="indexBuffer">インデックスバッファ</param>
32+ public MMDGPUModelPartPNm(int triangleCount, MMDVertexNm[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer)
33+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
34+ {
35+ this.vertices = vertices;
36+ //GPUリソース作成
37+ gpuVertices = new VertexPositionNormal[vertices.Length];
38+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormal), vertices.Length, BufferUsage.WriteOnly);
39+ //初期値代入
40+ for (int i = 0; i < vertices.Length; i++)
41+ {
42+ gpuVertices[i].Position = vertices[i].Position;
43+ gpuVertices[i].Normal = vertices[i].Normal;
44+ }
45+ // put the vertices into our vertex buffer
46+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
47+ }
48+ /// <summary>
49+ /// ボーンの設定
50+ /// </summary>
51+ /// <param name="bones">ボーン配列</param>
52+ public override void SetSkinMatrix(Matrix[] bones)
53+ {
54+ //頂点と法線位置の計算
55+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
56+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
57+ //GPUバッファへの書き込み
58+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
59+ }
60+ /// <summary>
61+ /// 表情の設定
62+ /// </summary>
63+ /// <param name="faceManager"></param>
64+ public override void SetFace(IMMDFaceManager faceManager)
65+ {
66+ MMDFaceManager.ApplyToVertex((MMDFaceManager)faceManager,vertices, VertMap);
67+ }
68+
69+ }
70+
71+ /// <summary>
72+ /// モデルパーツ(頂点+法線+色)
73+ /// </summary>
74+ public class MMDGPUModelPartPNmVc : MMDModelPart
75+ {
76+ readonly VertexPositionNormalColor[] gpuVertices;
77+ /// <summary>
78+ /// 頂点配列
79+ /// </summary>
80+ protected MMDVertexNmVc[] vertices;
81+
82+ /// <summary>
83+ /// コンストラクタ
84+ /// </summary>
85+ /// <param name="triangleCount">三角形の個数</param>
86+ /// <param name="vertices">頂点配列</param>
87+ /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param>
88+ /// <param name="indexBuffer">インデックスバッファ</param>
89+ public MMDGPUModelPartPNmVc(int triangleCount, MMDVertexNmVc[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer)
90+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
91+ {
92+ this.vertices = vertices;
93+ //GPUリソース作成
94+ gpuVertices = new VertexPositionNormalColor[vertices.Length];
95+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalColor), vertices.Length, BufferUsage.WriteOnly);
96+ //初期値代入
97+ for (int i = 0; i < vertices.Length; i++)
98+ {
99+ gpuVertices[i].Position = vertices[i].Position;
100+ gpuVertices[i].Normal = vertices[i].Normal;
101+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
102+ }
103+ // put the vertices into our vertex buffer
104+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
105+ }
106+ /// <summary>
107+ /// ボーンの設定
108+ /// </summary>
109+ /// <param name="bones">ボーン配列</param>
110+ public override void SetSkinMatrix(Matrix[] bones)
111+ {
112+ //頂点と法線位置の計算
113+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
114+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
115+ //GPUバッファへの書き込み
116+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
117+ }
118+ /// <summary>
119+ /// 表情の設定
120+ /// </summary>
121+ /// <param name="faceManager"></param>
122+ public override void SetFace(IMMDFaceManager faceManager)
123+ {
124+ MMDFaceManager.ApplyToVertex((MMDFaceManager)faceManager, vertices, VertMap);
125+ }
126+
127+ }
128+ /// <summary>
129+ /// モデルパーツ(頂点+法線+テクスチャー)
130+ /// </summary>
131+ public class MMDGPUModelPartPNmTx : MMDModelPart
132+ {
133+ readonly VertexPositionNormalTexture[] gpuVertices;
134+ /// <summary>
135+ /// 頂点配列
136+ /// </summary>
137+ protected MMDVertexNmTx[] vertices;
138+
139+ /// <summary>
140+ /// コンストラクタ
141+ /// </summary>
142+ /// <param name="triangleCount">三角形の個数</param>
143+ /// <param name="vertices">頂点配列</param>
144+ /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param>
145+ /// <param name="indexBuffer">インデックスバッファ</param>
146+ public MMDGPUModelPartPNmTx(int triangleCount, MMDVertexNmTx[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer)
147+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
148+ {
149+ this.vertices = vertices;
150+ //GPUリソース作成
151+ gpuVertices = new VertexPositionNormalTexture[vertices.Length];
152+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalTexture), vertices.Length, BufferUsage.WriteOnly);
153+ //初期値代入
154+ for (int i = 0; i < vertices.Length; i++)
155+ {
156+ gpuVertices[i].Position = vertices[i].Position;
157+ gpuVertices[i].Normal = vertices[i].Normal;
158+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
159+ }
160+ // put the vertices into our vertex buffer
161+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
162+ }
163+ /// <summary>
164+ /// ボーンの設定
165+ /// </summary>
166+ /// <param name="bones">ボーン配列</param>
167+ public override void SetSkinMatrix(Matrix[] bones)
168+ {
169+ //頂点と法線位置の計算
170+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
171+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
172+ //GPUバッファへの書き込み
173+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
174+ }
175+ /// <summary>
176+ /// 表情の設定
177+ /// </summary>
178+ /// <param name="faceManager"></param>
179+ public override void SetFace(IMMDFaceManager faceManager)
180+ {
181+ MMDFaceManager.ApplyToVertex((MMDFaceManager)faceManager, vertices, VertMap);
182+ }
183+
184+ }
185+ /// <summary>
186+ /// モデルパーツ(頂点+法線+テクスチャー+カラー)
187+ /// </summary>
188+ public class MMDGPUModelPartPNmTxVc : MMDModelPart
189+ {
190+ readonly VertexPositionNormalTextureColor[] gpuVertices;
191+ /// <summary>
192+ /// 頂点配列
193+ /// </summary>
194+ protected MMDVertexNmTxVc[] vertices;
195+
196+ /// <summary>
197+ /// コンストラクタ
198+ /// </summary>
199+ /// <param name="triangleCount">三角形の個数</param>
200+ /// <param name="vertices">頂点配列</param>
201+ /// <param name="vertMap">モデルの頂点とMMDの頂点対応</param>
202+ /// <param name="indexBuffer">インデックスバッファ</param>
203+ public MMDGPUModelPartPNmTxVc(int triangleCount, MMDVertexNmTxVc[] vertices, Dictionary<long, int[]> vertMap, IndexBuffer indexBuffer)
204+ : base(triangleCount, vertices.Length, vertMap, indexBuffer)
205+ {
206+ this.vertices = vertices;
207+ //GPUリソース作成
208+ gpuVertices = new VertexPositionNormalTextureColor[vertices.Length];
209+ vertexBuffer = new DynamicVertexBuffer(indexBuffer.GraphicsDevice, typeof(VertexPositionNormalTextureColor), vertices.Length, BufferUsage.WriteOnly);
210+ //初期値代入
211+ for (int i = 0; i < vertices.Length; i++)
212+ {
213+ gpuVertices[i].Position = vertices[i].Position;
214+ gpuVertices[i].Normal = vertices[i].Normal;
215+ gpuVertices[i].Color = new Color(vertices[i].VertexColor);
216+ gpuVertices[i].TextureCoordinate = vertices[i].TextureCoordinate;
217+ }
218+ // put the vertices into our vertex buffer
219+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
220+ }
221+ /// <summary>
222+ /// ボーンの設定
223+ /// </summary>
224+ /// <param name="bones">ボーン配列</param>
225+ public override void SetSkinMatrix(Matrix[] bones)
226+ {
227+ //頂点と法線位置の計算
228+ System.Threading.Tasks.Parallel.For(0, vertices.Length,
229+ (i) => SkinningHelpers.SkinVertex(bones, vertices[i], out gpuVertices[i].Position, out gpuVertices[i].Normal));
230+ //GPUバッファへの書き込み
231+ vertexBuffer.SetData(gpuVertices, 0, vertexCount, SetDataOptions.Discard);
232+ }
233+ /// <summary>
234+ /// 表情の設定
235+ /// </summary>
236+ /// <param name="faceManager"></param>
237+ public override void SetFace(IMMDFaceManager faceManager)
238+ {
239+ MMDFaceManager.ApplyToVertex((MMDFaceManager)faceManager, vertices, VertMap);
240+ }
241+
242+ }
243+#endif
244+}
--- branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 845)
+++ branches/XNA4/MikuMikuDanceXNA/MMDXCore.cs (revision 846)
@@ -42,9 +42,9 @@
4242 : base()
4343 {
4444 #if WINDOWS
45- ModelPartFactory = new MMDModelPartGPUFactory();
45+ ModelPartFactory = new MMDGPUModelPartFactory();
4646 #elif XBOX
47- ModelPartFactory = new MMDModelPartXBoxFactory();
47+ ModelPartFactory = new MMDXBoxModelPartFactory();
4848 #else
4949 throw new NotImplementedException();
5050 #endif
--- branches/XNA4/MikuMikuDanceXNA/Misc/VertexDeclarations.cs (revision 845)
+++ branches/XNA4/MikuMikuDanceXNA/Misc/VertexDeclarations.cs (revision 846)
@@ -4,9 +4,11 @@
44 using System.Text;
55 using Microsoft.Xna.Framework.Graphics;
66 using Microsoft.Xna.Framework;
7+using System.Runtime.InteropServices;
78
89 namespace MikuMikuDance.XNA.Misc
910 {
11+ [StructLayout(LayoutKind.Sequential)]
1012 struct VertexPositionNormal : IVertexType
1113 {
1214
@@ -19,6 +21,7 @@
1921 );
2022 public VertexDeclaration VertexDeclaration { get { return vertexDeclaration; } }
2123 }
24+ [StructLayout(LayoutKind.Sequential)]
2225 struct VertexPositionNormalColor : IVertexType
2326 {
2427
@@ -33,6 +36,7 @@
3336 );
3437 public VertexDeclaration VertexDeclaration { get { return vertexDeclaration; } }
3538 }
39+ [StructLayout(LayoutKind.Sequential)]
3640 struct VertexPositionNormalTextureColor : IVertexType
3741 {
3842
@@ -49,4 +53,18 @@
4953 );
5054 public VertexDeclaration VertexDeclaration { get { return vertexDeclaration; } }
5155 }
56+ [StructLayout(LayoutKind.Sequential)]
57+ struct VertexXBoxExtend : IVertexType
58+ {
59+ public Vector2 FacePtr;
60+ public Vector2 BlendIndices;
61+ public Vector2 BlendWeight;
62+ public readonly static VertexDeclaration vertexDeclaration = new VertexDeclaration
63+ (
64+ new VertexElement(0, VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 1),
65+ new VertexElement(sizeof(float) * 2, VertexElementFormat.Vector2, VertexElementUsage.BlendIndices, 0),
66+ new VertexElement(sizeof(float) * 4, VertexElementFormat.Vector2, VertexElementUsage.BlendWeight, 0)
67+ );
68+ public VertexDeclaration VertexDeclaration { get { return vertexDeclaration; } }
69+ }
5270 }
--- branches/XNA4/MMDPipeline/Model/MMDModelPartContentWriter.cs (revision 845)
+++ branches/XNA4/MMDPipeline/Model/MMDModelPartContentWriter.cs (revision 846)
@@ -42,7 +42,7 @@
4242 public override string GetRuntimeReader(TargetPlatform targetPlatform)
4343 {
4444 // MMDX側でのタイプライターを指定
45- return "MikuMikuDance.XNA.Model.MMDModelPartReader, MikuMikuDanceXNA";
45+ return "MikuMikuDance.XNA.Model.MMDGPUModelPartReader, MikuMikuDanceXNA";
4646 }
4747 }
4848 }
Show on old repository browser