return true;
}
+ Dictionary<int, MqoBone> bone_idmap;
+
+ // create bone_idmap
+ // map id to bone
+ void CreateBoneMap()
+ {
+ bone_idmap = new Dictionary<int, MqoBone>();
+ foreach (MqoBone bone in bones)
+ {
+ bone_idmap[bone.id] = bone;
+ }
+ }
+ void UpdateBones()
+ {
+ // assign node.parent
+ foreach (MqoBone bone in bones)
+ {
+ if (bone.pid != 0)
+ {
+ bone.parent = bone_idmap[bone.pid];
+ }
+ else
+ bone.parent = null;
+ }
+ // assign node.path
+ foreach (MqoBone bone in bones)
+ {
+ if (bone.parent != null)
+ {
+ bone.path = bone.parent.path + "|" + bone.name;
+ }
+ else
+ bone.path = "|" + bone.name;
+ }
+ // assign node.local_position
+ foreach (MqoBone bone in bones)
+ {
+ if (bone.parent != null)
+ {
+ bone.local_position = bone.world_position - bone.parent.world_position;
+ }
+ else
+ bone.local_position = bone.world_position;
+ }
+ }
+
public void Read(XmlReader reader)
{
reader.Read();
int i = 0;
while (reader.IsStartElement("Bone"))
{
- MqoBone bone = new MqoBone();
+ MqoBone bone = new MqoBone(i);
bone.Read(reader);
this.bones[i++] = bone;
}
reader.ReadEndElement();//BoneSet
+ len = i;
+ Array.Resize(ref bones, len);
+
+ CreateBoneMap();
+ UpdateBones();
+
while (reader.IsStartElement("Obj"))
{
//Console.WriteLine("Obj");
}
foreach (MqoBone bone in bones)
{
- if (bone == null)
- continue;
-
foreach (MqoWeit weit in bone.weits)
{
Dictionary<int, List<MqoWeit>> map = weitmap[weit.object_id];
for (int i = 0; i < len; ++i)
{
- this.weits[i].bone_id = weits[i].bone_id;
+ this.weits[i].node_id = weits[i].node_id;
this.weits[i].weit = weits[i].weit;
}
for (int i = len; i < 4; ++i)
{
- this.weits[i].bone_id = 1;
+ this.weits[i].node_id = 0;
this.weits[i].weit = 0.0f;
}
}