3 * Routines to read and write the low level (binary) simgear 3d object format.
6 // Written by Curtis Olson, started January 2000.
8 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
10 // This program is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU General Public License as published by
12 // the Free Software Foundation; either version 2 of the License, or
13 // (at your option) any later version.
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #ifndef _SG_BINOBJ_HXX
28 #define _SG_BINOBJ_HXX
37 #include <simgear/compiler.h>
38 #include <simgear/constants.h>
39 #include <simgear/math/sg_types.hxx>
40 #include <simgear/bucket/newbucket.hxx>
50 /** STL Structure used to store object information */
51 typedef vector < int_list > group_list;
52 typedef group_list::iterator group_list_iterator;
53 typedef group_list::const_iterator const_group_list_iterator;
56 /** Magic Number for our file format */
57 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
61 * A class to manipulate the simgear 3d object format.
62 * This class provides functionality to both read and write the binary format.
64 * Here is a really quick overview of the file syntax:
66 * - scenery-file: magic, nobjects, object+
68 * - magic: "TG" + version
70 * - object: obj_typecode, nproperties, nelements, property+, element+
72 * - element: nbytes, BYTE+
74 * - property: prop_typecode, nbytes, BYTE+
76 * - obj_typecode: bounding sphere | vertices | normals | texcoords |
77 * triangles | fans | strips
79 * - prop_typecode: material_name | ???
81 * - nelements: SHORT (Gives us 65536 which ought to be enough, right?)
83 * - nproperties: SHORT
87 * - nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
88 * floats = 5461 vertices which is not enough for future
91 * - vertex: FLOAT, FLOAT, FLOAT
94 unsigned short version;
98 point_list wgs84_nodes;
100 point_list texcoords;
103 string_list tri_materials;
105 group_list strips_tc;
106 string_list strip_materials;
109 string_list fan_materials;
113 inline unsigned short get_version() const { return version; }
115 inline Point3D get_gbs_center() const { return gbs_center; }
116 inline void set_gbs_center( Point3D p ) { gbs_center = p; }
118 inline float get_gbs_radius() const { return gbs_radius; }
119 inline void set_gbs_radius( float r ) { gbs_radius = r; }
121 inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
122 inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
124 inline point_list get_normals() const { return normals; }
125 inline void set_normals( point_list n ) { normals = n; }
127 inline point_list get_texcoords() const { return texcoords; }
128 inline void set_texcoords( point_list t ) { texcoords = t; }
130 inline group_list get_tris_v() const { return tris_v; }
131 inline void set_tris_v( group_list g ) { tris_v = g; }
132 inline group_list get_tris_tc() const { return tris_tc; }
133 inline void set_tris_tc( group_list g ) { tris_tc = g; }
134 inline string_list get_tri_materials() const { return tri_materials; }
135 inline void set_tri_materials( string_list s ) { tri_materials = s; }
137 inline group_list get_strips_v() const { return strips_v; }
138 inline void set_strips_v( group_list g ) { strips_v = g; }
139 inline group_list get_strips_tc() const { return strips_tc; }
140 inline void set_strips_tc( group_list g ) { strips_tc = g; }
141 inline string_list get_strip_materials() const { return strip_materials; }
142 inline void set_strip_materials( string_list s ) { strip_materials = s; }
144 inline group_list get_fans_v() const { return fans_v; }
145 inline void set_fans_v( group_list g ) { fans_v = g; }
146 inline group_list get_fans_tc() const { return fans_tc; }
147 inline void set_fans_tc( group_list g ) { fans_tc = g; }
148 inline string_list get_fan_materials() const { return fan_materials; }
149 inline void set_fan_materials( string_list s ) { fan_materials = s; }
152 * Read a binary file object and populate the provided structures.
153 * @param file input file name
154 * @return result of read
156 bool read_bin( const string& file );
159 * Write out the structures to a binary file. We assume that the
160 * groups come to us sorted by material property. If not, things
161 * don't break, but the result won't be as optimal.
162 * @param base name of output path
163 * @param name name of output file
164 * @param b bucket for object location
165 * @return result of write
167 bool write_bin( const string& base, const string& name, const SGBucket& b );
170 * Write out the structures to an ASCII file. We assume that the
171 * groups come to us sorted by material property. If not, things
172 * don't break, but the result won't be as optimal.
173 * @param base name of output path
174 * @param name name of output file
175 * @param b bucket for object location
176 * @return result of write
178 bool write_ascii( const string& base, const string& name,
184 * \relates SGBinObject
185 * Calculate the bounding sphere of a set of nodes.
186 * Center is the center of the tile and zero elevation.
187 * @param center center of our bounding radius
188 * @param wgs84_nodes list of points in wgs84 coordinates
191 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
194 #endif // _SG_BINOBJ_HXX