Reading the Inventor Mentor, I found out that Normals can be generated
on the fly for all vertex shapes. Since all VRML nodes are vertex, I
rewrote my script to remove Normal { ... } and normalIndex [ ... ]
data. This small change removed another 25% of the file.
Real-world savings are now on the order of 75%. It has taken a 2.3M
file down to 570K. Here it is, with the caveat that you should *carefully
check* a file before assuming it's worked correctly. It probably won't
work well on hand-generated VRML, for instance.
Those of you who are intimately familiar with how all of this works,
please let me know if you think any of what my script does will cause
a problem. So far it seems to work great, but maybe there are some
hidden gotchas I don't know about...
James Waldrop (JLW3) \ [email protected] / Ubique, Inc.
Systems Administrator \ [email protected] / 657 Mission #601
http://www.ubique.com/ \ 415.896.2434 / San Francisco, CA
#!/usr/bin/perl
#
# Written Fri May 19 11:48:25 PDT 1995 by
# James Waldrop ([email protected])
#
# invoke like so: scriptname foo1.wrl foo2.wrl
# produces output like foo1.wrl.new
for ($x=-1; $x++ < $#ARGV; ) {
$file = $ARGV[$x];
if (! (-e $file) ) {
print "$file not found, skipping...\n";
next;
}
&convert($file);
}
exit;
sub convert {
local ($file) = @_;
open (OLD, $file) || die "Couldn't open $file: $!\n";
open (NEW, ">$file.new") || die "Couldn't open $file.new: $!\n";
while (<OLD>) {
$line = $_;
if (/Normal/) { while(<OLD>) { last if /}/; } $line = ""; }
if (/normalIndex/) { while(<OLD>) { last if /[]]/; } $line = ""; }
$line =~ s/[-+]?[0-9]\.[0-9]+e[+-][0-9]+/0/g; # makes an assumption
$line =~ s/([0-9]+\.[0-9]{2})[0-9]+/$1/g; # replace 2 with
$line =~ s/0\.00/0/g; # get rid of 0.00 # digits of precision
$line =~ s/[ ]+/ /g;
$line =~ s/[\t]+/ /g;
$line =~ s/^ //g;
print NEW $line;
}
close OLD;
close NEW;
}