def draw(obj, context): o = context.selected_objects[0] for func, new_name in ( (lambda t: t, "spl"), (lambda t: t**3, "spl_t3"), (lambda t: t**6, "spl_t6"), (lambda t: np.sin(t), "spl_sint"), (lambda t: np.cos(t), "spl_cost"), (lambda t: t - 2.5, "spl_trans"), ): spline = DeCasteljau(*[ k.co for k in o.data.vertices], func = func) ts = np.linspace(0,1, obj['tsteps']) verts = [ tuple(spline(t)) for t in ts ] replace_mesh(context, new_name, verts, related_obj = o)
def draw(obj, context): o = context.selected_objects[0] for func, new_name in ( (lambda t: t, "spl"), (lambda t: t**3, "spl_t3"), (lambda t: t**6, "spl_t6"), (lambda t: np.sin(t), "spl_sint"), (lambda t: np.cos(t), "spl_cost"), (lambda t: t - 2.5, "spl_trans"), ): spline = DeCasteljau(*[k.co for k in o.data.vertices], func=func) ts = np.linspace(0, 1, obj['tsteps']) verts = [tuple(spline(t)) for t in ts] replace_mesh(context, new_name, verts, related_obj=o)
def draw(obj, context): """Always called when one of the parameters changes. Removes any existing Blossom object and redraws it. Uses the currently selected object as the 3 Points to interpolate in between. The z coordinate is ignored """ # Use the currently selected object as the 3 Points to interpolate in between new_name = context.select_objects[0].name + "_blossom" # Generate the vertices for the Blossom b = Blossom(*[(p.co[0],p.co[1]) for p in o.data.vertices]) ts = np.linspace(0,1, obj['tsteps']) ss = np.linspace(0,1, obj['ssteps']) verts = [ tuple(b(s,t)) + (0,) for s in ss for t in ts ] replace_mesh(context, new_name, verts, related_obj = o)
def subdivision_polygon(context, pts, t, name): bl = Blossom(*pts) cis = [] n = len(pts) - 1 for i in range(n+1): ts = (0,)*(n-i) + (t,)*i cis.append(bl(*ts)) verts = [ tuple(v) for v in cis ] edges = [ (i,i+1) for i in range(len(verts)-1) ] return replace_mesh(context, name, verts, edges)
def draw(obj, context): scn = bpy.context.scene o = context.selected_objects[0] draw_spline(context, o, o.name + "_spline") pts = [k.co for k in o.data.vertices] new_pts = find_best_approximation(pts) new_poly = replace_mesh(context, o.name + "_reduced_poly", new_pts, [ (i-1,i) for i in range(1, len(new_pts)) ], related_obj = o) draw_spline(context, new_poly, new_poly.name + "_spline")
def draw(obj, context): scn = bpy.context.scene o = context.selected_objects[0] draw_spline(context, o, o.name + "_spline") pts = [k.co for k in o.data.vertices] new_pts = find_best_approximation(pts) new_poly = replace_mesh(context, o.name + "_reduced_poly", new_pts, [(i - 1, i) for i in range(1, len(new_pts))], related_obj=o) draw_spline(context, new_poly, new_poly.name + "_spline")
def draw_spline(context, o, name): pts = [ k.co for k in o.data.vertices] s = DeCasteljauBezier(*pts) ts = np.linspace(0,1,100) verts = [ tuple(s(t)) for t in ts ] replace_mesh(context, name, verts, related_obj = o)