27 EggMaterialCollection::
28 EggMaterialCollection() {
34 EggMaterialCollection::
36 _materials(copy._materials),
37 _ordered_materials(copy._ordered_materials)
46 _materials = copy._materials;
47 _ordered_materials = copy._ordered_materials;
54 EggMaterialCollection::
55 ~EggMaterialCollection() {
64 _ordered_materials.clear();
76 return node->find_materials(
this);
96 OrderedMaterials::iterator oti;
97 for (oti = _ordered_materials.begin();
98 oti != _ordered_materials.end();
101 position = node->insert(position, material);
129 if (node->
is_of_type(EggPrimitive::get_class_type())) {
133 Materials::iterator ti = _materials.find(tex);
134 if (ti == _materials.end()) {
137 _materials.insert(Materials::value_type(tex, 1));
138 _ordered_materials.push_back(tex);
146 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
149 EggGroupNode::iterator ci;
150 for (ci = group->begin(); ci != group->end(); ++ci) {
193 return num_collapsed;
210 int num_collapsed = 0;
214 Collapser collapser(uet);
218 OrderedMaterials::const_iterator oti;
219 for (oti = _ordered_materials.begin();
220 oti != _ordered_materials.end();
224 std::pair<Collapser::const_iterator, bool> result = collapser.insert(tex);
225 if (!result.second) {
228 removed.insert(MaterialReplacement::value_type(tex, first));
235 Collapser::const_iterator ci;
236 for (ci = collapser.begin(); ci != collapser.end(); ++ci) {
240 return num_collapsed;
253 EggGroupNode::iterator ci;
254 for (ci = node->begin();
258 if (child->
is_of_type(EggPrimitive::get_class_type())) {
262 MaterialReplacement::const_iterator ri;
263 ri = replace.find(tex);
264 if (ri != replace.end()) {
270 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
285 OrderedMaterials::const_iterator oti;
286 for (oti = _ordered_materials.begin();
287 oti != _ordered_materials.end();
291 tex->set_name(nu.
add_name(tex->get_name()));
301 sort(_ordered_materials.begin(), _ordered_materials.end(),
312 nassertr(_materials.size() == _ordered_materials.size(),
false);
316 Materials::const_iterator ti;
317 ti = _materials.find(new_tex);
318 if (ti != _materials.end()) {
323 _materials.insert(Materials::value_type(new_tex, 0));
324 _ordered_materials.push_back(new_tex);
326 nassertr(_materials.size() == _ordered_materials.size(),
false);
336 nassertr(_materials.size() == _ordered_materials.size(),
false);
338 Materials::iterator ti;
339 ti = _materials.find(material);
340 if (ti == _materials.end()) {
345 _materials.erase(ti);
347 OrderedMaterials::iterator oti;
349 oti = find(_ordered_materials.begin(), _ordered_materials.end(), ptex);
350 nassertr(oti != _ordered_materials.end(),
false);
352 _ordered_materials.erase(oti);
354 nassertr(_materials.size() == _ordered_materials.size(),
false);
366 OrderedMaterials::const_iterator oti;
367 for (oti = _ordered_materials.begin();
368 oti != _ordered_materials.end();
388 OrderedMaterials::const_iterator oti;
389 for (oti = _ordered_materials.begin();
390 oti != _ordered_materials.end();
393 if (tex->get_name() == mref_name) {
A base class for any of a number of kinds of geometry primitives: polygons, point lights,...
void sort_by_mref()
Sorts all the materials into alphabetical order by MRef name.
get_material
Returns a pointer to the applied material, or NULL if there is no material applied.
This is our own Panda specialization on the default STL map.
void uniquify_mrefs()
Guarantees that each material in the collection has a unique MRef name.
bool is_equivalent_to(const EggMaterial &other, int eq) const
Returns true if the two materials are equivalent in all relevant properties (according to eq),...
A base class for nodes in the hierarchy that are not leaf nodes.
This is a collection of materials by MRef name.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
bool add_material(EggMaterial *material)
Explicitly adds a new material to the collection.
void clear()
Removes all materials from the collection.
int collapse_equivalent_materials(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate materials that are equivalent accord...
set_material
Applies the indicated material to the primitive.
EggGroupNode::iterator insert_materials(EggGroupNode *node)
Adds a series of EggMaterial nodes to the beginning of the indicated node to reflect each of the mate...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
static void replace_materials(EggGroupNode *node, const MaterialReplacement &replace)
Walks the egg hierarchy, changing out any reference to a material appearing on the left side of the m...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A handy class for converting a list of arbitrary names (strings) so that each name is guaranteed to b...
bool remove_material(EggMaterial *material)
Explicitly removes a material from the collection.
int extract_materials(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in ...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
An STL function object for sorting materials into order by properties.
std::string add_name(const std::string &name)
If name is nonempty and so far unique, returns it unchanged.
void remove_unused_materials(EggNode *node)
Removes any materials from the collection that aren't referenced by any primitives in the indicated e...
A base class for things that may be directly added into the egg hierarchy.
EggMaterial * create_unique_material(const EggMaterial ©, int eq)
Creates a new material if there is not already one equivalent (according to eq, see EggMaterial::is_e...
bool is_of_type(TypeHandle handle) const
Returns true if the current object is or derives from the indicated type.
This is our own Panda specialization on the default STL set.
EggMaterial * find_mref(const std::string &mref_name) const
Returns the material with the indicated MRef name, or NULL if no material matches.
int find_used_materials(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by...
An STL function object for sorting an array of pointers to Namables into order by name.
has_material
Returns true if the primitive is materiald (and get_material() will return a real pointer),...