[Bf-python] shape key animation on a bez curve (blender2.5)

Goat Man goatman.py at gmail.com
Fri Jul 16 05:54:31 CEST 2010


This script creates a bezier curve and tries to add shape animation to it.
 Operators are command line safe, so it works by ./blender -P script.py
Problem is the handles of the first few bez points shoot off to infinity
when the shapekey is viewed.
Not sure if this is a bug or i am just not using the API correctly.


import bpy, random, sys for o in bpy.data.objects: o.selected=False
bpy.context.scene.update() scn = bpy.context.scene data =
bpy.data.curves.new(name='brain', type='CURVE') for i in range(2): spline =
data.splines.new('BEZIER') bez = spline.bezier_points[-1] bez.co.x = i * 0.4
for j in range(3): x = i * 0.4; y = j * 0.1 spline.bezier_points.add() bez =
spline.bezier_points[-1] bez.co.x = x bez.co.y = y bez.handle1.x = i * 0.4 +
random.uniform(-.1,.1) bez.handle1.y = j * 0.1 + random.uniform(-.1,.1)
bez.handle2.x = i * 0.4 + random.uniform(-.1,.1) bez.handle2.y = j * 0.1 +
random.uniform(-.1,.1) bez.selected_control_point = bez.selected_handle1 =
bez.selected_handle2 = True # and 2 = Vector, what is bez.radius?
bpy.context.scene.update() obj = bpy.data.objects.new(name='brain',
object_data=data) bpy.context.scene.objects.link(obj)
bpy.context.scene.objects.active = obj print( dir(obj.data) ) print(
obj.data.shape_keys ) bpy.ops.object.shape_key_add() print(
dir(obj.data.shape_keys) ) sk = obj.data.shape_keys sk.relative = True print
( dir(sk.keys) ) print ( sk.keys ) bias = sk.keys[0] print ( dir(bias) )
print (bias.name, bias.relative_key) print ( bias.data )
bpy.ops.object.shape_key_add() bpy.context.scene.update() ## modify the
first shape key data - strange results when then shape is viewed, handles go
off into infinity shape = sk.keys[-1] for i,bez in enumerate( shape.data ):
bbez = bias.data[ i ] #bez.co.x = 1.0 #bez.co.y = .0 #bez.co.z = .0 print(
bbez.co, bez.co ) bez.co.x = -bbez.co.x bez.co.y = -bbez.co.y bez.co.z =
-bbez.co.z
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20100716/f235d232/attachment.html>


More information about the Bf-python mailing list