#! /bin/csh -f

#*+***********************************************************************
#*
#*  Module:
#*	mental ray 3.4
#*
#*  Copyright (c) 2001-2002 by Alias|Wavefront, Inc., and Alias|Wavefront,
#*  a division of Silicon Graphics Canada Ltd.  All rights reserved.
#*
#*  This file allows the standalone mental ray renderer, to render 
#*  .mi files that have been exported from Maya.
#*
#*-***********************************************************************


#
# Figure out where the mental ray standalone lives.  By
# default, we'll use the install location.  Users can override
# this behaviour by setting the MI_ROOT environment variable.
#

if( ! $?MI_ROOT ) then
	setenv MI_ROOT /usr/autodesk/mi3651
endif

#
# Use the ray executable from the standalone installation
#

setenv MI_RAY_SERVICE mayaray3651
setenv RAY ${MI_ROOT}/bin/ray


#
# check for no arguments
#

if ( $#argv < 1 ) then
	echo
	echo "* Not enough arguments"
	echo
	echo "Usage: mentalrayrender [options] scene.mi"
	echo
	echo "       Renders a mental ray .mi file using the mental ray"
	echo "       standalone renderer.  [options] can be any valid"
	echo "       mental ray renderer options."
	echo
	echo "       Options can also be specified in a RAYFLAGS environment variable."
	echo "       For example: setenv RAYFLAGS "\""-x on -v on"\"""
	echo
	echo "       Type "\"mentalrayrender -h\"" for a full list of available options."
	echo
	exit
endif

#
# check for SPM_HOST not set
#

if !($?SPM_HOST) then 
	echo
	echo "Error: SPM_HOST environment variable is not set. Please"
	echo "       set it to point to the name of your license server."
	echo
	echo "       For example:"
	echo 
	echo "       setenv SPM_HOST licenseServerMachine"
	echo
	exit
endif

#
# check for $RAY not set
#

if !( -x $RAY) then
	echo
	echo "Error: RAY executable $RAY not found"
	echo "       (or has no execute permissions)."
	echo
	echo "       Please ensure that the MI_ROOT environment variable"
	echo "       is set to point to your mental ray 3.4 standalone"
	echo "       installation."
	echo 
	exit

endif

#
# set up the basic library flags
#

set libFlags = "-L ${MI_ROOT}/lib -I ${MI_ROOT}/include"

if ($?RAYFLAGS) then
	echo
	echo Environment variable RAYFLAGS was found to be set to: $RAYFLAGS
endif

#
# build the render command
#

if ($?RAYFLAGS) then
	set raycommand = "$RAY $RAYFLAGS $libFlags $*"
else
	set raycommand = "$RAY $libFlags $*"
endif

echo
echo Starting render...
echo command: $raycommand 
echo

#
# invoke the render command
#

$raycommand

echo
echo Rendering complete.
echo


