forked from xxv/openscad-boxmaker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
boxmaker.scad
234 lines (205 loc) · 5.91 KB
/
boxmaker.scad
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* A finger-jointed lasercut box maker OpenSCAD library.
*
* Includes code from https://www.thingiverse.com/thing:448592/
* http://boxdesigner.connectionlab.org/
*/
module box_2d(box_inner, thickness, tabs, margin=2) {
layout_2d(box_inner, thickness) {
side_a_top(box_inner, thickness, tabs);
side_a(box_inner, thickness, tabs);
side_b(box_inner, thickness, tabs);
side_b(box_inner, thickness, tabs);
side_c(box_inner, thickness, tabs);
side_c(box_inner, thickness, tabs);
}
}
// An assembled version of the box for previewing.
module box_3d(inner, thickness, tabs) {
layout_3d(box_inner, thickness) {
side_a_top(box_inner, thickness, tabs);
side_a(box_inner, thickness, tabs);
side_b(box_inner, thickness, tabs);
side_b(box_inner, thickness, tabs);
side_c(box_inner, thickness, tabs);
side_c(box_inner, thickness, tabs);
}
}
module layout_2d(inner, thickness, margin=2) {
spacingA = inner[0] + thickness * 2 + margin;
spacingB = inner[1] + thickness * 2 + margin;
// bottom
children(0);
// top
translate([spacingA, 0, 0])
children(1);
// left
translate([spacingA * 2, inner[1], 0])
rotate([0, 0, -90])
children(2);
// right
translate([spacingA * 2 + inner[2] + thickness * 2 + margin, inner[1], 0])
rotate([0, 0, -90])
children(3);
// front
translate([0, inner[1] + margin + thickness * 2, 0])
children(4);
// back
translate([inner[0] + margin + thickness * 2,
inner[1] + margin + thickness * 2, 0])
children(5);
}
module layout_2d_horizontal(inner, thickness, margin=2) {
spacingA = inner[0] + thickness * 2 + margin;
spacingB = inner[1] + thickness * 2 + margin;
// bottom
children(0);
// top
translate([spacingA, 0, 0])
children(1);
// left
translate([spacingA * 2, spacingB, 0])
children(2);
// right
translate([spacingA * 2 + spacingB, spacingB, 0])
children(3);
// front
translate([0, spacingB, 0])
children(4);
// back
translate([spacingA, spacingB, 0])
children(5);
}
// An assembled version of the box for previewing.
module layout_3d(box_inner, thickness) {
color("red") {
// top
translate([0, 0, box_inner[2]])
linear_extrude(height=thickness)
children(0);
// bottom
translate([0, box_inner[1], 0])
rotate([180, 0, 0])
linear_extrude(height=thickness)
children(1);
}
color("green") {
// left
translate([0, box_inner[1], 0])
rotate([90, 0, -90])
linear_extrude(height=thickness)
children(2);
// right
translate([box_inner[0], 0, 0])
rotate([90, 0, 90])
linear_extrude(height=thickness)
children(3);
}
// front
color("blue") {
translate([0, 0, 0])
rotate([90, 0, 0])
linear_extrude(height=thickness)
children(4);
// back
translate([box_inner[0], box_inner[1], 0])
rotate([90, 0, 180])
linear_extrude(height=thickness)
children(5);
}
}
module side_a_top(inner, thickness, tabs) {
side([inner[0], inner[1]],
thickness,
[tabs[3], tabs[4], tabs[3], tabs[4]],
[0, 0, 0, 0]);
}
module side_a(inner, thickness, tabs) {
side([inner[0], inner[1]],
thickness,
[tabs[0], tabs[1], tabs[0], tabs[1]],
[0, 0, 0, 0]);
}
// left/right
module side_b(inner, thickness, tabs) {
side([inner[1], inner[2]],
thickness,
[tabs[4], tabs[2], tabs[1], tabs[2]],
[1, 0, 1, 0]);
}
// front/back
module side_c(inner, thickness, tabs) {
side([inner[0], inner[2]],
thickness,
[tabs[3], tabs[2], tabs[0], tabs[2]],
[1, 1, 1, 1]);
}
module side(inner, thickness, tabs, polarity) {
SMIDGE = 0.1;
x = inner[0] + thickness * 2;
y = inner[1] + thickness * 2;
translate([-thickness, -thickness])
difference() {
square([x, y]);
// bottom
if (tabs[2] > 0)
translate([0, -SMIDGE, 0])
edge_cuts(x, tabs[2], thickness + SMIDGE, polarity[2]);
// top
if (tabs[0] > 0)
translate([0, y - thickness, 0])
edge_cuts(x, tabs[0], thickness + SMIDGE, polarity[0]);
rotate([0, 0, -90]) {
translate([-y, 0, 0]) {
// left
if (tabs[3] > 0)
translate([0, -SMIDGE, 0])
edge_cuts(y, tabs[3], thickness + SMIDGE, polarity[3]);
// right
if (tabs[1] > 0)
translate([0, x - thickness, 0])
edge_cuts(y, tabs[1], thickness + SMIDGE, polarity[1]);
}
}
}
}
module edge_cuts(length, finger_width, cut_depth, polarity) {
if (polarity == 0) {
outside_cuts(length, finger_width, cut_depth);
} else {
difference() {
square([length, cut_depth]);
outside_cuts(length, finger_width, cut_depth);
}
}
}
// This module below based https://www.thingiverse.com/thing:448592/
// Customizable Box with Finger Joints by txoof
// licensed under the Creative Commons - Attribution license.
//cuts that fall at the end of an edge requiring an extra long cut
module outside_cuts(length, finger_width, cut_depth) {
//Calculate the maximum number of fingers and cuts possible
maxDiv = floor(length / finger_width);
//the usable divisions value must be odd for this layout
uDiv = (maxDiv % 2) == 0 ? maxDiv - 3 : maxDiv - 2;
numFinger = ceil(uDiv / 2);
numCuts = floor(uDiv / 2);
//calculate the length of the extra long cut
endCut = (length - uDiv * finger_width)/2;
//amount of padding to add to the iterative placement of cuts
// this is the extra long cut at the beginning and end of the edge
padding=endCut + finger_width;
square([endCut, cut_depth]);
for (i=[0:numCuts]) {
if (i < numCuts) {
translate([i*(finger_width*2)+padding, 0, 0])
square([finger_width, cut_depth]);
} else {
translate([i*(finger_width*2)+padding, 0, 0])
square([endCut, cut_depth]);
}
}
}
module empty() {
// Used if you don't want a given side.
}