#!/usr/local/bin/perl
# N.B. Change the above path if your site keeps perl someplace different!

# frankenrender renderer script
#
# This script drives the hybrid renderer that results when using
# the "ray server" -- the scheme where PRMan uses BMRT to return ray
# tracing results.  The rayserver DSO will launch BMRT using the
# environment variable RAYSERVER.  The purpose of this script is mainly
# to set that variable correctly.
#
# Usage: frankenrender file1 file2 ...
#        frankenrender [commonfiles] [-bmrt bmrtfiles] [-prman prmanfiles]
#
# For the first usage above, this script will set up RAYSERVER and call
# prman so that both renderers see exactly the same geometry and scene.
#
# If you want each renderer to see a different scene, then the second
# usage is preferred.  Using the -bmrt or -prman flag designates 
# subsequent files as applying to only one renderer or the other.
# File names that appear prior to either -bmrt or -prman will be sent
# to both renderers.
#
# Author:  Larry Gritz (gritzl@acm.org)
#

$forbmrt = 1;
$forprman = 1;
$bmrtargs = "";
$prmanargs = "";

$servercmd = "rendrib -rayserver ";

for ($i = 0;  $i <= $#ARGV;  $i = $i + 1) {
    if ($ARGV[$i] eq "-rayserver") {
	$i = $i + 1;
	$servercmd = $ARGV[$i];
	next;
    } elsif ($ARGV[$i] eq "-bmrt") {
	$forbmrt = 1;
	$forprman = 0;
	next;
    } elsif ($ARGV[$i] eq "-prman") {
	$forbmrt = 0;
	$forprman = 1;
	next;
    }
    if ($forprman) {
	$prmanargs = "$prmanargs $ARGV[$i] ";
    }
    if ($forbmrt) {
	$bmrtargs = "$bmrtargs $ARGV[$i] ";
    }
}

# print "prmanargs: $prmanargs \nbmrtargs: $bmrtargs\n";

$ENV{RAYSERVER} = "$servercmd $bmrtargs";

#print "RAYSERVER = \"$ENV{RAYSERVER}\"\n";
`prman $prmanargs`;

