# HG changeset patch # User Axel Jacobs # Date 1387130650 0 # Node ID c8df2d579470b52d2f5db6ee6d2b5a929e74b6f2 # Parent 417e2adf19bf1e52ff822d7cbeb29b6c5deb138d ltview: working and tested on LINUX and Vista diff -r 417e2adf19bf -r c8df2d579470 bin/ltview.pl --- a/bin/ltview.pl Sun Dec 15 18:03:49 2013 +0000 +++ b/bin/ltview.pl Sun Dec 15 18:04:10 2013 +0000 @@ -1,31 +1,31 @@ #!/usr/bin/perl # -# Make a nice view of an object -# Arguments are scene input files +# Make a nice view of a luminaire +# Argument is the Radiance description of a luminaire, incl. distribution # -# This is a re-write of Greg's original objview.csh. -# The only extra functionality is that we accept a scene on STDIN -# if no file name is given. +# This script is based on Radiance's objview.pl plus +# Rob Guglielmetti's ltview extension to his objview.rb # -# Axel, Nov 2013 +# Axel Jacobs, 25 Dec 2013 use strict; use warnings; use File::Temp qw/ tempdir /; -#my $td = tempdir( CLEANUP => 1 ); -my $td = "tmp"; -my $octree = "$td/ov$$.oct"; +my $td = tempdir( CLEANUP => 1 ); +my $octree = "$td/lt$$.oct"; my $room = "$td/rm$$.rad"; -my $rif = "$td/ov$$.rif"; +my $rif = "$td/lt$$.rif"; +my $lumi = "$td/lt$$.rad"; my $ambf = "$td/af$$.amb"; my $raddev = "x11"; # default output device. Overwrite with -o my $up = "Z"; -my $vw = "XYZ"; -my $rsize = 1; # room size in metres +my $vw = "XYZ"; # default view. See 'man rad' for details +my $bubble = 0; # Box or bubble? 0..box, 1..bubble +my $TINY = 0.01; my $opts = ""; # Options common to rad and glrad -my $rendopts = "-ab 1 -ds .15"; # For render= line in rif file +my $rendopts = "-ab 1 -ds .15 -av 0 0 0"; # For render= line in rif file my $usegl = 0; # Run glrad instead of rad (Boolean). my $radopt = 0; # An option specific to rad was passed (Boolean). my $glradopt = 0; # An option specific to glrad was passed (Boolean). @@ -34,9 +34,11 @@ $_ = $ARGV[0]; if (m/-g/) { # OpenGL output if ( $^O =~ /MSWin32/ ) { - die("OpenGL view is not available under Windows.\n"); + # No meaningful error messages under Windows. Just ignore... + #die("OpenGL view is not available under Windows.\n"); + } else { + $usegl = 1; } - $usegl = 1; } elsif (m/-u/) { # up direction $up = $ARGV[1]; shift @ARGV; @@ -45,11 +47,17 @@ } elsif (m/-b/) { # back face visibility $rendopts .= ' -bv'; } elsif (m/-v/) { # standard view "[Xx]?[Yy]?[Zz]?[vlcahs]?" - # Let rad do any error handling... + # Prepend view with '+' for custom view away from the luminaire, not at it. + # This is not defined by rad's default views. $vw = $ARGV[1]; shift @ARGV; } elsif (m/-N/) { # No. of parallel processes - $opts .= ' -N ' . $ARGV[1]; + if ( $^O =~ /MSWin32/ ) { + # Silently ignore this under Windoze + #die("Multi-processor support is not available under Windows.\n"); + } else { + $opts .= ' -N ' . $ARGV[1]; + } $radopt = 1; shift @ARGV; } elsif (m/-o/) { # output device (rvu -devices) @@ -63,9 +71,8 @@ } elsif (m/-S/) { # full-screen stereo $opts .= " $_"; $glradopt = 1; - } elsif (m/-r/) { # room size - $rsize = $ARGV[1]; - shift @ARGV; + } elsif (m/-r/) { # spherical room rather than box + $bubble = 1; } elsif (m/^-\w/) { die("objview: Bad option: $_\n"); } else { @@ -74,11 +81,11 @@ shift @ARGV; } -# We need one IES file +# We need exactly one input file: a Radiance luminaires description +#TODO: this could be expanded to handle Radiance .dat files and IES photometry files... if (! $#ARGV == 0) { - die("ltview: Need one IES photometry file\n"); + die("ltview: Need one Radiance luminaire.\n"); } -my $scene = $ARGV[0]; # Make sure we don't confuse glrad and rad options. if ($usegl) { @@ -93,24 +100,65 @@ open(FH, ">$room") or die("ltview: Can't write to temporary file $room\n"); -print FH < $b } @diffs; +my $size = $diffs[0]; + +# Move objects so centre is at origin +my $xtrans = -1.0 * ($dims[0] + $dims[1]) / 2; +my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2; +my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2; +# Scale so that largest object dimension is unity +my $scale = 1 / $size; + +my $cmd = "xform -t $xtrans $ytrans $ztrans -s $scale $ARGV[0] > $lumi"; +system "$cmd"; + +my $scene = "$room $lumi"; # Make this work under Windoze if ( $^O =~ /MSWin32/ ) { $scene =~ s{\\}{/}g; $octree =~ s{\\}{/}g; + $ambf =~ s{\\}{/}g; $raddev = "qt"; } +my $custom_vw = $vw; +$vw =~ s/^\+//; open(FH, ">$rif") or - die("objview: Can't write to temporary file $rif\n"); + die("ltview: Can't write to temporary file $rif\n"); print FH <$rif") or + die("ltview: Can't write to temporary file $rif\n"); + print FH <