This script imports a vmd into Blender for editing.
0.1 2010/05/15 first implement.
-0.2 2010/05/16 implement bone motion.
+0.2 2010/05/16 implement bone animation.
+0.3 2010/05/16 implement shape key animation.
'''
import bpy
armRotate=bone.matrix_local.rotation_part()
# quat
armRotateQuaternion=armRotate.to_quat()
- #if armRotateQuaternion.w<0:
- # armRotateQuaternion.w=-armRotateQuaternion.w
- # armRotateQuaternion.x=-armRotateQuaternion.x
- # armRotateQuaternion.y=-armRotateQuaternion.y
- # armRotateQuaternion.z=-armRotateQuaternion.z
# inv
armRotateInv=mathutils.Matrix(armRotate).transpose()
# quat
armRotateInvQuaternion=armRotateInv.to_quat()
- #if armRotateInvQuaternion.w<0:
- # armRotateInvQuaternion.w=-armRotateInvQuaternion.w
- # armRotateInvQuaternion.x=-armRotateInvQuaternion.x
- # armRotateInvQuaternion.y=-armRotateInvQuaternion.y
- # armRotateInvQuaternion.z=-armRotateInvQuaternion.z
reverseFlag=False
lastQ=None
return ipo.addCurve(name)
-def import_shape_key(l, mesh):
- print('import_shape_key: %s' % mesh.name)
- return 0
- # ToDo
- key = mesh.getData().key
- if key is None:
- Draw.PupMenu('selecting mesh not has a Key')
- return
- # get or create IPO
- ipo = key.getIpo()
- if ipo == None:
- ipo = Blender.Ipo.New("Key", "ShapeKey")
- key.ipo = ipo
+def getKey(mesh, name):
+ for shapeKey in mesh.shape_keys.keys:
+ if shapeKey.name==name:
+ return shapeKey
+
+
+def import_shape_key(l, meshObject):
+ print('import_shape_key: %s' % meshObject.name)
# insert shape keys
counter=0
last_frame=0
+
for n in l.morphKeys:
keyFrames=l.getMorphKeyFrameList(n)
if n=='base':
continue
name=englishmap.getEnglishSkinName(n)
- try:
- curve=IPO_CURVE_get_or_create(ipo, name)
- except NameError as msg:
- print(NameError, msg)
- print(n, name)
+ if not name:
+ name=n
+
+ shapeKey=getKey(meshObject.data, name)
+
+ if not shapeKey:
+ print("not found shapeKey: %s" % name)
continue
- curve.interpolation = Blender.IpoCurve.InterpTypes.LINEAR
- for i in xrange(len(keyFrames.list)):
+
+ for i in range(len(keyFrames.list)):
key=keyFrames.getKey(i)
+ shapeKey.value=key.weight
frame=keyFrames.getFrame(i)
- curve[frame]=key.weight
+ shapeKey.keyframe_insert("value", -1, frame)
+
last_frame=max(last_frame, frame)
counter+=1