-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhook.js
96 lines (85 loc) · 2.65 KB
/
hook.js
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
// Copy code here:
// https://studio.replicad.xyz/workbench
// and you'll be able to alter and download the model
const nothing = 0.00001;
/** @typedef { typeof import("replicad") } replicadLib */
/** @type {function(replicadLib, typeof defaultParams): any} */
const main = ({ draw, makeBaseBox, makeCylinder }, {}) => {
const thickness = 3.5;
const d = {
base: {
x: 10,
y: 14,
z: thickness,
},
};
(d.screwHolder = {
r: d.base.x / 2,
h: 6.5,
hole: 2,
}),
(d.hook = {
x: d.base.x,
y: thickness,
z: 8.5,
hole: 1.5,
r: 5,
});
const triangleSide = d.base.y * 0.3;
const triangle = draw([0, 0])
.lineTo([0, triangleSide])
.lineTo([triangleSide, 0])
.close()
.sketchOnPlane('YZ')
.extrude(d.base.x)
.translateX(d.base.x / -2)
.translateY(d.base.y / -2 + thickness - nothing)
.translateZ(thickness - nothing);
const base = makeBaseBox(d.base.x, d.base.y, d.base.z);
const screwHole = makeCylinder(d.screwHolder.hole, d.screwHolder.h * 2)
.translateZ(d.screwHolder.h * -0.1)
.translateY(d.base.y / 2);
const screwHolder = makeCylinder(d.screwHolder.r, d.screwHolder.h).translateY(
d.base.y / 2
);
const hookBase = makeBaseBox(d.hook.x, d.hook.y, d.hook.z).translateY(
(d.base.y - d.hook.y) / -2
);
const hookHole = makeCylinder(d.hook.hole, d.hook.x * 2).translateZ(
d.hook.x * -0.1
);
let hookOuter = makeCylinder(d.hook.r, d.hook.x)
.cut(hookHole)
.translateZ(d.hook.x / -2)
.rotate(90, [0, 0, 0], [0, 1, 0]);
const hookCut1 = makeBaseBox(20, 20, d.hook.r + 1)
.translateZ(-(d.hook.r + 1))
.translateY(-10);
const hookCut2 = makeBaseBox(20, 20, d.hook.r + 1)
.translateZ(-d.hook.r)
.translateY(10);
hookOuter = hookOuter
.cut(hookCut1)
.cut(hookCut2)
.translateY(-(d.base.y / 2 - d.hook.r))
.translateZ(d.hook.z - nothing);
const hook = hookBase.fuse(hookOuter);
// Nicer and flimsier cut
// const outerCut1 = makeBaseBox(20,d.base.y,20).translateZ(-3).translateY(-d.base.y + d.hook.r)
// const outerCut2 = makeCylinder(d.screwHolder.r, 25).translateZ(-2).translateY((d.base.y) / -2 + d.hook.r)
// const outerCut = outerCut1.cut(outerCut2);
const outerCut1 = makeBaseBox(20, d.base.y, 20)
.translateZ(-3)
.translateY(-d.base.y + d.hook.r);
const outerCut2 = makeCylinder(d.screwHolder.r * 1.2, 25)
.translateZ(-2)
.translateY(d.base.y / -2 + d.hook.r);
const outerCut = outerCut1.cut(outerCut2);
const part = base.fuse(screwHolder).cut(screwHole).fuse(hook).fuse(triangle);
return [
{
shape: part.cut(outerCut),
color: '#5c60d6',
},
];
};