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
33 #include <simgear/compiler.h>
34 #include <simgear/constants.h>
35 #include <simgear/math/sg_types.hxx>
36 #include <simgear/bucket/newbucket.hxx>
46 /** STL Structure used to store object information */
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;
52 /** Magic Number for our file format */
53 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
57 * A class to manipulate the simgear 3d object format.
58 * This class provides functionality to both read and write the binary format.
60 * Here is a really quick overview of the file syntax:
62 * - scenery-file: magic, nobjects, object+
64 * - magic: "TG" + version
66 * - object: obj_typecode, nproperties, nelements, property+, element+
68 * - element: nbytes, BYTE+
70 * - property: prop_typecode, nbytes, BYTE+
72 * - obj_typecode: bounding sphere | vertices | normals | texcoords |
73 * triangles | fans | strips
75 * - prop_typecode: material_name | ???
77 * - nelements: SHORT (Gives us 65536 which ought to be enough, right?)
79 * - nproperties: SHORT
83 * - nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
84 * floats = 5461 vertices which is not enough for future
87 * - vertex: FLOAT, FLOAT, FLOAT
90 unsigned short version;
94 point_list wgs84_nodes;
99 string_list tri_materials;
101 group_list strips_tc;
102 string_list strip_materials;
105 string_list fan_materials;
109 inline unsigned short get_version() const { return version; }
111 inline Point3D get_gbs_center() const { return gbs_center; }
112 inline void set_gbs_center( Point3D p ) { gbs_center = p; }
114 inline float get_gbs_radius() const { return gbs_radius; }
115 inline void set_gbs_radius( float r ) { gbs_radius = r; }
117 inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
118 inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
120 inline point_list get_normals() const { return normals; }
121 inline void set_normals( point_list n ) { normals = n; }
123 inline point_list get_texcoords() const { return texcoords; }
124 inline void set_texcoords( point_list t ) { texcoords = t; }
126 inline group_list get_tris_v() const { return tris_v; }
127 inline void set_tris_v( group_list g ) { tris_v = g; }
128 inline group_list get_tris_tc() const { return tris_tc; }
129 inline void set_tris_tc( group_list g ) { tris_tc = g; }
130 inline string_list get_tri_materials() const { return tri_materials; }
131 inline void set_tri_materials( string_list s ) { tri_materials = s; }
133 inline group_list get_strips_v() const { return strips_v; }
134 inline void set_strips_v( group_list g ) { strips_v = g; }
135 inline group_list get_strips_tc() const { return strips_tc; }
136 inline void set_strips_tc( group_list g ) { strips_tc = g; }
137 inline string_list get_strip_materials() const { return strip_materials; }
138 inline void set_strip_materials( string_list s ) { strip_materials = s; }
140 inline group_list get_fans_v() const { return fans_v; }
141 inline void set_fans_v( group_list g ) { fans_v = g; }
142 inline group_list get_fans_tc() const { return fans_tc; }
143 inline void set_fans_tc( group_list g ) { fans_tc = g; }
144 inline string_list get_fan_materials() const { return fan_materials; }
145 inline void set_fan_materials( string_list s ) { fan_materials = s; }
148 * Read a binary file object and populate the provided structures.
149 * @param file input file name
150 * @return result of read
152 bool read_bin( const string& file );
155 * Write out the structures to a binary file. We assume that the
156 * groups come to us sorted by material property. If not, things
157 * don't break, but the result won't be as optimal.
158 * @param base name of output path
159 * @param name name of output file
160 * @param b bucket for object location
161 * @return result of write
163 bool write_bin( const string& base, const string& name, const SGBucket& b );
166 * Write out the structures to an ASCII file. We assume that the
167 * groups come to us sorted by material property. If not, things
168 * don't break, but the result won't be as optimal.
169 * @param base name of output path
170 * @param name name of output file
171 * @param b bucket for object location
172 * @return result of write
174 bool write_ascii( const string& base, const string& name,
180 * \relates SGBinObject
181 * Calculate the bounding sphere of a set of nodes.
182 * Center is the center of the tile and zero elevation.
183 * @param center center of our bounding radius
184 * @param wgs84_nodes list of points in wgs84 coordinates
187 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
190 #endif // _SG_BINOBJ_HXX