summaryrefslogtreecommitdiff
path: root/src/helpers_blender.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/helpers_blender.py')
-rw-r--r--src/helpers_blender.py133
1 files changed, 133 insertions, 0 deletions
diff --git a/src/helpers_blender.py b/src/helpers_blender.py
new file mode 100644
index 0000000..470d5e8
--- /dev/null
+++ b/src/helpers_blender.py
@@ -0,0 +1,133 @@
+import solid as sl
+
+debug_trace = False
+
+def debugprint(info):
+ if debug_trace:
+ print(info)
+
+def box(width, height, depth):
+ return sl.cube([width, height, depth], center=True)
+
+
+def cylinder(radius, height, segments=100):
+ return sl.cylinder(r=radius, h=height, segments=segments, center=True)
+
+
+def sphere(radius):
+ return sl.sphere(radius)
+
+
+def cone(r1, r2, height):
+ return sl.cylinder(r1=r1, r2=r2, h=height) # , center=True)
+
+
+def rotate(shape, angle):
+ return sl.rotate(angle)(shape)
+
+
+def translate(shape, vector):
+ return sl.translate(tuple(vector))(shape)
+
+
+def mirror(shape, plane=None):
+ debugprint('mirror()')
+ planes = {
+ 'XY': [0, 0, 1],
+ 'YX': [0, 0, -1],
+ 'XZ': [0, 1, 0],
+ 'ZX': [0, -1, 0],
+ 'YZ': [1, 0, 0],
+ 'ZY': [-1, 0, 0],
+ }
+ return sl.mirror(planes[plane])(shape)
+
+
+def union(shapes):
+ debugprint('union()')
+ shape = None
+ for item in shapes:
+ if shape is None:
+ shape = item
+ else:
+ shape += item
+ return shape
+
+
+def add(shapes):
+ debugprint('union()')
+ shape = None
+ for item in shapes:
+ if shape is None:
+ shape = item
+ else:
+ shape += item
+ return shape
+
+
+def difference(shape, shapes):
+ debugprint('difference()')
+ for item in shapes:
+ shape -= item
+ return shape
+
+
+def intersect(shape1, shape2):
+ return sl.intersect()(shape1, shape2)
+
+
+def hull_from_points(points):
+ return sl.hull()(*points)
+
+
+def hull_from_shapes(shapes, points=None):
+ hs = []
+ if points is not None:
+ hs.extend(points)
+ if shapes is not None:
+ hs.extend(shapes)
+ return sl.hull()(*hs)
+
+
+def tess_hull(shapes, sl_tol=.5, sl_angTol=1):
+ return sl.hull()(*shapes)
+
+
+def triangle_hulls(shapes):
+ debugprint('triangle_hulls()')
+ hulls = []
+ for i in range(len(shapes) - 2):
+ hulls.append(hull_from_shapes(shapes[i: (i + 3)]))
+
+ return union(hulls)
+
+
+def polyline(point_list):
+ return sl.polygon(point_list)
+
+
+# def project_to_plate():
+# square = cq.Workplane('XY').rect(1000, 1000)
+# for wire in square.wires().objects:
+# plane = cq.Workplane('XY').add(cq.Face.makeFromWires(wire))
+
+def extrude_poly(outer_poly, inner_polys=None, height=1):
+ if inner_polys is not None:
+ return sl.linear_extrude(height=height, twist=0, convexity=0, center=True)(outer_poly, *inner_polys)
+ else:
+ return sl.linear_extrude(height=height, twist=0, convexity=0, center=True)(outer_poly)
+
+
+def import_file(fname):
+ print("IMPORTING FROM {}".format(fname))
+ return sl.import_(fname + ".stl")
+
+
+def export_file(shape, fname):
+ print("EXPORTING TO {}".format(fname))
+ sl.scad_render_to_file(shape, fname + ".scad")
+
+
+def export_dxf(shape, fname):
+ print("NO DXF EXPORT FOR SOLID".format(fname))
+ pass \ No newline at end of file