Created
January 26, 2014 13:35
-
-
Save pekkavaa/8632821 to your computer and use it in GitHub Desktop.
Some scripts for Doom sprite manipulation. They may or may not work correctly, only tested with Cygwin+Imagemagick
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# renames tiles given in dir $1 as frames given as list file $2 | |
tilelist=$(ls $1) | |
framelist=$(cat $2) | |
tiles=($tilelist) | |
frames=($framelist) | |
count=${#frames[@]} | |
for i in `seq 1 $count` | |
do | |
echo "copying $1/${tiles[$i-1]} ${frames[$i-1]}" | |
cp $1\/${tiles[$i-1]} ${frames[$i-1]} | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/sh | |
# generates ZDoom TEXTURES file with the given offset and size | |
# | |
# USAGE: | |
# ./sprite_offsets.sh "128, 128" "64, 64" sprite_name_list.txt > TEXTURES.something | |
size=$1 # of form "x, y" | |
offset=$2 # of form "x, y" | |
while read sprite; do | |
base=`basename "$sprite" .png` | |
read -r -d '' def <<EOF | |
sprite $base, $size | |
{ | |
Offset $offset | |
Patch $base, 0, 0 | |
{ | |
} | |
} | |
EOF | |
echo "$def" | |
done < $3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Sprite Doom filenames should be in parameter 8, e.g. "spiderframes.txt" | |
# | |
# Example: | |
# $ ./tile2sprite.sh spiderspace_noface.png 128 100 64 70 out babyspiderframes.txt ../TEXTURES.spiderframe | |
# | |
# | |
# filename width height ofs_x ofs_y tempspritedir tempfile TEXTURES-file | |
#echo $1 "$2"x"$3" "$4","$5" "$6"/sprite_%03d.png tempfile: $7 $8 | |
tiles="$1" | |
width="$2" | |
height="$3" | |
ofs_x="$4" | |
ofs_y="$5" | |
spritedir="$6" | |
framenames="$7" | |
output="$8" | |
echo Splitting "$tiles" to separate frames | |
echo Size: "$width"x"$height" | |
echo Offset: "$ofs_x", "$ofs_y" | |
echo Temp sprite dir: "$spritedir" | |
echo Framenames: "$framenames" | |
echo Output: "$output" | |
basedir=$(pwd) | |
namedir="$spritedir"/named | |
tiledir="$spritedir"/tiles | |
mkdir "$spritedir" | |
mkdir "$namedir" | |
mkdir "$tiledir" | |
pushd "$spritedir" | |
rm *.png | |
rm *.txt | |
popd | |
convert $1 -crop "$width"x"$height" "$tiledir"/sprite_%03d.png | |
pushd "$namedir" | |
rm *.text | |
rm *.png # remove old images | |
echo Restoring frame names | |
"$basedir"/rename_tiles.sh "$basedir"/"$tiledir" "$basedir"/"$framenames" | |
popd | |
echo Creating TEXTURES file to "$output" | |
ls -1 "$namedir" | grep .png > "$spritedir"/names.txt | |
./sprite_offsets.sh "$width, $height" "$ofs_x, $ofs_y" "$spritedir"/names.txt > "$output" | |
echo Sprites can be found at "$namedir" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# joins multiple sprites into a big tilesheet | |
# tiletys.sh spritedir size(e.g 100x100) outputfile | |
montage `ls $1 -1 | grep png | tr "\\n" " "` -tile 8x8 -geometry "$2"\>+0+0 -background none "$3" | |
# splitting back to tiles | |
# convert tileset.png -crop 66x66 out/sprite_%03d.png | |
# then rename the tiles back to zdoom matching names with rename_tiles.sh |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment