BsImporter.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //********************************** Banshee Engine (www.banshee3d.com) **************************************************//
  2. //**************** Copyright (c) 2016 Marko Pintera ([email protected]). All rights reserved. **********************//
  3. #pragma once
  4. #include "BsCorePrerequisites.h"
  5. #include "BsModule.h"
  6. namespace BansheeEngine
  7. {
  8. /** @addtogroup Importer
  9. * @{
  10. */
  11. /** Module responsible for importing various asset types and converting them to types usable by the engine. */
  12. class BS_CORE_EXPORT Importer : public Module<Importer>
  13. {
  14. public:
  15. Importer();
  16. ~Importer();
  17. /**
  18. * Imports a resource at the specified location, and returns the loaded data.
  19. *
  20. * @param[in] inputFilePath Pathname of the input file.
  21. * @param[in] importOptions (optional) Options for controlling the import. Caller must ensure import options
  22. * actually match the type of the importer used for the file type.
  23. *
  24. * @see createImportOptions
  25. */
  26. HResource import(const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);
  27. /** @copydoc import */
  28. template <class T>
  29. ResourceHandle<T> import(const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr)
  30. {
  31. return static_resource_cast<T>(import(inputFilePath, importOptions));
  32. }
  33. /**
  34. * Imports a resource and replaces the contents of the provided existing resource with new imported data.
  35. *
  36. * @param[in] inputFilePath Pathname of the input file.
  37. * @param[in] importOptions (optional) Options for controlling the import. Caller must ensure import options
  38. * actually match the type of the importer used for the file type.
  39. *
  40. * @see createImportOptions
  41. */
  42. void reimport(HResource& existingResource, const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);
  43. /**
  44. * Automatically detects the importer needed for the provided file and returns valid type of import options for
  45. * that importer.
  46. *
  47. * @param[in] inputFilePath Pathname of the input file.
  48. *
  49. * @return The new import options. Null is returned if the file path is not valid, or if a
  50. * valid importer cannot be found for the specified file.
  51. *
  52. * @note
  53. * You will need to type cast the importer options to a valid type, taking into consideration exact importer you
  54. * expect to be used for this file type. If you don't use a proper import options type, an exception will be thrown
  55. * during import.
  56. */
  57. ImportOptionsPtr createImportOptions(const Path& inputFilePath);
  58. /** @copydoc createImportOptions */
  59. template<class T>
  60. SPtr<T> createImportOptions(const Path& inputFilePath)
  61. {
  62. return std::static_pointer_cast<T>(createImportOptions(inputFilePath));
  63. }
  64. /**
  65. * Checks if we can import a file with the specified extension.
  66. *
  67. * @param[in] extension The extension without the leading dot.
  68. */
  69. bool supportsFileType(const WString& extension) const;
  70. /**
  71. * Checks if we can import a file with the specified magic number.
  72. *
  73. * @param[in] magicNumber The buffer containing the magic number.
  74. * @param[in] magicNumSize Size of the magic number buffer.
  75. */
  76. bool supportsFileType(const UINT8* magicNumber, UINT32 magicNumSize) const;
  77. /**
  78. * Adds a new asset importer for the specified file extension. If an asset importer for that extension already
  79. * exists, it is removed and replaced with the current one.
  80. *
  81. *
  82. * @param [in] importer The importer that is able to handle files with the specified extension. nullptr if you
  83. * want to remove an asset importer for the extension.
  84. *
  85. * @note Internal method.
  86. * @note This method should only be called by asset importers themselves on startup. Importer takes ownership
  87. * of the provided pointer and will release it. Assumes it is allocated using the general allocator.
  88. */
  89. void _registerAssetImporter(SpecificImporter* importer);
  90. private:
  91. Vector<SpecificImporter*> mAssetImporters;
  92. SpecificImporter* getImporterForFile(const Path& inputFilePath) const;
  93. };
  94. /** Provides easier access to Importer. */
  95. BS_CORE_EXPORT Importer& gImporter();
  96. /** @} */
  97. }