#!/bin/bash

### IMPORTANT ###
# This must be set to the absolute path of the educelab/sample-mounts directory
#################
UTILS_DIR="/Users/stephen/src/sample-mounts"

outputPrefix="PHercBod25"
version="1a"

liningPath="/Users/stephen/data/Herculaneum_Scrolls/Bodleian Scrolls/3D/202405 - Diamond scan cases/Scroll 25/7 - Lining/20240515174439_Bod-Scroll25-full+mask_lining.stl"
liningWallPath="/Users/stephen/data/Herculaneum_Scrolls/Bodleian Scrolls/3D/202405 - Diamond scan cases/Scroll 25/7 - Lining/20240515174439_Bod-Scroll25-full+mask_liningwall.stl"

previewLiningWall=false
previewModel=false

scrollHeight=163.89
liningDiameter=67
modelRotate='[0,0,107]'
modelTranslate='[0,0,85]'
liningOffset=3
wallThickness=2

generateOuterCylinder=true
honeycomb=true;
honeycombHoleEdges=6
honeycombNumCols=12
honeycombSpacing=1.5

alignmentNubs='[[-35,10],[-35,95],[-35,180],[35,10],[35,95],[35,180]]'
alignmentNubSize=3
alignmentNubDepth=1.5
alignmentNubMargin=0.5

overhangRemoval=true
overhangStepSize=0.5

escapeHoles=false
escapeOffset=1.5
escapeDiameter=4
escapeAngle=15

labelLine1="PHerc. Bod. 25"
labelLine2="V${version}"
labelLineHeight=3
labelDepth=0.5

markerRings=true

bottomBuffer=5
topBuffer=5
internalGap=3

(echo $(date) ":: Rendering left side..."
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD \
    -o "${outputPrefix}-v${version}-L.stl" \
    -D "side=\"l\"" \
    -D "lining=\"${liningPath}\"" \
    -D "liningWall=\"${liningWallPath}\"" \
    -D "previewLiningWall=${previewLiningWall}" \
    -D "previewModel=${previewModel}" \
    -D scrollHeight=${scrollHeight} \
    -D liningDiameter=${liningDiameter} \
    -D "modelRotate=${modelRotate}" \
    -D "modelTranslate=${modelTranslate}" \
    -D liningOffset=${liningOffset} \
    -D wallThickness=${wallThickness} \
    -D generateOuterCylinder=${generateOuterCylinder} \
    -D honeycomb=${honeycomb} \
    -D honeycombHoleEdges=${honeycombHoleEdges} \
    -D honeycombNumCols=${honeycombNumCols} \
    -D honeycombSpacing=${honeycombSpacing} \
    -D "alignmentNubs=${alignmentNubs}" \
    -D alignmentNubSize=${alignmentNubSize} \
    -D alignmentNubDepth=${alignmentNubDepth} \
    -D alignmentNubMargin=${alignmentNubMargin} \
    -D overhangRemoval=${overhangRemoval} \
    -D overhangStepSize=${overhangStepSize} \
    -D escapeHoles=${escapeHoles} \
    -D escapeOffset=${escapeOffset} \
    -D escapeDiameter=${escapeDiameter} \
    -D escapeAngle=${escapeAngle} \
    -D "labelLine1=\"${labelLine1}\"" \
    -D "labelLine2=\"${labelLine2}\"" \
    -D labelLineHeight=${labelLineHeight} \
    -D labelDepth=${labelDepth} \
    -D "markerRings=${markerRings}" \
    -D bottomBuffer=${bottomBuffer} \
    -D topBuffer=${topBuffer} \
    -D internalGap=${internalGap} \
    "${UTILS_DIR}/OpenSCAD/Scroll Case Generator.scad" && \
echo $(date) ":: Left side rendered."
echo)

