#!BPY """ Name: 'Game Engine Path Baker' Blender: 242 Group: 'Misc' Tooltip: 'Bake a path animation to and object's Ipo' """ __author__= "Timothy Wakeham" __url__= ["blender.org", "blenderartists.org"] __version__= "1.0" __bpydoc__= """\ This script bakes a path animation to an object's Ipo, for use in the game engine Usage: Modify the User variables as fits your application, and run from text window. """ # User edit stuff here ################################## #number of steps between each controlpoint res = 25 #object to make follow path bake_ob = 'Camera' #number of frames each step takes step_time = 1 #start frame start = 0 # End user edit stuff ################################### import Blender def coeff(p0, p1, p2, p3): co = [] for x in range(3): cx = 3 * (p1[x] - p0[x]) bx = 3 * (p2[x] - p1[x]) - cx ax = p3[x] - p0[x] - cx - bx co.append([ax, bx, cx]) return co def eval_curve(o, co, t): p = [] t2 = t*t for x in range(3): val = co[x][0] * t2 * t + co[x][1] * t2 + co[x][2] * t + o[x] p.append(val) return p obj = Blender.Object.GetSelected()[0] if obj.getType() <> 'Curve': Blender.Draw.PupMenu('Please select path to bake%t|Ok') raise curve = obj.getData() points = curve[0] num_points = len(points) frame = start step = 1.0 / res obj = Blender.Object.Get(bake_ob) ipo = Blender.Ipo.New('Object', 'Path') lx = ipo.addCurve('LocX') ly = ipo.addCurve('LocY') lz = ipo.addCurve('LocZ') for idx in range(num_points - 1): b0 = points[idx].getTriple() b1 = points[idx + 1].getTriple() p0 = b0[1] p1 = b0[2] p2 = b1[0] p3 = b1[1] co = coeff(p0, p1, p2, p3) for t in range(res): p = eval_curve(p0, co, step * t) lx[frame] = p[0] ly[frame] = p[1] lz[frame] = p[2] frame += step_time obj.setIpo(ipo)