#! /usr/bin/zsh if [ $# -lt 3 -o "$1" = "--help" ]; then echo echo 'Usage: virtualtex [--help | ] [e|E|w|W]' 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 The optional 4th argument e\|E\|w\|W is for the case of tiling echo square /e/astern \| /w/estern halfes of the full texture separately! 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.02, 08/16/03 echo else texturesize=`identify $1|cut -d " " -f 3` texturewidth=`echo $texturesize|cut -d x -f 1` textureheight=`echo $texturesize|cut -d x -f 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)) if [ $# -eq 4 ]; then if [ "$4" = "e" -o "$4" = "E" ]; then ioff=$(( texturewidth/tilesize )) elif [ "$4" = "w" -o "$4" = "W" ]; then ioff=0 else echo echo "*** Incorrect 4th parameter! ***" echo return fi fi i=0 while (( i * tilesize + tilesize <= texturewidth )); do ((offx = i * tilesize)) echo "tx_"$((i + ioff))"_"${j}": x-offset:" $((offx + ioff * tilesize)) "y-offset:" $offy convert -crop ${tilesize}x${tilesize}+${offx}+${offy} $1 tx_$((i + ioff))_${j}.$tileformat ((i++)) done ((j++)) done fi