Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created August 9, 2011 13:45
Show Gist options
  • Save zeffii/1134077 to your computer and use it in GitHub Desktop.
Save zeffii/1134077 to your computer and use it in GitHub Desktop.
i dont understand how to script keyframe ShapeKeys
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))]
]
# 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)
# make ShapeKeys()
# bpy.ops.anim.change_frame(frame=current_frame)
# bpy.ops.object.shape_key_add(from_mix=False)
# bpy.ops.anim.keyframe_insert(type='key_blocks["Key 1"]', value=1.0)
# bpy.context.active_object.data.shape_keys
# me.shape_keys.key_blocks['Key 1'].keyframe_insert(
# polyface.shape_key_add()
# Milestone 2
# make several shape keys
bpy.context.scene.objects.active = bpy.data.objects["NameOfMyCurveObject"]
polyface = bpy.context.active_object
'''
print("="*40)
print("="*40)
# turn tuple list into vector list.
shapes_as_vectors = []
for shape in shapes:
shape_points = []
for i in shape:
shape_points.append(Vector(i))
shapes_as_vectors.append(shape_points)
for shape in shapes_as_vectors:
print(shape)
# dest = [point.co for point in polyface.data.splines[0].points]
# dest = shape
this_shape = polyface.shape_key_add()
shape_points = [i.co for i in this_shape.data]
shape_points = shape
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment