Mercurial > hg > Game > Cerium
comparison old/tmp/revers.pl @ 612:fb88a682109e draft
add revers.pl
author | yutaka@henri.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 12 Nov 2009 17:00:08 +0900 (2009-11-12) |
parents | |
children |
comparison
equal
deleted
inserted
replaced
611:e4c355211bd7 | 612:fb88a682109e |
---|---|
1 #!/usr/bin/perl | |
2 | |
3 # fix Cerium xml normal vector | |
4 | |
5 my $i = -1; | |
6 my (@x,@y,@z); | |
7 my @cord; | |
8 my $flag = 0; | |
9 my $fix = 1; | |
10 | |
11 sub v { | |
12 print "$x[0] $y[0] $z[0]\n"; | |
13 print "$x[1] $y[1] $z[1]\n"; | |
14 print "$x[2] $y[2] $z[2]\n"; | |
15 } | |
16 | |
17 sub outer { | |
18 my ($ax,$ay,$az) = ( | |
19 $x[1]-$x[0], | |
20 $y[1]-$y[0], | |
21 $z[1]-$z[0], | |
22 ); | |
23 my ($bx,$by,$bz) = ( | |
24 $x[2]-$x[0], | |
25 $y[2]-$y[0], | |
26 $z[2]-$z[0], | |
27 ); | |
28 my ($ox,$oy,$oz) = ( | |
29 $ay*$bz - $az*$by, | |
30 -$ax*$bz + $az*$bx, | |
31 $ax*$by - $ay*$bx, | |
32 ); | |
33 my($r) = sqrt($ox*$ox+$oy*$oy+$oz*$oz); | |
34 ($ox,$oy,$oz) = ($ox/$r,$oy/$r,$oz/$r); | |
35 push(@cord, [$ox,$oy,$oz]); | |
36 # print " $ox $oy $oz\n"; | |
37 } | |
38 | |
39 if (@ARGV != 2) { | |
40 die "Usage : objectname filename\n"; | |
41 } | |
42 | |
43 my ($object, $file) = @ARGV; | |
44 open(IN, $file); | |
45 | |
46 while(<IN>) { | |
47 if (! $fix) { | |
48 if (/<sur/) { | |
49 print; | |
50 next; | |
51 } | |
52 } | |
53 if (/<normal/) { | |
54 $i= -2; | |
55 print if ($fix); | |
56 next; | |
57 } | |
58 if (/<\/normal/) { | |
59 $i = -1; | |
60 print if ($fix); | |
61 next; | |
62 } | |
63 | |
64 if (/$object/) { | |
65 $flag = 1; | |
66 } | |
67 | |
68 if (/\/$object/) { | |
69 $flag = 0; | |
70 } | |
71 | |
72 if ( $i < -1) { | |
73 if ($i== -4) { | |
74 my $cord = shift(@cord); | |
75 if ($fix) { | |
76 | |
77 if ($flag == 1) { | |
78 $cord->[0] = -$cord->[0]; | |
79 $cord->[1] = -$cord->[1]; | |
80 $cord->[2] = -$cord->[2]; | |
81 } | |
82 | |
83 print " $cord->[0] $cord->[1] $cord->[2] \n"; | |
84 print " $cord->[0] $cord->[1] $cord->[2] \n"; | |
85 print " $cord->[0] $cord->[1] $cord->[2] \n"; | |
86 | |
87 } else { | |
88 print "outer $i $cord->[0] $cord->[1] $cord->[2] \n"; | |
89 print ; | |
90 } | |
91 $i = -2; | |
92 } else { | |
93 $i--; | |
94 } | |
95 next; | |
96 } | |
97 print if ($fix); | |
98 if (/<\/coord/) { | |
99 $i = -1; | |
100 next; | |
101 } | |
102 if (/<coord/) { | |
103 @cord = (); | |
104 $i=0; | |
105 next; | |
106 } | |
107 if ($i<0) { | |
108 next; | |
109 } | |
110 if (/([-]*[.\d]+)\s+([-]*[.\d]+)\s+([-]*[.\d]+)/) { | |
111 ($x[$i],$y[$i],$z[$i]) = ($1,$2,$3); | |
112 # print "$i $_"; | |
113 if ($i==2) { | |
114 &outer; | |
115 $i = 0; | |
116 next; | |
117 } | |
118 $i++; | |
119 } else { | |
120 $i = -1; | |
121 } | |
122 } | |
123 | |
124 # end |