Panda3D
Loading...
Searching...
No Matches
eggTextureCollection.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 eggTextureCollection.h
10 * @author drose
11 * @date 2000-02-15
12 */
13
14#ifndef EGGTEXTURECOLLECTION_H
15#define EGGTEXTURECOLLECTION_H
16
17#include "pandabase.h"
18
19#include "eggTexture.h"
20#include "eggGroupNode.h"
22
23#include "pmap.h"
24
25/**
26 * This is a collection of textures by TRef name. It can extract the textures
27 * from an egg file and sort them all together; it can also manage the
28 * creation of unique textures and the assignment of unique TRef names.
29 */
30class EXPCL_PANDA_EGG EggTextureCollection {
31
32 // This is a bit of private interface stuff that must be here as a forward
33 // reference. This allows us to define the EggTextureCollection as an STL
34 // container.
35
36private:
37 typedef pmap<PT_EggTexture, int> Textures;
38 typedef vector_PT_EggTexture OrderedTextures;
39
40public:
41 typedef OrderedTextures::const_iterator iterator;
42 typedef iterator const_iterator;
43 typedef OrderedTextures::size_type size_type;
44
45 typedef pmap<PT_EggTexture, PT_EggTexture > TextureReplacement;
46
47 // Here begins the actual public interface to EggTextureCollection.
48
49PUBLISHED:
50 EggTextureCollection();
51 EggTextureCollection(const EggTextureCollection &copy);
52 EggTextureCollection &operator = (const EggTextureCollection &copy);
53 ~EggTextureCollection();
54
55 void clear();
56
58
59 bool is_empty() const;
60 int get_num_textures() const;
61 EggTexture *get_texture(int index) const;
62 MAKE_SEQ(get_textures, get_num_textures, get_texture);
63
64public:
65 EggGroupNode::iterator insert_textures(EggGroupNode *node);
66 EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position);
67
68PUBLISHED:
69 int find_used_textures(EggNode *node);
71
73 int collapse_equivalent_textures(int eq, TextureReplacement &removed);
74 static void replace_textures(EggGroupNode *node,
75 const TextureReplacement &replace);
76
77 void uniquify_trefs();
78 void sort_by_tref();
79 void sort_by_basename();
80
81public:
82 // Can be used to traverse all the textures in the collection, in order as
83 // last sorted.
84 INLINE iterator begin() const;
85 INLINE iterator end() const;
86 INLINE bool empty() const;
87
88PUBLISHED:
89 INLINE EggTexture *operator [](size_type n) const;
90 INLINE size_type size() const;
91
92 bool add_texture(EggTexture *texture);
93 bool remove_texture(EggTexture *texture);
94
95 // create_unique_texture() creates a new texture if there is not already one
96 // equivalent (according to eq, see EggTexture::is_equivalent_to()) to the
97 // indicated texture, or returns the existing one if there is.
98 EggTexture *create_unique_texture(const EggTexture &copy, int eq);
99
100 // Find a texture with a particular TRef name.
101 EggTexture *find_tref(const std::string &tref_name) const;
102
103 // Find a texture with a particular filename.
104 EggTexture *find_filename(const Filename &filename) const;
105
106private:
107 Textures _textures;
108 OrderedTextures _ordered_textures;
109};
110
111#include "eggTextureCollection.I"
112
113#endif
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.
Definition eggNode.h:36
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...
size_type size() const
Returns the number of EggTextures in the collection.
EggTexture * 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_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.
Definition eggTexture.h:30
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
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.