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