CmImporter.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #pragma once
  2. #include "CmPrerequisites.h"
  3. #include "CmModule.h"
  4. namespace CamelotFramework
  5. {
  6. /**
  7. * @brief Module responsible for importing various asset types and converting
  8. * them to types usable by the engine.
  9. */
  10. class CM_EXPORT Importer : public Module<Importer>
  11. {
  12. public:
  13. /**
  14. * @brief Constructor.
  15. */
  16. Importer();
  17. ~Importer();
  18. /**
  19. * @brief Imports a resource at the specified location, and returns the loaded data.
  20. *
  21. * @param inputFilePath Pathname of the input file.
  22. * @param importOptions (optional) Options for controlling the import.
  23. */
  24. HResource import(const String& inputFilePath, ConstImportOptionsPtr importOptions = nullptr);
  25. /**
  26. * @brief Automatically detects the importer needed for the provided file and returns valid type of
  27. * import options for that importer.
  28. *
  29. * @param inputFilePath Pathname of the input file.
  30. *
  31. * @return The new import options.
  32. *
  33. * @note You will need to type cast the importer options to a valid type,
  34. * taking into consideration exact importer you expect to be used for this file type.
  35. * If you don't use a proper import options type, an exception will be thrown during import.
  36. *
  37. * nullptr is returned if the file path is not valid, or if a valid importer cannot be found for
  38. * the specified file.
  39. */
  40. ImportOptionsPtr createImportOptions(const String& inputFilePath);
  41. /**
  42. * @brief Checks if we can import a file with the specified extension.
  43. *
  44. * @param extension The extension without leading dot.
  45. */
  46. bool supportsFileType(const String& extension) const;
  47. /**
  48. * @brief Checks if we can import a file with the specified magic number.
  49. *
  50. * @param magicNumber The buffer containing the magic number.
  51. * @param magicNumSize Size of the magic number buffer.
  52. */
  53. bool supportsFileType(const UINT8* magicNumber, UINT32 magicNumSize) const;
  54. /**
  55. * @brief Adds a new asset importer for the specified file extension. If an asset importer for that extension
  56. * already exists, it is removed and replaced with the current one.
  57. *
  58. * @note This method should only be called by asset importers themselves on startup.
  59. *
  60. * @param [in] importer The importer that is able to handle files with the specified extension. nullptr if you
  61. * want to remove an asset importer for the extension.
  62. */
  63. void registerAssetImporter(SpecificImporter* importer);
  64. private:
  65. Vector<SpecificImporter*>::type mAssetImporters;
  66. SpecificImporter* getImporterForFile(const String& inputFilePath) const;
  67. };
  68. }