IMeshCache.h 7.0 KB

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