# HG changeset patch # User Axel Jacobs # Date 1302384079 -3600 # Node ID 572fcaba44b907df04226f0dc3202a97efd5aabf # Parent d59fbab896adb9950231ad6d2b5cf5da5bd0273e Added objsomething. diff -r d59fbab896ad -r 572fcaba44b9 bin/objpict.pl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/objpict.pl Sat Apr 09 22:21:19 2011 +0100 @@ -0,0 +1,98 @@ +#!/usr/bin/perl + +# Make a nice multi-view picture of an object +# Command line arguments contain materials and object files +# +# This is a re-write of Greg's objpict.csh and should be a drop-in +# replacement, with no funcionality added or removed + +use strict; +use warnings; + +use File::Temp qw/ tempdir /; +my $td = tempdir( CLEANUP => 1 ); + +my $xres = 800; +my $yres = 800; +my $rpict_cmd = "rpict -av .2 .2 .2 -x $xres -y $yres"; + +my $inprad = "$td/op$$.rad"; +my $testroom = "$td/testroom.rad"; +my $octree = "$td/op.oct"; + +# See if files actually exist. +foreach (@ARGV) { + if (! -e) { + die("Can't read file $_\n"); + } +} + +# Dump files passed on command line or from STDIN to a temp file. +open(FH, ">$inprad") or + die("Can\'t write to temporary file $inprad"); +while (<>) { + print FH; +} +close(FH); + +# Create some lights and a box as back drop. +# The objects and view points will be inside the box. +open(FH, ">$testroom") or + die("Can\'t write to temporary file $testroom"); +print FH < $b } @diffs; +my $size = $diffs[0]; + +my $vw1 = "-vtl -vp 2 .5 .5 -vd -1 0 0 -vh 1 -vv 1"; +my $vw2 = "-vtl -vp .5 2 .5 -vd 0 -1 0 -vh 1 -vv 1"; +my $vw3 = "-vtl -vp .5 .5 2 -vd 0 0 -1 -vu -1 0 0 -vh 1 -vv 1"; +my $vw4 = "-vp 3 3 3 -vd -1 -1 -1 -vh 20 -vv 20"; + +# 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 -t .5 .5 .5 $inprad"; +$cmd .= " |oconv $testroom - > $octree"; +system "$cmd"; + +# Render four different views of the objects +system "$rpict_cmd $vw1 $octree > $td/right.hdr"; +system "$rpict_cmd $vw2 $octree > $td/front.hdr"; +system "$rpict_cmd $vw3 $octree > $td/down.hdr"; +system "$rpict_cmd $vw4 $octree > $td/oblique.hdr"; + +# Compose the four views into one image +$cmd = "pcompos $td/down.hdr 0 $xres $td/oblique.hdr $xres $yres"; +$cmd .= " $td/right.hdr 0 0 $td/front.hdr $xres 0"; +$cmd .= " |pfilt -1 -r .6 -x /2 -y /2"; +exec "$cmd"; + +#EOF