Panda3D

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