-
Notifications
You must be signed in to change notification settings - Fork 5
/
template.scad
70 lines (64 loc) · 2.7 KB
/
template.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
use <arrange.scad>
use <placeholders.scad>
use <supports.scad>
use <util.scad>
include <definitions.scad>
include <BOSL2/std.scad>
function orient_cross_support(vertices) = (
let(base_points = [for(v=vertices) if (v.z < .0001) v])
let(vec = last(base_points) - first(base_points))
let(angle = angleTo(vec, X))
let(matrix = (
affine3d_identity()
* rot([-90, 0, 0])
* rot([0, 0, -angle])
* move(-first(base_points))
))
[for (v=apply(matrix, vertices)) [v.x, v.y]]
);
function arrange_key_plates(cluster, spacing=2, reverse_columns=false, align_items="end") = (
assert(cluster == "finger" || cluster == "thumb")
let(columns = cluster == "finger" ? finger_columns : thumb_columns)
arrange([
for (colIndex=[0:len(columns)-1])
let(column_u = get_column_width(cluster, colIndex))
arrange([
for (rowIndex=[0:len(columns[colIndex])-1])
let (overrides = get_overrides(cluster, colIndex, rowIndex))
let (alignment = get_alignment_override(cluster, colIndex, rowIndex))
let (u = overrides[0])
let (h = overrides[1])
plate(column_u, h, align=alignment)
], direction="column-reverse", spacing=spacing)
], direction=reverse_columns ? "row-reverse" : "row", spacing=spacing, align_items=align_items)
);
function arrange_column_supports(cluster, spacing=0, align_items="center") = (
assert(cluster == "finger" || cluster == "thumb")
let(columns = cluster == "finger" ? finger_columns : thumb_columns)
arrange(flatten([
for(columnIndex=[0:len(columns)-1], i=[0,1])
[[rot([0, 0, 90], p=column_support(cluster, columnIndex))]]
]), spacing=spacing, align_items=align_items)
);
finger_cluster_front = rot([0, 0, 90], p=orient_cross_support(finger_cluster_cross_support_front()));
finger_cluster_back = rot([0, 0, 90], p=orient_cross_support(finger_cluster_cross_support_back()));
arrange([
arrange([
arrange_key_plates("finger"),
arrange_column_supports("finger", spacing=0, align_items="end"),
[finger_cluster_front],
[finger_cluster_back]
], spacing=2, align_items="start"),
arrange([
arrange_key_plates("thumb", reverse_columns=true, align_items="start"),
arrange_column_supports("thumb", align_items="start", spacing=-2),
arrange([
[orient_cross_support(thumb_front_cross_support([2]))],
[orient_cross_support(thumb_front_cross_support([1]))],
[orient_cross_support(thumb_front_cross_support([0]))],
[orient_cross_support(thumb_back_cross_support([2]))],
[orient_cross_support(thumb_back_cross_support([1]))],
[orient_cross_support(thumb_back_cross_support([0]))],
], spacing=2, align_items="start")
], spacing=2, align_items="start"),
], direction="column", align_items="start", spacing=-10);