OSDN Git Service

MqoBone#turned
authornomeu <nomeu@nomeu.org>
Wed, 28 Jan 2015 13:33:04 +0000 (22:33 +0900)
committernomeu <nomeu@nomeu.org>
Wed, 28 Jan 2015 13:33:04 +0000 (22:33 +0900)
MqxFile.cs
MqxReader.cs

index 61875e6..54d9e71 100644 (file)
@@ -30,11 +30,18 @@ namespace Tso2MqoGui
 
         public Point3 world_position;
         public Point3 local_position;
+        public bool turned;
+        public bool world_turned;
         public Matrix44 matrix
         {
             get
             {
                 Matrix44 m = Matrix44.Identity;
+                if (turned)
+                {
+                    m.m11 = -1.0f;
+                    m.m33 = -1.0f;
+                }
                 m.m41 = local_position.x;
                 m.m42 = local_position.y;
                 m.m43 = local_position.z;
index c9a610e..ee0eeb7 100644 (file)
@@ -61,6 +61,25 @@ namespace Tso2MqoGui
                 bone_idmap[bone.id] = bone;
             }
         }
+
+        Dictionary<string, bool> bone_turnedmap;
+
+        void CreateBoneTurnedMap()
+        {
+            bone_turnedmap = new Dictionary<string, bool>();
+            using (StreamReader reader = new StreamReader(@"turned.txt"))
+            {
+                while (true)
+                {
+                    string line = reader.ReadLine();
+
+                    if (line == null)
+                        break;
+
+                    bone_turnedmap[line] = true;
+                }
+            }
+        }
         void UpdateBones()
         {
             // assign node.parent
@@ -83,12 +102,32 @@ namespace Tso2MqoGui
                 else
                     bone.path = "|" + bone.name;
             }
+            // assign node.turned
+            foreach (MqoBone bone in bones)
+            {
+                bone.turned = bone_turnedmap.ContainsKey(bone.name);
+            }
+            // assign node.world_turned
+            foreach (MqoBone bone in bones)
+            {
+                if (bone.parent != null)
+                {
+                    bone.world_turned = bone.parent.world_turned ^ bone.turned;
+                }
+                else
+                    bone.world_turned = bone.turned;
+            }
             // assign node.local_position
             foreach (MqoBone bone in bones)
             {
                 if (bone.parent != null)
                 {
                     bone.local_position = bone.world_position - bone.parent.world_position;
+                    if (bone.parent.world_turned)
+                    {
+                        bone.local_position.x = -bone.local_position.x;
+                        bone.local_position.z = -bone.local_position.z;
+                    }
                 }
                 else
                     bone.local_position = bone.world_position;
@@ -123,6 +162,7 @@ namespace Tso2MqoGui
             Array.Resize(ref bones, len);
 
             CreateBoneMap();
+            CreateBoneTurnedMap();
             UpdateBones();
 
             while (reader.IsStartElement("Obj"))