15 #include "eggTextureCollection.h"
16 #include "eggGroupNode.h"
17 #include "eggPrimitive.h"
18 #include "eggTexture.h"
19 #include "pt_EggTexture.h"
22 #include "nameUniquifier.h"
31 EggTextureCollection::
32 EggTextureCollection() {
40 EggTextureCollection::
42 _textures(copy._textures),
43 _ordered_textures(copy._ordered_textures)
54 _textures = copy._textures;
55 _ordered_textures = copy._ordered_textures;
64 EggTextureCollection::
65 ~EggTextureCollection() {
76 _ordered_textures.clear();
91 return node->find_textures(
this);
103 return _ordered_textures.empty();
113 return _ordered_textures.size();
123 nassertr(index >= 0 && index < (
int)_ordered_textures.size(), NULL);
125 return _ordered_textures[index];
151 OrderedTextures::iterator oti;
152 for (oti = _ordered_textures.begin();
153 oti != _ordered_textures.end();
156 position = node->insert(position, texture);
199 if (node->
is_of_type(EggPrimitive::get_class_type())) {
203 for (
int i = 0; i < num_textures; i++) {
206 Textures::iterator ti = _textures.find(tex);
207 if (ti == _textures.end()) {
210 _textures.insert(Textures::value_type(tex, 1));
211 _ordered_textures.push_back(tex);
219 for (
int j = 0; j < i; j++) {
233 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
236 EggGroupNode::iterator ci;
237 for (ci = group->begin(); ci != group->end(); ++ci) {
287 return num_collapsed;
309 int num_collapsed = 0;
313 Collapser collapser(uet);
317 OrderedTextures::const_iterator oti;
318 for (oti = _ordered_textures.begin();
319 oti != _ordered_textures.end();
323 pair<Collapser::const_iterator, bool> result = collapser.insert(tex);
324 if (!result.second) {
327 removed.insert(TextureReplacement::value_type(tex, first));
334 Collapser::const_iterator ci;
335 for (ci = collapser.begin(); ci != collapser.end(); ++ci) {
339 return num_collapsed;
355 EggGroupNode::iterator ci;
356 for (ci = node->begin();
360 if (child->
is_of_type(EggPrimitive::get_class_type())) {
362 EggPrimitive::Textures new_textures;
363 EggPrimitive::Textures::const_iterator ti;
364 for (ti = primitive->_textures.begin();
365 ti != primitive->_textures.end();
367 PT_EggTexture tex = (*ti);
368 TextureReplacement::const_iterator ri;
369 ri = replace.find(tex);
370 if (ri != replace.end()) {
372 new_textures.push_back((*ri).second);
374 new_textures.push_back(tex);
377 primitive->_textures.swap(new_textures);
379 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
397 OrderedTextures::const_iterator oti;
398 for (oti = _ordered_textures.begin();
399 oti != _ordered_textures.end();
403 tex->set_name(nu.
add_name(tex->get_name()));
416 sort(_ordered_textures.begin(), _ordered_textures.end(),
430 sort(_ordered_textures.begin(), _ordered_textures.end(),
443 nassertr(_textures.size() == _ordered_textures.size(),
false);
445 PT_EggTexture new_tex = texture;
447 Textures::const_iterator ti;
448 ti = _textures.find(new_tex);
449 if (ti != _textures.end()) {
454 _textures.insert(Textures::value_type(new_tex, 0));
455 _ordered_textures.push_back(new_tex);
457 nassertr(_textures.size() == _ordered_textures.size(),
false);
470 nassertr(_textures.size() == _ordered_textures.size(),
false);
472 Textures::iterator ti;
473 ti = _textures.find(texture);
474 if (ti == _textures.end()) {
481 OrderedTextures::iterator oti;
482 PT_EggTexture ptex = texture;
483 oti = find(_ordered_textures.begin(), _ordered_textures.end(), ptex);
484 nassertr(oti != _ordered_textures.end(),
false);
486 _ordered_textures.erase(oti);
488 nassertr(_textures.size() == _ordered_textures.size(),
false);
504 OrderedTextures::const_iterator oti;
505 for (oti = _ordered_textures.begin();
506 oti != _ordered_textures.end();
530 OrderedTextures::const_iterator oti;
531 for (oti = _ordered_textures.begin();
532 oti != _ordered_textures.end();
535 if (tex->get_name() == tref_name) {
553 OrderedTextures::const_iterator oti;
554 for (oti = _ordered_textures.begin();
555 oti != _ordered_textures.end();
A base class for any of a number of kinds of geometry primitives: polygons, point lights...
void sort_by_tref()
Sorts all the textures into alphabetical order by TRef name.
int collapse_equivalent_textures(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate textures that are equivalent accordi...
void uniquify_trefs()
Guarantees that each texture in the collection has a unique TRef name.
This is our own Panda specialization on the default STL map.
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...
bool multitexture_over(EggTexture *other)
Indicates that this texture should be layered on top of the other texture.
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)...
A base class for nodes in the hierarchy that are not leaf nodes.
void remove_unused_textures(EggNode *node)
Removes any textures from the collection that aren't referenced by any primitives in the indicated eg...
Defines a texture map that may be applied to geometry.
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
void clear()
Removes all textures from the collection.
This is a collection of textures by TRef name.
EggTexture * get_texture() const
Returns the first texture on the primitive, if any, or NULL if there are no textures on the primitive...
bool add_texture(EggTexture *texture)
Explicitly adds a new texture to the collection.
int extract_textures(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggTextures encountered in t...
bool remove_texture(EggTexture *texture)
Explicitly removes a texture from the collection.
bool is_empty() const
Returns true if there are no EggTexures in the collection, false otherwise.
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
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...
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...
The name of a file, such as a texture file or an Egg file.
EggTexture * find_filename(const Filename &filename) const
Returns the texture with the indicated filename, or NULL if no texture matches.
An STL function object for sorting textures into order by properties.
int get_num_textures() const
Returns the number of textures applied to the primitive.
void sort_by_basename()
Sorts all the textures into alphabetical order by the basename part (including extension) of the file...
const Filename & get_filename() const
Returns a nonmodifiable reference to the filename.
int find_used_textures(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by ...
string add_name(const string &name)
If name is nonempty and so far unique, returns it unchanged.
A base class for things that may be directly added into the egg hierarchy.
This is our own Panda specialization on the default STL set.
An STL function object for sorting an array of pointers to Namables into order by name...
EggTexture * find_tref(const string &tref_name) const
Returns the texture with the indicated TRef name, or NULL if no texture matches.
int get_num_textures() const
Returns the number of EggTextures in the collection.
EggTexture * get_texture(int index) const
Returns the nth EggTexture in the collection.