|
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, Nov 2013 |
|
11 |
|
12 use strict; |
|
13 use warnings; |
|
14 use File::Temp qw/ tempdir /; |
|
15 |
|
16 #my $td = tempdir( CLEANUP => 1 ); |
|
17 my $td = "tmp"; |
|
18 my $octree = "$td/ov$$.oct"; |
|
19 my $room = "$td/rm$$.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 my $rsize = 1; # room size in metres |
|
26 |
|
27 my $opts = ""; # Options common to rad and glrad |
|
28 my $rendopts = "-ab 1 -ds .15"; # For render= line in rif file |
|
29 my $usegl = 0; # Run glrad instead of rad (Boolean). |
|
30 my $radopt = 0; # An option specific to rad was passed (Boolean). |
|
31 my $glradopt = 0; # An option specific to glrad was passed (Boolean). |
|
32 |
|
33 while (@ARGV) { |
|
34 $_ = $ARGV[0]; |
|
35 if (m/-g/) { # OpenGL output |
|
36 if ( $^O =~ /MSWin32/ ) { |
|
37 die("OpenGL view is not available under Windows.\n"); |
|
38 } |
|
39 $usegl = 1; |
|
40 } elsif (m/-u/) { # up direction |
|
41 $up = $ARGV[1]; |
|
42 shift @ARGV; |
|
43 } elsif ((m/-s/) or (m/-w/)) { # silent, no warnings |
|
44 $opts .= " $_"; |
|
45 } elsif (m/-b/) { # back face visibility |
|
46 $rendopts .= ' -bv'; |
|
47 } elsif (m/-v/) { # standard view "[Xx]?[Yy]?[Zz]?[vlcahs]?" |
|
48 # Let rad do any error handling... |
|
49 $vw = $ARGV[1]; |
|
50 shift @ARGV; |
|
51 } elsif (m/-N/) { # No. of parallel processes |
|
52 $opts .= ' -N ' . $ARGV[1]; |
|
53 $radopt = 1; |
|
54 shift @ARGV; |
|
55 } elsif (m/-o/) { # output device (rvu -devices) |
|
56 $raddev = $ARGV[1]; |
|
57 $radopt = 1; |
|
58 shift @ARGV; |
|
59 } elsif ((m/-V/) or (m/-e/)) { # print view, explicate variables |
|
60 # Think of those two as '-verbose'. |
|
61 $opts .= " $_"; |
|
62 $radopt = 1; |
|
63 } elsif (m/-S/) { # full-screen stereo |
|
64 $opts .= " $_"; |
|
65 $glradopt = 1; |
|
66 } elsif (m/-r/) { # room size |
|
67 $rsize = $ARGV[1]; |
|
68 shift @ARGV; |
|
69 } elsif (m/^-\w/) { |
|
70 die("objview: Bad option: $_\n"); |
|
71 } else { |
|
72 last; |
|
73 } |
|
74 shift @ARGV; |
|
75 } |
|
76 |
|
77 # We need one IES file |
|
78 if (! $#ARGV == 0) { |
|
79 die("ltview: Need one IES photometry file\n"); |
|
80 } |
|
81 my $scene = $ARGV[0]; |
|
82 |
|
83 # Make sure we don't confuse glrad and rad options. |
|
84 if ($usegl) { |
|
85 if ($radopt) { |
|
86 die("objview: glrad output requested, but rad option passed.\n"); |
|
87 } |
|
88 } else { |
|
89 if ($glradopt) { |
|
90 die("objview: rad output requested, but glrad option passed.\n"); |
|
91 } |
|
92 } |
|
93 |
|
94 open(FH, ">$room") or |
|
95 die("ltview: Can't write to temporary file $room\n"); |
|
96 print FH <<EndOfRoom; |
|
97 void plastic surf 0 0 5 .2 .2 .2 0 0 |
|
98 !genbox -i surf room $rsize $rsize $rsize |xform -t -$rsize/2 -$rsize/2 -$rsize/2 |
|
99 EndOfRoom |
|
100 close(FH); |
|
101 |
|
102 # Make this work under Windoze |
|
103 if ( $^O =~ /MSWin32/ ) { |
|
104 $scene =~ s{\\}{/}g; |
|
105 $octree =~ s{\\}{/}g; |
|
106 $raddev = "qt"; |
|
107 } |
|
108 |
|
109 open(FH, ">$rif") or |
|
110 die("objview: Can't write to temporary file $rif\n"); |
|
111 print FH <<EndOfRif; |
|
112 scene= $scene |
|
113 EXPOSURE= .5 |
|
114 UP= $up |
|
115 view= $vw |
|
116 OCTREE= $octree |
|
117 oconv= -f |
|
118 AMBF= $ambf |
|
119 render= $rendopts |
|
120 EndOfRif |
|
121 close(FH); |
|
122 |
|
123 if ($usegl) { |
|
124 system "glrad $opts $rif"; |
|
125 } else { |
|
126 system "rad -o $raddev $opts $rif"; |
|
127 } |
|
128 |
|
129 #EOF |