class Importer

Inherits: Module<Importer>

Module responsible for importing various asset types and converting them to types usable by the engine.

Public

Constructors

Importer

Importer()

Methods

~Importer

~Importer() noexcept

Import

HResource Import(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr, const UUID &UUID = UUID::kEmpty)

Imports a resource at the specified location, and returns the loaded data.

If file contains more than one resource only the primary resource is imported (for example an FBX a mesh would be imported, but animations ignored).

inputFilePath
Pathname of the input file.
importOptions
(optional) Options for controlling the import. Caller must ensure import options actually match the type of the importer used for the file type.
UUID
Specific UUID to assign to the resource. If not specified a randomly generated UUID will be assigned.

Returns: Imported resource.

ImportAsync

TAsyncOp<HResource> ImportAsync(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr, const UUID &UUID = UUID::kEmpty)

Same as import(), except it imports a resource without blocking the main thread.

The resulting resource will be placed in the returned AsyncOp object when the import ends.

ImportAll

SPtr<MultiResource> ImportAll(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr)

Imports a resource at the specified location, and returns the loaded data.

This method returns all imported resources, which is relevant for files that can contain multiple resources (for example an FBX which may contain both a mesh and animations).

inputFilePath
Pathname of the input file.
importOptions
(optional) Options for controlling the import. Caller must ensure import options actually match the type of the importer used for the file type.

Returns: A list of all imported resources. The primary resource is always the first returned resource.

ImportAllAsync

TAsyncOp<SPtr<MultiResource>> ImportAllAsync(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr)

Same as importAll(), except it imports a resource without blocking the main thread.

The returned AsyncOp will contain a list of the imported resources, after the import ends.

CreateImportOptions

SPtr<ImportOptions> CreateImportOptions(const Path &inputFilePath)

Automatically detects the importer needed for the provided file and returns valid type of import options for that importer.

inputFilePath
Pathname of the input file.

Returns: The new import options. Null is returned if the file path is not valid, or if a valid importer cannot be found for the specified file.

SupportsFileType

bool SupportsFileType(const String &extension) const

Checks if we can import a file with the specified extension.

extension
The extension without the leading dot.

SupportsFileType

bool SupportsFileType(const u8 *magicNumber, u32 magicNumberSize) const

Checks if we can import a file with the specified magic number.

magicNumber
The buffer containing the magic number.
magicNumberSize
Size of the magic number buffer.

staticInstance

static T &Instance()

Returns a reference to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticInstancePtr

static T *InstancePtr()

Returns a pointer to the module instance.

Module has to have been started up first otherwise an exception will be thrown.

staticShutDown

static void ShutDown()

Shuts down this module and frees any resources it is using.

staticIsStarted

static bool IsStarted()

Query if the module has been started.

Internal

Methods

RegisterAssetImporter

void RegisterAssetImporter(SpecificImporter *importer)

Registers a new asset importer for a specific set of extensions (as determined by the implementation).

If an asset importer for one or multiple extensions already exists, it is removed and replaced with this one.

importer
The importer that is able to handle import of certain type of files.

ImportInternal

SPtr<Resource> ImportInternal(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr)

Alternative to import() which doesn't create a resource handle, but instead returns a raw resource pointer.

ImportAllInternal

Vector<SubResourceRaw> ImportAllInternal(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr)

Alternative to ImportAll() which doesn't create resource handles, but instead returns raw resource pointers.

ImportAllAsyncInternal

TAsyncOp<Vector<SubResourceRaw>> ImportAllAsyncInternal(const Path &inputFilePath, SPtr<const ImportOptions> importOptions = nullptr)

Alternative to ImportAllAsync() which doesn't create resource handles, but instead returns raw resource pointers.

Protected

Methods

~Module<T>

virtual ~Module<T>() = default

OnStartUp

virtual void OnStartUp()

Override if you want your module to be notified once it has been constructed and started.

OnShutDown

virtual void OnShutDown()

Override if you want your module to be notified just before it is deleted.

staticInstanceInternal

static T *&InstanceInternal()

Returns a singleton instance of this module.

staticIsDestroyed

static bool &IsDestroyed()

Checks has the Module been shut down.

staticIsStartedUp

static bool &IsStartedUp()

Checks has the Module been started up.

Private

Methods

GetImporterForFile

SpecificImporter *GetImporterForFile(const Path &inputFilePath) const

Searches available importers and attempts to find one that can import the file of the provided type.

Returns null if one cannot be found.

PrepareForImport

SpecificImporter *PrepareForImport(const Path &filePath, SPtr<const ImportOptions> &importOptions) const

Prepares for import of a file at the specified path.

Returns the type of importer the file can be imported with, or null if the file isn't valid or is of unsupported type. Also creates the default set of import options unless already provided.

WaitForAsync

void WaitForAsync(SpecificImporter *importer)

Checks is the specific importer currently importing something asynchronously.

If the importer doesn't support multiple threads then the method will wait until async. import completes.

Fields

mAssetImporters

Vector<SpecificImporter *> mAssetImporters

mPerImporterQueues

UnorderedMap<SpecificImporter *, UPtr<SchedulerTicketQueue>> mPerImporterQueues

Queues for importers having to run sequential tasks.

mPerImporterQueueMutex

Mutex mPerImporterQueueMutex