(echo $(date) ":: Rendering right side..."
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD \
    -o "${outputPrefix}-v${version}-R.stl" \
    -D "side=\"r\"" \
    -D "lining=\"${liningPath}\"" \
    -D "liningWall=\"${liningWallPath}\"" \
    -D "previewLiningWall=${previewLiningWall}" \
    -D "previewModel=${previewModel}" \
    -D scrollHeight=${scrollHeight} \
    -D liningDiameter=${liningDiameter} \
    -D "modelRotate=${modelRotate}" \
    -D "modelTranslate=${modelTranslate}" \
    -D liningOffset=${liningOffset} \
    -D wallThickness=${wallThickness} \
    -D generateOuterCylinder=${generateOuterCylinder} \
    -D honeycomb=${honeycomb} \
    -D honeycombHoleEdges=${honeycombHoleEdges} \
    -D honeycombNumCols=${honeycombNumCols} \
    -D honeycombSpacing=${honeycombSpacing} \
    -D "alignmentNubs=${alignmentNubs}" \
    -D alignmentNubSize=${alignmentNubSize} \
    -D alignmentNubDepth=${alignmentNubDepth} \
    -D alignmentNubMargin=${alignmentNubMargin} \
    -D overhangRemoval=${overhangRemoval} \
    -D overhangStepSize=${overhangStepSize} \
    -D escapeHoles=${escapeHoles} \
    -D escapeOffset=${escapeOffset} \
    -D escapeDiameter=${escapeDiameter} \
    -D escapeAngle=${escapeAngle} \
    -D "labelLine1=\"${labelLine1}\"" \
    -D "labelLine2=\"${labelLine2}\"" \
    -D labelLineHeight=${labelLineHeight} \
    -D labelDepth=${labelDepth} \
    -D "markerRings=${markerRings}" \
    -D bottomBuffer=${bottomBuffer} \
    -D topBuffer=${topBuffer} \
    -D internalGap=${internalGap} \
    "${UTILS_DIR}/OpenSCAD/Scroll Case Generator.scad" && \
echo $(date) ":: Right side rendered."
echo)

(echo $(date) ":: Rendering stand..."
/Applications/OpenSCAD.app/Contents/MacOS/OpenSCAD \
    -o "${outputPrefix}-v${version}-Stand.stl" \
    -D "side=\"s\"" \
    -D "lining=\"${liningPath}\"" \
    -D "liningWall=\"${liningWallPath}\"" \
    -D "previewLiningWall=${previewLiningWall}" \
    -D "previewModel=${previewModel}" \
    -D scrollHeight=${scrollHeight} \
    -D liningDiameter=${liningDiameter} \
    -D "modelRotate=${modelRotate}" \
    -D "modelTranslate=${modelTranslate}" \
    -D liningOffset=${liningOffset} \
    -D wallThickness=${wallThickness} \
    -D generateOuterCylinder=${generateOuterCylinder} \
    -D honeycomb=${honeycomb} \
    -D honeycombHoleEdges=${honeycombHoleEdges} \
    -D honeycombNumCols=${honeycombNumCols} \
    -D honeycombSpacing=${honeycombSpacing} \
    -D "alignmentNubs=${alignmentNubs}" \
    -D alignmentNubSize=${alignmentNubSize} \
    -D alignmentNubDepth=${alignmentNubDepth} \
    -D alignmentNubMargin=${alignmentNubMargin} \
    -D overhangRemoval=${overhangRemoval} \
    -D overhangStepSize=${overhangStepSize} \
    -D escapeHoles=${escapeHoles} \
    -D escapeOffset=${escapeOffset} \
    -D escapeDiameter=${escapeDiameter} \
    -D escapeAngle=${escapeAngle} \
    -D "labelLine1=\"${labelLine1}\"" \
    -D "labelLine2=\"${labelLine2}\"" \
    -D labelLineHeight=${labelLineHeight} \
    -D labelDepth=${labelDepth} \
    -D "markerRings=${markerRings}" \
    -D bottomBuffer=${bottomBuffer} \
    -D topBuffer=${topBuffer} \
    -D internalGap=${internalGap} \
    "${UTILS_DIR}/OpenSCAD/Scroll Case Generator.scad" && \
echo $(date) ":: Stand rendered."
echo)
