CmImporter.h 3.0 KB

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