OSDN Git Service

fix bone tail.
authorousttrue <ousttrue@gmail.com>
Sun, 30 May 2010 01:18:28 +0000 (10:18 +0900)
committerousttrue <ousttrue@gmail.com>
Sun, 30 May 2010 01:18:28 +0000 (10:18 +0900)
swig/blender24/pmd_import.py

index 105ec0c..eaa2915 100644 (file)
@@ -41,6 +41,9 @@ else:
 MMD_SHAPE_GROUP_NAME='_MMD_SHAPE'
 
 
+###############################################################################
+# ProgressBar
+###############################################################################
 class ProgressBar(object):
     def __init__(self, base):
         print "#### %s ####" % base
@@ -85,6 +88,9 @@ def progress_set(message, progress):
     progressBar.set(message, progress)
 
 
+###############################################################################
+# functions
+###############################################################################
 def convert_coord(pos):
     """
     Left handed y-up to Right handed z-up
@@ -331,16 +337,6 @@ def import16MaerialAndMesh(mesh, l, material_order, face_map, tex_dir):
     return vertex_map
 
 
-def validParent(parent):
-    if parent==None:
-        return False
-    if parent.name.startswith("arm twist"):
-        return False
-    if parent.name.startswith("wrist twist"):
-        return False
-    return True
-
-
 class Builder(object):
     def __init__(self):
         self.boneMap={}
@@ -356,55 +352,34 @@ class Builder(object):
             name=b.getName().encode(INTERNAL_ENCODING)
         self.boneMap[name]=b
 
-        if b.tail_index==0:
-            return
-
         bone=Blender.Armature.Editbone()
         bone.name=name
-        armature.bones[name] = bone
-
-        #if bone.name=='center':
-        if False:
-            # center
-            pos=Mathutils.Vector(*convert_coord(b.pos))
-            bone.tail = pos
-            bone.head = pos-Mathutils.Vector(0, 0.01, 0)
+        armature.bones[name]=bone
+
+        if b.tail_index==0:
+            # 先端
+            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)
+            assert(parent)
+            bone.parent=parent
+            assert(parent.tail==bone.head)
+            bone.options=[Blender.Armature.CONNECTED]
+            bone.layerMask = (1<<1)
         else:
             bone.head = Mathutils.Vector(*convert_coord(b.pos))
             bone.tail = Mathutils.Vector(*convert_coord(b.tail))
-
-            if validParent(parent):
+            if parent:
                 bone.parent=parent
                 if parent.tail==bone.head:
-                    bone.parent=parent
                     bone.options=[Blender.Armature.CONNECTED]
 
-            if bone.head==bone.tail:
-                bone.tail=bone.head-Mathutils.Vector(0, 1, 0)
+        if bone.head==bone.tail:
+            bone.tail=bone.head-Mathutils.Vector(0, 1, 0)
 
         for c in b.children:
             self.__build(armature, c, b, bone)
 
-    def connect(self, armature):
-        def getKey(index):
-            for key, value in self.boneMap.items():
-                if index==value.index:
-                    return key
-
-        for k, b in self.boneMap.items():
-            if b.tail_index==0:
-                continue
-            bone=armature.bones[k]
-            key=getKey(b.tail_index)
-            if not key:
-                return
-            try:
-                tail=armature.bones[key]
-                # connect
-                tail.parent=bone
-                tail.options=[Blender.Armature.CONNECTED]
-            except:
-                pass
 
 def importArmature(scene, l):
     # create armature
@@ -428,7 +403,6 @@ def importArmature(scene, l):
 
     builder=Builder()
     builder.build(armature, l.bones)
-    builder.connect(armature)
 
     armature.update()