1//************************************ bs::framework - Copyright 2018 Marko Pintera **************************************//
2//*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********//
3#pragma once
4
5#include "BsCorePrerequisites.h"
6
7namespace bs
8{
9 /** @addtogroup Importer-Internal
10 * @{
11 */
12
13 /**
14 * Contains a resource that was imported from a file that contains multiple resources (for example an animation from an
15 * FBX file).
16 */
17 struct SubResourceRaw
18 {
19 String name; /**< Unique name of the sub-resource. */
20 SPtr<Resource> value; /**< Contents of the sub-resource. */
21 };
22
23 /** Modes signififying the level of asynchronous functionality provided by a SpecificImporter. */
24 enum class ImporterAsyncMode
25 {
26 /** Asynchronous import is supported but only on a single thread. */
27 Single,
28 /** Asynchronous import for multiple simultaneous threads is supported. */
29 Multi
30 };
31
32 /**
33 * Abstract class that is to be specialized for converting a certain asset type into an engine usable resource
34 * (for example a .png file into an engine usable texture).
35 *
36 * On initialization this class must register itself with the Importer module, which delegates asset import calls to a
37 * specific importer.
38 */
39 class BS_CORE_EXPORT SpecificImporter
40 {
41 public:
42 SpecificImporter() {}
43 virtual ~SpecificImporter() {}
44
45 /**
46 * Check is the provided extension supported by this importer.
47 *
48 * @note Provided extension should be without the leading dot.
49 */
50 virtual bool isExtensionSupported(const String& ext) const = 0;
51
52 /** Check if the provided magic number is supported by this importer. */
53 virtual bool isMagicNumberSupported(const UINT8* magicNumPtr, UINT32 numBytes) const = 0;
54
55 /** Returns the level of asynchronous import supported by this importer. */
56 virtual ImporterAsyncMode getAsyncMode() const { return ImporterAsyncMode::Multi; }
57
58 /**
59 * Imports the given file. If file contains more than one resource only the primary resource is imported (for
60 * example for an FBX a mesh would be imported, but animations ignored).
61 *
62 * @param[in] filePath Pathname of the file, with file extension.
63 * @param[in] importOptions Options that can control how is the resource imported.
64 * @return null if it fails, otherwise the loaded object.
65 */
66 virtual SPtr<Resource> import(const Path& filePath, SPtr<const ImportOptions> importOptions) = 0;
67
68 /**
69 * Imports the given file. This method returns all imported resources, which is relevant for files that can contain
70 * multiple resources (for example an FBX which may contain both a mesh and animations).
71 *
72 * @param[in] filePath Pathname of the file, with file extension.
73 * @param[in] importOptions Options that can control how are the resources imported.
74 * @return Empty array if it fails, otherwise the loaded objects. First element is always the
75 * primary resource.
76 */
77 virtual Vector<SubResourceRaw> importAll(const Path& filePath, SPtr<const ImportOptions> importOptions);
78
79 /**
80 * Creates import options specific for this importer. Import options are provided when calling import() in order
81 * to customize the import, and provide additional information.
82 */
83 virtual SPtr<ImportOptions> createImportOptions() const;
84
85 /**
86 * Gets the default import options.
87 *
88 * @return The default import options.
89 */
90 SPtr<const ImportOptions> getDefaultImportOptions() const;
91
92 private:
93 mutable SPtr<const ImportOptions> mDefaultImportOptions;
94 };
95
96 /** @} */
97}