X-Git-Url: http://git.osdn.jp/view?a=blobdiff_plain;f=swig%2Fblender25%2Fimport_anim_vmd.py;h=923fb34654ced30c8f02b01a18807034c49f384a;hb=4b7b856e70fe8047f985e2598020032d0d87a672;hp=d24d9fa68011c79f3965259276adea2614d0907e;hpb=02f6ac3b41048c7d9d68c186af74530529a9ffcb;p=meshio%2Fmeshio.git diff --git a/swig/blender25/import_anim_vmd.py b/swig/blender25/import_anim_vmd.py index d24d9fa..923fb34 100644 --- a/swig/blender25/import_anim_vmd.py +++ b/swig/blender25/import_anim_vmd.py @@ -8,7 +8,8 @@ vmd Importer 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 @@ -60,21 +61,11 @@ def import_motion_key(l, o): 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 @@ -141,39 +132,39 @@ def IPO_CURVE_get_or_create(ipo, name): 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