| 1 |
greg |
2.1 |
#!/usr/bin/perl
|
| 2 |
greg |
2.2 |
# RCSid $Id: objview.pl,v 2.1 2013/12/04 20:07:07 greg Exp $
|
| 3 |
greg |
2.1 |
#
|
| 4 |
|
|
# Make a nice view of an object
|
| 5 |
|
|
# Arguments are scene input files
|
| 6 |
|
|
#
|
| 7 |
|
|
# This is a re-write of Greg's original objview.csh.
|
| 8 |
|
|
# The only extra functionality is that we accept a scene on STDIN
|
| 9 |
|
|
# if no file name is given.
|
| 10 |
|
|
#
|
| 11 |
|
|
# Axel, Nov 2013
|
| 12 |
|
|
|
| 13 |
|
|
use strict;
|
| 14 |
|
|
use warnings;
|
| 15 |
|
|
use File::Temp qw/ tempdir /;
|
| 16 |
|
|
|
| 17 |
|
|
my $td = tempdir( CLEANUP => 1 );
|
| 18 |
|
|
my $octree = "$td/ov$$.oct";
|
| 19 |
|
|
my $lights = "$td/lt$$.rad";
|
| 20 |
|
|
my $rif = "$td/ov$$.rif";
|
| 21 |
|
|
my $ambf = "$td/af$$.amb";
|
| 22 |
|
|
my $raddev = "x11"; # default output device. Overwrite with -o
|
| 23 |
|
|
my $up = "Z";
|
| 24 |
|
|
my $vw = "XYZ";
|
| 25 |
|
|
|
| 26 |
|
|
my $opts = ""; # Options common to rad and glrad
|
| 27 |
|
|
my $rendopts = ""; # For render= line in rif file
|
| 28 |
|
|
my $usegl = 0; # Run glrad instead of rad (Boolean).
|
| 29 |
|
|
my $radopt = 0; # An option specific to rad was passed (Boolean).
|
| 30 |
|
|
my $glradopt = 0; # An option specific to glrad was passed (Boolean).
|
| 31 |
|
|
|
| 32 |
|
|
while (@ARGV) {
|
| 33 |
|
|
$_ = $ARGV[0];
|
| 34 |
greg |
2.2 |
if (m/^-g\b/) { # OpenGL output
|
| 35 |
greg |
2.1 |
if ( $^O =~ /MSWin32/ ) {
|
| 36 |
|
|
die("OpenGL view is not available under Windows.\n");
|
| 37 |
|
|
}
|
| 38 |
|
|
$usegl = 1;
|
| 39 |
greg |
2.2 |
} elsif (m/^-u\b/) { # up direction
|
| 40 |
greg |
2.1 |
$up = $ARGV[1];
|
| 41 |
|
|
shift @ARGV;
|
| 42 |
greg |
2.2 |
} elsif ((m/^-s\b/) or (m/^-w/)) { # silent, no warnings
|
| 43 |
greg |
2.1 |
$opts .= " $_";
|
| 44 |
greg |
2.2 |
} elsif (m/^-b/) { # back face visibility
|
| 45 |
greg |
2.1 |
$rendopts .= ' -bv';
|
| 46 |
greg |
2.2 |
} elsif (m/^-v\b/) { # standard view "[Xx]?[Yy]?[Zz]?[vlcahs]?"
|
| 47 |
greg |
2.1 |
# Let rad do any error handling...
|
| 48 |
|
|
$vw = $ARGV[1];
|
| 49 |
|
|
shift @ARGV;
|
| 50 |
greg |
2.2 |
} elsif (m/^-N\b/) { # No. of parallel processes
|
| 51 |
greg |
2.1 |
$opts .= ' -N ' . $ARGV[1];
|
| 52 |
|
|
$radopt = 1;
|
| 53 |
|
|
shift @ARGV;
|
| 54 |
greg |
2.2 |
} elsif (m/^-o\b/) { # output device (rvu -devices)
|
| 55 |
greg |
2.1 |
$raddev = $ARGV[1];
|
| 56 |
|
|
$radopt = 1;
|
| 57 |
|
|
shift @ARGV;
|
| 58 |
greg |
2.2 |
} elsif ((m/^-V\b/) or (m/^-e\b/)) { # print view, explicate variables
|
| 59 |
greg |
2.1 |
# Think of those two as '-verbose'.
|
| 60 |
|
|
$opts .= " $_";
|
| 61 |
|
|
$radopt = 1;
|
| 62 |
greg |
2.2 |
} elsif (m/^-S\b/) { # full-screen stereo
|
| 63 |
greg |
2.1 |
$opts .= " $_";
|
| 64 |
|
|
$glradopt = 1;
|
| 65 |
|
|
} elsif (m/^-\w/) {
|
| 66 |
|
|
die("objview: Bad option: $_\n");
|
| 67 |
|
|
} else {
|
| 68 |
|
|
last;
|
| 69 |
|
|
}
|
| 70 |
|
|
shift @ARGV;
|
| 71 |
|
|
}
|
| 72 |
|
|
|
| 73 |
|
|
# We need at least one Radiance file or a scene on STDIN
|
| 74 |
|
|
if ($#ARGV < 0) {
|
| 75 |
|
|
open(FH, ">$td/stdin.rad") or
|
| 76 |
|
|
die("objview: Can't write to temporary file $td/stdin.rad\n");
|
| 77 |
|
|
while (<>) {
|
| 78 |
|
|
print FH;
|
| 79 |
|
|
}
|
| 80 |
|
|
# Pretend stdin.rad was passed as argument.
|
| 81 |
|
|
@ARGV = ("$td/stdin.rad");
|
| 82 |
|
|
}
|
| 83 |
|
|
|
| 84 |
|
|
# Make sure we don't confuse glrad and rad options.
|
| 85 |
|
|
if ($usegl) {
|
| 86 |
|
|
if ($radopt) {
|
| 87 |
|
|
die("objview: glrad output requested, but rad option passed.\n");
|
| 88 |
|
|
}
|
| 89 |
|
|
} else {
|
| 90 |
|
|
if ($glradopt) {
|
| 91 |
|
|
die("objview: rad output requested, but glrad option passed.\n");
|
| 92 |
|
|
}
|
| 93 |
|
|
}
|
| 94 |
|
|
|
| 95 |
|
|
open(FH, ">$lights") or
|
| 96 |
|
|
die("objview: Can't write to temporary file $lights\n");
|
| 97 |
|
|
print FH <<EndOfLights;
|
| 98 |
|
|
void glow dim 0 0 4 .1 .1 .15 0
|
| 99 |
|
|
dim source background 0 0 4 0 0 1 360
|
| 100 |
|
|
void light bright 0 0 3 1000 1000 1000
|
| 101 |
|
|
bright source sun1 0 0 4 1 .2 1 5
|
| 102 |
|
|
bright source sun2 0 0 4 .3 1 1 5
|
| 103 |
|
|
bright source sun3 0 0 4 -1 -.7 1 5
|
| 104 |
|
|
EndOfLights
|
| 105 |
|
|
close(FH);
|
| 106 |
|
|
|
| 107 |
|
|
my @scenes = @ARGV;
|
| 108 |
|
|
push (@scenes, $lights);
|
| 109 |
|
|
|
| 110 |
|
|
# Make this work under Windoze
|
| 111 |
|
|
if ( $^O =~ /MSWin32/ ) {
|
| 112 |
|
|
for my $i (0 .. $#scenes) {
|
| 113 |
|
|
# rad doesn't like Windows-style backslashes.
|
| 114 |
|
|
$scenes[$i] =~ s{\\}{/}g;
|
| 115 |
|
|
}
|
| 116 |
|
|
$octree =~ s{\\}{/}g;
|
| 117 |
|
|
$ambf =~ s{\\}{/}g;
|
| 118 |
|
|
$raddev = "qt";
|
| 119 |
|
|
}
|
| 120 |
|
|
|
| 121 |
|
|
my $scene = join(' ', @scenes);
|
| 122 |
|
|
open(FH, ">$rif") or
|
| 123 |
|
|
die("objview: Can't write to temporary file $rif\n");
|
| 124 |
|
|
print FH <<EndOfRif;
|
| 125 |
|
|
scene= $scene
|
| 126 |
|
|
EXPOSURE= .5
|
| 127 |
|
|
UP= $up
|
| 128 |
|
|
view= $vw
|
| 129 |
|
|
OCTREE= $octree
|
| 130 |
|
|
oconv= -f
|
| 131 |
|
|
AMBF= $ambf
|
| 132 |
|
|
render= $rendopts
|
| 133 |
|
|
EndOfRif
|
| 134 |
|
|
close(FH);
|
| 135 |
|
|
|
| 136 |
|
|
if ($usegl) {
|
| 137 |
|
|
system "glrad $opts $rif";
|
| 138 |
|
|
} else {
|
| 139 |
|
|
system "rad -o $raddev $opts $rif";
|
| 140 |
|
|
}
|
| 141 |
|
|
|
| 142 |
|
|
#EOF
|