forked from choller/autokey3d
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkey.scad
125 lines (109 loc) · 2.92 KB
/
key.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
include <settings.scad>;
$fn = 100;
// For debugging purposes only, you can override particular
// profile or system definitions directly in the program, e.g.:
//
//cutangle = 100;
//bumpkey = 1;
//platspace = 0.0;
//bump_addcutdepth = 0.0;
//bump_addaspace = 0.0;
// Do not change anything below unless you know what you are doing
addaspace = bumpkey ? bump_addaspace : 0.0;
addplatspace = bumpkey ? bump_addplatspace : 0.0;
addcutdepth = bumpkey ? bump_addcutdepth : 0.0;
keycomb = bumpkey ? [0,0,0,0,0,0] : combination;
nohandle = false;
lasercut = false;
mark = false;
module branding(h) {
linear_extrude(height=h,center=true)
import("branding/branding.dxf");
}
module rawprofile(h) {
if (h > 0) {
linear_extrude(height=h,center=true)
import("profile.dxf");
} else {
import("profile.dxf");
}
}
module profile() {
/*
We first create the difference between our extruded profile
and a bounding box (called the "negative"), and then we use
that negative to cut our blank out of another bounding box.
It's necessary to take this detour because we cannot
thin using minkowski, but we can thicken the negative
which means thinning the key blank of course.
*/
if (tol > 0) {
if (use2DThinning) {
linear_extrude(height=csz+1,center=true)
difference() {
translate([-csx/4,-csy/4])
square([csx,csy]);
minkowski() {
difference() {
translate([-csx/4,-csy/4])
square([csx,csy]);
resize([0,ph,0],auto=[true,true,false],center=true)
rawprofile(0);
}
circle(r=tol);
}
}
} else {
difference() {
translate([-csx/4,-csy/4,-csz/4])
cube([csx,csy,1]);
minkowski() {
difference() {
translate([-csx/4,-csy/4,-csz/4])
cube([csx,csy,csz]);
resize([0,ph,0],auto=[true,true,false],center=true)
rawprofile(csz+1);
}
cylinder(r=tol, h=0.1);
}
}
}
} else {
resize([0,ph,0],auto=[true,true,false],center=true)
rawprofile(csz+1);
}
}
rotate([270,180,0])
union() {
difference() {
/* Create the uncut blank and make sure it is zero-aligned with y-axis */
translate([-tol,0,0])
resize([0,0,kl]) profile();
/* Cut the key tip */
keytipcuts();
if (!blank) {
keycombcuts(lasercut);
}
}
khcyo = -(khcy-ph)/2;
khyo = khcyo - (khy-khcy)/2;
// Key handle connector
translate([khcxoff,khcyo,kl/2]) //Add +0.1 to z here to check that handle is exact
cube([khcx,khcy,khcz]);
if (mark) {
translate([khcxoff,khcyo,kl/2])
translate([khcx,khcy/2,khcz/2])
sphere(r=khcx/4);
}
if (!nohandle) {
// Key handle
translate([khcxoff,khyo,kl/2+khcz]) //Add +0.1 to z here to check that handle is exact
cube([khx,khy,khz]);
// Branding
khzb = thin_handle ? khz*0.1 : khz*0.5 - 1;
translate([khcxoff+khx+0.1,khyo + 0.1*khy,kl/2+khcz+khzb])
resize([0,0.8*khy,0],auto=[false,true,true],center=true)
rotate([90,0,90])
branding(bh);
}
}