#! /bin/csh -f -e
#
# Generates POVRAY rendering of scene $1.pov

if ( ( $#argv > 0 ) && ( "x$1" == "x-photo" ) ) then 
  set square = 0
  shift
else 
  set square = 1
endif
  
if ( ( $#argv > 0 ) && ( "x$1" == "x-quick" ) ) then 
  set rays = 1
  set qual = 4
  if ( $square ) then
    set width = 140
    set height = 140
  else
    set width = 100
    set height = 140
  endif
  shift
else if ( ( $#argv > 0 ) && ( "x$1" == "x-small" ) ) then 
  set rays = 3
  set qual = 9
  if ( $square ) then
    set width = 140
    set height = 140
  else
    set width = 100
    set height = 140
  endif
  shift
else if ( ( $#argv > 0 ) && ( "x$1" == "x-big" ) ) then 
  set rays = 3
  set qual = 9
  if ( $square ) then
    set width = 800
    set height = 800
  else
    set width = 560
    set height = 784
  endif
  shift
else
  set rays = 3
  set qual = 9
  if ( $square ) then
    set width = 400
    set height = 400
  else
    set width = 280
    set height = 392
  endif
endif
  
if ( $#argv != 1 ) then
  echo "usage: [-square] [ -quick | -big ] $0 scene.pov "
  exit 1
endif

set scene = "$1"
set scene = ${scene:r}

set d = `date +%y-%m-%d-%H%M%S`
echo "generating picture in directory $d"
mkdir $d
cp -p $0 $d
cp -p ${scene}.pov [a-zA-Z0-9]*.inc $d
cd $d

set povbin = "${HOME}/programs-by-others/CODE/raytrace-pov-TMP/SPARC"

nice \
  ${povbin}/povray \
    +A +FT +Q${qual} +R${rays} +H${height} +W${width} \
    +L${HOME}/PUB/povray \
    +I${scene}.pov \
    +O${scene}.tga \
  |& tee povray.log

if ( -e ${scene}.tga ) then
  cat ${scene}.tga \
    | tgatoppm \
    > ${scene}.ppm
  cat ${scene}.ppm \
    | pnmgamma 1.8 \
    | ppmquant -floyd -map standard-6x6x6-colormap.ppm \
    | ppmtogif > ${scene}.gif
  ln -s ${scene}.gif p.gif
  xv ${scene}.gif ${scene}.ppm &
  mv ${scene}.tga /tmp
endif
#
#
#
