#! /usr/bin/zsh if [ $# -ne 3 -o "$1" = "--help" ]; then echo echo 'Usage: virtualtex [--help | ]' echo echo echo The shell script \'virtualtex\' is a tool for Celestia \> 1.3.0 echo that supports \'virtual textures\'. echo echo The script generates the required tiles tx_i_j of \ desired \(square\) size, echo \, in a specified format, \ = \ png, tga, jpg,..., echo from an input texture, \, in any popular graphics format. echo echo Besides Linux/Unix, the script also runs in a current Cygwin \ installation echo under Windows, \( http://www.cygwin.com \). If the z-shell \(\'zsh\'\) \ is unavailable, echo it also may be executed with the \'bash\' shell, by replacing \ \#\! /usr/bin/zsh by echo \#\! /bin/bash in the first line. echo echo The script assumes that a recent version of the ImageMagick package echo \( http://www.ImageMagick.org \) is installed \ \(either under Unix/Linux or Windows\). echo The utilities \'convert\' and \'identify\' of that package are used. echo echo Author: Dr. Fridger Schrempp, fridger.schrempp@desy.de echo Version: 1.01, 08/13/03 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 + tilesize <= textureheight )); do ((offy = j * tilesize)) i=0 while (( i * tilesize + 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