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

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

Public Member Functions

 __init__ ()
 
 __init__ (const EggTextureCollection copy)
 
bool addTexture (EggTexture texture)
 Explicitly adds a new texture to the collection. More...
 
 clear ()
 Removes all textures from the collection. More...
 
int collapseEquivalentTextures (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 collapseEquivalentTextures (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()). More...
 
EggTexture createUniqueTexture (const EggTexture copy, int eq)
 
int extractTextures (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...
 
EggTexture findFilename (const Filename filename)
 Returns the texture with the indicated filename, or NULL if no texture matches. More...
 
EggTexture findTref (str tref_name)
 Returns the texture with the indicated TRef name, or NULL if no texture matches. More...
 
int findUsedTextures (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 getNumTextures ()
 Returns the number of EggTextures in the collection. More...
 
EggTexture getTexture (int index)
 Returns the nth EggTexture in the collection. More...
 
list getTextures ()
 
bool isEmpty ()
 Returns true if there are no EggTexures in the collection, false otherwise. More...
 
EggTexture operator [] (EggTextureCollection::SizeType n)
 Returns the nth EggTexture in the collection. More...
 
EggTextureCollection operator= (const EggTextureCollection copy)
 
bool removeTexture (EggTexture texture)
 Explicitly removes a texture from the collection. More...
 
 removeUnusedTextures (EggNode node)
 Removes any textures from the collection that aren't referenced by any primitives in the indicated egg hierarchy. More...
 
EggTextureCollection::SizeType size ()
 Returns the number of EggTextures in the collection. More...
 
 sortByBasename ()
 Sorts all the textures into alphabetical order by the basename part (including extension) of the filename. More...
 
 sortByTref ()
 Sorts all the textures into alphabetical order by TRef name. More...
 
 uniquifyTrefs ()
 Guarantees that each texture in the collection has a unique TRef name. More...
 

Static Public Member Functions

static replaceTextures (EggGroupNode node, const EggTextureCollection::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.

Member Function Documentation

◆ __init__() [1/2]

__init__ ( )

◆ __init__() [2/2]

__init__ ( const EggTextureCollection  copy)

◆ addTexture()

bool addTexture ( 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.

◆ clear()

clear ( )

Removes all textures from the collection.

◆ collapseEquivalentTextures() [1/2]

int collapseEquivalentTextures ( 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.

◆ collapseEquivalentTextures() [2/2]

int collapseEquivalentTextures ( 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.

◆ createUniqueTexture()

EggTexture createUniqueTexture ( const EggTexture  copy,
int  eq 
)

◆ extractTextures()

int extractTextures ( 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.

◆ findFilename()

EggTexture findFilename ( const Filename  filename)

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

◆ findTref()

EggTexture findTref ( str  tref_name)

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

◆ findUsedTextures()

int findUsedTextures ( 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.

◆ getNumTextures()

int getNumTextures ( )

Returns the number of EggTextures in the collection.

◆ getTexture()

EggTexture getTexture ( int  index)

Returns the nth EggTexture in the collection.

◆ getTextures()

list getTextures ( )

◆ isEmpty()

bool isEmpty ( )

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

◆ operator []()

EggTexture operator [] ( EggTextureCollection::SizeType  n)

Returns the nth EggTexture in the collection.

◆ operator=()

EggTextureCollection operator= ( const EggTextureCollection  copy)

◆ removeTexture()

bool removeTexture ( 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.

◆ removeUnusedTextures()

removeUnusedTextures ( 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.

◆ replaceTextures()

static replaceTextures ( EggGroupNode  node,
const EggTextureCollection::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.

◆ size()

EggTextureCollection::SizeType size ( )

Returns the number of EggTextures in the collection.

◆ sortByBasename()

sortByBasename ( )

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.

◆ sortByTref()

sortByTref ( )

Sorts all the textures into alphabetical order by TRef name.

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

◆ uniquifyTrefs()

uniquifyTrefs ( )

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

This is essential before writing an egg file.