BsImporter.h 3.6 KB

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