| 1 |
greg |
2.1 |
#!/usr/bin/perl -w
|
| 2 |
|
|
# RCSid $Id$
|
| 3 |
|
|
#
|
| 4 |
|
|
# Visualize ambient positions and gradients
|
| 5 |
|
|
#
|
| 6 |
|
|
use strict;
|
| 7 |
|
|
sub userror {
|
| 8 |
|
|
print STDERR "Usage: genambpos [-l lvl][-s scale][-p][-d] scene.amb > ambloc.rad\n";
|
| 9 |
|
|
exit 1;
|
| 10 |
|
|
}
|
| 11 |
|
|
my $lvlsel = -1;
|
| 12 |
|
|
my $scale = 0.25;
|
| 13 |
|
|
my $doposgrad = 0;
|
| 14 |
|
|
my $dodirgrad = 0;
|
| 15 |
|
|
my $savedARGV = "genambpos @ARGV";
|
| 16 |
|
|
# Get options
|
| 17 |
|
|
while ($#ARGV >= 0) {
|
| 18 |
|
|
if ("$ARGV[0]" =~ /^-p/) {
|
| 19 |
|
|
$doposgrad=1;
|
| 20 |
|
|
} elsif ("$ARGV[0]" =~ /^-d/) {
|
| 21 |
|
|
$dodirgrad=1;
|
| 22 |
|
|
} elsif ("$ARGV[0]" =~ /^-l/) {
|
| 23 |
|
|
$lvlsel = $ARGV[1];
|
| 24 |
|
|
shift @ARGV;
|
| 25 |
|
|
} elsif ("$ARGV[0]" =~ /^-s/) {
|
| 26 |
|
|
$scale = $ARGV[1];
|
| 27 |
|
|
shift @ARGV;
|
| 28 |
|
|
} elsif ("$ARGV[0]" =~ /^-./) {
|
| 29 |
|
|
userror();
|
| 30 |
|
|
} else {
|
| 31 |
|
|
last;
|
| 32 |
|
|
}
|
| 33 |
|
|
shift @ARGV;
|
| 34 |
|
|
}
|
| 35 |
|
|
userror() if ($#ARGV != 0);
|
| 36 |
|
|
my $cmd = "getinfo < $ARGV[0] " .
|
| 37 |
|
|
q[| sed -n 's/^.* -aa \([.0-9][.0-9]*\) .*$/\1/p'];
|
| 38 |
|
|
my $ambacc=`$cmd`;
|
| 39 |
|
|
die "Missing -aa setting in header\n" if (! $ambacc );
|
| 40 |
|
|
$scale *= $ambacc**.25;
|
| 41 |
|
|
my $outfmt = '
|
| 42 |
|
|
void glow posglow
|
| 43 |
|
|
0
|
| 44 |
|
|
0
|
| 45 |
|
|
4 ${agr} ${agg} ${agb} 0
|
| 46 |
|
|
|
| 47 |
|
|
posglow sphere position${recno}
|
| 48 |
|
|
0
|
| 49 |
|
|
0
|
| 50 |
|
|
4 ${px} ${py} ${pz} ${psiz}
|
| 51 |
|
|
|
| 52 |
|
|
posglow cone pgarrow${recno}
|
| 53 |
|
|
0
|
| 54 |
|
|
0
|
| 55 |
|
|
8
|
| 56 |
|
|
${ cx0 } ${ cy0 } ${ cz0 }
|
| 57 |
|
|
${ cx1 } ${ cy1 } ${ cz1 }
|
| 58 |
|
|
${ cr0 } 0
|
| 59 |
|
|
';
|
| 60 |
|
|
my $posgradfmt = '
|
| 61 |
|
|
void brightfunc pgpat
|
| 62 |
|
|
2 posfunc ambpos.cal
|
| 63 |
|
|
0
|
| 64 |
|
|
6 ${ px } ${ py } ${ pz } ${ pgx } ${ pgy } ${ pgz }
|
| 65 |
|
|
|
| 66 |
|
|
pgpat glow pgval
|
| 67 |
|
|
0
|
| 68 |
|
|
0
|
| 69 |
|
|
4 ${avr} ${avg} ${avb} 0
|
| 70 |
|
|
|
| 71 |
|
|
void mixfunc pgeval
|
| 72 |
|
|
4 pgval void ellipstencil ambpos.cal
|
| 73 |
|
|
0
|
| 74 |
|
|
9 ${ px } ${ py } ${ pz } ${ux/r0} ${uy/r0} ${uz/r0} ${vx/r1} ${vy/r1} ${vz/r1}
|
| 75 |
|
|
|
| 76 |
|
|
pgeval polygon pgellipse${recno}
|
| 77 |
|
|
0
|
| 78 |
|
|
0
|
| 79 |
|
|
12
|
| 80 |
|
|
${ px1 } ${ py1 } ${ pz1 }
|
| 81 |
|
|
${ px2 } ${ py2 } ${ pz2 }
|
| 82 |
|
|
${ px3 } ${ py3 } ${ pz3 }
|
| 83 |
|
|
${ px4 } ${ py4 } ${ pz4 }
|
| 84 |
|
|
';
|
| 85 |
|
|
$outfmt .= $posgradfmt if ($doposgrad);
|
| 86 |
|
|
my $dirgradfmt='
|
| 87 |
|
|
void glow tipglow
|
| 88 |
|
|
0
|
| 89 |
|
|
0
|
| 90 |
|
|
4 ${2*agr} ${2*agg} ${2*agb} 0
|
| 91 |
|
|
|
| 92 |
|
|
tipglow sphere atip
|
| 93 |
|
|
0
|
| 94 |
|
|
0
|
| 95 |
|
|
4 ${ cx1 } ${ cy1 } ${ cz1 } ${psiz/7}
|
| 96 |
|
|
|
| 97 |
|
|
void brightfunc dgpat
|
| 98 |
|
|
2 dirfunc ambpos.cal
|
| 99 |
|
|
0
|
| 100 |
|
|
9 ${ px } ${ py } ${ pz } ${ nx } ${ ny } ${ nz } ${ dgx } ${ dgy } ${ dgz }
|
| 101 |
|
|
|
| 102 |
|
|
dgpat glow dgval
|
| 103 |
|
|
0
|
| 104 |
|
|
0
|
| 105 |
|
|
4 ${avr} ${avg} ${avb} 0
|
| 106 |
|
|
|
| 107 |
|
|
dgval ring dgdisk${recno}a
|
| 108 |
|
|
0
|
| 109 |
|
|
0
|
| 110 |
|
|
8
|
| 111 |
|
|
${ px+dgx*.0001 } ${ py+dgy*.0001 } ${ pz+dgz*.0001 }
|
| 112 |
|
|
${ dgx } ${ dgy } ${ dgz }
|
| 113 |
|
|
0 ${ r0/2 }
|
| 114 |
|
|
|
| 115 |
|
|
dgval ring dgdisk${recno}b
|
| 116 |
|
|
0
|
| 117 |
|
|
0
|
| 118 |
|
|
8
|
| 119 |
|
|
${ px-dgx*.0001 } ${ py-dgy*.0001 } ${ pz-dgz*.0001 }
|
| 120 |
|
|
${ -dgx } ${ -dgy } ${ -dgz }
|
| 121 |
|
|
0 ${ r0/2 }
|
| 122 |
|
|
';
|
| 123 |
|
|
$outfmt .= $dirgradfmt if ($dodirgrad);
|
| 124 |
|
|
# Load & convert ambient values
|
| 125 |
|
|
print "# Output produced by: $savedARGV\n";
|
| 126 |
|
|
system "lookamb -h -d $ARGV[0] | rcalc -e 'LV:$lvlsel;SF:$scale' -f rambpos.cal -o '$outfmt'\n";
|
| 127 |
|
|
exit;
|