![]() |
ezEngine Release 26.9
|
Provides functionality for importing files as asset documents. More...
#include <AssetDocumentGenerator.h>

Classes | |
| struct | ImportMode |
| Describes one option to import an asset. More... | |
Public Types | |
| enum class | ImportResult { Imported , AlreadyExists } |
Public Member Functions | |
| ezStatus | Import (ezStringView sInputFileAbs, ezStringView sMode, bool bOpenDocument, ImportResult *out_pResult=nullptr, ezStringBuilder *out_pDocumentPath=nullptr) |
| Imports the given file with the mode. Must be a mode that the generator supports. | |
| ezStringBuilder | GetImportTargetPath (ezStringView sInputFileAbs) const |
| Returns the path of the document that importing the given file would produce. | |
| virtual bool | NeedsImport (ezStringView sInputFileAbs, ezStringView sMode) const |
| Whether Import() should run Generate() at all. | |
| virtual void | GetImportModes (ezStringView sAbsInputFile, ezDynamicArray< ImportMode > &out_modes) const =0 |
| Used to fill out which import modes may be available for the given asset. | |
| virtual ezStringView | GetDocumentExtension () const =0 |
| Returns the target asset document file extension. | |
| virtual ezStringView | GetGeneratorGroup () const =0 |
| Allows to merge the import modes of multiple generators in the UI in one group. | |
| virtual ezStatus | Generate (ezStringView sInputFileAbs, ezStringView sMode, ezDynamicArray< ezDocument * > &out_generatedDocuments)=0 |
| Tells the generator to create a new asset document with the chosen mode. | |
| bool | SupportsFileType (ezStringView sFile) const |
| Returns whether this generator supports the given file type for import. | |
Public Member Functions inherited from ezReflectedClass | |
| virtual const ezRTTI * | GetDynamicRTTI () const |
| bool | IsInstanceOf (const ezRTTI *pType) const |
| Returns whether the type of this instance is of the given type or derived from it. | |
| template<typename T > | |
| EZ_ALWAYS_INLINE bool | IsInstanceOf () const |
| Returns whether the type of this instance is of the given type or derived from it. | |
Static Public Member Functions | |
| static void | GetSupportsFileTypes (ezSet< ezString > &out_extensions) |
| Creates a list of all importable file extensions. Note that this is an expensive function so the the result should be cached. | |
| static void | ImportAssets () |
| Opens a file browse dialog to let the user choose which files to import. | |
| static void | ImportAssets (const ezDynamicArray< ezString > &filesToImport) |
| Opens the "Asset Import" dialog to let the user choose how to import the given files. | |
| static void | CreateGenerators (ezDynamicArray< ezAssetDocumentGenerator * > &out_generators) |
| Instantiates all currently available generators. | |
| static void | DestroyGenerators (const ezDynamicArray< ezAssetDocumentGenerator * > &generators) |
| Destroys the previously instantiated generators. | |
Static Public Member Functions inherited from ezNoBase | |
| static const ezRTTI * | GetStaticRTTI () |
Protected Member Functions | |
| void | AddSupportedFileType (ezStringView sExtension) |
Friends | |
| class | ezQtAssetImportDlg |
Provides functionality for importing files as asset documents.
Derived from this class to add a custom importer (see existing derived classes for examples). Each importer typically handles one target asset type.
|
strong |
|
pure virtual |
Tells the generator to create a new asset document with the chosen mode.
Import() only calls this when NeedsImport() said there is something to do, so an implementation that maps one file to one document doesn't have to check whether its target already exists. Returning success with an empty array means nothing was left to create, which Import() reports as ImportResult::AlreadyExists.
Implemented in ezAnimationClipAssetDocumentGenerator, ezDecalAssetDocumentGenerator, ezLUTAssetDocumentGenerator, ezMeshAssetDocumentGenerator, ezSkeletonAssetDocumentGenerator, ezTextureAssetDocumentGenerator, ezTextureCubeAssetDocumentGenerator, ezJoltCollisionMeshAssetDocumentGenerator, ezJoltConvexCollisionMeshAssetDocumentGenerator, ezKrautTreeAssetDocumentGenerator, and ezMiniAudioSoundAssetDocumentGenerator.
|
pure virtual |
Returns the target asset document file extension.
Implemented in ezAnimationClipAssetDocumentGenerator, ezDecalAssetDocumentGenerator, ezLUTAssetDocumentGenerator, ezMeshAssetDocumentGenerator, ezAnimatedMeshAssetDocumentGenerator, ezSkeletonAssetDocumentGenerator, ezTextureAssetDocumentGenerator, ezTextureCubeAssetDocumentGenerator, ezJoltCollisionMeshAssetDocumentGenerator, ezJoltConvexCollisionMeshAssetDocumentGenerator, ezKrautTreeAssetDocumentGenerator, and ezMiniAudioSoundAssetDocumentGenerator.
|
pure virtual |
Allows to merge the import modes of multiple generators in the UI in one group.
Not really used anymore, but theoretically allows to show the same file multiple times in the import dialog, such that one can import it as multiple different asset types.
Implemented in ezAnimationClipAssetDocumentGenerator, ezDecalAssetDocumentGenerator, ezLUTAssetDocumentGenerator, ezMeshAssetDocumentGenerator, ezSkeletonAssetDocumentGenerator, ezTextureAssetDocumentGenerator, ezTextureCubeAssetDocumentGenerator, ezJoltCollisionMeshAssetDocumentGenerator, ezJoltConvexCollisionMeshAssetDocumentGenerator, ezKrautTreeAssetDocumentGenerator, and ezMiniAudioSoundAssetDocumentGenerator.
|
pure virtual |
Used to fill out which import modes may be available for the given asset.
Note: sAbsInputFile may be empty, in this case it should fill out the array for "general purpose" import (any file of the supported types).
Implemented in ezAnimationClipAssetDocumentGenerator, ezDecalAssetDocumentGenerator, ezLUTAssetDocumentGenerator, ezMeshAssetDocumentGenerator, ezAnimatedMeshAssetDocumentGenerator, ezSkeletonAssetDocumentGenerator, ezTextureAssetDocumentGenerator, ezTextureCubeAssetDocumentGenerator, ezJoltCollisionMeshAssetDocumentGenerator, ezJoltConvexCollisionMeshAssetDocumentGenerator, ezKrautTreeAssetDocumentGenerator, and ezMiniAudioSoundAssetDocumentGenerator.
| ezStringBuilder ezAssetDocumentGenerator::GetImportTargetPath | ( | ezStringView | sInputFileAbs | ) | const |
Returns the path of the document that importing the given file would produce.
The source path with GetDocumentExtension() substituted, which is the convention every generator follows. A generator that creates several documents from one file returns the primary one here. For modes that derive the document names from the file's content, this path may never be created.
Creates a list of all importable file extensions. Note that this is an expensive function so the the result should be cached.
| out_Extensions | List of all file extensions that can be imported. |
| ezStatus ezAssetDocumentGenerator::Import | ( | ezStringView | sInputFileAbs, |
| ezStringView | sMode, | ||
| bool | bOpenDocument, | ||
| ImportResult * | out_pResult = nullptr, |
||
| ezStringBuilder * | out_pDocumentPath = nullptr |
||
| ) |
Imports the given file with the mode. Must be a mode that the generator supports.
Importing a file that was imported before is not an error, it does nothing and reports ImportResult::AlreadyExists. Distinguishing the two cases is only possible through out_pResult, the returned status is a success either way.
| out_pDocumentPath | The document that was created, or the one that already existed. Also set when generating fails, in which case it is the path that would have been used. Left alone only when the file type isn't supported at all, since then there is no target path. |
|
static |
Opens a file browse dialog to let the user choose which files to import.
After the user chose one or multiple files, opens the "Asset Import" dialog to let them choose details.
|
virtual |
Whether Import() should run Generate() at all.
The default returns false if GetImportTargetPath() already exists, which is the correct answer for every generator that turns one source file into one document.
Override this for modes where one source file produces multiple documents: there the primary path existing says nothing about whether the others do, so the generator has to decide, or return true and skip individual documents while generating.
Reimplemented in ezAnimationClipAssetDocumentGenerator.