-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenSCADSpool.scad
More file actions
497 lines (439 loc) · 16.8 KB
/
Copy pathOpenSCADSpool.scad
File metadata and controls
497 lines (439 loc) · 16.8 KB
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
// Render part of spool
show = "bottom"; // [all, bottom, top, barrel, cutout, label]
/* [Size] */
// Spool outer diameter
flange_diameter = 200;
// Spool inner diameter
barrel_diameter = 81.0; // 0.1
// Hole diameter
bore_diameter = 57.0; // 0.1
// Inner width of the spool. Overal width is width + 2 x flange_width
width = 60.0; // 0.1
// Strength of the flange
flange_width = 3.5; // 0.1
// Thickness of the outer flange border
flange_wall = 6.0; // 0.1
/* [Flange] */
// Number of cutouts to safe material and weight (-1: disable)
flange_cutout_segments = 3; // [-1:1:12]
// Export as 3MF or AMF file, set in your slicer on this object top and bottom shell layers to 0 and choose an infill pattern (see README.md for details)
flange_cutout_keep = false; // [false, true]
// Cutout crossing width
flange_cutout_crossing_width = 20;
// Window width in the crossing (0: disable)
flange_cutout_crossing_window = 0;
// Extend the crossing window to the bore (for cable tie)
flange_cutout_crossing_window_bore = false; // [false, true]
// Round cutout corners
flange_cutout_fillet = 3;
// Filament clip on the flange border
flange_filament_clip = false; // [false, true]
// Number of hole pairs
flange_filament_hole_count = 4; // [1:1:12]
// Filament holes BambuLab spool compatible
flange_filament_hole_bambulab = false; // [false, true]
// Inclined filament holes
flange_filament_hole_inclined = false; // [false, true]
// Chamfer of flange
flange_chamfer_size = 1.0; // 0.1
/* [Barrel] */
// Type of the barrel
barrel_type = "quick"; // [modular, quick, solid]
// Connector snap strength (0: No snap / 1: standard / 2: full
snap_ratio = 1; // [0:0.05:2]
// Bore wall thickness (when barrel not solid)
bore_wall = 1.8; // 0.1
// Barrel wall thickness (when barrel not solid)
barrel_wall = 1.2; // 0.1
// How many percent of the barrel wall is on the bottom side
barrel_wall_split_percent = 20;
// Notch for BambuLab filament, only on the top part of the spool (position; 0: disable)
barrel_notch_bambulab = 0; // [0:1:12]
// Hole to hold end of filament, only on the top part of the spool (position; 0: disable)
barrel_fixing_hole = 0; // [0:1:12]
/* [Label] */
// Level meter
label_level_meter = false; // [false, true]
// Diameter of the content when full (0: max (flange_radius) )
label_level_full_diameter = 174;
// Show this value on full mark
label_level_full_factor = 1000;
// Font size
label_level_font_size = 5.5; // 0.1
// Texture depth
label_depth = 0.8; // 0.1
// Use color instead of relief
label_color = false; // [false, true]
// Area for BambuLab label (position; 0: disable)
label_area_bambulab = 0; // [0:1:12]
// Separate color for BambuLab label area
label_area_bambulab_color = false; // [false, true]
// Custom label area (position; 0: disable)
label_area_position = 0; // [0:1:12]
// Custom label area width and height (0: disable)
label_area_size = [90, 40];
/* [Other] */
// Small pocket (include lid) to reuse BambuLab RFID tags (position; 0: disable)
bambulab_rfid_pocket = 0; // [0:1:12]
/* [Hidden] */
flange_radius = flange_diameter / 2;
barrel_radius = barrel_diameter / 2;
bore_radius = bore_diameter / 2;
outer_width = width + 2 * flange_width;
connector_radius = bore_radius + bore_wall + 3.2;
barrel_height_top = width * (1 - (barrel_wall_split_percent / 100));
label_level_full_radius = label_level_full_diameter / 2;
rounding_mesh_error = 0.001;
$fn = 200;
if (show == "all" || show == "bottom") {
color([0.5, 0.5, 0.5]) union() {
flange();
if (barrel_type == "quick") barrel();
}
}
if (show == "all" || show == "barrel") {
color([0.5, 0.5, 0.5]) {
if (barrel_type != "quick") barrel(true);
}
}
if (show == "all" || show == "top") {
spool_show() color([0.5, 0.5, 0.5]) union() {
flange();
if (barrel_type == "quick") barrel(true);
}
}
if (flange_cutout_keep || show == "cutout") {
spool_show(true) color([1, 1, 0]) linear_extrude(flange_width) flange_cutout();
}
if (label_color || show == "label") {
spool_show(true) color([0, 0, 0]) linear_extrude(label_depth) flange_level();
}
if (label_area_bambulab_color) {
spool_show(true) color([1, 1, 1]) linear_extrude(0.2) label_area_bambulab();
}
/*********
* Common *
*********/
module ring(inner_radius, outer_radius) {
difference() {
circle(outer_radius);
circle(inner_radius);
}
}
module tube(inner_radius, outer_radius, height) {
linear_extrude(height) ring(inner_radius, outer_radius);
}
module crossings_rotate(segments) {
for (i = [0 : 1 : segments - 1]) {
rotate([0, 0, (360 / segments) * i]) children();
}
}
/**
* Rotate to the cutout center
*
* @param number Segment number
*/
module cutout_rotate(number = 1) {
rotate([0, 0, (flange_cutout_segments ? (360 / flange_cutout_segments) * (number - 0.5) : 0)]) children();
}
/********
* Spool *
*********/
module spool_show(both = false) {
if (show == "all") translate([0, 0, outer_width]) rotate([180, 0, 0]) children();
if (show != "all" || both) children();
}
/*********
* Flange *
**********/
module flange() {
difference() {
intersection() {
linear_extrude(flange_width) difference() {
ring(bore_radius, flange_radius);
if (flange_cutout_segments > -1) flange_cutout();
if (flange_cutout_crossing_window) flange_cutout_window();
}
flange_chamfer();
}
if (flange_filament_clip) flange_filament_clip();
if (flange_filament_hole_bambulab) flange_filament_hole();
if (flange_filament_hole_inclined) flange_filament_hole(45);
if (label_level_meter) linear_extrude(label_depth) flange_level();
if (bambulab_rfid_pocket) bambulab_rfid_pocket_hole();
if (label_area_bambulab_color) linear_extrude(0.2) label_area_bambulab();
if (barrel_type == "modular") modular_connector(true);
}
if (bambulab_rfid_pocket) linear_extrude(1) bambulab_rfid_shape();
}
module flange_chamfer() {
p = [[bore_radius + flange_chamfer_size, 0], [flange_radius - flange_chamfer_size, 0], [flange_radius, flange_chamfer_size], [flange_radius, flange_width], [bore_radius, flange_width], [bore_radius, flange_chamfer_size]];
rotate_extrude() polygon(points = p, paths = [[0, 1, 2, 3, 4, 5]]);
}
/* Flange cutout */
module flange_cutout() {
offset(r = flange_cutout_fillet) offset(r = -flange_cutout_fillet) difference() {
if (barrel_type == "modular") {
ring(barrel_radius + flange_wall, flange_radius - flange_wall);
} else {
ring(barrel_radius, flange_radius - flange_wall);
}
flange_cutout_crossings(flange_cutout_crossing_width);
if (label_level_meter && flange_cutout_crossing_window) offset(r = 2) hull() flange_level(false);
if (label_area_bambulab) label_area_bambulab();
if (label_area_position) label_area_custom();
if (bambulab_rfid_pocket) offset(r = 1) bambulab_rfid_pocket();
}
}
module flange_cutout_window() {
offset(r = flange_cutout_fillet) offset(r = -flange_cutout_fillet) difference() {
flange_cutout_crossings(flange_cutout_crossing_window);
if (flange_cutout_crossing_window_bore) {
if (barrel_type == "quick") {
circle(connector_radius + ((barrel_wall > bore_wall) ? barrel_wall : bore_wall));
} else {
circle(bore_radius + bore_wall);
}
} else {
if (barrel_type == "modular") {
circle(barrel_radius + flange_wall);
} else {
circle(barrel_radius);
}
}
ring(flange_radius - flange_wall, flange_radius);
}
}
module flange_cutout_crossings(width) {
crossings_rotate(flange_cutout_segments) flange_cutout_crossing(width);
}
module flange_cutout_crossing(width) {
translate([0, -width / 2, 0]) square([flange_radius, width]);
}
/* Filament clip */
module flange_filament_clip() {
rotate_extrude() translate([flange_radius - 3, flange_width - 1.2]) filament_clip();
}
module filament_clip() {
r = 1.741 / 2;
p = [[-r, 0], [-0.808, 1.2], [0.808, 1.2], [r, 0]];
circle(r);
polygon(points = p, paths = [[0, 1, 2, 3]]);
}
/* Filament hole */
module flange_filament_hole(angle = 0) {
r = flange_radius - 3;
s = 30;
a = asin(s / (2 * r));
crossings_rotate(flange_filament_hole_count) {
rotate([-angle, 0, + a]) translate([r, 0, -2]) cylinder(h = flange_width * 2 + 4, r = 1.75);
rotate([+angle, 0, - a]) translate([r, 0, -2]) cylinder(h = flange_width * 2 + 4, r = 1.75);
}
}
/*********
* Barrel *
**********/
module barrel(top = false) {
translate([0, 0, flange_width]) difference() {
union() {
if (barrel_type == "modular") barrel_modular();
else if (barrel_type == "quick") barrel_quick(top);
else if (barrel_type == "solid") barrel_solid(width);
if(top && barrel_notch_bambulab) barrel_notch_bambulab();
}
if(top && barrel_fixing_hole) barrel_fixing_hole();
}
}
/* Modular barrel */
module barrel_modular() {
translate([0, 0, width + flange_width]) rotate([180, 0, 0]) barrel_modular_connector();
barrel_solid(width);
translate([0, 0, -flange_width]) barrel_modular_connector();
}
module barrel_modular_connector() {
intersection() {
barrel_solid(flange_width);
flange_chamfer();
modular_connector(false);
}
}
/* Quick connect barrel */
module barrel_quick(top) {
height_split = (width / 2) + 2.1;
if (top) {
// Bore wall
tube(connector_radius, connector_radius + bore_wall, height_split);
// Chamfer
rotate_extrude() translate([bore_radius, 0]) bore_chamfer(bore_wall + 3.2 + rounding_mesh_error);
// Connector
translate([0, 0, height_split]) {
crossings_rotate(3) quick_hold_top(connector_radius);
}
// Barrel wall
barrel_wall(barrel_height_top);
} else {
// Bore wall
tube(bore_radius, bore_radius + bore_wall, height_split);
// Connector
rotate([0, 0, -25]) translate([0, 0, height_split]) {
crossings_rotate(3) quick_hold_bottom(bore_radius + bore_wall);
}
// Barrel wall
barrel_wall(width * (barrel_wall_split_percent / 100));
}
}
module barrel_wall(height) {
if(flange_cutout_crossing_window_bore) {
linear_extrude(height) difference() {
barrel_wall_cutout();
offset(r = -barrel_wall) barrel_wall_cutout();
}
} else {
tube(barrel_radius - barrel_wall, barrel_radius, height);
}
}
module barrel_wall_cutout() {
difference() {
circle(barrel_radius);
flange_cutout_window();
}
}
module bore_chamfer(a) {
p = [[0, 0], [a, 0], [a, a]];
polygon(points = p, paths= [[0, 1, 2]]);
}
/* Solid barrel */
module barrel_solid(width) {
difference() {
tube(bore_radius, barrel_radius, width);
if(flange_cutout_crossing_window_bore) linear_extrude(width) flange_cutout_window();
}
}
/* Barrel notch for BambuLab filament */
module barrel_notch_bambulab() {
cutout_rotate(barrel_notch_bambulab) translate([barrel_radius - barrel_wall, 0, 0]) rotate([90, 0, 90]) linear_extrude(3 + barrel_wall) hull() {
translate([0, 3]) circle(1.5);
square([4, 0.0001], center = true);
}
}
/* Barrel hole to hold end of filament */
module barrel_fixing_hole() {
cutout_rotate(barrel_fixing_hole) translate([bore_radius - 0.5, 0, (barrel_type == "quick" ? barrel_height_top : width) - 1.5]) rotate([0, 90, 0]) cylinder(barrel_radius - bore_radius + 1, 1, 1);
}
/************
* Connector *
*************/
/* Modular connector */
module modular_connector(flange = false) {
connector_height = flange_width * 2 / 3;
connector_depth = flange_width / 2;
connector_inner_radius = barrel_radius - connector_depth;
parts = flange_cutout_segments < 2 ? 2 : flange_cutout_segments;
remove_edge = connector_depth * 0.2;
translate([0, 0, flange_width / 3]) rotate([0, 0, -90/parts]) {
if(flange) {
modular_connector_notch(connector_height, connector_depth, parts);
crossings_rotate(parts) rotate_extrude(angle = 180 / parts) square([barrel_radius, connector_height]);
// Remove edge of the notch
cylinder(connector_height, connector_inner_radius + remove_edge, connector_inner_radius + remove_edge);
} else {
difference() {
modular_connector_notch(connector_height, connector_depth, parts);
crossings_rotate(parts) rotate_extrude(angle = 180 / parts) translate([connector_inner_radius, 0, 0]) square([connector_depth, connector_height / 2]);
// Remove edge of the notch
tube(barrel_radius - remove_edge, barrel_radius, remove_edge);
}
}
}
}
module modular_connector_notch(connector_height, connector_depth, parts) {
connector_inner_radius = barrel_radius - connector_depth;
translate([0, 0, connector_height / 2]) cylinder(connector_height / 2, connector_inner_radius, barrel_radius);
cylinder(connector_height / 2, barrel_radius, connector_inner_radius);
crossings_rotate(parts) {
// Lug
lug_size = connector_depth / sqrt(2) * snap_ratio;
rotate([0, 0, -15]) translate([connector_inner_radius, 0, connector_height / 2]) rotate([0, 0, 45]) cube([lug_size, lug_size, connector_height], center = true);
// Stop
translate([connector_inner_radius, 0, connector_height / 2]) difference() {
rotate([0, 0, 45]) cube([connector_depth * 2 / sqrt(2), connector_depth * 2 / sqrt(2), connector_height], center = true);
translate([connector_depth / 2, connector_depth / 2, 0]) cube([connector_depth, connector_depth, connector_height], center = true);
}
}
}
/* Quick connector */
module quick_hold_bottom(inner_radius) {
size = 2 + 1 * snap_ratio;
a = ((size - 0.7) * sqrt(2) * 180) / (PI * inner_radius);
rotate_extrude(angle = 25) translate([inner_radius - rounding_mesh_error, 0]) quick_lug();
rotate([0, 0, 25 + a]) {
intersection() {
rotate_extrude() translate([inner_radius, 0]) quick_lug();
translate([inner_radius - 0.1, 0, -1.5]) rotate([0, 0, 45]) cube([size, size, 3], center = true);
}
}
}
module quick_hold_top(inner_radius) {
size = 2 + 1 * snap_ratio;
a = ((size - 0.7) * sqrt(2) * 180) / (PI * inner_radius);
rotate_extrude(angle = 25) translate([inner_radius + rounding_mesh_error, 0]) mirror([1, 0]) quick_lug();
rotate([0, 0, a / -2]) {
translate([0, 0, -3]) intersection() {
rotate_extrude() translate([inner_radius, 0]) mirror([1, 0]) quick_lug(3);
translate([inner_radius - 0.1, 0, 0]) rotate([0, 0, 45]) cube([size, size, 6], center = true);
}
}
}
module quick_lug(height = 0) {
p = [[0, -2.932], [3, -1.2], [3, height], [0, height]];
polygon(points = p, paths= [[0, 1, 2, 3]]);
}
/********
* Label *
*********/
/* Level meter */
module flange_level(mark = true) {
levels = [0.2, 0.4, 0.6, 0.8, 1];
for (i = [ 0 : len(levels) - 1 ]) {
r = level_radius(levels[i]);
if (mark) intersection() {
ring(r-.3, r+.3);
difference() {
flange_cutout_crossing(flange_cutout_crossing_width);
if(flange_cutout_crossing_window) flange_cutout_crossing(flange_cutout_crossing_window);
}
}
if (flange_cutout_crossing_window) {
translate([r - 1 - label_level_font_size, flange_cutout_crossing_width / 2 + 1]) rotate([0, 180, -90]) text(str(levels[i] * label_level_full_factor), size = label_level_font_size, halign = "left");
} else {
translate([r - 1 - label_level_font_size, 0]) rotate([0, 180, -90]) text(str(levels[i] * label_level_full_factor), size = label_level_font_size, halign = "center");
}
}
}
function level_radius(factor) = sqrt(factor * ((label_level_full_radius ? label_level_full_radius : flange_radius)^2 - barrel_radius^2) + barrel_radius^2);
/* Label area */
module label_area_bambulab() {
cutout_rotate(label_area_bambulab) hull() {
translate([flange_radius - 15, 0]) circle(10);
translate([flange_radius - 41, 0]) circle(10);
}
}
module label_area_custom() {
cutout_rotate(label_area_position) translate([bore_radius + (flange_radius - bore_radius - label_area_size[1]) / 2, -label_area_size[0] / 2]) square([label_area_size[1], label_area_size[0]]);
}
/********
* Other *
*********/
module bambulab_rfid_shape() {
translate([7, 0]) circle(10);
square([14, 20], center = true);
}
module bambulab_rfid_pocket(notch = false) {
cutout_rotate(bambulab_rfid_pocket) translate([47.5, 0]) {
bambulab_rfid_shape();
if(notch) translate([0, 7]) square(5);
}
}
module bambulab_rfid_pocket_hole() {
translate([0, 0, flange_width - 1.2]) linear_extrude(1.2) bambulab_rfid_pocket(true);
}