-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmake_stls.sh
More file actions
executable file
·146 lines (122 loc) · 3.75 KB
/
make_stls.sh
File metadata and controls
executable file
·146 lines (122 loc) · 3.75 KB
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/bin/bash
{
# Exit on error
set -o errexit
set -o errtrace
# Constants
openscad="/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD"
timestamp=$(git log -n1 --date=unix --format="%ad" openscad)
commit_hash=$(git log -n1 --format="%h" openscad)
# Flags
bonk=
prefix="higher_lower"
dir="local/3d-models/$prefix-$timestamp-$commit_hash"
query=
# Internal variables
_found_matches=
function help() {
echo "\
Renders STL models.
Usage:
./make_stls.sh [-hectb] [-p PREFIX] [-d DIRECTORY] [-q COMMA,SEPARATED,QUERY]
Usage:
./make_stls.sh Export all STLs
./make_stls.sh -h Show this message and quit
./make_stls.sh -e Echo out output directory and quit
./make_stls.sh -c Echo out commit hash and quit
./make_stls.sh -t Echo out timestamp and quit
./make_stls.sh -b Bonk and open folder when done
./make_stls.sh -p <prefix> Set filename prefix
Default is 'oskitone-apc'
./make_stls.sh -d <directory> Set output directory
Default is local/3d-models/<prefix>...
./make_stls.sh -q <query> Export only STLs whose filename stubs match
comma-separated query
Examples:
./make_stls.sh -p test -q switch Exports test-...-switch_clutch.stl
./make_stls.sh -p wheels,enc Exports oskitone-apc-...-wheels.stl,
oskitone-apc-...-enclosure_bottom.stl,
and oskitone-apc-...-enclosure_top.stl
"
}
function export_stl() {
stub="$1"
override=$(echo "SHOW_${stub}" | tr '[a-z]' '[A-Z]')
y_rotation="${2:-0}"
function _run() {
filename="$dir/$prefix-$timestamp-$commit_hash-$stub.stl"
echo "Exporting $filename..."
# The "& \" at the end runs everything in parallel!
$openscad "openscad/higher_lower.scad" \
--quiet \
-o "$filename" \
--export-format "binstl" \
-D "SHOW_ENCLOSURE_BOTTOM=false " \
-D "SHOW_BATTERY_HOLDER=false " \
-D "SHOW_BATTERIES=false " \
-D "SHOW_PCB=false " \
-D "SHOW_SWITCH_CLUTCH=false " \
-D "SHOW_SPEAKER=false " \
-D "SHOW_ROCKER=false " \
-D "SHOW_ENCLOSURE_TOP=false " \
-D "SHOW_PRINT_TEST=false " \
-D "Y_ROTATION=$y_rotation " \
-D "$override=true" \
& \
}
if [[ -z "$query" ]]; then
_run
else
for query_iterm in "${query[@]}"; do
if [[ "$stub" == *"$query_iterm"* ]]; then
_found_matches=true
_run
fi
done
fi
}
function run() {
mkdir -pv $dir >/dev/null
echo "$dir"
echo
function finish() {
# Kill descendent processes
pkill -P "$$"
}
trap finish EXIT
start=`date +%s`
export_stl enclosure_bottom
export_stl battery_holder
export_stl switch_clutch 90
export_stl rocker
export_stl enclosure_top 180
export_stl print_test 180
wait
end=`date +%s`
runtime=$((end-start))
if [[ "$query" && -z $_found_matches ]]; then
echo "Found no matches for query '$query'"
else
if [[ $bonk ]]; then
printf "\a"
open $dir
fi
fi
echo
echo "Finished in $runtime seconds"
}
while getopts "h?b?p:d:e?c?t?q:" opt; do
case "$opt" in
h) help; exit ;;
b) bonk=true ;;
p) prefix="$OPTARG" ;;
d) dir="$OPTARG" ;;
e) echo "$dir"; exit ;;
c) echo "$commit_hash"; exit ;;
t) echo "$timestamp"; exit ;;
q) IFS="," read -r -a query <<< "$OPTARG" ;;
*) help; exit ;;
esac
done
run "${query[@]}"
}