Created
August 10, 2011 12:45
-
-
Save zeffii/1136715 to your computer and use it in GitHub Desktop.
scripting shapekey blender 2.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
print_divider() | |
# Milestone 2 | |
# make several shape keys | |
shape_iterator = 0 | |
shapes = vectorize_list(shapes) | |
for shape in shapes: | |
print("----") | |
shapename = "frame"+str(shape_iterator) | |
active_shape = polyface.shape_key_add(shapename) | |
polyface.active_shape_key_index = shape_iterator | |
iterator = 0 | |
for i in bpy.context.object.active_shape_key.data: | |
print(">", i.co) | |
print(">", shape[iterator]) | |
iterator += 1 | |
shape_iterator += 1 | |
# code snips | |
# bpy.ops.anim.change_frame(frame=current_frame) | |
# bpy.context.active_object.data.shape_keys | |
# me.shape_keys.key_blocks['Key 1'].keyframe_insert( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment