bin/objpict.pl
changeset 35 eaa48934a5bd
parent 18 eb4125f74a79
equal deleted inserted replaced
34:b32315c3402e 35:eaa48934a5bd
     1 #!/usr/bin/perl 
     1 #!/usr/bin/perl
     2 
     2 
     3 # Make a nice multi-view picture of an object
     3 # Make a nice multi-view picture of an object
     4 # Command line arguments contain materials and object files
     4 # Command line arguments contain materials and object files
     5 #
     5 #
     6 # This is a re-write of Greg's objpict.csh and should be a drop-in
     6 # This is a re-write of Greg's objpict.csh and should be a drop-in
    14 
    14 
    15 my $xres = 1024;
    15 my $xres = 1024;
    16 my $yres = 1024;
    16 my $yres = 1024;
    17 my $rpict_cmd = "rpict -av .2 .2 .2 -x $xres -y $yres";
    17 my $rpict_cmd = "rpict -av .2 .2 .2 -x $xres -y $yres";
    18 
    18 
    19 my $inprad = "$td/op$$.rad";
       
    20 my $testroom = "$td/testroom.rad";
    19 my $testroom = "$td/testroom.rad";
    21 my $octree = "$td/op.oct";
    20 my $octree = "$td/op.oct";
    22 
    21 
    23 # See if files actually exist.
    22 # We need at least one Radiance file or a scene on STDIN (but not both)
    24 foreach (@ARGV) {
    23 if ($#ARGV < 0) {
    25 	if (! -e) {
    24 	open(FH, ">$td/stdin.rad") or 
    26 		die("Can't read file $_\n");
    25 			die("objview: Can't write to temporary file $td/stdin.rad\n");
       
    26 	while (<>) {
       
    27 		print FH;
    27 	}
    28 	}
       
    29 	# Pretend stdin.rad was passed as argument.
       
    30 	@ARGV = ("$td/stdin.rad");
    28 }
    31 }
    29 
       
    30 # Dump files passed on command line or from STDIN to a temp file.
       
    31 open(FH, ">$inprad") or
       
    32 		die("Can\'t write to temporary file $inprad");
       
    33 while (<>) {
       
    34 	print FH;
       
    35 }
       
    36 close(FH);
       
    37 
    32 
    38 # Create some lights and a box as back drop.
    33 # Create some lights and a box as back drop.
    39 # The objects and view points will be inside the box.
    34 # The objects and view points will be inside the box.
    40 open(FH, ">$testroom") or
    35 open(FH, ">$testroom") or
    41 		die("Can\'t write to temporary file $testroom");
    36 		die("Can\'t write to temporary file $testroom");
    54 wall_mat polygon box.5137  0  0  12  5 -5 5  5 -5 -5  5 5 -5  5 5 5
    49 wall_mat polygon box.5137  0  0  12  5 -5 5  5 -5 -5  5 5 -5  5 5 5
    55 wall_mat polygon box.6457  0  0  12  -5 5 5  -5 -5 5  5 -5 5  5 5 5
    50 wall_mat polygon box.6457  0  0  12  -5 5 5  -5 -5 5  5 -5 5  5 5 5
    56 EndOfTestroom
    51 EndOfTestroom
    57 close(FH);
    52 close(FH);
    58 
    53 
    59 my $dimstr = `getbbox -h $inprad`;
    54 my $dimstr = `getbbox -h @ARGV`;
    60 # Values returned by getbbox are indented and padded with spaces.
    55 chomp $dimstr;
    61 $dimstr =~ s/(\s)+/\ /g;   # squeeze spaces
    56 # Values returned by getbbox are indented and delimited with multiple spaces.
    62 $dimstr =~ s/^\ //;   # remove leading space
    57 $dimstr =~ s/^\s+//;   # remove leading spaces
    63 my @dims = split(/\ /, $dimstr);   # convert to array
    58 my @dims = split(/\s+/, $dimstr);   # convert to array
    64 
    59 
    65 # Find largest axes-aligned dimension
    60 # Find largest axes-aligned dimension
    66 my @diffs = ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]);
    61 my @diffs = ($dims[1]-$dims[0], $dims[3]-$dims[2], $dims[5]-$dims[4]);
    67 @diffs = reverse sort { $a <=> $b } @diffs;
    62 @diffs = reverse sort { $a <=> $b } @diffs;
    68 my $size = $diffs[0];
    63 my $size = $diffs[0];
    69 
    64 
       
    65 # Define the four views
    70 my $vw1 = "-vtl -vp 2 .5 .5 -vd -1 0 0 -vh 1 -vv 1";
    66 my $vw1 = "-vtl -vp 2 .5 .5 -vd -1 0 0 -vh 1 -vv 1";
    71 my $vw2 = "-vtl -vp .5 2 .5 -vd 0 -1 0 -vh 1 -vv 1";
    67 my $vw2 = "-vtl -vp .5 2 .5 -vd 0 -1 0 -vh 1 -vv 1";
    72 my $vw3 = "-vtl -vp .5 .5 2 -vd 0 0 -1 -vu -1 0 0 -vh 1 -vv 1";
    68 my $vw3 = "-vtl -vp .5 .5 2 -vd 0 0 -1 -vu -1 0 0 -vh 1 -vv 1";
    73 my $vw4 = "-vp 3 3 3 -vd -1 -1 -1 -vh 20 -vv 20";
    69 my $vw4 = "-vp 3 3 3 -vd -1 -1 -1 -vh 20 -vv 20";
    74 
    70 
    77 my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2;
    73 my $ytrans = -1.0 * ($dims[2] + $dims[3]) / 2;
    78 my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2;
    74 my $ztrans = -1.0 * ($dims[4] + $dims[5]) / 2;
    79 # Scale so that largest object dimension is unity
    75 # Scale so that largest object dimension is unity
    80 my $scale = 1 / $size;
    76 my $scale = 1 / $size;
    81 
    77 
    82 my $cmd = "xform -t $xtrans $ytrans $ztrans -s $scale -t .5 .5 .5 $inprad";
    78 my $cmd = "xform -t $xtrans $ytrans $ztrans -s $scale -t .5 .5 .5 @ARGV";
    83 $cmd .= " |oconv $testroom - > $octree";
    79 $cmd .= " |oconv $testroom - > $octree";
    84 system "$cmd";
    80 system "$cmd";
    85 
    81 
    86 # Render four different views of the objects
    82 # Render four different views of the objects
    87 system "$rpict_cmd $vw1 $octree > $td/right.hdr";
    83 system "$rpict_cmd $vw1 $octree > $td/right.hdr";