[Bf-python] vertex animation in blender 2.5 / shapekeys
Campbell Barton
ideasman42 at gmail.com
Tue May 24 08:57:50 CEST 2011
# Assuming you added 2 shape keys to the active cube
bpy.context.object.data.shape_keys.key_blocks["Key 1"].value = 0.5
bpy.context.object.data.shape_keys.key_blocks["Key 1"].keyframe_insert("value")
For more info on keyframing see:
http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.bpy_struct.html#bpy.types.bpy_struct.keyframe_insert
On Mon, May 23, 2011 at 10:21 AM, sc3sc3 . <sc3sc3 at gmail.com> wrote:
>
> hi
>
> sorry about crossposting
>
> actually it concerns this question
> http://blenderartists.org/forum/showthread.php?219358-vertex-animation-in-blender-2.5
>
> but noone apparently has an answer
> so i hope to find it here
>
>
> does anybody have a simple example concerning animating vertices ( shapekeys
> ) ?
>
> http://wiki.blender.org/index.php/Dev:2.5/Py/Scripts/Cookbook/Code_snippets/Meshes#Vertex_groups_and_shapekeys
> there is for example this script
> but how does one introduce the next step
> and actually animating those shapekeys through python ?
> i tried all kinds of ways of adding keyframes on the timeline but of no
> avail :-(
>
>
> #----------------------------------------------------------
> # File shapekey.py
> #----------------------------------------------------------
> import bpy, random
>
> def run(origin):
> # Add UV sphere
> bpy.ops.mesh.primitive_uv_sphere_add(
> segments=6, ring_count=5, size=1, location=origin)
> ob = bpy.context.object
> ob.name = 'ShapeKeyObject'
> ob.show_name = True
>
> # Create Left and Right vertex groups
> left = ob.vertex_groups.new('Left')
> right = ob.vertex_groups.new('Right')
> for v in ob.data.vertices:
> if v.co[0] > 0.001:
> left.add([v.index], 1.0, 'REPLACE')
> elif v.co[0] < -0.001:
> right.add([v.index], 1.0, 'REPLACE')
> else:
> left.add([v.index], 0.5, 'REPLACE')
> right.add([v.index], 0.5, 'REPLACE')
>
> # Add Basis key
> bpy.ops.object.shape_key_add(None)
> basis = ob.active_shape_key
>
> # Add FrontForward key: front verts move one unit forward
> # Slider from -1.0 to +2.0
> bpy.ops.object.shape_key_add(None)
> frontFwd = ob.active_shape_key
> frontFwd.name = 'FrontForward'
> frontFwd.slider_min = -1.0
> frontFwd.slider_max = 2.0
> for v in [19, 20, 23, 24]:
> pt = frontFwd.data[v].co
> pt[1] = pt[1] - 1
>
> # Add TopUp keys: top verts move one unit up. TopUp_L and
> # TopUp_R only affect left and right halves, respectively
> keylist = [(None, ''), ('Left', '_L'), ('Right', '_R')]
> for (vgrp, suffix) in keylist:
> bpy.ops.object.shape_key_add(None)
> topUp = ob.active_shape_key
> topUp.name = 'TopUp' + suffix
> if vgrp:
> topUp.vertex_group = vgrp
> for v in [0, 1, 9, 10, 17, 18, 25]:
> pt = topUp.data[v].co
> pt[2] = pt[2] + 1
>
> # Pose shape keys
> for shape in ob.data.shape_keys.key_blocks:
> shape.value = random.random()
> return
>
> if __name__ == "__main__":
> # Create five object with random shapekeys
> for j in range(5):
> run((3*j,0,0))
>
>
>
> thanks for any help
> kind regards
> sc3*2
>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
>
>
--
- Campbell
More information about the Bf-python
mailing list