8 # Written by Axel Jacobs <axel@jaloxa.eu> |
8 # Written by Axel Jacobs <axel@jaloxa.eu> |
9 |
9 |
10 use strict; |
10 use strict; |
11 use warnings; |
11 use warnings; |
12 use Math::Trig; |
12 use Math::Trig; |
13 use File::Copy; |
13 use File::Copy qw(copy); |
14 use File::Temp qw/ tempdir /; |
14 use File::Temp qw/ tempdir /; |
15 |
15 |
16 my $td = tempdir( CLEANUP => 1 ); |
16 my $td = tempdir( CLEANUP => 1 ); |
17 my $oct = "$td/ltview.oct"; |
17 my $oct = "$td/ltview.oct"; |
18 my $room = "$td/room.rad"; |
18 my $room = "$td/room.rad"; |
19 my $rdim; # Overall room dimensions |
19 my $box; # Overall box dimensions |
|
20 my $default_box = 10; # Default box dimensions |
20 my $rif = "$td/ltview.rif"; |
21 my $rif = "$td/ltview.rif"; |
21 my $lumi = "$td/lumi.rad"; |
22 my $lumi = "$td/lumi.rad"; # Fitting as given on cmd line, or generated by ies2rad |
22 my $ies = "$td/lumi.ies"; |
23 my $lumi2 = "$td/lumi2.rad"; # Fitting scaled to max unity |
23 my $raddev = "x11"; # default output device. Overwrite with -o |
24 my $raddev = "x11"; # default output device. Overwrite with -o |
24 my $is_ies = 0; # input file is IES photometry, not a Radiance luminaire |
25 my $is_ies = 0; # input file is IES photometry, not a Radiance luminaire |
25 |
26 |
26 my $maxscale = 1; # Maximum luminiare dimension after scaling |
27 my $maxscale = 1; # Maximum luminiare dimension after scaling |
27 my $opts = ""; # Options common to rad and glrad |
28 my $opts = ""; # Options common to rad and glrad |
34 $is_ies = 1; |
35 $is_ies = 1; |
35 } elsif (m/-o/) { # output device (rvu -devices) |
36 } elsif (m/-o/) { # output device (rvu -devices) |
36 $raddev = $ARGV[1]; |
37 $raddev = $ARGV[1]; |
37 $radopt = 1; |
38 $radopt = 1; |
38 shift @ARGV; |
39 shift @ARGV; |
39 } elsif (m/-r/) { |
40 } elsif (m/-b/) { |
40 $rdim = $ARGV[1]; # Room dimensions |
41 $box = $ARGV[1]; # Box dimensions |
41 shift @ARGV; |
42 shift @ARGV; |
42 } elsif (m/^-\w/) { |
43 } elsif (m/^-\w/) { |
43 die("objview: Bad option: $_\n"); |
44 die("objview: Bad option: '$_'\n"); |
44 } else { |
45 } else { |
45 last; |
46 last; |
46 } |
47 } |
47 shift @ARGV; |
48 shift @ARGV; |
48 } |
49 } |
49 |
50 |
50 # We need one Radiance luminaires description, or an IES file |
51 # We need exactly one Radiance luminaires or IES file |
51 if (! $#ARGV == 0) { |
52 if (! $#ARGV == 0) { |
52 die("ltview: Need one Radiance luminaire or IES file.\n"); |
53 die("ltview: Need one Radiance luminaire or IES file.\n"); |
53 } |
54 } |
54 |
55 |
|
56 if ($is_ies == 0) { |
|
57 # Input file is a Radiance luminaire |
|
58 $lumi = $ARGV[0]; |
|
59 } else { |
|
60 # Input file is IES photometry |
|
61 system "ies2rad -p $td -o lumi $ARGV[0]"; |
|
62 } |
|
63 |
|
64 |
55 open(FH, ">$room") or |
65 open(FH, ">$room") or |
56 die("ltview: Can't write to temporary file $room\n"); |
66 die("ltview: Can't write to temporary file '$room'\n"); |
57 print FH "void plastic wall_mat 0 0 5 .2 .2 .2 0 0\n"; |
67 print FH "void plastic wall_mat 0 0 5 .2 .2 .2 0 0\n"; |
58 |
68 |
59 my $r; |
69 my $b2; |
60 if (defined $rdim) { |
70 if (defined $box) { |
61 # Room dimensions are giving explicitly. Don't touch the fitting. |
71 # Room dimensions are giving explicitly. Don't touch the fitting. |
62 $r = $rdim; |
72 $b2 = $box / 2; |
63 |
73 |
64 copy ($ARGV[0], $lumi); |
74 $lumi2 = $ARGV[0]; |
65 } else { |
75 } else { |
66 # Scale fitting so it fits nicely into our default test room. |
76 # Scale fitting so it fits nicely into our default test room. |
67 $r = 5; # Default room dimension |
77 $b2 = $default_box; # Default room dimension |
68 |
78 |
69 # Work out how large the luminaire is and scale so that the longest |
79 # Work out how large the luminaire is and scale so that the longest |
70 # axis-align dimension is $maxscale |
80 # axis-align dimension is $maxscale |
71 my $dimstr = `getbbox -h $ARGV[0]`; |
81 my $dimstr = `getbbox -h $lumi`; |
72 chomp $dimstr; |
82 chomp $dimstr; |
73 # Values returned by getbbox are indented and delimited with multiple spaces. |
83 # Values returned by getbbox are indented and delimited with multiple spaces. |
74 $dimstr =~ s/^\s+//; # remove leading spaces |
84 $dimstr =~ s/^\s+//; # remove leading spaces |
75 my @dims = split(/\s+/, $dimstr); # convert to array |
85 my @dims = split(/\s+/, $dimstr); # convert to array |
76 |
86 |
84 my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2; |
94 my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2; |
85 my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2; |
95 my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2; |
86 # Scale so that largest object dimension is $maxscale |
96 # Scale so that largest object dimension is $maxscale |
87 my $scale = $maxscale / $size; |
97 my $scale = $maxscale / $size; |
88 |
98 |
89 system "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi"; |
99 #system "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi"; |
|
100 system "xform -t $xtrans $ytrans $ztrans -s $scale $lumi > $lumi2"; |
90 } |
101 } |
91 |
102 |
92 print FH <<EndOfRoom; |
103 print FH <<EndOfRoom; |
93 # Don't generate -y face so we can look into the box (could use clipping) |
104 # Don't generate -y face so we can look into the box (could use clipping) |
94 #wall_mat polygon box.1540 0 0 12 $r -$r -$r $r -$r $r -$r -$r $r -$r -$r -$r |
105 #wall_mat polygon box.1540 0 0 12 $b2 -$b2 -$b2 $b2 -$b2 $b2 -$b2 -$b2 $b2 -$b2 -$b2 -$b2 |
95 wall_mat polygon box.4620 0 0 12 -$r -$r $r -$r $r $r -$r $r -$r -$r -$r -$r |
106 wall_mat polygon box.4620 0 0 12 -$b2 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2 |
96 wall_mat polygon box.2310 0 0 12 -$r $r -$r $r $r -$r $r -$r -$r -$r -$r -$r |
107 wall_mat polygon box.2310 0 0 12 -$b2 $b2 -$b2 $b2 $b2 -$b2 $b2 -$b2 -$b2 -$b2 -$b2 -$b2 |
97 wall_mat polygon box.3267 0 0 12 $r $r -$r -$r $r -$r -$r $r $r $r $r $r |
108 wall_mat polygon box.3267 0 0 12 $b2 $b2 -$b2 -$b2 $b2 -$b2 -$b2 $b2 $b2 $b2 $b2 $b2 |
98 wall_mat polygon box.5137 0 0 12 $r -$r $r $r -$r -$r $r $r -$r $r $r $r |
109 wall_mat polygon box.5137 0 0 12 $b2 -$b2 $b2 $b2 -$b2 -$b2 $b2 $b2 -$b2 $b2 $b2 $b2 |
99 wall_mat polygon box.6457 0 0 12 -$r $r $r -$r -$r $r $r -$r $r $r $r $r |
110 wall_mat polygon box.6457 0 0 12 -$b2 $b2 $b2 -$b2 -$b2 $b2 $b2 -$b2 $b2 $b2 $b2 $b2 |
100 EndOfRoom |
111 EndOfRoom |
101 close(FH); |
112 close(FH); |
102 |
113 |
103 my $scene = "$room $lumi"; |
114 my $scene = "$room $lumi"; |
104 # Make this work under Windoze |
115 # Make this work under Windoze |
108 $raddev = "qt"; |
119 $raddev = "qt"; |
109 } |
120 } |
110 |
121 |
111 # Tweak bounding box so we get a nice view covering all of the box, without |
122 # Tweak bounding box so we get a nice view covering all of the box, without |
112 # having a wasteful black border around it. Must work for arbitrary box dims. |
123 # having a wasteful black border around it. Must work for arbitrary box dims. |
113 my $zone = 1.1 * $r * ( 1 + 1/tan(22.5*pi/180) ); |
124 my $zone = 1.1 * $b2 * ( 1 + 1/tan(22.5*pi/180) ); |
114 |
125 |
115 open(FH, ">$rif") or |
126 open(FH, ">$rif") or |
116 die("ltview: Can't write to temporary file $rif\n"); |
127 die("ltview: Can't write to temporary file '$rif'\n"); |
117 print FH <<EndOfRif; |
128 print FH <<EndOfRif; |
118 scene= $scene |
129 scene= $scene |
119 EXPOSURE= 2 |
130 EXPOSURE= 2 |
120 ZONE= Interior -$zone $zone -$zone $zone -$zone $zone |
131 ZONE= Interior -$zone $zone -$zone $zone -$zone $zone |
121 UP= Z |
132 UP= Z |