Skip to content

Instantly share code, notes, and snippets.

@zeffii
Created July 23, 2012 15:59
Show Gist options
  • Save zeffii/3164381 to your computer and use it in GitHub Desktop.
Save zeffii/3164381 to your computer and use it in GitHub Desktop.
nurbs surface maybe
import bpy
from mathutils import Vector
# surface_points = bpy.context.object.data.splines[0].points
# points = [point.co for point in surface_points]
points = [ Vector((-1.5, -1.5, 1.2507835626602173, 1.0)),
Vector((-1.5, -0.5, 0.0, 1.0)),
Vector((-1.5, 0.5, 0.0, 1.0)),
Vector((-1.5, 1.5, 0.0, 1.0)),
Vector((-0.5, -1.5, 0.0, 1.0)),
Vector((-0.5, -0.5, 0.699999988079071, 1.0)),
Vector((-0.5, 0.5, -1.0731102228164673, 1.0)),
Vector((-0.5, 1.5, 0.0, 1.0)),
Vector((0.5, -1.5, 0.0, 1.0)),
Vector((0.5, -0.5, 0.699999988079071, 1.0)),
Vector((0.5, 0.5, -1.0731102228164673, 1.0)),
Vector((0.5, 1.5, -0.856956958770752, 1.0)),
Vector((1.5, -1.5, 0.0, 1.0)),
Vector((1.5, -0.5, 0.0, 1.0)),
Vector((1.5, 0.5, 0.0, 1.0)),
Vector((1.5, 1.5, -0.856956958770752, 1.0))]
def MakeNURBSSurface(object_name, surface_name, point_list):
surface_data = bpy.data.curves.new(name=surface_name, type='SURFACE')
surface_data.dimensions = '3D'
object_data = bpy.data.objects.new(object_name, surface_data)
object_data.location = (0,0,0)
bpy.context.scene.objects.link(object_data)
nurbs_surface = surface_data.splines.new('NURBS')
nurbs_surface.order_u = 4
nurbs_surface.order_v = 4
# nurbs_surface.point_count_u = 4
# nurbs_surface.point_count_v = 4
nurbs_surface.points.add(len(point_list)-1)
for idx, element in enumerate(point_list):
nurbs_surface.points[idx].co = element
nurbs_surface.use_cyclic_u = False
nurbs_surface.use_cyclic_v = False
nurbs_surface.use_bezier_u = False
nurbs_surface.use_bezier_v = False
nurbs_surface.use_endpoint_u = True
nurbs_surface.use_endpoint_v = True
MakeNURBSSurface("NameOfMySurfaceObject", "NameOfMySurface", points)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment