Panda3D
Public Types | Public Member Functions | Static Public Member Functions | List of all members
EggTextureCollection Class Reference

This is a collection of textures by TRef name. More...

#include "eggTextureCollection.h"

Public Types

typedef iterator const_iterator
 
typedef OrderedTextures::const_iterator iterator
 
typedef OrderedTextures::size_type size_type
 
typedef pmap< PT_EggTexture, PT_EggTexture > TextureReplacement
 

Public Member Functions

 EggTextureCollection (const EggTextureCollection &copy)
 
bool add_texture (EggTexture *texture)
 Explicitly adds a new texture to the collection. More...
 
iterator begin () const
 
void clear ()
 Removes all textures from the collection. More...
 
int collapse_equivalent_textures (int eq, EggGroupNode *node)
 Walks through the collection and collapses together any separate textures that are equivalent according to the indicated equivalence factor, eq (see EggTexture::is_equivalent_to()). More...
 
int collapse_equivalent_textures (int eq, TextureReplacement &removed)
 Walks through the collection and collapses together any separate textures that are equivalent according to the indicated equivalence factor, eq (see EggTexture::is_equivalent_to()). More...
 
EggTexturecreate_unique_texture (const EggTexture &copy, int eq)
 Creates a new texture if there is not already one equivalent (according to eq, see EggTexture::is_equivalent_to()) to the indicated texture, or returns the existing one if there is. More...
 
bool empty () const
 
iterator end () const
 
int extract_textures (EggGroupNode *node)
 Walks the egg hierarchy beginning at the indicated node, and removes any EggTextures encountered in the hierarchy, adding them to the collection. More...
 
EggTexturefind_filename (const Filename &filename) const
 Returns the texture with the indicated filename, or NULL if no texture matches. More...
 
EggTexturefind_tref (const string &tref_name) const
 Returns the texture with the indicated TRef name, or NULL if no texture matches. More...
 
int find_used_textures (EggNode *node)
 Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by primitives but are not already members of the collection, adding them to the collection. More...
 
int get_num_textures () const
 Returns the number of EggTextures in the collection. More...
 
EggTextureget_texture (int index) const
 Returns the nth EggTexture in the collection. More...
 
EggGroupNode::iterator insert_textures (EggGroupNode *node)
 Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textures in the collection. More...
 
EggGroupNode::iterator insert_textures (EggGroupNode *node, EggGroupNode::iterator position)
 Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textures in the collection. More...
 
bool is_empty () const
 Returns true if there are no EggTexures in the collection, false otherwise. More...
 
 MAKE_SEQ (get_textures, get_num_textures, get_texture)
 
EggTextureCollectionoperator= (const EggTextureCollection &copy)
 
EggTextureoperator[] (size_type n) const
 Returns the nth EggTexture in the collection. More...
 
bool remove_texture (EggTexture *texture)
 Explicitly removes a texture from the collection. More...
 
void remove_unused_textures (EggNode *node)
 Removes any textures from the collection that aren't referenced by any primitives in the indicated egg hierarchy. More...
 
size_type size () const
 Returns the number of EggTextures in the collection. More...
 
void sort_by_basename ()
 Sorts all the textures into alphabetical order by the basename part (including extension) of the filename. More...
 
void sort_by_tref ()
 Sorts all the textures into alphabetical order by TRef name. More...
 
void uniquify_trefs ()
 Guarantees that each texture in the collection has a unique TRef name. More...
 

Static Public Member Functions

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 map with its corresponding texture on the right side. More...
 

Detailed Description

This is a collection of textures by TRef name.

It can extract the textures from an egg file and sort them all together; it can also manage the creation of unique textures and the assignment of unique TRef names.

Definition at line 34 of file eggTextureCollection.h.

Member Function Documentation

◆ add_texture()

bool EggTextureCollection::add_texture ( EggTexture texture)

Explicitly adds a new texture to the collection.

Returns true if the texture was added, false if it was already there or if there was some error.

Definition at line 442 of file eggTextureCollection.cxx.

References remove_texture().

Referenced by EggGroupNode::rebuild_vertex_pools(), and sort_by_basename().

◆ clear()

void EggTextureCollection::clear ( )

Removes all textures from the collection.

Definition at line 74 of file eggTextureCollection.cxx.

References extract_textures().

◆ collapse_equivalent_textures() [1/2]

int EggTextureCollection::collapse_equivalent_textures ( int  eq,
EggGroupNode node 
)

Walks through the collection and collapses together any separate textures that are equivalent according to the indicated equivalence factor, eq (see EggTexture::is_equivalent_to()).

The return value is the number of textures removed.

This flavor of collapse_equivalent_textures() automatically adjusts all the primitives in the egg hierarchy to refer to the new texture pointers.

Definition at line 279 of file eggTextureCollection.cxx.

Referenced by EggData::collapse_equivalent_textures(), remove_unused_textures(), and EggData::set_coordinate_system().

◆ collapse_equivalent_textures() [2/2]

int EggTextureCollection::collapse_equivalent_textures ( int  eq,
EggTextureCollection::TextureReplacement removed 
)

Walks through the collection and collapses together any separate textures that are equivalent according to the indicated equivalence factor, eq (see EggTexture::is_equivalent_to()).

The return value is the number of textures removed.

This flavor of collapse_equivalent_textures() does not adjust any primitives in the egg hierarchy; instead, it fills up the 'removed' map with an entry for each removed texture, mapping it back to the equivalent retained texture. It's up to the user to then call replace_textures() with this map, if desired, to apply these changes to the egg hierarchy.

Definition at line 308 of file eggTextureCollection.cxx.

References replace_textures().

◆ create_unique_texture()

EggTexture * EggTextureCollection::create_unique_texture ( const EggTexture copy,
int  eq 
)

Creates a new texture if there is not already one equivalent (according to eq, see EggTexture::is_equivalent_to()) to the indicated texture, or returns the existing one if there is.

Definition at line 501 of file eggTextureCollection.cxx.

References find_tref(), and EggTexture::is_equivalent_to().

Referenced by MaxToEggConverter::convert(), EggPrimitive::copy_vertices(), and remove_texture().

◆ extract_textures()

int EggTextureCollection::extract_textures ( EggGroupNode node)

Walks the egg hierarchy beginning at the indicated node, and removes any EggTextures encountered in the hierarchy, adding them to the collection.

Returns the number of EggTextures encountered.

Definition at line 88 of file eggTextureCollection.cxx.

References is_empty().

Referenced by clear(), and EggData::set_coordinate_system().

◆ find_filename()

EggTexture * EggTextureCollection::find_filename ( const Filename filename) const

Returns the texture with the indicated filename, or NULL if no texture matches.

Definition at line 550 of file eggTextureCollection.cxx.

References EggFilenameNode::get_filename().

Referenced by find_tref().

◆ find_tref()

EggTexture * EggTextureCollection::find_tref ( const string &  tref_name) const

Returns the texture with the indicated TRef name, or NULL if no texture matches.

Definition at line 527 of file eggTextureCollection.cxx.

References find_filename().

Referenced by create_unique_texture().

◆ find_used_textures()

int EggTextureCollection::find_used_textures ( EggNode node)

Walks the egg hierarchy beginning at the indicated node, looking for textures that are referenced by primitives but are not already members of the collection, adding them to the collection.

If this is called following extract_textures(), it can be used to pick up any additional texture references that appeared in the egg hierarchy (but whose EggTexture node was not actually part of the hierarchy).

If this is called in lieu of extract_textures(), it will fill up the collection with all of the referenced textures (and only the referenced textures), without destructively removing the EggTextures from the hierarchy.

This also has the side effect of incrementing the internal usage count for a texture in the collection each time a texture reference is encountered. This side effect is taken advantage of by remove_unused_textures().

And one more side effect: this function identifies the presence of multitexturing in the egg file, and calls multitexture_over() on each texture appropriately so that, after this call, you may expect get_multitexture_sort() to return a reasonable value for each texture.

Definition at line 196 of file eggTextureCollection.cxx.

References EggPrimitive::get_num_textures(), EggPrimitive::get_texture(), TypedObject::is_of_type(), EggTexture::multitexture_over(), and remove_unused_textures().

Referenced by EggNode::apply_texmats(), EggData::collapse_equivalent_textures(), insert_textures(), EggLoader::make_polyset(), EggReader::pre_process_egg_file(), EggFile::read_egg(), EggGroupNode::recompute_tangent_binormal_auto(), EggFile::scan_textures(), and EggFile::write_texture_refs().

◆ get_num_textures()

int EggTextureCollection::get_num_textures ( ) const

Returns the number of EggTextures in the collection.

Definition at line 112 of file eggTextureCollection.cxx.

References get_texture().

Referenced by is_empty().

◆ get_texture()

EggTexture * EggTextureCollection::get_texture ( int  index) const

Returns the nth EggTexture in the collection.

Definition at line 122 of file eggTextureCollection.cxx.

References insert_textures().

Referenced by get_num_textures(), and operator[]().

◆ insert_textures() [1/2]

EggGroupNode::iterator EggTextureCollection::insert_textures ( EggGroupNode node)

Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textures in the collection.

Returns an iterator representing the first position after the newly inserted textures.

Definition at line 137 of file eggTextureCollection.cxx.

Referenced by get_texture(), and EggData::set_coordinate_system().

◆ insert_textures() [2/2]

EggGroupNode::iterator EggTextureCollection::insert_textures ( EggGroupNode node,
EggGroupNode::iterator  position 
)

Adds a series of EggTexture nodes to the beginning of the indicated node to reflect each of the textures in the collection.

Returns an iterator representing the first position after the newly inserted textures.

Definition at line 150 of file eggTextureCollection.cxx.

References find_used_textures().

◆ is_empty()

bool EggTextureCollection::is_empty ( ) const

Returns true if there are no EggTexures in the collection, false otherwise.

Definition at line 102 of file eggTextureCollection.cxx.

References get_num_textures().

Referenced by extract_textures().

◆ operator[]()

EggTexture * EggTextureCollection::operator[] ( size_type  n) const
inline

Returns the nth EggTexture in the collection.

Definition at line 54 of file eggTextureCollection.I.

References get_texture(), and size().

◆ remove_texture()

bool EggTextureCollection::remove_texture ( EggTexture texture)

Explicitly removes a texture from the collection.

Returns true if the texture was removed, false if it wasn't there or if there was some error.

Definition at line 469 of file eggTextureCollection.cxx.

References create_unique_texture().

Referenced by add_texture().

◆ remove_unused_textures()

void EggTextureCollection::remove_unused_textures ( EggNode node)

Removes any textures from the collection that aren't referenced by any primitives in the indicated egg hierarchy.

This also, incidentally, adds textures to the collection that had been referenced by primitives but had not previously appeared in the collection.

Definition at line 257 of file eggTextureCollection.cxx.

References collapse_equivalent_textures().

Referenced by find_used_textures(), and EggData::set_coordinate_system().

◆ replace_textures()

void EggTextureCollection::replace_textures ( EggGroupNode node,
const TextureReplacement replace 
)
static

Walks the egg hierarchy, changing out any reference to a texture appearing on the left side of the map with its corresponding texture on the right side.

This is most often done following a call to collapse_equivalent_textures(). It does not directly affect the Collection.

Definition at line 353 of file eggTextureCollection.cxx.

References TypedObject::is_of_type(), and uniquify_trefs().

Referenced by collapse_equivalent_textures().

◆ size()

EggTextureCollection::size_type EggTextureCollection::size ( ) const
inline

Returns the number of EggTextures in the collection.

Definition at line 64 of file eggTextureCollection.I.

Referenced by EggPrimitive::clear(), EggPrimitive::get_vertex(), operator[](), EggPrimitive::operator[](), and EggPrimitive::set_vertex().

◆ sort_by_basename()

void EggTextureCollection::sort_by_basename ( )

Sorts all the textures into alphabetical order by the basename part (including extension) of the filename.

Subsequent operations using begin()/end() will traverse in this sorted order.

Definition at line 429 of file eggTextureCollection.cxx.

References add_texture().

Referenced by sort_by_tref().

◆ sort_by_tref()

void EggTextureCollection::sort_by_tref ( )

Sorts all the textures into alphabetical order by TRef name.

Subsequent operations using begin()/end() will traverse in this sorted order.

Definition at line 415 of file eggTextureCollection.cxx.

References sort_by_basename().

Referenced by EggData::set_coordinate_system(), and uniquify_trefs().

◆ uniquify_trefs()

void EggTextureCollection::uniquify_trefs ( )

Guarantees that each texture in the collection has a unique TRef name.

This is essential before writing an egg file.

Definition at line 394 of file eggTextureCollection.cxx.

References NameUniquifier::add_name(), and sort_by_tref().

Referenced by EggFile::read_egg(), replace_textures(), EggFile::scan_textures(), EggData::set_coordinate_system(), and EggFile::write_texture_refs().


The documentation for this class was generated from the following files: