Panda3D
|
00001 // Filename: palettizer.h 00002 // Created by: drose (01Dec00) 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 PALETTIZER_H 00016 #define PALETTIZER_H 00017 00018 #include "pandatoolbase.h" 00019 00020 #include "txaFile.h" 00021 00022 #include "typedWritable.h" 00023 #include "eggRenderMode.h" 00024 #include "pvector.h" 00025 #include "pset.h" 00026 #include "pmap.h" 00027 00028 class PNMFileType; 00029 class EggFile; 00030 class PaletteGroup; 00031 class TextureImage; 00032 class TexturePlacement; 00033 class FactoryParams; 00034 00035 //////////////////////////////////////////////////////////////////// 00036 // Class : Palettizer 00037 // Description : This is the main engine behind egg-palettize. It 00038 // contains all of the program parameters, from the 00039 // command line or saved from a previous session, and 00040 // serves as the driving force in the actual palettizing 00041 // process. 00042 //////////////////////////////////////////////////////////////////// 00043 class Palettizer : public TypedWritable { 00044 public: 00045 Palettizer(); 00046 00047 bool get_noabs() const; 00048 void set_noabs(bool noabs); 00049 00050 bool is_valid() const; 00051 void report_pi() const; 00052 void report_statistics() const; 00053 00054 void read_txa_file(istream &txa_file, const string &txa_filename); 00055 void all_params_set(); 00056 void process_command_line_eggs(bool force_texture_read, const Filename &state_filename); 00057 void process_all(bool force_texture_read, const Filename &state_filename); 00058 void optimal_resize(); 00059 void reset_images(); 00060 void generate_images(bool redo_all); 00061 bool read_stale_eggs(bool redo_all); 00062 bool write_eggs(); 00063 00064 EggFile *get_egg_file(const string &name); 00065 bool remove_egg_file(const string &name); 00066 00067 void add_command_line_egg(EggFile *egg_file); 00068 00069 PaletteGroup *get_palette_group(const string &name); 00070 PaletteGroup *test_palette_group(const string &name) const; 00071 PaletteGroup *get_default_group(); 00072 TextureImage *get_texture(const string &name); 00073 00074 private: 00075 static const char *yesno(bool flag); 00076 00077 public: 00078 static int _pi_version; 00079 static int _min_pi_version; 00080 static int _read_pi_version; 00081 00082 enum RemapUV { 00083 RU_never, 00084 RU_group, 00085 RU_poly, 00086 RU_invalid 00087 }; 00088 00089 static RemapUV string_remap(const string &str); 00090 00091 bool _is_valid; 00092 00093 // These values are not stored in the textures.boo file, but are 00094 // specific to each session. 00095 TxaFile _txa_file; 00096 string _default_groupname; 00097 string _default_groupdir; 00098 bool _noabs; 00099 00100 // The following parameter values specifically relate to textures 00101 // and palettes. These values are stored in the textures.boo file 00102 // for future reference. 00103 string _generated_image_pattern; 00104 string _map_dirname; 00105 Filename _shadow_dirname; 00106 Filename _rel_dirname; 00107 int _pal_x_size, _pal_y_size; 00108 LColord _background; 00109 int _margin; 00110 bool _omit_solitary; 00111 bool _omit_everything; 00112 double _coverage_threshold; 00113 bool _force_power_2; 00114 bool _aggressively_clean_mapdir; 00115 bool _round_uvs; 00116 double _round_unit; 00117 double _round_fuzz; 00118 RemapUV _remap_uv, _remap_char_uv; 00119 PNMFileType *_color_type; 00120 PNMFileType *_alpha_type; 00121 PNMFileType *_shadow_color_type; 00122 PNMFileType *_shadow_alpha_type; 00123 EggRenderMode::AlphaMode _cutout_mode; 00124 double _cutout_ratio; 00125 00126 private: 00127 typedef pvector<TexturePlacement *> Placements; 00128 void compute_statistics(ostream &out, int indent_level, 00129 const Placements &placements) const; 00130 00131 typedef pmap<string, EggFile *> EggFiles; 00132 EggFiles _egg_files; 00133 00134 typedef pvector<EggFile *> CommandLineEggs; 00135 CommandLineEggs _command_line_eggs; 00136 00137 typedef pset<TextureImage *> CommandLineTextures; 00138 CommandLineTextures _command_line_textures; 00139 00140 typedef pmap<string, PaletteGroup *> Groups; 00141 Groups _groups; 00142 00143 typedef pmap<string, TextureImage *> Textures; 00144 Textures _textures; 00145 typedef pvector<TextureImage *> TextureConflicts; 00146 TextureConflicts _texture_conflicts; 00147 00148 00149 // The TypedWritable interface follows. 00150 public: 00151 static void register_with_read_factory(); 00152 virtual void write_datagram(BamWriter *writer, Datagram &datagram); 00153 virtual int complete_pointers(TypedWritable **p_list, 00154 BamReader *manager); 00155 00156 virtual void finalize(BamReader *manager); 00157 00158 protected: 00159 static TypedWritable *make_Palettizer(const FactoryParams ¶ms); 00160 void fillin(DatagramIterator &scan, BamReader *manager); 00161 00162 private: 00163 // These values are only filled in while reading from the bam file; 00164 // don't use them otherwise. 00165 int _num_egg_files; 00166 int _num_groups; 00167 int _num_textures; 00168 00169 public: 00170 static TypeHandle get_class_type() { 00171 return _type_handle; 00172 } 00173 static void init_type() { 00174 TypedWritable::init_type(); 00175 register_type(_type_handle, "Palettizer", 00176 TypedWritable::get_class_type()); 00177 } 00178 virtual TypeHandle get_type() const { 00179 return get_class_type(); 00180 } 00181 00182 private: 00183 static TypeHandle _type_handle; 00184 00185 friend class TxaLine; 00186 }; 00187 00188 // This is a global Palettizer pointer that may be filled in when the 00189 // Palettizer is created, for convenience in referencing it from 00190 // multiple places. (Generally, a standalone program will only create 00191 // one Palettizer object in a session.) 00192 extern Palettizer *pal; 00193 00194 #endif