15 #include "materialCollection.h"
25 MaterialCollection() {
35 _materials(copy._materials)
44 void MaterialCollection::
46 _materials = copy._materials;
61 if (_materials.get_ref_count() > 1) {
62 Materials old_materials = _materials;
63 _materials = Materials::empty_array(0);
64 _materials.v() = old_materials.v();
67 _materials.push_back(node_material);
79 int material_index = -1;
80 for (
int i = 0; material_index == -1 && i < (int)_materials.size(); i++) {
81 if (_materials[i] == node_material) {
86 if (material_index == -1) {
96 if (_materials.get_ref_count() > 1) {
97 Materials old_materials = _materials;
98 _materials = Materials::empty_array(0);
99 _materials.v() = old_materials.v();
102 _materials.erase(_materials.begin() + material_index);
117 for (
int i = 0; i < other_num_materials; i++) {
131 Materials new_materials;
133 for (
int i = 0; i < num_materials; i++) {
136 new_materials.push_back(material);
139 _materials = new_materials;
152 Materials new_materials;
155 for (
int i = 0; i < num_materials; i++) {
157 bool duplicated =
false;
159 for (
int j = 0; j < i && !duplicated; j++) {
164 new_materials.push_back(material);
168 _materials = new_materials;
207 for (
int i = 0; i < num_materials; i++) {
209 if (material->get_name() == name) {
223 return _materials.size();
233 nassertr(index >= 0 && index < (
int)_materials.size(), NULL);
235 return _materials[index];
247 nassertr(index >= 0 && index < (
int)_materials.size(), NULL);
249 return _materials[index];
260 return _materials.size();
285 write(ostream &out,
int indent_level)
const {
bool has_material(Material *material) const
Returns true if the indicated Material appears in this collection, false otherwise.
void add_material(Material *node_material)
Adds a new Material to the collection.
void write(ostream &out, int indent_level=0) const
Writes a complete multi-line description of the MaterialCollection to the indicated output stream...
int size() const
Returns the number of materials in the collection.
void clear()
Removes all Materials from the collection.
Material * get_material(int index) const
Returns the nth Material in the collection.
Defines the way an object appears in the presence of lighting.
void output(ostream &out) const
Writes a brief one-line description of the MaterialCollection to the indicated output stream...
Material * find_material(const string &name) const
Returns the material in the collection with the indicated name, if any, or NULL if no material has th...
void remove_duplicate_materials()
Removes any duplicate entries of the same Materials on this collection.
int get_num_materials() const
Returns the number of Materials in the collection.
void remove_materials_from(const MaterialCollection &other)
Removes from this collection all of the Materials listed in the other collection. ...
void add_materials_from(const MaterialCollection &other)
Adds all the Materials indicated in the other collection to this material.
Material * operator[](int index) const
Returns the nth Material in the collection.
bool remove_material(Material *node_material)
Removes the indicated Material from the collection.