bin/ltview.pl
changeset 38 a21b69f32c77
child 44 c8df2d579470
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/ltview.pl	Sun Dec 01 23:16:26 2013 +0000
@@ -0,0 +1,129 @@
+#!/usr/bin/perl
+#
+# Make a nice view of an object
+# Arguments are scene input files
+#
+# This is a re-write of Greg's original objview.csh.
+# The only extra functionality is that we accept a scene on STDIN
+# if no file name is given.
+#
+# Axel, Nov 2013
+
+use strict;
+use warnings;
+use File::Temp qw/ tempdir /;
+
+#my $td = tempdir( CLEANUP => 1 );
+my $td = "tmp";
+my $octree = "$td/ov$$.oct";
+my $room = "$td/rm$$.rad";
+my $rif = "$td/ov$$.rif";
+my $ambf = "$td/af$$.amb";
+my $raddev = "x11";   # default output device. Overwrite with -o
+my $up = "Z";
+my $vw = "XYZ";
+my $rsize = 1;    # room size in metres
+
+my $opts = "";        # Options common to rad and glrad
+my $rendopts = "-ab 1 -ds .15";    # For render= line in rif file
+my $usegl = 0;        # Run glrad instead of rad (Boolean).
+my $radopt = 0;       # An option specific to rad was passed (Boolean).
+my $glradopt = 0;     # An option specific to glrad was passed (Boolean).
+
+while (@ARGV) {
+	$_ = $ARGV[0];
+	if (m/-g/) {   # OpenGL output
+		if ( $^O =~ /MSWin32/ ) {
+			die("OpenGL view is not available under Windows.\n");
+		}
+		$usegl = 1;
+	} elsif (m/-u/) {   # up direction
+		$up = $ARGV[1];
+		shift @ARGV;
+	} elsif ((m/-s/) or (m/-w/)) {   # silent, no warnings
+		$opts .= " $_";
+	} elsif (m/-b/) {   # back face visibility
+		$rendopts .= ' -bv';
+	} elsif (m/-v/) {   # standard view "[Xx]?[Yy]?[Zz]?[vlcahs]?"
+		# Let rad do any error handling...
+		$vw = $ARGV[1];
+		shift @ARGV;
+	} elsif (m/-N/) {   # No. of parallel processes
+		$opts .= ' -N ' . $ARGV[1];
+		$radopt = 1;
+		shift @ARGV;
+	} elsif (m/-o/) {   # output device (rvu -devices)
+		$raddev = $ARGV[1];
+		$radopt = 1;
+		shift @ARGV;
+	} elsif ((m/-V/) or (m/-e/)) {   # print view, explicate variables
+		# Think of those two as '-verbose'.
+		$opts .= " $_";
+		$radopt = 1;
+	} elsif (m/-S/) {   # full-screen stereo
+		$opts .= " $_";
+		$glradopt = 1;
+	} elsif (m/-r/) {    # room size
+		$rsize = $ARGV[1];
+		shift @ARGV;
+	} elsif (m/^-\w/) {
+		die("objview: Bad option: $_\n");
+	} else {
+		last;
+	}
+	shift @ARGV;
+}
+
+# We need one IES file
+if (! $#ARGV == 0) {
+	die("ltview: Need one IES photometry file\n");
+}
+my $scene = $ARGV[0];
+
+# Make sure we don't confuse glrad and rad options.
+if ($usegl) {
+	if ($radopt) {
+		die("objview: glrad output requested, but rad option passed.\n");
+	}
+} else {
+	if ($glradopt) {
+		die("objview: rad output requested, but glrad option passed.\n");
+	}
+}
+
+open(FH, ">$room") or
+		die("ltview: Can't write to temporary file $room\n");
+print FH <<EndOfRoom;
+void plastic surf  0  0  5  .2 .2 .2 0 0
+!genbox -i surf room $rsize $rsize $rsize |xform -t -$rsize/2 -$rsize/2 -$rsize/2
+EndOfRoom
+close(FH);
+
+# Make this work under Windoze
+if ( $^O =~ /MSWin32/ ) {
+	$scene =~ s{\\}{/}g;
+	$octree =~ s{\\}{/}g;
+	$raddev = "qt";
+}
+
+open(FH, ">$rif") or
+		die("objview: Can't write to temporary file $rif\n");
+print FH <<EndOfRif;
+scene= $scene
+EXPOSURE= .5
+UP= $up
+view= $vw
+OCTREE= $octree
+oconv= -f
+AMBF= $ambf
+render= $rendopts
+EndOfRif
+close(FH);
+
+if ($usegl) {
+	system "glrad $opts $rif";
+} else {
+	system "rad -o $raddev $opts $rif";
+}
+
+#EOF