1 // Copyright (C) 2002-2012 Nikolaus Gebhardt
\r
2 // This file is part of the "Irrlicht Engine".
\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h
\r
5 #ifndef __I_MESH_CACHE_H_INCLUDED__
\r
6 #define __I_MESH_CACHE_H_INCLUDED__
\r
8 #include "IReferenceCounted.h"
\r
17 class IAnimatedMesh;
\r
18 class IAnimatedMeshSceneNode;
\r
21 //! The mesh cache stores already loaded meshes and provides an interface to them.
\r
22 /** You can access it using ISceneManager::getMeshCache(). All existing
\r
23 scene managers will return a pointer to the same mesh cache, because it
\r
24 is shared between them. With this interface, it is possible to manually
\r
25 add new loaded meshes (if ISceneManager::getMesh() is not sufficient),
\r
26 to remove them and to iterate through already loaded meshes. */
\r
27 class IMeshCache : public virtual IReferenceCounted
\r
32 virtual ~IMeshCache() {}
\r
34 //! Adds a mesh to the internal list of loaded meshes.
\r
35 /** Usually, ISceneManager::getMesh() is called to load a mesh
\r
36 from a file. That method searches the list of loaded meshes if
\r
37 a mesh has already been loaded and returns a pointer to if it
\r
38 is in that list and already in memory. Otherwise it loads the
\r
39 mesh. With IMeshCache::addMesh(), it is possible to pretend
\r
40 that a mesh already has been loaded. This method can be used
\r
41 for example by mesh loaders who need to load more than one mesh
\r
42 with one call. They can add additional meshes with this method
\r
43 to the scene manager. The COLLADA loader for example uses this
\r
45 \param name Name of the mesh. When calling
\r
46 ISceneManager::getMesh() with this name it will return the mesh
\r
48 \param mesh Pointer to a mesh which will now be referenced by
\r
50 virtual void addMesh(const io::path& name, IAnimatedMesh* mesh) = 0;
\r
52 //! Removes the mesh from the cache.
\r
53 /** After loading a mesh with getMesh(), the mesh can be
\r
54 removed from the cache using this method, freeing a lot of
\r
56 \param mesh Pointer to the mesh which shall be removed. */
\r
57 virtual void removeMesh(const IMesh* const mesh) = 0;
\r
59 //! Returns amount of loaded meshes in the cache.
\r
60 /** You can load new meshes into the cache using getMesh() and
\r
61 addMesh(). If you ever need to access the internal mesh cache,
\r
62 you can do this using removeMesh(), getMeshNumber(),
\r
63 getMeshByIndex() and getMeshName().
\r
64 \return Number of meshes in cache. */
\r
65 virtual u32 getMeshCount() const = 0;
\r
67 //! Returns current index number of the mesh or -1 when not found.
\r
68 /** \param mesh Pointer to the mesh to search for.
\r
69 \return Index of the mesh in the cache, or -1 if not found. */
\r
70 virtual s32 getMeshIndex(const IMesh* const mesh) const = 0;
\r
72 //! Returns a mesh based on its index number.
\r
73 /** \param index: Index of the mesh, number between 0 and
\r
75 Note that this number is only valid until a new mesh is loaded
\r
77 \return Pointer to the mesh or 0 if there is none with this
\r
79 virtual IAnimatedMesh* getMeshByIndex(u32 index) = 0;
\r
81 //! Returns a mesh based on its name (often a filename).
\r
82 /** \deprecated Use getMeshByName() instead. This method may be removed by
\r
84 _IRR_DEPRECATED_ IAnimatedMesh* getMeshByFilename(const io::path& filename)
\r
86 return getMeshByName(filename);
\r
89 //! Get the name of a loaded mesh, based on its index. (Name is often identical to the filename).
\r
90 /** \deprecated Use getMeshName() instead. This method may be removed by
\r
92 _IRR_DEPRECATED_ const io::path& getMeshFilename(u32 index) const
\r
94 return getMeshName(index).getInternalName();
\r
97 //! Get the name of a loaded mesh, if there is any. (Name is often identical to the filename).
\r
98 /** \deprecated Use getMeshName() instead. This method may be removed by
\r
100 _IRR_DEPRECATED_ const io::path& getMeshFilename(const IMesh* const mesh) const
\r
102 return getMeshName(mesh).getInternalName();
\r
105 //! Renames a loaded mesh.
\r
106 /** \deprecated Use renameMesh() instead. This method may be removed by
\r
108 _IRR_DEPRECATED_ bool setMeshFilename(u32 index, const io::path& filename)
\r
110 return renameMesh(index, filename);
\r
113 //! Renames a loaded mesh.
\r
114 /** \deprecated Use renameMesh() instead. This method may be removed by
\r
116 _IRR_DEPRECATED_ bool setMeshFilename(const IMesh* const mesh, const io::path& filename)
\r
118 return renameMesh(mesh, filename);
\r
121 //! Returns a mesh based on its name.
\r
122 /** \param name Name of the mesh. Usually a filename.
\r
123 \return Pointer to the mesh or 0 if there is none with this number. */
\r
124 virtual IAnimatedMesh* getMeshByName(const io::path& name) = 0;
\r
126 //! Get the name of a loaded mesh, based on its index.
\r
127 /** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
\r
128 \return The name if mesh was found and has a name, else the path is empty. */
\r
129 virtual const io::SNamedPath& getMeshName(u32 index) const = 0;
\r
131 //! Get the name of the loaded mesh if there is any.
\r
132 /** \param mesh Pointer to mesh to query.
\r
133 \return The name if mesh was found and has a name, else the path is empty. */
\r
134 virtual const io::SNamedPath& getMeshName(const IMesh* const mesh) const = 0;
\r
136 //! Renames a loaded mesh.
\r
137 /** Note that renaming meshes might change the ordering of the
\r
138 meshes, and so the index of the meshes as returned by
\r
139 getMeshIndex() or taken by some methods will change.
\r
140 \param index The index of the mesh in the cache.
\r
141 \param name New name for the mesh.
\r
142 \return True if mesh was renamed. */
\r
143 virtual bool renameMesh(u32 index, const io::path& name) = 0;
\r
145 //! Renames the loaded mesh
\r
146 /** Note that renaming meshes might change the ordering of the
\r
147 meshes, and so the index of the meshes as returned by
\r
148 getMeshIndex() or taken by some methods will change.
\r
149 \param mesh Mesh to be renamed.
\r
150 \param name New name for the mesh.
\r
151 \return True if mesh was renamed. */
\r
152 virtual bool renameMesh(const IMesh* const mesh, const io::path& name) = 0;
\r
154 //! Check if a mesh was already loaded.
\r
155 /** \param name Name of the mesh. Usually a filename.
\r
156 \return True if the mesh has been loaded, else false. */
\r
157 virtual bool isMeshLoaded(const io::path& name) = 0;
\r
159 //! Clears the whole mesh cache, removing all meshes.
\r
160 /** All meshes will be reloaded completely when using ISceneManager::getMesh()
\r
161 after calling this method.
\r
162 Warning: If you have pointers to meshes that were loaded with ISceneManager::getMesh()
\r
163 and you did not grab them, then they may become invalid. */
\r
164 virtual void clear() = 0;
\r
166 //! Clears all meshes that are held in the mesh cache but not used anywhere else.
\r
167 /** Warning: If you have pointers to meshes that were loaded with ISceneManager::getMesh()
\r
168 and you did not grab them, then they may become invalid. */
\r
169 virtual void clearUnusedMeshes() = 0;
\r
173 } // end namespace scene
\r
174 } // end namespace irr
\r