3 # This script generates normalmaps using The GIMP to do the heavy lifting.
4 # give any unrecognized switch (say, -h) for usage info.
6 rm /tmp/normals_filelist.txt
24 while test -n "$1"; do
27 if [ -z "$2" ] ; then echo "Missing scale parameter"; exit 1; fi
33 if [ -z "$2" ] ; then echo "Missing pattern parameter"; exit 1; fi
43 if [[ $2 =~ ^[0-9]+$ ]]; then
51 if [ -z "$2" ] ; then echo "Missing filter parameter"; exit 1; fi
91 if [ -z "$2" ] ; then echo "Missing conversion parameter"; exit 1; fi
147 echo "`basename $0` [--scale|-s <value>] [--filter|-f <string>]"
148 echo " [--wrap|-w] [--heightalpha|-a] [--invertx|-x] [--inverty|-y]"
149 echo " [--conversion|-c <string>] [--skiptools|-t] [--skipinventory|-i [<value>]]"
150 echo " [--dryrun|-d] [--pattern|-p <pattern>]"
151 echo -e "\nDefaults to a scale of 8, checking all files in the current directory, and not"
152 echo "skipping apparent tools or inventory images. Filter, if specified, may be one"
153 echo "of: sobel3, sobel5, prewitt3, prewitt5, 3x3, 5x5, 7x7, or 9x9, or a value 1"
154 echo "through 8 (1=sobel3, 2=sobel5, etc.). Defaults to 0 (four-sample). The height"
155 echo "source is taken from the image's alpha channel if heightalpha is specified.\n"
157 echo "If inventory skip is specified, an optional resolution may also be included"
158 echo "(default is 64). Conversion can be one of: biased, red, green, blue, maxrgb,"
159 echo "minrgb, colorspace, normalize-only, heightmap or a value from 1 to 9"
160 echo "corresponding respectively to those keywords. Defaults to 0 (simple"
161 echo "normalize) if not specified. Wrap, if specified, enables wrapping of the"
162 echo "normalmap around the edges of the texture (defaults to no). Invert X/Y"
163 echo "reverses the calculated gradients for the X and/or Y dimensions represented"
164 echo "by the normalmap (both default to non-inverted)."
166 echo "The pattern, can be an escaped pattern string such as \*apple\* or"
167 echo "default_\*.png or similar (defaults to all PNG and JPG images in the current"
168 echo "directory that do not contain \"_normal\" or \"_specular\" in their filenames)."
170 echo "If set for dry-run, the actions this script will take will be printed, but no"
171 echo "images will be generated. Passing an invalid value to a switch will generally"
172 echo "cause that switch to revert to its default value."
179 echo -e "\nProcessing files based on pattern \"$pattern\" ..."
183 out=`echo "$1" | sed 's/.png/_normal.png/' | sed 's/.jpg/_normal.png/'`
185 echo "Launched process to generate normalmap: \"$1\" --> \"$out\"" >&2
189 (normalMap-fbx-conversion fileName newFileName filter nscale wrap heightsource conversion invertx inverty)
192 (image (car (gimp-file-load RUN-NONINTERACTIVE fileName fileName)))
193 (drawable (car (gimp-image-get-active-layer image)))
194 (drawable (car (gimp-image-flatten image)))
196 (if (> (car (gimp-drawable-type drawable)) 1)
197 (gimp-convert-rgb image) ()
217 (gimp-file-save RUN-NONINTERACTIVE image drawable newFileName newFileName)
218 (gimp-image-delete image)
221 (normalMap-fbx-conversion \"$1\" \"$out\" $2 $3 $4 $5 $6 $7 $8)" -b '(gimp-quit 0)'
226 for file in `ls $pattern |grep -v "_normal.png"|grep -v "_specular"` ; do
228 invtest=`file "$file" |grep "$invresolution x $invresolution"`
229 if $skipinventory && [ -n "$invtest" ] ; then
230 echo "Skipped presumed "$invresolution"px inventory image: $file" >&2
234 tooltest=`echo "$file" \
236 | grep -v "_shovel" \
243 if $skiptools && [ -z "$tooltest" ] ; then
244 echo "Skipped presumed tool image: $file" >&2
249 echo "Would have generated a normalmap for $file" >&2
252 echo \"$file\" $filter $scale $wrap $heightsource $conversion $invertx $inverty
254 done | xargs -P $numprocs -n 8 -I{} bash -c normalMap\ \{\}\ \{\}\ \{\}\ \{\}\ \{\}\ \{\}\ \{\}\ \{\}