• R/O
  • SSH
  • HTTPS

mmdx: Commit


Commit MetaInfo

Revision662 (tree)
Zeit2011-01-10 20:03:35
Autorwilfrem

Log Message

IK情報の読み込みまで

Ändern Zusammenfassung

Diff

--- branches/XNA4/MMDPipeline/Model/MMDIKDataContent.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDIKDataContent.cs (nonexistent)
@@ -1,36 +0,0 @@
1-using System;
2-using System.Collections.Generic;
3-using System.Linq;
4-using System.Text;
5-
6-namespace MikuMikuDance.XNA.Model
7-{
8- /// <summary>
9- /// MMD用のIK情報(パイプライン用)
10- /// </summary>
11- class MMDIKDataContent
12- {
13- /// <summary>
14- /// IKボーン番号
15- /// </summary>
16- /// <remarks>この番号で指定されたボーンがIKとなる</remarks>
17- public UInt16 IKBoneIndex;
18- /// <summary>
19- /// IKターゲットボーン番号
20- /// </summary>
21- /// <remarks>IKボーンが最初に接続するボーン</remarks>
22- public UInt16 IKTargetBoneIndex;
23- /// <summary>
24- /// 再帰演算回数
25- /// </summary>
26- public UInt16 Iteration;
27- /// <summary>
28- /// IKの影響度
29- /// </summary>
30- public float ControlWeight;
31- /// <summary>
32- /// K影響下のボーン番号
33- /// </summary>
34- public UInt16[] IKChildBones;
35- }
36-}
--- branches/XNA4/MMDPipeline/Model/MMDBoneContent.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDBoneContent.cs (revision 662)
@@ -6,18 +6,14 @@
66
77 namespace MikuMikuDance.XNA.Model
88 {
9- public struct MMDBoneContent
9+ public class MMDBoneContent
1010 {
1111 /// <summary>
1212 /// ボーンの名前
1313 /// </summary>
1414 public string Name;
15+
1516 /// <summary>
16- /// IKボーンの接続先(影響IKボーン)
17- /// </summary>
18- public UInt16 IKParentBoneIndex;
19-
20- /// <summary>
2117 /// ボーンのバインドポーズ行列
2218 /// </summary>
2319 public QuatTransformContent BindPose;
@@ -30,5 +26,9 @@
3026 /// </summary>
3127 /// <remarks>親が無い場合は-1</remarks>
3228 public int SkeletonHierarchy;
29+ /// <summary>
30+ /// このボーンに対応するIKリスト
31+ /// </summary>
32+ public List<int> IKs;
3333 }
3434 }
--- branches/XNA4/MMDPipeline/Model/MMDModelScene.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDModelScene.cs (revision 662)
@@ -15,8 +15,6 @@
1515 {
1616 NodeContent root = new NodeContent();
1717 public NodeContent Root { get { return root; } }
18- MMDIKDataContent[] iks;
19- public MMDIKDataContent[] IK { get { return iks; } }
2018 MMDSkinDataContent[] skins;
2119 public MMDSkinDataContent[] Skins { get { return skins; } }
2220 MMDRigidContent[] rigids;
@@ -43,7 +41,6 @@
4341 BoneContent bone = BuildSkelton(model, identity);
4442 root.Children.Add(bone);
4543 //メッシュ以外の情報の整理
46- BuildIK(model);
4744 BuildFace(model);
4845 BuildPhysics(model);
4946 //このクラスを不透明データに入れる
@@ -76,13 +73,19 @@
7673 MMDBoneTag[] boneTags = new MMDBoneTag[model.Bones.Length];
7774 for (int i = 0; i < boneTags.Length; i++)
7875 boneTags[i] = new MMDBoneTag();
79- //タグ設定
80- for (int i = 0; i < boneTags.Length; i++)
76+ //タグにIK情報を入れる
77+ for (int i = 0; i < model.IKs.Length; i++)
8178 {
82- if (model.Bones[i].IKParentBoneIndex > 0)//ここでオブジェクト入れるのは、番号が変わるため……
83- boneTags[i].ikParentBone = boneMap[model.Bones[i].IKParentBoneIndex];
84- else
85- boneTags[i].ikParentBone = null;
79+ MMDBoneIKTag ikTag = new MMDBoneIKTag();
80+ ikTag.Iteration = model.IKs[i].Iterations;
81+ ikTag.ControlWeight = model.IKs[i].AngleLimit;
82+ ikTag.IKChildBones = new BoneContent[model.IKs[i].IKChildBoneIndex.Length];
83+ for (int j = 0; j < ikTag.IKChildBones.Length; j++)
84+ {
85+ ikTag.IKChildBones[j] = boneMap[model.IKs[i].IKChildBoneIndex[j]];
86+ }
87+ //IK情報を対応するタグに挿入
88+ boneTags[model.IKs[i].IKTargetBoneIndex].IKs.Add(ikTag);
8689 }
8790 //ボーンにMMD用のタグを挿入
8891 for (int i = 0; i < boneTags.Length; i++)
@@ -135,25 +138,7 @@
135138 return result;
136139 }
137140
138- private void BuildIK(MMDModel1 model)
139- {
140- iks = new MMDIKDataContent[model.IKs.Length];
141- //IKの格納
142- for (UInt16 i = 0; i < model.IKs.Length; i++)
143- {
144- MMDIKDataContent ik = new MMDIKDataContent();
145- ik.IKBoneIndex = model.IKs[i].IKBoneIndex;
146- ik.IKTargetBoneIndex = model.IKs[i].IKTargetBoneIndex;
147- ik.Iteration = model.IKs[i].Iterations;
148- ik.ControlWeight = model.IKs[i].AngleLimit;
149- ik.IKChildBones = new ushort[model.IKs[i].IKChildBoneIndex.Length];
150- for (byte i2 = 0; i2 < model.IKs[i].IKChildBoneIndex.Length; i2++)
151- {
152- ik.IKChildBones[i2] = model.IKs[i].IKChildBoneIndex[i2];
153- }
154- iks[i] = ik;
155- }
156- }
141+
157142
158143 private void BuildFace(MMDModel1 model)
159144 {
--- branches/XNA4/MMDPipeline/Model/MMDBoneTag.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDBoneTag.cs (revision 662)
@@ -11,7 +11,25 @@
1111 /// </summary>
1212 class MMDBoneTag
1313 {
14- //ikParentのボーン
15- public BoneContent ikParentBone;
14+ //IK情報
15+ public List<MMDBoneIKTag> IKs = new List<MMDBoneIKTag>();
1616 }
17+ /// <summary>
18+ /// ボーン付属のIK情報
19+ /// </summary>
20+ class MMDBoneIKTag
21+ {
22+ /// <summary>
23+ /// 再帰演算回数
24+ /// </summary>
25+ public UInt16 Iteration;
26+ /// <summary>
27+ /// IKの影響度
28+ /// </summary>
29+ public float ControlWeight;
30+ /// <summary>
31+ /// K影響下のボーン番号
32+ /// </summary>
33+ public BoneContent[] IKChildBones;
34+ }
1735 }
--- branches/XNA4/MMDPipeline/Model/MMDBoneWriter.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDBoneWriter.cs (revision 662)
@@ -20,9 +20,10 @@
2020 {
2121 output.WriteObject(value.BindPose);
2222 output.WriteObject(value.InverseBindPose);
23- output.Write(value.IKParentBoneIndex);
23+ //output.Write(value.IKParentBoneIndex);
2424 output.Write(value.Name);
2525 output.Write(value.SkeletonHierarchy);
26+ output.WriteObject(value.IKs);
2627 }
2728
2829 public override string GetRuntimeType(TargetPlatform targetPlatform)
--- branches/XNA4/MMDPipeline/Model/MMDIKContent.cs (nonexistent)
+++ branches/XNA4/MMDPipeline/Model/MMDIKContent.cs (revision 662)
@@ -0,0 +1,27 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+
6+namespace MikuMikuDance.XNA.Model
7+{
8+ public class MMDIKContent
9+ {
10+ /// <summary>
11+ /// ターゲットIK番号
12+ /// </summary>
13+ public int IKBoneIndex;
14+ /// <summary>
15+ /// 再帰演算回数
16+ /// </summary>
17+ public UInt16 Iteration;
18+ /// <summary>
19+ /// IKの影響度
20+ /// </summary>
21+ public float ControlWeight;
22+ /// <summary>
23+ /// K影響下のボーン番号
24+ /// </summary>
25+ public List<int> IKChildBones = new List<int>();
26+ }
27+}
--- branches/XNA4/MMDPipeline/Model/MMDIKWriter.cs (nonexistent)
+++ branches/XNA4/MMDPipeline/Model/MMDIKWriter.cs (revision 662)
@@ -0,0 +1,37 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using Microsoft.Xna.Framework;
5+using Microsoft.Xna.Framework.Graphics;
6+using Microsoft.Xna.Framework.Content.Pipeline;
7+using Microsoft.Xna.Framework.Content.Pipeline.Graphics;
8+using Microsoft.Xna.Framework.Content.Pipeline.Processors;
9+using Microsoft.Xna.Framework.Content.Pipeline.Serialization.Compiler;
10+
11+namespace MikuMikuDance.XNA.Model
12+{
13+ /// <summary>
14+ /// MMDIKContentのタイプライター
15+ /// </summary>
16+ [ContentTypeWriter]
17+ public class MMDIKWriter : ContentTypeWriter<MMDIKContent>
18+ {
19+ protected override void Write(ContentWriter output, MMDIKContent value)
20+ {
21+ output.Write(value.IKBoneIndex);
22+ output.Write(value.Iteration);
23+ output.Write(value.ControlWeight);
24+ output.WriteObject(value.IKChildBones);
25+ }
26+
27+ public override string GetRuntimeType(TargetPlatform targetPlatform)
28+ {
29+ return "MikuMikuDance.XNA.Model.MMDIK, MikuMikuDanceXNA";
30+ }
31+
32+ public override string GetRuntimeReader(TargetPlatform targetPlatform)
33+ {
34+ return "MikuMikuDance.XNA.Model.MMDIKReader, MikuMikuDanceXNA";
35+ }
36+ }
37+}
--- branches/XNA4/MMDPipeline/Model/SkinningHelpers.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/SkinningHelpers.cs (revision 662)
@@ -38,9 +38,11 @@
3838 throw new InvalidContentException(string.Format("スケルトンに{0}本のボーンが含まれています。サポートされている最大ボーン数は{1}本です.", bones.Count, maxBones));
3939 }
4040 List<MMDBoneContent> mmdBones = new List<MMDBoneContent>();
41+ List<MMDIKContent> mmdIKs = new List<MMDIKContent>();
4142 foreach (BoneContent bone in bones)
4243 {
43- MMDBoneContent mmdBone;
44+ MMDBoneContent mmdBone = new MMDBoneContent();
45+ mmdBone.IKs = new List<int>();
4446 mmdBone.BindPose = QuatTransformContent.FromMatrix(bone.Transform);
4547 mmdBone.InverseBindPose = QuatTransformContent.FromMatrix(Microsoft.Xna.Framework.Matrix.Invert(bone.AbsoluteTransform));
4648 mmdBone.SkeletonHierarchy = bones.IndexOf(bone.Parent as BoneContent);
@@ -47,16 +49,24 @@
4749 if (bone.OpaqueData.ContainsKey("MMDBoneTag"))
4850 {
4951 MMDBoneTag tag = bone.OpaqueData["MMDBoneTag"] as MMDBoneTag;
50- if (tag != null && tag.ikParentBone != null)
52+ if (tag != null && tag.IKs.Count > 0)
5153 {
52- int index = bones.IndexOf(tag.ikParentBone);
53- mmdBone.IKParentBoneIndex = index >= 0 ? (ushort)index : (ushort)0;
54+ foreach (var ik in tag.IKs)
55+ {
56+ MMDIKContent mmdik = new MMDIKContent();
57+ mmdik.IKBoneIndex = bones.IndexOf(bone);
58+ mmdik.Iteration = ik.Iteration;
59+ mmdik.ControlWeight = ik.ControlWeight;
60+ foreach (var ikchild in ik.IKChildBones)
61+ {
62+ mmdik.IKChildBones.Add(bones.IndexOf(ikchild));
63+ }
64+ mmdBone.IKs.Add(mmdIKs.Count);
65+ mmdIKs.Add(mmdik);
66+ }
5467 }
55- else
56- mmdBone.IKParentBoneIndex =0;
5768 }
58- else
59- mmdBone.IKParentBoneIndex =0;
69+
6070 mmdBone.Name = bone.Name;
6171 mmdBones.Add(mmdBone);
6272 }
@@ -65,7 +75,7 @@
6575
6676 motionData = ProcessAnimations(skeleton.Animations, bones);
6777
68- return new MMDBoneManagerContent(mmdBones);
78+ return new MMDBoneManagerContent(mmdBones, mmdIKs);
6979 }
7080
7181 /// <summary>
--- branches/XNA4/MMDPipeline/Model/MMDBoneManagerContent.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDBoneManagerContent.cs (revision 662)
@@ -7,11 +7,13 @@
77 {
88 public class MMDBoneManagerContent
99 {
10- public MMDBoneContent[] bones;
10+ public List<MMDBoneContent> bones;
11+ public List<MMDIKContent> iks;
1112
12- public MMDBoneManagerContent(List<MMDBoneContent> bones)
13+ public MMDBoneManagerContent(List<MMDBoneContent> bones, List<MMDIKContent> iks)
1314 {
14- this.bones = bones.ToArray();
15+ this.bones = bones;
16+ this.iks = iks;
1517 }
1618 }
1719 }
--- branches/XNA4/MMDPipeline/Model/MMDBoneManagerWriter.cs (revision 661)
+++ branches/XNA4/MMDPipeline/Model/MMDBoneManagerWriter.cs (revision 662)
@@ -19,6 +19,7 @@
1919 protected override void Write(ContentWriter output, MMDBoneManagerContent value)
2020 {
2121 output.WriteObject(value.bones);
22+ output.WriteObject(value.iks);
2223 }
2324
2425 public override string GetRuntimeType(TargetPlatform targetPlatform)
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 661)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneManager.cs (revision 662)
@@ -2,16 +2,19 @@
22 using System.Collections.Generic;
33 using System.Linq;
44 using System.Text;
5+using System.Collections.ObjectModel;
56
67 namespace MikuMikuDance.XNA.Model
78 {
89 public class MMDBoneManager
910 {
10- MMDBone[] bones;
11+ ReadOnlyCollection<MMDBone> bones;
12+ ReadOnlyCollection<MMDIK> iks;
1113
12- public MMDBoneManager(MMDBone[] bones)
14+ public MMDBoneManager(List<MMDBone> bones, List<MMDIK> iks)
1315 {
14- this.bones = bones;
16+ this.bones = new ReadOnlyCollection<MMDBone>(bones);
17+ this.iks = new ReadOnlyCollection<MMDIK>(iks);
1518 }
1619 }
1720 }
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneManagerReader.cs (revision 661)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneManagerReader.cs (revision 662)
@@ -14,8 +14,9 @@
1414 {
1515 protected override MMDBoneManager Read(ContentReader input, MMDBoneManager existingInstance)
1616 {
17- MMDBone[] bones = input.ReadObject<MMDBone[]>();
18- return new MMDBoneManager(bones);
17+ List<MMDBone> bones = input.ReadObject<List<MMDBone>>();
18+ List<MMDIK> iks = input.ReadObject<List<MMDIK>>();
19+ return new MMDBoneManager(bones, iks);
1920 }
2021 }
2122 }
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDBone.cs (revision 661)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDBone.cs (revision 662)
@@ -3,6 +3,7 @@
33 using System.Linq;
44 using System.Text;
55 using MikuMikuDance.XNA.Misc;
6+using System.Collections.ObjectModel;
67
78 namespace MikuMikuDance.XNA.Model
89 {
@@ -9,18 +10,14 @@
910 /// <summary>
1011 /// ボーン構造体
1112 /// </summary>
12- public struct MMDBone
13+ public class MMDBone
1314 {
1415 /// <summary>
1516 /// ボーンの名前
1617 /// </summary>
1718 public readonly string Name;
19+
1820 /// <summary>
19- /// IKボーンの接続先(影響IKボーン)
20- /// </summary>
21- public readonly UInt16 IKParentBoneIndex;
22-
23- /// <summary>
2421 /// ボーンのバインドポーズ行列
2522 /// </summary>
2623 public readonly QuatTransform BindPose;
@@ -33,6 +30,10 @@
3330 /// </summary>
3431 /// <remarks>親が無い場合は-1</remarks>
3532 public readonly int SkeletonHierarchy;
33+ /// <summary>
34+ /// このボーンに対応するIKリスト
35+ /// </summary>
36+ public readonly ReadOnlyCollection<int> IKs;
3637
3738 /// <summary>
3839 /// ボーンのローカル変換行列
@@ -46,13 +47,13 @@
4647 /// <remarks>毎フレームごとにLocalTransformから計算され、上書きされる</remarks>
4748 public QuatTransform GlobalTransform;
4849
49- public MMDBone(string name, UInt16 ikParentBoneIndex, QuatTransform bindPose, QuatTransform inverseBindPose, int skeletonHierarchy)
50+ public MMDBone(string name, QuatTransform bindPose, QuatTransform inverseBindPose, int skeletonHierarchy, List<int> iks)
5051 {
5152 Name = name;
52- IKParentBoneIndex = ikParentBoneIndex;
5353 BindPose = bindPose;
5454 InverseBindPose = inverseBindPose;
5555 SkeletonHierarchy = skeletonHierarchy;
56+ IKs = new ReadOnlyCollection<int>(iks);
5657 LocalTransform = bindPose;
5758 GlobalTransform = QuatTransform.Identity;
5859 }
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDIK.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDIK.cs (revision 662)
@@ -0,0 +1,36 @@
1+using System;
2+using System.Collections.Generic;
3+using System.Linq;
4+using System.Text;
5+using System.Collections.ObjectModel;
6+
7+namespace MikuMikuDance.XNA.Model
8+{
9+ public class MMDIK
10+ {
11+ /// <summary>
12+ /// ターゲットIK番号
13+ /// </summary>
14+ public readonly int IKBoneIndex;
15+ /// <summary>
16+ /// 再帰演算回数
17+ /// </summary>
18+ public readonly UInt16 Iteration;
19+ /// <summary>
20+ /// IKの影響度
21+ /// </summary>
22+ public readonly float ControlWeight;
23+ /// <summary>
24+ /// K影響下のボーン番号
25+ /// </summary>
26+ public readonly ReadOnlyCollection<int> IKChildBones;
27+
28+ public MMDIK(int ikBoneIndex, UInt16 iteration, float controlWeight, List<int> ikChildBones)
29+ {
30+ IKBoneIndex = ikBoneIndex;
31+ Iteration = iteration;
32+ ControlWeight = controlWeight;
33+ IKChildBones = new ReadOnlyCollection<int>(ikChildBones);
34+ }
35+ }
36+}
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneReader.cs (revision 661)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDBoneReader.cs (revision 662)
@@ -17,10 +17,11 @@
1717 {
1818 QuatTransform bindPose = input.ReadObject<QuatTransform>();
1919 QuatTransform invPose = input.ReadObject<QuatTransform>();
20- ushort ikp = input.ReadUInt16();
20+ //ushort ikp = input.ReadUInt16();
2121 string name = input.ReadString();
2222 int sh = input.ReadInt32();
23- return new MMDBone(name, ikp, bindPose, invPose, sh);
23+ List<int> iks = input.ReadObject<List<int>>();
24+ return new MMDBone(name, bindPose, invPose, sh, iks);
2425 }
2526 }
2627 }
--- branches/XNA4/MikuMikuDanceXNA/Model/MMDIKReader.cs (nonexistent)
+++ branches/XNA4/MikuMikuDanceXNA/Model/MMDIKReader.cs (revision 662)
@@ -0,0 +1,24 @@
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+
8+namespace MikuMikuDance.XNA.Model
9+{
10+ /// <summary>
11+ /// MMDIKのタイプリーダ
12+ /// </summary>
13+ public class MMDIKReader : ContentTypeReader<MMDIK>
14+ {
15+ protected override MMDIK Read(ContentReader input, MMDIK existingInstance)
16+ {
17+ int ikBoneIndex = input.ReadInt32();
18+ ushort iteration = input.ReadUInt16();
19+ float controlWeight = input.ReadSingle();
20+ List<int> ikchild = input.ReadObject<List<int>>();
21+ return new MMDIK(ikBoneIndex, iteration, controlWeight, ikchild);
22+ }
23+ }
24+}
Show on old repository browser