-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
50 lines (45 loc) · 1.73 KB
/
main.py
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
from build123d import *
import argparse
import os
import yaml
from tqdm import tqdm
from key import KeyConfig, Key
from stem import stem_from_config
parser = argparse.ArgumentParser(
"Custom Keycap Generator",
"Generate custom print-ready keycap geometries",
"Work in progress. Contributions welcome."
)
parser.add_argument('style')
parser.add_argument('layout')
parser.add_argument('-o', '--output-path', default="output")
parser.add_argument('-f', '--format', default='stl', choices=['stl', 'brep', 'step', '3mf'])
if __name__ == '__main__':
args = parser.parse_args()
with open(f"configs/styles/{args.style}.yaml") as f:
style = yaml.safe_load(f.read())
with open(f"configs/layouts/{args.layout}.yaml") as f:
layout = yaml.safe_load(f)
print(f"Generating {len(layout['keys'])} keys...")
for key_name, key_conf in tqdm(layout['keys'].items()):
base = key_conf.pop('base', '')
modifiers = key_conf.pop('modifiers', [])
config = (
style['global'] |
style['bases'].get(base, {}) |
key_conf
)
for mod in modifiers:
config = config | style['modifiers'][mod]
stem = stem_from_config(**config.pop('stem', {}))
key_config = KeyConfig(**config)
key = Key(key_config, stem)
out_path = os.path.join(args.output_path, f"{key_name}.{args.format}")
if args.format == 'stl':
key.shape().export_stl(out_path)
elif args.format == 'brep':
key.shape().export_brep(out_path)
elif args.format == 'step':
key.shape().export_step(out_path)
elif args.format == '3mf':
key.shape().export_3mf(out_path, 1e-3, 0.1, Unit.MILLIMETER)