├── src
├── .gitignore
├── shapes.py
├── mat.py
├── lib.py
└── main.py
├── .gitignore
├── .python-version
├── things
├── left.stl
├── right.stl
├── left_bottom_plate.stl
└── right_bottom_plate.stl
├── Makefile
├── requirements.txt
├── README.md
└── LICENSE
/src/.gitignore:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | __pycache__
2 |
--------------------------------------------------------------------------------
/.python-version:
--------------------------------------------------------------------------------
1 | 3.8.0
2 |
--------------------------------------------------------------------------------
/things/left.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/omurovec/dactyl-high-profile/HEAD/things/left.stl
--------------------------------------------------------------------------------
/things/right.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/omurovec/dactyl-high-profile/HEAD/things/right.stl
--------------------------------------------------------------------------------
/things/left_bottom_plate.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/omurovec/dactyl-high-profile/HEAD/things/left_bottom_plate.stl
--------------------------------------------------------------------------------
/things/right_bottom_plate.stl:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/omurovec/dactyl-high-profile/HEAD/things/right_bottom_plate.stl
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | .PHONY: watch
2 | watch: run
3 | watchmedo shell-command --patterns="*.py" --recursive --command='python src/main.py' src
4 |
5 | .PHONY: run
6 | run:
7 | mkdir -p things
8 | python src/main.py
9 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
1 | argh==0.26.2
2 | euclid3==0.1
3 | pathtools==0.1.2
4 | prettytable==0.7.2
5 | pypng==0.0.19
6 | PyYAML==5.3.1
7 | regex==2019.12.20
8 | six==1.14.0
9 | solidpython==0.4.8
10 | watchdog==0.10.2
11 |
--------------------------------------------------------------------------------
/src/shapes.py:
--------------------------------------------------------------------------------
1 | from lib import *
2 | from math import radians, sin, cos
3 |
4 | SWITCH_RISER_RADIUS = 0.9
5 | SWITCH_RISER_HEIGHT = 4.5
6 |
7 |
8 | def switch_riser_raw_dot_fn():
9 | return sphere(SWITCH_RISER_RADIUS)
10 |
11 |
12 | switch_riser_raw_dot = switch_riser_raw_dot_fn()
13 |
14 | top_dot = translate(0, 0, SWITCH_RISER_HEIGHT)(switch_riser_raw_dot)
15 |
16 |
17 | def switch_riser_post_fn():
18 | post = translate(0, 0, SWITCH_RISER_HEIGHT / 2)(
19 | cylinder(SWITCH_RISER_RADIUS, SWITCH_RISER_HEIGHT, center=True)
20 | )
21 |
22 | return union(post, top_dot)
23 |
24 |
25 | switch_riser_post = switch_riser_post_fn()
26 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Yet another Dactyl Manuform Spinoff (Low Profile)
2 |
3 | 
4 |
5 | This repo is a _fork of a_ re-implementation of the [Dactyl Manuform Tight](https://github.com/okke-formsma/dactyl-manuform-tight) in python, with a few of my own changes.
6 |
7 | There are some hacks in here to get the border walls and thumb cluster to line up properly at the current tenting angle and key layout.
8 | I didn't build this script with the goal of making it easy to share and extend... so if you're using this repo as a starting point for your own dactyl build, good luck, and beware of some shard edges.
9 |
10 | ## Generating OpenSCAD Models
11 |
12 | This script is tested against Python 3.8.0
13 |
14 | Intall dependencies with `pip install -r requirements.txt`
15 |
16 | Run a one-off scad model build with `make run`
17 |
18 | Watch and rebuild scad models with `make watch` (useful for development)
19 |
--------------------------------------------------------------------------------
/src/mat.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | from math import radians, sin, cos
3 |
4 | def point3(x, y, z):
5 | return np.transpose(np.array([x,y,z,1]))
6 |
7 | def vec3(x, y, z):
8 | return np.transpose(np.array([[x,y,z,0]]))
9 |
10 | def to_point(pv):
11 | return pv.tolist()[:-1]
12 |
13 | def translate(x, y, z):
14 | return np.array([
15 | [1, 0, 0, x],
16 | [0, 1, 0, y],
17 | [0, 0, 1, z],
18 | [0, 0, 0, 1],
19 | ])
20 |
21 | def scale(x, y, z):
22 | return np.array([
23 | [x, 0, 0, 0],
24 | [0, y, 0, 0],
25 | [0, 0, z, 0],
26 | [0, 0, 0, 1],
27 | ])
28 |
29 | def identity():
30 | return scale(1,1,1)
31 |
32 | def rotate_x(deg):
33 | rad = radians(deg)
34 | return np.array([
35 | [1, 0, 0, 0],
36 | [0, cos(rad), -sin(rad), 0],
37 | [0, sin(rad), cos(rad), 0],
38 | [0, 0, 0, 1],
39 | ])
40 |
41 |
42 | def rotate_y(deg):
43 | rad = radians(deg)
44 | return np.array([
45 | [cos(rad), 0, sin(rad), 0],
46 | [0, 1, 0, 0],
47 | [-sin(rad), 0, cos(rad), 0],
48 | [0, 0, 0, 1],
49 | ])
50 |
51 | def rotate_z(deg):
52 | rad = radians(deg)
53 | return np.array([
54 | [cos(rad), -sin(rad), 0, 0],
55 | [sin(rad), cos(rad), 0, 0],
56 | [0, 0, 1, 0],
57 | [0, 0, 0, 1],
58 | ])
59 |
60 | def compose(*mats):
61 | result = identity()
62 | for m in mats:
63 | result = m @ result
64 | return result
65 |
--------------------------------------------------------------------------------
/src/lib.py:
--------------------------------------------------------------------------------
1 | import solid
2 |
3 | default_segments = 18
4 |
5 | class NativeSCAD():
6 | def __init__(self, solid_fn, *args, mat_apply = None, **kwargs):
7 | def build_solid_fn():
8 | return solid_fn(*args, **kwargs)
9 | self.solid = build_solid_fn
10 |
11 | def __call__(self, other):
12 | assert isinstance(other, NativeSCAD)
13 | return Composer([self, other])
14 |
15 | def _apply_to(self, other):
16 | return self.compile()(other)
17 |
18 | def matrix_apply(self, point):
19 | assert self.mat_apply is not None
20 |
21 | return
22 |
23 | def compile(self):
24 | return self.solid()
25 |
26 | class Composer(NativeSCAD):
27 | def __init__(self, children):
28 | assert len(children) > 0
29 | self.children = children
30 |
31 | def _apply_to(self, other):
32 | result = other
33 | for c in reversed(self.children):
34 | result = c._apply_to(result)
35 | return result
36 |
37 | def compile(self):
38 | result = self.children[-1].compile()
39 | for c in reversed(self.children[:-1]):
40 | result = c._apply_to(result)
41 | return result
42 |
43 | class Merger(NativeSCAD):
44 | def __init__(self, solid_fn, children):
45 | self.solid = solid_fn
46 | self.children = children
47 |
48 | def __call__(self, other):
49 | raise 'Cannot call merger'
50 |
51 | def _apply_to(self, other):
52 | raise 'Cannot apply merger'
53 |
54 | def compile(self):
55 | return self.solid()(*[c.compile() for c in self.children])
56 |
57 | def translate(x, y, z):
58 | return NativeSCAD(solid.translate, [x, y, z])
59 |
60 | def identity():
61 | return translate(0, 0, 0)
62 |
63 | def scale(x, y, z):
64 | return NativeSCAD(solid.scale, [x, y, z])
65 |
66 | def rotate(*, a, v):
67 | return NativeSCAD(solid.rotate, a=a, v=v)
68 |
69 | def rotate_x(a):
70 | return rotate(a=a, v=[1, 0, 0])
71 |
72 | def rotate_y(a):
73 | return rotate(a=a, v=[0, 1, 0])
74 |
75 | def rotate_z(a):
76 | return rotate(a=a, v=[0, 0, 1])
77 |
78 | def mirror(x, y, z):
79 | return NativeSCAD(solid.mirror, [x, y, z])
80 |
81 | def flip_lr():
82 | return mirror(-1, 0, 0)
83 |
84 | def project(*args, **kwargs):
85 | return NativeSCAD(solid.projection, *args, **kwargs)
86 |
87 | def offset(*args):
88 | return NativeSCAD(solid.offset, *args)
89 |
90 | def extrude_linear(height):
91 | return NativeSCAD(solid.linear_extrude, height)
92 |
93 | def colour(r, g, b, z):
94 | return NativeSCAD(solid.color, [r/ 255.0, g/ 255.0, b/ 255.0, z])
95 |
96 | # Functional
97 | def compose(*atoms):
98 | assert len(atoms) > 0
99 | return Composer(list(reversed(atoms)))
100 |
101 | # Merges
102 | def union(*children):
103 | return Merger(solid.union, children)
104 |
105 | def hull(*children):
106 | return Merger(solid.hull, children)
107 |
108 | def difference(*children):
109 | return Merger(solid.difference, children)
110 |
111 | def intersection(*children):
112 | return Merger(solid.intersection, children)
113 |
114 | # def projection(child):
115 | # return NativeSCAD(solid.projection, child)
116 |
117 | #def linear_extrude
118 |
119 | # Shapes
120 | def cube(x, y, z, **kwargs):
121 | return NativeSCAD(solid.cube, [x, y ,z], **kwargs)
122 |
123 | def cylinder(r, h, segments = default_segments, **kwargs):
124 | return NativeSCAD(solid.cylinder, r=r, h=h, segments=segments, **kwargs)
125 |
126 | def cylinderr1r2(r1, r2, h, segments = default_segments, **kwargs):
127 | return NativeSCAD(solid.cylinder, r1=r1, r2=r2, h=h, segments=segments, **kwargs)
128 |
129 | def sphere(r, segments = default_segments, **kwargs):
130 | return NativeSCAD(solid.sphere, r=r, segments=segments, **kwargs)
131 |
132 | def square(x, y, **kwargs):
133 | return NativeSCAD(solid.square, [x, y], **kwargs)
134 |
135 | def render_to_file(obj, filename):
136 | solid.scad_render_to_file(obj.compile(), filename)
137 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU AFFERO GENERAL PUBLIC LICENSE
2 | Version 3, 19 November 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU Affero General Public License is a free, copyleft license for
11 | software and other kinds of works, specifically designed to ensure
12 | cooperation with the community in the case of network server software.
13 |
14 | The licenses for most software and other practical works are designed
15 | to take away your freedom to share and change the works. By contrast,
16 | our General Public Licenses are intended to guarantee your freedom to
17 | share and change all versions of a program--to make sure it remains free
18 | software for all its users.
19 |
20 | When we speak of free software, we are referring to freedom, not
21 | price. Our General Public Licenses are designed to make sure that you
22 | have the freedom to distribute copies of free software (and charge for
23 | them if you wish), that you receive source code or can get it if you
24 | want it, that you can change the software or use pieces of it in new
25 | free programs, and that you know you can do these things.
26 |
27 | Developers that use our General Public Licenses protect your rights
28 | with two steps: (1) assert copyright on the software, and (2) offer
29 | you this License which gives you legal permission to copy, distribute
30 | and/or modify the software.
31 |
32 | A secondary benefit of defending all users' freedom is that
33 | improvements made in alternate versions of the program, if they
34 | receive widespread use, become available for other developers to
35 | incorporate. Many developers of free software are heartened and
36 | encouraged by the resulting cooperation. However, in the case of
37 | software used on network servers, this result may fail to come about.
38 | The GNU General Public License permits making a modified version and
39 | letting the public access it on a server without ever releasing its
40 | source code to the public.
41 |
42 | The GNU Affero General Public License is designed specifically to
43 | ensure that, in such cases, the modified source code becomes available
44 | to the community. It requires the operator of a network server to
45 | provide the source code of the modified version running there to the
46 | users of that server. Therefore, public use of a modified version, on
47 | a publicly accessible server, gives the public access to the source
48 | code of the modified version.
49 |
50 | An older license, called the Affero General Public License and
51 | published by Affero, was designed to accomplish similar goals. This is
52 | a different license, not a version of the Affero GPL, but Affero has
53 | released a new version of the Affero GPL which permits relicensing under
54 | this license.
55 |
56 | The precise terms and conditions for copying, distribution and
57 | modification follow.
58 |
59 | TERMS AND CONDITIONS
60 |
61 | 0. Definitions.
62 |
63 | "This License" refers to version 3 of the GNU Affero General Public License.
64 |
65 | "Copyright" also means copyright-like laws that apply to other kinds of
66 | works, such as semiconductor masks.
67 |
68 | "The Program" refers to any copyrightable work licensed under this
69 | License. Each licensee is addressed as "you". "Licensees" and
70 | "recipients" may be individuals or organizations.
71 |
72 | To "modify" a work means to copy from or adapt all or part of the work
73 | in a fashion requiring copyright permission, other than the making of an
74 | exact copy. The resulting work is called a "modified version" of the
75 | earlier work or a work "based on" the earlier work.
76 |
77 | A "covered work" means either the unmodified Program or a work based
78 | on the Program.
79 |
80 | To "propagate" a work means to do anything with it that, without
81 | permission, would make you directly or secondarily liable for
82 | infringement under applicable copyright law, except executing it on a
83 | computer or modifying a private copy. Propagation includes copying,
84 | distribution (with or without modification), making available to the
85 | public, and in some countries other activities as well.
86 |
87 | To "convey" a work means any kind of propagation that enables other
88 | parties to make or receive copies. Mere interaction with a user through
89 | a computer network, with no transfer of a copy, is not conveying.
90 |
91 | An interactive user interface displays "Appropriate Legal Notices"
92 | to the extent that it includes a convenient and prominently visible
93 | feature that (1) displays an appropriate copyright notice, and (2)
94 | tells the user that there is no warranty for the work (except to the
95 | extent that warranties are provided), that licensees may convey the
96 | work under this License, and how to view a copy of this License. If
97 | the interface presents a list of user commands or options, such as a
98 | menu, a prominent item in the list meets this criterion.
99 |
100 | 1. Source Code.
101 |
102 | The "source code" for a work means the preferred form of the work
103 | for making modifications to it. "Object code" means any non-source
104 | form of a work.
105 |
106 | A "Standard Interface" means an interface that either is an official
107 | standard defined by a recognized standards body, or, in the case of
108 | interfaces specified for a particular programming language, one that
109 | is widely used among developers working in that language.
110 |
111 | The "System Libraries" of an executable work include anything, other
112 | than the work as a whole, that (a) is included in the normal form of
113 | packaging a Major Component, but which is not part of that Major
114 | Component, and (b) serves only to enable use of the work with that
115 | Major Component, or to implement a Standard Interface for which an
116 | implementation is available to the public in source code form. A
117 | "Major Component", in this context, means a major essential component
118 | (kernel, window system, and so on) of the specific operating system
119 | (if any) on which the executable work runs, or a compiler used to
120 | produce the work, or an object code interpreter used to run it.
121 |
122 | The "Corresponding Source" for a work in object code form means all
123 | the source code needed to generate, install, and (for an executable
124 | work) run the object code and to modify the work, including scripts to
125 | control those activities. However, it does not include the work's
126 | System Libraries, or general-purpose tools or generally available free
127 | programs which are used unmodified in performing those activities but
128 | which are not part of the work. For example, Corresponding Source
129 | includes interface definition files associated with source files for
130 | the work, and the source code for shared libraries and dynamically
131 | linked subprograms that the work is specifically designed to require,
132 | such as by intimate data communication or control flow between those
133 | subprograms and other parts of the work.
134 |
135 | The Corresponding Source need not include anything that users
136 | can regenerate automatically from other parts of the Corresponding
137 | Source.
138 |
139 | The Corresponding Source for a work in source code form is that
140 | same work.
141 |
142 | 2. Basic Permissions.
143 |
144 | All rights granted under this License are granted for the term of
145 | copyright on the Program, and are irrevocable provided the stated
146 | conditions are met. This License explicitly affirms your unlimited
147 | permission to run the unmodified Program. The output from running a
148 | covered work is covered by this License only if the output, given its
149 | content, constitutes a covered work. This License acknowledges your
150 | rights of fair use or other equivalent, as provided by copyright law.
151 |
152 | You may make, run and propagate covered works that you do not
153 | convey, without conditions so long as your license otherwise remains
154 | in force. You may convey covered works to others for the sole purpose
155 | of having them make modifications exclusively for you, or provide you
156 | with facilities for running those works, provided that you comply with
157 | the terms of this License in conveying all material for which you do
158 | not control copyright. Those thus making or running the covered works
159 | for you must do so exclusively on your behalf, under your direction
160 | and control, on terms that prohibit them from making any copies of
161 | your copyrighted material outside their relationship with you.
162 |
163 | Conveying under any other circumstances is permitted solely under
164 | the conditions stated below. Sublicensing is not allowed; section 10
165 | makes it unnecessary.
166 |
167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
168 |
169 | No covered work shall be deemed part of an effective technological
170 | measure under any applicable law fulfilling obligations under article
171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
172 | similar laws prohibiting or restricting circumvention of such
173 | measures.
174 |
175 | When you convey a covered work, you waive any legal power to forbid
176 | circumvention of technological measures to the extent such circumvention
177 | is effected by exercising rights under this License with respect to
178 | the covered work, and you disclaim any intention to limit operation or
179 | modification of the work as a means of enforcing, against the work's
180 | users, your or third parties' legal rights to forbid circumvention of
181 | technological measures.
182 |
183 | 4. Conveying Verbatim Copies.
184 |
185 | You may convey verbatim copies of the Program's source code as you
186 | receive it, in any medium, provided that you conspicuously and
187 | appropriately publish on each copy an appropriate copyright notice;
188 | keep intact all notices stating that this License and any
189 | non-permissive terms added in accord with section 7 apply to the code;
190 | keep intact all notices of the absence of any warranty; and give all
191 | recipients a copy of this License along with the Program.
192 |
193 | You may charge any price or no price for each copy that you convey,
194 | and you may offer support or warranty protection for a fee.
195 |
196 | 5. Conveying Modified Source Versions.
197 |
198 | You may convey a work based on the Program, or the modifications to
199 | produce it from the Program, in the form of source code under the
200 | terms of section 4, provided that you also meet all of these conditions:
201 |
202 | a) The work must carry prominent notices stating that you modified
203 | it, and giving a relevant date.
204 |
205 | b) The work must carry prominent notices stating that it is
206 | released under this License and any conditions added under section
207 | 7. This requirement modifies the requirement in section 4 to
208 | "keep intact all notices".
209 |
210 | c) You must license the entire work, as a whole, under this
211 | License to anyone who comes into possession of a copy. This
212 | License will therefore apply, along with any applicable section 7
213 | additional terms, to the whole of the work, and all its parts,
214 | regardless of how they are packaged. This License gives no
215 | permission to license the work in any other way, but it does not
216 | invalidate such permission if you have separately received it.
217 |
218 | d) If the work has interactive user interfaces, each must display
219 | Appropriate Legal Notices; however, if the Program has interactive
220 | interfaces that do not display Appropriate Legal Notices, your
221 | work need not make them do so.
222 |
223 | A compilation of a covered work with other separate and independent
224 | works, which are not by their nature extensions of the covered work,
225 | and which are not combined with it such as to form a larger program,
226 | in or on a volume of a storage or distribution medium, is called an
227 | "aggregate" if the compilation and its resulting copyright are not
228 | used to limit the access or legal rights of the compilation's users
229 | beyond what the individual works permit. Inclusion of a covered work
230 | in an aggregate does not cause this License to apply to the other
231 | parts of the aggregate.
232 |
233 | 6. Conveying Non-Source Forms.
234 |
235 | You may convey a covered work in object code form under the terms
236 | of sections 4 and 5, provided that you also convey the
237 | machine-readable Corresponding Source under the terms of this License,
238 | in one of these ways:
239 |
240 | a) Convey the object code in, or embodied in, a physical product
241 | (including a physical distribution medium), accompanied by the
242 | Corresponding Source fixed on a durable physical medium
243 | customarily used for software interchange.
244 |
245 | b) Convey the object code in, or embodied in, a physical product
246 | (including a physical distribution medium), accompanied by a
247 | written offer, valid for at least three years and valid for as
248 | long as you offer spare parts or customer support for that product
249 | model, to give anyone who possesses the object code either (1) a
250 | copy of the Corresponding Source for all the software in the
251 | product that is covered by this License, on a durable physical
252 | medium customarily used for software interchange, for a price no
253 | more than your reasonable cost of physically performing this
254 | conveying of source, or (2) access to copy the
255 | Corresponding Source from a network server at no charge.
256 |
257 | c) Convey individual copies of the object code with a copy of the
258 | written offer to provide the Corresponding Source. This
259 | alternative is allowed only occasionally and noncommercially, and
260 | only if you received the object code with such an offer, in accord
261 | with subsection 6b.
262 |
263 | d) Convey the object code by offering access from a designated
264 | place (gratis or for a charge), and offer equivalent access to the
265 | Corresponding Source in the same way through the same place at no
266 | further charge. You need not require recipients to copy the
267 | Corresponding Source along with the object code. If the place to
268 | copy the object code is a network server, the Corresponding Source
269 | may be on a different server (operated by you or a third party)
270 | that supports equivalent copying facilities, provided you maintain
271 | clear directions next to the object code saying where to find the
272 | Corresponding Source. Regardless of what server hosts the
273 | Corresponding Source, you remain obligated to ensure that it is
274 | available for as long as needed to satisfy these requirements.
275 |
276 | e) Convey the object code using peer-to-peer transmission, provided
277 | you inform other peers where the object code and Corresponding
278 | Source of the work are being offered to the general public at no
279 | charge under subsection 6d.
280 |
281 | A separable portion of the object code, whose source code is excluded
282 | from the Corresponding Source as a System Library, need not be
283 | included in conveying the object code work.
284 |
285 | A "User Product" is either (1) a "consumer product", which means any
286 | tangible personal property which is normally used for personal, family,
287 | or household purposes, or (2) anything designed or sold for incorporation
288 | into a dwelling. In determining whether a product is a consumer product,
289 | doubtful cases shall be resolved in favor of coverage. For a particular
290 | product received by a particular user, "normally used" refers to a
291 | typical or common use of that class of product, regardless of the status
292 | of the particular user or of the way in which the particular user
293 | actually uses, or expects or is expected to use, the product. A product
294 | is a consumer product regardless of whether the product has substantial
295 | commercial, industrial or non-consumer uses, unless such uses represent
296 | the only significant mode of use of the product.
297 |
298 | "Installation Information" for a User Product means any methods,
299 | procedures, authorization keys, or other information required to install
300 | and execute modified versions of a covered work in that User Product from
301 | a modified version of its Corresponding Source. The information must
302 | suffice to ensure that the continued functioning of the modified object
303 | code is in no case prevented or interfered with solely because
304 | modification has been made.
305 |
306 | If you convey an object code work under this section in, or with, or
307 | specifically for use in, a User Product, and the conveying occurs as
308 | part of a transaction in which the right of possession and use of the
309 | User Product is transferred to the recipient in perpetuity or for a
310 | fixed term (regardless of how the transaction is characterized), the
311 | Corresponding Source conveyed under this section must be accompanied
312 | by the Installation Information. But this requirement does not apply
313 | if neither you nor any third party retains the ability to install
314 | modified object code on the User Product (for example, the work has
315 | been installed in ROM).
316 |
317 | The requirement to provide Installation Information does not include a
318 | requirement to continue to provide support service, warranty, or updates
319 | for a work that has been modified or installed by the recipient, or for
320 | the User Product in which it has been modified or installed. Access to a
321 | network may be denied when the modification itself materially and
322 | adversely affects the operation of the network or violates the rules and
323 | protocols for communication across the network.
324 |
325 | Corresponding Source conveyed, and Installation Information provided,
326 | in accord with this section must be in a format that is publicly
327 | documented (and with an implementation available to the public in
328 | source code form), and must require no special password or key for
329 | unpacking, reading or copying.
330 |
331 | 7. Additional Terms.
332 |
333 | "Additional permissions" are terms that supplement the terms of this
334 | License by making exceptions from one or more of its conditions.
335 | Additional permissions that are applicable to the entire Program shall
336 | be treated as though they were included in this License, to the extent
337 | that they are valid under applicable law. If additional permissions
338 | apply only to part of the Program, that part may be used separately
339 | under those permissions, but the entire Program remains governed by
340 | this License without regard to the additional permissions.
341 |
342 | When you convey a copy of a covered work, you may at your option
343 | remove any additional permissions from that copy, or from any part of
344 | it. (Additional permissions may be written to require their own
345 | removal in certain cases when you modify the work.) You may place
346 | additional permissions on material, added by you to a covered work,
347 | for which you have or can give appropriate copyright permission.
348 |
349 | Notwithstanding any other provision of this License, for material you
350 | add to a covered work, you may (if authorized by the copyright holders of
351 | that material) supplement the terms of this License with terms:
352 |
353 | a) Disclaiming warranty or limiting liability differently from the
354 | terms of sections 15 and 16 of this License; or
355 |
356 | b) Requiring preservation of specified reasonable legal notices or
357 | author attributions in that material or in the Appropriate Legal
358 | Notices displayed by works containing it; or
359 |
360 | c) Prohibiting misrepresentation of the origin of that material, or
361 | requiring that modified versions of such material be marked in
362 | reasonable ways as different from the original version; or
363 |
364 | d) Limiting the use for publicity purposes of names of licensors or
365 | authors of the material; or
366 |
367 | e) Declining to grant rights under trademark law for use of some
368 | trade names, trademarks, or service marks; or
369 |
370 | f) Requiring indemnification of licensors and authors of that
371 | material by anyone who conveys the material (or modified versions of
372 | it) with contractual assumptions of liability to the recipient, for
373 | any liability that these contractual assumptions directly impose on
374 | those licensors and authors.
375 |
376 | All other non-permissive additional terms are considered "further
377 | restrictions" within the meaning of section 10. If the Program as you
378 | received it, or any part of it, contains a notice stating that it is
379 | governed by this License along with a term that is a further
380 | restriction, you may remove that term. If a license document contains
381 | a further restriction but permits relicensing or conveying under this
382 | License, you may add to a covered work material governed by the terms
383 | of that license document, provided that the further restriction does
384 | not survive such relicensing or conveying.
385 |
386 | If you add terms to a covered work in accord with this section, you
387 | must place, in the relevant source files, a statement of the
388 | additional terms that apply to those files, or a notice indicating
389 | where to find the applicable terms.
390 |
391 | Additional terms, permissive or non-permissive, may be stated in the
392 | form of a separately written license, or stated as exceptions;
393 | the above requirements apply either way.
394 |
395 | 8. Termination.
396 |
397 | You may not propagate or modify a covered work except as expressly
398 | provided under this License. Any attempt otherwise to propagate or
399 | modify it is void, and will automatically terminate your rights under
400 | this License (including any patent licenses granted under the third
401 | paragraph of section 11).
402 |
403 | However, if you cease all violation of this License, then your
404 | license from a particular copyright holder is reinstated (a)
405 | provisionally, unless and until the copyright holder explicitly and
406 | finally terminates your license, and (b) permanently, if the copyright
407 | holder fails to notify you of the violation by some reasonable means
408 | prior to 60 days after the cessation.
409 |
410 | Moreover, your license from a particular copyright holder is
411 | reinstated permanently if the copyright holder notifies you of the
412 | violation by some reasonable means, this is the first time you have
413 | received notice of violation of this License (for any work) from that
414 | copyright holder, and you cure the violation prior to 30 days after
415 | your receipt of the notice.
416 |
417 | Termination of your rights under this section does not terminate the
418 | licenses of parties who have received copies or rights from you under
419 | this License. If your rights have been terminated and not permanently
420 | reinstated, you do not qualify to receive new licenses for the same
421 | material under section 10.
422 |
423 | 9. Acceptance Not Required for Having Copies.
424 |
425 | You are not required to accept this License in order to receive or
426 | run a copy of the Program. Ancillary propagation of a covered work
427 | occurring solely as a consequence of using peer-to-peer transmission
428 | to receive a copy likewise does not require acceptance. However,
429 | nothing other than this License grants you permission to propagate or
430 | modify any covered work. These actions infringe copyright if you do
431 | not accept this License. Therefore, by modifying or propagating a
432 | covered work, you indicate your acceptance of this License to do so.
433 |
434 | 10. Automatic Licensing of Downstream Recipients.
435 |
436 | Each time you convey a covered work, the recipient automatically
437 | receives a license from the original licensors, to run, modify and
438 | propagate that work, subject to this License. You are not responsible
439 | for enforcing compliance by third parties with this License.
440 |
441 | An "entity transaction" is a transaction transferring control of an
442 | organization, or substantially all assets of one, or subdividing an
443 | organization, or merging organizations. If propagation of a covered
444 | work results from an entity transaction, each party to that
445 | transaction who receives a copy of the work also receives whatever
446 | licenses to the work the party's predecessor in interest had or could
447 | give under the previous paragraph, plus a right to possession of the
448 | Corresponding Source of the work from the predecessor in interest, if
449 | the predecessor has it or can get it with reasonable efforts.
450 |
451 | You may not impose any further restrictions on the exercise of the
452 | rights granted or affirmed under this License. For example, you may
453 | not impose a license fee, royalty, or other charge for exercise of
454 | rights granted under this License, and you may not initiate litigation
455 | (including a cross-claim or counterclaim in a lawsuit) alleging that
456 | any patent claim is infringed by making, using, selling, offering for
457 | sale, or importing the Program or any portion of it.
458 |
459 | 11. Patents.
460 |
461 | A "contributor" is a copyright holder who authorizes use under this
462 | License of the Program or a work on which the Program is based. The
463 | work thus licensed is called the contributor's "contributor version".
464 |
465 | A contributor's "essential patent claims" are all patent claims
466 | owned or controlled by the contributor, whether already acquired or
467 | hereafter acquired, that would be infringed by some manner, permitted
468 | by this License, of making, using, or selling its contributor version,
469 | but do not include claims that would be infringed only as a
470 | consequence of further modification of the contributor version. For
471 | purposes of this definition, "control" includes the right to grant
472 | patent sublicenses in a manner consistent with the requirements of
473 | this License.
474 |
475 | Each contributor grants you a non-exclusive, worldwide, royalty-free
476 | patent license under the contributor's essential patent claims, to
477 | make, use, sell, offer for sale, import and otherwise run, modify and
478 | propagate the contents of its contributor version.
479 |
480 | In the following three paragraphs, a "patent license" is any express
481 | agreement or commitment, however denominated, not to enforce a patent
482 | (such as an express permission to practice a patent or covenant not to
483 | sue for patent infringement). To "grant" such a patent license to a
484 | party means to make such an agreement or commitment not to enforce a
485 | patent against the party.
486 |
487 | If you convey a covered work, knowingly relying on a patent license,
488 | and the Corresponding Source of the work is not available for anyone
489 | to copy, free of charge and under the terms of this License, through a
490 | publicly available network server or other readily accessible means,
491 | then you must either (1) cause the Corresponding Source to be so
492 | available, or (2) arrange to deprive yourself of the benefit of the
493 | patent license for this particular work, or (3) arrange, in a manner
494 | consistent with the requirements of this License, to extend the patent
495 | license to downstream recipients. "Knowingly relying" means you have
496 | actual knowledge that, but for the patent license, your conveying the
497 | covered work in a country, or your recipient's use of the covered work
498 | in a country, would infringe one or more identifiable patents in that
499 | country that you have reason to believe are valid.
500 |
501 | If, pursuant to or in connection with a single transaction or
502 | arrangement, you convey, or propagate by procuring conveyance of, a
503 | covered work, and grant a patent license to some of the parties
504 | receiving the covered work authorizing them to use, propagate, modify
505 | or convey a specific copy of the covered work, then the patent license
506 | you grant is automatically extended to all recipients of the covered
507 | work and works based on it.
508 |
509 | A patent license is "discriminatory" if it does not include within
510 | the scope of its coverage, prohibits the exercise of, or is
511 | conditioned on the non-exercise of one or more of the rights that are
512 | specifically granted under this License. You may not convey a covered
513 | work if you are a party to an arrangement with a third party that is
514 | in the business of distributing software, under which you make payment
515 | to the third party based on the extent of your activity of conveying
516 | the work, and under which the third party grants, to any of the
517 | parties who would receive the covered work from you, a discriminatory
518 | patent license (a) in connection with copies of the covered work
519 | conveyed by you (or copies made from those copies), or (b) primarily
520 | for and in connection with specific products or compilations that
521 | contain the covered work, unless you entered into that arrangement,
522 | or that patent license was granted, prior to 28 March 2007.
523 |
524 | Nothing in this License shall be construed as excluding or limiting
525 | any implied license or other defenses to infringement that may
526 | otherwise be available to you under applicable patent law.
527 |
528 | 12. No Surrender of Others' Freedom.
529 |
530 | If conditions are imposed on you (whether by court order, agreement or
531 | otherwise) that contradict the conditions of this License, they do not
532 | excuse you from the conditions of this License. If you cannot convey a
533 | covered work so as to satisfy simultaneously your obligations under this
534 | License and any other pertinent obligations, then as a consequence you may
535 | not convey it at all. For example, if you agree to terms that obligate you
536 | to collect a royalty for further conveying from those to whom you convey
537 | the Program, the only way you could satisfy both those terms and this
538 | License would be to refrain entirely from conveying the Program.
539 |
540 | 13. Remote Network Interaction; Use with the GNU General Public License.
541 |
542 | Notwithstanding any other provision of this License, if you modify the
543 | Program, your modified version must prominently offer all users
544 | interacting with it remotely through a computer network (if your version
545 | supports such interaction) an opportunity to receive the Corresponding
546 | Source of your version by providing access to the Corresponding Source
547 | from a network server at no charge, through some standard or customary
548 | means of facilitating copying of software. This Corresponding Source
549 | shall include the Corresponding Source for any work covered by version 3
550 | of the GNU General Public License that is incorporated pursuant to the
551 | following paragraph.
552 |
553 | Notwithstanding any other provision of this License, you have
554 | permission to link or combine any covered work with a work licensed
555 | under version 3 of the GNU General Public License into a single
556 | combined work, and to convey the resulting work. The terms of this
557 | License will continue to apply to the part which is the covered work,
558 | but the work with which it is combined will remain governed by version
559 | 3 of the GNU General Public License.
560 |
561 | 14. Revised Versions of this License.
562 |
563 | The Free Software Foundation may publish revised and/or new versions of
564 | the GNU Affero General Public License from time to time. Such new versions
565 | will be similar in spirit to the present version, but may differ in detail to
566 | address new problems or concerns.
567 |
568 | Each version is given a distinguishing version number. If the
569 | Program specifies that a certain numbered version of the GNU Affero General
570 | Public License "or any later version" applies to it, you have the
571 | option of following the terms and conditions either of that numbered
572 | version or of any later version published by the Free Software
573 | Foundation. If the Program does not specify a version number of the
574 | GNU Affero General Public License, you may choose any version ever published
575 | by the Free Software Foundation.
576 |
577 | If the Program specifies that a proxy can decide which future
578 | versions of the GNU Affero General Public License can be used, that proxy's
579 | public statement of acceptance of a version permanently authorizes you
580 | to choose that version for the Program.
581 |
582 | Later license versions may give you additional or different
583 | permissions. However, no additional obligations are imposed on any
584 | author or copyright holder as a result of your choosing to follow a
585 | later version.
586 |
587 | 15. Disclaimer of Warranty.
588 |
589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
597 |
598 | 16. Limitation of Liability.
599 |
600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
608 | SUCH DAMAGES.
609 |
610 | 17. Interpretation of Sections 15 and 16.
611 |
612 | If the disclaimer of warranty and limitation of liability provided
613 | above cannot be given local legal effect according to their terms,
614 | reviewing courts shall apply local law that most closely approximates
615 | an absolute waiver of all civil liability in connection with the
616 | Program, unless a warranty or assumption of liability accompanies a
617 | copy of the Program in return for a fee.
618 |
619 | END OF TERMS AND CONDITIONS
620 |
621 | How to Apply These Terms to Your New Programs
622 |
623 | If you develop a new program, and you want it to be of the greatest
624 | possible use to the public, the best way to achieve this is to make it
625 | free software which everyone can redistribute and change under these terms.
626 |
627 | To do so, attach the following notices to the program. It is safest
628 | to attach them to the start of each source file to most effectively
629 | state the exclusion of warranty; and each file should have at least
630 | the "copyright" line and a pointer to where the full notice is found.
631 |
632 |
633 | Copyright (C)
634 |
635 | This program is free software: you can redistribute it and/or modify
636 | it under the terms of the GNU Affero General Public License as published by
637 | the Free Software Foundation, either version 3 of the License, or
638 | (at your option) any later version.
639 |
640 | This program is distributed in the hope that it will be useful,
641 | but WITHOUT ANY WARRANTY; without even the implied warranty of
642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643 | GNU Affero General Public License for more details.
644 |
645 | You should have received a copy of the GNU Affero General Public License
646 | along with this program. If not, see .
647 |
648 | Also add information on how to contact you by electronic and paper mail.
649 |
650 | If your software can interact with users remotely through a computer
651 | network, you should also make sure that it provides a way for users to
652 | get its source. For example, if your program is a web application, its
653 | interface could display a "Source" link that leads users to an archive
654 | of the code. There are many ways you could offer source, and different
655 | solutions will be better for different programs; see section 13 for the
656 | specific requirements.
657 |
658 | You should also get your employer (if you work as a programmer) or school,
659 | if any, to sign a "copyright disclaimer" for the program, if necessary.
660 | For more information on this, and how to apply and follow the GNU AGPL, see
661 | .
662 |
--------------------------------------------------------------------------------
/src/main.py:
--------------------------------------------------------------------------------
1 | import datetime
2 | from math import radians, sin, cos
3 | from lib import *
4 | from shapes import *
5 | import lib
6 | import mat
7 |
8 | switch_thickness = 1.3
9 | switch_top_thickness = 2.8
10 | web_thickness = 3
11 | switch_rim_thickness = 2
12 |
13 | post_width = 0.5
14 | post_rad = post_width / 2
15 |
16 | keyhole_size = 13.8
17 | keyswitch_height = 15
18 | keyswitch_width = 15
19 |
20 | plate_outer_width = keyhole_size + switch_rim_thickness * 2
21 |
22 | max_num_rows = 4
23 | num_cols = 6
24 | num_pinky_columns = 2
25 |
26 | cols_with_max_rows = [2, 3]
27 |
28 | sa_profile_key_height = 2
29 | cap_top_height = switch_top_thickness + sa_profile_key_height
30 |
31 | # extra space between the base of keys
32 | extra_height = 3
33 | extra_width = 3
34 | mount_height = keyswitch_height
35 | mount_width = keyswitch_width
36 | # use 10 for faster prototyping, 15 for real
37 | tenting_angle = 11.0
38 | z_offset = 9.0
39 |
40 | should_include_risers = False
41 |
42 |
43 | def is_pinky(col):
44 | return col >= num_cols - num_pinky_columns
45 |
46 |
47 | # aka: alpha
48 | def row_curve_deg(col):
49 | # I tried to have a different curve for pinkys, but it didn't work well
50 | return 17
51 |
52 |
53 | # aka: beta
54 | col_curve_deg = 4.0
55 |
56 | column_radius = cap_top_height + ((mount_width + extra_width) / 2) / sin(
57 | radians(col_curve_deg) / 2
58 | )
59 |
60 |
61 | def row_radius(col):
62 | return cap_top_height + ((mount_height + extra_height) / 2) / sin(
63 | radians(row_curve_deg(col)) / 2
64 | )
65 |
66 |
67 | # default 3
68 | # controls left-right tilt / tenting (higher number is more tenting)
69 | center_col = 3
70 | center_row = 1
71 |
72 |
73 | def column_extra_transform(col):
74 | if is_pinky(col):
75 | # TODO: translate first?
76 | return compose(rotate_x(6), rotate_y(-3))
77 | else:
78 | return identity()
79 |
80 |
81 | def num_rows_for_col(col):
82 | if col in cols_with_max_rows:
83 | return max_num_rows
84 | else:
85 | return max_num_rows - 1
86 |
87 |
88 | def does_coord_exist(row, col):
89 | return col >= 0 and col < num_cols and row >= 0 and row < num_rows_for_col(col)
90 |
91 |
92 | def negative(vect):
93 | return [-x for x in vect]
94 |
95 |
96 | def bottom_transform(height):
97 | return extrude_linear(height)(project())
98 |
99 |
100 | def bottom_hull(shape):
101 | return hull(shape, bottom_transform(0.1)(shape))
102 |
103 |
104 | def single_switch_fn():
105 | outer_width = keyhole_size + switch_rim_thickness * 2
106 |
107 | bottom_wall = cube(outer_width, switch_rim_thickness, switch_thickness)
108 | top_wall = translate(0, keyhole_size + switch_rim_thickness, 0)(bottom_wall)
109 |
110 | left_wall = cube(switch_rim_thickness, outer_width, switch_thickness)
111 | right_wall = translate(keyhole_size + switch_rim_thickness, 0, 0)(left_wall)
112 |
113 | nub_len = 2.75
114 | nub_cyl = translate(0, 0, -1)(rotate_x(90)(cylinder(1, nub_len, 30, center=True)))
115 | # nub_cube = translate(-switch_rim_thickness / 2, 0, 0.)(cube(switch_rim_thickness, nub_len, 4, center=True))
116 | # left_nub = translate(switch_rim_thickness, (outer_width) / 2, 0)(hull(nub_cyl, nub_cube))
117 |
118 | # right_nub_cube = translate(switch_rim_thickness / 2, 0, 0)(cube(switch_rim_thickness, nub_len, 4, center=True))
119 | # right_nub = translate(-switch_rim_thickness + outer_width, (outer_width) / 2, 0)(hull(nub_cyl, right_nub_cube))
120 |
121 | return translate(-outer_width / 2, -outer_width / 2, 0)(
122 | union(
123 | bottom_wall,
124 | top_wall,
125 | left_wall,
126 | right_wall,
127 | # left_nub,
128 | # right_nub,
129 | )
130 | )
131 |
132 |
133 | single_switch = single_switch_fn()
134 |
135 | filled_switch = translate(0, 0, switch_thickness / 2.0)(
136 | cube(plate_outer_width, plate_outer_width, switch_thickness, center=True)
137 | )
138 |
139 | sa_length = 16.5
140 | sa_width = 17
141 | sa_height = 16.5
142 | sa_base_height = 1.5
143 | sa_extra_height = 2
144 | sa_double_length = 37.5
145 |
146 |
147 | def sa_cap_fn():
148 | # bl2 = sa_length / 2
149 | m = 20.0
150 |
151 | bot = square(sa_width, sa_height, center=True)
152 | bot = extrude_linear(0.1)(bot)
153 |
154 | mid = square(sa_width, sa_height, center=True)
155 | mid = extrude_linear(0.1)(mid)
156 | mid = translate(0, 0, sa_base_height)(mid)
157 |
158 | top = square(14, 14, center=True)
159 | top = extrude_linear(0.1)(top)
160 | top = translate(0, 0, sa_extra_height)(top)
161 |
162 | return colour(220, 163, 163, 1)(
163 | translate(0, 0, switch_top_thickness + 1.5)(hull(bot, mid, top))
164 | )
165 |
166 |
167 | sa_cap = sa_cap_fn()
168 |
169 |
170 | def row_cols():
171 | for row in range(max_num_rows):
172 | for col in range(num_cols):
173 | if row < num_rows_for_col(col):
174 | yield (row, col)
175 |
176 |
177 | def all_of_shape(shape):
178 | return [grid_position(row, col, shape) for (row, col) in row_cols()]
179 |
180 |
181 | web_post = translate(-post_rad, -post_rad, switch_thickness - web_thickness)(
182 | cube(post_width, post_width, web_thickness)
183 | )
184 | short_web_post = translate(-post_rad, -post_rad, 0)(
185 | cube(post_width, post_width, post_width)
186 | )
187 |
188 | SQUARE_OFFSET_IDXS = [
189 | [[-1, -1], [1, -1]],
190 | [[-1, 1], [1, 1]],
191 | ]
192 |
193 |
194 | def square_apply(square, fn):
195 | return [[fn(x) for x in y] for y in square]
196 |
197 |
198 | def square_translater_at_offset(offset):
199 | def fn(idx):
200 | return translate(idx[0] * offset, idx[1] * offset, 0)
201 |
202 | return square_apply(SQUARE_OFFSET_IDXS, fn)
203 |
204 |
205 | def apply_translate_square(square, shape):
206 | def fn(translator):
207 | return translator(shape)
208 |
209 | return square_apply(square, fn)
210 |
211 |
212 | outer_post_delta = keyhole_size / 2 + switch_rim_thickness # - post_rad/2
213 |
214 | outer_post_translate_square = square_translater_at_offset(outer_post_delta)
215 |
216 | web_post_tr = translate(outer_post_delta, outer_post_delta, 0)(web_post)
217 | web_post_tl = translate(-outer_post_delta, outer_post_delta, 0)(web_post)
218 | web_post_br = translate(outer_post_delta, -outer_post_delta, 0)(web_post)
219 | web_post_bl = translate(-outer_post_delta, -outer_post_delta, 0)(web_post)
220 |
221 | web_posts = apply_translate_square(outer_post_translate_square, web_post)
222 | short_web_posts = apply_translate_square(outer_post_translate_square, short_web_post)
223 |
224 | inner_post_delta = keyhole_size / 2 + post_rad
225 | inner_post_translate_square = square_translater_at_offset(inner_post_delta)
226 |
227 | inner_web_posts = apply_translate_square(inner_post_translate_square, web_post)
228 | short_inner_web_posts = apply_translate_square(
229 | inner_post_translate_square, short_web_post
230 | )
231 |
232 | post_left_edge_indexes = [[0, 0], [1, 0]]
233 | post_top_edge_indexes = [[1, 0], [1, 1]]
234 | post_right_edge_indexes = [[1, 1], [0, 1]]
235 | post_bot_edge_indexes = [[0, 1], [0, 0]]
236 |
237 | square_idx_tl = [1, 0]
238 | square_idx_tr = [1, 1]
239 | square_idx_bl = [0, 0]
240 | square_idx_br = [0, 1]
241 |
242 |
243 | def get_web_post(idx):
244 | return web_posts[idx[0]][idx[1]]
245 |
246 |
247 | post_left_edge = [get_web_post(e) for e in post_left_edge_indexes]
248 | post_top_edge = [get_web_post(e) for e in post_top_edge_indexes]
249 | post_right_edge = [get_web_post(e) for e in post_right_edge_indexes]
250 | post_bot_edge = [get_web_post(e) for e in post_bot_edge_indexes]
251 |
252 |
253 | def get_in_square(square, idx):
254 | return square[idx[0]][idx[1]]
255 |
256 |
257 | def get_inner_web_post(idx):
258 | return get_in_square(inner_web_posts, idx)
259 |
260 |
261 | def get_short_web_post(idx):
262 | return get_in_square(short_web_posts, idx)
263 |
264 |
265 | def get_short_inner_web_post(idx):
266 | return get_in_square(short_inner_web_posts, idx)
267 |
268 |
269 | def column_offset(col):
270 | if col == 2:
271 | return [1, 5, -3]
272 | elif col == 3:
273 | return [3, 0, -0.5]
274 | elif is_pinky(col):
275 | return [7.0, -14.5, 5.0]
276 | else:
277 | return [0, 0, 0]
278 |
279 |
280 | def col_z_rotate(col):
281 | if is_pinky(col):
282 | return -3.0
283 | else:
284 | return 0
285 |
286 |
287 | def place_on_grid_base(row, column, domain):
288 | column_angle = col_curve_deg * (center_col - column)
289 | row_angle = row_curve_deg(column) * (center_row - row)
290 |
291 | return domain.compose(
292 | # Row Sphere
293 | domain.translate(0, 0, -row_radius(column)),
294 | domain.rotate_x(row_angle),
295 | domain.translate(0, 0, row_radius(column)),
296 | # Row Offset
297 | # column_extra_transform(column),
298 | # Col sphere
299 | domain.translate(0, 0, -column_radius),
300 | domain.rotate_y(column_angle),
301 | domain.translate(0, 0, column_radius),
302 | # Z Fix
303 | domain.rotate_z(col_z_rotate(column)),
304 | # Column offset
305 | domain.translate(*column_offset(column)),
306 | # Misc
307 | domain.rotate_y(tenting_angle),
308 | domain.translate(0, 0, z_offset),
309 | )
310 |
311 |
312 | def place_on_grid(row, column):
313 | return place_on_grid_base(row, column, lib)
314 |
315 |
316 | def point_on_grid(row, column, x, y, z):
317 | point = mat.point3(x, y, z)
318 | tx_point = place_on_grid_base(row, column, mat) @ point
319 |
320 | return tx_point[:3]
321 |
322 |
323 | def grid_position(row, col, shape):
324 | return place_on_grid(row, col)(shape)
325 |
326 |
327 | def connectors():
328 | def make_edge_connection(r1, c1, e1, r2, c2, e2):
329 | posts1 = [grid_position(r1, c1, e) for e in e1]
330 | posts2 = [grid_position(r2, c2, e) for e in e2]
331 | return hull(*posts1, *posts2)
332 |
333 | all_connectors = []
334 | for col in range(num_cols - 1):
335 | for row in range(max_num_rows):
336 | if does_coord_exist(row, col) and does_coord_exist(row, col + 1):
337 | if (row, col) == (0, 3):
338 | right_edge = [
339 | translate(1, 1, 0)(web_post_tr),
340 | translate(0, 1, 0)(web_post_tr),
341 | web_post_br,
342 | ]
343 | else:
344 | right_edge = post_right_edge
345 | all_connectors.append(
346 | make_edge_connection(
347 | row, col, right_edge, row, col + 1, post_left_edge
348 | )
349 | )
350 |
351 | for col in range(num_cols):
352 | for row in range(max_num_rows - 1):
353 | if does_coord_exist(row, col) and does_coord_exist(row + 1, col):
354 | all_connectors.append(
355 | make_edge_connection(
356 | row, col, post_bot_edge, row + 1, col, post_top_edge
357 | )
358 | )
359 |
360 | for col in range(num_cols - 1):
361 | row = num_rows_for_col(col) - 1
362 | next_col = col + 1
363 | next_row = num_rows_for_col(next_col) - 1
364 | if next_row == row + 1:
365 | this_t = place_on_grid(row, col)
366 | next_t = place_on_grid(next_row, next_col)
367 | this_level_t = place_on_grid(row, next_col)
368 | all_connectors.append(
369 | hull(
370 | this_t(web_post_br), this_level_t(web_post_bl), next_t(web_post_tl),
371 | )
372 | )
373 | all_connectors.append(
374 | hull(this_t(web_post_br), next_t(web_post_tl), next_t(web_post_bl),)
375 | )
376 | if next_row == row - 1:
377 | this_t = place_on_grid(row, col)
378 | next_t = place_on_grid(next_row, next_col)
379 | this_level_t = place_on_grid(next_row, col)
380 |
381 | all_connectors.append(
382 | hull(
383 | this_t(web_post_tr), this_level_t(web_post_br), next_t(web_post_bl),
384 | )
385 | )
386 |
387 | all_connectors.append(
388 | hull(this_t(web_post_tr), this_t(web_post_br), next_t(web_post_bl),)
389 | )
390 |
391 | def does_diag_exist(row, col):
392 | for dr in [0, 1]:
393 | for dc in [0, 1]:
394 | if not does_coord_exist(row + dr, col + dc):
395 | return False
396 | return True
397 |
398 | for col in range(num_cols - 1):
399 | for row in range(max_num_rows - 1):
400 | if does_diag_exist(row, col):
401 | p1 = grid_position(row, col, web_post_br)
402 | p2 = grid_position(row + 1, col, web_post_tr)
403 | p3 = grid_position(row + 1, col + 1, web_post_tl)
404 | p4 = grid_position(row, col + 1, web_post_bl)
405 | all_connectors.append(hull(p1, p2, p3, p4))
406 |
407 | return union(*all_connectors)
408 |
409 |
410 | SWITCH_RISER_OFFSET = 9.8 + SWITCH_RISER_RADIUS
411 | switch_riser_offset_square = square_translater_at_offset(SWITCH_RISER_OFFSET)
412 |
413 |
414 | def get_riser_is_connector(rc1, idx1, rc2, idx2):
415 | if rc1 == [0, 3] and rc2 == [0, 4]:
416 | return False
417 | return True
418 |
419 |
420 | def get_riser_offset_delta(row_col, idx):
421 | if row_col == [0, 1] and idx == square_idx_tr:
422 | return [-2.5, 0]
423 | if row_col == [0, 3] and idx == square_idx_tl:
424 | return [2.5, 0]
425 | if row_col == [0, 3] and idx == square_idx_tr:
426 | return [-0.5, 0]
427 | if row_col == [0, 4] and idx == square_idx_tl:
428 | return [2.5, 0]
429 | if row_col == [2, 4] and idx == square_idx_bl:
430 | return [2.5, 0]
431 | if row_col == [3, 2] and idx == square_idx_br:
432 | return [-3.5, 1]
433 | if row_col == [2, 1] and idx == square_idx_br:
434 | return [-3, 0]
435 | else:
436 | return None
437 |
438 |
439 | def wall_connect(row1, col1, idx1, row2, col2, idx2, **kwargs):
440 | place_fn1 = place_on_grid(row1, col1)
441 | place_fn2 = place_on_grid(row2, col2)
442 |
443 | delta1 = get_riser_offset_delta([row1, col1], idx1)
444 | delta2 = get_riser_offset_delta([row2, col2], idx2)
445 |
446 | connectors = get_riser_is_connector([row1, col1], idx1, [row2, col2], idx2)
447 |
448 | return wall_connect_from_placer(
449 | place_fn1,
450 | idx1,
451 | place_fn2,
452 | idx2,
453 | delta1=delta1,
454 | delta2=delta2,
455 | connectors=connectors,
456 | **kwargs,
457 | )
458 |
459 |
460 | def make_offsetter(idx, delta):
461 | offsetter = get_in_square(switch_riser_offset_square, idx)
462 |
463 | if delta:
464 | z = 0
465 | if len(delta) == 3:
466 | z = delta[2]
467 | offsetter = translate(delta[0], delta[1], z)(offsetter)
468 | return offsetter
469 |
470 |
471 | def wall_connect_from_placer(
472 | place_fn1,
473 | idx1,
474 | place_fn2,
475 | idx2,
476 | *,
477 | delta1=None,
478 | delta2=None,
479 | connectors=True,
480 | walls=True
481 | ):
482 | offsetter1 = make_offsetter(idx1, delta1)
483 | offsetter2 = make_offsetter(idx2, delta2)
484 |
485 | post1 = offsetter1(switch_riser_post)
486 | post2 = offsetter2(switch_riser_post)
487 |
488 | shapes = []
489 |
490 | if should_include_risers:
491 | shapes.append(hull(place_fn1(post1), place_fn2(post2)))
492 |
493 | if connectors:
494 | shapes.append(
495 | hull(
496 | place_fn1(union(offsetter1(web_post), get_in_square(web_posts, idx1))),
497 | place_fn2(union(offsetter2(web_post), get_in_square(web_posts, idx2))),
498 | )
499 | )
500 |
501 | if walls:
502 | shapes.append(
503 | bottom_hull(
504 | hull(
505 | place_fn1(offsetter1(switch_riser_raw_dot)),
506 | place_fn2(offsetter2(switch_riser_raw_dot)),
507 | )
508 | )
509 | )
510 |
511 | return union(*shapes)
512 |
513 |
514 | def case_walls():
515 | all_shapes = []
516 |
517 | # Top wall
518 | for col in range(0, num_cols):
519 | all_shapes.append(wall_connect(0, col, square_idx_tl, 0, col, square_idx_tr))
520 | for col in range(0, num_cols - 1):
521 | all_shapes.append(
522 | wall_connect(0, col, square_idx_tr, 0, col + 1, square_idx_tl)
523 | )
524 |
525 | # Right wall
526 | max_col = num_cols - 1
527 | for row in range(0, num_rows_for_col(max_col)):
528 | all_shapes.append(
529 | wall_connect(row, max_col, square_idx_tr, row, max_col, square_idx_br)
530 | )
531 | for row in range(0, num_rows_for_col(max_col) - 1):
532 | all_shapes.append(
533 | wall_connect(row, max_col, square_idx_br, row + 1, max_col, square_idx_tr)
534 | )
535 |
536 | # Left wall
537 | for row in range(0, num_rows_for_col(0)):
538 | all_shapes.append(wall_connect(row, 0, square_idx_tl, row, 0, square_idx_bl))
539 | for row in range(0, num_rows_for_col(0) - 1):
540 | all_shapes.append(
541 | wall_connect(row, 0, square_idx_bl, row + 1, 0, square_idx_tl)
542 | )
543 |
544 | # Bottom wall
545 | def include_wall(col):
546 | return col >= 2
547 |
548 | for col in range(0, num_cols):
549 | all_shapes.append(
550 | wall_connect(
551 | num_rows_for_col(col) - 1,
552 | col,
553 | square_idx_bl,
554 | num_rows_for_col(col) - 1,
555 | col,
556 | square_idx_br,
557 | walls=include_wall(col),
558 | )
559 | )
560 | for col in range(0, num_cols - 1):
561 | all_shapes.append(
562 | wall_connect(
563 | num_rows_for_col(col) - 1,
564 | col,
565 | square_idx_br,
566 | num_rows_for_col(col + 1) - 1,
567 | col + 1,
568 | square_idx_bl,
569 | walls=include_wall(col),
570 | )
571 | )
572 |
573 | return union(*all_shapes)
574 |
575 |
576 | def all_switches():
577 | return union(*all_of_shape(single_switch))
578 |
579 |
580 | def filled_switches():
581 | return union(*all_of_shape(filled_switch))
582 |
583 |
584 | def all_caps():
585 | return union(*all_of_shape(sa_cap))
586 |
587 |
588 | def post_test():
589 | return union(*[y for x in short_web_posts for y in x],)
590 |
591 |
592 | thumb_basic_postition = point_on_grid(num_rows_for_col(1), 1, 0, 0, 0)
593 | thumb_offsets = [16, 4.8, -2.5]
594 | # thumb_offsets = [16, 7, -5]
595 | thumb_position = [sum(x) for x in zip(thumb_basic_postition, thumb_offsets)]
596 |
597 |
598 | def thumb_placer(rot, move):
599 | return compose(
600 | rotate_x(rot[0]),
601 | rotate_y(rot[1]),
602 | rotate_z(rot[2]),
603 | translate(*move),
604 | rotate_z(-10),
605 | translate(*thumb_position),
606 | )
607 |
608 |
609 | thumb_r_placer = thumb_placer([14, -26, 12], [-17.4, -11.8, -4.2])
610 | thumb_m_placer = thumb_placer([8, -17, 22], [-36, -17.6, -12])
611 | thumb_l_placer = thumb_placer([6, -5, 30], [-54, -26.5, -16])
612 |
613 | thumb_bl_placer = thumb_placer([4, -10, 27], [-35.3, -38.2, -18])
614 | thumb_br_placer = thumb_placer([4, -26, 18], [-15.8, -30.7, -11.6])
615 |
616 | thumb_placement_fns = [
617 | thumb_r_placer,
618 | thumb_m_placer,
619 | thumb_l_placer,
620 | thumb_br_placer,
621 | thumb_bl_placer,
622 | ]
623 |
624 |
625 | def thumbs_post_offsets(placer, post):
626 | if placer == thumb_br_placer:
627 | if post == square_idx_bl:
628 | return [3, 0, 0]
629 | if post == square_idx_tr:
630 | return [0, -3.8, 0]
631 |
632 | if placer == thumb_r_placer:
633 | if post == square_idx_bl:
634 | return [20, 0, 0]
635 | if post == square_idx_tl:
636 | return [4, 0, 0]
637 |
638 | if placer == thumb_bl_placer:
639 | if post == square_idx_br:
640 | return [-3, 0, 0]
641 | if post == square_idx_tl:
642 | return [0, -3, 0]
643 |
644 | if placer == thumb_l_placer:
645 | if post == square_idx_br:
646 | return [-10.8, 0, -0.5]
647 |
648 | if placer == thumb_m_placer:
649 | if post == square_idx_tr:
650 | return [-2, 0, 0]
651 |
652 | return None
653 |
654 |
655 | def thumb_wall(place_fn1, idx1, place_fn2, idx2, **kwargs):
656 | d1 = thumbs_post_offsets(place_fn1, idx1)
657 | d2 = thumbs_post_offsets(place_fn2, idx2)
658 |
659 | return wall_connect_from_placer(
660 | place_fn1, idx1, place_fn2, idx2, delta1=d1, delta2=d2, **kwargs
661 | )
662 |
663 |
664 | def get_offset_thumb_placer(placer, idx, shape):
665 | delta = thumbs_post_offsets(placer, idx)
666 | return placer(make_offsetter(idx, delta)(shape))
667 |
668 |
669 | def thumb_walls():
670 | return union(
671 | thumb_wall(thumb_bl_placer, square_idx_bl, thumb_bl_placer, square_idx_br),
672 | thumb_wall(thumb_bl_placer, square_idx_br, thumb_br_placer, square_idx_bl),
673 | thumb_wall(thumb_br_placer, square_idx_bl, thumb_br_placer, square_idx_br),
674 | thumb_wall(thumb_bl_placer, square_idx_bl, thumb_bl_placer, square_idx_tl),
675 | thumb_wall(
676 | thumb_bl_placer,
677 | square_idx_tl,
678 | thumb_l_placer,
679 | square_idx_br,
680 | connectors=False,
681 | ),
682 | thumb_wall(
683 | thumb_l_placer,
684 | square_idx_br,
685 | thumb_l_placer,
686 | square_idx_bl,
687 | connectors=False,
688 | ),
689 | thumb_wall(thumb_l_placer, square_idx_bl, thumb_l_placer, square_idx_tl),
690 | thumb_wall(thumb_l_placer, square_idx_tl, thumb_l_placer, square_idx_tr),
691 | thumb_wall(thumb_l_placer, square_idx_tr, thumb_m_placer, square_idx_tl),
692 | thumb_wall(
693 | thumb_m_placer, square_idx_tl, thumb_m_placer, square_idx_tr, walls=False
694 | ),
695 | thumb_wall(
696 | thumb_m_placer, square_idx_tr, thumb_r_placer, square_idx_tl, walls=False
697 | ),
698 | thumb_wall(
699 | thumb_r_placer, square_idx_tl, thumb_r_placer, square_idx_tr, walls=False
700 | ),
701 | thumb_wall(
702 | thumb_r_placer, square_idx_tr, thumb_r_placer, square_idx_br, walls=False
703 | ),
704 | thumb_wall(thumb_br_placer, square_idx_br, thumb_br_placer, square_idx_tr),
705 | thumb_wall(
706 | thumb_r_placer,
707 | square_idx_bl,
708 | thumb_r_placer,
709 | square_idx_br,
710 | walls=False,
711 | connectors=False,
712 | ),
713 | hull(
714 | get_offset_thumb_placer(thumb_br_placer, square_idx_tr, top_dot),
715 | get_offset_thumb_placer(thumb_r_placer, square_idx_bl, top_dot),
716 | get_offset_thumb_placer(
717 | thumb_r_placer, square_idx_bl, switch_riser_raw_dot
718 | ),
719 | ),
720 | hull(
721 | get_offset_thumb_placer(thumb_br_placer, square_idx_tr, top_dot),
722 | get_offset_thumb_placer(
723 | thumb_br_placer, square_idx_tr, switch_riser_raw_dot
724 | ),
725 | get_offset_thumb_placer(
726 | thumb_r_placer, square_idx_bl, switch_riser_raw_dot
727 | ),
728 | ),
729 | hull(
730 | get_offset_thumb_placer(
731 | thumb_r_placer, square_idx_br, switch_riser_raw_dot
732 | ),
733 | get_offset_thumb_placer(
734 | thumb_r_placer, square_idx_bl, switch_riser_raw_dot
735 | ),
736 | get_offset_thumb_placer(
737 | thumb_br_placer, square_idx_tr, switch_riser_raw_dot
738 | ),
739 | ),
740 | bottom_hull(
741 | hull(
742 | get_offset_thumb_placer(
743 | thumb_r_placer, square_idx_br, switch_riser_raw_dot
744 | ),
745 | get_offset_thumb_placer(
746 | thumb_br_placer, square_idx_tr, switch_riser_raw_dot
747 | ),
748 | )
749 | ),
750 | )
751 |
752 |
753 | def thumb_connectors():
754 | right_thumb_cover_sphere = get_offset_thumb_placer(
755 | thumb_r_placer, square_idx_bl, translate(0, 1.7, 0)(web_post)
756 | )
757 |
758 | left_thumb_cover_lower_sphere = get_offset_thumb_placer(
759 | thumb_bl_placer, square_idx_tl, translate(0, 2, 0)(web_post)
760 | )
761 | left_thumb_cover_upper_sphere = thumb_l_placer(translate(0, 0, 0)(web_post_br))
762 |
763 | br_tr_with_offset = thumb_br_placer(translate(0.8, 0.2, 0)(web_post_tr))
764 |
765 | thumb_l_special_point = get_offset_thumb_placer(
766 | thumb_l_placer, square_idx_bl, translate(10, 1.1, 0)(web_post)
767 | )
768 |
769 | return union(
770 | hull(
771 | thumb_m_placer(web_post_tr),
772 | thumb_m_placer(web_post_br),
773 | thumb_r_placer(web_post_tl),
774 | thumb_r_placer(web_post_bl),
775 | ),
776 | hull(
777 | thumb_m_placer(web_post_tl),
778 | thumb_l_placer(web_post_tr),
779 | thumb_m_placer(web_post_bl),
780 | thumb_l_placer(web_post_br),
781 | thumb_m_placer(web_post_bl),
782 | ),
783 | hull(
784 | thumb_bl_placer(web_post_tr),
785 | thumb_bl_placer(web_post_br),
786 | thumb_br_placer(web_post_tl),
787 | thumb_br_placer(web_post_bl),
788 | ),
789 | hull(
790 | thumb_bl_placer(web_post_tl),
791 | thumb_m_placer(web_post_bl),
792 | thumb_l_placer(web_post_br),
793 | ),
794 | hull(
795 | thumb_bl_placer(web_post_tl),
796 | thumb_bl_placer(web_post_tr),
797 | thumb_m_placer(web_post_bl),
798 | ),
799 | hull(
800 | thumb_bl_placer(web_post_tr),
801 | thumb_m_placer(web_post_bl),
802 | thumb_m_placer(web_post_br),
803 | ),
804 | hull(
805 | thumb_br_placer(web_post_tl),
806 | thumb_bl_placer(web_post_tr),
807 | thumb_m_placer(web_post_br),
808 | ),
809 | hull(
810 | thumb_m_placer(web_post_br),
811 | thumb_r_placer(web_post_bl),
812 | thumb_br_placer(web_post_tl),
813 | ),
814 | hull(
815 | thumb_r_placer(web_post_bl),
816 | thumb_br_placer(web_post_tl),
817 | br_tr_with_offset,
818 | ),
819 | hull(
820 | thumb_r_placer(web_post_bl), thumb_r_placer(web_post_br), br_tr_with_offset,
821 | ),
822 | # Right special connectors
823 | hull(
824 | right_thumb_cover_sphere,
825 | get_offset_thumb_placer(thumb_r_placer, square_idx_bl, web_post),
826 | thumb_r_placer(web_post_br),
827 | get_offset_thumb_placer(thumb_r_placer, square_idx_br, web_post),
828 | ),
829 | hull(
830 | right_thumb_cover_sphere,
831 | get_offset_thumb_placer(thumb_r_placer, square_idx_bl, web_post),
832 | get_offset_thumb_placer(
833 | thumb_br_placer, square_idx_tr, switch_riser_raw_dot
834 | ),
835 | br_tr_with_offset,
836 | ),
837 | # Left special connectors
838 | hull(
839 | thumb_l_placer(web_post_bl),
840 | get_offset_thumb_placer(thumb_l_placer, square_idx_bl, web_post),
841 | thumb_l_special_point,
842 | ),
843 | hull(
844 | thumb_l_placer(web_post_bl),
845 | thumb_l_placer(web_post_br),
846 | thumb_l_special_point,
847 | ),
848 | hull(
849 | left_thumb_cover_lower_sphere,
850 | get_offset_thumb_placer(thumb_bl_placer, square_idx_tl, web_post),
851 | thumb_bl_placer(web_post_tl),
852 | ),
853 | hull(
854 | left_thumb_cover_lower_sphere,
855 | thumb_bl_placer(web_post_tl),
856 | left_thumb_cover_upper_sphere,
857 | ),
858 | hull(
859 | left_thumb_cover_lower_sphere,
860 | left_thumb_cover_upper_sphere,
861 | thumb_l_special_point,
862 | ),
863 | hull(
864 | left_thumb_cover_lower_sphere,
865 | get_offset_thumb_placer(thumb_l_placer, square_idx_br, web_post),
866 | thumb_l_special_point,
867 | get_offset_thumb_placer(thumb_bl_placer, square_idx_tl, web_post),
868 | ),
869 | )
870 |
871 |
872 | def thumb_to_body_connectors():
873 | return union(
874 | bottom_hull(
875 | hull(
876 | thumb_r_placer(
877 | get_in_square(switch_riser_offset_square, square_idx_br)(
878 | switch_riser_raw_dot
879 | )
880 | ),
881 | place_on_grid(3, 2)(
882 | get_in_square(switch_riser_offset_square, square_idx_bl)(
883 | switch_riser_raw_dot
884 | )
885 | ),
886 | )
887 | ),
888 | hull(
889 | thumb_r_placer(
890 | get_in_square(switch_riser_offset_square, square_idx_br)(
891 | switch_riser_raw_dot
892 | )
893 | ),
894 | thumb_r_placer(
895 | get_in_square(switch_riser_offset_square, square_idx_tr)(
896 | switch_riser_raw_dot
897 | )
898 | ),
899 | place_on_grid(3, 2)(
900 | get_in_square(switch_riser_offset_square, square_idx_bl)(
901 | switch_riser_raw_dot
902 | )
903 | ),
904 | ),
905 | hull(
906 | thumb_r_placer(
907 | get_in_square(switch_riser_offset_square, square_idx_tr)(
908 | switch_riser_raw_dot
909 | )
910 | ),
911 | place_on_grid(3, 2)(
912 | get_in_square(switch_riser_offset_square, square_idx_bl)(
913 | switch_riser_raw_dot
914 | )
915 | ),
916 | place_on_grid(2, 1)(
917 | get_in_square(switch_riser_offset_square, square_idx_br)(
918 | switch_riser_raw_dot
919 | )
920 | ),
921 | ),
922 | hull(
923 | thumb_r_placer(
924 | get_in_square(switch_riser_offset_square, square_idx_tr)(
925 | switch_riser_raw_dot
926 | )
927 | ),
928 | thumb_r_placer(
929 | get_in_square(switch_riser_offset_square, square_idx_tl)(
930 | switch_riser_raw_dot
931 | )
932 | ),
933 | place_on_grid(2, 1)(
934 | get_in_square(switch_riser_offset_square, square_idx_br)(
935 | switch_riser_raw_dot
936 | )
937 | ),
938 | ),
939 | bottom_hull(
940 | hull(
941 | thumb_m_placer(
942 | get_in_square(switch_riser_offset_square, square_idx_tl)(
943 | switch_riser_raw_dot
944 | )
945 | ),
946 | place_on_grid(2, 0)(
947 | get_in_square(switch_riser_offset_square, square_idx_bl)(
948 | switch_riser_raw_dot
949 | )
950 | ),
951 | )
952 | ),
953 | hull(
954 | thumb_m_placer(
955 | get_in_square(switch_riser_offset_square, square_idx_tl)(
956 | switch_riser_raw_dot
957 | )
958 | ),
959 | place_on_grid(2, 0)(
960 | get_in_square(switch_riser_offset_square, square_idx_bl)(
961 | switch_riser_raw_dot
962 | )
963 | ),
964 | place_on_grid(2, 0)(
965 | get_in_square(switch_riser_offset_square, square_idx_br)(
966 | switch_riser_raw_dot
967 | )
968 | ),
969 | ),
970 | )
971 |
972 |
973 | def thumb_switches():
974 | return union(*[fn(single_switch) for fn in thumb_placement_fns])
975 |
976 |
977 | def filled_thumb_switches():
978 | return union(*[fn(filled_switch) for fn in thumb_placement_fns])
979 |
980 |
981 | def bottom_edge_at_position(row, col):
982 | yield row, col, square_idx_bl
983 | yield row, col, square_idx_br
984 |
985 |
986 | def bottom_edge_iterator():
987 | for col in range(num_cols):
988 | row = num_rows_for_col(col) - 1
989 |
990 | yield from bottom_edge_at_position(row, col)
991 | return
992 |
993 |
994 | def thumb_spots():
995 | return [
996 | [thumb_l_placer, square_idx_tl],
997 | [thumb_l_placer, square_idx_tr],
998 | [thumb_m_placer, square_idx_tl],
999 | [thumb_m_placer, square_idx_tr],
1000 | [thumb_r_placer, square_idx_tl],
1001 | [thumb_r_placer, square_idx_tr],
1002 | [thumb_r_placer, square_idx_br],
1003 | [thumb_br_placer, square_idx_br],
1004 | ]
1005 |
1006 |
1007 | def thumb_caps():
1008 | return union(*[fn(sa_cap) for fn in thumb_placement_fns[-2:]])
1009 |
1010 |
1011 | def blocker():
1012 | size = 500
1013 | shape = cube(size, size, size)
1014 | shape = translate(-size / 2, -size / 2, -size)(shape)
1015 | return shape
1016 |
1017 |
1018 | screw_insert_height = 4.2
1019 | screw_insert_bottom_radius = 5.31 / 2.0
1020 | screw_insert_top_radius = 5.1 / 2
1021 |
1022 | screw_insert_width = 2
1023 | bottom_height = 2
1024 |
1025 | screw_insert_outer = translate(0, 0, bottom_height)(
1026 | cylinderr1r2(
1027 | screw_insert_bottom_radius + screw_insert_width,
1028 | screw_insert_top_radius + screw_insert_width,
1029 | screw_insert_height + screw_insert_width,
1030 | )
1031 | )
1032 | screw_insert_inner = translate(0, 0, bottom_height)(
1033 | cylinderr1r2(
1034 | screw_insert_bottom_radius, screw_insert_top_radius, screw_insert_height
1035 | )
1036 | )
1037 |
1038 |
1039 | def screw_insert(col, row, shape, ox, oy):
1040 | postiion = point_on_grid(row, col, 0, 0, 0)
1041 | postiion[2] = 0
1042 | postiion[0] += ox
1043 | postiion[1] += oy
1044 | return translate(*postiion)(shape)
1045 |
1046 |
1047 | def screw_insert_all_shapes(shape):
1048 | return union(
1049 | screw_insert(2, 0, shape, -5.3, 5.9),
1050 | screw_insert(num_cols - 1, 0, shape, 6.7, 5.5),
1051 | screw_insert(num_cols - 1, num_rows_for_col(num_cols - 1), shape, 6.8, 14.4),
1052 | screw_insert(0, 0, shape, -6.2, -6),
1053 | screw_insert(1, max_num_rows + 1, shape, -9.8, 3.4),
1054 | screw_insert(0, max_num_rows - 1, shape, -17.4, -2),
1055 | )
1056 |
1057 |
1058 | trrs_holder_size = [6.0, 11.0, 7.0]
1059 | trrs_hole_size = [2.6, 10.0]
1060 | trrs_holder_thickness = 2.5
1061 |
1062 | trrs_front_thickness = 1.8
1063 |
1064 |
1065 | def trrs_key_holder_position():
1066 | base_place = point_on_grid(0, 0, 0, keyswitch_width / 2, 0)
1067 | return [base_place[0] + 3, base_place[1] + 2.43, 8.5]
1068 |
1069 |
1070 | def trrs_holder():
1071 | shape = cube(
1072 | trrs_holder_size[0] + trrs_holder_thickness,
1073 | trrs_holder_size[1] + trrs_front_thickness,
1074 | trrs_holder_size[2] + trrs_holder_thickness * 2,
1075 | )
1076 |
1077 | pos = trrs_key_holder_position()
1078 |
1079 | placed_shape = translate(
1080 | -trrs_holder_size[0] / 2,
1081 | -trrs_holder_size[1],
1082 | -(trrs_holder_size[2] / 2 + trrs_holder_thickness),
1083 | )(shape)
1084 |
1085 | return translate(*trrs_key_holder_position())(placed_shape)
1086 |
1087 |
1088 | def trrs_holder_hole():
1089 | rect_hole = cube(*trrs_holder_size)
1090 | rect_hole = translate(
1091 | -trrs_holder_size[0] / 2, -trrs_holder_size[1], -trrs_holder_size[2] / 2,
1092 | )(rect_hole)
1093 |
1094 | cylinder_hole = cylinder(*trrs_hole_size, segments=30)
1095 | cylinder_hole = rotate_x(90)(cylinder_hole)
1096 | cylinder_hole = translate(0, 5, 0)(cylinder_hole)
1097 |
1098 | return translate(*trrs_key_holder_position())(union(rect_hole, cylinder_hole))
1099 |
1100 |
1101 | usb_holder_hole_dims = [9, 8, 3.5]
1102 | usb_holder_thickness = 0.5
1103 |
1104 |
1105 | def usb_holder_position():
1106 | base_place = point_on_grid(0, 0, 0, keyswitch_width / 2, 0)
1107 | return [base_place[0] + 8, base_place[1] + 2, 4]
1108 |
1109 |
1110 | def usb_holder_rim():
1111 | base_shape = cube(
1112 | usb_holder_hole_dims[0] + usb_holder_thickness * 2,
1113 | usb_holder_thickness * 2,
1114 | usb_holder_hole_dims[2] + usb_holder_thickness * 2,
1115 | )
1116 |
1117 | placed_shape = translate(
1118 | -usb_holder_hole_dims[0] / 2 - usb_holder_thickness,
1119 | 0,
1120 | -usb_holder_hole_dims[2] / 2 - usb_holder_thickness,
1121 | )(base_shape)
1122 |
1123 | return translate(*usb_holder_position())(placed_shape)
1124 |
1125 |
1126 | def usb_holder_hole():
1127 | placed_shape = translate(
1128 | -usb_holder_hole_dims[0] / 2,
1129 | -usb_holder_hole_dims[1] / 2,
1130 | -usb_holder_hole_dims[2] / 2,
1131 | )(cube(*usb_holder_hole_dims))
1132 |
1133 | return translate(*usb_holder_position())(placed_shape)
1134 |
1135 |
1136 | reset_switch_hole_height = 4.2
1137 | reset_switch_width = 6.0
1138 | reset_switch_hole_depth = 6.5
1139 | reset_switch_hole_back = 5.0
1140 |
1141 | reset_switch_hole_radius = 4.3 / 2
1142 |
1143 | reset_switch_total_depth = reset_switch_hole_depth + reset_switch_hole_back
1144 | reset_switch_total_height = reset_switch_hole_height + 2 * bottom_height
1145 |
1146 |
1147 | def unplaced_reset_switch_body():
1148 | shape = cube(
1149 | reset_switch_width,
1150 | reset_switch_total_depth,
1151 | reset_switch_total_height,
1152 | center=True,
1153 | )
1154 | return translate(0, 0, reset_switch_total_height / 2)(shape)
1155 |
1156 |
1157 | def unplaced_reset_switch_body_hole():
1158 | rect = translate(
1159 | 0, -reset_switch_hole_back / 2.0, reset_switch_hole_height / 2.0 + bottom_height
1160 | )(
1161 | cube(
1162 | reset_switch_width + 0.2,
1163 | reset_switch_hole_depth,
1164 | reset_switch_hole_height,
1165 | center=True,
1166 | )
1167 | )
1168 | cyl = translate(0, -reset_switch_hole_back / 2, bottom_height / 2)(
1169 | cylinder(reset_switch_hole_radius, bottom_height, center=True)
1170 | )
1171 |
1172 | return union(rect, cyl)
1173 |
1174 |
1175 | def place_reset_switch_shape(shape):
1176 | base_point = point_on_grid(1, 1, 0, 0, 0)
1177 |
1178 | return translate(base_point[0], base_point[1], 0)(shape)
1179 |
1180 |
1181 | reset_switch_body = place_reset_switch_shape(unplaced_reset_switch_body())
1182 | reset_switch_body_hole = place_reset_switch_shape(unplaced_reset_switch_body_hole())
1183 |
1184 |
1185 | def right_shell():
1186 | global should_include_risers
1187 | should_include_risers = True
1188 |
1189 | cover = translate(-60, 20, 0)(cube(15, 15, 20))
1190 |
1191 | full_proto = difference(
1192 | union(
1193 | all_switches(),
1194 | connectors(),
1195 | case_walls(),
1196 | screw_insert_all_shapes(screw_insert_outer),
1197 | # all_caps(),
1198 | thumb_switches(),
1199 | thumb_walls(),
1200 | thumb_connectors(),
1201 | # thumb_caps(),
1202 | thumb_to_body_connectors(),
1203 |
1204 | # trrs_holder(),
1205 | usb_holder_rim(),
1206 | ),
1207 | union(
1208 | blocker(),
1209 | screw_insert_all_shapes(screw_insert_inner),
1210 | # trrs_holder_hole(),
1211 | usb_holder_hole(),
1212 | ),
1213 | )
1214 |
1215 | # return intersection(cover, full_proto)
1216 | return full_proto
1217 |
1218 |
1219 | def left_shell():
1220 | return flip_lr()(right_shell())
1221 |
1222 |
1223 | screw_head_height = 1.0
1224 | screw_head_radius = 5.5 / 2
1225 | screw_hole_radius = 1.7
1226 |
1227 |
1228 | def wall_shape():
1229 | walls_3d = union(case_walls(), thumb_walls(), thumb_to_body_connectors(),)
1230 |
1231 | walls_2d = offset(0.4)(project(cut=True))(translate(0, 0, -0.1)(walls_3d))
1232 |
1233 | return walls_2d
1234 |
1235 |
1236 | def model_outline():
1237 | global should_include_risers
1238 | should_include_risers = True
1239 |
1240 | solid_bottom = project()(
1241 | union(
1242 | filled_switches(),
1243 | connectors(),
1244 | case_walls(),
1245 | filled_thumb_switches(),
1246 | thumb_walls(),
1247 | thumb_connectors(),
1248 | thumb_to_body_connectors(),
1249 | )
1250 | )
1251 |
1252 | bottom_2d = difference(solid_bottom, wall_shape())
1253 | return extrude_linear(bottom_height)(bottom_2d)
1254 |
1255 |
1256 | weight_width = 19.5
1257 | weight_height = 16.5
1258 |
1259 | weight_z_offset = 0.5
1260 |
1261 |
1262 | def weight_shape():
1263 | return translate(0, 0, 1.5 + weight_z_offset)(
1264 | cube(weight_width, weight_height, 3, center=True)
1265 | )
1266 |
1267 |
1268 | def weight_shape_vert():
1269 | return rotate_z(90)(weight_shape())
1270 |
1271 |
1272 | def place_weight_hole(x, y):
1273 | return translate(x, y, 0)(weight_shape())
1274 |
1275 |
1276 | def bottom_weight_cutouts():
1277 | shapes = []
1278 |
1279 | base_point = point_on_grid(0, num_cols - 1, 0, 0, 0)
1280 | base_x = base_point[0] - 9
1281 | base_y = base_point[1] - 4
1282 |
1283 | space_between = 1
1284 | offsets = space_between + weight_width
1285 | offsets_y = space_between + weight_height
1286 |
1287 | r3_y = base_y - 2 * offsets_y
1288 |
1289 | topr = base_y + offsets_y
1290 |
1291 | for x in range(2):
1292 | shapes.append(place_weight_hole(1 + base_x - offsets * x, base_y))
1293 | for x in range(3, 4):
1294 | shapes.append(place_weight_hole(base_x - offsets * x + 2, base_y))
1295 | for x in range(4, 5):
1296 | shapes.append(place_weight_hole(base_x - offsets * x - 8, base_y))
1297 |
1298 | for x in range(2, 5):
1299 | shapes.append(place_weight_hole(base_x - offsets * x - 4, base_y - offsets_y))
1300 |
1301 | for x in range(5):
1302 | shapes.append(place_weight_hole(base_x - offsets * x, base_y - 2 * offsets_y))
1303 |
1304 | shapes.append(place_weight_hole(base_x - offsets * 2, topr))
1305 | shapes.append(place_weight_hole(base_x - offsets * 3, topr))
1306 |
1307 | base_thumb_x = base_x - offsets * 4 + 5
1308 | base_thumb_y = base_y - offsets_y * 3 - weight_width + weight_height + 1
1309 |
1310 | angled_shape = rotate_z(107)(weight_shape())
1311 | shapes.append(
1312 | translate(base_thumb_x - offsets_y - 0.4, base_thumb_y - 9.5, 0)(angled_shape)
1313 | )
1314 | shapes.append(
1315 | translate(base_thumb_x - offsets_y + 16, base_thumb_y - 1, 0)(angled_shape)
1316 | )
1317 |
1318 | return union(*shapes)
1319 |
1320 |
1321 | reset_switch_body = place_reset_switch_shape(unplaced_reset_switch_body())
1322 | reset_switch_body_hole = place_reset_switch_shape(unplaced_reset_switch_body_hole())
1323 |
1324 |
1325 | def bottom_plate():
1326 | return difference(
1327 | union(
1328 | model_outline(),
1329 | # reset_switch_body,
1330 | # screw_insert_all_shapes(screw_insert_outer),
1331 | ),
1332 | union(
1333 | screw_insert_all_shapes(
1334 | cylinderr1r2(screw_head_radius, screw_head_radius, screw_head_height)
1335 | ),
1336 | screw_insert_all_shapes(
1337 | cylinderr1r2(screw_hole_radius, screw_hole_radius, bottom_height)
1338 | ),
1339 | # bottom_weight_cutouts(),
1340 | # reset_switch_body_hole,
1341 | ),
1342 | )
1343 |
1344 |
1345 | def left_bottom_plate():
1346 | return flip_lr()(bottom_plate())
1347 |
1348 |
1349 | def thumb_corner():
1350 | global should_include_risers
1351 | should_include_risers = False
1352 | return difference(
1353 | union(
1354 | thumb_switches(),
1355 | thumb_walls(),
1356 | thumb_connectors(),
1357 | # thumb_caps(),
1358 | thumb_to_body_connectors(),
1359 | ),
1360 | union(blocker(),),
1361 | )
1362 |
1363 |
1364 | def write_test():
1365 | render_to_file(right_shell(), "things/right.scad")
1366 | render_to_file(left_shell(), "things/left.scad")
1367 | render_to_file(bottom_plate(), "things/right_bottom_plate.scad")
1368 | render_to_file(left_bottom_plate(), "things/left_bottom_plate.scad")
1369 |
1370 |
1371 | def run():
1372 | write_test()
1373 | print("done")
1374 |
1375 |
1376 | if __name__ == "__main__":
1377 | run()
1378 |
--------------------------------------------------------------------------------