| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Create character spritesheet and join all the rendered images |
| 4 | # Requires blender and imagemagick |
| 5 | # |
| 6 | set -e |
| 7 | SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) |
| 8 | if [ "$#" -ne 1 ]; then |
| 9 | echo "Usage: make_spritesheet.sh body" |
| 10 | exit 1 |
| 11 | fi |
| 12 | |
| 13 | if [[ "$OSTYPE" == "linux-gnu" ]]; then |
| 14 | BLENDER=blender |
| 15 | elif [[ "$OSTYPE" == "msys" ]]; then |
| 16 | BLENDER="/c/Program Files/Blender Foundation/Blender 4.4/blender.exe" |
| 17 | else |
| 18 | # macOS |
| 19 | BLENDER=/Applications/blender.app/Contents/MacOS/blender |
| 20 | fi |
| 21 | if [[ "$OSTYPE" == "msys" ]]; then |
| 22 | BLENDER_OUT="C:/out" |
| 23 | else |
| 24 | BLENDER_OUT="out" |
| 25 | fi |
| 26 | |
| 27 | INFILE=$1/src.blend |
| 28 | # Render separate body parts (in collections) |
| 29 | parts=(legs upper) |
| 30 | # Render separate actions |
| 31 | actions_legs=(idle run) |
| 32 | actions_upper=(idle run idle_handgun run_handgun idle_dualgun run_dualgun idle_rifle run_rifle idle_riflefire run_riflefire) |
| 33 | idle_frames=1 |
| 34 | run_frames=80 |
| 35 | len_i=${#parts[*]} |
| 36 | for (( i=0; i<len_i; i++ )) |
| 37 | do |
| 38 | part=${parts[$i]} |
| 39 | collections=base |
| 40 | if [[ $part == *"legs"* ]] |
| 41 | then |
| 42 | actions=${actions_legs[@]} |
| 43 | collections=$collections,legs |
| 44 | else |
| 45 | actions=${actions_upper[@]} |
| 46 | collections=$collections,upper |
| 47 | fi |
| 48 | for action in $actions |
| 49 | do |
| 50 | rm -rf out |
| 51 | if [[ $action == *"run"* ]] |
| 52 | then |
| 53 | frames=$run_frames |
| 54 | else |
| 55 | frames=$idle_frames |
| 56 | fi |
| 57 | # Include right hand collection if the part is "upper" and action doesn't have guns |
| 58 | if [[ $part == *"upper"* ]] && [[ $action != *"handgun"* ]] && [[ $action != *"dualgun"* ]] && [[ $action != *"rifle"* ]] |
| 59 | then |
| 60 | collections=$collections,hand_right |
| 61 | fi |
| 62 | "$BLENDER" -noaudio -b "$INFILE" -P ${SCRIPT_DIR}/render.py -- "$collections" "$action" "$frames" "$part" |
| 63 | |
| 64 | DIMENSIONS=`identify -format "%wx%h" "${BLENDER_OUT}/${part}_${action}_0_00.png"` |
| 65 | OUTFILE=$1/${part}_${action}_${DIMENSIONS}.png |
| 66 | rm -f "$OUTFILE" |
| 67 | montage -geometry +0+0 -background none -tile x8 "${BLENDER_OUT}/${part}_${action}_*.png" -channel A tmpimage |
| 68 | magick convert tmpimage -dither None -colors 32 -level 25%,60% "$OUTFILE" |
| 69 | rm tmpimage |
| 70 | chmod 644 "$OUTFILE" |
| 71 | echo "Created $OUTFILE" |
| 72 | done |
| 73 | done |
| 74 | |
| 75 | rm -rf out/ |