Add test version of the scad script

This commit is contained in:
Matt McWilliams 2025-02-02 19:51:24 -05:00
parent 53f4dd4a2d
commit 7660f4605f
1 changed files with 42 additions and 0 deletions

42
scad.sh Normal file
View File

@ -0,0 +1,42 @@
#!/bin/bash
SRC="${1}"
FILENAME=$(basename "${1}")
NAME="${FILENAME%.*}"
THEME=DeepOcean
function generateStl () {
echo openscad -enable manifold -D VERBOSE=false -D PART=\"${2}\" --export-format=asciistl -o "stl/${NAME}_${2}.stl" "${1}"
}
function sortStl () {
echo python3 scad/common/c14n_stl.py "stl/${NAME}_${1}.stl"
}
function generateJpeg () {
echo openscad --enable manifold --viewall --render --imgsize=512,512 --colorscheme=${THEME} -o "img/${NAME}_${2}.png" "${1}"
echo convert "img/${NAME}_${2}.png" -sampling-factor 4:2:0 -strip -quality 85 -interlace JPEG -colorspace RGB "img/${NAME}_${2}.jpg"
echo rm -f "img/${NAME}_${2}.png"
}
function generateScad () {
generateStl "${SRC}" "${1}"
sortStl "${1}"
generateJpeg "${SRC}" "${1}"
}
function getParts () {
tmpFile=$(mktemp)
cat "${SRC}" | grep "PART ==" | awk -F'==' '{print $2}' | awk -F'"' '{print $2}' | awk -F'"' '{print $1}' | sort > models.txt
echo "${tmpFile}"
}
if [[ -z "${2}" ]]; then
partsList=$(getParts)
while read part; do
generateScad "${part}"
done < "${partsList}"
else
generateScad "${2}"
fi