Panda3D
 All Classes Functions Variables Enumerations
texturePlacement.h
1 // Filename: texturePlacement.h
2 // Created by: drose (28Nov00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef TEXTUREPLACEMENT_H
16 #define TEXTUREPLACEMENT_H
17 
18 #include "pandatoolbase.h"
19 
20 #include "omitReason.h"
21 #include "texturePosition.h"
22 
23 #include "typedWritable.h"
24 #include "luse.h"
25 
26 #include "pset.h"
27 
28 class TextureImage;
29 class DestTextureImage;
30 class PaletteGroup;
31 class PaletteImage;
32 class PalettePage;
33 class TextureProperties;
34 class TextureReference;
35 class PNMImage;
36 
37 ////////////////////////////////////////////////////////////////////
38 // Class : TexturePlacement
39 // Description : This corresponds to a particular assignment of a
40 // TextureImage with a PaletteGroup, and specifically
41 // describes which PaletteImage (if any), and where on
42 // the PaletteImage, the TextureImage has been assigned
43 // to.
44 ////////////////////////////////////////////////////////////////////
46 private:
48 
49 public:
50  TexturePlacement(TextureImage *texture, PaletteGroup *group);
52 
53  const string &get_name() const;
54  TextureImage *get_texture() const;
55  const TextureProperties &get_properties() const;
56  PaletteGroup *get_group() const;
57 
58  void add_egg(TextureReference *reference);
59  void remove_egg(TextureReference *reference);
60  void mark_eggs_stale();
61 
62  void set_dest(DestTextureImage *dest);
63  DestTextureImage *get_dest() const;
64 
65  bool determine_size();
66  bool is_size_known() const;
67  OmitReason get_omit_reason() const;
68  int get_x_size() const;
69  int get_y_size() const;
70  double get_uv_area() const;
71 
72  bool is_placed() const;
73  PaletteImage *get_image() const;
74  PalettePage *get_page() const;
75  int get_placed_x() const;
76  int get_placed_y() const;
77  int get_placed_x_size() const;
78  int get_placed_y_size() const;
79  double get_placed_uv_area() const;
80 
81  void place_at(PaletteImage *image, int x, int y);
82  void force_replace();
83  void omit_solitary();
84  void not_solitary();
85  bool intersects(int x, int y, int x_size, int y_size);
86 
87  void compute_tex_matrix(LMatrix3d &transform);
88 
89  void write_placed(ostream &out, int indent_level = 0);
90 
91  bool is_filled() const;
92  void mark_unfilled();
93  void fill_image(PNMImage &image);
94  void fill_swapped_image(PNMImage &image, int index);
95  void flag_error_image(PNMImage &image);
96 
98  TextureSwaps _textureSwaps;
99 
100 private:
101  void compute_size_from_uvs(const LTexCoordd &min_uv, const LTexCoordd &max_uv);
102 
103  TextureImage *_texture;
104  PaletteGroup *_group;
105  PaletteImage *_image;
106  DestTextureImage *_dest;
107 
108  bool _has_uvs;
109  bool _size_known;
110  TexturePosition _position;
111 
112  bool _is_filled;
113  TexturePosition _placed;
114  OmitReason _omit_reason;
115 
117  References _references;
118 
119  // The TypedWritable interface follows.
120 public:
121  static void register_with_read_factory();
122  virtual void write_datagram(BamWriter *writer, Datagram &datagram);
123  virtual int complete_pointers(TypedWritable **p_list,
124  BamReader *manager);
125 
126 protected:
127  static TypedWritable *make_TexturePlacement(const FactoryParams &params);
128  void fillin(DatagramIterator &scan, BamReader *manager);
129 
130 private:
131  // This value is only filled in while reading from the bam file;
132  // don't use it otherwise.
133  int _num_references;
134  int _margin_override;
135  int _num_textureSwaps;
136 
137 public:
138  static TypeHandle get_class_type() {
139  return _type_handle;
140  }
141  static void init_type() {
142  TypedWritable::init_type();
143  register_type(_type_handle, "TexturePlacement",
144  TypedWritable::get_class_type());
145  }
146  virtual TypeHandle get_type() const {
147  return get_class_type();
148  }
149 
150 private:
151  static TypeHandle _type_handle;
152 };
153 
154 
155 // This is an STL object to sort an array of TexturePlacement pointers
156 // in order from biggest to smallest.
158 public:
159  bool operator ()(TexturePlacement *a, TexturePlacement *b) const;
160 };
161 
162 #endif
163 
int get_x_size() const
Returns the size in the X dimension, in pixels, of the texture image as it must appear in the palette...
This represents a texture filename as it has been resized and copied to the map directory (e...
void not_solitary()
Indicates that the texture, formerly indicated as solitary, is now no longer.
void flag_error_image(PNMImage &image)
Sets the rectangle of the palette image represented by the texture placement to red, to represent a missing texture.
bool determine_size()
Attempts to determine the appropriate size of the texture for the given placement.
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
Definition: pnmImage.h:68
DestTextureImage * get_dest() const
Returns the DestTextureImage that corresponds to this texture as it was copied to the install directo...
This is the fundamental interface for extracting binary objects from a Bam file, as generated by a Ba...
Definition: bamReader.h:122
bool is_placed() const
Returns true if the texture has been placed on a palette image, false otherwise.
const string & get_name() const
Returns the name of the texture that this placement represents.
This is the particular reference of a texture filename by an egg file.
This represents a particular position of a texture within a PaletteImage.
virtual void write_datagram(BamWriter *writer, Datagram &datagram)
Fills the indicated datagram up with a binary representation of the current object, in preparation for writing to a Bam file.
Base class for objects that can be written to and read from Bam files.
Definition: typedWritable.h:37
This is the highest level of grouping for TextureImages.
Definition: paletteGroup.h:47
This is a two-component point in space.
Definition: lpoint2.h:411
int get_placed_y() const
Returns the Y pixel at which the texture has been placed within its PaletteImage. ...
int get_placed_x_size() const
Returns the size in the X dimension, in pixels, of the texture image as it has been placed within the...
This is the fundamental interface for writing binary objects to a Bam file, to be extracted later by ...
Definition: bamWriter.h:73
This is a particular collection of textures, within a PaletteGroup, that all share the same TexturePr...
Definition: palettePage.h:37
void place_at(PaletteImage *image, int x, int y)
Assigns the texture to a particular position within the indicated PaletteImage.
int get_y_size() const
Returns the size in the Y dimension, in pixels, of the texture image as it must appear in the palette...
void omit_solitary()
Sets the omit reason (returned by get_omit()) to OR_solitary, indicating that the palettized version ...
static void register_with_read_factory()
Registers the current object as something that can be read from a Bam file.
bool operator()(TexturePlacement *a, TexturePlacement *b) const
Compares two TexturePlacement objects and returns true if the first one is bigger than the second one...
This is a 3-by-3 transform matrix.
Definition: lmatrix.h:4375
void force_replace()
Removes the texture from its particular PaletteImage, but does not remove it from the PaletteGroup...
void mark_unfilled()
Marks the texture as unfilled, so that it will need to be copied into the palette image again...
void compute_tex_matrix(LMatrix3d &transform)
Stores in the indicated matrix the appropriate texture matrix transform for the new placement of the ...
const TextureProperties & get_properties() const
Returns the grouping properties of the image.
OmitReason get_omit_reason() const
Returns the reason the texture has been omitted from a palette image, or OR_none if it has not...
bool is_filled() const
Returns true if the texture has been filled (i.e.
double get_placed_uv_area() const
Returns the total area of the rectangle occupied by the UV minmax box, as it has been placed...
An instance of this class is passed to the Factory when requesting it to do its business and construc...
Definition: factoryParams.h:40
This corresponds to a particular assignment of a TextureImage with a PaletteGroup, and specifically describes which PaletteImage (if any), and where on the PaletteImage, the TextureImage has been assigned to.
PalettePage * get_page() const
Returns the particular PalettePage on which the texture has been placed.
void add_egg(TextureReference *reference)
Records the fact that a particular egg file is using this particular TexturePlacement.
PaletteGroup * get_group() const
Returns the group that this placement represents.
int get_placed_x() const
Returns the X pixel at which the texture has been placed within its PaletteImage. ...
int get_placed_y_size() const
Returns the size in the Y dimension, in pixels, of the texture image as it has been placed within the...
void remove_egg(TextureReference *reference)
Notes that a particular egg file is no longer using this particular TexturePlacement.
PaletteImage * get_image() const
Returns the particular PaletteImage on which the texture has been placed.
bool is_size_known() const
Returns true if the texture's size is known, false otherwise.
void fill_swapped_image(PNMImage &image, int index)
Fills in the rectangle of the swapped palette image represented by the texture placement with the ima...
This is a single palette image, one of several within a PalettePage, which is in turn one of several ...
Definition: paletteImage.h:36
bool intersects(int x, int y, int x_size, int y_size)
Returns true if the particular position this texture has been assigned to overlaps the rectangle whos...
A class to retrieve the individual data elements previously stored in a Datagram. ...
This represents a single source texture that is referenced by one or more egg files.
Definition: textureImage.h:51
void set_dest(DestTextureImage *dest)
Sets the DestTextureImage that corresponds to this texture as it was copied to the install directory...
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
TextureImage * get_texture() const
Returns the texture that this placement represents.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
double get_uv_area() const
Returns the total area of the rectangle occupied by the UV minmax box, in UV coordinates.
virtual int complete_pointers(TypedWritable **p_list, BamReader *manager)
Called after the object is otherwise completely read from a Bam file, this function's job is to store...
void mark_eggs_stale()
Marks all the egg files that reference this placement stale.
void write_placed(ostream &out, int indent_level=0)
Writes the placement position information on a line by itself.
void fill_image(PNMImage &image)
Fills in the rectangle of the palette image represented by the texture placement with the image pixel...
This is the set of characteristics of a texture that, if different from another texture, prevent the two textures from sharing a PaletteImage.