2023-03-01 18:47:06 +00:00
|
|
|
import cadquery as cq
|
2023-03-27 19:57:55 +00:00
|
|
|
from math import floor
|
2023-03-01 18:47:06 +00:00
|
|
|
|
2023-03-27 19:57:55 +00:00
|
|
|
|
|
|
|
def extrude_shape(*, model, face, w, h, x_offset, y_offset, element, height):
|
2023-03-01 18:47:06 +00:00
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
2023-03-27 19:57:55 +00:00
|
|
|
.center(-w / 2 + x_offset + element["x"], -h / 2 + y_offset + element["y"])
|
|
|
|
.placeSketch(element["shape"])
|
2023-03-01 18:47:06 +00:00
|
|
|
.extrude(height)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth):
|
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
|
2023-03-27 19:57:55 +00:00
|
|
|
.placeSketch(hole["shape"])
|
2023-03-01 18:47:06 +00:00
|
|
|
.cutBlind(-depth)
|
|
|
|
)
|
2023-03-08 20:24:43 +00:00
|
|
|
|
|
|
|
|
2023-03-20 16:19:14 +00:00
|
|
|
def extrude_shape2(*, model, face, w, h, x_offset, y_offset, hole, depth):
|
|
|
|
return (
|
|
|
|
model.faces(face)
|
|
|
|
.workplane(centerOption="CenterOfBoundBox")
|
|
|
|
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
|
|
|
|
.placeSketch(hole["shape"])
|
|
|
|
.extrude(-depth)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
2023-03-27 19:57:55 +00:00
|
|
|
def hex_vents(*, size, width, height):
|
|
|
|
# size is radius of the hexagon
|
|
|
|
# Information about how this works:
|
|
|
|
# https://www.redblobgames.com/grids/hexagons/
|
2023-03-15 14:17:39 +00:00
|
|
|
|
2023-03-27 19:57:55 +00:00
|
|
|
x_step = size * (3**0.5)
|
|
|
|
y_step = size * 3 / 2
|
|
|
|
|
|
|
|
x_count = floor(width / x_step) - 1
|
|
|
|
|
|
|
|
if height > 4 * size:
|
|
|
|
y_count = floor((height - 2 * size) / (1.5 * size))
|
|
|
|
else:
|
|
|
|
y_count = 1
|
|
|
|
|
|
|
|
x_size = (x_count + 0.5) * x_step # Assumes at least 2 rows
|
|
|
|
y_size = 2 * size + 1.5 * size * (y_count - 1)
|
|
|
|
|
|
|
|
x_offset = (width - x_size) / 2 + 0.5 * x_step
|
|
|
|
y_offset = (height - y_size) / 2 + size
|
2023-03-20 16:19:14 +00:00
|
|
|
|
2023-03-15 14:17:39 +00:00
|
|
|
vent_positions = []
|
2023-03-27 19:57:55 +00:00
|
|
|
for x in range(0, x_count):
|
|
|
|
for y in range(0, y_count):
|
2023-03-15 14:17:39 +00:00
|
|
|
vent_positions.append(
|
|
|
|
(
|
2023-03-27 19:57:55 +00:00
|
|
|
(x + (y % 2) / 2) * x_step + x_offset,
|
|
|
|
y * y_step + y_offset,
|
2023-03-15 14:17:39 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
vents = [
|
|
|
|
{
|
|
|
|
"x": 0,
|
|
|
|
"y": 0,
|
2023-03-27 19:57:55 +00:00
|
|
|
"shape": cq.Sketch().push(vent_positions).regularPolygon(size * 0.9, 6),
|
2023-03-15 14:17:39 +00:00
|
|
|
}
|
|
|
|
]
|
|
|
|
|
2023-03-20 16:19:14 +00:00
|
|
|
return vents
|