2 # include <simgear_config.h>
5 #include <simgear/compiler.h>
14 #include "sg_binobj.hxx"
20 int main( int argc, char **argv ) {
25 cout << "Usage: " << argv[0] << " binary_obj_file" << endl;
29 bool result = obj.read_bin( argv[1] );
31 cout << "error loading: " << argv[1] << endl;
35 cout << "# FGFS Scenery" << endl;
36 cout << "# Version " << obj.get_version() << endl;
39 printf("# gbs %.5f %.5f %.5f %.2f\n", obj.get_gbs_center().x(),
40 obj.get_gbs_center().y(), obj.get_gbs_center().z(),
41 obj.get_gbs_radius());
44 std::vector<SGVec3d> nodes = obj.get_wgs84_nodes();
45 cout << "# vertex list" << endl;
46 for ( i = 0; i < (int)nodes.size(); ++i ) {
47 printf("v %.5f %.5f %.5f\n", nodes[i].x(), nodes[i].y(), nodes[i].z() );
51 std::vector<SGVec3f> normals = obj.get_normals();
52 cout << "# vertex normal list" << endl;
53 for ( i = 0; i < (int)normals.size(); ++i ) {
54 printf("vn %.5f %.5f %.5f\n",
55 normals[i].x(), normals[i].y(), normals[i].z() );
59 std::vector<SGVec2f> texcoords = obj.get_texcoords();
60 cout << "# texture coordinate list" << endl;
61 for ( i = 0; i < (int)texcoords.size(); ++i ) {
62 printf("vt %.5f %.5f\n",
63 texcoords[i].x(), texcoords[i].y() );
67 cout << "# geometry groups" << endl;
71 int_list vertex_index;
72 int_list normal_index;
76 string_list pt_materials = obj.get_pt_materials();
77 group_list pts_v = obj.get_pts_v();
78 group_list pts_n = obj.get_pts_n();
79 for ( i = 0; i < (int)pts_v.size(); ++i ) {
80 material = pt_materials[i];
81 vertex_index = pts_v[i];
82 normal_index = pts_n[i];
83 cout << "# usemtl " << material << endl;
85 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
86 cout << vertex_index[j] << "/" << normal_index[j] << " ";
92 string_list tri_materials = obj.get_tri_materials();
93 group_list tris_v = obj.get_tris_v();
94 group_list tris_n = obj.get_tris_n();
95 group_list tris_tc = obj.get_tris_tc();
96 for ( i = 0; i < (int)tris_v.size(); ++i ) {
97 material = tri_materials[i];
98 vertex_index = tris_v[i];
99 normal_index = tris_n[i];
100 tex_index = tris_tc[i];
101 cout << "# usemtl " << material << endl;
103 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
104 cout << vertex_index[j];
105 if ( normal_index.size() ) {
106 cout << "/" << normal_index[j];
108 cout << "/" << tex_index[j];
115 string_list strip_materials = obj.get_strip_materials();
116 group_list strips_v = obj.get_strips_v();
117 group_list strips_n = obj.get_strips_n();
118 group_list strips_tc = obj.get_strips_tc();
119 for ( i = 0; i < (int)strips_v.size(); ++i ) {
120 material = strip_materials[i];
121 vertex_index = strips_v[i];
122 normal_index = strips_n[i];
123 tex_index = strips_tc[i];
124 cout << "# usemtl " << material << endl;
126 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
127 cout << vertex_index[j];
128 if ( normal_index.size() ) {
129 cout << "/" << normal_index[j];
131 cout << "/" << tex_index[j] << " ";
137 string_list fan_materials = obj.get_fan_materials();
138 group_list fans_v = obj.get_fans_v();
139 group_list fans_n = obj.get_fans_n();
140 group_list fans_tc = obj.get_fans_tc();
141 for ( i = 0; i < (int)fans_v.size(); ++i ) {
142 material = fan_materials[i];
143 vertex_index = fans_v[i];
144 normal_index = fans_n[i];
145 tex_index = fans_tc[i];
146 cout << "# usemtl " << material << endl;
148 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
149 cout << vertex_index[j];
150 if ( normal_index.size() ) {
151 cout << "/" << normal_index[j];
153 cout << "/" << tex_index[j] << " ";