Panda3D
eggMaterialCollection.h
1 // Filename: eggMaterialCollection.h
2 // Created by: drose (30Apr01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef EGGMATERIALCOLLECTION_H
16 #define EGGMATERIALCOLLECTION_H
17 
18 #include "pandabase.h"
19 
20 #include "eggMaterial.h"
21 #include "eggGroupNode.h"
22 #include "vector_PT_EggMaterial.h"
23 
24 #include "pmap.h"
25 
26 ////////////////////////////////////////////////////////////////////
27 // Class : EggMaterialCollection
28 // Description : This is a collection of materials by MRef name. It
29 // can extract the materials from an egg file and sort
30 // them all together; it can also manage the creation of
31 // unique materials and the assignment of unique MRef
32 // names.
33 ////////////////////////////////////////////////////////////////////
34 class EXPCL_PANDAEGG EggMaterialCollection {
35 
36  // This is a bit of private interface stuff that must be here as a
37  // forward reference. This allows us to define the
38  // EggMaterialCollection as an STL container.
39 
40 private:
42  typedef vector_PT_EggMaterial OrderedMaterials;
43 
44 public:
45  typedef OrderedMaterials::const_iterator iterator;
46  typedef iterator const_iterator;
47  typedef OrderedMaterials::size_type size_type;
48 
50 
51  // Here begins the actual public interface to EggMaterialCollection.
52 
53 PUBLISHED:
56  EggMaterialCollection &operator = (const EggMaterialCollection &copy);
58 
59  void clear();
60 
61  int extract_materials(EggGroupNode *node);
62 
63 public:
64  EggGroupNode::iterator insert_materials(EggGroupNode *node);
65  EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
66 
67 PUBLISHED:
68  int find_used_materials(EggNode *node);
69  void remove_unused_materials(EggNode *node);
70 
71  int collapse_equivalent_materials(int eq, EggGroupNode *node);
72  int collapse_equivalent_materials(int eq, MaterialReplacement &removed);
73  static void replace_materials(EggGroupNode *node,
74  const MaterialReplacement &replace);
75 
76  void uniquify_mrefs();
77  void sort_by_mref();
78 
79  // Can be used to traverse all the materials in the collection, in
80  // order as last sorted.
81 public:
82  INLINE iterator begin() const;
83  INLINE iterator end() const;
84  INLINE bool empty() const;
85  INLINE size_type size() const;
86 
87 PUBLISHED:
88  bool add_material(EggMaterial *material);
89  bool remove_material(EggMaterial *material);
90 
91  // create_unique_material() creates a new material if there is not
92  // already one equivalent (according to eq, see
93  // EggMaterial::is_equivalent_to()) to the indicated material, or
94  // returns the existing one if there is.
95  EggMaterial *create_unique_material(const EggMaterial &copy, int eq);
96 
97  // Find a material with a particular MRef name.
98  EggMaterial *find_mref(const string &mref_name) const;
99 
100 private:
101  Materials _materials;
102  OrderedMaterials _ordered_materials;
103 };
104 
105 #include "eggMaterialCollection.I"
106 
107 #endif
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:51
This is a collection of materials by MRef name.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:38