• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision13 (tree)
Zeit2010-02-28 21:30:34
Autorwilfrem

Log Message

処理の整理でXBox360上でfps40-60を実現

Ändern Zusammenfassung

Diff

--- trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 13)
@@ -20,7 +20,7 @@
2020 /// </summary>
2121 internal IKLimitation Limitation { get; set; }
2222
23- MMDModel Model { get; set; }
23+ internal MMDModel Model { get; set; }
2424 Dictionary<string, int> BoneDic;
2525 Quaternion[] skinRots = null;//GetSkinRotation用の配列保持用。XBoxのGC回避のため
2626 Vector4[] skinTranses = null;//GetSkinTransration用の配列保持用。XBoxのGC回避のため
@@ -41,6 +41,7 @@
4141 boneindex++;
4242 }
4343 Solver = new IK_CCDSolver();//デフォルトはCCD法
44+ //Solver = new IK_ParticleSolver();//デフォルトはパーティクル法
4445 Limitation = new IKLimitation();//デフォルトリミッタ
4546 ResetMotion();
4647 Refresh();//返却用配列の更新
--- trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Model/MMDModel.cs (revision 13)
@@ -191,8 +191,8 @@
191191 Vector2 faceTextureSize = new Vector2(faceTexture.Texture.Width, faceTexture.Texture.Height);
192192
193193 //ライティング設定の取得
194- Vector3[] LightVectors, LightColors, LightSpeculars;
195- LightManager.GetParameters(out LightVectors, out LightColors, out LightSpeculars);
194+ Vector3[] LightVectors, LightColors;
195+ LightManager.GetParameters(out LightVectors, out LightColors);
196196
197197 foreach (ModelMesh mesh in ModelData.ModelData.Meshes)
198198 {
@@ -204,13 +204,13 @@
204204 //ライティングセット(すげーアホなコード書いてるが、ToStringするとGC発生しちゃうのでやむなく……)
205205 effect.Parameters["DirLight0Direction"].SetValue(LightVectors[0]);
206206 effect.Parameters["DirLight0DiffuseColor"].SetValue(LightColors[0]);
207- effect.Parameters["DirLight0SpecularColor"].SetValue(LightSpeculars[0]);
207+ //effect.Parameters["DirLight0SpecularColor"].SetValue(LightSpeculars[0]);
208208 effect.Parameters["DirLight1Direction"].SetValue(LightVectors[1]);
209209 effect.Parameters["DirLight1DiffuseColor"].SetValue(LightColors[1]);
210- effect.Parameters["DirLight1SpecularColor"].SetValue(LightSpeculars[1]);
210+ //effect.Parameters["DirLight1SpecularColor"].SetValue(LightSpeculars[1]);
211211 effect.Parameters["DirLight2Direction"].SetValue(LightVectors[2]);
212212 effect.Parameters["DirLight2DiffuseColor"].SetValue(LightColors[2]);
213- effect.Parameters["DirLight2SpecularColor"].SetValue(LightSpeculars[2]);
213+ //effect.Parameters["DirLight2SpecularColor"].SetValue(LightSpeculars[2]);
214214
215215 //ボーン設定
216216 effect.Parameters["BoneRotationTexture"].SetValue(
--- trunk/MikuMikuDanceXNA/Motion/IKLimitation.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Motion/IKLimitation.cs (revision 13)
@@ -151,34 +151,36 @@
151151 /// <returns>修正済みボーントランスフォーム</returns>
152152 public virtual QuatTransform AdjustTotalBoneMove(int boneIndex, MMDBoneManager manager)
153153 {
154+ bool flag = false;
155+ foreach (var i in TotalRotationLimits)
156+ {
157+ if (i.Key == manager[boneIndex].BoneData.Name)
158+ flag = true;
159+ }
160+ if (!flag)
161+ return manager[boneIndex].BoneTransform;
154162 //まずは軸回転のマトリクスを生成する
155163 Matrix bonetrans = manager[boneIndex].BoneTransform.CreateMatrix();
156164 Matrix bindpose = manager[boneIndex].BoneData.BindPose.CreateMatrix();
157165 Matrix moveMat = bonetrans * Matrix.Invert(bindpose);
158-
166+
159167 //回転を取得
160168 Vector3 temp, trans;
161169 Quaternion rot;
162-
170+
163171 moveMat.Decompose(out temp, out rot, out trans);
164-
165172
173+
166174 float YRot, XRot, ZRot;
167175 MMDMath.DecompositeQuaternion(rot, out YRot, out XRot, out ZRot);
168176
169-
170- foreach (var i in TotalRotationLimits)
171- {
172- if (i.Key == manager[boneIndex].BoneData.Name)
173- {
174- XRot=i.Value.Adjust(XRot, 0);
175- YRot=i.Value.Adjust(YRot, 1);
176- ZRot=i.Value.Adjust(ZRot, 2);
177- }
178- }
179-
180- return new QuatTransform(Quaternion.CreateFromYawPitchRoll(YRot,XRot,ZRot), trans) * manager[boneIndex].BoneData.BindPose;
181-
177+ RotationLimit lim = TotalRotationLimits[manager[boneIndex].BoneData.Name];
178+ XRot = lim.Adjust(XRot, 0);
179+ YRot = lim.Adjust(YRot, 1);
180+ ZRot = lim.Adjust(ZRot, 2);
181+
182+ return new QuatTransform(Quaternion.CreateFromYawPitchRoll(YRot, XRot, ZRot), trans) * manager[boneIndex].BoneData.BindPose;
183+
182184 }
183185 }
184186 }
--- trunk/MikuMikuDanceXNA/Motion/IKSolver.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Motion/IKSolver.cs (revision 13)
@@ -5,6 +5,7 @@
55 using MikuMikuDance.XNA.Model;
66 using MikuMikuDance.XNA.Model.ModelData;
77 using Microsoft.Xna.Framework;
8+using Microsoft.Xna.Framework.Graphics;
89
910 namespace MikuMikuDance.XNA.Motion
1011 {
@@ -18,6 +19,10 @@
1819 /// </summary>
1920 CyclicCoordinateDescent = 1,
2021 /// <summary>
22+ /// Particle方
23+ /// </summary>
24+ Particle=2,
25+ /// <summary>
2126 /// ユーザー定義ソルバ
2227 /// </summary>
2328 User = 999,
@@ -42,28 +47,6 @@
4247 IKSolveType Type { get; }
4348
4449 }
45-#if false
46- public class IK_CCDSolver : IKSolver
47- {
48- /// <summary>
49- /// ソルバの種別
50- /// </summary>
51- public IKSolveType Type { get { return IKSolveType.CyclicCoordinateDescent; } }
52- /// <summary>
53- /// Cyclic-Coordinate-Descent法によるソルブ
54- /// </summary>
55- /// <param name="Movement">IKの位置(モデル全体の座標系)</param>
56- /// <param name="bones">IK影響下のリスト(IKTargetからIK影響外の親まで逆順で)</param>
57- /// <param name="ikBone">IKボーン</param>
58- /// <param name="manager">ボーンマネージャ</param>
59- /// <param name="limitation">IK回転方向制限オブジェクト</param>
60- public void Solve(Vector3 Movement, List<int> bones, MMDBone ikBone, MMDBoneManager manager, IKLimitation limitation)
61- {
62- //計算用スケルトンの組み立て
63-
64- }
65- }
66-#endif
6750 /// <summary>
6851 /// Cyclic-Coordinate-Descent法によるIKソルバー
6952 /// </summary>
@@ -96,7 +79,7 @@
9679 {
9780 for (int i = 1; i < bones.Count; i++)
9881 {//IKボーンを逆順に処理
99-
82+
10083 //現在検索中のボーンの根元の位置を取得
10184 QuatTransform qtrans = IKBase;
10285 for (int j = bones.Count - 1; j >= i; j--)
@@ -118,6 +101,10 @@
118101 // (2) 基準関節i→目標位置へのベクトル(b)(ボーンi基準座標系)
119102 localTargetPos = Vector3.Transform(Movement, invCoord);
120103
104+ if ((localEffectorPos - localTargetPos).LengthSquared() < errToleranceSq)
105+ {
106+ return;
107+ }
121108
122109 // (1) 基準関節→エフェクタ位置への方向ベクトル
123110 Vector3 basis2Effector = Vector3.Normalize(localEffectorPos);
@@ -126,12 +113,12 @@
126113 // 回転角
127114 float rotationDotProduct = Vector3.Dot(basis2Effector, basis2Target);
128115 float rotationAngle = (float)Math.Acos(rotationDotProduct);
129-
116+
130117 //回転量制限をかける
131- if (rotationAngle > Math.PI * ikBone.BoneData.IK.ControlWeight)
132- rotationAngle = (float)Math.PI * ikBone.BoneData.IK.ControlWeight;
133- if (rotationAngle < -Math.PI * ikBone.BoneData.IK.ControlWeight)
134- rotationAngle = -(float)Math.PI * ikBone.BoneData.IK.ControlWeight;
118+ if (rotationAngle > MathHelper.Pi * ikBone.BoneData.IK.ControlWeight)
119+ rotationAngle = MathHelper.Pi * ikBone.BoneData.IK.ControlWeight;
120+ if (rotationAngle < -MathHelper.Pi * ikBone.BoneData.IK.ControlWeight)
121+ rotationAngle = -MathHelper.Pi * ikBone.BoneData.IK.ControlWeight;
135122
136123 if(!float.IsNaN(rotationAngle))
137124 {
@@ -151,11 +138,12 @@
151138 CheckNaN(manager[bones[i]].BoneTransform);
152139
153140 }
141+
154142 }
155- if ((localEffectorPos - localTargetPos).LengthSquared() < errToleranceSq)
143+ /*if ((localEffectorPos - localTargetPos).LengthSquared() < errToleranceSq)
156144 {
157145 return;
158- }
146+ }*/
159147 }
160148 }
161149 bool CheckNaN(Vector3 input)
@@ -187,4 +175,71 @@
187175
188176 }
189177 }
178+ //設計途中で、MMDの場合、毎回のループで可動制限のためボーンに適応しなければならず、計算量が変わらないことに気づいたのでボツ
179+ /*internal class IK_ParticleSolver : IKSolver
180+ {
181+ struct Particle
182+ {
183+ public Matrix mat;//パーティクルの位置及び回転を表す
184+ public float constraint;//点と次の点との距離
185+ }
186+ Particle[] Particles = new Particle[100];//100個用意しておけば……(;・∀・)ダ、ダイジョウブ…?
187+
188+ /// <summary>
189+ /// ソルバの種別
190+ /// </summary>
191+ public IKSolveType Type { get { return IKSolveType.CyclicCoordinateDescent; } }
192+ /// <summary>
193+ /// Particle法によるソルブ
194+ /// </summary>
195+ /// <param name="Movement">IKの位置(モデル全体の座標系)</param>
196+ /// <param name="bones">IK影響下のリスト(IKTargetからIK影響外の親まで逆順で)</param>
197+ /// <param name="ikBone">IKボーン</param>
198+ /// <param name="manager">ボーンマネージャ</param>
199+ /// <param name="limitation">IK回転方向制限オブジェクト</param>
200+ public void Solve(Vector3 Movement, List<int> bones, MMDBone ikBone, MMDBoneManager manager, IKLimitation limitation)
201+ {
202+ //再帰回数を取得
203+ ushort MaxIterations = ikBone.BoneData.IK.Iteration;
204+ //IKでソルブしない固定点を取得
205+ Matrix IKBase = manager.GetWorldQuatTransform(manager[bones.Last()].BoneData.SkeletonHierarchy).CreateMatrix();
206+
207+ //パーティクルの計算
208+ for (ushort it = 0; it < MaxIterations; it++)
209+ {
210+ //パーティクルの更新
211+ Particles[bones.Count - 1].mat = manager[bones.Last()].BoneTransform.CreateMatrix() * IKBase;
212+ for (int i = bones.Count - 2; i >= 0; i--)
213+ {
214+ Particles[i].mat = manager[bones[i]].BoneTransform.CreateMatrix() * Particles[i + 1].mat;
215+ Particles[i].constraint = (Particles[i].mat.Translation - Particles[i + 1].mat.Translation).Length();
216+ }
217+ Vector3 dv = Movement - Particles[0].mat.Translation;
218+ Particles[0].mat.Translation += dv;
219+
220+ for (int i = 1; i < bones.Count - 1; i++)
221+ {
222+ dv = Particles[i].mat.Translation - Particles[i - 1].mat.Translation;
223+ dv *= 0.5f - Particles[i - 1].constraint / dv.Length() * 0.5f;
224+ Particles[i - 1].mat.Translation += dv;
225+ Particles[i].mat.Translation -= dv;
226+ }
227+ dv = IKBase.Translation - Particles[bones.Count - 1].mat.Translation;
228+ dv *= 1f - Particles[bones.Count - 1].constraint / dv.Length() * 0.5f;
229+ Particles[Particles.Length - 1].mat.Translation += dv;
230+ }
231+ manager[bones[bones.Count - 1]].BoneTransform = QuatTransform.FromMatrix(Particles[bones.Count - 1].mat * Matrix.Invert(IKBase));
232+ //パーティクルのボーンへの当てはめ
233+ for (int i = 1; i <bones.Count; i++)
234+ {
235+ Matrix invCoord = Matrix.Invert(manager[bones[i-1]].BoneTransform.CreateMatrix());
236+ Vector3 p1 = Vector3.Transform(Particles[i].mat.Translation, invCoord);
237+ Vector3 p0 = Vector3.Transform(manager[bones[i]].BoneTransform.Translation, invCoord);
238+ Vector3 dv = Vector3.Normalize(p1 - p0);
239+
240+ manager[bones[i]].BoneTransform = QuatTransform.FromMatrix(Particles[i].mat * Matrix.Invert(Particles[i + 1].mat));
241+ manager[bones[i]].BoneTransform = limitation.AdjustTotalBoneMove(bones[i], manager);
242+ }
243+ }
244+ }*/
190245 }
--- trunk/MikuMikuDanceXNA/Stages/MMDLightManager.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Stages/MMDLightManager.cs (revision 13)
@@ -19,17 +19,17 @@
1919 /// キーライト
2020 /// </summary>
2121 public MMDLight KeyLight = new MMDLight(new Vector3(1, -1, 1),
22- new Color(154, 145, 106), new Color(154, 145, 106));
22+ new Color(154, 145, 106));// new Color(154, 145, 106));
2323 /// <summary>
2424 /// フィルライト
2525 /// </summary>
2626 public MMDLight FillLight = new MMDLight(new Vector3(-1, 1, -1),
27- new Color(246, 194, 104), Color.Black);
27+ new Color(246, 194, 104));
2828 /// <summary>
2929 /// バックライト
3030 /// </summary>
3131 public MMDLight BackLight = new MMDLight(new Vector3(-1, -1, -1),
32- new Color(82, 92, 100), new Color(82, 92, 100));
32+ new Color(82, 92, 100));//, new Color(82, 92, 100));
3333 /// <summary>
3434 /// ライト
3535 /// </summary>
@@ -54,14 +54,13 @@
5454
5555
5656
57- internal void GetParameters(out Vector3[] dir, out Vector3[] color, out Vector3[] spec)
57+ internal void GetParameters(out Vector3[] dir, out Vector3[] color)
5858 {
5959 dir = m_dir;
6060 color = m_color;
61- spec = m_spec;
6261 for (int i = 0; i < 3; i++)
6362 {
64- this[i].SetParameters(out dir[i], out color[i], out spec[i]);
63+ this[i].SetParameters(out dir[i], out color[i]);
6564 }
6665 }
6766 }
--- trunk/MikuMikuDanceXNA/Stages/MMDLight.cs (revision 12)
+++ trunk/MikuMikuDanceXNA/Stages/MMDLight.cs (revision 13)
@@ -20,22 +20,16 @@
2020 /// カラー
2121 /// </summary>
2222 public Color Color;
23- /// <summary>
24- /// スペキュラ
25- /// </summary>
26- public Color Specular;
27- internal MMDLight(Vector3 dir, Color color, Color spec)
23+ internal MMDLight(Vector3 dir, Color color)
2824 {
2925 Direction = dir;
3026 Color = color;
31- Specular = spec;
3227 }
33- internal void SetParameters(out Vector3 dir, out Vector3 color, out Vector3 spec)
28+ internal void SetParameters(out Vector3 dir, out Vector3 color)
3429 {
3530 dir = Direction;
3631 dir.Normalize();
3732 color = Color.ToVector3();
38- spec = Color.ToVector3();
3933 }
4034 }
4135
Show on old repository browser