1 | #!/usr/bin/perl |
---|
2 | |
---|
3 | # Read the whole file |
---|
4 | $file = $ARGV[0] or $file = 'building0010'; |
---|
5 | |
---|
6 | open(INFO, $file.'.wrl'); |
---|
7 | @WholeWrl = <INFO>; |
---|
8 | close(INFO); |
---|
9 | $IndexedFaceSetStart = 0; |
---|
10 | $IndexedFaceSetEnd = 0; |
---|
11 | $TextureCoordinateStart = 0; |
---|
12 | $TextureCoordinateEnd = 0; |
---|
13 | |
---|
14 | if (1) |
---|
15 | { |
---|
16 | for ( $i = 0; $i < @WholeWrl; ++$i) |
---|
17 | { |
---|
18 | if ( $WholeWrl[$i] =~ /geometry IndexedFaceSet {/) |
---|
19 | { |
---|
20 | print "Find IndexedFaceSetStart"."\n" ; |
---|
21 | $IndexedFaceSetStart = $i+3; |
---|
22 | print @WholeWrl[$IndexedFaceSetStart]; |
---|
23 | } |
---|
24 | elsif ( $WholeWrl[$i] =~ /texCoord TextureCoordinate {/) |
---|
25 | { |
---|
26 | print "Find TextureCoordinateStart"."\n" ; |
---|
27 | $TextureCoordinateStart = $i+2; |
---|
28 | print @WholeWrl[$TextureCoordinateStart]; |
---|
29 | } |
---|
30 | elsif ($WholeWrl[$i] =~ /]/) |
---|
31 | { |
---|
32 | if ($IndexedFaceSetEnd == 0 && $IndexedFaceSetStart != 0) |
---|
33 | { |
---|
34 | print "Find End of IndexedFaceSet"."\n"; |
---|
35 | $IndexedFaceSetEnd = $i-1; |
---|
36 | print @WholeWrl[$IndexedFaceSetEnd]; |
---|
37 | } |
---|
38 | if ($TextureCoordinateEnd == 0 && $TextureCoordinateStart != 0) |
---|
39 | { |
---|
40 | print "Find End of TextureCoordinate"."\n"; |
---|
41 | $TextureCoordinateEnd = $i-1; |
---|
42 | print @WholeWrl[$TextureCoordinateEnd]; |
---|
43 | } |
---|
44 | } |
---|
45 | } |
---|
46 | @IndexedFaceSet = @WholeWrl[$IndexedFaceSetStart..$IndexedFaceSetEnd]; |
---|
47 | # clear up the data |
---|
48 | for ($i = 0; $i < @IndexedFaceSet; ++$i) |
---|
49 | { |
---|
50 | $IndexedFaceSet[$i] =~ s/,//; |
---|
51 | } |
---|
52 | $OutIndexedFaceSetFile = 'IndexedFaceSet_'.$file; |
---|
53 | open(INFO, ">$OutIndexedFaceSetFile"); |
---|
54 | print INFO @IndexedFaceSet; |
---|
55 | close(INFO); |
---|
56 | |
---|
57 | @TextureCoordinate = @WholeWrl[$TextureCoordinateStart..$TextureCoordinateEnd]; |
---|
58 | for ($i = 0; $i < @TextureCoordinate; ++$i) |
---|
59 | { |
---|
60 | $TextureCoordinate[$i] =~ s/,//; |
---|
61 | } |
---|
62 | $OutTextureCoordinateFile = 'TextureCoordinate_'.$file; |
---|
63 | open(INFO, ">$OutTextureCoordinateFile"); |
---|
64 | print INFO @TextureCoordinate; |
---|
65 | close(INFO); |
---|
66 | |
---|
67 | } |
---|