Mercurial > hg > Game > Cerium
changeset 612:fb88a682109e draft
add revers.pl
author | yutaka@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 12 Nov 2009 17:00:08 +0900 |
parents | e4c355211bd7 |
children | a8a825ca5945 |
files | old/tmp/revers.pl |
diffstat | 1 files changed, 124 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/old/tmp/revers.pl Thu Nov 12 17:00:08 2009 +0900 @@ -0,0 +1,124 @@ +#!/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