Files
drybox-ng/box.scad
2024-04-07 17:52:29 -04:00

348 lines
13 KiB
OpenSCAD

/* */
include <BOSL/constants.scad>
include <BOSL/shapes.scad>
include <BOSL/transforms.scad>
include <BOSL/joiners.scad>
include <./pc4m10.scad>
include <inserts/inserts.scad>
include <fdmouse.scad>
/* [Part] */
PART = ""; // [ all_corners, corner_top, corner_bottom, edge_back_bottom, edge_side_top, edge_side_foot, edge_top_front, edge_top_back, edge_test, full_box, joiner_top, joiner_bottom, profile, side_edge, rbfoot, hinge ]
/* [Dimensions] */
PROFILE_SIZE = 34;
BOX_X = 530;
BOX_Y = 210;
BOX_Z = 210;
WIN_LIP = 10;
WIN_TRIM = 5;
WIN_THICK = 3;
FLOOR_LIP = 10;
FLOOR_THICK = 5;
JOINER_H = 18;
JOINER_W = 10;
RB_MOUNT_INSET=17;
RB_MOUNT_WIDTH=9;
RB_MOUNT_LEN=136;
RB_MOUNT_OUT_H=19;
RB_MOUNT_IN_H=6.15;
/* [Render Options] */
render_fs=.4;
render_fn=undef;
render_fa=.4;
// Set Render Options
$fs= ($preview) ? $fs : render_fs;
$fn= ($preview) ? $fn : render_fn;
$fa= ($preview) ? $fa : render_fa;
/***
sides:
V_TOP, [0,0,1] : Top Middle Brace
V_ALLPOS, [1,1,1] POS Corner
V_TOPLEFT, [-1,0,1] : Left Top Edge
***/
//profile();
module profile(ps=PROFILE_SIZE, wl=WIN_LIP, wt=WIN_THICK, wtr=WIN_TRIM, fl=FLOOR_LIP, ft=FLOOR_THICK, flx=false, fly=false, wx=true, wy=true) {
conv = (wx && wy && flx)
? 3
: ((wx && wy) || (wy && flx))
? 2
: (wx || wy || flx)
? 1
: 0;
gon=concat(
[[0,ps-wl-wtr]], // Trim Start
// Y Window
wy ? [[0,ps-wl],[wt,ps-wl],[wt,ps]]
: [[0,ps]],
[[2*wt,ps]], // End of Y.
// Inner Cut to X
flx ? [[ps-fl,2*wt+fl],[ps-fl,2*wt+fl-ft],[ps,2*wt+fl-ft]]
: [[ps,2*wt]],
// X Window
wx ? [[ps,wt],[ps-wl,wt],[ps-wl,0]]
: [[ps,0]],
[[ps-wl-wtr,0]]
);
polygon(points = gon, convexity=conv);
}
module rb_foot(fw=RB_MOUNT_WIDTH, rl=RB_MOUNT_LEN, rh=RB_MOUNT_OUT_H, fl=10) {
translate([-(fl+rl/2),0]) linear_extrude(height=fw-1)
offset(r=1)offset(delta=-1)union() {
square([rl+2*fl, rh]);
square([fl, rh+fl]);
translate([rl+fl,0]) square([fl, rh+fl]);
}
back=5;
bmax = back + (fw-1);
fwd(bmax)up(fw-1)
yrot(90)linear_extrude(height=rl, center=true) polygon([[0,bmax-fw+1],[0,bmax],[fw-1,bmax]]);
}
module hinge_mount(bz=WIN_THICK, bl=10) {
zspread(l=40) {
zrot(-90)xrot(90)right(5) {
up(3+2) cyl(d1=7, d2=9,h=7, align=V_TOP);
thread_insertM3(bl=bl,bz=-(bl-3), $die=true);
//%thread_insertM3(bl=10,bz=-7);
}
}
zrot(-90)xrot(90)left(5) {
up(3+2) cyl(d1=7, d2=9,h=7, align=V_TOP);
thread_insertM3(bl=bl,bz=-(bl-3), $die=true);
//%thread_insertM3(bl=10,bz=-7);
}
}
module box_edge(ps=PROFILE_SIZE, l=10, orient=ORIENT_Z, jh = JOINER_H,jw = JOINER_W, jb=5, jup = false, jdown=false, flx=false, ft=FLOOR_THICK, wl=WIN_LIP, wx=true, wt=WIN_THICK, wtr = WIN_TRIM, hm=false, ht=0, tubepass=false, tn = 2, ix=true, iy=true, rbfoot=false, cm=false, align=V_CENTER) {
inner_off = ps/2 + wt;
joiner_off = inner_off - jb/sqrt(2);
jzoff = l/2-jw/2;
psoff = ps/2 - wl - wt;
face_off = ((ps+psoff)/4);
orient_and_align([ps,ps,l], orient=orient, align=align, orig_orient=ORIENT_Z) left(ps/2) fwd(ps/2) {
difference() {
linear_extrude(height=l, center=true)
profile(flx=flx, fly=true, wx=wx, wy=true);
if (jup) up(jzoff) back(joiner_off)right(joiner_off)zrot(45)boxjoiner_clear(orient=ORIENT_Y_90, align=V_CENTER, cl="green");
if (jdown) down(jzoff)back(joiner_off)right(joiner_off)zrot(45)boxjoiner_clear(orient=ORIENT_Y_90, align=V_CENTER, cl="brown");
if (tubepass) {
if (tn > 1) {
zspread(l=l/2, n=tn) zrot(-45)back(face_off*sqrt(2)-.01)pc4M10_clear(orient=ORIENT_Y,align=V_BACK);
} else {
zrot(-45)back(face_off*sqrt(2)-.01)pc4M10_clear(orient=ORIENT_Y,align=V_BACK);
}
}
if (hm) right(face_off)back(face_off)zrot(45) color("gold") hinge_mount();
if (iy) back(ps-wl/2)right(wt)yrot(-90) thread_insertM3(bl=5+wt, bz=-wt-2, $die=true);
if (ix && flx )
right(ps-wl/2)back(ps/2-ft-1)xrot(-90) thread_insertM3(bl=ft+3, bz=-ft, $die=true);
if (ix && wx)
right(ps-wl/2)back(wt)xrot(90) thread_insertM3(bl=5+wt, bz=-wt-2, $die=true);
if (cm) zspread(n=2, l=20) right(inner_off)back(inner_off)zrot(-45)xrot(-90){
thread_insertM3(bl=6, bz=-4, $die=true);
%thread_insertM3(bl=6, bz=-4, $die=false);
}
}
if (hm) zrot(45) right(face_off*sqrt(2)) %hinge(theta=ht);
if (tubepass) {
if (tn > 1) {
zspread(l=l/2, n=tn) right(0)zrot(-45)back(face_off*sqrt(2))pc4M10(orient=ORIENT_Y,align=V_BACK);
} else {
right(0)zrot(-45)back(face_off*sqrt(2))pc4M10(orient=ORIENT_Y,align=V_BACK);
}
}
if (jup) up(l/2 - jw/2)back(joiner_off)right(joiner_off)zrot(45)boxjoiner(orient=ORIENT_Y_90, align=V_CENTER);
if (jdown) down(l/2 - jw/2)back(joiner_off)right(joiner_off)zrot(45)xrot(180)boxjoiner(orient=ORIENT_Y_90, align=V_CENTER);
if (rbfoot) right(ps/2+psoff-2)zrot(180)yrot(90)rb_foot();
}
}
module box_corner(ps = PROFILE_SIZE, l=0, zfl = true, zw = false, wl=WIN_LIP, wt=WIN_THICK, align=V_CENTER, orient=ORIENT_Z) {
psoff = ps/2 - wl - wt;
coff = ps + psoff;
sz = 3*ps/2 + psoff;
orient_and_align([sz,sz,sz], orient=orient, align=align) {
intersection() {
// Cap
fwd(ps)right(psoff)down(psoff)right(ps/2)box_edge(l=PROFILE_SIZE, orient=ORIENT_Y, align=V_BACK+V_LEFT, flx=zfl, wx=zw);
right(ps)fwd(psoff)down(psoff)fwd(ps/2)box_edge(l=PROFILE_SIZE, orient=ORIENT_X, align=V_BACK+V_LEFT, flx=zfl, wx=zw);
down(ps/2+WIN_TRIM)fwd(psoff)right(psoff)box_edge(l=PROFILE_SIZE, orient=ORIENT_Z_90, align=V_TOP, flx=false, wx=true);
}
fwd(1)right(psoff)down(psoff)right(ps/2)box_edge(l=ps+1, orient=ORIENT_Y, jup=true, align=V_BACK+V_LEFT, flx=zfl, wx=zw);
right(1)fwd(psoff)down(psoff)fwd(ps/2)box_edge(l=ps+1, orient=ORIENT_X, jdown=true, align=V_BACK+V_LEFT, flx=zfl, wx=zw);
down(1)fwd(psoff)right(psoff)box_edge(l=ps+1, orient=ORIENT_Z_90, align=V_TOP, jup=true, flx=false, wx=true);
}
}
module beam_joiner(jw=JOINER_W, jh=JOINER_H, fl=false) {
difference() {
union() {
boxjoiner(jh=jh, jw=jw,l=5,align=V_FRONT, orient=ORIENT_X);
zrot(180)boxjoiner(jh=jh, jw=jw,l=5,align=V_FRONT, orient=ORIENT_X);
}
if (fl)
left(jh/2)down(3)yrot(45)cuboid([jw,2*jh,4]);
}
}
module box_all_corners(ex=0) {
// top
up(ex) fwd(ex) left(ex) box_corner(zfl=false, zw=true,align=V_UP+V_FRONT+V_LEFT, orient=ORIENT_ZNEG);
up(ex) back(ex) left(ex) box_corner(zfl=false, zw=true,align=V_UP+V_BACK+V_LEFT, orient=ORIENT_ZNEG_90);
up(ex) back(ex) right(ex) box_corner(zfl=false, zw=true, align=V_UP+V_BACK+V_RIGHT, orient=ORIENT_ZNEG_180);
up(ex) fwd(ex) right(ex) box_corner(zfl=false,zw=true,align=V_UP+V_FRONT+V_RIGHT, orient=ORIENT_ZNEG_270);
// bottom
down(ex) fwd(ex) right(ex) box_corner(align=V_DOWN+V_FRONT+V_RIGHT, orient=ORIENT_Z);
down(ex) back(ex) right(ex) box_corner(align=V_DOWN+V_BACK+V_RIGHT, orient=ORIENT_Z_90);
down(ex) back(ex) left(ex) box_corner(align=V_DOWN+V_BACK+V_LEFT, orient=ORIENT_Z_180);
down(ex) fwd(ex) left(ex) box_corner(align=V_DOWN+V_FRONT+V_LEFT, orient=ORIENT_Z_270);
}
module boxjoiner(slop=.01, align=V_FRONT, jh=JOINER_H, jw=JOINER_W, l=3, orient=ORIENT_Z) {
orient_and_align([jw,0,jh], orig_align=V_FRONT, align=align, orient=orient)
joiner(h=jh, w=jw, l=l, screwsize= $preview ? undef : .8);
}
module boxjoiner_clear(inset=5, slop=.01, jh=JOINER_H, jw=JOINER_W, align=V_FRONT, orient=ORIENT_Z, cl=undef) {
color(cl)
orient_and_align([jw,inset,jh],orient=orient, align=align) fwd() {
cuboid([jw+slop,inset+slop,jh], align=V_BACK);
joiner_clear(h=jh, w=jw+slop);
}
}
module hinge(theta=90) {
x=7;
py=20;
difference() {
left(x/2)cuboid([x,20,50], fillet=2, edges=EDGES_X_ALL);
hinge_mount($die=true);
}
left(5.5)back(py/2 + 5)zrot(theta){
cylinder(r=5, h=6);
difference() {
left((x)/2-5)back(10+5)cuboid([x,20,50], fillet=2, edges=EDGES_X_ALL);
right(5)back(10+5)zrot(180) {
hinge_mount(bl=9, $die=true);
%hinge_mount(bl=9,$die=false);
}
}
}
}
wt=WIN_TRIM;
wl=WIN_LIP;
ps = PROFILE_SIZE;
psoff = ps/2 - wl - wt;
coff = ps + psoff;
sz = 3*ps/2;
lx = BOX_X - 2* sz - 2*psoff;
ly = BOX_Y - sz;
lz = BOX_Z - sz;
echo(str("Edge Len X: ", lx, " (3 x ", lx/3, ")"));
echo(str("Edge Len Y: ", ly, " (1 x ", ly, ")"));
echo(str("Edge Len Z: ", lz, " (1 x ", lz, ")"));
echo(str("Window Size: ", lx + 2* (ps-WIN_THICK-1), "mm x ", ly + 2*(ps-WIN_THICK-1), "mm"));
if (PART == "profile") {
profile(flx=true);
}
if (PART == "all_corners")
box_all_corners(ex=30);
if (PART == "corner_top") box_corner(zw=true, zfl=false);
if (PART == "corner_bottom") box_corner(zw=false, zfl=true);
if (PART == "edge_back_bottom") {
left(coff/2-2*psoff) back(lx/3/2)zrot(315)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) back(lx/3/2)zrot(225)ear(thick=.2, dis=-2);
left(coff/2-2*psoff) fwd(lx/3/2)zrot(45)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) fwd(lx/3/2)zrot(135)ear(thick=.2, dis=-2);
up((wt+wl)/sqrt(2))xrot(90) zrot(45) box_edge(l=lx/3, jup=true, jdown=true, flx=true, wx=false, tubepass=true, orient=ORIENT_Z);
}
if (PART == "edge_side_foot") {
box_edge(l=ly, rbfoot=true, flx=true, wx=false, jup=true, jdown=true, cm=true, orient=ORIENT_Y);
}
if (PART == "edge_side_top") {
left(coff/2-2*psoff) back(ly/2)zrot(315)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) back(ly/2)zrot(225)ear(thick=.2, dis=-2);
left(coff/2-2*psoff) fwd(ly/2)zrot(45)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) fwd(ly/2)zrot(135)ear(thick=.2, dis=-2);
up((wt+wl)/sqrt(2))yrot(45)box_edge(l=ly, rbfoot=false, flx=false, wx=true, jup=true, jdown=true, cm=true, orient=ORIENT_Y);
}
if (PART == "edge_top_front") {
//r = $t *90 - 45;
r=-45;
box_edge(l=lx/3, rbfoot=false, hm=true, ht=r, flx=false, iy=false, wx=true, jup=true, jdown=true, cm=true, orient=ORIENT_XNEG_180);
face_off = ((ps+psoff)/4);
//xrot(45)yrot(-90)right(face_off+7/2)zrot(180)hinge();
}
if (PART == "edge_top_back") {
left(coff/2-2*psoff) back(lx/3/2)zrot(315)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) back(lx/3/2)zrot(225)ear(thick=.2, dis=-2);
left(coff/2-2*psoff) fwd(lx/3/2)zrot(45)ear(thick=.2, dis=-2);
right(coff/2-2*psoff) fwd(lx/3/2)zrot(135)ear(thick=.2, dis=-2);
up((wt+wl)/sqrt(2)) yrot(45+90)zrot(90)box_edge(l=lx/3, rbfoot=false, hm=false, flx=false, iy=true, wx=true, jup=true, jdown=true, cm=true, orient=ORIENT_XNEG_180);
}
if (PART == "full_box") {
up(lz/2+ps) {
// Top Corners:
right(ps+lx/2) fwd(ps+ly/2) box_corner(orient=ORIENT_ZNEG_270, zfl=false);
right(ps+lx/2) back(ps+ly/2) box_corner(orient=ORIENT_ZNEG_180);
left(ps+lx/2) back(ps+ly/2) box_corner(orient=ORIENT_ZNEG_90);
left(ps+lx/2) fwd(ps+ly/2) box_corner(orient=ORIENT_ZNEG);
}
up(lz/2+coff) { // Top Edges
fwd(coff + ly/2) xspread(n=3, lx/3) box_edge(l=lx/3, hm=true, jup=true, jdown=true, iy=false, flx=true, wx=false, orient=ORIENT_XNEG_180);
back(coff + ly/2) {
xspread(n=3, lx/3)box_edge(l=lx/3, jup=true, jdown=true, flx=true, wx=false, tubepass=false, orient=ORIENT_X_180);
}
right(coff + lx/2) box_edge(l=ly, jup=true, jdown=true, flx=true, wx=false, orient=ORIENT_YNEG_180);
left(coff + lx/2) zrot(180)box_edge(l=ly, jup=true, jdown=true, flx=true, wx=false, orient=ORIENT_YNEG_180);
}
{ // vertical
left(coff+lx/2)fwd(coff+ly/2)
box_edge(l=lz,jup=true, ix=false, jdown=true);
right(coff+lx/2)fwd(coff+ly/2)
box_edge(l=lz,jup=true, iy=false, jdown=true, orient=ORIENT_Z_90);
right(coff+lx/2)back(coff+ly/2)
box_edge(l=lz,jup=true, jdown=true, orient=ORIENT_Z_180);
left(coff+lx/2)back(coff+ly/2)
box_edge(l=lz,jup=true, jdown=true, orient=ORIENT_Z_270);
}
down(lz/2+coff) {
fwd(coff + ly/2) xspread(n=3, lx/3) box_edge(l=lx/3, iy=false, jup=true, jdown=true, flx=true, wx=false, orient=ORIENT_X);
back(coff + ly/2) zrot(180) { // rear
xspread(n=3, lx/3)box_edge(l=lx/3, jup=true, jdown=true, flx=true, wx=false, tubepass=true, orient=ORIENT_X);
}
right(coff + lx/2) box_edge(l=ly, jup=true, jdown=true, flx=true, wx=false, rbfoot=true, orient=ORIENT_Y);
left(coff + lx/2) zrot(180)box_edge(l=ly, jup=true, jdown=true, flx=true, wx=false, rbfoot=true, orient=ORIENT_Y);
}
down(lz/2+ps) {
// Bottom Corners:
right(ps+lx/2) fwd(ps+ly/2)box_corner();
right(ps+lx/2) back(ps+ly/2)box_corner(orient=ORIENT_Z_90);
left(ps+lx/2) back(ps+ly/2)box_corner(orient=ORIENT_Z_180);
left(ps+lx/2) fwd(ps+ly/2)box_corner(orient=ORIENT_Z_270);
}
xspread(n=6, l=70*6) %cyl(d=200, l=70, orient=ORIENT_X);
}
if (PART == "joiner_top") beam_joiner(fl=false);
if (PART == "joiner_bottom") {
back(JOINER_W) right(JOINER_H/2) zrot(225)ear();
back(JOINER_W) left(JOINER_H/2 - 5) zrot(315)ear();
fwd(JOINER_W) right(JOINER_H/2) zrot(135)ear();
fwd(JOINER_W) left(JOINER_H/2-5) zrot(45)ear();
up(5) beam_joiner(fl=true);
}
if (PART == "rbfoot") rb_foot();
if (PART == "edge_test") box_edge(l=35, tubepass=true, jup=true, jdown=true, tn=1, flx=true, wx = false, orient=ORIENT_Y);
if (PART == "hinge") {
r = $t *90;
hinge(theta=r);
}