aboutsummaryrefslogtreecommitdiffstats
path: root/src/dactyl_manuform.py
diff options
context:
space:
mode:
authorJoshua Shreve <j.a.shreve@gmail.com>2021-07-08 22:05:34 -0400
committerJoshua Shreve <j.a.shreve@gmail.com>2021-07-08 22:05:34 -0400
commite3bf24d17cdbda9ace5dbcae257c5c856ef984d9 (patch)
tree6bcfbc6741f47feac4faad63a59011001fc3da82 /src/dactyl_manuform.py
parent7746b122ed99c5e31e8334d26817e4c00ac76560 (diff)
Added helper files to remove the cadquery / solid python helpers from the main file. Improved notch and added holes around key plate for mounting. Still WIP, but should be functional.
Diffstat (limited to 'src/dactyl_manuform.py')
-rw-r--r--src/dactyl_manuform.py296
1 files changed, 2 insertions, 294 deletions
diff --git a/src/dactyl_manuform.py b/src/dactyl_manuform.py
index 2753064..1265d5b 100644
--- a/src/dactyl_manuform.py
+++ b/src/dactyl_manuform.py
@@ -118,301 +118,9 @@ def column_offset(column: int) -> list:
####################################################
if ENGINE == 'cadquery':
- import cadquery as cq
- def box(width, height, depth):
- return cq.Workplane("XY").box(width, height, depth)
-
- def cylinder(radius, height, segments=100):
- return cq.Workplane("XY").union(cq.Solid.makeCylinder(radius=radius, height=height))
-
- def sphere(radius):
- return cq.Workplane('XY').union(cq.Solid.makeSphere(radius))
-
- def cone(r1, r2, height):
- return cq.Workplane('XY').union(
- cq.Solid.makeCone(radius1=r1, radius2=r2, height=height))
-
- def rotate(shape, angle):
- origin = (0, 0, 0)
- shape = shape.rotate(axisStartPoint=origin, axisEndPoint=(1, 0, 0), angleDegrees=angle[0])
- shape = shape.rotate(axisStartPoint=origin, axisEndPoint=(0, 1, 0), angleDegrees=angle[1])
- shape = shape.rotate(axisStartPoint=origin, axisEndPoint=(0, 0, 1), angleDegrees=angle[2])
- return shape
-
-
- def translate(shape, vector):
- return shape.translate(tuple(vector))
-
-
- def mirror(shape, plane=None):
- print('mirror()')
- return shape.mirror(mirrorPlane=plane)
-
-
- def union(shapes):
- print('union()')
- shape = None
- for item in shapes:
- if shape is None:
- shape = item
- else:
- shape = shape.union(item)
- return shape
-
- def add(shapes):
- print('union()')
- shape = None
- for item in shapes:
- if shape is None:
- shape = item
- else:
- shape = shape.add(item)
- return shape
-
-
- def difference(shape, shapes):
- print('difference()')
- for item in shapes:
- shape = shape.cut(item)
- return shape
-
-
- def intersect(shape1, shape2):
- return shape1.intersect(shape2)
-
-
- def face_from_points(points):
- # print('face_from_points()')
- edges = []
- num_pnts = len(points)
- for i in range(len(points)):
- p1 = points[i]
- p2 = points[(i + 1) % num_pnts]
- edges.append(
- cq.Edge.makeLine(
- cq.Vector(p1[0], p1[1], p1[2]),
- cq.Vector(p2[0], p2[1], p2[2]),
- )
- )
-
- face = cq.Face.makeFromWires(cq.Wire.assembleEdges(edges))
-
- return face
-
-
- def hull_from_points(points):
- # print('hull_from_points()')
- hull_calc = sphull(points)
- n_faces = len(hull_calc.simplices)
-
- faces = []
- for i in range(n_faces):
- face_items = hull_calc.simplices[i]
- fpnts = []
- for item in face_items:
- fpnts.append(points[item])
- faces.append(face_from_points(fpnts))
-
- shape = cq.Solid.makeSolid(cq.Shell.makeShell(faces))
- shape = cq.Workplane('XY').union(shape)
- return shape
-
-
- def hull_from_shapes(shapes, points=None):
- # print('hull_from_shapes()')
- vertices = []
- for shape in shapes:
- verts = shape.vertices()
- for vert in verts.objects:
- vertices.append(np.array(vert.toTuple()))
- if points is not None:
- for point in points:
- vertices.append(np.array(point))
-
- shape = hull_from_points(vertices)
- return shape
-
-
- def tess_hull(shapes, sl_tol=.5, sl_angTol=1):
- # print('hull_from_shapes()')
- vertices = []
- solids = []
- for wp in shapes:
- for item in wp.solids().objects:
- solids.append(item)
-
- for shape in solids:
- verts = shape.tessellate(sl_tol, sl_angTol)[0]
- for vert in verts:
- vertices.append(np.array(vert.toTuple()))
-
- shape = hull_from_points(vertices)
- return shape
-
- def triangle_hulls(shapes):
- print('triangle_hulls()')
- hulls = [cq.Workplane('XY')]
- for i in range(len(shapes) - 2):
- hulls.append(hull_from_shapes(shapes[i: (i + 3)]))
-
- return union(hulls)
-
- def polyline(point_list):
- return cq.Workplane('XY').polyline(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):#vector=(0,0,1)):
- outer_wires = cq.Wire.assembleEdges(outer_poly.edges().objects)
- inner_wires = []
- if inner_polys is not None:
- for item in inner_polys:
- inner_wires.append(cq.Wire.assembleEdges(item.edges().objects))
-
- return cq.Workplane('XY').add(cq.Solid.extrudeLinear(outerWire=outer_wires, innerWires=inner_wires, vecNormal=cq.Vector(0, 0, height)))
-
-
- def import_file(filename):
- return cq.Workplane('XY').add(cq.importers.importShape(
- cq.exporters.ExportTypes.STEP,
- filename+".step"))
-
-
- def export_file(shape, fname):
- cq.exporters.export(w=shape, fname=fname+".step",
- exportType='STEP')
-
- def export_dxf(shape, fname):
- cq.exporters.export(w=shape, fname=fname+".dxf",
- exportType='DXF')
-
+ from src.helpers_cadquery import *
else:
- import solid as sl
-
-
- 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):
- print('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):
- print('union()')
- shape = None
- for item in shapes:
- if shape is None:
- shape = item
- else:
- shape += item
- return shape
-
-
- def add(shapes):
- print('union()')
- shape = None
- for item in shapes:
- if shape is None:
- shape = item
- else:
- shape += item
- return shape
-
-
- def difference(shape, shapes):
- print('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):
- print('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):
- return sl.import_(fname+".stl")
-
-
- def export_file(shape, fname):
- print("EXPORTING TO {}".format(fname+".scad"))
- sl.scad_render_to_file(shape, fname+".scad")
-
-
- def export_dxf(shape, fname):
- pass
+ from src.helpers_solid import *
####################################################
# END HELPER FUNCTIONS