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