00001 #ifdef HAVE_CONFIG_H
00002 # include <simgear_config.h>
00003 #endif
00004
00005 #include <simgear/compiler.h>
00006
00007 #include <unistd.h>
00008 #include <iostream>
00009
00010 #include "sg_binobj.hxx"
00011
00012 using std::cout;
00013 using std::endl;
00014
00015
00016 int main( int argc, char **argv ) {
00017 int i, j;
00018
00019
00020 if ( argc != 2 ) {
00021 cout << "Usage: " << argv[0] << " binary_obj_file" << endl;
00022 }
00023
00024 SGBinObject obj;
00025 bool result = obj.read_bin( argv[1] );
00026 if ( !result ) {
00027 cout << "error loading: " << argv[1] << endl;
00028 exit(-1);
00029 }
00030
00031 cout << "# FGFS Scenery" << endl;
00032 cout << "# Version " << obj.get_version() << endl;
00033 cout << endl;
00034
00035 printf("# gbs %.5f %.5f %.5f %.2f\n", obj.get_gbs_center().x(),
00036 obj.get_gbs_center().y(), obj.get_gbs_center().z(),
00037 obj.get_gbs_radius());
00038 cout << endl;
00039
00040 std::vector<SGVec3d> nodes = obj.get_wgs84_nodes();
00041 cout << "# vertex list" << endl;
00042 for ( i = 0; i < (int)nodes.size(); ++i ) {
00043 printf("v %.5f %.5f %.5f\n", nodes[i].x(), nodes[i].y(), nodes[i].z() );
00044 }
00045 cout << endl;
00046
00047 std::vector<SGVec3f> normals = obj.get_normals();
00048 cout << "# vertex normal list" << endl;
00049 for ( i = 0; i < (int)normals.size(); ++i ) {
00050 printf("vn %.5f %.5f %.5f\n",
00051 normals[i].x(), normals[i].y(), normals[i].z() );
00052 }
00053 cout << endl;
00054
00055 std::vector<SGVec2f> texcoords = obj.get_texcoords();
00056 cout << "# texture coordinate list" << endl;
00057 for ( i = 0; i < (int)texcoords.size(); ++i ) {
00058 printf("vt %.5f %.5f\n",
00059 texcoords[i].x(), texcoords[i].y() );
00060 }
00061 cout << endl;
00062
00063 cout << "# geometry groups" << endl;
00064 cout << endl;
00065
00066 string material;
00067 int_list vertex_index;
00068 int_list normal_index;
00069 int_list tex_index;
00070
00071
00072 string_list pt_materials = obj.get_pt_materials();
00073 group_list pts_v = obj.get_pts_v();
00074 group_list pts_n = obj.get_pts_n();
00075 for ( i = 0; i < (int)pts_v.size(); ++i ) {
00076 material = pt_materials[i];
00077 vertex_index = pts_v[i];
00078 normal_index = pts_n[i];
00079 cout << "# usemtl " << material << endl;
00080 cout << "pt ";
00081 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
00082 cout << vertex_index[j] << "/" << normal_index[j] << " ";
00083 }
00084 cout << endl;
00085 }
00086
00087
00088 string_list tri_materials = obj.get_tri_materials();
00089 group_list tris_v = obj.get_tris_v();
00090 group_list tris_n = obj.get_tris_n();
00091 group_list tris_tc = obj.get_tris_tc();
00092 for ( i = 0; i < (int)tris_v.size(); ++i ) {
00093 material = tri_materials[i];
00094 vertex_index = tris_v[i];
00095 normal_index = tris_n[i];
00096 tex_index = tris_tc[i];
00097 cout << "# usemtl " << material << endl;
00098 cout << "f ";
00099 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
00100 cout << vertex_index[j];
00101 if ( normal_index.size() ) {
00102 cout << "/" << normal_index[j];
00103 }
00104 cout << "/" << tex_index[j];
00105 cout << " ";
00106 }
00107 cout << endl;
00108 }
00109
00110
00111 string_list strip_materials = obj.get_strip_materials();
00112 group_list strips_v = obj.get_strips_v();
00113 group_list strips_n = obj.get_strips_n();
00114 group_list strips_tc = obj.get_strips_tc();
00115 for ( i = 0; i < (int)strips_v.size(); ++i ) {
00116 material = strip_materials[i];
00117 vertex_index = strips_v[i];
00118 normal_index = strips_n[i];
00119 tex_index = strips_tc[i];
00120 cout << "# usemtl " << material << endl;
00121 cout << "ts ";
00122 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
00123 cout << vertex_index[j];
00124 if ( normal_index.size() ) {
00125 cout << "/" << normal_index[j];
00126 }
00127 cout << "/" << tex_index[j] << " ";
00128 }
00129 cout << endl;
00130 }
00131
00132
00133 string_list fan_materials = obj.get_fan_materials();
00134 group_list fans_v = obj.get_fans_v();
00135 group_list fans_n = obj.get_fans_n();
00136 group_list fans_tc = obj.get_fans_tc();
00137 for ( i = 0; i < (int)fans_v.size(); ++i ) {
00138 material = fan_materials[i];
00139 vertex_index = fans_v[i];
00140 normal_index = fans_n[i];
00141 tex_index = fans_tc[i];
00142 cout << "# usemtl " << material << endl;
00143 cout << "tf ";
00144 for ( j = 0; j < (int)vertex_index.size(); ++j ) {
00145 cout << vertex_index[j];
00146 if ( normal_index.size() ) {
00147 cout << "/" << normal_index[j];
00148 }
00149 cout << "/" << tex_index[j] << " ";
00150 }
00151 cout << endl;
00152 }
00153 }