1
// Copyright (C) 2002-2011 Nikolaus Gebhardt
2
// This file is part of the "Irrlicht Engine".
3
// For conditions of distribution and use, see copyright notice in irrlicht.h
5
#ifndef __C_MESH_CACHE_H_INCLUDED__
6
#define __C_MESH_CACHE_H_INCLUDED__
8
#include "IMeshCache.h"
16
class CMeshCache : public IMeshCache
20
virtual ~CMeshCache();
22
//! Adds a mesh to the internal list of loaded meshes.
23
/** Usually, ISceneManager::getMesh() is called to load a mesh from file.
24
That method searches the list of loaded meshes if a mesh has already been loaded and
25
returns a pointer to if it is in that list and already in memory. Otherwise it loads
26
the mesh. With IMeshCache::addMesh(), it is possible to pretend that a mesh already
27
has been loaded. This method can be used for example by mesh loaders who need to
28
load more than one mesh with one call. They can add additional meshes with this
29
method to the scene manager. The COLLADA loader for example uses this method.
30
\param filename: Filename of the mesh. When called ISceneManager::getMesh() with this
31
parameter, the method will return the mesh parameter given with this method.
32
\param mesh: Pointer to a mesh which will now be referenced by this name. */
33
virtual void addMesh(const io::path& filename, IAnimatedMesh* mesh);
35
//! Removes a mesh from the cache.
36
/** After loading a mesh with getMesh(), the mesh can be removed from the cache
37
using this method, freeing a lot of memory. */
38
virtual void removeMesh(const IMesh* const mesh);
40
//! Returns amount of loaded meshes in the cache.
41
/** You can load new meshes into the cache using getMesh() and addMesh().
42
If you ever need to access the internal mesh cache, you can do this using
43
removeMesh(), getMeshNumber(), getMeshByIndex() and getMeshFilename() */
44
virtual u32 getMeshCount() const;
46
//! Returns current index number of the mesh, and -1 if it is not in the cache.
47
virtual s32 getMeshIndex(const IMesh* const mesh) const;
49
//! Returns a mesh based on its index number.
50
/** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
51
Note that this number is only valid until a new mesh is loaded or removed *
52
\return Returns pointer to the mesh or 0 if there is none with this number. */
53
virtual IAnimatedMesh* getMeshByIndex(u32 index);
55
//! Returns a mesh based on its name.
56
/** \param name Name of the mesh. Usually a filename.
57
\return Pointer to the mesh or 0 if there is none with this number. */
58
virtual IAnimatedMesh* getMeshByName(const io::path& name);
60
//! Get the name of a loaded mesh, based on its index.
61
/** \param index: Index of the mesh, number between 0 and getMeshCount()-1.
62
\return The name if mesh was found and has a name, else the path is empty. */
63
virtual const io::SNamedPath& getMeshName(u32 index) const;
65
//! Get the name of a loaded mesh, if there is any.
66
/** \param mesh Pointer to mesh to query.
67
\return The name if mesh was found and has a name, else the path is empty. */
68
virtual const io::SNamedPath& getMeshName(const IMesh* const mesh) const;
70
//! Renames a loaded mesh.
71
/** Note that renaming meshes might change the ordering of the
72
meshes, and so the index of the meshes as returned by
73
getMeshIndex() or taken by some methods will change.
74
\param index The index of the mesh in the cache.
75
\param name New name for the mesh.
76
\return True if mesh was renamed. */
77
virtual bool renameMesh(u32 index, const io::path& name);
79
//! Renames a loaded mesh.
80
/** Note that renaming meshes might change the ordering of the
81
meshes, and so the index of the meshes as returned by
82
getMeshIndex() or taken by some methods will change.
83
\param mesh Mesh to be renamed.
84
\param name New name for the mesh.
85
\return True if mesh was renamed. */
86
virtual bool renameMesh(const IMesh* const mesh, const io::path& name);
88
//! returns if a mesh already was loaded
89
virtual bool isMeshLoaded(const io::path& name);
91
//! Clears the whole mesh cache, removing all meshes.
94
//! Clears all meshes that are held in the mesh cache but not used anywhere else.
95
virtual void clearUnusedMeshes();
101
MeshEntry ( const io::path& name )
105
io::SNamedPath NamedPath;
108
bool operator < (const MeshEntry& other) const
110
return (NamedPath < other.NamedPath);
115
core::array<MeshEntry> Meshes;
119
} // end namespace scene
120
} // end namespace irr