-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathdoblo-factory.scad
688 lines (616 loc) · 24.8 KB
/
doblo-factory.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
/*
Copyright (c) 2013 Daniel M. Taub
Copyright (c) 2010 Daniel K. Schneider
This file is part of DobloFactory.
DobloFactory is free source: you can redistribute it and/or modify
modify it under the terms of the CC BY-NC-SA 3.0 License:
CreativeCommons Attribution-NonCommerical-ShareAlike 3.0
as published by Creative Commons.
You should have received a copy of the CC BY-NC-SA 3.0 License
with this source package.
If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>
*/
// may change this include based on printer types
include <lib/doblo-params.scad>;
NUDGE = .001; // slight amount to make sure interfaces touch
// -------------------------------- DOBLO and STL merging ------------------------------
// Import an STL and place it.
// Only tested with DUPLOS !!
module merge_stl (file, col, row, up, stl_z_offset_mm, scale,shrink = 1) {
// Move STOL right and forward - origin is x=leftmost and y=backmost
x_offset_mm = col * PART_WIDTH(scale) + PART_WIDTH(scale) ;
y_offset_mm = - (row * PART_WIDTH(scale) + PART_WIDTH(scale)) ;
z_offset_mm = up * PART_HEIGHT(scale) + stl_z_offset_mm ;
// the STL
translate([x_offset_mm, y_offset_mm, z_offset_mm])
{
scale(1/shrink) import(file);
}
}
// ----------------------------------- DOBLO bricks making code -------------------------------
// all of these can be used in custom modules, i.e. they respect the grid model
module doblo (col, row, up, width,length,height,nibbles_on_off,diamonds_on_off,scale)
/* Use cases:
- typical Doblo block, use only once to create the first layer, e.g. a small or larger plate
that can fit on top of another doblo or Duplo(TM) block.
- See also "block", it doesn't have nibbles underneath and it should be used to build 3D structures
- See also doblo_light, a more light-weight block with just "grid walls" underneath.
*/
{
// build the cube from its center
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) + height * PART_HEIGHT(scale) / 2.0;
// User info
echo(str("DOBLO brick width(x)=", width * PART_WIDTH(scale), "mm, length=", length*PART_WIDTH(scale), "mm, height=", height*PART_HEIGHT(scale), "mm" ));
// the cube is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
//the doblo
union () {
if (diamonds_on_off && (width > 1 && length > 1)) {
difference () {
difference() {
// the cube
cube([width*PART_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)], true);
// inner emptiness, a bit smaller and shifted down
translate([0,0,-DOBLOWALL(scale)])
#cube([width*PART_WIDTH(scale) - 2*DOBLOWALL(scale), length*PART_WIDTH(scale)-2*DOBLOWALL(scale), height*PART_HEIGHT(scale)], true);
}
// diamonds
diamonds (width, length, height, scale=scale);
}
}
else {
difference() {
// the cube
cube([width*PART_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)], true);
// inner emptiness, a bit smaller and shifted down
translate([0,0,-DOBLOWALL(scale)])
cube([width*PART_WIDTH(scale) - 2*DOBLOWALL(scale), length*PART_WIDTH(scale)-2*DOBLOWALL(scale), height*PART_HEIGHT(scale)], true);
}
}
// nibbles on top
if (nibbles_on_off)
{
// (col, row, up, width, length)
nibbles (-width/2, -length/2, height/2, width, length, scale = scale);
}
// nibbles underneath - only if x or y is bigger than 1
if (width > 1 && length > 1)
{
// big nibbles underneath
bottom_nibbles (width, length, height, scale = scale);
// lattice (for low resolution printers - e.g. 0.35 layers - this is not needed)
if (LATTICE_TYPE > 0 )
{
bottom_lattice (width, length, height, scale = scale);
}
}
else {
// big nibbles underneath
if (USE_INSET(scale))
bottom_nibbles_part (width, length, height, scale = scale);
// lattice (for low resolution printers - e.g. 0.35 layers - this is not needed)
/*if (LATTICE_TYPE > 0 )
{
bottom_lattice (width, length, height, scale = scale);
}
*/
}
if ((scale < 0.6) && (!USE_INSET(scale)))
{
bottom_nibbles_thin (width, length, height,scale=scale);
}
//little walls inside (insets)
if (USE_INSET(scale))
difference()
{
union()
{
for(j=[1:length])
translate([0,-PART_WIDTH(scale)*length/2+j*2*NO(scale)-2*NO(scale)/2,0]) cube([width*PART_WIDTH(scale), INSET_WIDTH(scale), height*PART_HEIGHT(scale)],true);
for (i = [1:width])
translate([-PART_WIDTH(scale)*width/2+i*2*NO(scale)-2*NO(scale)/2,00]) cube([INSET_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)],true);
}
cube([width*PART_WIDTH(scale)-INSET_LENGTH(scale), length*PART_WIDTH(scale)-INSET_LENGTH(scale), height*PART_HEIGHT(scale)+2], true);
}
}
}
}
module nibbles (col, row, up, width, length, scale, extra = false,filled=false,hscale = 1)
/* Use cases:
- needed by the doblo and the block modules
- can also be stuck on top on parts of a nibble-less doblo or block
*/
{
// Uses a local coordinate system left/back = 0,0
// E.g. nibbles (-2, -2, 0, 4, 4 );
// echo ("PART_WIDTH(scale)", PART_WIDTH(scale), "NO(scale)", NO(scale));
x_start = col * PART_WIDTH(scale) + NO(scale) ;
// echo ("x_start", x_start, "col", col);
y_start = - ( row * PART_WIDTH(scale) + NO(scale));
// echo ("y_start", y_start, "row", row);
z_local = up * PART_HEIGHT(scale) + NH(scale) / 2;
translate ([x_start , y_start, z_local]) {
// 0,0 is left/back corner. Draw to the right (x) and forward (-y)
for(j=[1:length])
{
for (i = [1:width])
{
translate([(i-1) * PART_WIDTH(scale), -(1) * (j-1) * PART_WIDTH(scale), 0]) doblonibble(scale = scale,extra=extra,filled=filled,heightscale=hscale);
}
}
}
}
module diamonds (width, length, height)
{
x_start = -width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = -length/2 * PART_WIDTH(scale) + NBO(scale);
z_pos = -height * PART_HEIGHT(scale)/2+DIAMOND;
echo (str ("height = ", height, "z_pos= ", z_pos));
translate ([0, y_start, z_pos]) {
// holes along y-axis
for (i = [0:length-2]) {
// echo (str ("diamond y offset=", i*PART_WIDTH(scale)+PART_WIDTH(scale)));
translate([0, i* NBO(scale), 0])
rotate (a=45, v=[1,0,0]) { cube([width*PART_WIDTH(scale)+PART_WIDTH(scale),DIAMOND,DIAMOND],true); }
}
}
translate ([x_start, 0, z_pos]) {
// holes along x-axis
for (j = [0:width-2]) {
// echo (str ("diamond x offset=", j*PART_WIDTH(scale)-PART_WIDTH(scale)));
translate([j * NBO(scale), 0, 0])
rotate (a=45, v=[0,1,0]) { cube([DIAMOND,length*PART_WIDTH(scale)+PART_WIDTH(scale),DIAMOND],true); }
}
}
}
// produces a wider spaced lattice (not used currently)
module bottom_lattice_wide (width, length, height)
{
x_start = -width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = -length/2 * PART_WIDTH(scale) + NBO(scale);
z_pos = height * PART_HEIGHT(scale)/2 - LATTICE_WIDTH(scale) - LATTICE_WIDTH(scale)/2;
translate ([0, y_start, z_pos]) {
// grid along y-axis
for (i = [0:length-2]) {
translate([0, i* NBO(scale), 0])
{ cube([width*PART_WIDTH(scale), LATTICE_WIDTH(scale), LATTICE_WIDTH(scale)],true); }
}
}
// grid along x-axis
translate ([x_start, 0, z_pos]) {
// holes along x-axis
for (j = [0:width-2]) {
translate([j * NBO(scale), 0, 0])
{ cube([LATTICE_WIDTH(scale),length*PART_WIDTH(scale),LATTICE_WIDTH(scale)],true); }
}
}
}
module bottom_lattice (width, length, height)
{
spacing = NBO(scale)/LATTICE_TYPE;
x_start = -width/2 * PART_WIDTH(scale) + spacing;
y_start = -length/2 * PART_WIDTH(scale) + spacing;
z_pos = height * PART_HEIGHT(scale)/2 - LATTICE_WIDTH(scale) - LATTICE_WIDTH(scale)/2;
translate ([0, y_start, z_pos]) {
// grid along y-axis
for (i = [0:LATTICE_TYPE*length-2]) {
translate([0, i* spacing, 0])
{ cube([width*PART_WIDTH(scale), LATTICE_WIDTH(scale), LATTICE_WIDTH(scale)],true); }
}
}
// grid along x-axis
translate ([x_start, 0, z_pos]) {
// holes along x-axis
for (j = [0:LATTICE_TYPE*width-2]) {
translate([j * spacing, 0, 0])
{ cube([LATTICE_WIDTH(scale),length*PART_WIDTH(scale),LATTICE_WIDTH(scale)],true); }
}
}
}
module bottom_nibbles_thin (width, length, height)
/* Use cases:
- needed by the doblo module
- can also be stuck into the feet of an imported STL
*/
{
x_start = -width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = -length/2 * PART_WIDTH(scale) + NBO(scale);
z_local = 0;
translate ([x_start , y_start, z_local]) {
if (width == 1){
for(j=[0:length-2])
{
translate([-NBO(scale)/2, j * NBO(scale), 0]) doblobottomnibble_thin(height*PART_HEIGHT(scale),scale=scale);
}
}
else if (length == 1){
for (i = [0:width-2])
{
translate([i * NBO(scale), -NBO(scale)/2, 0]) doblobottomnibble_thin(height*PART_HEIGHT(scale),scale=scale);
}
}
}
}
module bottom_nibbles_part (width, length, height)
/* Use cases:
- needed by the doblo module for h or w == 1
*/
{
SUPPORT_HEIGHT = height * PART_HEIGHT(scale);
x_start = -width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = -length/2 * PART_WIDTH(scale) + NBO(scale);
z_local = 0;
translate ([x_start , y_start, z_local]) {
if(width == 1){
for(j=[0:length-1]){
translate([0-ALONG_LEN(scale)/4,j*2*NO(scale)-NO(scale),0])
cube([ALONG_LEN(scale)/2, INSET_WIDTH(scale), SUPPORT_HEIGHT],true);
translate([-2*NO(scale)+ALONG_LEN(scale)/4,j*2*NO(scale)-NO(scale),0])
cube([ALONG_LEN(scale)/2, INSET_WIDTH(scale), SUPPORT_HEIGHT],true);
if (j!= length-1)
translate([-NO(scale),j*2*NO(scale),0]){
union(){
cube([INSET_WIDTH(scale), ALONG_LEN(scale), SUPPORT_HEIGHT],true);
cube([CROSS_LEN(scale), INSET_WIDTH(scale), SUPPORT_HEIGHT],true);
}
}
}
}
else if (length == 1) {
for(i=[0:width-1]) {
translate([i*2*NO(scale)-NO(scale),0-ALONG_LEN(scale)/4,0])
cube([INSET_WIDTH(scale), ALONG_LEN(scale)/2, SUPPORT_HEIGHT],true);
translate([i*2*NO(scale)-NO(scale),-2*NO(scale)+ALONG_LEN(scale)/4,0])
cube([INSET_WIDTH(scale), ALONG_LEN(scale)/2, SUPPORT_HEIGHT],true);
if (i != width-1)
translate([i*2*NO(scale),-NO(scale),0])
union(){
cube([INSET_WIDTH(scale), CROSS_LEN(scale), SUPPORT_HEIGHT],true);
cube([ALONG_LEN(scale), INSET_WIDTH(scale), SUPPORT_HEIGHT],true);
}
}
}
}
}
module bottom_nibbles (width, length, height)
/* Use cases:
- needed by the doblo module
- can also be stuck into the feet of an imported STL
*/
{
x_start = -width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = -length/2 * PART_WIDTH(scale) + NBO(scale);
z_local = 0;
translate ([x_start , y_start, z_local]) {
for(j=[0:length-2])
{
for (i = [0:width-2])
{
translate([i * NBO(scale), j * NBO(scale), 0]) doblobottomnibble(height*PART_HEIGHT(scale),scale=scale);
}
}
}
}
module tri_prism(top,side,end)
{
translate([side/2,-end/2,-top/6-NUDGE])rotate([0,-90,0])linear_extrude(height=side)
polygon(points=[[0,0],[top,end],[0,end]],paths=[[0,1,2]]);
}
module angle_doblo(col,row,up,width,length,width,height,nibbles_on_off,scale){
doblo(col,row,up,width,length,height,false,false,scale);
angle_block(col,row,up+2,width,length,height,nibbles_on_off,scale);
}
module angle_block (col, row, up, width,length,height,nibbles_on_off, scale)
{
// build the cube from its center
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) + height * PART_HEIGHT(scale) / 2.0;
top = PART_HEIGHT(scale)*height;
side = PART_WIDTH(scale)*width;
end = PART_WIDTH(scale)*length;
ang = atan(top/end);
hyp = top/sin(ang);
off_y = (hyp-end)/2;
off_z = -NUDGE ;//-top/6-NUDGE;
oy = (hyp-end)/2;
oz=-top/FULL-NUDGE;
// the cube is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
tri_prism(top,side,end);
// nibbles on top
if (nibbles_on_off)
{
// (col, row, up, width, length)
translate([0,oy,oz])rotate([ang,0,0])translate([0,off_y,off_z])nibbles (-width/2, -length/2, height/2, width, length, scale=scale);
}
}
}
module block (col, row, up, width,length,height,nibbles_on_off, scale)
/* Use cases:
- building blocks for 3D structures (saves times and plastic, use a light fill in skeinforge)
- movable blocks for games (printed apart)
*/
{
// build the cube from its center
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) + height * PART_HEIGHT(scale) / 2.0;
// the cube is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
//the cube
cube([width*PART_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)], true);
// nibbles on top
if (nibbles_on_off)
{
// (col, row, up, width, length)
nibbles (-width/2, -length/2, height/2, width, length, scale=scale);
}
}
}
module house_lr (col, row, up, width,length,height, scale)
/* Use cases:
- create doors with openscad difference operator
- a hack, only work along x axis and with a min. height and width
*/
{
// build the cube from its center
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) + height * PART_HEIGHT(scale) / 2.0;
roof_l = sqrt ( (length*PART_WIDTH(scale)*length*PART_WIDTH(scale)) + (length*PART_WIDTH(scale)*length*PART_WIDTH(scale) ) ) / 2;
// the cube is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
//the cube
cube([width*PART_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)], true);
translate ([0,0,height*PART_HEIGHT(scale)/2]) {
rotate ([45,0,0]) {
cube([width*PART_WIDTH(scale), roof_l, roof_l], true);
}
}
}
}
module house_fb (col, row, up, width,length,height, scale)
/* Use cases:
- create doors with openscad difference operator
- a hack, only work along y axis and with a min. height and length ... try ;)
*/
{
// build the cube from its center
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) + height * PART_HEIGHT(scale) / 2.0;
// That was 40 years ago
roof_l = sqrt ( (width*PART_WIDTH(scale)*width*PART_WIDTH(scale)) + (width*PART_WIDTH(scale)*width*PART_WIDTH(scale) ) ) / 2;
// the cube is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
//the cube
cube([width*PART_WIDTH(scale), length*PART_WIDTH(scale), height*PART_HEIGHT(scale)], true);
translate ([0,0,height*PART_HEIGHT(scale)/2]) {
rotate ([0,45,0]) {
cube([roof_l, length*PART_WIDTH(scale), roof_l], true);
}
}
}
}
LEGO_DIV = false;
module base_plate (col, row, up, width,length,height,nibbles_on_off, scale)
/* Use cases:
- Creating an easy to print base plate for showing off your prints. I believe that buying one in a shop is more efficient ....
- to do: an other version that has round holes allowing to stack it.
*/
{
// construction of the grid underneath
// spacing = (scale < 0.6) ? NBO(scale)/LATTICE_TYPE*2 : NBO(scale)/LATTICE_TYPE;
spacing = (scale > 0.6) ? NBO(scale) : NBO(scale)*2;
offset = NBO(scale);
x_start = - width/2 * PART_WIDTH(scale) + NBO(scale);
y_start = - length/2 * PART_WIDTH(scale) + NBO(scale);
z_pos = (scale<0.6) ? height * PART_HEIGHT(scale)/2 - LATTICE_WIDTH(scale) * 2 : height * PART_HEIGHT(scale)/2 - LATTICE_WIDTH(scale) - LATTICE_WIDTH(scale)/2 ;
n_rows = (scale > 0.6) ? length-2 : (length-2)/2 ; // Need less for legos
n_cols = (scale > 0.6) ? width-2 : (width-2)/2;
// positioning of the grid with respect to the cube
x_0 = col * PART_WIDTH(scale) + width * PART_WIDTH(scale) / 2.0;
y_0 = - (row * PART_WIDTH(scale) + length * PART_WIDTH(scale) / 2.0) ;
z_0 = up * PART_HEIGHT(scale) ;
difference () {
block (col, row, up, width,length,height,nibbles_on_off, scale) ;
union () {
translate ([x_0, y_0, z_0])
{
translate ([0, y_start, z_pos]) {
// grid along y-axis
for (i = [0:n_rows]) {
translate([0, i* spacing, 0])
{ cube([width*PART_WIDTH(scale)-offset*2, LATTICE_WIDTH(scale), LATTICE_WIDTH(scale)],true); }
}
}
// grid along x-axis
translate ([x_start, 0, z_pos]) {
// holes along x-axis
for (j = [0:n_cols]) {
translate([j * spacing, 0, 0])
{ cube([LATTICE_WIDTH(scale),length*PART_WIDTH(scale)-offset*2,LATTICE_WIDTH(scale)],true); }
}
}
}
}
}
}
// ------ Cylinder block
module cyl_block (col, row, up, bottom_r, top_r, height, nibbles_on_off, scale)
{
bottom_r_mm = bottom_r * NO(scale);
top_r_mm = top_r * NO(scale);
x_0 = col * PART_WIDTH(scale) + bottom_r_mm;
y_0 = - (row * PART_WIDTH(scale) + bottom_r_mm);
z_0 = up * PART_HEIGHT(scale);
// the cylinder is drawn at absolute x,y,z = 0 then moved
translate ([x_0, y_0, z_0]) {
cylinder(h= height*PART_HEIGHT(scale), r1 = bottom_r_mm, r2 = top_r_mm, center = false, $fs = 0.2);
if (nibbles_on_off)
{
// (col, row, up, width, length)
// circle is a bit different from cube
nibbles (-top_r/2+0.5, -top_r/2+0.5, height, top_r-1, top_r-1, scale);
}
}
}
// -------------- support block (triangle )
// Support block for building platforms
// so bad ... :(
// NOTE: make the support block stick into something, else it won't print
module support (col,row,up,height,angle,thickness, scale)
{
if (angle == 0) {
translate ([0, 0, 0]) {
support1 (col,row,up,height,angle,thickness, scale);
}
}
if (angle == 90) {
translate ([0, -PART_WIDTH(scale) , 0]) {
support1 (col,row,up,height,angle,thickness, scale);
}
}
if (angle == 180) {
translate ([PART_WIDTH(scale), -PART_WIDTH(scale) - PART_WIDTH(scale)* (thickness-1) , 0]) {
support1 (col,row,up,height,angle,thickness, scale);
}
}
if (angle == 270) {
translate ([PART_WIDTH(scale) + PART_WIDTH(scale) * (thickness-1), 0 , 0]) {
support1 (col,row,up,height,angle,thickness, scale);
}
}
}
module support1 (col,row,up,height,angle,thickness, scale)
{
height_mm = height * PART_HEIGHT(scale) ;
length_mm = height * PART_WIDTH(scale) / 4;
width_mm = PART_WIDTH(scale)*thickness;
x_0 = col * PART_WIDTH(scale);
y_0 = - (row * PART_WIDTH(scale));
z_0 = up * PART_HEIGHT(scale);
translate ([x_0, y_0 , z_0]) {
rotate (a=angle, v=[0,0,1]) {
polyhedron ( points = [[0, -width_mm, height_mm], [0, 0, height_mm], [0, 0, 0], [0, -width_mm, 0], [length_mm, -width_mm, height_mm], [length_mm, 0, height_mm]], triangles = [[0,3,2], [0,2,1], [3,0,4], [1,2,5], [0,5,4], [0,1,5], [5,2,4], [4,2,3], ]);
}
}
}
// --------------------- ramp
module ramp (col,row,up,height,angle,scale)
{
if (angle == 0) {
translate ([0, -NO(scale), 0]) {
ramp1 (col,row,up,height,angle);
}
}
if (angle == 90) {
translate ([NO(scale), -(2*NO(scale)) , 0]) {
ramp1 (col,row,up,height,angle);
}
}
if (angle == 180) {
translate ([(2*NO(scale)), -NO(scale) , 0]) {
ramp1 (col,row,up,height,angle);
}
}
if (angle == 270) {
translate ([NO(scale), 0 , 0]) {
ramp1 (col,row,up,height,angle);
}
}
}
module ramp1 (col,row,up,height,angle)
{
height_mm = height * PART_HEIGHT(scale);
length_mm = height * PART_WIDTH(scale);
x_0 = col * PART_WIDTH(scale);
y_0 = - (row * PART_WIDTH(scale));
z_0 = up * PART_HEIGHT(scale);
translate ([x_0, y_0 , z_0]) {
rotate (a=angle, v=[0,0,1]) {
polyhedron ( points = [[0, -NO(scale), height_mm], [0, NO(scale), height_mm], [0, NO(scale), 0], [0, -NO(scale), 0], [length_mm, -NO(scale), 0], [length_mm, NO(scale), 0]], triangles = [[0,3,2], [0,2,1], [3,0,4], [1,2,5], [0,5,4], [0,1,5], [5,2,4], [4,2,3], ]);
}
}
}
// ---------------------------------- Auxiliary modules ---------------------
module doblonibble(extra=false,filled=false,heightscale=1) {
// Lego size does not have holes in the nibbles
nb_r = NB_RADIUS(scale) + (extra ? DOBLOWALL(scale)/2.2 : 0);
nb_r_i = NB_RADIUS_INSIDE(scale) + (extra ? DOBLOWALL(scale)/2.2 : 0);
if (scale < 0.6 || filled) {
cylinder(r=nb_r, h=heightscale*NH(scale), center=true, $fs = 0.2);
} else {
difference() {
cylinder(r=nb_r, h=heightscale*NH(scale), center=true, $fs = 0.2);
cylinder(r=nb_r_i,h=heightscale*NH(scale)+1,center=true, $fs = 0.2);
}
}
}
module doblobottomnibble(height_mm)
{
difference() {
cylinder(r=NB_BOTTOM_RADIUS(scale), h=height_mm, center=true,$fs = 0.2);
cylinder(r=NB_BOTTOM_RADIUS_INSIDE(scale), h=height_mm+1,center=true,$fs = 0.2);
}
}
module doblobottomnibble_thin(height_mm)
{
cylinder(r=NB_BOTTOM_RADIUS_THIN(scale), h=height_mm, center=true,$fs = 0.2);
//cylinder(r=NB_BOTTOM_RADIUS_INSIDE(scale)/4, h=height_mm+1,center=true,$fs = 0.2);
}
/*
Hackey--should build shell separately and then insert bottom nibbles
currently, has some holes. Even CW is duplo compatible, odd is offset .5
*/
module doblo_curve_down(col,row,up,width,length,height,nibbles,size,cw=1){
difference(){
block_curve_down(col,row,up,width,length,height,nibbles,size,cw=cw);
translate([0,0,-0.01])difference(){
block(col-cw/2,row,up,width+cw,length,height*2/3,false,size);
doblo(col-cw/2,row,up,width+cw,length,height*2/3,false,false,size);
}
}
}
module doblo_curve_up(col,row,up,width,length,height,nibbles,size,cw=2,bottom_holes=true){
difference(){
union(){
translate([-0.01,0,0])curve(col+width,row,up,cw,length,height,false,true,size);
translate([0.01,0,0])curve(col-1,row,up,cw,length,height,true,true,size);
doblo(col,row,up,width,length,height,nibbles,false,size);
if(nibbles && cw>1){
nibbles(col-floor(cw/2),row,up+height,floor(cw/2),length,size);
nibbles(col+width,row,up+height,cw/2,length,size);
}
}
if (bottom_holes){
nibbles(col+width,row,up,ceil(cw),length,DOBLO,filled=true,hscale=1.5);
nibbles(col-ceil(cw),row,up,ceil(cw),length,DOBLO,filled=true,hscale=1.5);
}
}
}
module block_curve_down(col,row,up,width,length,height,nibbles,size,cw=1){
//intersection(){
union(){
curve(col-1,row,up,cw,length,height,blockType=size);
block(col,row,up,width,length,height,nibbles,size);
curve(col+width,row,up,cw,length,height,blockType=size,xflip=false);
}
// doblo(col,row,up,width,length,height,nibbles,false,size);
// }
}
module curve(x=0,y=0,z=0,w=1,h=1,d=FULL,xflip=true,yflip=false,blockType=DOBLO){
bwidth = DOBLOWIDTH(blockType)/blockType;
bheight = PART_HEIGHT(blockType);
offset = xflip ? -bwidth/2 : 0;
boxoffset = xflip ? (1-w)*bwidth/2 : 0;
zoff = yflip ? bheight*d : 0;
translate([(x/2)*bwidth-offset,(-y/2)*bwidth,(z)*bheight])
intersection(){
translate([0,0,zoff])rotate([90,0,0])scale([1,bheight*d*2/(bwidth*w/2) ,1])cylinder(h=bwidth/2*h,r=w*bwidth/4);
translate([boxoffset+offset,-bwidth/2*h-.05,0])cube([(w)*bwidth/2,h*bwidth/2+.1,bheight*d]);
}
}