Panda3D
Loading...
Searching...
No Matches
eggMaterialCollection.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 eggMaterialCollection.h
10 * @author drose
11 * @date 2001-04-30
12 */
13
14#ifndef EGGMATERIALCOLLECTION_H
15#define EGGMATERIALCOLLECTION_H
16
17#include "pandabase.h"
18
19#include "eggMaterial.h"
20#include "eggGroupNode.h"
22
23#include "pmap.h"
24
25/**
26 * This is a collection of materials by MRef name. It can extract the
27 * materials from an egg file and sort them all together; it can also manage
28 * the creation of unique materials and the assignment of unique MRef names.
29 */
30class EXPCL_PANDA_EGG EggMaterialCollection {
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 EggMaterialCollection as an STL
34 // container.
35
36private:
37 typedef pmap<PT_EggMaterial, int> Materials;
38 typedef vector_PT_EggMaterial OrderedMaterials;
39
40public:
41 typedef OrderedMaterials::const_iterator iterator;
42 typedef iterator const_iterator;
43 typedef OrderedMaterials::size_type size_type;
44
45 typedef pmap<PT_EggMaterial, PT_EggMaterial > MaterialReplacement;
46
47 // Here begins the actual public interface to EggMaterialCollection.
48
49PUBLISHED:
50 EggMaterialCollection();
51 EggMaterialCollection(const EggMaterialCollection &copy);
52 EggMaterialCollection &operator = (const EggMaterialCollection &copy);
53 ~EggMaterialCollection();
54
55 void clear();
56
58
59public:
60 EggGroupNode::iterator insert_materials(EggGroupNode *node);
61 EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
62
63PUBLISHED:
66
68 int collapse_equivalent_materials(int eq, MaterialReplacement &removed);
69 static void replace_materials(EggGroupNode *node,
70 const MaterialReplacement &replace);
71
72 void uniquify_mrefs();
73 void sort_by_mref();
74
75 // Can be used to traverse all the materials in the collection, in order as
76 // last sorted.
77public:
78 INLINE iterator begin() const;
79 INLINE iterator end() const;
80 INLINE bool empty() const;
81 INLINE size_type size() const;
82
83PUBLISHED:
84 bool add_material(EggMaterial *material);
85 bool remove_material(EggMaterial *material);
86
87 // create_unique_material() creates a new material if there is not already
88 // one equivalent (according to eq, see EggMaterial::is_equivalent_to()) to
89 // the indicated material, or returns the existing one if there is.
91
92 // Find a material with a particular MRef name.
93 EggMaterial *find_mref(const std::string &mref_name) const;
94
95private:
96 Materials _materials;
97 OrderedMaterials _ordered_materials;
98};
99
101
102#endif
A base class for nodes in the hierarchy that are not leaf nodes.
bool add_material(EggMaterial *material)
Explicitly adds a new material to the collection.
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...
void uniquify_mrefs()
Guarantees that each material in the collection has a unique MRef name.
int find_used_materials(EggNode *node)
Walks the egg hierarchy beginning at the indicated node, looking for materials that are referenced by...
int collapse_equivalent_materials(int eq, EggGroupNode *node)
Walks through the collection and collapses together any separate materials that are equivalent accord...
int extract_materials(EggGroupNode *node)
Walks the egg hierarchy beginning at the indicated node, and removes any EggMaterials encountered in ...
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...
bool remove_material(EggMaterial *material)
Explicitly removes a material from the collection.
void sort_by_mref()
Sorts all the materials into alphabetical order by MRef name.
EggMaterial * create_unique_material(const EggMaterial &copy, int eq)
Creates a new material if there is not already one equivalent (according to eq, see EggMaterial::is_e...
void clear()
Removes all materials from the collection.
EggMaterial * find_mref(const std::string &mref_name) const
Returns the material with the indicated MRef name, or NULL if no material matches.
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.
Definition eggNode.h:36
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.