Panda3D
|
00001 // Filename: eggTextureCollection.h 00002 // Created by: drose (15Feb00) 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 EGGTEXTURECOLLECTION_H 00016 #define EGGTEXTURECOLLECTION_H 00017 00018 #include "pandabase.h" 00019 00020 #include "eggTexture.h" 00021 #include "eggGroupNode.h" 00022 #include "vector_PT_EggTexture.h" 00023 00024 #include "pmap.h" 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : EggTextureCollection 00028 // Description : This is a collection of textures by TRef name. It 00029 // can extract the textures from an egg file and sort 00030 // them all together; it can also manage the creation of 00031 // unique textures and the assignment of unique TRef 00032 // names. 00033 //////////////////////////////////////////////////////////////////// 00034 class EXPCL_PANDAEGG EggTextureCollection { 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 // EggTextureCollection as an STL container. 00039 00040 private: 00041 typedef pmap<PT_EggTexture, int> Textures; 00042 typedef vector_PT_EggTexture OrderedTextures; 00043 00044 public: 00045 typedef OrderedTextures::const_iterator iterator; 00046 typedef iterator const_iterator; 00047 typedef OrderedTextures::size_type size_type; 00048 00049 typedef pmap<PT_EggTexture, PT_EggTexture > TextureReplacement; 00050 00051 // Here begins the actual public interface to EggTextureCollection. 00052 00053 PUBLISHED: 00054 EggTextureCollection(); 00055 EggTextureCollection(const EggTextureCollection ©); 00056 EggTextureCollection &operator = (const EggTextureCollection ©); 00057 ~EggTextureCollection(); 00058 00059 void clear(); 00060 00061 int extract_textures(EggGroupNode *node); 00062 00063 bool is_empty() const; 00064 int get_num_textures() const; 00065 EggTexture *get_texture(int index) const; 00066 MAKE_SEQ(get_textures, get_num_textures, get_texture); 00067 00068 public: 00069 EggGroupNode::iterator insert_textures(EggGroupNode *node); 00070 EggGroupNode::iterator insert_textures(EggGroupNode *node, EggGroupNode::iterator position); 00071 00072 PUBLISHED: 00073 int find_used_textures(EggNode *node); 00074 void remove_unused_textures(EggNode *node); 00075 00076 int collapse_equivalent_textures(int eq, EggGroupNode *node); 00077 int collapse_equivalent_textures(int eq, TextureReplacement &removed); 00078 static void replace_textures(EggGroupNode *node, 00079 const TextureReplacement &replace); 00080 00081 void uniquify_trefs(); 00082 void sort_by_tref(); 00083 void sort_by_basename(); 00084 00085 public: 00086 // Can be used to traverse all the textures in the collection, in 00087 // order as last sorted. 00088 INLINE iterator begin() const; 00089 INLINE iterator end() const; 00090 INLINE bool empty() const; 00091 00092 PUBLISHED: 00093 INLINE EggTexture *operator [](size_type n) const; 00094 INLINE size_type size() const; 00095 00096 bool add_texture(EggTexture *texture); 00097 bool remove_texture(EggTexture *texture); 00098 00099 // create_unique_texture() creates a new texture if there is not 00100 // already one equivalent (according to eq, see 00101 // EggTexture::is_equivalent_to()) to the indicated texture, or 00102 // returns the existing one if there is. 00103 EggTexture *create_unique_texture(const EggTexture ©, int eq); 00104 00105 // Find a texture with a particular TRef name. 00106 EggTexture *find_tref(const string &tref_name) const; 00107 00108 // Find a texture with a particular filename. 00109 EggTexture *find_filename(const Filename &filename) const; 00110 00111 private: 00112 Textures _textures; 00113 OrderedTextures _ordered_textures; 00114 }; 00115 00116 #include "eggTextureCollection.I" 00117 00118 #endif