head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.37; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.53; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.00; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.55; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# decode_binobj.cxx

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

@ 1.3 log @Oops, try again. @ text @d160 1 a160 1