1
0

IMeshCache.h 5.3 KB

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