#!/usr/local/bin/perl

# 
# dat2live3d: 
# 
#     [1999/08/02] OSHIRO Naoki.
# 
#     $Log:$
#

$size=250;

$n=0;
$new_index=1;
while (<>) {
    chop;
    next if /^ *#/;
    if (($x,$y,$z)=split(/ +/)) {
	$p{$n}.=" $x,$y,$z";
	$new_index=0;
    } elsif (/^ *$/) {
	if ($new_index==0) {
	    $new_index=1;
	    $n++;
	}
    }
}

print "<HTML>\n";
print "<APPLET ARCHIVE=\"live.jar\" CODE=\"Live.class\" WIDTH=$size HEIGHT=$size ALIGN=LEFT>\n";
print "<PARAM NAME=INPUT VALUE=\"\n";
print "Graphics3D[{\n";

print "Polygon[{\n";
for ($i=0; $i<$n; $i++) {
    @a=split(' ', $p{$i});
    $last_a=pop(@a);
    foreach (@a) {
	print "  {$_},\n";
    }
    print "  {$last_a}\n\n";
    print "}]";
    print ", Polygon[{" if ($i<$n-1);
    print "\n";
}

print "},\n";
print "{Lighting -> True}]\n";
print "\">\n";
print "</APPLET>\n";
print "</HTML>\n";
