| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Create head spritesheet and join all the rendered images |
| 4 | # |
| 5 | if [ "$#" -ne 1 ]; then |
| 6 | echo "Usage: make_spritesheet.sh head" |
| 7 | exit 1 |
| 8 | fi |
| 9 | |
| 10 | # TODO: linux path |
| 11 | BLENDER=/Applications/blender.app/Contents/MacOS/blender |
| 12 | INFILE=$1.blend |
| 13 | # TODO: layers |
| 14 | parts=(head) |
| 15 | # Render separate actions |
| 16 | actions=(idle firing) |
| 17 | idle_frames=1 |
| 18 | firing_frames=1 |
| 19 | len_i=${#parts[*]} |
| 20 | for (( i=0; i<len_i; i++ )) |
| 21 | do |
| 22 | part=${parts[$i]} |
| 23 | for action in ${actions[@]} |
| 24 | do |
| 25 | if [[ $action == *"firing"* ]] |
| 26 | then |
| 27 | frames=$firing_frames |
| 28 | else |
| 29 | frames=$idle_frames |
| 30 | fi |
| 31 | layers=$i |
| 32 | "$BLENDER" -b "$INFILE" -P render.py -- "$layers" "$action" "$frames" "$part" |
| 33 | for (( j=0; j<8; j++ )) |
| 34 | do |
| 35 | # Face not looking down needs to be shifted down a pixel |
| 36 | if [ "$j" -ge 3 -a "$j" -le 5 ] |
| 37 | then |
| 38 | : |
| 39 | else |
| 40 | convert "out/${part}_${action}_${j}_00.png" -page +0+1 -background none -flatten tmpimage |
| 41 | mv tmpimage "out/${part}_${action}_${j}_00.png" |
| 42 | fi |
| 43 | done |
| 44 | |
| 45 | DIMENSIONS=`identify -format "%wx%h" "out/${part}_${action}_0_00.png"` |
| 46 | done |
| 47 | OUTFILE=$1_${DIMENSIONS}.png |
| 48 | rm "$OUTFILE" |
| 49 | montage -geometry +0+0 -background none -tile 8x "out/${part}_idle_*.png" "out/${part}_firing_*.png" -channel A tmpimage |
| 50 | convert tmpimage -dither None -colors 32 -level 25%,60% "$OUTFILE" |
| 51 | rm tmpimage |
| 52 | chmod 644 "$OUTFILE" |
| 53 | echo "Created $OUTFILE" |
| 54 | done |
| 55 | |
| 56 | rm -rf out/ |