00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef TEXTUREPLACEMENT_H
00016 #define TEXTUREPLACEMENT_H
00017
00018 #include "pandatoolbase.h"
00019
00020 #include "omitReason.h"
00021 #include "texturePosition.h"
00022
00023 #include "typedWritable.h"
00024 #include "luse.h"
00025
00026 #include "pset.h"
00027
00028 class TextureImage;
00029 class DestTextureImage;
00030 class PaletteGroup;
00031 class PaletteImage;
00032 class PalettePage;
00033 class TextureProperties;
00034 class TextureReference;
00035 class PNMImage;
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045 class TexturePlacement : public TypedWritable {
00046 private:
00047 TexturePlacement();
00048
00049 public:
00050 TexturePlacement(TextureImage *texture, PaletteGroup *group);
00051 ~TexturePlacement();
00052
00053 const string &get_name() const;
00054 TextureImage *get_texture() const;
00055 const TextureProperties &get_properties() const;
00056 PaletteGroup *get_group() const;
00057
00058 void add_egg(TextureReference *reference);
00059 void remove_egg(TextureReference *reference);
00060 void mark_eggs_stale();
00061
00062 void set_dest(DestTextureImage *dest);
00063 DestTextureImage *get_dest() const;
00064
00065 bool determine_size();
00066 bool is_size_known() const;
00067 OmitReason get_omit_reason() const;
00068 int get_x_size() const;
00069 int get_y_size() const;
00070 double get_uv_area() const;
00071
00072 bool is_placed() const;
00073 PaletteImage *get_image() const;
00074 PalettePage *get_page() const;
00075 int get_placed_x() const;
00076 int get_placed_y() const;
00077 int get_placed_x_size() const;
00078 int get_placed_y_size() const;
00079 double get_placed_uv_area() const;
00080
00081 void place_at(PaletteImage *image, int x, int y);
00082 void force_replace();
00083 void omit_solitary();
00084 void not_solitary();
00085 bool intersects(int x, int y, int x_size, int y_size);
00086
00087 void compute_tex_matrix(LMatrix3d &transform);
00088
00089 void write_placed(ostream &out, int indent_level = 0);
00090
00091 bool is_filled() const;
00092 void mark_unfilled();
00093 void fill_image(PNMImage &image);
00094 void fill_swapped_image(PNMImage &image, int index);
00095 void flag_error_image(PNMImage &image);
00096
00097 typedef pvector<TextureImage *> TextureSwaps;
00098 TextureSwaps _textureSwaps;
00099
00100 private:
00101 void compute_size_from_uvs(const LTexCoordd &min_uv, const LTexCoordd &max_uv);
00102
00103 TextureImage *_texture;
00104 PaletteGroup *_group;
00105 PaletteImage *_image;
00106 DestTextureImage *_dest;
00107
00108 bool _has_uvs;
00109 bool _size_known;
00110 TexturePosition _position;
00111
00112 bool _is_filled;
00113 TexturePosition _placed;
00114 OmitReason _omit_reason;
00115
00116 typedef pset<TextureReference *> References;
00117 References _references;
00118
00119
00120 public:
00121 static void register_with_read_factory();
00122 virtual void write_datagram(BamWriter *writer, Datagram &datagram);
00123 virtual int complete_pointers(TypedWritable **p_list,
00124 BamReader *manager);
00125
00126 protected:
00127 static TypedWritable *make_TexturePlacement(const FactoryParams ¶ms);
00128 void fillin(DatagramIterator &scan, BamReader *manager);
00129
00130 private:
00131
00132
00133 int _num_references;
00134 int _margin_override;
00135 int _num_textureSwaps;
00136
00137 public:
00138 static TypeHandle get_class_type() {
00139 return _type_handle;
00140 }
00141 static void init_type() {
00142 TypedWritable::init_type();
00143 register_type(_type_handle, "TexturePlacement",
00144 TypedWritable::get_class_type());
00145 }
00146 virtual TypeHandle get_type() const {
00147 return get_class_type();
00148 }
00149
00150 private:
00151 static TypeHandle _type_handle;
00152 };
00153
00154
00155
00156
00157 class SortPlacementBySize {
00158 public:
00159 bool operator ()(TexturePlacement *a, TexturePlacement *b) const;
00160 };
00161
00162 #endif
00163