BsImporter.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. * @brief Imports a resource and replaces the contents of the provided existing resource with new imported data.
  28. *
  29. * @param inputFilePath Pathname of the input file.
  30. * @param importOptions (optional) Options for controlling the import. Caller must
  31. * ensure import options actually match the type of the importer used
  32. * for the file type.
  33. *
  34. * @see createImportOptions
  35. */
  36. void reimport(HResource& existingResource, const Path& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);
  37. /**
  38. * @brief Automatically detects the importer needed for the provided file and returns valid type of
  39. * import options for that importer.
  40. *
  41. * @param inputFilePath Pathname of the input file.
  42. *
  43. * @return The new import options.
  44. *
  45. * @note You will need to type cast the importer options to a valid type,
  46. * taking into consideration exact importer you expect to be used for this file type.
  47. * If you don't use a proper import options type, an exception will be thrown during import.
  48. *
  49. * nullptr is returned if the file path is not valid, or if a valid importer cannot be found for
  50. * the specified file.
  51. */
  52. ImportOptionsPtr createImportOptions(const Path& inputFilePath);
  53. /**
  54. * @brief Checks if we can import a file with the specified extension.
  55. *
  56. * @param extension The extension without the leading dot.
  57. */
  58. bool supportsFileType(const WString& extension) const;
  59. /**
  60. * @brief Checks if we can import a file with the specified magic number.
  61. *
  62. * @param magicNumber The buffer containing the magic number.
  63. * @param magicNumSize Size of the magic number buffer.
  64. */
  65. bool supportsFileType(const UINT8* magicNumber, UINT32 magicNumSize) const;
  66. /**
  67. * @brief Adds a new asset importer for the specified file extension. If an asset importer for that extension
  68. * already exists, it is removed and replaced with the current one.
  69. *
  70. * @note Internal method. This method should only be called by asset importers themselves on startup.
  71. *
  72. * @param [in] importer The importer that is able to handle files with the specified extension. nullptr if you
  73. * want to remove an asset importer for the extension.
  74. */
  75. void _registerAssetImporter(SpecificImporter* importer);
  76. private:
  77. Vector<SpecificImporter*> mAssetImporters;
  78. SpecificImporter* getImporterForFile(const Path& inputFilePath) const;
  79. };
  80. }