OSDN Git Service

fix IK.
authorousttrue <ousttrue@gmail.com>
Sun, 30 May 2010 02:44:01 +0000 (11:44 +0900)
committerousttrue <ousttrue@gmail.com>
Sun, 30 May 2010 02:44:01 +0000 (11:44 +0900)
swig/blender24/pmd_import.py
swig/blender24/vmd_import.py
swig/englishmap.py

index eaa2915..5af4cec 100644 (file)
@@ -345,6 +345,7 @@ class Builder(object):
         for b in bones:
             if not b.parent:
                 self.__build(armature, b, None, None)
+        armature.update()
 
     def __build(self, armature, b, p, parent):
         name=englishmap.getEnglishBoneName(b.getName())
@@ -360,11 +361,16 @@ class Builder(object):
             # 先端
             assert(b.type==6 or b.type==7)
             bone.head = Mathutils.Vector(*convert_coord(b.pos))
-            bone.tail=bone.head-Mathutils.Vector(0, 1, 0)
+            bone.tail=bone.head+Mathutils.Vector(0, 1, 0)
             assert(parent)
             bone.parent=parent
-            assert(parent.tail==bone.head)
+            if bone.name=="center_t":
+                # センターボーンは(0, 1, 0)の方向を向いていないと具合が悪い
+                parent.tail=parent.head+Mathutils.Vector(0, 1, 0)
+            else:
+                assert(parent.tail==bone.head)
             bone.options=[Blender.Armature.CONNECTED]
+            # armature layer 2
             bone.layerMask = (1<<1)
         else:
             bone.head = Mathutils.Vector(*convert_coord(b.pos))
@@ -375,7 +381,7 @@ class Builder(object):
                     bone.options=[Blender.Armature.CONNECTED]
 
         if bone.head==bone.tail:
-            bone.tail=bone.head-Mathutils.Vector(0, 1, 0)
+            bone.tail=bone.head+Mathutils.Vector(0, 1, 0)
 
         for c in b.children:
             self.__build(armature, c, b, bone)
@@ -394,6 +400,7 @@ def importArmature(scene, l):
             armature_object.drawMode | Blender.Object.DrawModes.XRAY)
     # armature settings
     armature.drawType = Blender.Armature.OCTAHEDRON
+    armature.drawNames=True
     armature.envelopes = False
     armature.vertexGroups = True
     armature.mirrorEdit = True
@@ -401,11 +408,12 @@ def importArmature(scene, l):
     # create armature
     armature.makeEditable()
 
+    ############################################################
+    # build bone
+    ############################################################
     builder=Builder()
     builder.build(armature, l.bones)
 
-    armature.update()
-
     ############################################################
     # IK
     ############################################################
@@ -414,8 +422,7 @@ def importArmature(scene, l):
     for ik in l.ik_list:
         # IKtarget->parent(=IK).name
         target=l.bones[ik.target]
-        parent=l.bones[target.parent_index]
-        name = englishmap.getEnglishBoneName(parent.getName())
+        name = englishmap.getEnglishBoneName(target.getName())
         p_bone = pose.bones[name]
         if not p_bone:
             print 'not found', name
@@ -424,26 +431,18 @@ def importArmature(scene, l):
             print 'over MAX_CHAINLEN', ik, len(ik.children)
             continue
         # IK solver
-        ik_const = p_bone.constraints.append(Blender.Constraint.Type.IKSOLVER)
-        ik_const[cSetting.CHAINLEN] = len(ik.children)
-        ik_const[cSetting.TARGET] = armature_object
+        ik_solver = p_bone.constraints.append(Blender.Constraint.Type.IKSOLVER)
+        ik_solver[cSetting.CHAINLEN] = len(ik.children)
+        ik_solver[cSetting.TARGET] = armature_object
 
         effector_name=englishmap.getEnglishBoneName(
                 l.bones[ik.index].getName())
         if not effector_name:
             effector_name=l.bones[ik.index].getName()
 
-        ik_const[cSetting.BONE] = effector_name
-        ik_const[cSetting.ITERATIONS]=ik.iterations
-        ik_const.influence = ik.weight
-        # Limit ROT
-        #lrot_const = p_bone.constraints.append(Blender.Constraint.Type.LIMITROT)
-        #lrot_const[cSetting.OWNERSPACE] = cSetting.SPACE_LOCAL
-        #lrot_const[cSetting.LIMIT] = (cSetting.LIMIT_XROT | cSetting.LIMIT_ZROT)
-        #lrot_const[cSetting.XMIN] = 0.1
-        #lrot_const[cSetting.XMAX] = 180
-        #lrot_const[cSetting.ZMIN] = 180 - 0.1
-        #lrot_const[cSetting.ZMAX] = 0
+        ik_solver[cSetting.BONE]=effector_name
+        #ik_solver.influence=ik.weight
+        ik_solver[cSetting.USETIP]=False
 
     armature.makeEditable()
     armature.update()
@@ -577,7 +576,6 @@ def run(filename):
     armature_object=importArmature(scene, l)
     if armature_object:
         armature = armature_object.getData()
-        armature.drawNames=True
         root.makeParent([armature_object])
 
         # add armature modifier
@@ -585,18 +583,23 @@ def run(filename):
             mod=o.modifiers.append(Blender.Modifier.Types.ARMATURE)
             mod[Blender.Modifier.Settings.OBJECT] = armature_object
             mod[Blender.Modifier.Settings.ENVELOPES] = False
-            o.makeDisplayList()
+            #o.makeDisplayList()
 
         ############################################################
         # Limitation
         ############################################################
         for n, b in armature_object.getPose().bones.items():
+            if n.endswith("_t"):
+                continue
+
             if n.startswith("knee_"):
                 b.lockYRot=True
                 b.lockZRot=True
                 b.limitX=True
                 b.limitMin=[0, 0, 0]
                 b.limitMax=[180, 0, 0]
+            elif n.startswith("ankle_"):
+                b.lockYRot=True
 
     # redraw
     scene.update(0)
index a000f37..88d80b5 100644 (file)
@@ -123,7 +123,11 @@ def import_motion_key(l, o, progressCount):
     last_frame=0
     for n in l.boneKeys:
         keyFrames=l.getBoneKeyFrameList(n)
-        boneName=englishmap.getEnglishBoneName(n).encode(INTERNAL_ENCODING)
+        try:
+            boneName=englishmap.getEnglishBoneName(n).encode(INTERNAL_ENCODING)
+        except:
+            print(n)
+            assert(False)
         try:
             poseBone=pose.bones[boneName]
             bone=armature.bones[boneName]
index 6217593..0f4a305 100644 (file)
@@ -133,8 +133,8 @@ boneMap=[
 ("hair IK_R_t", "右髪IK先"),
 ("leg IK_L_t", "左足IK先"),
 ("leg IK_R_t", "右足IK先"),
-("toe IK_L_t", "左つま先IK先"),
-("toe IK_R_t", "右つま先IK先"),
+("toe IK_L_t", "左つま先IK先"),
+("toe IK_R_t", "右つま先IK先"),
 ("front hair1_t", "前髪1先"),
 ("front hair2_t", "前髪2先"),
 ("front hair3_t", "前髪3先"),