+class Builder(object):
+ def __init__(self):
+ self.boneMap={}
+
+ def build(self, armature, bones):
+ 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())
+ if not name:
+ name=b.getName().encode(INTERNAL_ENCODING)
+ self.boneMap[name]=b
+
+ bone=Blender.Armature.Editbone()
+ bone.name=name
+ 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
+ if bone.name=="center_t":
+ # センターボーンは(0, 1, 0)の方向を向いていないと具合が悪い
+ parent.tail=parent.head+Mathutils.Vector(0, 1, 0)
+ bone.head=parent.tail
+ bone.tail=bone.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))
+ bone.tail = Mathutils.Vector(*convert_coord(b.tail))
+ if parent:
+ bone.parent=parent
+ if parent.tail==bone.head:
+ bone.options=[Blender.Armature.CONNECTED]