-
-
Save zeffii/10727363 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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