Panda3D
|
00001 // Filename: fltHeader.h 00002 // Created by: drose (24Aug00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #ifndef FLTHEADER_H 00016 #define FLTHEADER_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "fltBeadID.h" 00021 #include "fltVertex.h" 00022 #include "fltMaterial.h" 00023 #include "fltTexture.h" 00024 #include "fltLightSourceDefinition.h" 00025 #include "fltEyepoint.h" 00026 #include "fltTrackplane.h" 00027 #include "fltInstanceDefinition.h" 00028 00029 #include "pathReplace.h" 00030 #include "pointerTo.h" 00031 #include "filename.h" 00032 #include "dSearchPath.h" 00033 #include "distanceUnit.h" 00034 #include "pvector.h" 00035 #include "pset.h" 00036 #include "pmap.h" 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Class : FltHeader 00040 // Description : This is the first bead in the file, the top of the 00041 // bead hierarchy, and the primary interface to reading 00042 // and writing a Flt file. You always read a Flt file 00043 // by creating a header and calling read_flt(), which 00044 // fills in its children beads automatically; you write 00045 // a Flt file by creating a header, adding its children, 00046 // and calling write_flt(). 00047 //////////////////////////////////////////////////////////////////// 00048 class FltHeader : public FltBeadID { 00049 public: 00050 FltHeader(PathReplace *path_replace); 00051 00052 virtual void apply_converted_filenames(); 00053 00054 void set_path_replace(PathReplace *path_replace); 00055 PathReplace *get_path_replace(); 00056 const PathReplace *get_path_replace() const; 00057 Filename convert_path(const Filename &orig_filename, 00058 const DSearchPath &additional_path = DSearchPath()); 00059 00060 void set_flt_filename(const Filename &flt_filename); 00061 const Filename &get_flt_filename() const; 00062 00063 FltError read_flt(Filename filename); 00064 FltError read_flt(istream &in); 00065 FltError write_flt(Filename filename); 00066 FltError write_flt(ostream &out); 00067 00068 enum AttrUpdate { 00069 AU_none, 00070 AU_if_missing, 00071 AU_always 00072 }; 00073 00074 void set_auto_attr_update(AttrUpdate attr); 00075 AttrUpdate get_auto_attr_update() const; 00076 00077 enum Units { 00078 U_meters = 0, 00079 U_kilometers = 1, 00080 U_feet = 4, 00081 U_inches = 5, 00082 U_nautical_miles = 8 00083 }; 00084 00085 enum Flags { 00086 F_save_vertex_normals = 0x80000000 00087 }; 00088 00089 enum ProjectionType { 00090 PT_flat_earth = 0, 00091 PT_trapezoidal = 1, 00092 PT_round_earth = 2, 00093 PT_lambert = 3, 00094 PT_utm = 4 00095 }; 00096 00097 enum VertexStorageType { 00098 VTS_double = 1 00099 }; 00100 00101 enum DatabaseOrigin { 00102 DO_open_flight = 100, 00103 DO_dig = 200, 00104 DO_es_ct6 = 300, 00105 DO_psp = 400, 00106 DO_ge_civ = 600, 00107 DO_es_gdf = 700, 00108 }; 00109 00110 enum EarthModel { 00111 EM_wgs84 = 0, 00112 EM_wgs72 = 1, 00113 EM_bessel = 2, 00114 EM_clarke_1866 = 3, 00115 EM_nad27 = 4 00116 }; 00117 00118 int _format_revision_level; 00119 int _edit_revision_level; 00120 string _last_revision; 00121 int _next_group_id; 00122 int _next_lod_id; 00123 int _next_object_id; 00124 int _next_face_id; 00125 int _unit_multiplier; 00126 Units _vertex_units; 00127 bool _texwhite_new; 00128 unsigned int _flags; 00129 ProjectionType _projection_type; 00130 int _next_dof_id; 00131 VertexStorageType _vertex_storage_type; 00132 DatabaseOrigin _database_origin; 00133 double _sw_x, _sw_y; 00134 double _delta_x, _delta_y; 00135 int _next_sound_id; 00136 int _next_path_id; 00137 int _next_clip_id; 00138 int _next_text_id; 00139 int _next_bsp_id; 00140 int _next_switch_id; 00141 double _sw_lat, _sw_long; 00142 double _ne_lat, _ne_long; 00143 double _origin_lat, _origin_long; 00144 double _lambert_upper_lat, _lambert_lower_lat; 00145 int _next_light_id; 00146 int _next_road_id; 00147 int _next_cat_id; 00148 EarthModel _earth_model; 00149 int _next_adaptive_id; 00150 int _next_curve_id; 00151 double _delta_z; 00152 double _radius; 00153 int _next_mesh_id; 00154 00155 public: 00156 int get_flt_version() const; 00157 void set_flt_version(int version); 00158 static int min_flt_version(); 00159 static int max_flt_version(); 00160 bool check_version() const; 00161 00162 DistanceUnit get_units() const; 00163 00164 // Accessors into the instance pool. 00165 bool has_instance(int instance_index) const; 00166 FltInstanceDefinition *get_instance(int instance_index) const; 00167 void clear_instances(); 00168 void add_instance(FltInstanceDefinition *instance); 00169 void remove_instance(int instance_index); 00170 00171 00172 // Accessors into the vertex palette. 00173 int get_num_vertices() const; 00174 FltVertex *get_vertex(int n) const; 00175 void clear_vertices(); 00176 void add_vertex(FltVertex *vertex); 00177 00178 FltVertex *get_vertex_by_offset(int offset); 00179 int get_offset_by_vertex(FltVertex *vertex); 00180 00181 00182 // Accessors into the color palette. This is read-only; why would 00183 // you want to mess with building a new color palette? 00184 int get_num_colors() const; 00185 LColor get_color(int color_index) const; 00186 LRGBColor get_rgb(int color_index) const; 00187 bool has_color_name(int color_index) const; 00188 string get_color_name(int color_index) const; 00189 00190 int get_closest_color(const LColor &color) const; 00191 int get_closest_rgb(const LRGBColor &color) const; 00192 00193 int get_num_color_entries() const; 00194 int get_num_color_shades() const; 00195 00196 // These functions are mainly used behind-the-scenes to decode the 00197 // strange forest of color options defined for faces and vertices. 00198 LColor get_color(int color_index, bool use_packed_color, 00199 const FltPackedColor &packed_color, 00200 int transparency); 00201 LRGBColor get_rgb(int color_index, bool use_packed_color, 00202 const FltPackedColor &packed_color); 00203 00204 // Accessors into the material palette. 00205 bool has_material(int material_index) const; 00206 FltMaterial *get_material(int material_index) const; 00207 void clear_materials(); 00208 void add_material(FltMaterial *material); 00209 void remove_material(int material_index); 00210 00211 00212 // Accessors into the texture palette. 00213 bool has_texture(int texture_index) const; 00214 FltTexture *get_texture(int texture_index) const; 00215 void clear_textures(); 00216 void add_texture(FltTexture *texture); 00217 void remove_texture(int texture_index); 00218 00219 00220 // Accessors into the light source palette. 00221 bool has_light_source(int light_index) const; 00222 FltLightSourceDefinition *get_light_source(int light_index) const; 00223 void clear_light_sources(); 00224 void add_light_source(FltLightSourceDefinition *light_source); 00225 void remove_light_source(int light_index); 00226 00227 00228 // Accessors into the eyepoint/trackplane palette. 00229 bool got_eyepoint_trackplane_palette() const; 00230 void set_eyepoint_trackplane_palette(bool flag); 00231 00232 int get_num_eyepoints() const; 00233 FltEyepoint *get_eyepoint(int n); 00234 int get_num_trackplanes() const; 00235 FltTrackplane *get_trackplane(int n); 00236 00237 private: 00238 // Instance subtrees. These are standalone subtrees, which may be 00239 // referenced by various points in the hierarchy, stored by instance 00240 // ID number. 00241 typedef pmap<int, PT(FltInstanceDefinition)> Instances; 00242 Instances _instances; 00243 00244 00245 // Support for the vertex palette. 00246 int update_vertex_lookups(); 00247 00248 typedef pvector<PT(FltVertex)> Vertices; 00249 typedef pset<FltVertex *> UniqueVertices; 00250 00251 typedef pmap<int, FltVertex *> VerticesByOffset; 00252 typedef pmap<FltVertex *, int> OffsetsByVertex; 00253 00254 Vertices _vertices; 00255 UniqueVertices _unique_vertices; 00256 VerticesByOffset _vertices_by_offset; 00257 OffsetsByVertex _offsets_by_vertex; 00258 00259 bool _vertex_lookups_stale; 00260 00261 // This is maintained while the header is being read, to map the 00262 // vertices to their corresponding offsets in the vertex palette. 00263 int _current_vertex_offset; 00264 00265 00266 // Support for the color palette. 00267 bool _got_color_palette; 00268 typedef pvector<FltPackedColor> Colors; 00269 typedef pmap<int, string> ColorNames; 00270 Colors _colors; 00271 ColorNames _color_names; 00272 00273 00274 // Support for the material palette. 00275 bool _got_14_material_palette; 00276 typedef pmap<int, PT(FltMaterial)> Materials; 00277 Materials _materials; 00278 int _next_material_index; 00279 00280 00281 // Support for the texture palette. 00282 AttrUpdate _auto_attr_update; 00283 typedef pmap<int, PT(FltTexture)> Textures; 00284 Textures _textures; 00285 int _next_pattern_index; 00286 00287 00288 // Support for the light source palette. 00289 typedef pmap<int, PT(FltLightSourceDefinition)> LightSources; 00290 LightSources _light_sources; 00291 00292 00293 // Support for the eyepoint/trackplane palette. 00294 bool _got_eyepoint_trackplane_palette; 00295 FltEyepoint _eyepoints[10]; 00296 FltTrackplane _trackplanes[10]; 00297 00298 // This pointer is used to resolve references in the flt file. 00299 PT(PathReplace) _path_replace; 00300 Filename _flt_filename; 00301 00302 protected: 00303 virtual bool extract_record(FltRecordReader &reader); 00304 virtual bool extract_ancillary(FltRecordReader &reader); 00305 00306 virtual bool build_record(FltRecordWriter &writer) const; 00307 virtual FltError write_ancillary(FltRecordWriter &writer) const; 00308 00309 private: 00310 bool extract_vertex(FltRecordReader &reader); 00311 bool extract_color_palette(FltRecordReader &reader); 00312 bool extract_material(FltRecordReader &reader); 00313 bool extract_14_material_palette(FltRecordReader &reader); 00314 bool extract_texture(FltRecordReader &reader); 00315 bool extract_texture_map(FltRecordReader &reader); 00316 bool extract_light_source(FltRecordReader &reader); 00317 bool extract_eyepoint_palette(FltRecordReader &reader); 00318 00319 FltError write_vertex_palette(FltRecordWriter &writer) const; 00320 FltError write_color_palette(FltRecordWriter &writer) const; 00321 FltError write_material_palette(FltRecordWriter &writer) const; 00322 FltError write_texture_palette(FltRecordWriter &writer) const; 00323 FltError write_light_source_palette(FltRecordWriter &writer) const; 00324 FltError write_eyepoint_palette(FltRecordWriter &writer) const; 00325 00326 public: 00327 virtual TypeHandle get_type() const { 00328 return get_class_type(); 00329 } 00330 virtual TypeHandle force_init_type() {init_type(); return get_class_type();} 00331 static TypeHandle get_class_type() { 00332 return _type_handle; 00333 } 00334 static void init_type() { 00335 FltBeadID::init_type(); 00336 register_type(_type_handle, "FltHeader", 00337 FltBeadID::get_class_type()); 00338 } 00339 00340 private: 00341 static TypeHandle _type_handle; 00342 }; 00343 00344 #endif 00345 00346