15 #include "eggMaterialCollection.h" 16 #include "eggGroupNode.h" 17 #include "eggPrimitive.h" 18 #include "eggMaterial.h" 20 #include "nameUniquifier.h" 30 EggMaterialCollection::
31 EggMaterialCollection() {
39 EggMaterialCollection::
41 _materials(copy._materials),
42 _ordered_materials(copy._ordered_materials)
53 _materials = copy._materials;
54 _ordered_materials = copy._ordered_materials;
63 EggMaterialCollection::
64 ~EggMaterialCollection() {
75 _ordered_materials.clear();
90 return node->find_materials(
this);
116 OrderedMaterials::iterator oti;
117 for (oti = _ordered_materials.begin();
118 oti != _ordered_materials.end();
121 position = node->insert(position, material);
157 if (node->
is_of_type(EggPrimitive::get_class_type())) {
161 Materials::iterator ti = _materials.find(tex);
162 if (ti == _materials.end()) {
165 _materials.insert(Materials::value_type(tex, 1));
166 _ordered_materials.push_back(tex);
174 }
else if (node->
is_of_type(EggGroupNode::get_class_type())) {
177 EggGroupNode::iterator ci;
178 for (ci = group->begin(); ci != group->end(); ++ci) {
228 return num_collapsed;
250 int num_collapsed = 0;
254 Collapser collapser(uet);
258 OrderedMaterials::const_iterator oti;
259 for (oti = _ordered_materials.begin();
260 oti != _ordered_materials.end();
264 pair<Collapser::const_iterator, bool> result = collapser.insert(tex);
265 if (!result.second) {
268 removed.insert(MaterialReplacement::value_type(tex, first));
275 Collapser::const_iterator ci;
276 for (ci = collapser.begin(); ci != collapser.end(); ++ci) {
280 return num_collapsed;
296 EggGroupNode::iterator ci;
297 for (ci = node->begin();
301 if (child->
is_of_type(EggPrimitive::get_class_type())) {
305 MaterialReplacement::const_iterator ri;
306 ri = replace.find(tex);
307 if (ri != replace.end()) {
313 }
else if (child->
is_of_type(EggGroupNode::get_class_type())) {
331 OrderedMaterials::const_iterator oti;
332 for (oti = _ordered_materials.begin();
333 oti != _ordered_materials.end();
337 tex->set_name(nu.
add_name(tex->get_name()));
350 sort(_ordered_materials.begin(), _ordered_materials.end(),
363 nassertr(_materials.size() == _ordered_materials.size(),
false);
367 Materials::const_iterator ti;
368 ti = _materials.find(new_tex);
369 if (ti != _materials.end()) {
374 _materials.insert(Materials::value_type(new_tex, 0));
375 _ordered_materials.push_back(new_tex);
377 nassertr(_materials.size() == _ordered_materials.size(),
false);
390 nassertr(_materials.size() == _ordered_materials.size(),
false);
392 Materials::iterator ti;
393 ti = _materials.find(material);
394 if (ti == _materials.end()) {
399 _materials.erase(ti);
401 OrderedMaterials::iterator oti;
403 oti = find(_ordered_materials.begin(), _ordered_materials.end(), ptex);
404 nassertr(oti != _ordered_materials.end(),
false);
406 _ordered_materials.erase(oti);
408 nassertr(_materials.size() == _ordered_materials.size(),
false);
424 OrderedMaterials::const_iterator oti;
425 for (oti = _ordered_materials.begin();
426 oti != _ordered_materials.end();
449 OrderedMaterials::const_iterator oti;
450 for (oti = _ordered_materials.begin();
451 oti != _ordered_materials.end();
454 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.
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.
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...
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...
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...
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.
void set_material(EggMaterial *material)
Applies the indicated material to the primitive.
int extract_materials(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in ...
An STL function object for sorting materials into order by properties.
EggMaterial * get_material() const
Returns a pointer to the applied material, or NULL if there is no material applied.
void remove_unused_materials(EggNode *node)
Removes any materials from the collection that aren't referenced by any primitives in the indicated e...
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.
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.
int find_used_materials(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by...
bool has_material() const
Returns true if the primitive is materiald (and get_material() will return a real pointer)...
An STL function object for sorting an array of pointers to Namables into order by name...
EggMaterial * find_mref(const string &mref_name) const
Returns the material with the indicated MRef name, or NULL if no material matches.