MMD_SHAPE_GROUP_NAME='_MMD_SHAPE'
+###############################################################################
+# ProgressBar
+###############################################################################
class ProgressBar(object):
def __init__(self, base):
print "#### %s ####" % base
progressBar.set(message, progress)
+###############################################################################
+# functions
+###############################################################################
def convert_coord(pos):
"""
Left handed y-up to Right handed z-up
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={}
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
builder=Builder()
builder.build(armature, l.bones)
- builder.connect(armature)
armature.update()