Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created August 11, 2011 13:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/1139684 to your computer and use it in GitHub Desktop.
Save zeffii/1139684 to your computer and use it in GitHub Desktop.
scripted keyframing of curve coordinates in blender
import bpy
from mathutils import Vector
listOfVectors = [((0,0,0,1)),((1,0,0,1)),((1,1,0,1)),((0,1,0,1))]
shapes = [ [((0,0,0,1)),((1,0,0,1)),((1,1,0,1)),((0,1,0,1))],
[((0,0,0,1)),((2,0,0,1)),((1,1,0,1)),((0,1,0,1))],
[((0,0,0,1)),((1,0,0,1)),((1,2,0,1)),((0,1,0,1))],
[((0,0,0,1)),((1,0,0,1)),((1,1,0,1)),((-1,1,0,1))]
]
def print_divider():
print()
print("="*40)
# turn tuple list into vector list.
def vectorize_list(shapes):
shapes_as_vectors = []
for shape in shapes:
shape_points = []
for i in shape:
shape_points.append(Vector(i))
shapes_as_vectors.append(shape_points)
return shapes_as_vectors
# create a spline curve from a number of points
def MakePolyFace(objname, curvename, cList):
curvedata = bpy.data.curves.new(name=curvename, type='CURVE')
curvedata.dimensions = '2D'
objectdata = bpy.data.objects.new(objname, curvedata)
objectdata.location = (0,0,0) #object origin
bpy.context.scene.objects.link(objectdata)
polyline = curvedata.splines.new('POLY')
polyline.points.add(len(cList)-1)
for num in range(len(cList)):
polyline.points[num].co = (cList[num])
polyline.order_u = len(polyline.points)-1
polyline.use_endpoint_u = True
polyline.use_cyclic_u = True
MakePolyFace("NameOfMyCurveObject", "NameOfMyCurve", listOfVectors)
# set shape to active, and select it
bpy.context.scene.objects.active = bpy.data.objects["NameOfMyCurveObject"]
polyface = bpy.context.active_object
polyface.select = True
bpy.ops.object.mode_set(mode = 'EDIT')
shapes = vectorize_list(shapes)
frame_num = 0
Spline = polyface.data.splines[0]
for shape in shapes:
bpy.context.scene.frame_set(frame_num)
iterator = 0
for coord in Spline.points:
coord.co = shape[iterator]
coord.keyframe_insert('co')
iterator += 1
frame_num += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment