ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/util/objview.pl
Revision: 2.1
Committed: Wed Dec 4 20:07:07 2013 UTC (10 years, 3 months ago) by greg
Content type: text/plain
Branch: MAIN
CVS Tags: rad4R2P2, rad5R0, rad4R2, rad4R2P1
Log Message:
Replaced objview and objpict with Perl scripts written by Axel Jacobs

File Contents

# Content
1 #!/usr/bin/perl
2 # RCSid $Id$
3 #
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 if (m/-g/) { # OpenGL output
35 if ( $^O =~ /MSWin32/ ) {
36 die("OpenGL view is not available under Windows.\n");
37 }
38 $usegl = 1;
39 } elsif (m/-u/) { # up direction
40 $up = $ARGV[1];
41 shift @ARGV;
42 } elsif ((m/-s/) or (m/-w/)) { # silent, no warnings
43 $opts .= " $_";
44 } elsif (m/-b/) { # back face visibility
45 $rendopts .= ' -bv';
46 } elsif (m/-v/) { # standard view "[Xx]?[Yy]?[Zz]?[vlcahs]?"
47 # Let rad do any error handling...
48 $vw = $ARGV[1];
49 shift @ARGV;
50 } elsif (m/-N/) { # No. of parallel processes
51 $opts .= ' -N ' . $ARGV[1];
52 $radopt = 1;
53 shift @ARGV;
54 } elsif (m/-o/) { # output device (rvu -devices)
55 $raddev = $ARGV[1];
56 $radopt = 1;
57 shift @ARGV;
58 } elsif ((m/-V/) or (m/-e/)) { # print view, explicate variables
59 # Think of those two as '-verbose'.
60 $opts .= " $_";
61 $radopt = 1;
62 } elsif (m/-S/) { # full-screen stereo
63 $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