Fixed hexagon vents, unified punch_hole / extrude_shape APIs

This commit is contained in:
Roberto Alsina 2023-03-27 16:57:55 -03:00
parent 68849b5aca
commit c49f9c6348
8 changed files with 59 additions and 54 deletions

View File

@ -2,7 +2,7 @@
import cadquery as cq import cadquery as cq
from utils import punch_hole2, extrude_shape2 from utils import punch_hole
# The hole is for a random USB sound card. # The hole is for a random USB sound card.
# Consumers should set proper offsets for the hole # Consumers should set proper offsets for the hole
@ -33,7 +33,7 @@ def add(
# Holes # Holes
if back_face: if back_face:
for hole in holes: for hole in holes:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=back_face, face=back_face,
# FIXME: This is weird because it's the RIGHT side, # FIXME: This is weird because it's the RIGHT side,

View File

@ -1,6 +1,6 @@
import cadquery as cq import cadquery as cq
from utils import extrude_shape, punch_hole2, hex_vents from utils import extrude_shape, punch_hole, hex_vents
stand_positions = [(3.5, 3.5), (61.5, 3.5), (61.5, 52.5), (3.5, 52.5)] stand_positions = [(3.5, 3.5), (61.5, 3.5), (61.5, 52.5), (3.5, 52.5)]
stands = ( stands = (
@ -71,7 +71,7 @@ elements = [
] ]
vents = hex_vents(size=6, width=width, height=height) vents = hex_vents(size=3, width=width, height=height)
# Hole distances are relative to the rightmost pillar # Hole distances are relative to the rightmost pillar
@ -110,7 +110,7 @@ def add(
if bottom_face: if bottom_face:
# Vents # Vents
for vent in vents: for vent in vents:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=bottom_face, face=bottom_face,
w=width, w=width,
@ -128,16 +128,16 @@ def add(
face=bottom_face, face=bottom_face,
w=width, w=width,
h=height, h=height,
x_offset=offset_x + element["x"], x_offset=offset_x,
y_offset=shell_t + offset_y + element["y"], y_offset=shell_t + offset_y,
shape=element["shape"], element=element,
height=-(element["height"] + shell_t), height=-(element["height"] + shell_t),
) )
if back_face: if back_face:
# Holes # Holes
for hole in holes: for hole in holes:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=back_face, face=back_face,
w=width, w=width,

Binary file not shown.

View File

@ -7,7 +7,6 @@ import usb_hub
import zero_holder as cpu_holder import zero_holder as cpu_holder
import screen_pillars import screen_pillars
import keyboard import keyboard
from utils import extrude_shape, punch_hole, punch_hole2
# Base for the notebook. Basically a kbd base that extends back # Base for the notebook. Basically a kbd base that extends back
# as much as possible # as much as possible

View File

@ -1,4 +1,4 @@
from utils import extrude_shape, punch_hole2 from utils import extrude_shape, punch_hole
import cadquery as cq import cadquery as cq
elements = None elements = None
@ -52,20 +52,20 @@ def add(
face=bottom_face, face=bottom_face,
w=width, w=width,
h=height, h=height,
x_offset=offset_x + element["x"], x_offset=offset_x,
y_offset=shell_t + offset_y + element["y"], y_offset=shell_t + offset_y,
shape=element["shape"], element=element,
height=-(element["height"] + shell_t), height=-(element["height"] + shell_t),
) )
# Screw holes # Screw holes
for hole in bottom_holes: for hole in bottom_holes:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=bottom_face, face=bottom_face,
w=width, w=width,
h=height, h=height,
x_offset=offset_x + hole["x"], x_offset=offset_x,
y_offset=shell_t + offset_y + hole["y"], y_offset=shell_t + offset_y,
hole=hole, hole=hole,
depth=hole["depth"], depth=hole["depth"],
) )

View File

@ -1,6 +1,6 @@
import cadquery as cq import cadquery as cq
from utils import punch_hole2, extrude_shape, extrude_shape2 from utils import punch_hole, extrude_shape
# Measurements for my USB hub, YMMV # Measurements for my USB hub, YMMV
@ -54,16 +54,16 @@ def add(
face=bottom_face, face=bottom_face,
w=width, w=width,
h=height, h=height,
x_offset=offset_x + element["x"], x_offset=offset_x,
y_offset=shell_t + offset_y + element["y"], y_offset=shell_t + offset_y,
shape=element["shape"], element=element,
height=-(element["height"] + shell_t), height=-(element["height"] + shell_t),
) )
# Holes # Holes
if back_face: if back_face:
for hole in holes: for hole in holes:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=back_face, face=back_face,
w=width, w=width,

