• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision73 (tree)
Zeit2010-03-21 15:03:32
Autorwilfrem

Log Message

高速化に成功。TimeRularがバグってるので正確な時間分からないが、どうも2体分ぐらい出す余裕まで出来たっぽい

Ändern Zusammenfassung

Diff

--- trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 73)
@@ -22,8 +22,8 @@
2222
2323 internal MMDModel Model { get; set; }
2424 Dictionary<string, int> BoneDic;
25- Quaternion[] skinRots = null;//GetSkinRotation用の配列保持用。XBoxのGC回避のため
26- Vector4[] skinTranses = null;//GetSkinTransration用の配列保持用。XBoxのGC回避のため
25+ internal Quaternion[] skinRots = null;//GetSkinRotation用の配列保持用。XBoxのGC回避のため
26+ internal Vector4[] skinTranses = null;//GetSkinTransration用の配列保持用。XBoxのGC回避のため
2727 List<int> underIKs = new List<int>(20);//SolveIKのデータ計算用。XBoxのGC回避のため
2828
2929 internal MMDBoneManager CloneForBake()
@@ -169,35 +169,18 @@
169169 /// </summary>
170170 internal void UpdateSkinTransforms()
171171 {
172+ if (skinRots == null || skinRots.Length != Count
173+ || skinTranses == null || skinTranses.Length != Count)
174+ Refresh();
172175 for (int bone = 0; bone < Count; bone++)
173176 {
174177 QuatTransform xform =
175178 this[bone].BoneData.InverseBindPose * this[bone].WorldTransform;
176179
177- this[bone].SkinRotation = xform.Rotation;
178- this[bone].SkinTranslation = new Vector4(xform.Translation.X, xform.Translation.Y, xform.Translation.Z, this[bone].SkinTranslation.W);
180+ skinRots[bone] = xform.Rotation;
181+ skinTranses[bone] = new Vector4(xform.Translation.X, xform.Translation.Y, xform.Translation.Z, skinTranses[bone].W);
179182 }
180183 }
181- internal Quaternion[] GetSkinRotation()
182- {
183- if (skinRots == null || skinRots.Length != Count)
184- Refresh();
185- for (int bone = 0; bone < Count; bone++)
186- {
187- skinRots[bone] = this[bone].SkinRotation;
188- }
189- return skinRots;
190- }
191- internal Vector4[] GetSkinTranslation()
192- {
193- if (skinTranses == null || skinTranses.Length != Count)
194- Refresh();
195- for (int bone = 0; bone < Count; bone++)
196- {
197- skinTranses[bone] = this[bone].SkinTranslation;
198- }
199- return skinTranses;
200- }
201184 private void Refresh()
202185 {
203186 skinRots = new Quaternion[Count];
--- trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 73)
@@ -77,7 +77,7 @@
7777 FaceManager = new MMDFaceManager(this);
7878 Player = new AnimationPlayer(this);
7979 // 頂点テクスチャの生成
80- int width = BoneManager.GetSkinRotation().Length;
80+ int width = BoneManager.skinRots.Length;
8181 int height = 1;
8282
8383 rotationTexture = new FlipTexture2D(graphics, width, height, 1,
@@ -85,7 +85,7 @@
8585
8686 translationTexture = new FlipTexture2D(graphics, width, height, 1,
8787 TextureUsage.Linear, SurfaceFormat.Vector4);
88- faceTexture = new FlipTexture2D(graphics, FaceManager.GetFaceTranslation().Length, height, 1,
88+ faceTexture = new FlipTexture2D(graphics, FaceManager.FaceTranslations.Length, height, 1,
8989 TextureUsage.Linear, SurfaceFormat.Vector4);
9090
9191 //エッジ描画用のバッファ作成
@@ -174,10 +174,15 @@
174174 }
175175 #endif
176176 BoneManager.Update();
177+ if (mmdXNA.TimeRular != null && UseTimeRular)
178+ {
179+ mmdXNA.TimeRular.EndMark(1, "BoneManager");
180+ mmdXNA.TimeRular.BeginMark(1, "FaceManager", Color.Cyan);
181+ }
177182 FaceManager.Update();
178183 #if TRACE
179184 if (mmdXNA.TimeRular != null && UseTimeRular)
180- mmdXNA.TimeRular.EndMark(1, "BoneManager");
185+ mmdXNA.TimeRular.EndMark(1, "FaceManager");
181186 #endif
182187 if (mmdXNA.UsePhysic)
183188 physics.Update();
@@ -229,13 +234,19 @@
229234
230235 }
231236
232-
237+ /*public bool Break = false;
238+ System.Diagnostics.Stopwatch debug = new System.Diagnostics.Stopwatch();
239+ double Start = 0;*/
240+
233241 private void ModelDraw(GraphicsDevice graphics, string EffectTechniqueName)
234242 {
235-#if TRACE
236- if (mmdXNA.TimeRular != null && UseTimeRular)
237- mmdXNA.TimeRular.BeginMark(1, "ModelDraw-Prepare", Color.PaleGreen);
238-#endif
243+ //prepare処理 2.8294ms
244+ /*if (!debug.IsRunning)
245+ debug.Start();
246+ if (Break)
247+ {
248+ Start = debug.Elapsed.TotalMilliseconds;
249+ }*/
239250 //ビューとプロジェクション取得
240251 Matrix view = mmdXNA.Camera.GetViewMatrix();
241252 Matrix projection = mmdXNA.Camera.GetProjectionMatrix(graphics);
@@ -245,12 +256,11 @@
245256 faceTexture.Flip();
246257
247258 //スキンアニメーション用テクスチャ
248- rotationTexture.Texture.SetData<Quaternion>(BoneManager.GetSkinRotation());
249- translationTexture.Texture.SetData<Vector4>(BoneManager.GetSkinTranslation());
259+ rotationTexture.Texture.SetData<Quaternion>(BoneManager.skinRots);
260+ translationTexture.Texture.SetData<Vector4>(BoneManager.skinTranses);
250261 //フェイステクスチャ
251- //TODO: GetFaceTranslationがボトルネック。
252- faceTexture.Texture.SetData<Vector4>(FaceManager.GetFaceTranslation());
253-
262+ faceTexture.Texture.SetData<Vector4>(FaceManager.FaceTranslations);
263+
254264 //ライティング設定の取得
255265 Vector3 LightVector, LightColor;
256266 mmdXNA.LightManager.GetParameters(out LightVector, out LightColor);
@@ -258,24 +268,24 @@
258268 CullMode mode = graphics.RenderState.CullMode;
259269 graphics.RenderState.CullMode = CullMode.None;
260270
261-#if TRACE
262- if (mmdXNA.TimeRular != null && UseTimeRular)
271+ /*if (Break)
263272 {
264- mmdXNA.TimeRular.EndMark(1, "ModelDraw-Prepare");
265- mmdXNA.TimeRular.BeginMark(1, "ModelDraw-Core", Color.RosyBrown);
266- }
267-#endif
273+ System.Diagnostics.Debug.WriteLine((debug.Elapsed.TotalMilliseconds - Start).ToString());
274+ Break = false;
275+ }*/
276+ //2.8294ms
277+ //modelDraw処理 4.4583ms
268278 foreach (ModelMesh mesh in ModelData.ModelData.Meshes)
269279 {
270280 #if TRACE
271- if (mmdXNA.TimeRular != null && UseTimeRular)
272- mmdXNA.TimeRular.BeginMark(2, "ModelDraw-SetData", Color.RosyBrown);//メモ:この中の実行コードが時間くってる
281+ /*if (mmdXNA.TimeRular != null && UseTimeRular)
282+ mmdXNA.TimeRular.BeginMark(2, "ModelDraw-SetData", Color.RosyBrown);*///メモ:この中の実行コードが時間くってる
273283 #endif
274284 foreach (Effect effect in mesh.Effects)//メモ:エフェクト17回ループで処理時間食ってる
275285 {
276286 //エフェクトルーチン。
277287 //テクニックセット
278- effect.CurrentTechnique = effect.Techniques[EffectTechniqueName];
288+ //effect.CurrentTechnique = effect.Techniques[EffectTechniqueName];
279289 //ライティングセット
280290 effect.Parameters["AmbientLightColor"].SetValue(mmdXNA.LightManager.AmbientLight.ToVector3());
281291 effect.Parameters["DirLight0Direction"].SetValue(LightVector);
@@ -298,34 +308,24 @@
298308 effect.Parameters["View"].SetValue(view);
299309 effect.Parameters["Projection"].SetValue(projection);
300310 }
301-#if TRACE
302- if (mmdXNA.TimeRular != null && UseTimeRular)
303- {
304- mmdXNA.TimeRular.EndMark(2, "ModelDraw-SetData");
305- mmdXNA.TimeRular.BeginMark(2, "ModelDraw-Draw", Color.RoyalBlue);
306- }
307-#endif
311+
308312 mesh.Draw();
309-#if TRACE
310- if (mmdXNA.TimeRular != null && UseTimeRular)
311- mmdXNA.TimeRular.EndMark(2, "ModelDraw-Draw");
312-#endif
313+
313314 }
314-#if TRACE
315- if (mmdXNA.TimeRular != null && UseTimeRular)
316- {
317- mmdXNA.TimeRular.EndMark(1, "ModelDraw-Core");
318- mmdXNA.TimeRular.BeginMark(1, "ModelDraw-After", Color.OrangeRed);
319- }
320-#endif
315+ //7.2877ms
316+ //after 0.1025ms
317+
318+
321319 //CullModeの変更を戻す
322320 graphics.RenderState.CullMode = mode;
323- //アクセサリの描画
321+ //7.3902ms
322+
323+ //アクセサリの描画 3.5308ms
324324 foreach (var acc in Accessories)
325325 {
326326 if (BoneManager.ContainsBone(acc.Value.BoneName))
327327 {
328- Matrix baseMat = BoneManager.GetWorldQuatTransform(BoneManager.IndexOf(acc.Value.BoneName)).CreateMatrix();
328+ Matrix baseMat = World * BoneManager.GetWorldQuatTransform(BoneManager.IndexOf(acc.Value.BoneName)).CreateMatrix();
329329 if (acc.Key.Enabled)
330330 {
331331 acc.Key.Draw(baseMat * acc.Value.Transform);
@@ -332,11 +332,10 @@
332332 }
333333 }
334334 }
335-#if TRACE
336- if (mmdXNA.TimeRular != null && UseTimeRular)
337- mmdXNA.TimeRular.EndMark(1, "ModelDraw-After");
338-#endif
335+ //10.921ms
336+
339337
338+
340339 }
341340
342341 }
--- trunk/MikuMikuDanceXNA/Model/MMDBone.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Model/MMDBone.cs (revision 73)
@@ -22,7 +22,7 @@
2222 /// WorldTransform
2323 /// </summary>
2424 public QuatTransform WorldTransform { get; set; }
25- /// <summary>
25+ /*/// <summary>
2626 /// SkinRotation
2727 /// </summary>
2828 public Quaternion SkinRotation { get; set; }
@@ -29,7 +29,7 @@
2929 /// <summary>
3030 /// SkinTranslation
3131 /// </summary>
32- public Vector4 SkinTranslation { get; set; }
32+ public Vector4 SkinTranslation { get; set; }*/
3333
3434 internal MMDBone() { }//内部からのみ
3535 }
--- trunk/MikuMikuDanceXNA/Model/MMDFaceManager.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Model/MMDFaceManager.cs (revision 73)
@@ -10,7 +10,7 @@
1010 public class MMDFaceManager
1111 {
1212 MMDModel model;
13- Vector4[] FaceTranslations;//頂点番号ごとの移動量
13+ internal Vector4[] FaceTranslations;//頂点番号ごとの移動量
1414 internal Dictionary<string, float> FaceRates;//適応中の表情リスト
1515 Dictionary<string, int> FaceDictionary;//表情辞書
1616 int baseIndex;
@@ -81,10 +81,7 @@
8181 }
8282 }
8383 }
84- internal Vector4[] GetFaceTranslation()
85- {
86- return FaceTranslations;
87- }
84+
8885
8986 internal bool ContainsFace(string p)
9087 {
--- trunk/MikuMikuDanceXNA/Motion/AnimationPlayer.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Motion/AnimationPlayer.cs (revision 73)
@@ -332,7 +332,6 @@
332332 result.Faces[Frame, i].FaceName = FaceList[i];
333333 }
334334 }
335- System.Diagnostics.Debug.WriteLine(index.ToString());
336335 }
337336 }
338337 }
--- trunk/MikuMikuDanceXNA/Accessory/MMDAccessory.cs (revision 72)
+++ trunk/MikuMikuDanceXNA/Accessory/MMDAccessory.cs (revision 73)
@@ -43,6 +43,18 @@
4343 World = world;
4444 UseTimeRular = true;
4545 game.Components.Add(this);
46+ //アクセサリの初期設定
47+ foreach (ModelMesh mesh in ModelData.Meshes)
48+ {
49+ foreach (BasicEffect effect in mesh.Effects)
50+ {
51+ effect.LightingEnabled = true;
52+ effect.DirectionalLight0.Enabled = true;
53+ effect.DirectionalLight1.Enabled = false;
54+ effect.DirectionalLight2.Enabled = false;
55+
56+ }
57+ }
4658 }
4759 /// <summary>
4860 /// アクセサリの描画(DrawableGameComponent用
@@ -61,13 +73,6 @@
6173 /// <param name="baseTransform">基準トランスフォーム</param>
6274 internal void Draw(Matrix baseTransform)
6375 {
64-#if TRACE
65- if (mmd.TimeRular != null && UseTimeRular)
66- {
67- mmd.TimeRular.BeginMark(1, "AccessoryDraw", Color.Red);
68- mmd.TimeRular.BeginMark(2, "AccessoryDraw-Prepare", Color.Gray);
69- }
70-#endif
7176 //アクセサリ描画用に設定
7277 Game.GraphicsDevice.RenderState.AlphaBlendEnable = true;
7378 Game.GraphicsDevice.RenderState.BlendFunction = BlendFunction.Add;
@@ -80,33 +85,19 @@
8085 //モデルのCullModeを変更
8186 CullMode mode = Game.GraphicsDevice.RenderState.CullMode;
8287 Game.GraphicsDevice.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
83-#if TRACE
84- if (mmd.TimeRular != null && UseTimeRular)
85- {
86- mmd.TimeRular.EndMark(2, "AccessoryDraw-Prepare");
87- mmd.TimeRular.BeginMark(2, "AccessoryDraw-Core", Color.Green);
88- }
89-#endif
9088 //アクセサリの描画
9189 foreach (ModelMesh mesh in ModelData.Meshes)
9290 {
9391 foreach (BasicEffect effect in mesh.Effects)
9492 {
95- effect.LightingEnabled = true;
9693 effect.AmbientLightColor = mmd.LightManager.AmbientLight.ToVector3();
9794 effect.DirectionalLight0.Direction = mmd.LightManager.KeyLight.Direction;
9895 effect.DirectionalLight0.Direction.Normalize();
9996 effect.DirectionalLight0.DiffuseColor = mmd.LightManager.KeyLight.Color.ToVector3();//new Vector3(0.2f, 0.2f, 0.2f);
10097 effect.DirectionalLight0.SpecularColor = mmd.LightManager.KeyLight.Color.ToVector3();
101- effect.DirectionalLight0.Enabled = true;
102- effect.DirectionalLight1.Enabled = false;
103- effect.DirectionalLight2.Enabled = false;
104- effect.PreferPerPixelLighting = true;
105-
10698 effect.World = baseTransform * World;
10799 effect.View = mmd.Camera.GetViewMatrix();
108100 effect.Projection = mmd.Camera.GetProjectionMatrix(Game.GraphicsDevice);
109-
110101 }
111102 mesh.Draw();
112103 }
@@ -115,14 +106,6 @@
115106 //CullModeの変更を戻す
116107 Game.GraphicsDevice.RenderState.CullMode = mode;
117108
118-#if TRACE
119- if (mmd.TimeRular != null && UseTimeRular)
120- {
121- mmd.TimeRular.EndMark(2, "AccessoryDraw-Core");
122- mmd.TimeRular.EndMark(1, "AccessoryDraw");
123- }
124-#endif
125-
126109 }
127110
128111 }
--- trunk/MikuMikuDanceXNA/memo.txt (revision 72)
+++ trunk/MikuMikuDanceXNA/memo.txt (revision 73)
@@ -42,5 +42,12 @@
4242 v1.00の次
4343 -処理の高速化
4444 -ライティングをMMDに近づけた(スポットライトだけ未実装)
45--
45+-モーションのベイク機能実装
4646
47+
48+MMDX周りの技術メモ
49+ひにけにXNAのTimeRularはXBoxで嘘をつくことがある。Draw内でBeginMarkを呼び出した際に発生。理由は不明
50+XBoxのGCはマーク&スィープ方式のGC。その為、毎回ヒープオブジェクトをnewしていると、GCが大量発生し、まともに動かない。よって、ヒープオブジェクトのメモリ管理が必要(GCの意味なし)
51+XBoxのCPUはインテル製のように、シングルスレッドを自動的に割り振ったりとかはしてくれない。
52+XBoxのCPUは6コア、うち4コア使用可能。性能は4コアフル稼働でCore2Duo2G程度しかない。ボトルネックはCPU
53+XBoxのGPUは計算速いので、なるべくGPUに計算させる。
Show on old repository browser