scad.sh generates all stls, sorts them, and generates web-optimized images

This commit is contained in:
Matt McWilliams 2025-02-02 20:05:25 -05:00
parent 8d641e5598
commit 6c223d0fc6
1 changed files with 9 additions and 6 deletions

15
scad.sh
View File

@ -6,17 +6,17 @@ NAME="${FILENAME%.*}"
THEME=DeepOcean THEME=DeepOcean
function generateStl () { function generateStl () {
echo openscad -enable manifold -D VERBOSE=false -D PART=\"${2}\" --export-format=asciistl -o "stl/${NAME}_${2}.stl" "${1}" openscad --enable manifold -D VERBOSE=false -D PART=\"${2}\" --export-format=asciistl -o "stl/${NAME}_${2}.stl" "${1}"
} }
function sortStl () { function sortStl () {
echo python3 scad/common/c14n_stl.py "stl/${NAME}_${1}.stl" python3 scad/common/c14n_stl.py "stl/${NAME}_${1}.stl"
} }
function generateJpeg () { function generateJpeg () {
echo openscad --enable manifold --viewall --render --imgsize=512,512 --colorscheme=${THEME} -o "img/${NAME}_${2}.png" "${1}" 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" 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" rm -f "img/${NAME}_${2}.png"
} }
function generateScad () { function generateScad () {
@ -27,16 +27,19 @@ function generateScad () {
function getParts () { function getParts () {
tmpFile=$(mktemp) tmpFile=$(mktemp)
cat "${SRC}" | grep "PART ==" | awk -F'==' '{print $2}' | awk -F'"' '{print $2}' | awk -F'"' '{print $1}' | sort > models.txt cat "${SRC}" | grep "PART ==" | awk -F'==' '{print $2}' | awk -F'"' '{print $2}' | awk -F'"' '{print $1}' | sort > "${tmpFile}"
echo "${tmpFile}" echo "${tmpFile}"
} }
if [[ -z "${2}" ]]; then if [[ -z "${2}" ]]; then
echo "Generate all parts in ${SRC}..."
partsList=$(getParts) partsList=$(getParts)
while read part; do while read part; do
echo "Generating ${part}..."
generateScad "${part}" generateScad "${part}"
done < "${partsList}" done < "${partsList}"
else else
echo "Generating ${2} in ${SRC}..."
generateScad "${2}" generateScad "${2}"
fi fi