Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/brockus.py
Last active August 29, 2015 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/10727363 to your computer and use it in GitHub Desktop.
Save zeffii/10727363 to your computer and use it in GitHub Desktop.
# inspired by http://blender.stackexchange.com/a/8587/47
import bpy
from mathutils import Vector
scene = bpy.context.scene
surface_data = bpy.data.curves.new('wook', 'SURFACE')
surface_data.dimensions = '3D'
# 16 coordinates, set points per segments (U * V)
points = [
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.0, 1.0)),
Vector((-0.5, -1.5, 0.0, 1.0)), Vector((-0.5, -0.5, 1.0, 1.0)),
Vector((-0.5, 0.5, 1.0, 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, 1.0, 1.0)),
Vector((0.5, 0.5, 1.0, 1.0)), Vector((0.5, 1.5, 0.0, 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.0, 1.0))
]
for i in range(0, 16, 4):
spline = surface_data.splines.new(type='NURBS')
spline.points.add(3) # already has a default zero vector
for p, new_co in zip(spline.points, points[i:i+4]):
p.co = new_co
surface_object = bpy.data.objects.new('NURBS_OBJ', surface_data)
scene.objects.link(surface_object)
splines = surface_object.data.splines
for s in splines:
for p in s.points:
p.select = True
bpy.context.scene.objects.active = surface_object
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.curve.make_segment()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment