-
Notifications
You must be signed in to change notification settings - Fork 2
/
parametric_container.scad
1076 lines (976 loc) · 33.5 KB
/
parametric_container.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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* OpenSCAD script to create fully parametric models of shipping containers
$Id$
(C) 2019 by Philipp Reichmuth, [email protected]
This work is licensed under a Creative Commons
Attribution-ShareAlike 4.0 International License
(https://creativecommons.org/licenses/by-sa/4.0/)
Initial code taken from Parametric Shipping Container
(C) gundyboyz, https://www.thingiverse.com/thing:1392128,
licensed under Creative Commons Attribution Unported 3.0
(https://creativecommons.org/licenses/by/3.0/)
*/
// Leave the following constants alone!
// Meaningful names for the indexes into the various vectors
TYPE = 0; DIR = 1; STRING = 1; X = 2; Y = 3; W = 4; FONT_SIZE = 4; H = 5; ROTATE = 5; D = 6;
// Constants for the vector types
OPENING = "O"; WINDOW = "W"; WALL = "D";
TEXT_INT = "TI"; TEXT_EXT = "TE";
// Constants for indexing container walls
TOP = 0; FRONT = 1; BACK = 2; RIGHT = 3; LEFT = 4; BOTTOM = 5;
// Constants for assembly styles
INPLACE = 0; FACEUP = 1; FACEDOWN = 2;
// -----------------------------------------------
// Parameter definition begins here
// Measurements of shipping container (in meters)
// Shipping container size (external)
EXT_LENGTH = 6.06; // Standard lengths: 6.06 for 20', 12.19 for 40'
EXT_WIDTH = 2.44; // Standard width: 2.44
EXT_HEIGHT = 2.59; // Standard heights: 2.59 or 2.90 for High Cube
// Model settings
SCALE = 100; // 1:<SCALE> sizing
THICKNESS_WALL = 1.5; // External wall in mm
THICKNESS_WALL_INT = 1.5; // Internal wall in mm
TOLERANCE = 0.1; // Tolerance for assembly of walls (excluding frame)
// Container styles:
//
// General wall styles:
// "none": An empty wall with just the container frame.
// "flat": A flat wall
// "ridges": A corrugated wall with ridges
//
// Wall-specific styles:
// "crossbars": A container bottom with a few broad ridges.
// "door": A simple door: 2 hinges, 1 separator, 1 latch
//
// Interior styles:
// "none": Generate a hollow container
// "infill": Generate a solid container
// "walls": Generate interior parametric walls
// "tank": Generate a tanktainer (works best with no walls)
// This is an incredibly cumbersome way to do it in
// OpenSCAD, but I hope it is customizer-friendly
STYLE_FRONT="door";
STYLE_BACK="ridges";
STYLE_RIGHT="ridges";
STYLE_LEFT="ridges";
STYLE_TOP="ridges";
STYLE_BOTTOM="flat";
STYLE_FILL="walls";
// Assembly styles
// "box": a single box
// "lid": box with separate lid
// "parts": separate parts, face up, except bottom.
// Interior walls will be placed correctly, but
// ridged container bottoms may be hard to print.
// "facedown": separate parts, face down
// "faceup": separate parts, all face up, including bottom
// Container bottoms with ridges are easily
// printable this way, but interior walls will
// not work and will be ignored.
// "custom": custom placement for every part
ASSEMBLY_STYLE = "parts";
// Parts displacement distance in mm
PART_D = 3;
// Custom wall placement
// "inplace" - Generate the wall in place
// "faceup" - Generate the wall separately, face up
// "facedown" - Generate the wall separately, face down
PLACE_TOP = "inplace";
PLACE_FRONT = "faceup";
PLACE_BACK = "faceup";
PLACE_LEFT = "facedown";
PLACE_RIGHT = "faceup";
PLACE_BOTTOM = "inplace"; // inplace = facedown
function customassembly(assembly = [PLACE_TOP,
PLACE_FRONT, PLACE_BACK, PLACE_RIGHT, PLACE_LEFT,
PLACE_BOTTOM]) =
[ for (i=assembly) i=="inplace" ? 0 :
i=="faceup" ? 1 :
i=="facedown" ? 2 : 0 ];
ASSEMBLY = ASSEMBLY_STYLE == "box" ? [0,0,0,0,0,0] :
ASSEMBLY_STYLE == "lid" ? [1,0,0,0,0,0] :
ASSEMBLY_STYLE == "parts" ? [1,1,1,1,1,2] :
ASSEMBLY_STYLE == "faceup" ? [1,1,1,1,1,1] :
ASSEMBLY_STYLE == "facedown" ? [2,2,2,2,2,2] :
ASSEMBLY_STYLE == "custom" ? customassembly() :
[0,0,0,0,0,0] ;
FRAME_INSET_X = 0.02; // X-direction Inset of vertical frame (vis-a-vis corner pieces)
FRAME_INSET_Y = 0.02; // X-direction Inset of vertical frame (vis-a-vis corner pieces)
FRAME_THICKNESS = 0.10; // Frame thickness
TOP_INSET = 0.02; // Z-direction offset of top panels
SIDE_INSET = 0.03; // Y-direction offset of side panels
SIDE_I = m2mm(SIDE_INSET); // Convert to scale (this needs to be placed here)
/* Supplementary architectural features of the container:
- Opening: a top-to-bottom cut in a wall
- Window: a rectangular cut with a frame
- Wall: an interior wall
- Text: text set into the inner container bottom.
Features are defined by coordinates in a local coordinate
system relative to the wall they're in.
All units in m.
Interior text can be placed in X direction only so far.
*/
PLACE_WINDOWS = false;
PLACE_TEXT_INT = false;
PLACE_TEXT_EXT = true;
FEATURES = [
opening(wall=RIGHT, x=0.5, width=4),
window(wall=LEFT, x=0.75, y=0.8, width=1.8, height=1.7),
window(wall=BACK, x=0.3, y=2.05, width=1.8, height=0.3),
window(wall=FRONT, x=0.3, y=1.05, width=1.8, height=1.8),
wall(dir="x", x=1, y=1.2, length=1.5),
wall(dir="y", x=2.5, y=0.75, length=1.0),
text_int(text="Robe", x=0.25, y=2.1, size=6),
text_int(text="Bed 1", x=3.0, y=1.7, size=8),
text_ext(text=str("1:",SCALE), x=0.25, y=2.1, size=6)
];
// Color the frame differently
FRAMECOLOR="red";
// Parameter definition ends here
// -----------------------------------------------
// Internal constants begin here
// Dimensions of container corner castings from ISO 1161
// Corner casting body
ISO_1161_CORNER_HEIGHT = 0.12;
ISO_1161_CORNER_LENGTH = 0.18;
ISO_1161_CORNER_WIDTH = 0.16;
// Corner casting body thickness
// So far we have not made the corner castings hollow yet,
// so this is just the depth of the corner holes
ISO_1161_CORNER_THICKNESS = 0.028;
// Corner casting hole dimensions
// X and Y holes are identical
ISO_1161_CORNER_Y_HOLE_LENGTH = 0.078;
ISO_1161_CORNER_Y_HOLE_WIDTH = 0.051;
ISO_1161_CORNER_Z_HOLE_LENGTH = 0.124;
ISO_1161_CORNER_Z_HOLE_WIDTH = 0.0635;
// Corner casting holes
ISO_1161_CORNER_X_OFFSET = 0.089;
ISO_1161_CORNER_Y_OFFSET = 0.1;
ISO_1161_CORNER_Z_OFFSET = 0;
// Now we convert all those measurements down to scale
ISO_ch = m2mm(ISO_1161_CORNER_HEIGHT);
ISO_cl = m2mm(ISO_1161_CORNER_LENGTH);
ISO_cw = m2mm(ISO_1161_CORNER_WIDTH);
ISO_cyhl = m2mm(ISO_1161_CORNER_Y_HOLE_LENGTH);
ISO_cyhw = m2mm(ISO_1161_CORNER_Y_HOLE_WIDTH);
ISO_czhl = m2mm(ISO_1161_CORNER_Z_HOLE_LENGTH);
ISO_czhw = m2mm(ISO_1161_CORNER_Z_HOLE_WIDTH);
ISO_ct = m2mm(ISO_1161_CORNER_THICKNESS);
ISO_cxo = m2mm(ISO_1161_CORNER_X_OFFSET);
ISO_cyo = m2mm(ISO_1161_CORNER_Y_OFFSET);
ISO_czo = m2mm(ISO_1161_CORNER_Z_OFFSET);
// Measurements of simple container door
DOOR_INSET = m2mm(0.1); // Doors are inset 10 cm
SEPARATOR_WIDTH = m2mm(0.1);
SEPARATOR_DEPTH = THICKNESS_WALL;
HINGE_LENGTH = m2mm(0.5); // 4 hinges
HINGE_WIDTH = m2mm(0.1);
HINGE_DEPTH = m2mm(0.1);
HINGE_POS_HIGH = m2mm(EXT_HEIGHT)-2*HINGE_LENGTH; // Upper hinge
HINGE_POS_LOW = HINGE_LENGTH; // Lower hinge
LATCH_WIDTH = m2mm(0.5);
LATCH_DEPTH = m2mm(0.1);
LATCH_LENGTH = m2mm(0.1);
LATCH_POS = m2mm(EXT_HEIGHT)/2; // Vertical position
// Ridge parameters
RIDGE_DEPTH = 0.025; // Depth of ridges. Usually between 0.025 and 0.05 (1-2 inches). 0 will get rid of all ridges everywhere
RIDGE_STYLE = "90deg"; // TODO: support different angles
RIDGES_L = EXT_LENGTH > 7 ? 50 : 25; // Number of ridges to create
RIDGES_BOTTOM = EXT_LENGTH > 7 ? 10 : 5; // Number of ridges to create
RIDGES_BOTTOM_RATIO = 0.8; // 80% ridge, 20% bar
// Container sizes in mm in generated model
EXT_L = m2mm(EXT_LENGTH);
EXT_W = m2mm(EXT_WIDTH);
EXT_H = m2mm(EXT_HEIGHT);
FRAME_I_X = m2mm(FRAME_INSET_X);
FRAME_I_Y = m2mm(FRAME_INSET_Y);
FRAME_T = m2mm(FRAME_THICKNESS);
TOP_I = m2mm(TOP_INSET);
// Ridge parameters
RIDGE_D = m2mm(RIDGE_DEPTH);
// Width of ridges depending on number on long side
RIDGE_WIDTH = EXT_L / RIDGES_L;
// Number of ridges on short side, assume equal width
RIDGES_S = EXT_W / RIDGE_WIDTH;
// Ridges at the bottom of containers
RIDGES_BOTTOM_WIDTH = EXT_L / RIDGES_BOTTOM;
// Helper to fix some topology issues in OpenSCAD
INFINITESIMAL=0.0001;
// ------------ You shouldn't need to change anything past here! -----------
/* Container assembly algorithm:
When we look at the container in X direction,
our container consists of the following parts:
* Bottom (interior structures, no frame parts)
* Front (top and bottom frame bars)
* Back (top and bottom frame bars)
* Left (4 corners, 4 frame bars)
* Right (4 corners, 4 frame bars)
* Top (no frame parts)
* Fill (no frame parts)
Any of these can be...
- in place
- flat
- flat reverse, for easier 3D-printing in some cases
The edges of all walls (but not frame bars & corners)
are cut off at 45°, so that the container can be
assembled from separate parts.
----- Styles: -----------------------------------
bottom front left right back top fill
"none" X X X X X X X
"flat" X X X X X X
"ridges" X X X X X X
"crossbars" X
"door" X X
"walls" X
"infill" X
"tank" X
---- Supplementary handling ---------------------
frames X X X X
openings X X X X
text X (internal, on top)
annotation X (external, on the bottom)
WARNING: When adding new styles, make sure that the
parts placement function accounts for the correct thickness
of the respective walls.
*/
PLACEMENT_TEST = false;
module container() {
difference() {
union() {
placePart(BOTTOM, ASSEMBLY[BOTTOM])
bottom(STYLE_BOTTOM);
placePart(FRONT, ASSEMBLY[FRONT])
front(STYLE_FRONT);
placePart(RIGHT, ASSEMBLY[RIGHT])
right(STYLE_RIGHT);
placePart(LEFT, ASSEMBLY[LEFT])
left(STYLE_LEFT);
placePart(BACK, ASSEMBLY[BACK])
back(STYLE_BACK);
placePart(TOP, ASSEMBLY[TOP])
top(STYLE_TOP);
fill(STYLE_FILL);
if(PLACEMENT_TEST) {
// Some test cubes to test if we are above the
// X-Y plane
translate(v=[-40,10,-1])
cube(size=[120,2,1]);
translate(v=[28,-40,-1])
cube(size=[2,120,1]);
};
};
if(PLACEMENT_TEST) {
// Intersect with a couple of test cubes to test if
// we are below the X-Y plane
translate(v=[-20,-40,-5])
cube(size=[10,120,5]);
translate(v=[10,-40,-5])
cube(size=[10,120,5]);
translate(v=[40,-40,-5])
cube(size=[10,120,5]);
translate(v=[70,-40,-5])
cube(size=[10,120,5]);
};
};
};
// Placement of wall parts for separate assembly
// This module essentially consists of a list of displacement
// instructions for various walls.
module placePart(wall, style) {
// Vertical displacement for faces (front and back walls)
SIDE_D = ((wall == RIGHT) && (STYLE_RIGHT == "none")) ||
((wall == LEFT) && (STYLE_LEFT == "none")) ?
ISO_cw : // empty frames: corner width
THICKNESS_WALL + SIDE_I; // all other walls
// Vertical displacement for faces (front and back walls)
FACE_D = ((wall == FRONT) && (STYLE_FRONT == "door")) ||
((wall == BACK) && (STYLE_BACK == "door")) ?
THICKNESS_WALL + DOOR_INSET : // doors
((wall == FRONT) && (STYLE_FRONT == "none")) ||
((wall == BACK) && (STYLE_BACK == "none")) ?
FRAME_T : // empty frames
THICKNESS_WALL + SIDE_I; // all other walls
// In place - leave everything as is (box assembly)
inPlace = [ [[0,0,0],[0,0,0]],
[[0,0,0],[0,0,0]],
[[0,0,0],[0,0,0]],
[[0,0,0],[0,0,0]],
[[0,0,0],[0,0,0]],
[[0,0,0],[0,0,0]] ];
// Face up - place walls ridges up, smooth side down
faceUp = [
[ [0,EXT_W+PART_D,-EXT_H+THICKNESS_WALL+TOP_I],[0,0,0] ], // top
[ [-EXT_H-PART_D,0,FACE_D],[0,90,0] ], // front
[ [EXT_L+EXT_H+PART_D,0,-EXT_L+FACE_D],[0,-90,0] ], // back
[ [0,-EXT_H-PART_D,SIDE_D],[-90,0,0] ], // right
[ [0,2*EXT_W+2*PART_D+EXT_H,-EXT_W+SIDE_D],[90,0,0] ], // left
[ [0,EXT_W,THICKNESS_WALL], [180,0,0] ] // bottom
];
// Face down - place walls ridges down, smooth side up
faceDown = [
[ [0,2*EXT_W+PART_D,EXT_H-TOP_I],[180,0,0] ], // top
[ [-PART_D,0,0],[0,-90,0] ], // front
[ [EXT_L+PART_D,0,EXT_L],[0,90,0] ], // back
[ [0,-PART_D,0],[90,0,0] ], // right
[ [0,2*EXT_W+2*PART_D,EXT_W],[-90,0,0] ], // left
[ [0,0,0], [0,0,0] ] // bottom
];
orientation = [inPlace, faceUp, faceDown];
translate(orientation[style][wall][0])
rotate(orientation[style][wall][1])
children();
};
module side(style=STYLE_RIGHT, features=FEATURES, dir=RIGHT) {
// By default this generates a "right" side.
// To generate left sides, we need to translate &
// rotate it into the correct position.
difference() {
union() {
if (style == "ridges") {
side_ridges();
} else if (style == "flat") {
side_flat();
} else if (style == "none") {
// ISO 1161 frame only
side_frame();
};
// Generate window frames
if (PLACE_WINDOWS) {
for (feature = FEATURES) {
createFrame(feature, dir);
};
};
}; // union
// Generate cutouts
if (PLACE_WINDOWS) {
for (feature = FEATURES) {
createCutout(feature, dir);
};
};
}; // difference
};
module right(style=STYLE_RIGHT, features=FEATURES) {
side(style, features, RIGHT);
};
module left(style=STYLE_LEFT, features=FEATURES) {
// Translate & rotate the default "right" side, so that it
// becomes a "left" side
translate(v=[EXT_L, EXT_W, 0])
rotate([0,0,180])
side(style, features, LEFT);
};
module face(style=STYLE_FRONT, features=FEATURES, dir=FRONT) {
// By default this generates a "front" face.
// To generate "back" faces, we need to translate & rotate it into the correct position.
difference() {
union() {
if (style == "door") {
face_door();
} else if (style == "ridges") {
face_ridges();
} else if (style == "flat") {
face_flat();
} else if (style == "none") {
// Frame only
face_frame();
};
// Generate window frames
if (PLACE_WINDOWS) {
for (feature = FEATURES) {
createFrame(feature, dir);
};
};
}; // union
// Generate cutouts
if (PLACE_WINDOWS) {
for (feature = FEATURES) {
createCutout(feature, dir, offsetX=DOOR_INSET);
};
};
}; // difference
};
module front(style=STYLE_FRONT, features=FEATURES) {
face(style, features, FRONT);
};
module back(style=STYLE_BACK, features=FEATURES) {
// Translate & rotate the default "front" face, so that it
// becomes a "back" face
translate(v=[EXT_L, EXT_W, 0])
rotate([0,0,180])
face(style, features, BACK);
}
module top(style=STYLE_TOP) {
if (style == "ridges") {
top_ridges();
} else if (style == "flat") {
top_flat();
} else if (style == "none") {
// nothing
};
};
module bottom(style=STYLE_BOTTOM, features=FEATURES) {
difference() {
if (style == "crossbars") {
bottom_crossbars();
} else if (style == "ridges") {
bottom_ridges();
} else if (style == "flat") {
bottom_flat();
} else if (style == "none") {
// nothing
};
// superimpose internal text here if we want it
if (PLACE_TEXT_INT) {
for (text = features) {
if (text[TYPE] == TEXT_INT) {
createText(text);
};
};
};
// superimpose bottom text here if we want it
if (PLACE_TEXT_EXT) {
for (text = features) {
if (text[TYPE] == TEXT_EXT) {
createText(text);
};
};
};
};
};
module fill(style=STYLE_FILL, features=FEATURES) {
if (style == "walls") {
// generate interior walls here
for (wall = features) {
createWall(wall);
}
} else if (style == "infill") {
fill_infill();
} else if (style == "tank") {
fill_tank();
} else if (style == "none") {
// nothing
};
};
// Side wall styles
// Side frame
module side_frame(h = EXT_H, l = EXT_L, w = EXT_W,
t = FRAME_T,
inset = [FRAME_I_X, FRAME_I_Y, 0],
ch = ISO_ch, cl = ISO_cl, cw = ISO_cw) {
// Generate parallel beams from offsets & length
beams = concat(
// Horizontal
mve( [ [cl-inf(),0,0],
[cl-inf(),0,h-t] ],
[l-2*cl+inf(2), t, t] ),
// Vertical
mve( [ [inset[0],inset[1],ch-inf()],
[l-t-inset[0],inset[1],ch-inf()]],
[t-inset[0],t-inset[1],h-2*ch+inf(2)]) );
for(i = beams) {
translate(i[0])
color(FRAMECOLOR)
cube(size=i[1]);}
// Corners
for(i = [ [[0,0,0],[0,0,0],[0,0,0]],
[[l,0,0],[1,0,0],[0,0,0]],
[[0,0,h],[0,0,0],[0,0,1]],
[[l,0,h],[1,0,0],[0,0,1]]
]) {
translate(i[0])
mirror(i[1]) mirror(i[2])
color(FRAMECOLOR)
corner();
};
};
// Side flat wall
module side_flat(inset = SIDE_I,
t=FRAME_T, l=EXT_L, h=EXT_H,
wall=THICKNESS_WALL) {
side_frame();
intersection() {
translate(v=[t, inset, t])
cube(size=[l-2*t, wall, h-2*t]);
// corners cut at 45° for easier assembly
translate(v=[0,0,h])
rotate([-90,0,0])
pyramid45(l,h);
};
};
// Side wall with ridges
module side_ridges(inset = SIDE_I,
h=EXT_H, t=FRAME_T,
count=RIDGES_L,
rd=RIDGE_D, rw=RIDGE_WIDTH) {
difference() {
side_flat(inset);
// Generate simple rectangular ridges
for (i = [0 : count - 1]) {
translate (v=[(i*rw) - (rw/4), inset, t])
ridge(rw / 2, rd, h-2*t);
}
};
}
// Face styles
// Frame only
module face_frame(offset = SIDE_I, //ignored
w=EXT_W, h=EXT_H,
t=FRAME_T, cw=ISO_cw){
for(i = [ [0,cw,0],
[0,cw,h-t] ]) {
translate(i)
color(FRAMECOLOR)
cube(size=[t, w-2*cw, t]);
}
};
// Flat wall
module face_flat(offset = SIDE_I,
w=EXT_W, h=EXT_H,
t=FRAME_T, cw=ISO_cw,
wall=THICKNESS_WALL) {
face_frame(offset, w, h, t, cw);
intersection() {
translate(v=[offset, t, t])
cube(size=[wall, w-2*t, h-2*t]);
// corners cut at 45° for easier assembly
translate(v=[0,0,h])
rotate([0,90,0])
pyramid45(h, w);
};
};
// Front wall with vertical ridges
module face_ridges(offset = SIDE_I,
w=EXT_W, h=EXT_H,
t=FRAME_T, cw=ISO_cw,
wall=THICKNESS_WALL,
count=RIDGES_S,
rd=RIDGE_D, rw=RIDGE_WIDTH){
difference() {
face_flat();
for (i = [0 : count - 1]) {
translate (v=[offset, (i*rw) - (rw/4), t])
ridge(rd, rw/2, h-2*t);
}
};
};
// Simple front door: 2 doors, 4 ridges, 4 hinges,
// center separator, latch
module face_door(offset = DOOR_INSET,
w=EXT_W, h=EXT_H,
t=FRAME_T, cw=ISO_cw,
wall=THICKNESS_WALL,
rd=RIDGE_D, rw=RIDGE_WIDTH, // Ridges
sd=SEPARATOR_DEPTH, // Door separator
sw=SEPARATOR_WIDTH,
hpl=HINGE_POS_LOW, // Hinge
hph=HINGE_POS_HIGH,
hl=HINGE_LENGTH,
hw=HINGE_WIDTH, hd=HINGE_DEPTH,
lp=LATCH_POS, ll=LATCH_LENGTH, // Latch
lw=LATCH_WIDTH, ld=LATCH_DEPTH,
) {
face_frame(offset, w, h, t, cw);
// Face plane with 45" cutoff
intersection() {
union() {
// Generate corrugated door
difference() {
// Door plane
translate(v=[offset, t, t])
cube(size=[wall, w-2*t, h-2*t]);
// Ridges in door
for(i = [ [offset, t, hpl+hl/2 - rw*3/2],
[offset, t, hpl+hl/2 + rw*3/2],
[offset, t, hph+hl/2 - rw*3/2],
[offset, t, hph+hl/2 + rw*3/2]
] ) {
translate(v = i)
ridge(rd, w-2*t, rw/2);
}
};
// Door separator
translate(v=[0, w/2-sw/2, t])
cubecylinder(size=[sd, sw, h-2*t]);
// Hinges
for(y = [t, w-t-hw]) {
for(z = [hpl, hph]) {
translate(v=[offset-hd,y,z])
cubecylinder(size=[hd,hw,hl]);
};
};
// Latch
translate(v=[offset-ld,w/2-lw/2,lp])
rotate([-90,0,0])
cubecylinder(size=[ld,ll,lw]);
}; // union
// corners cut at 45° for easier assembly
translate(v=[0,0,h])
rotate([0,90,0])
pyramid45(h, w);
}; // difference
};
// Top styles
// Flat top
module top_flat(offset = TOP_I,
h=EXT_H, l=EXT_L, w=EXT_W,
ch=ISO_ch,cl=ISO_cl,cw=ISO_cw,
t=FRAME_T, wall=THICKNESS_WALL) {
// Figure out how to treat tolerance:
// * TOLERANCE when separate objects
// * -inf() when together, to avoid geometry errors
// in SCAD
delta = (PLACE_TOP != "regular") ? TOLERANCE : -inf();
difference() {
intersection() {
translate(v=[0,0,h-wall-offset])
cube(size=[l,w,wall]);
// corners cut at 45° for easier assembly
translate(v=[0,0,h])
mirror([0,0,1])
pyramid45(l,w);
};
// For the top cover we need different geometry:
// - No overhangs
// - Spare offset around corners easier assembly
// This is so that we can put the top cover on the
// container more easily when printed separately.
//
// Exclude corners
for(i = [ [0,0,0],
[l-cl-delta,0,0],
[0,w-cw-delta,0],
[l-cl-delta,w-cw-delta,0] ]) {
translate(i)
cube(size=[cl+delta,cw+delta,h]); // Full height
};
// Exclude frame bars
cube(size=[l, t+delta, h]);
cube(size=[t+delta, w, h]);
translate([l, w, 0])
rotate([0,0,180]) {
cube(size=[l, t+delta, h]);
cube(size=[t+delta, w, h]);};
};
};
// Ridged top
module top_ridges(offset = TOP_I,
h=EXT_H, l=EXT_L, w=EXT_W,
ch=ISO_ch,cl=ISO_cl,cw=ISO_cw,
t=FRAME_T, wall=THICKNESS_WALL,
count=RIDGES_L,
rd=RIDGE_D, rw=RIDGE_WIDTH) {
difference() {
top_flat(offset, h, l, w, ch, cl, cw, t, wall);
// Generate ridges
for (i = [0 : count - 1]) {
translate (v=[(i*rw) - (rw/4), offset, h-offset-rd])
ridge(rw / 2, w, rd);
}
};
};
// Bottom styles
// Flat bottom
module bottom_flat(l=EXT_L, w=EXT_W, h=EXT_H,
t=FRAME_T,
wall=THICKNESS_WALL,
ch=ISO_ch, cl=ISO_cl, cw=ISO_cw
) {
difference() {
intersection() {
cube(size=[l, w, wall]);
// corners cut at 45° for easier assembly
pyramid45(l, w);
};
// All exclusions full height, to be assembly-friendly
// Exclude corners, full height
for(i = [ [0,0,0],
[l-cl,0,0],
[0,w-cw,0],
[l-cl,w-cw,0] ]) {
translate(i)
cube(size=[cl,cw,h]);
};
// Exclude frame bars, full height
cube(size=[l, t, h]);
cube(size=[t, w, h]);
translate([l, w, 0])
rotate([0,0,180]) {
cube(size=[l, t, h]);
cube(size=[t, w, h]);};
};
};
// Bottom with wide-spaced ridges
module bottom_crossbars() {
difference() {
bottom_flat();
// Ridges along bottom
translate(v=[RIDGES_BOTTOM_WIDTH*(1-RIDGES_BOTTOM_RATIO)/2,0,0])
for (i = [0 : RIDGES_BOTTOM - 1]) {
translate (v=[(i*RIDGES_BOTTOM_WIDTH), FRAME_T, 0])
cube(size=[RIDGES_BOTTOM_WIDTH * RIDGES_BOTTOM_RATIO, EXT_W - 2*FRAME_T, RIDGE_D]);
};
};
};
// Bottom with ordinary ridges
module bottom_ridges() {
difference() {
bottom_flat();
// Ridges along bottom
for (i = [0 : RIDGES_L - 1]) {
translate (v=[(i*RIDGE_WIDTH) - (RIDGE_WIDTH / 4), FRAME_T, 0])
cube(size=[RIDGE_WIDTH / 2, EXT_W - 2*FRAME_T, RIDGE_D]);
};
};
};
// Fill styles
// Filled-in container, no hollow model
module fill_infill(offset = THICKNESS_WALL) {
translate(v=[offset-inf(), offset-inf(), offset-inf()])
cube(size=[EXT_L-2*offset+inf(2),
EXT_W-2*offset+inf(2),
EXT_H-2*offset+inf(2)]);
};
// Single tank for tanktainer
// Possibly customize this more to allow different shapes
module fill_tank(rounding = 5) {
center = [EXT_L/2, EXT_W/2, EXT_H/2];
facecenter = [0, EXT_W/2, EXT_H/2];
minkowski() {
intersection() {
// Faces follow a sphere shape
translate(v=center)
sphere(r=EXT_L/2-rounding, $fn=100);
// Sides follow a cylinder shape
translate(v=facecenter)
rotate([0,90,0])
cylinder(r=EXT_W/2-rounding, h=EXT_L, $fn=50);
};
// The sphere/cylinder boundary is rounded off
sphere(r=rounding, $FN=100);
};
};
// Some geometric primitives
// 45" pyramid over a rectangle of length l and width w
// TODO: this needs to accept a delta value for either
// positive or negative tolerance
module pyramid45(l = EXT_L, w = EXT_W, d=0){
polyhedron(
points = [ [d ,d ,d], [l-d,d, d],
[l-d,w-d,d], [d, w-d,d], // 0,1,2,3: base
[w/2-d/2, w/2, w/2-d/2],
[l-w/2-d/2, w/2, w/2-d/2] // 4,5: top
],
faces = [ [0,1,2,3], // base
[4,5,1,0], // right
[5,2,1], // back
[5,4,3,2], // left
[3,4,0] ], // front
convexity = 2
);
}
// Half cube, half circle
// Cylinder half to the front, cube to the back
module cubecylinder(size = [10,5,20], faces=20) {
union(){
translate(v=[size[1]/2, size[1]/2, 0])
cylinder(r=size[1]/2, h=size[2], $fn=faces);
translate(v=[size[1]/2, 0, 0])
cube(size=[size[0]-size[1]/2, size[1], size[2]]);
}
}
// Container-related geometric helpers
// Ridges of various styles
module ridge(x, y, z, style=RIDGE_STYLE) {
if(style=="90deg") { // Simple 90° ridge is a cube
cube(size=[x, y, z]);
};
// Add other ridge styles here, e.g. customizable angles
};
// ISO 1161 container corner casting - vertical hole
module corner_hole_Z( thickness = ISO_ct ) {
intersection(){
cylinder(h=thickness,r=ISO_czhl/2, $fn=20);
translate(v=[ISO_czhl/-2,ISO_czhw/-2,0])
cube(size=[ISO_czhl, ISO_czhw, thickness]);
};
};
// ISO 1161 container corner casting - front hole
module corner_hole_X(thickness = ISO_ct ) {
corner_hole_Y(thickness);
}
// ISO 1161 container corner casting - side hole
module corner_hole_Y(thickness = ISO_ct ) {
hull() {
translate(v=[(ISO_cyhl-ISO_cyhw)/-2,0,0])
cylinder(h=thickness, r=ISO_cyhw/2, $fn=20);
translate(v=[(ISO_cyhl-ISO_cyhw)/2,0,0])
cylinder(h=thickness, r=ISO_cyhw/2, $fn=20);
}
};
// ISO 1161 container corner casting
module corner() {
difference() {
cube(size=[ISO_cl, ISO_cw, ISO_ch]);
// X hole
translate(v=[0,ISO_cxo,m2mm(ISO_1161_CORNER_HEIGHT)/2])
rotate([0,90,0])
translate(v=[m2mm(0.005),0,inf(-1)])
corner_hole_X();
// Y hole
translate(v=[ISO_cyo,0,ISO_ch/2])
rotate([-90,90,0])
translate(v=[m2mm(0.005),0,inf(-1)])
corner_hole_Y();
// Z hole
translate(v=[ISO_cyo, ISO_cxo,0])
corner_hole_Z();
// Hollow core
// Add this if necessary
};
};
// Helper functions - Generate various container features
// Create text embedded in the floor
// TODO: implement rotation
module createText(text) {
// Text at the top of the floor
if (text[TYPE] == TEXT_INT) {
translate ([m2mm(text[X]), m2mm(text[Y]), THICKNESS_WALL * 0.75])
linear_extrude(height = THICKNESS_WALL) {
text(text = text[STRING],
font = "Arial",
size = text[FONT_SIZE],
halign = "left",
valign = "top");
};
// Text at the bottom of the floor
} else if (text[TYPE] == TEXT_EXT) {
translate ([EXT_L-m2mm(text[X]), m2mm(text[Y]), 0])
mirror([1,0,0])
linear_extrude(height = THICKNESS_WALL * 0.25) {
text(text = text[STRING],
font = "Arial",
size = text[FONT_SIZE],
halign = "left",
valign = "top");
};
};
};
// Create cutouts (applies to openings and windows)
module createCutout(opening, direction = "", offsetX = 0, offsetY = 0) {
// Optionally limit generating cutouts to a single wall
if (direction == "" || direction == opening[DIR]) {
if (opening[TYPE] == WINDOW || opening[TYPE] == OPENING) {
translate (v=[x(opening), y(opening), z(opening)])
cube(size=[w(opening)+offsetX,
d(opening)+offsetY,
h(opening)]);
};
};
}
// Create the frame for a window
module createFrame(opening, direction="") {
// Optionally limit frame generation to a single wall
if (direction == "" || direction == opening[DIR]) {
if (opening[TYPE] == WINDOW) {
echo("Placing stuff in direction", opening[DIR]);
placement =
opening[DIR] == LEFT || opening[DIR] == RIGHT ?
[[x(opening) - 1, y(opening), z(opening) - 1],
[w(opening) + 2, d(opening), h(opening) + 2]] :
opening[DIR] == BACK || opening[DIR] == FRONT ?
[[x(opening), y(opening) - 1, z(opening) - 1],
[w(opening), d(opening) + 2, h(opening) + 2]] :
// [w(opening), d(opening) + 2, h(opening) + 2]] :
[[],[]];
cutoff =
opening[DIR] == LEFT || opening[DIR] == RIGHT ?
[[0,0,EXT_H], [-90,0,0], [EXT_L,EXT_H],
[EXT_L, FRAME_THICKNESS, EXT_H]] :
opening[DIR] == BACK || opening[DIR] == FRONT ?
[[0,0,EXT_H], [0,90,0], [EXT_W, EXT_H],
[FRAME_THICKNESS, EXT_W, EXT_H] ] :
[ [], [], [], [] ];
// When generating window frames, we need to make
// sure that that they also follow the internal 45°
// edge cutoff (for easier assembly)
intersection() {
// The frame is just a cube, we cut out the
// opening for the window separately.
translate(v=placement[0])
cube(size=placement[1]);
union() {
// Cut off wall edges at 45° internally
translate(v=cutoff[0])
rotate(cutoff[1])
pyramid45(cutoff[2][0], cutoff[2][1]);
// Leave frame on the outside as is