• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision8 (tree)
Zeit2010-02-26 01:19:24
Autorwilfrem

Log Message

速度アップのためのトレースコード追加

Ändern Zusammenfassung

Diff

--- trunk/MikuMikuDanceXNA/Model/AnimationPlayer.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/Model/AnimationPlayer.cs (revision 8)
@@ -3,6 +3,7 @@
33 using Microsoft.Xna.Framework;
44 using MikuMikuDance.XNA.Model.ModelData;
55 using MikuMikuDance.XNA.Motion;
6+using Microsoft.Xna.Framework.Graphics;
67
78 namespace MikuMikuDance.XNA.Model
89 {
@@ -89,6 +90,10 @@
8990
9091 private void InnerUpdate(MMDMotion motion, decimal NowFrame)
9192 {
93+#if TRACE
94+ if (mmdModel.mmdXNA.TimeRular != null && mmdModel.UseTimeRular)
95+ mmdModel.mmdXNA.TimeRular.BeginMark(2, "Anime-MotionToBone-" + mmdModel.Name, Color.BlueViolet);
96+#endif
9297 //モーションのボーンリストを取得
9398 List<string> motionBones = motion.GetBoneList();
9499 //リストにあるボーンの位置を順番に更新
@@ -101,6 +106,14 @@
101106 mmdModel.BoneManager[bone].BoneTransform = move * mmdModel.BoneManager[bone].BoneData.BindPose;
102107 }
103108 }
109+#if TRACE
110+ if (mmdModel.mmdXNA.TimeRular != null && mmdModel.UseTimeRular)
111+ {
112+ mmdModel.mmdXNA.TimeRular.EndMark(2, "Anime-MotionToBone-" + mmdModel.Name);
113+ mmdModel.mmdXNA.TimeRular.BeginMark(2, "Anime-IKBone-" + mmdModel.Name, Color.BlueViolet);
114+ }
115+#endif
116+ mmdModel.BoneManager.UpdateWorldTransforms();
104117 //IKボーンの処理
105118 for (int i = 0; i < mmdModel.BoneManager.Count; i++)
106119 {
@@ -107,6 +120,13 @@
107120 if (mmdModel.BoneManager[i].BoneData.IK != null)
108121 mmdModel.BoneManager.SolveIK(i, mmdModel.BoneManager[i].BoneTransform);
109122 }
123+#if TRACE
124+ if (mmdModel.mmdXNA.TimeRular != null && mmdModel.UseTimeRular)
125+ {
126+ mmdModel.mmdXNA.TimeRular.EndMark(2, "Anime-IKBone-" + mmdModel.Name);
127+ mmdModel.mmdXNA.TimeRular.BeginMark(2, "Anime-Face-" + mmdModel.Name, Color.BlueViolet);
128+ }
129+#endif
110130 //フェイスモーションの処理
111131 List<string> faces = motion.GetFaceList();
112132 //リストにあるフェイスのデータを順番に処理
@@ -114,6 +134,10 @@
114134 {
115135 mmdModel.FaceManager.SetFace(face, motion.GetFaceRate(face, NowFrame));
116136 }
137+#if TRACE
138+ if (mmdModel.mmdXNA.TimeRular != null && mmdModel.UseTimeRular)
139+ mmdModel.mmdXNA.TimeRular.EndMark(2, "Anime-Face-" + mmdModel.Name);
140+#endif
117141 }
118142
119143 /// <summary>
--- trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 8)
@@ -2,6 +2,7 @@
22 using MikuMikuDance.XNA.Model.ModelData;
33 using Microsoft.Xna.Framework;
44 using MikuMikuDance.XNA.Motion;
5+using Microsoft.Xna.Framework.Graphics;
56
67 namespace MikuMikuDance.XNA.Model
78 {
@@ -239,7 +240,15 @@
239240 i = this[i].BoneData.SkeletonHierarchy;//boneのindexはWORD
240241 //親ボーンを登録
241242 } while (ik.IKChildBones.IndexOf((ushort)i) >= 0); //IK影響下じゃないボーンが見つかるまで探索(固定点決めるようにiKじゃないボーンも一つ入れておく)
243+#if TRACE
244+ if(Model.mmdXNA.TimeRular!=null && Model.UseTimeRular)
245+ Model.mmdXNA.TimeRular.BeginMark(4,"SolveIK",Color.Blue);
246+#endif
242247 Solver.Solve(moveVec, underIKs, this[ikbone], this, Limitation);//IKを解決
248+#if TRACE
249+ if (Model.mmdXNA.TimeRular != null && Model.UseTimeRular)
250+ Model.mmdXNA.TimeRular.EndMark(4, "SolveIK");
251+#endif
243252 //解決時に解がボーンに入っているのでそのまま帰る
244253 }
245254
--- trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 8)
@@ -4,6 +4,7 @@
44 using MikuMikuDance.XNA.Stages;
55 using System;
66 using System.Text;
7+using System.Diagnostics;
78
89 namespace MikuMikuDance.XNA.Model
910 {
@@ -28,6 +29,8 @@
2829 //物理エンジンマネージャ
2930 //MMDPhysics physics;
3031
32+ internal string Name{get;set;}
33+
3134 //properties...
3235 /// <summary>
3336 /// ボーンマネージャ
@@ -54,6 +57,10 @@
5457 /// </summary>
5558 /// <remarks>未実装...</remarks>
5659 public bool UseToon { get; set; }
60+ /// <summary>
61+ /// MikuMikuDanceXNA.TimeRularをこのモデルが呼び出すかどうか
62+ /// </summary>
63+ public bool UseTimeRular { get; set; }
5764 //このクラスはMikuMikuDanceXNAからしか作れない
5865 internal MMDModel(Game game)
5966 :base(game)
@@ -63,6 +70,7 @@
6370 //physics = new MMDPhysics(this);
6471 game.Components.Add(this);
6572 LightManager = new MMDLightManager();
73+ UseTimeRular = true;
6674 }
6775
6876 internal void ModelSetup(MMDModelData modelData, MikuMikuDanceXNA mmdxna, GraphicsDevice graphics)
@@ -99,8 +107,23 @@
99107 /// <remarks>DrawableGameContentを継承してるため自動更新</remarks>
100108 public override void Update(GameTime gameTime)
101109 {
110+#if TRACE//速度検査用コード。
111+ if (mmdXNA.TimeRular != null && UseTimeRular)
112+ mmdXNA.TimeRular.BeginMark(1,"Player-" + Name, Color.BlueViolet);
113+#endif
102114 Player.Update(gameTime);
115+#if TRACE
116+ if (mmdXNA.TimeRular != null && UseTimeRular)
117+ {
118+ mmdXNA.TimeRular.EndMark(1, "Player-" + Name);
119+ mmdXNA.TimeRular.BeginMark(1, "BoneManager-" + Name, Color.Cyan);
120+ }
121+#endif
103122 BoneManager.Update();
123+#if TRACE
124+ if (mmdXNA.TimeRular != null && UseTimeRular)
125+ mmdXNA.TimeRular.EndMark(1, "BoneManager-" + Name);
126+#endif
104127 /*if (mmdXNA.UsePhysic)
105128 physics.Update();*/
106129 base.Update(gameTime);
--- trunk/MikuMikuDanceXNA/MikuMikuDanceXNA.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/MikuMikuDanceXNA.cs (revision 8)
@@ -6,6 +6,7 @@
66 using MikuMikuDance.XNA.Motion;
77 using MikuMikuDance.XNA.Motion.MotionData;
88 using MikuMikuDance.XNA.Stages;
9+using MikuMikuDance.XNA.Debug;
910 //using BulletX.Dynamics;
1011 //using BulletX;
1112
@@ -41,6 +42,9 @@
4142
4243 //デバッグ用
4344 //internal XnaDebugDraw debugDrawer;
45+#if TRACE
46+ public ITimeRular TimeRular = null;
47+#endif
4448
4549 //地面(仮置き)
4650 //private MMDGroundObject Ground { get; set; }
@@ -86,6 +90,7 @@
8690 public MMDModel LoadModel(string assetName, Game game, Matrix defaultTransform)
8791 {
8892 MMDModel result = new MMDModel(game);
93+ result.Name = assetName;
8994 result.World = defaultTransform;
9095 result.ModelSetup(Content.Load<MMDModelData>(assetName), this, game.GraphicsDevice);
9196 return result;
--- trunk/MikuMikuDanceXNA/Motion/IKSolver.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/Motion/IKSolver.cs (revision 8)
@@ -87,9 +87,9 @@
8787 //再帰回数を取得
8888 ushort MaxIterations = ikBone.BoneData.IK.Iteration;
8989
90- Vector3 localTargetPos = Vector3.Zero;
90+ Vector3 localTargetPos = Vector3.One;
9191 Vector3 localEffectorPos = Vector3.Zero;
92- manager.UpdateWorldTransforms();
92+ //manager.UpdateWorldTransforms();
9393 for (ushort it = 0; it < MaxIterations; it++)
9494 {
9595 for (int i = 1; i < bones.Count; i++)
@@ -96,11 +96,11 @@
9696 {//IKボーンを逆順に処理
9797
9898 //エフェクタの現在位置を取得
99- Vector3 objectVecLoc = manager.GetWorldTransform(bones[0]);
99+ Vector3 objectVecLoc = manager.GetWorldTransform(bones[0]);//TODO: ボトルネックになっている。
100100 //現在検索中のボーンの根元の位置を取得
101- QuatTransform rootQuat = manager.GetWorldQuatTransform(bones[i]);
101+ QuatTransform rootQuat = manager.GetWorldQuatTransform(bones[i]);//TODO: ボトルネックになっている。
102102 Vector3 rootVec = rootQuat.Translation;
103-
103+
104104 QuatTransform qtrans = rootQuat;
105105 Matrix invCoord = Matrix.Invert(qtrans.CreateMatrix());
106106 // 各ベクトルの座標変換を行い、検索中のボーンi基準の座標系にする
@@ -107,13 +107,13 @@
107107 Vector3 objectVec = Vector3.Transform(objectVecLoc, invCoord);
108108 Vector3 targetPos = Vector3.Transform(Movement, invCoord);
109109 rootVec = Vector3.Transform(rootVec, invCoord);//ゼロになるはずだが……
110-
110+
111111 // (1) 基準関節→エフェクタ位置へのベクトル(a)(ボーンi基準座標系)
112112 localEffectorPos = objectVec - rootVec;
113113 // (2) 基準関節→目標位置へのベクトル(b)(ボーンi基準座標系)
114114 localTargetPos = targetPos - rootVec;
115-
116115
116+
117117 // (1) 基準関節→エフェクタ位置への方向ベクトル
118118 Vector3 basis2Effector = Vector3.Normalize(localEffectorPos);
119119 // (2) 基準関節→目標位置への方向ベクトル
@@ -127,7 +127,7 @@
127127 rotationAngle = (float)Math.PI * ikBone.BoneData.IK.ControlWeight;
128128 if (rotationAngle < -Math.PI * ikBone.BoneData.IK.ControlWeight)
129129 rotationAngle = -(float)Math.PI * ikBone.BoneData.IK.ControlWeight;
130-
130+
131131 if(!float.IsNaN(rotationAngle))
132132 {
133133 // 回転軸
--- trunk/MikuMikuDanceXNA/Motion/MMDMotion.cs (revision 7)
+++ trunk/MikuMikuDanceXNA/Motion/MMDMotion.cs (revision 8)
@@ -5,6 +5,7 @@
55 using Microsoft.Xna.Framework;
66 using MikuMikuDance.XNA.Motion.MotionData;
77 using MikuMikuDance.XNA.Model.ModelData;
8+using Microsoft.Xna.Framework.Graphics;
89
910 namespace MikuMikuDance.XNA.Motion
1011 {
@@ -148,6 +149,10 @@
148149 /// <returns>トランスフォーム</returns>
149150 internal QuatTransform GetBoneTransform(string bone, decimal NowFrame)
150151 {
152+#if TRACE
153+ if(mmdXNA.TimeRular!=null)
154+ mmdXNA.TimeRular.BeginMark(3, "MMDMotion-GetBoneTransform", Color.Blue);
155+#endif
151156 MMDBoneMotion[] motions = BoneMotions[bone];
152157 //前後のフレームをチェック
153158 long BeforePos = 0;
@@ -185,8 +190,11 @@
185190 float Progress = ((float)(NowFrame - motions[BeforePos].FrameNo)) / ((float)(motions[NextPos].FrameNo - motions[BeforePos].FrameNo));
186191 q = Quaternion.Slerp(motions[BeforePos].Quatanion, motions[NextPos].Quatanion, Progress);
187192 v = Vector3.Lerp(motions[BeforePos].Location, motions[NextPos].Location, Progress);
188-
189193 }
194+#if TRACE
195+ if (mmdXNA.TimeRular != null)
196+ mmdXNA.TimeRular.EndMark(3, "MMDMotion-GetBoneTransform");
197+#endif
190198 return new QuatTransform(q, v);
191199 }
192200
Show on old repository browser