Gorilla.AssetsManager
Unit Gorilla.AssetsManager.pasThe AssetsManager is the core component in effective media management inside your Gorilla3D application. Models, textures, audio and so on will be cached for faster access and reusage. You can build packages within the AssetsManager for modular media management. For example: you could build a package for the main character and reference to it in every scene package. Scene packages are extremly useful for compact and fast loading of all data of a specific scene.
Classes
- EGorillaAssetsException = class ( EAbort )
- TGorillaAsset = class ( TObject )
- TGorillaTextureAsset = class ( TGorillaAsset )
- TGorillaModelAsset = class ( TGorillaAsset )
- TGorillaStreamAsset = class ( TGorillaAsset )
- TGorillaAudioAsset = class ( TGorillaStreamAsset )
- TGorillaVideoAsset = class ( TGorillaStreamAsset )
- TGorillaMiscAsset = class ( TGorillaStreamAsset )
- TGorillaDialogueAsset = class ( TGorillaStreamAsset )
- TGorillaInventoryAsset = class ( TGorillaStreamAsset )
- TGorillaAssetsGroup = class ( TCollectionItem )
- TGorillaAssetsGroupCollection = class ( TOwnedCollection )
- TGorillaAssetsPackage = class ( TCollectionItem )
- TGorillaAssetsPackageCollection = class ( TOwnedCollection )
- TGorillaAssetsManager = class ( TComponent )
Enumerations
- enum TGorillaLevelOfDetail = ( LowQuality, MediumQuality, HighQuality, ExcellentQuality ) ;
Constants
- const GORILLA_ASSETS_MODEL : Integer = $0;
- const GORILLA_ASSETS_TEXTURE : Integer = $1;
- const GORILLA_ASSETS_AUDIO : Integer = $2;
- const GORILLA_ASSETS_VIDEO : Integer = $3;
- const GORILLA_ASSETS_MISC : Integer = $4;
- const GORILLA_ASSETS_DIALOGUE : Integer = $5;
- const GORILLA_ASSETS_INVENTORY : Integer = $6;
- const GORILLA_ASSETS_MODEL_DESCR : string = "MODELS";
- const GORILLA_ASSETS_TEXTURE_DESCR : string = "TEXTURES";
- const GORILLA_ASSETS_AUDIO_DESCR : string = "AUDIO";
- const GORILLA_ASSETS_VIDEO_DESCR : string = "VIDEO";
- const GORILLA_ASSETS_MISC_DESCR : string = "MISC";
- const GORILLA_ASSETS_DIALOGUE_DESCR : string = "DIALOGUE";
- const GORILLA_ASSETS_INVENTORY_DESCR : string = "INVENTORY";
- const GORILLA_PACKAGE_DEFAULT : string = "default";
Mics. types
- type TGorillaAssetGroupId = integer;
- type TGorillaAssetClass = class of TGorillaAsset;
TGorillaLevelOfDetail
The level of detail enumerator describes the rendering quality of assets. This could affect textures and models and will increase performance.
Remarks
This enumerator is implemented for future functionality and not operational yet!TGorillaAsset
Basic asset class. Every texture, model, audio-file, ... is based on this class inside the AssetsManager
Ancestors
Members
Fields
- protected FGroup :
TGorillaAssetsGroup
- protected FId :
TGUID
- protected FFilename :
string
- protected FExtension :
string
- protected FCached :
Boolean
Methods
- public constructor Create ( const AGroup : TGorillaAssetsGroup ) ;
- public destructor Destroy ( ) ;
- protected function GetArchivePath ( ) : string ; virtual;
- protected function GetArchiveFilePath ( const APath : string ) : string ; class virtual;
- protected procedure SaveToArchive ( AArchive : TZipFile; const APath : string ) ; virtual;
- protected procedure LoadFromArchive ( AArchive : TZipFile; const APath : string ) ; overload virtual;
- protected function LoadFromArchive ( AArchive : TZipFile; const AGroup : TGorillaAssetsGroup; const APath : string ) : TGorillaAsset ; class overload virtual;
- public function GetGroupId
(
)
: Integer
;
class abstract virtual;
Static function overwritten by the extended asset class for automatic group association.
- public function GetGroupDescr
(
)
: string
;
class abstract virtual;
Static function overwritten by the extended asset class to return group name.
- public function GetSupportedExtensions
(
)
: TArray<System.string>
;
class abstract virtual;
Static function overwritten by the extended asset class that returns a string array with all supported file extensions.
- public function IsExtensionSupported
(
const
AExt :
string
)
: Boolean
;
class virtual;
Static function that checks if a specific extension is supported by a specific asset class. The method uses the GetSupportedExtensions routine.
- public function ImportFromFile
(
const
AGroup :
TGorillaAssetsGroup; const
AFilename :
string
)
: TGorillaAsset
;
class overload virtual;
Loads an asset from supplied filename and stores it in supplied asset group.
- public function ImportFromStream
(
const
AGroup :
TGorillaAssetsGroup; const
AFilename :
string; const
AStream :
TStream
)
: TGorillaAsset
;
class abstract overload virtual;
Loads an asset from stream with a supplied filename and stores it into the supplied asset group.
- public procedure ImportFromFile
(
const
AFilename :
string
)
;
overload virtual;
Loads data for an existing asset by a supplied filename.
- public procedure ImportFromStream
(
const
AFilename :
string; const
AStream :
TStream
)
;
abstract overload virtual;
Loads data from supplied stream for an existing asset by a supplied filename.
- public function GetSize
(
)
: Int64
;
virtual;
Returns the size of the asset in bytes.
- public function ToJSON
(
)
: TJSONObject
;
virtual;
Returns a json object with all serialized fields to store within a assets manager package.
- public procedure FromJSON
(
const
AValue :
TJSONObject
)
;
virtual;
Allows to load field values from a json object.
Properties
- public Group : TGorillaAssetsGroup
- public Id : TGUID
- public Filename : string
The original filename of the asset. Optional it includes the path from where the asset was loaded.
read FFilename - public Extension : string
- public Cached : Boolean
TGorillaTextureAsset
Textures are cached as TBitmap.
Remarks
Files with extension *.bmp, *.jpg, *.jpeg, *.dds, *.gif, *.png, *.tif, *.tiff, *.tga are mapped to this assset type.Ancestors
Members
Fields
Methods
- public constructor Create ( const AGroup : TGorillaAssetsGroup ) ;
- public destructor Destroy ( ) ;
- protected function GetBitmap ( ) : TBitmap ;
- protected procedure SaveToArchive ( AArchive : TZipFile; const APath : string ) ; override;
- public function GetGroupId ( ) : Integer ; class override;
- public function GetGroupDescr ( ) : string ; class override;
- public function GetSupportedExtensions ( ) : TArray<System.string> ; class override;
- public function ImportFromStream ( const AGroup : TGorillaAssetsGroup; const AFilename : string; const AStream : TStream ) : TGorillaAsset ; class overload override;
- public procedure ImportFromStream ( const AFilename : string; const AStream : TStream ) ; overload override;
- public function GetSize ( ) : Int64 ; override;
- public function ToJSON ( ) : TJSONObject ; override;
Properties
TGorillaModelAsset
Models are cached as Gorilla.DefTypes.TModelDef structure. When storing packages, models will be saved as G3D models.
Remarks
Files with extension *.obj, *.g3d, *.dae, *.stl, *.x3d, *.x3dvz, *.x3dz, *.fbx are mapped to this asset type.Ancestors
Members
Fields
Methods
- public destructor Destroy ( ) ;
- protected procedure SaveToArchive ( AArchive : TZipFile; const APath : string ) ; override;
- protected procedure LoadFromArchive ( AArchive : TZipFile; const APath : string ) ; overload override;
- protected function InternalLoadModelDefFromStream ( const AStream : TStream; const APackage : TGorillaAssetsPackage; const AFilename : string ) : TObject ; class;
- public function GetGroupId ( ) : Integer ; class override;
- public function GetGroupDescr ( ) : string ; class override;
- public function GetSupportedExtensions ( ) : TArray<System.string> ; class override;
- public function ImportFromStream ( const AGroup : TGorillaAssetsGroup; const AFilename : string; const AStream : TStream ) : TGorillaAsset ; class overload override;
- public procedure ImportFromStream ( const AFilename : string; const AStream : TStream ) ; overload override;
- public function GetSize ( ) : Int64 ; override;
Properties
TGorillaStreamAsset
This is the custom stream asset used for audio, video, misc, dialogue, and inventory assets.
Remarks
Depending on the asset specific file extensions will be mapped for auto- detection.Ancestors
Members
Fields
Methods
- public constructor Create ( const AGroup : TGorillaAssetsGroup ) ;
- public destructor Destroy ( ) ;
- protected procedure SaveToArchive ( AArchive : TZipFile; const APath : string ) ; override;
- protected procedure LoadFromArchive ( AArchive : TZipFile; const APath : string ) ; overload override;
- public procedure ImportFromStream ( const AFilename : string; const AStream : TStream ) ; overload override;
- public function GetSize ( ) : Int64 ; override;
- public function ToJSON ( ) : TJSONObject ; override;
Properties
- public Stream : TMemoryStream
Returns the buffered memory stream containing data, depending of the type of stream asset: audio, video, misc, dialogue, inventory,...
read FStream
TGorillaAudioAsset
Store and load audio files to the package archive.
Remarks
Files with extension *.aiff, *.asf, *.asx, *.dls, *.flac, *.fsb, *.it, *.m3u, *.midi, *.mod, *.mp2, *.mp3, *.ogg, *.pls, *.s3m, *.vag, *.wav, *.wax, *.wma, *.xm, *.xma are mapped with this asset type.Ancestors
Members
Methods
- public constructor Create ( const AGroup : TGorillaAssetsGroup ) ;
- public destructor Destroy ( ) ;
- public function GetGroupId ( ) : Integer ; class override;
- public function GetGroupDescr ( ) : string ; class override;
- public function GetSupportedExtensions ( ) : TArray<System.string> ; class override;
- public function ImportFromStream ( const AGroup : TGorillaAssetsGroup; const AFilename : string; const AStream : TStream ) : TGorillaAsset ; class overload override;
TGorillaVideoAsset
Store and load video files to the package archive.
Remarks
Files with extension *.mp4, *.mpg and *.mpeg are mapped to this asset type.Ancestors
Members
TGorillaMiscAsset
This is multi type asset used for user specific data.
Remarks
Files with extension *.txt, *.json, *.xml are mapped to this asset type.Ancestors
Members
TGorillaDialogueAsset
Store and load assets containing a dialogue system.
Remarks
Files with extension *.dia or *.dlg are mapped to this asset type.Ancestors
Members
Fields
Properties
TGorillaInventoryAsset
Store and load assets containing an inventory declaration.
Remarks
Files with extension *.iff are mapped to this asset type.Ancestors
Members
TGorillaAssetsGroup
An assets group is a category for media types, like: textures, models, audio, ...
Ancestors
Members
Fields
- protected FDescr :
string
- protected FAssetClass :
TGorillaAssetClass
- protected FAssets :
TGorillaAssetsMap
Methods
- public constructor Create
(
ACollection :
TCollection
)
;
Default constructor
- public constructor CreateForAsset
(
ACollection :
TCollection; const
AAssetClass :
TGorillaAssetClass
)
;
Constructor with asset class type assignment.
- public destructor Destroy ( ) ;
- protected function GetPackage ( ) : TGorillaAssetsPackage ; virtual;
- protected function GetGroupIndex ( ) : Integer ; virtual;
- protected procedure DoOnAssetsValueNotify ( ASender : TObject; const AItem : TGorillaAsset; AAction : TCollectionNotification ) ; virtual;
- protected function GetArchivePath ( ) : string ; virtual;
- protected function GetArchiveFilePath ( const APath : string ) : string ; class virtual;
- protected procedure SaveToArchive ( AArchive : TZipFile ) ; virtual;
- protected function LoadFromArchive ( ACollection : TCollection; AArchive : TZipFile; APath : string ) : TGorillaAssetsGroup ; class virtual;
- protected function GetDisplayName ( ) : string ; override;
- protected procedure SetDisplayName ( const AValue : string ) ; override;
- public procedure Initialize
(
AAssetClass :
TGorillaAssetClass
)
;
Initializes the asset group instance. Creating the assets hashmap and applying the assets class type.
- public function FindAssetByFilename
(
const
AFilename :
string
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename.
- public function GetAssetFromId
(
const
AId :
TGUID
)
: TGorillaAsset
;
Returns an asset by a supplied unique identifier (GUID). If not asset with this GUID could be found, the method returns nil.
- public function GetAssetFromFile
(
const
AFilename :
string
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename. If no asset could be found, the routine imports the asset from supplied file.
- public function GetAssetFromStream
(
const
AFilename :
string; const
AStream :
TStream
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename. If no asset could be found, the routine imports the asset from supplied stream and supplied filename.
- public procedure Clear
(
)
;
Removes all assets from the specific asset group.
- public procedure AddAsset
(
const
AAsset :
TGorillaAsset
)
;
virtual;
Adds an existing asset instance to the specific asset group.
- public function AddEmptyAsset
(
const
AFileName :
string
)
: TGorillaAsset
;
overload;
Creates and adds an empty asset object to the specific group.
- public function AddEmptyAsset
(
const
AId :
TGUID
)
: TGorillaAsset
;
overload;
Creates and adds an empty asset object to the specific group.
- public function GetSize
(
)
: Int64
;
virtual;
Returns the size in bytes. The size contains the the number of bytes used by the asset group itself and all its contained assets.
- public function ToJSON
(
)
: TJSONObject
;
virtual;
Serializes an asset group to json format.
- public procedure FromJSON
(
const
AValue :
TJSONObject
)
;
virtual;
Applies field values of an asset group from supplied json format.
Properties
- public Package : TGorillaAssetsPackage
- public GroupIndex : Integer
- public Assets : TDictionary<System.TGUID,Gorilla.AssetsManager.TGorillaAsset>
- published DisplayName : string
Get or set a group description for identifying a specific group.
read GetDisplayName
write SetDisplayName - published AssetClass : TGorillaAssetClass
Returns the linked asset class type that is allowed to used within the specific asset group.
read FAssetClass
write FAssetClass
TGorillaAssetsGroupCollection
Ancestors
Members
Properties
- public Package : TGorillaAssetsPackage
Get the owner assets package. This property is needed to store all data in the zip package file.
read GetPackage
TGorillaAssetsPackage
Defining an asset package which stores media files inside of a zip packed file or stream. A package is very useful to reuse assets and pack assets together for easier rollout.
Ancestors
Members
Fields
- protected FArchive :
TZipFile
- protected FStream :
TStream
- protected FGUID :
TGUID
- protected FDescr :
string
- protected FGroups :
TGorillaAssetsGroupCollection
Methods
- public constructor Create ( ACollection : TCollection ) ;
- public destructor Destroy ( ) ;
- protected function GetManager ( ) : TGorillaAssetsManager ;
- protected function GetArchive ( ) : TZipFile ;
- protected function GetDisplayName ( ) : string ; override;
- protected procedure SetDisplayName ( const AValue : string ) ; override;
- public procedure Initialize
(
)
;
Initializes the assets package component by generating a guid and creating all default asset groups: GORILLA_ASSETS_MODEL, GORILLA_ASSETS_TEXTURE, GORILLA_ASSETS_AUDIO, GORILLA_ASSETS_VIDEO, GORILLA_ASSETS_MISC, GORILLA_ASSETS_DIALOGUE, GORILLA_ASSETS_INVENTORY
- public function AddGroup
(
const
AClass :
TGorillaAssetClass
)
: TGorillaAssetsGroup
;
Adds a new asset group to the package depending on the supplied asset class type.
- public procedure RemoveGroup
(
const
AIdx :
Integer
)
;
overload;
Removes a specific asset group from package by the supplied asset group id. If the group do not exist, the routine will leave.
- public procedure RemoveGroup
(
const
ADescr :
string
)
;
overload;
Removes a specific asset group from package by the supplied asset group descriptin. If the group do not exist, the routine will leave.
- public function GetGroup
(
const
AIdx :
Integer
)
: TGorillaAssetsGroup
;
overload;
Tries to find a specific assets group by the supplied group id. If no group could be found, the routine returns nil.
- public function GetGroup
(
const
ADescr :
string
)
: TGorillaAssetsGroup
;
overload;
Tries to find a specific assets group by the supplied group description. If no group could be found, the routine returns nil.
- public function GetGroupIndex
(
const
ADescr :
string
)
: Integer
;
overload;
Returns the group index inside of the group collection by the supplied description. If the specific group could not be found, the routine returns -1.
- public function GetGroupIndex
(
const
AGroup :
TGorillaAssetsGroup
)
: Integer
;
overload;
Returns the group index inside of the group collection by the supplied instance. If the specific group could not be found, the routine returns -1.
- public procedure ClearGroup
(
const
AIdx :
Integer
)
;
Removes all contained assets from a specific group. The method will lookup for the group by the supplied index. If no group could be found, the routine will leave.
- public function AddAssetFromFile
(
const
AFilename :
string
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename. The method automatically detects the asset group and searches for the asset. If no asset could be found, the routine imports the asset from supplied file.
- public function GetAssetFromId
(
const
AGroup :
Integer; const
AId :
TGUID
)
: TGorillaAsset
;
Returns an asset by a supplied unique identifier (GUID) in the supplied asset group. If not asset with this GUID could be found, the method returns nil.
- public function GetAssetFromFile
(
const
AGroup :
Integer; const
AFilename :
string
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename. The routine searches in the supplied asset group. If no asset could be found, the routine imports the asset from supplied file.
- public function GetAssetFromStream
(
const
AGroup :
Integer; const
AFilename :
string; const
AStream :
TStream
)
: TGorillaAsset
;
Tries to find a specific asset by a supplied filename. The routine searches in the supplied asset group. If no asset could be found, the routine imports the asset from supplied stream.
- public function GetSize
(
)
: Int64
;
virtual;
Returns the number of bytes of the package itself, all groups and all contained assets inside.
- public procedure LoadFromFile
(
const
AFilename :
string
)
;
virtual;
Loads a package with all groups and assets from supplied file.
- public procedure LoadFromStream
(
const
AStream :
TStream
)
;
virtual;
Loads a package with all groups and assets from supplied stream.
- public procedure SaveToFile ( const AFilename : string ) ; virtual;
- public procedure SaveToStream
(
const
AStream :
TStream
)
;
virtual;
Stores a package with all groups and assets to a zip archive stream.
Properties
- public Manager : TGorillaAssetsManager
- public GUID : TGUID
Returns the unique identifier of the specific package. This value is automatically set while construction.
read FGUID - public Archive : TZipFile
- public Stream : TStream
- published DisplayName : string
A description for the specific asset package to better identify different packages.
read GetDisplayName
write SetDisplayName - published Groups : TGorillaAssetsGroupCollection
TGorillaAssetsPackageCollection
Ancestors
Members
Properties
TGorillaAssetsManager
The AssetsManager is central access point to all of your media data. Use packages and groups to organize your data.
Ancestors
Members
Fields
Methods
- public constructor Create ( AOwner : TComponent ) ;
- public destructor Destroy ( ) ;
- public function GetSize ( ) : Int64 ; virtual;
- public function AddEmptyPackage
(
const
ADescr :
string
=
)
: TGorillaAssetsPackage
;
virtual;
Creates a new and empty package. The package contains the default groups: MODELS, TEXTURES, AUDIO, VIDEO, ... without any assets.
- public function GetPackageIndex
(
const
AGUID :
TGUID
)
: Integer
;
overload virtual;
Returns the collection index of a specific assets package by its unique identifier.
- public function GetPackageIndex
(
const
ADescr :
string
)
: Integer
;
overload virtual;
Returns the collection index of a specific assets package by its description.
- public function GetPackage
(
const
AGUID :
TGUID
)
: TGorillaAssetsPackage
;
overload virtual;
Returns a package object by its unique identifier.
- public function GetPackage
(
const
ADescr :
string
)
: TGorillaAssetsPackage
;
overload virtual;
Returns a package object by its description.
- public procedure RemovePackage
(
const
AGUID :
TGUID
)
;
overload virtual;
Removes a specific package by its supplied unique identifier. The method destroys all groups and assets within. If the package could not be found, the routine will leave.
- public procedure RemovePackage
(
const
ADescr :
string
)
;
overload virtual;
Removes a specific package by its supplied description. The method destroys all groups and assets within. If the package could not be found, the routine will leave.
- public procedure ClearPackages
(
)
;
Destroys all contained packages with its groups and assets.
- public function LoadPackageFromFile
(
const
AFilename :
string
)
: TGorillaAssetsPackage
;
virtual;
Creates a new package and adds it to the manager. Afterwards the method will load the package from file.