View File

@ -1,12 +1,13 @@
import cadquery as cq import cadquery as cq
from math import floor
# TODO make API of extrude_shape and punch_hole more consistent
def extrude_shape(*, model, face, w, h, x_offset, y_offset, shape, height): def extrude_shape(*, model, face, w, h, x_offset, y_offset, element, height):
return ( return (
model.faces(face) model.faces(face)
.workplane(centerOption="CenterOfBoundBox") .workplane(centerOption="CenterOfBoundBox")
.center(-w / 2 + x_offset, -h / 2 + y_offset) .center(-w / 2 + x_offset + element["x"], -h / 2 + y_offset + element["y"])
.placeSketch(shape) .placeSketch(element["shape"])
.extrude(height) .extrude(height)
) )
@ -16,12 +17,7 @@ def punch_hole(*, model, face, w, h, x_offset, y_offset, hole, depth):
model.faces(face) model.faces(face)
.workplane(centerOption="CenterOfBoundBox") .workplane(centerOption="CenterOfBoundBox")
.center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"]) .center(-w / 2 + x_offset + hole["x"], -h / 2 + y_offset + hole["y"])
.placeSketch( .placeSketch(hole["shape"])
cq.Sketch()
.trapezoid(hole["width"], hole["height"], 90, mode="a")
.vertices()
.fillet(hole["fillet"])
)
.cutBlind(-depth) .cutBlind(-depth)
) )
@ -36,31 +32,41 @@ def extrude_shape2(*, model, face, w, h, x_offset, y_offset, hole, depth):
) )
def punch_hole2(*, 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"])
.cutBlind(-depth)
)
def hex_vents(*, size, width, height): def hex_vents(*, size, width, height):
# size is radius of the hexagon
# Information about how this works:
# https://www.redblobgames.com/grids/hexagons/
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
vent_positions = [] vent_positions = []
for x in range(1, width // size): for x in range(0, x_count):
for y in range(1, int(height // size / 0.8)): for y in range(0, y_count):
vent_positions.append( vent_positions.append(
( (
(x + (y % 2) / 2) * size - size * 0.2, (x + (y % 2) / 2) * x_step + x_offset,
y * size * 0.8 + size * 0.2, y * y_step + y_offset,
) )
) )
vents = [ vents = [
{ {
"x": 0, "x": 0,
"y": 0, "y": 0,
"shape": cq.Sketch().push(vent_positions).regularPolygon((size) / 2, 6), "shape": cq.Sketch().push(vent_positions).regularPolygon(size * 0.9, 6),
} }
] ]

View File

@ -1,6 +1,6 @@
import cadquery as cq import cadquery as cq
from utils import extrude_shape, punch_hole2, hex_vents from utils import extrude_shape, punch_hole, hex_vents
width = 65 width = 65
height = 30 height = 30
@ -42,7 +42,7 @@ elements = [
}, },
] ]
vents = hex_vents(size=6, width=width, height=height) vents = hex_vents(size=3, width=width, height=height)
holes = [ holes = [
# One hole for everything TODO: improve # One hole for everything TODO: improve
@ -70,7 +70,7 @@ def add(
if bottom_face: if bottom_face:
# Vents # Vents
for vent in vents: for vent in vents:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=bottom_face, face=bottom_face,
w=width, w=width,
@ -88,16 +88,16 @@ def add(
face=bottom_face, face=bottom_face,
w=width, w=width,
h=height, h=height,
x_offset=offset_x + element["x"], x_offset=offset_x,
y_offset=shell_t + offset_y + element["y"], y_offset=shell_t + offset_y,
shape=element["shape"], element=element,
height=-(element["height"] + shell_t), height=-(element["height"] + shell_t),
) )
# Holes # Holes
if back_face: if back_face:
for hole in holes: for hole in holes:
model = punch_hole2( model = punch_hole(
model=model, model=model,
face=back_face, face=back_face,
w=width, w=width,