#! /usr/bin/zsh if [ $# -ne 3 -o "$1" = "--help" ]; then echo echo 'Usage: virtualtex [--help| ]' echo else texturewidth=`/usr/bin/identify $1|cut -d " " -f 3|cut -d x -f 1` ((textureheight = texturewidth/2)) tilesize=$2 tileformat="$3" echo echo "Texture size = " $texturewidth "x" $textureheight "tilesize = " $tilesize echo "Number of tiles =" $(( texturewidth/tilesize * textureheight/tilesize )) echo "Image format of tiles:" $tileformat echo echo "Tile: " echo j=0 while (( j * tilesize < textureheight )); do ((offy = j * tilesize)) i=0 while (( i * tilesize < texturewidth )); do ((offx = i * tilesize)) echo "tx_"${i}"_"${j}": x-offset:" $offx "y-offset:" $offy /usr/bin/convert -crop ${tilesize}x${tilesize}+${offx}+${offy} $1 tx_${i}_${j}.$tileformat ((i++)) done ((j++)) done fi