IMeshLoader.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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_LOADER_H_INCLUDED
  5. #define IRR_I_MESH_LOADER_H_INCLUDED
  6. #include "IReferenceCounted.h"
  7. #include "path.h"
  8. #include "IMeshTextureLoader.h"
  9. namespace irr
  10. {
  11. namespace io
  12. {
  13. class IReadFile;
  14. } // end namespace io
  15. namespace scene
  16. {
  17. class IAnimatedMesh;
  18. //! Class which is able to load an animated mesh from a file.
  19. /** If you want Irrlicht be able to load meshes of
  20. currently unsupported file formats (e.g. .cob), then implement
  21. this and add your new Meshloader with
  22. ISceneManager::addExternalMeshLoader() to the engine. */
  23. class IMeshLoader : public virtual IReferenceCounted
  24. {
  25. public:
  26. //! Constructor
  27. IMeshLoader() : TextureLoader(0), IndexTypeHint(EITH_OPTIMAL) {}
  28. //! Destructor
  29. virtual ~IMeshLoader()
  30. {
  31. if ( TextureLoader )
  32. TextureLoader->drop();
  33. }
  34. //! Returns true if the file might be loaded by this class.
  35. /** This decision should be based on the file extension (e.g. ".cob")
  36. only.
  37. \param filename Name of the file to test.
  38. \return True if the file might be loaded by this class. */
  39. virtual bool isALoadableFileExtension(const io::path& filename) const = 0;
  40. //! Creates/loads an animated mesh from the file.
  41. /** \param file File handler to load the file from.
  42. \return Pointer to the created mesh. Returns 0 if loading failed.
  43. If you no longer need the mesh, you should call IAnimatedMesh::drop().
  44. See IReferenceCounted::drop() for more information. */
  45. virtual IAnimatedMesh* createMesh(io::IReadFile* file) = 0;
  46. //! Set a new texture loader which this meshloader can use when searching for textures.
  47. /** NOTE: Not all meshloaders do support this interface. Meshloaders which
  48. support it will return a non-null value in getMeshTextureLoader from the start. Setting a
  49. texture-loader to a meshloader which doesn't support it won't help.
  50. \param textureLoader The textureloader to use. When set to NULL the mesh will not load any textures.
  51. */
  52. virtual void setMeshTextureLoader(IMeshTextureLoader* textureLoader)
  53. {
  54. if ( textureLoader != TextureLoader )
  55. {
  56. if ( textureLoader )
  57. textureLoader->grab();
  58. if ( TextureLoader )
  59. TextureLoader->drop();
  60. TextureLoader = textureLoader;
  61. }
  62. }
  63. //! Get the texture loader used when this meshloader searches for textures.
  64. /** NOTE: not all meshloaders support this interface so this can return NULL.
  65. */
  66. virtual IMeshTextureLoader* getMeshTextureLoader() const
  67. {
  68. return TextureLoader;
  69. }
  70. enum E_INDEX_TYPE_HINT
  71. {
  72. //! Prefer to use 16-bit index buffers even if it breaks the mesh
  73. //! The default (and only option) before Irrlicht 1.9
  74. EITH_16BIT,
  75. //! Allow using 32-bit index buffers
  76. EITH_32BIT,
  77. //! Allow 32-bit, but copy back to 16-bit when 32 is not needed.
  78. //! So tiny overhead (sometimes extra allocation+copying) on loading,
  79. //! but meshes are later more optimal.
  80. //! Default since Irrlicht 1.9
  81. EITH_OPTIMAL
  82. };
  83. //! Give loader a hint if you would prefer 16 or 32 bit meshbuffers.
  84. /**
  85. Before Irrlicht 1.9 Irrlicht worked mostly with 16-bit meshbuffers.
  86. Rendering 32-bit meshbuffers works, but some functions like
  87. mesh-writing and mesh manipulation might not work yet.
  88. NOTE: Most loaders will ignore this hint so far, but hopefully
  89. will care about it in the future.
  90. */
  91. void setIndexTypeHint(E_INDEX_TYPE_HINT typeHint)
  92. {
  93. IndexTypeHint = typeHint;
  94. }
  95. //! Return current preference user has for the index type of meshbuffers
  96. /** Note that this is _not_ necessarily the type used by the meshloader */
  97. E_INDEX_TYPE_HINT getIndexTypeHint() const
  98. {
  99. return IndexTypeHint;
  100. }
  101. protected:
  102. IMeshTextureLoader* TextureLoader;
  103. E_INDEX_TYPE_HINT IndexTypeHint;
  104. };
  105. } // end namespace scene
  106. } // end namespace irr
  107. #endif