]> git.mxchange.org Git - simgear.git/blob - simgear/io/sg_binobj.hxx
Additional bug fixes after testing.
[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 #include <simgear/math/sg_types.hxx>
38 #include <simgear/bucket/newbucket.hxx>
39
40 #include <stdio.h>
41 #include <time.h>
42
43 #include <list>
44 #include STL_STRING
45
46
47
48 typedef vector < int_list > group_list;
49 typedef group_list::iterator group_list_iterator;
50 typedef group_list::const_iterator const_group_list_iterator;
51
52
53 #define SG_FILE_MAGIC_NUMBER  ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
54
55
56 /*
57    scenery-file: magic, nobjects, object+
58    magic: "TG" + version
59    object: obj_typecode, nproperties, nelements, property+, element+
60    element: nbytes, BYTE+
61    property: prop_typecode, nbytes, BYTE+
62    obj_typecode: bounding sphere | vertices | normals | texcoords | triangles |
63                 fans | strips 
64    prop_typecode: material_name | ???
65    nelements: SHORT (Gives us 65536 which ought to be enough, right?)
66    nproperties: SHORT
67    *_typecode: CHAR
68    nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
69                     floats = 5461 vertices which is not enough for future
70                     growth)
71    vertex: FLOAT, FLOAT, FLOAT
72 */
73
74
75 // calculate the bounding sphere.  Center is the center of the
76 // tile and zero elevation
77 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
78
79
80 // write out the structures to an ASCII file.  We assume that the
81 // groups come to us sorted by material property.  If not, things
82 // don't break, but the result won't be as optimal.
83 bool sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b,
84                       Point3D gbs_center, float gbs_radius,
85                       const point_list& wgs84_nodes, const point_list& normals,
86                       const point_list& texcoords, 
87                       const group_list& tris_v, const group_list& tris_tc, 
88                       const string_list& tri_materials,
89                       const group_list& strips_v, const group_list& strips_tc, 
90                       const string_list& strip_materials,
91                       const group_list& fans_v, const group_list& fans_tc,
92                       const string_list& fan_materials );
93
94
95 // read a binary file object and populate the provided structures.
96 bool sgReadBinObj( const string& file,
97                     Point3D &gbs_center, float *gbs_radius,
98                     point_list& wgs84_nodes, point_list& normals,
99                     point_list& texcoords, 
100                     group_list& tris_v, group_list& tris_tc, 
101                     string_list& tri_materials,
102                     group_list& strips_v, group_list& strips_tc, 
103                     string_list& strip_materials,
104                     group_list& fans_v, group_list& fans_tc,
105                     string_list& fan_materials );
106
107 // write out the structures to a binary file.  We assume that the
108 // groups come to us sorted by material property.  If not, things
109 // don't break, but the result won't be as optimal.
110 bool sgWriteBinObj( const string& base, const string& name, const SGBucket& b,
111                     Point3D gbs_center, float gbs_radius,
112                     const point_list& wgs84_nodes, const point_list& normals,
113                     const point_list& texcoords, 
114                     const group_list& tris_v, const group_list& tris_tc, 
115                     const string_list& tri_materials,
116                     const group_list& strips_v, const group_list& strips_tc, 
117                     const string_list& strip_materials,
118                     const group_list& fans_v, const group_list& fans_tc,
119                     const string_list& fan_materials );
120
121
122 #endif // _SG_BINOBJ_HXX