Panda3D
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"
21 #include "vector_PT_EggMaterial.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  */
30 class 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 
36 private:
38  typedef vector_PT_EggMaterial OrderedMaterials;
39 
40 public:
41  typedef OrderedMaterials::const_iterator iterator;
42  typedef iterator const_iterator;
43  typedef OrderedMaterials::size_type size_type;
44 
46 
47  // Here begins the actual public interface to EggMaterialCollection.
48 
49 PUBLISHED:
52  EggMaterialCollection &operator = (const EggMaterialCollection &copy);
54 
55  void clear();
56 
57  int extract_materials(EggGroupNode *node);
58 
59 public:
60  EggGroupNode::iterator insert_materials(EggGroupNode *node);
61  EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
62 
63 PUBLISHED:
64  int find_used_materials(EggNode *node);
65  void remove_unused_materials(EggNode *node);
66 
67  int collapse_equivalent_materials(int eq, EggGroupNode *node);
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.
77 public:
78  INLINE iterator begin() const;
79  INLINE iterator end() const;
80  INLINE bool empty() const;
81  INLINE size_type size() const;
82 
83 PUBLISHED:
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.
90  EggMaterial *create_unique_material(const EggMaterial &copy, int eq);
91 
92  // Find a material with a particular MRef name.
93  EggMaterial *find_mref(const std::string &mref_name) const;
94 
95 private:
96  Materials _materials;
97  OrderedMaterials _ordered_materials;
98 };
99 
100 #include "eggMaterialCollection.I"
101 
102 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for nodes in the hierarchy that are not leaf nodes.
Definition: eggGroupNode.h:46
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A base class for things that may be directly added into the egg hierarchy.
Definition: eggNode.h:35