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 )
57 scenery-file: magic, nobjects, object+
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 |
64 prop_typecode: material_name | ???
65 nelements: SHORT (Gives us 65536 which ought to be enough, right?)
68 nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
69 floats = 5461 vertices which is not enough for future
71 vertex: FLOAT, FLOAT, FLOAT
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 );
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 );
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 );
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 );
122 #endif // _SG_BINOBJ_HXX