Mercurial > hg > Members > kono > Cerium
annotate TaskManager/Test/test_render/tools/create_sglist.pl @ 321:f64d75473f95
merge 317
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 10 Jun 2009 15:23:25 +0900 |
parents | 7efc5ede2c03 |
children | a18ded47c5dd |
rev | line source |
---|---|
200 | 1 #!/usr/bin/perl |
196
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
2 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
3 # TODO |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
4 # 同じ名前の SceneGraph が来た時の処理 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
5 # まあ Blender の時点でそうならないように書くべきなんだが |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
6 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
7 #################################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
8 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
9 # Create SceneGraph List |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
10 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
11 # SceneGraph が記載された xml ファイルを読み込み、 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
12 # 名前に対応するID列が記述された SGList.h を生成する。 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
13 # また、名前から ID を取得するために sglist_table を生成しておく。 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
14 # sglist_table は SGList.cpp に記述する |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
15 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
16 # xml に ID を入れれば table は要らないんだが、 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
17 # xml の読み込む順番、その時々に応じて使うものと使わないもので |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
18 # ID にズレが出てくるので、Blender からの出力時点では決定できない。 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
19 # このスクリプトで xml に上書きするって手もあるけど、微妙じゃない? |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
20 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
21 # xml ファイルは複数指定可能。 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
22 # 実際に使うやつ全て指定する感じでおk |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
23 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
24 # (例) |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
25 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
26 # % cat ../xml_file/universe.xml |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
27 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
28 # <?xml version="1.0"?> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
29 # <OBJECT-3D> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
30 # <surface name="Earth" size="5952" prim="Triangle" parent="NULL"> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
31 # (省略) |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
32 # </surface> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
33 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
34 # <surface name="Moon" size="3312" prim="Triangle" parent="Earth"> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
35 # (省略) |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
36 # </surface> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
37 # <OBJECT-3D> |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
38 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
39 # % ./create_sglist.pl ../xml_file/universe.xml |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
40 # % cat SGList.h |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
41 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
42 # /* ../xml_file/universe.xml */ |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
43 # #define Earth 0 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
44 # #define Moon 1 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
45 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
46 # /* Number of Scene */ |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
47 # #define SGLIST_LENGTH 2 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
48 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
49 # /* Scene Table */ |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
50 # const char *sglist_table[SGLIST_LENGTH] = { |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
51 # "Earth", "Moon" |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
52 # }; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
53 # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
54 #################################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
55 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
56 use strict; |
321 | 57 # |
58 # to install this, | |
59 # cpan -i XML::LibXML::SAX::Generator | |
60 # | |
196
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
61 use XML::LibXML; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
62 |
321 | 63 my $outfile_h = "SGList.h"; |
64 my $outfile_c = "SGList.cpp"; | |
196
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
65 my $id = 0; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
66 my @table; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
67 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
68 ################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
69 # cretae SGList.h # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
70 ################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
71 open(FH, ">$outfile_h") || die "Error: Can't open file : $outfile_h\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
72 |
201 | 73 print FH "#ifndef INCLUDED_SGLIST\n"; |
74 print FH "#define INCLUDED_SGLIST\n\n"; | |
196
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
75 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
76 foreach (@ARGV) { |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
77 my $parser = XML::LibXML->new(); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
78 my $doc = $parser->parse_file($_); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
79 my @nodes = $doc->findnodes('//surface'); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
80 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
81 print FH "/* $_ */\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
82 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
83 foreach my $surface (@nodes) { |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
84 my $name = $surface->findvalue('@name'); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
85 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
86 $table[$id] = $name; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
87 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
88 print FH "#define $name\t $id\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
89 $id++; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
90 } |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
91 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
92 print FH "\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
93 } |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
94 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
95 print FH "/* Number of Scene */\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
96 print FH "#define SGLIST_LENGTH $id\n\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
97 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
98 print FH "/* Scene Table */\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
99 print FH "extern const char *sglist_table[SGLIST_LENGTH];\n\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
100 print FH "#endif\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
101 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
102 close(FH); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
103 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
104 ##################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
105 # cretae SGList.cpp # |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
106 ##################### |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
107 open(FH, ">$outfile_c") || die "Error: Can't open file : $outfile_c\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
108 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
109 print FH "#include \"SGList.h\"\n\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
110 print FH "const char *sglist_table[SGLIST_LENGTH] = {\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
111 print FH " \""; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
112 print FH join("\", \"", @table); |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
113 print FH "\"\n};\n"; |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
114 |
932a05a7a1db
add SceneGraphRoot, tools/create_sglist.pl
gongo@gendarme.cr.ie.u-ryukyu.ac.jp
parents:
diff
changeset
|
115 close(FH); |