-
-
Save zeffii/5f0b03c799ba8d146ebd to your computer and use it in GitHub Desktop.
test
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
# 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) |
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
# filename = "PWD/blender_loft.py" | |
# exec(compile(open(filename).read(), filename, 'exec')) | |
import bpy | |
import addon_utils | |
addon_utils.enable('mesh_bsurfaces') | |
def add_curve(location): | |
bpy.ops.curve.primitive_bezier_curve_add() | |
obj = bpy.context.object | |
obj.location = location | |
return obj | |
def main(): | |
obj1 = add_curve((0,0,0)) | |
obj2 = add_curve((0,1,3)) | |
obj3 = add_curve((0,0,6)) | |
# In case this code is run after a bunch of other code we want to | |
# ensure the state of the scene | |
# :: deselect everything. no active either. | |
bpy.ops.object.select_all(action='DESELECT') | |
obj1.select = True | |
obj2.select = True | |
obj3.select = True | |
bpy.ops.object.join('INVOKE_DEFAULT') | |
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(mode='EDIT') | |
bpy.ops.mesh.reveal() | |
bpy.ops.gpencil.surfsk_add_surface('INVOKE_DEFAULT') | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment