]> git.mxchange.org Git - simgear.git/blob - simgear/io/decode_binobj.cxx
2cae546d5b926c07e0b0859dd9f46e45309e3495
[simgear.git] / simgear / io / decode_binobj.cxx
1 #include <simgear/compiler.h>
2
3 #include <unistd.h>
4 #include STL_IOSTREAM
5
6 #if !defined(SG_HAVE_NATIVE_SGI_COMPILERS)
7 SG_USING_STD(cout);
8 SG_USING_STD(endl);
9 #endif
10
11 #include "sg_binobj.hxx"
12
13
14 int main( int argc, char **argv ) {
15     int i, j;
16
17     // check usage
18     if ( argc != 2 ) {
19         cout << "Usage: " << argv[0] << " binary_obj_file" << endl;
20     }
21
22     SGBinObject obj;
23     bool result = obj.read_bin( argv[1] );
24     if ( !result ) {
25         cout << "error loading: " << argv[1] << endl;
26         exit(-1);
27     }
28
29     cout << "# FGFS Scenery" << endl;
30     cout << "# Version " << obj.get_version() << endl;
31     cout << endl;
32
33     printf("# gbs %.5f %.5f %.5f %.2f\n", obj.get_gbs_center().x(), 
34            obj.get_gbs_center().y(), obj.get_gbs_center().z(),
35            obj.get_gbs_radius());
36     cout << endl;
37
38     point_list nodes = obj.get_wgs84_nodes();
39     cout << "# vertex list" << endl;
40     for ( i = 0; i < (int)nodes.size(); ++i ) {
41         printf("v %.5f %.5f %.5f\n", nodes[i].x(), nodes[i].y(), nodes[i].z() );
42     }
43     cout << endl;
44
45     point_list normals = obj.get_normals();
46     cout << "# vertex normal list" << endl;
47     for ( i = 0; i < (int)normals.size(); ++i ) {
48         printf("vn %.5f %.5f %.5f\n",
49                normals[i].x(), normals[i].y(), normals[i].z() );
50     }
51     cout << endl;
52
53     point_list texcoords = obj.get_texcoords();
54     cout << "# texture coordinate list" << endl;
55     for ( i = 0; i < (int)texcoords.size(); ++i ) {
56         printf("vt %.5f %.5f\n",
57                texcoords[i].x(), texcoords[i].y() );
58     }
59     cout << endl;
60
61     cout << "# triangle groups" << endl;
62     cout << endl;
63
64     string material;
65     int_list vertex_index;
66     int_list tex_index;
67
68     // generate triangles
69     string_list tri_materials = obj.get_tri_materials();
70     group_list tris_v = obj.get_tris_v();
71     group_list tris_tc = obj.get_tris_tc();
72     for ( i = 0; i < (int)tris_v.size(); ++i ) {
73         material = tri_materials[i];
74         vertex_index = tris_v[i];
75         tex_index = tris_tc[i];
76         cout << "# usemtl " << material << endl;
77         cout << "f ";
78         for ( j = 0; j < (int)vertex_index.size(); ++j ) {
79             cout << vertex_index[j] << "/" << tex_index[j] << " ";
80         }
81         cout << endl;
82     }
83
84     // generate strips
85     string_list strip_materials = obj.get_strip_materials();
86     group_list strips_v = obj.get_strips_v();
87     group_list strips_tc = obj.get_strips_tc();
88     for ( i = 0; i < (int)strips_v.size(); ++i ) {
89         material = strip_materials[i];
90         vertex_index = strips_v[i];
91         tex_index = strips_tc[i];
92         cout << "# usemtl " << material << endl;
93         cout << "ts ";
94         for ( j = 0; j < (int)vertex_index.size(); ++j ) {
95             cout << vertex_index[j] << "/" << tex_index[j] << " ";
96         }
97         cout << endl;
98     }
99
100     // generate fans
101     string_list fan_materials = obj.get_fan_materials();
102     group_list fans_v = obj.get_fans_v();
103     group_list fans_tc = obj.get_fans_tc();
104     for ( i = 0; i < (int)fans_v.size(); ++i ) {
105         material = fan_materials[i];
106         vertex_index = fans_v[i];
107         tex_index = fans_tc[i];
108         cout << "# usemtl " << material << endl;
109         cout << "tf ";
110         for ( j = 0; j < (int)vertex_index.size(); ++j ) {
111             cout << vertex_index[j] << "/" << tex_index[j] << " ";
112         }
113         cout << endl;
114     }
115 }