Panda3D

eggMaterialCollection.h

00001 // Filename: eggMaterialCollection.h
00002 // Created by:  drose (30Apr01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef EGGMATERIALCOLLECTION_H
00016 #define EGGMATERIALCOLLECTION_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "eggMaterial.h"
00021 #include "eggGroupNode.h"
00022 #include "vector_PT_EggMaterial.h"
00023 
00024 #include "pmap.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : EggMaterialCollection
00028 // Description : This is a collection of materials by MRef name.  It
00029 //               can extract the materials from an egg file and sort
00030 //               them all together; it can also manage the creation of
00031 //               unique materials and the assignment of unique MRef
00032 //               names.
00033 ////////////////////////////////////////////////////////////////////
00034 class EXPCL_PANDAEGG EggMaterialCollection {
00035 
00036   // This is a bit of private interface stuff that must be here as a
00037   // forward reference.  This allows us to define the
00038   // EggMaterialCollection as an STL container.
00039 
00040 private:
00041   typedef pmap<PT_EggMaterial, int> Materials;
00042   typedef vector_PT_EggMaterial OrderedMaterials;
00043 
00044 public:
00045   typedef OrderedMaterials::const_iterator iterator;
00046   typedef iterator const_iterator;
00047   typedef OrderedMaterials::size_type size_type;
00048 
00049   typedef pmap<PT_EggMaterial,  PT_EggMaterial > MaterialReplacement;
00050 
00051   // Here begins the actual public interface to EggMaterialCollection.
00052 
00053 PUBLISHED:
00054   EggMaterialCollection();
00055   EggMaterialCollection(const EggMaterialCollection &copy);
00056   EggMaterialCollection &operator = (const EggMaterialCollection &copy);
00057   ~EggMaterialCollection();
00058 
00059   void clear();
00060 
00061   int extract_materials(EggGroupNode *node);
00062 
00063 public:
00064   EggGroupNode::iterator insert_materials(EggGroupNode *node);
00065   EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
00066 
00067 PUBLISHED:
00068   int find_used_materials(EggNode *node);
00069   void remove_unused_materials(EggNode *node);
00070 
00071   int collapse_equivalent_materials(int eq, EggGroupNode *node);
00072   int collapse_equivalent_materials(int eq, MaterialReplacement &removed);
00073   static void replace_materials(EggGroupNode *node,
00074                                const MaterialReplacement &replace);
00075 
00076   void uniquify_mrefs();
00077   void sort_by_mref();
00078 
00079   // Can be used to traverse all the materials in the collection, in
00080   // order as last sorted.
00081 public:
00082   INLINE iterator begin() const;
00083   INLINE iterator end() const;
00084   INLINE bool empty() const;
00085   INLINE size_type size() const;
00086 
00087 PUBLISHED:
00088   bool add_material(EggMaterial *material);
00089   bool remove_material(EggMaterial *material);
00090 
00091   // create_unique_material() creates a new material if there is not
00092   // already one equivalent (according to eq, see
00093   // EggMaterial::is_equivalent_to()) to the indicated material, or
00094   // returns the existing one if there is.
00095   EggMaterial *create_unique_material(const EggMaterial &copy, int eq);
00096 
00097   // Find a material with a particular MRef name.
00098   EggMaterial *find_mref(const string &mref_name) const;
00099 
00100 private:
00101   Materials _materials;
00102   OrderedMaterials _ordered_materials;
00103 };
00104 
00105 #include "eggMaterialCollection.I"
00106 
00107 #endif
 All Classes Functions Variables Enumerations