2 # include <simgear_config.h>
5 #include <simgear/compiler.h>
15 #include "sg_binobj.hxx"
16 #include <simgear/debug/logstream.hxx>
22 int main( int argc, char **argv ) {
27 cout << "Usage: " << argv[0] << " binary_obj_file" << endl;
31 sglog().setLogLevels( SG_ALL, SG_ALERT );
34 bool result = obj.read_bin( argv[1] );
36 cout << "error loading: " << argv[1] << endl;
40 cout << "# FGFS Scenery" << endl;
41 cout << "# Version " << obj.get_version() << endl;
44 printf("# gbs %.5f %.5f %.5f %.2f\n", obj.get_gbs_center().x(),
45 obj.get_gbs_center().y(), obj.get_gbs_center().z(),
46 obj.get_gbs_radius());
49 std::vector<SGVec3d> nodes = obj.get_wgs84_nodes();
50 cout << "# vertex list" << endl;
51 for ( i = 0; i < (int)nodes.size(); ++i ) {
52 printf("v %.5f %.5f %.5f\n", nodes[i].x(), nodes[i].y(), nodes[i].z() );
56 std::vector<SGVec3f> normals = obj.get_normals();
57 cout << "# vertex normal list" << endl;
58 for ( i = 0; i < (int)normals.size(); ++i ) {
59 printf("vn %.5f %.5f %.5f\n",
60 normals[i].x(), normals[i].y(), normals[i].z() );
64 std::vector<SGVec2f> texcoords = obj.get_texcoords();
65 cout << "# texture coordinate list" << endl;
66 for ( i = 0; i < (int)texcoords.size(); ++i ) {
67 printf("vt %.5f %.5f\n",
68 texcoords[i].x(), texcoords[i].y() );
72 cout << "# geometry groups" << endl;
76 int_list vertex_index;
77 int_list normal_index;
81 string_list pt_materials = obj.get_pt_materials();
82 group_list pts_v = obj.get_pts_v();
83 group_list pts_n = obj.get_pts_n();
84 for ( i = 0; i < (int)pts_v.size(); ++i ) {
85 material = pt_materials[i];
86 vertex_index = pts_v[i];
87 normal_index = pts_n[i];
88 cout << "# usemtl " << material << endl;
90 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
91 cout << vertex_index[j] << "/" << normal_index[j] << " ";
97 string_list tri_materials = obj.get_tri_materials();
98 group_list tris_v = obj.get_tris_v();
99 group_list tris_n = obj.get_tris_n();
100 group_list tris_tc = obj.get_tris_tc();
101 for ( i = 0; i < (int)tris_v.size(); ++i ) {
102 material = tri_materials[i];
103 vertex_index = tris_v[i];
104 normal_index = tris_n[i];
105 tex_index = tris_tc[i];
106 cout << "# usemtl " << material << endl;
108 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
109 cout << vertex_index[j];
110 if ( normal_index.size() ) {
111 cout << "/" << normal_index[j];
113 cout << "/" << tex_index[j];
120 string_list strip_materials = obj.get_strip_materials();
121 group_list strips_v = obj.get_strips_v();
122 group_list strips_n = obj.get_strips_n();
123 group_list strips_tc = obj.get_strips_tc();
124 for ( i = 0; i < (int)strips_v.size(); ++i ) {
125 material = strip_materials[i];
126 vertex_index = strips_v[i];
127 normal_index = strips_n[i];
128 tex_index = strips_tc[i];
129 cout << "# usemtl " << material << endl;
131 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
132 cout << vertex_index[j];
133 if ( normal_index.size() ) {
134 cout << "/" << normal_index[j];
136 cout << "/" << tex_index[j] << " ";
142 string_list fan_materials = obj.get_fan_materials();
143 group_list fans_v = obj.get_fans_v();
144 group_list fans_n = obj.get_fans_n();
145 group_list fans_tc = obj.get_fans_tc();
146 for ( i = 0; i < (int)fans_v.size(); ++i ) {
147 material = fan_materials[i];
148 vertex_index = fans_v[i];
149 normal_index = fans_n[i];
150 tex_index = fans_tc[i];
151 cout << "# usemtl " << material << endl;
153 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
154 cout << vertex_index[j];
155 if ( normal_index.size() ) {
156 cout << "/" << normal_index[j];
158 cout << "/" << tex_index[j] << " ";