eggMaterialCollection.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. #ifndef EGGMATERIALCOLLECTION_H
  15. #define EGGMATERIALCOLLECTION_H
  16. #include "pandabase.h"
  17. #include "eggMaterial.h"
  18. #include "eggGroupNode.h"
  19. #include "vector_PT_EggMaterial.h"
  20. #include "pmap.h"
  21. ////////////////////////////////////////////////////////////////////
  22. // Class : EggMaterialCollection
  23. // Description : This is a collection of materials by MRef name. It
  24. // can extract the materials from an egg file and sort
  25. // them all together; it can also manage the creation of
  26. // unique materials and the assignment of unique MRef
  27. // names.
  28. ////////////////////////////////////////////////////////////////////
  29. class EXPCL_PANDAEGG EggMaterialCollection {
  30. // This is a bit of private interface stuff that must be here as a
  31. // forward reference. This allows us to define the
  32. // EggMaterialCollection as an STL container.
  33. private:
  34. typedef pmap<PT_EggMaterial, int> Materials;
  35. typedef vector_PT_EggMaterial OrderedMaterials;
  36. public:
  37. typedef OrderedMaterials::const_iterator iterator;
  38. typedef iterator const_iterator;
  39. typedef OrderedMaterials::size_type size_type;
  40. typedef pmap<PT_EggMaterial, PT_EggMaterial > MaterialReplacement;
  41. // Here begins the actual public interface to EggMaterialCollection.
  42. PUBLISHED:
  43. EggMaterialCollection();
  44. EggMaterialCollection(const EggMaterialCollection &copy);
  45. EggMaterialCollection &operator = (const EggMaterialCollection &copy);
  46. ~EggMaterialCollection();
  47. void clear();
  48. int extract_materials(EggGroupNode *node);
  49. public:
  50. EggGroupNode::iterator insert_materials(EggGroupNode *node);
  51. EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
  52. PUBLISHED:
  53. int find_used_materials(EggNode *node);
  54. void remove_unused_materials(EggNode *node);
  55. int collapse_equivalent_materials(int eq, EggGroupNode *node);
  56. int collapse_equivalent_materials(int eq, MaterialReplacement &removed);
  57. static void replace_materials(EggGroupNode *node,
  58. const MaterialReplacement &replace);
  59. void uniquify_mrefs();
  60. void sort_by_mref();
  61. // Can be used to traverse all the materials in the collection, in
  62. // order as last sorted.
  63. public:
  64. INLINE iterator begin() const;
  65. INLINE iterator end() const;
  66. INLINE bool empty() const;
  67. INLINE size_type size() const;
  68. PUBLISHED:
  69. bool add_material(EggMaterial *material);
  70. bool remove_material(EggMaterial *material);
  71. // create_unique_material() creates a new material if there is not
  72. // already one equivalent (according to eq, see
  73. // EggMaterial::is_equivalent_to()) to the indicated material, or
  74. // returns the existing one if there is.
  75. EggMaterial *create_unique_material(const EggMaterial &copy, int eq);
  76. // Find a material with a particular MRef name.
  77. EggMaterial *find_mref(const string &mref_name) const;
  78. private:
  79. Materials _materials;
  80. OrderedMaterials _ordered_materials;
  81. };
  82. #include "eggMaterialCollection.I"
  83. #endif