Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/egg/eggMaterialCollection.h

Go to the documentation of this file.
00001 // Filename: eggMaterialCollection.h
00002 // Created by:  drose (30Apr01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef EGGMATERIALCOLLECTION_H
00020 #define EGGMATERIALCOLLECTION_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "eggMaterial.h"
00025 #include "eggGroupNode.h"
00026 #include "vector_PT_EggMaterial.h"
00027 
00028 #include <string>
00029 #include "pmap.h"
00030 
00031 ////////////////////////////////////////////////////////////////////
00032 //       Class : EggMaterialCollection
00033 // Description : This is a collection of materials by MRef name.  It
00034 //               can extract the materials from an egg file and sort
00035 //               them all together; it can also manage the creation of
00036 //               unique materials and the assignment of unique MRef
00037 //               names.
00038 ////////////////////////////////////////////////////////////////////
00039 class EXPCL_PANDAEGG EggMaterialCollection {
00040 
00041   // This is a bit of private interface stuff that must be here as a
00042   // forward reference.  This allows us to define the
00043   // EggMaterialCollection as an STL container.
00044 
00045 private:
00046   typedef pmap<PT_EggMaterial, int> Materials;
00047   typedef vector_PT_EggMaterial OrderedMaterials;
00048 
00049 public:
00050   typedef OrderedMaterials::const_iterator iterator;
00051   typedef iterator const_iterator;
00052   typedef OrderedMaterials::size_type size_type;
00053 
00054   typedef pmap<PT_EggMaterial,  PT_EggMaterial > MaterialReplacement;
00055 
00056   // Here begins the actual public interface to EggMaterialCollection.
00057 
00058 public:
00059   EggMaterialCollection();
00060   EggMaterialCollection(const EggMaterialCollection &copy);
00061   EggMaterialCollection &operator = (const EggMaterialCollection &copy);
00062   ~EggMaterialCollection();
00063 
00064   void clear();
00065 
00066   int extract_materials(EggGroupNode *node);
00067   EggGroupNode::iterator insert_materials(EggGroupNode *node);
00068   EggGroupNode::iterator insert_materials(EggGroupNode *node, EggGroupNode::iterator position);
00069 
00070   int find_used_materials(EggNode *node);
00071   void remove_unused_materials(EggNode *node);
00072 
00073   int collapse_equivalent_materials(int eq, EggGroupNode *node);
00074   int collapse_equivalent_materials(int eq, MaterialReplacement &removed);
00075   static void replace_materials(EggGroupNode *node,
00076                                const MaterialReplacement &replace);
00077 
00078   void uniquify_mrefs();
00079   void sort_by_mref();
00080 
00081   // Can be used to traverse all the materials in the collection, in
00082   // order as last sorted.
00083   INLINE iterator begin() const;
00084   INLINE iterator end() const;
00085   INLINE bool empty() const;
00086   INLINE size_type size() const;
00087 
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

Generated on Fri May 2 00:37:42 2003 for Panda by doxygen1.3