--- ray/src/util/genambpos.pl 2014/04/24 23:15:42 2.1 +++ ray/src/util/genambpos.pl 2022/02/15 04:08:26 2.11 @@ -1,17 +1,21 @@ #!/usr/bin/perl -w -# RCSid $Id: genambpos.pl,v 2.1 2014/04/24 23:15:42 greg Exp $ +# RCSid $Id: genambpos.pl,v 2.11 2022/02/15 04:08:26 greg Exp $ # # Visualize ambient positions and gradients # use strict; +my $windoz = ($^O eq "MSWin32" or $^O eq "MSWin64"); +die "Not supported under Windows -- sorry!\n" if ( $windoz ); sub userror { - print STDERR "Usage: genambpos [-l lvl][-s scale][-p][-d] scene.amb > ambloc.rad\n"; + print STDERR "Usage: genambpos [-l lvl][-w minwt][-r rad][-s sf][-p][-d] scene.amb > ambloc.rad\n"; exit 1; } my $lvlsel = -1; my $scale = 0.25; my $doposgrad = 0; my $dodirgrad = 0; +my $minwt = 0.5001**6; +my $fixedrad=""; my $savedARGV = "genambpos @ARGV"; # Get options while ($#ARGV >= 0) { @@ -22,9 +26,15 @@ while ($#ARGV >= 0) { } elsif ("$ARGV[0]" =~ /^-l/) { $lvlsel = $ARGV[1]; shift @ARGV; + } elsif ("$ARGV[0]" =~ /^-w/) { + $minwt = $ARGV[1]; + shift @ARGV; } elsif ("$ARGV[0]" =~ /^-s/) { $scale = $ARGV[1]; shift @ARGV; + } elsif ("$ARGV[0]" =~ /^-r/) { + $fixedrad = "-e psiz:$ARGV[1]"; + shift @ARGV; } elsif ("$ARGV[0]" =~ /^-./) { userror(); } else { @@ -34,11 +44,12 @@ while ($#ARGV >= 0) { } userror() if ($#ARGV != 0); my $cmd = "getinfo < $ARGV[0] " . - q[| sed -n 's/^.* -aa \([.0-9][.0-9]*\) .*$/\1/p']; + q[| sed -n 's/^.* -aa \([.0-9][^ ]*\) .*$/\1/p']; my $ambacc=`$cmd`; die "Missing -aa setting in header\n" if (! $ambacc ); -$scale *= $ambacc**.25; -my $outfmt = ' +die "Zero -aa setting in header\n" if ($ambacc <= .00001); +$scale *= $ambacc; +my $ambfmt = ' void glow posglow 0 0 @@ -47,22 +58,32 @@ void glow posglow posglow sphere position${recno} 0 0 -4 ${px} ${py} ${pz} ${psiz} +4 ${ px } ${ py } ${ pz } ${ psiz } +'; +my $posgradfmt = ' +void glow arrglow +0 +0 +4 ${wt*agr} ${wt*agg} ${wt*agb} 0 -posglow cone pgarrow${recno} +arrglow cone pgarrow${recno} 0 0 8 - ${ cx0 } ${ cy0 } ${ cz0 } - ${ cx1 } ${ cy1 } ${ cz1 } - ${ cr0 } 0 -'; -my $posgradfmt = ' + ${ cx0 } ${ cy0 } ${ cz0 } + ${ cx1 } ${ cy1 } ${ cz1 } + ${ cr0 } 0 + void brightfunc pgpat 2 posfunc ambpos.cal 0 6 ${ px } ${ py } ${ pz } ${ pgx } ${ pgy } ${ pgz } +pgpat colorfunc pgpat +4 1 if(corralled,.1,1) if(corralled,.1,1) ambpos.cal +0 +7 ${ px } ${ py } ${ pz } ${ ux } ${ uy } ${ uz } ${ cflags } + pgpat glow pgval 0 0 @@ -77,23 +98,23 @@ pgeval polygon pgellipse${recno} 0 0 12 - ${ px1 } ${ py1 } ${ pz1 } - ${ px2 } ${ py2 } ${ pz2 } - ${ px3 } ${ py3 } ${ pz3 } - ${ px4 } ${ py4 } ${ pz4 } + ${ px1 } ${ py1 } ${ pz1 } + ${ px2 } ${ py2 } ${ pz2 } + ${ px3 } ${ py3 } ${ pz3 } + ${ px4 } ${ py4 } ${ pz4 } '; -$outfmt .= $posgradfmt if ($doposgrad); -my $dirgradfmt=' +$posgradfmt .= ' void glow tipglow 0 0 4 ${2*agr} ${2*agg} ${2*agb} 0 -tipglow sphere atip +tipglow sphere atip${recno} 0 0 -4 ${ cx1 } ${ cy1 } ${ cz1 } ${psiz/7} - +4 ${ cx1 } ${ cy1 } ${ cz1 } ${psiz/7} +' if ($dodirgrad); +my $dirgradfmt=' void brightfunc dgpat 2 dirfunc ambpos.cal 0 @@ -108,20 +129,30 @@ dgval ring dgdisk${recno}a 0 0 8 - ${ px+dgx*.0001 } ${ py+dgy*.0001 } ${ pz+dgz*.0001 } + ${ px+dgx/dg*eps*.5 } ${ py+dgy/dg*eps*.5 } ${ pz+dgz/dg*eps*.5 } ${ dgx } ${ dgy } ${ dgz } - 0 ${ r0/2 } + 0 ${ r0/2 } dgval ring dgdisk${recno}b 0 0 8 - ${ px-dgx*.0001 } ${ py-dgy*.0001 } ${ pz-dgz*.0001 } + ${ px-dgx/dg*eps*.5 } ${ py-dgy/dg*eps*.5 } ${ pz-dgz/dg*eps*.5 } ${ -dgx } ${ -dgy } ${ -dgz } - 0 ${ r0/2 } + 0 ${ r0/2 } '; -$outfmt .= $dirgradfmt if ($dodirgrad); # Load & convert ambient values print "# Output produced by: $savedARGV\n"; -system "lookamb -h -d $ARGV[0] | rcalc -e 'LV:$lvlsel;SF:$scale' -f rambpos.cal -o '$outfmt'\n"; +system "lookamb -h -d $ARGV[0] | rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" . + " -f rambpos.cal -e cond=acond $fixedrad -o '$ambfmt'"; +if ($doposgrad) { + system "lookamb -h -d $ARGV[0] " . + "| rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" . + " -f rambpos.cal -e cond=pcond $fixedrad -o '$posgradfmt'"; +} +if ($dodirgrad) { + system "lookamb -h -d $ARGV[0] " . + "| rcalc -e 'LV:$lvlsel;MW:$minwt;SF:$scale'" . + " -f rambpos.cal -e cond=dcond -o '$dirgradfmt'"; +} exit;