Skip to content

Instantly share code, notes, and snippets.

Created December 4, 2015 11:08
Show Gist options
  • Save anonymous/48d0f70b061f955f35f3 to your computer and use it in GitHub Desktop.
Save anonymous/48d0f70b061f955f35f3 to your computer and use it in GitHub Desktop.
test
# filename = "PWD/blender_loft.py"
# exec(compile(open(filename).read(), filename, 'exec'))
import bpy
import bpy_extras
import numpy
from mathutils import Matrix
# Create a spline/bezier from a list of points
def new_curve_from_points(pLists, name_prefix):
curve_data = bpy.data.curves.new(name_prefix + 'CurveToLoft', 'CURVE')
curve_data.dimensions = "3D"
obj = bpy.data.objects.new(name_prefix + 'CurveToLoft', curve_data)
bpy.context.scene.objects.link(obj)
for plist in pLists:
spline = curve_data.splines.new('BEZIER')
npts = len(plist)
spline.bezier_points.add(npts - 1)
for i in range(0, npts):
spline.bezier_points[i].co = plist[i]
return obj
def get_point_lists():
print('hello')
p0 = [[1, 0, 0], [0, 0, 0], [0, 1, 0]]
p1 = [[1, 1, 0], [0, 1, 0], [0, 0, 1]]
return [p0, p1]
def loft(curves):
obj = new_curve_from_points(curves, 'joined_curves')
obj.select = True
# create a mesh to store the final surface
me = bpy.data.meshes.new("outputLoft")
ob = bpy.data.objects.new("outputLoft", me)
scn = bpy.context.scene
scn.objects.link(ob)
scn.objects.active = ob
ob.select = True
# curves + object should be selected
# call lofting
bpy.ops.object.mode_set('INVOKE_REGION_WIN', mode='EDIT', toggle=True)
bpy.ops.mesh.reveal()
bpy.ops.gpencil.surfsk_add_surface('INVOKE_DEFAULT')
if __name__ == "__main__":
pLists = get_point_lists()
loft(pLists)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment