Mercurial > hg > Members > kono > Cerium
view old/tmp/revers.pl @ 880:f4bdf2b0d7da
[Renderer/Test/aquarium] sync aquarium (1 bug)
author | kazz <kazz@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Tue, 06 Jul 2010 23:37:11 +0900 |
parents | b0fb0272191c |
children |
line wrap: on
line source
#!/usr/bin/perl # fix Cerium xml normal vector my $i = -1; my (@x,@y,@z); my @cord; my $flag = 0; my $fix = 1; sub v { print "$x[0] $y[0] $z[0]\n"; print "$x[1] $y[1] $z[1]\n"; print "$x[2] $y[2] $z[2]\n"; } sub outer { my ($ax,$ay,$az) = ( $x[1]-$x[0], $y[1]-$y[0], $z[1]-$z[0], ); my ($bx,$by,$bz) = ( $x[2]-$x[0], $y[2]-$y[0], $z[2]-$z[0], ); my ($ox,$oy,$oz) = ( $ay*$bz - $az*$by, -$ax*$bz + $az*$bx, $ax*$by - $ay*$bx, ); my($r) = sqrt($ox*$ox+$oy*$oy+$oz*$oz); ($ox,$oy,$oz) = ($ox/$r,$oy/$r,$oz/$r); push(@cord, [$ox,$oy,$oz]); # print " $ox $oy $oz\n"; } if (@ARGV != 2) { die "Usage : objectname filename\n"; } my ($object, $file) = @ARGV; open(IN, $file); while(<IN>) { if (! $fix) { if (/<sur/) { print; next; } } if (/<normal/) { $i= -2; print if ($fix); next; } if (/<\/normal/) { $i = -1; print if ($fix); next; } if (/$object/) { $flag = 1; } if (/\/$object/) { $flag = 0; } if ( $i < -1) { if ($i== -4) { my $cord = shift(@cord); if ($fix) { if ($flag == 1) { $cord->[0] = -$cord->[0]; $cord->[1] = -$cord->[1]; $cord->[2] = -$cord->[2]; } print " $cord->[0] $cord->[1] $cord->[2] \n"; print " $cord->[0] $cord->[1] $cord->[2] \n"; print " $cord->[0] $cord->[1] $cord->[2] \n"; } else { print "outer $i $cord->[0] $cord->[1] $cord->[2] \n"; print ; } $i = -2; } else { $i--; } next; } print if ($fix); if (/<\/coord/) { $i = -1; next; } if (/<coord/) { @cord = (); $i=0; next; } if ($i<0) { next; } if (/([-]*[.\d]+)\s+([-]*[.\d]+)\s+([-]*[.\d]+)/) { ($x[$i],$y[$i],$z[$i]) = ($1,$2,$3); # print "$i $_"; if ($i==2) { &outer; $i = 0; next; } $i++; } else { $i = -1; } } # end