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>
44 #include <simgear/math/sg_types.hxx>
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 #define SG_FILE_MAGIC_NUMBER ( ('S'<<24) + ('G'<<16) + SG_BINOBJ_VERSION )
56 scenery-file: magic, nobjects, object+
58 object: obj_typecode, nproperties, nelements, property+, element+
59 element: nbytes, BYTE+
60 property: prop_typecode, nbytes, BYTE+
61 obj_typecode: bounding sphere | vertices | normals | texcoords | triangles |
63 prop_typecode: material_name | ???
64 nelements: SHORT (Gives us 65536 which ought to be enough, right?)
67 nbytes: INTEGER (If we used short here that would mean 65536 bytes = 16384
68 floats = 5461 vertices which is not enough for future
70 vertex: FLOAT, FLOAT, FLOAT
74 // calculate the bounding sphere. Center is the center of the
75 // tile and zero elevation
76 double sgCalcBoundingRadius( Point3D center, point_list& wgs84_nodes );
79 // write out the structures to an ASCII file. We assume that the
80 // groups come to us sorted by material property. If not, things
81 // don't break, but the result won't be as optimal.
82 void sgWriteAsciiObj( const string& base, const string& name, const SGBucket& b,
83 Point3D gbs_center, float gbs_radius,
84 const point_list& wgs84_nodes, const point_list& normals,
85 const point_list& texcoords,
86 const group_list& tris_v, const group_list& tris_tc,
87 const string_list& tri_materials,
88 const group_list& strips_v, const group_list& strips_tc,
89 const string_list& strip_materials,
90 const group_list& fans_v, const group_list& fans_tc,
91 const string_list& fan_materials );
94 // read a binary file object and populate the provided structures.
95 void sgReadBinObj( const string& file,
96 Point3D &gbs_center, float *gbs_radius,
97 point_list& wgs84_nodes, point_list& normals,
98 point_list& texcoords,
99 group_list& tris_v, group_list& tris_tc,
100 string_list& tri_materials,
101 group_list& strips_v, group_list& strips_tc,
102 string_list& strip_materials,
103 group_list& fans_v, group_list& fans_tc,
104 string_list& fan_materials );
106 // write out the structures to a binary file. We assume that the
107 // groups come to us sorted by material property. If not, things
108 // don't break, but the result won't be as optimal.
109 void sgWriteBinObj( const string& base, const string& name, const SGBucket& b,
110 Point3D gbs_center, float gbs_radius,
111 const point_list& wgs84_nodes, const point_list& normals,
112 const point_list& texcoords,
113 const group_list& tris_v, const group_list& tris_tc,
114 const string_list& tri_materials,
115 const group_list& strips_v, const group_list& strips_tc,
116 const string_list& strip_materials,
117 const group_list& fans_v, const group_list& fans_tc,
118 const string_list& fan_materials );
121 #endif // _SG_BINOBJ_HXX