]> git.mxchange.org Git - simgear.git/blob - simgear/io/sg_binobj.hxx
Move binary file reading and writing to simgear.
[simgear.git] / simgear / io / sg_binobj.hxx
1 // sg_binobj.hxx -- routines to read and write low level flightgear 3d objects
2 //
3 // Written by Curtis Olson, started January 2000.
4 //
5 // Copyright (C) 2000  Curtis L. Olson  - curt@flightgear.org
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 //
21 // $Id$
22 //
23
24
25 #ifndef _SG_BINOBJ_HXX
26 #define _SG_BINOBJ_HXX
27
28
29 #ifdef HAVE_CONFIG_H
30 #include <config.h>
31 #endif
32
33 #include <plib/sg.h>
34
35 #include <simgear/compiler.h>
36 #include <simgear/constants.h>
37
38 #include <stdio.h>
39 #include <time.h>
40
41 #include <list>
42 #include STL_STRING
43
44 #include <simgear/math/sg_types.hxx>
45
46
47 typedef vector < int_list > group_list;
48 typedef group_list::iterator group_list_iterator;
49 typedef group_list::const_iterator const_group_list_iterator;
50
51
52 #define SG_FILE_MAGIC_NUMBER  ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
53
54
55 /*
56    scenery-file: magic, nobjects, object+
57    magic: "TG" + version
58    object: obj_typecode, nproperties, nelements, property+, element+
59    element: nbytes, BYTE+
60    property: prop_typecode, nbytes, BYTE+
61    obj_typecode: bounding sphere | vertices | normals | texcoords | triangles |
62                 fans | strips 
63    prop_typecode: material_name | ???
64    nelements: SHORT (Gives us 65536 which ought to be enough, right?)
65    nproperties: SHORT
66    *_typecode: CHAR
67    nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
68                     floats = 5461 vertices which is not enough for future
69                     growth)
70    vertex: FLOAT, FLOAT, FLOAT
71 */
72
73
74 // calculate the bounding sphere.  Center is the center of the
75 // tile and zero elevation
76 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
77
78
79 // write out the structures to an ASCII file.  We assume that the
80 // groups come to us sorted by material property.  If not, things
81 // don't break, but the result won't be as optimal.
82 void sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b,
83                       Point3D gbs_center, float gbs_radius,
84                       const point_list& wgs84_nodes, const point_list& normals,
85                       const point_list& texcoords, 
86                       const group_list& tris_v, const group_list& tris_tc, 
87                       const string_list& tri_materials,
88                       const group_list& strips_v, const group_list& strips_tc, 
89                       const string_list& strip_materials,
90                       const group_list& fans_v, const group_list& fans_tc,
91                       const string_list& fan_materials );
92
93
94 // read a binary file object and populate the provided structures.
95 void sgReadBinObj( const string& file,
96                     Point3D &gbs_center, float *gbs_radius,
97                     point_list& wgs84_nodes, point_list& normals,
98                     point_list& texcoords, 
99                     group_list& tris_v, group_list& tris_tc, 
100                     string_list& tri_materials,
101                     group_list& strips_v, group_list& strips_tc, 
102                     string_list& strip_materials,
103                     group_list& fans_v, group_list& fans_tc,
104                     string_list& fan_materials );
105
106 // write out the structures to a binary file.  We assume that the
107 // groups come to us sorted by material property.  If not, things
108 // don't break, but the result won't be as optimal.
109 void sgWriteBinObj( const string& base, const string& name, const SGBucket& b,
110                     Point3D gbs_center, float gbs_radius,
111                     const point_list& wgs84_nodes, const point_list& normals,
112                     const point_list& texcoords, 
113                     const group_list& tris_v, const group_list& tris_tc, 
114                     const string_list& tri_materials,
115                     const group_list& strips_v, const group_list& strips_tc, 
116                     const string_list& strip_materials,
117                     const group_list& fans_v, const group_list& fans_tc,
118                     const string_list& fan_materials );
119
120
121 #endif // _SG_BINOBJ_HXX