def create_curve(self, ctx, guides, parent): if len(guides) > 1: name = parent.name + "_Hair_Guide" newcurve = bpy.data.curves.new(name, type='CURVE') newcurve.dimensions = '3D' curve = bpy.data.curves[newcurve.name] curve.splines.clear() for guide in guides: count = len(guide) newspline = curve.splines.new('BEZIER') newspline.bezier_points.add(count-1) for i in range(count): first, last, co = (i == 0), (i == count-1), guide[i] bez = newspline.bezier_points[i] handle_type = 'VECTOR' if first or last else 'AUTO' bez.co = co bez.handle_left = self.center_of(co, guide[i+1]) if first else co bez.handle_left_type = handle_type bez.handle_right = co if last else self.center_of(co, guide[i-1]) bez.handle_right_type = handle_type curve = bpy.data.objects.new(name, newcurve) link_to_scene(ctx, curve) curve.location = parent.location curve.rotation_euler = parent.rotation_euler curve.scale = parent.scale
def create_empty_mesh_object(self, ctx): newmesh = bpy.data.meshes.new("temp_mesh") newmesh.from_pydata([], [], []) newmesh.update(calc_edges=True) owner = bpy.data.objects.new("Blabla", newmesh) link_to_scene(ctx, owner) return owner
def create_curve(self, ctx, shapes, classname): # Create Spline newcurve = bpy.data.curves.new(classname, type='CURVE') newcurve.dimensions = '3D' curve_from_shapes(newcurve, shapes, self.close) # Create object and link to collection self.owner = bpy.data.objects.new(classname, newcurve) link_to_scene(ctx, self.owner) set_as_active_object(ctx, self.owner) self.data = self.owner.data
def create_mesh(self, ctx, meshdata, classname): verts, edges, faces, = meshdata newmesh = bpy.data.meshes.new(classname) newmesh.from_pydata(verts, edges, faces) newmesh.update(calc_edges=True) self.owner = bpy.data.objects.new(classname, newmesh) link_to_scene(ctx, self.owner) set_as_active_object(ctx, self.owner) self.data = self.owner.data self.data.use_auto_smooth = True