1 // sg_binobj.hxx -- routines to read and write low level flightgear 3d objects
3 // Written by Curtis Olson, started January 2000.
5 // Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org
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.
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.
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.
25 #ifndef _SG_BINOBJ_HXX
26 #define _SG_BINOBJ_HXX
35 #include <simgear/compiler.h>
36 #include <simgear/constants.h>
37 #include <simgear/math/sg_types.hxx>
38 #include <simgear/bucket/newbucket.hxx>
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;
53 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
59 point_list wgs84_nodes;
64 string_list tri_materials;
67 string_list strip_materials;
70 string_list fan_materials;
74 inline Point3D get_gbs_center() const { return gbs_center; }
75 inline void set_gbs_center( Point3D p ) { gbs_center = p; }
77 inline float get_gbs_radius() const { return gbs_radius; }
78 inline void set_gbs_radius( float r ) { gbs_radius = r; }
80 inline point_list get_wgs84_nodes() const { return wgs84_nodes; }
81 inline void set_wgs84_nodes( point_list n ) { wgs84_nodes = n; }
83 inline point_list get_normals() const { return normals; }
84 inline void set_normals( point_list n ) { normals = n; }
86 inline point_list get_texcoords() const { return texcoords; }
87 inline void set_texcoords( point_list t ) { texcoords = t; }
89 inline group_list get_tris_v() const { return tris_v; }
90 inline void set_tris_v( group_list g ) { tris_v = g; }
91 inline group_list get_tris_tc() const { return tris_tc; }
92 inline void set_tris_tc( group_list g ) { tris_tc = g; }
93 inline string_list get_tri_materials() const { return tri_materials; }
94 inline void set_tri_materials( string_list s ) { tri_materials = s; }
96 inline group_list get_strips_v() const { return strips_v; }
97 inline void set_strips_v( group_list g ) { strips_v = g; }
98 inline group_list get_strips_tc() const { return strips_tc; }
99 inline void set_strips_tc( group_list g ) { strips_tc = g; }
100 inline string_list get_strip_materials() const { return strip_materials; }
101 inline void set_strip_materials( string_list s ) { strip_materials = s; }
103 inline group_list get_fans_v() const { return fans_v; }
104 inline void set_fans_v( group_list g ) { fans_v = g; }
105 inline group_list get_fans_tc() const { return fans_tc; }
106 inline void set_fans_tc( group_list g ) { fans_tc = g; }
107 inline string_list get_fan_materials() const { return fan_materials; }
108 inline void set_fan_materials( string_list s ) { fan_materials = s; }
113 scenery-file: magic, nobjects, object+
114 magic: "TG" + version
115 object: obj_typecode, nproperties, nelements, property+, element+
116 element: nbytes, BYTE+
117 property: prop_typecode, nbytes, BYTE+
118 obj_typecode: bounding sphere | vertices | normals | texcoords | triangles |
120 prop_typecode: material_name | ???
121 nelements: SHORT (Gives us 65536 which ought to be enough, right?)
124 nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
125 floats = 5461 vertices which is not enough for future
127 vertex: FLOAT, FLOAT, FLOAT
131 // calculate the bounding sphere. Center is the center of the
132 // tile and zero elevation
133 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
136 // read a binary file object and populate the provided structures.
137 bool sgReadBinObj( const string& file, SGBinObject* obj );
139 // write out the structures to a binary file. We assume that the
140 // groups come to us sorted by material property. If not, things
141 // don't break, but the result won't be as optimal.
142 bool sgWriteBinObj( const string& base, const string& name, const SGBucket& b,
143 const SGBinObject* obj );
145 // write out the structures to an ASCII file. We assume that the
146 // groups come to us sorted by material property. If not, things
147 // don't break, but the result won't be as optimal.
148 bool sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b,
152 #endif // _SG_BINOBJ_HXX