29EggTextureCollection() {
37 _textures(copy._textures),
38 _ordered_textures(copy._ordered_textures)
47 _textures = copy._textures;
48 _ordered_textures = copy._ordered_textures;
56~EggTextureCollection() {
65 _ordered_textures.clear();
77 return node->find_textures(
this);
86 return _ordered_textures.empty();
94 return _ordered_textures.size();
102 nassertr(index >= 0 && index < (
int)_ordered_textures.size(),
nullptr);
104 return _ordered_textures[index];
124 OrderedTextures::iterator oti;
125 for (oti = _ordered_textures.begin();
126 oti != _ordered_textures.end();
129 position = node->insert(position, texture);
162 if (node->
is_of_type(EggPrimitive::get_class_type())) {
166 for (
int i = 0; i < num_textures; i++) {
169 Textures::iterator ti = _textures.find(tex);
170 if (ti == _textures.end()) {
173 _textures.insert(Textures::value_type(tex, 1));
174 _ordered_textures.push_back(tex);
182 for (
int j = 0; j < i; j++) {
196 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
199 EggGroupNode::iterator ci;
200 for (ci = group->begin(); ci != group->end(); ++ci) {
243 return num_collapsed;
260 int num_collapsed = 0;
264 Collapser collapser(uet);
268 OrderedTextures::const_iterator oti;
269 for (oti = _ordered_textures.begin();
270 oti != _ordered_textures.end();
274 std::pair<Collapser::const_iterator, bool> result = collapser.insert(tex);
275 if (!result.second) {
278 removed.insert(TextureReplacement::value_type(tex, first));
285 Collapser::const_iterator ci;
286 for (ci = collapser.begin(); ci != collapser.end(); ++ci) {
290 return num_collapsed;
303 EggGroupNode::iterator ci;
304 for (ci = node->begin();
308 if (child->
is_of_type(EggPrimitive::get_class_type())) {
310 EggPrimitive::Textures new_textures;
311 EggPrimitive::Textures::const_iterator ti;
312 for (ti = primitive->_textures.begin();
313 ti != primitive->_textures.end();
315 PT_EggTexture tex = (*ti);
316 TextureReplacement::const_iterator ri;
317 ri = replace.find(tex);
318 if (ri != replace.end()) {
320 new_textures.push_back((*ri).second);
322 new_textures.push_back(tex);
325 primitive->_textures.swap(new_textures);
327 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
342 OrderedTextures::const_iterator oti;
343 for (oti = _ordered_textures.begin();
344 oti != _ordered_textures.end();
348 tex->set_name(nu.
add_name(tex->get_name()));
358 sort(_ordered_textures.begin(), _ordered_textures.end(),
369 sort(_ordered_textures.begin(), _ordered_textures.end(),
380 nassertr(_textures.size() == _ordered_textures.size(),
false);
382 PT_EggTexture new_tex = texture;
384 Textures::const_iterator ti;
385 ti = _textures.find(new_tex);
386 if (ti != _textures.end()) {
391 _textures.insert(Textures::value_type(new_tex, 0));
392 _ordered_textures.push_back(new_tex);
394 nassertr(_textures.size() == _ordered_textures.size(),
false);
404 nassertr(_textures.size() == _ordered_textures.size(),
false);
406 Textures::iterator ti;
407 ti = _textures.find(texture);
408 if (ti == _textures.end()) {
415 OrderedTextures::iterator oti;
416 PT_EggTexture ptex = texture;
417 oti = find(_ordered_textures.begin(), _ordered_textures.end(), ptex);
418 nassertr(oti != _ordered_textures.end(),
false);
420 _ordered_textures.erase(oti);
422 nassertr(_textures.size() == _ordered_textures.size(),
false);
434 OrderedTextures::const_iterator oti;
435 for (oti = _ordered_textures.begin();
436 oti != _ordered_textures.end();
456find_tref(
const std::string &tref_name)
const {
458 OrderedTextures::const_iterator oti;
459 for (oti = _ordered_textures.begin();
460 oti != _ordered_textures.end();
463 if (tex->get_name() == tref_name) {
478 OrderedTextures::const_iterator oti;
479 for (oti = _ordered_textures.begin();
480 oti != _ordered_textures.end();
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
A base class for nodes in the hierarchy that are not leaf nodes.
A base class for things that may be directly added into the egg hierarchy.
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
get_num_textures
Returns the number of textures applied to the primitive.
get_texture
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
This is a collection of textures by TRef name.
bool add_texture(EggTexture *texture)
Explicitly adds a new texture to the collection.
bool is_empty() const
Returns true if there are no EggTexures in the collection, false otherwise.
EggTexture * find_tref(const std::string &tref_name) const
Returns the texture with the indicated TRef name, or NULL if no texture matches.
void sort_by_tref()
Sorts all the textures into alphabetical order by TRef name.
get_texture
Returns the nth EggTexture in the collection.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
EggTexture * find_filename(const Filename &filename) const
Returns the texture with the indicated filename, or NULL if no texture matches.
int collapse_equivalent_textures(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate textures that are equivalent accordi...
static void replace_textures(EggGroupNode *node, const TextureReplacement &replace)
Walks the egg hierarchy, changing out any reference to a texture appearing on the left side of the ma...
void clear()
Removes all textures from the collection.
int extract_textures(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggTextures encountered in t...
void uniquify_trefs()
Guarantees that each texture in the collection has a unique TRef name.
EggGroupNode::iterator insert_textures(EggGroupNode *node)
Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textu...
void remove_unused_textures(EggNode *node)
Removes any textures from the collection that aren't referenced by any primitives in the indicated eg...
void sort_by_basename()
Sorts all the textures into alphabetical order by the basename part (including extension) of the file...
EggTexture * create_unique_texture(const EggTexture ©, int eq)
Creates a new texture if there is not already one equivalent (according to eq, see EggTexture::is_equ...
get_num_textures
Returns the number of EggTextures in the collection.
bool remove_texture(EggTexture *texture)
Explicitly removes a texture from the collection.
Defines a texture map that may be applied to geometry.
bool is_equivalent_to(const EggTexture &other, int eq) const
Returns true if the two textures are equivalent in all relevant properties (according to eq),...
bool multitexture_over(EggTexture *other)
Indicates that this texture should be layered on top of the other texture.
The name of a file, such as a texture file or an Egg file.
An STL function object for sorting an array of pointers to Namables into order by name.
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
std::string add_name(const std::string &name)
If name is nonempty and so far unique, returns it unchanged.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
An STL function object for sorting textures into order by properties.
This is our own Panda specialization on the default STL map.
This is our own Panda specialization on the default STL set.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.