Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
0.8.3:assetsmanager [2021/01/30 16:40] – [Package] admin | 0.8.3:assetsmanager [2022/04/08 14:06] (current) – [Storing your assets package at runtime] admin | ||
---|---|---|---|
Line 15: | Line 15: | ||
This structure allows a complex and flexible asset structure for your project. | This structure allows a complex and flexible asset structure for your project. | ||
- | The assets manager allows two different | + | The assets manager allows two kinds of packages. |
^Package Type ^Description^ | ^Package Type ^Description^ | ||
- | |File-Based|The package data is loaded on-the-fly from file by a TFileStream. Do not modify position or data in that stream.| | + | |File-Based|The package data is loaded on-the-fly from file by a TFileStream. Do not modify position or data of that stream.| |
- | |In-Memory|The package data is stored completely as TMemoryStream in memory. The data is compressed as zip-stream to reduce memory. Do not modify position or data in this stream.| | + | |In-Memory|The package data is stored completely as TMemoryStream in memory. The data is compressed as zip-stream to reduce memory. Do not modify position or data of this stream.| |
Packages are kept simple and transparent. File-based packages can be viewed easily by a typical ZIP-Viewer. | Packages are kept simple and transparent. File-based packages can be viewed easily by a typical ZIP-Viewer. | ||
Line 28: | Line 28: | ||
By detecting the file extension he is able to organize the media file into the package. | By detecting the file extension he is able to organize the media file into the package. | ||
- | Default group ids to access the specific group of each package: | + | Default group ids to access the specific group of each package |
^ Constant | ^ Constant | ||
- | | GORILLA_ASSETS_MODEL | 0 | *.obj, *.g3d, *.dae, *.stl, *.x3d, *.x3dvz, *.x3dz, *.fbx, *.gltf, *.babylon | | + | | GORILLA_ASSETS_MODEL | 0 | *.obj, *.g3d, *.dae, *.stl, *.x3d, *.x3dvz, *.x3dz, *.fbx, *.gltf, *.babylon, *.ply, *.skp | |
| GORILLA_ASSETS_TEXTURE | 1 | *.bmp, *.jpg, *.jpeg, *.dds, *.gif, *.png, *.tif, *.tiff, *.tga | | | GORILLA_ASSETS_TEXTURE | 1 | *.bmp, *.jpg, *.jpeg, *.dds, *.gif, *.png, *.tif, *.tiff, *.tga | | ||
| GORILLA_ASSETS_AUDIO| 2 | *.aiff, *.asf, *.asx, *.dls, *.flac, *.fsb, *.it, *.m3u, *.midi, *.mod, *.mp2, *.mp3, *.ogg, *.pls, *.s3m, *.vag, *.wav, *.wax, *.wma, *.xm, *.xma (FMOD Support activated) | | | GORILLA_ASSETS_AUDIO| 2 | *.aiff, *.asf, *.asx, *.dls, *.flac, *.fsb, *.it, *.m3u, *.midi, *.mod, *.mp2, *.mp3, *.ogg, *.pls, *.s3m, *.vag, *.wav, *.wax, *.wma, *.xm, *.xma (FMOD Support activated) | | ||
Line 38: | Line 38: | ||
| GORILLA_ASSETS_DIALOGUE | 5 | *.dia, *.dlg| | | GORILLA_ASSETS_DIALOGUE | 5 | *.dia, *.dlg| | ||
| GORILLA_ASSETS_INVENTORY| 6 | *.iff | | | GORILLA_ASSETS_INVENTORY| 6 | *.iff | | ||
+ | | GORILLA_ASSETS_SKILLSYSTEM| 6 | *.ssf | | ||
| GORILLA_ASSETS_SCRIPT| 7 | *.pas | | | GORILLA_ASSETS_SCRIPT| 7 | *.pas | | ||
- | | GORILLA_ASSETS_PREFAB| 8 | *.prefab | | + | | GORILLA_ASSETS_PREFAB| 8 | *.prefab, *.prefabz |
===== Sub-Groups ===== | ===== Sub-Groups ===== | ||
- | Since 0.8.3 also assets can contain | + | Since 0.8.3 also assets can contain |
This is getting important especially for TGorillaModelAsset which can contain textures, prefabs or scripts. | This is getting important especially for TGorillaModelAsset which can contain textures, prefabs or scripts. | ||
- | In elder assets manager | + | Because in elder assets manager |
===== Assets ===== | ===== Assets ===== | ||
Line 54: | Line 55: | ||
A TGorillaModelAsset holds model and animation data by the internal definition format TModelDef. | A TGorillaModelAsset holds model and animation data by the internal definition format TModelDef. | ||
- | The asset converts all original model formats and writes them as *.g3d file to the zip-archive. | + | The asset converts all original model formats and writes them in G3D format |
- | __**Caution: | + | __**Caution: |
The following example shows how to load and show a model from a file-based package. | The following example shows how to load and show a model from a file-based package. | ||
Line 81: | Line 82: | ||
</ | </ | ||
==== TGorillaTextureAsset ==== | ==== TGorillaTextureAsset ==== | ||
- | Holds the texture as TBitmap in memory and writes those in original file format to zip-archive. | ||
+ | TGorillaTextureAsset is a pseudo asset. It doesn' | ||
+ | When asset data is requested it will always load up the data from archive again. | ||
+ | The asset stores textures in PNG file format to the archive to preserve alpha channel. | ||
+ | |||
+ | <file pascal> | ||
+ | procedure TForm1.LoadImage(); | ||
+ | var LGrp : TGorillaAssetsGroup; | ||
+ | LAst : TGorillaTextureAsset; | ||
+ | LBmp : TBitmap; | ||
+ | begin | ||
+ | // load a file-based package | ||
+ | FPackage := FPackage := FAssetsManager.LoadPackageFromFile(' | ||
+ | |||
+ | // get the model def from archive | ||
+ | LGrp := FPackage.GetGroup(GORILLA_ASSETS_TEXTURE); | ||
+ | LAst := LGrp.FindAssetByFilename(' | ||
+ | | ||
+ | // this will request bitmap data from archive stream | ||
+ | LBmp := LAst.Bitmap; | ||
+ | try | ||
+ | // we then assign it to our image on the form | ||
+ | Image1.Bitmap.Assign(LBmp); | ||
+ | finally | ||
+ | LBmp.free(); | ||
+ | end; | ||
+ | end; | ||
+ | </ | ||
==== TGorillaAudioAsset ==== | ==== TGorillaAudioAsset ==== | ||
Holds audio files in a TMemoryStream and writes those in original file format to zip-archive. | Holds audio files in a TMemoryStream and writes those in original file format to zip-archive. | ||
Line 98: | Line 125: | ||
==== TGorillaInventoryAsset ==== | ==== TGorillaInventoryAsset ==== | ||
Holds inventory configuration data in a TMemoryStream and writes those as *.iff file to zip-archive. | Holds inventory configuration data in a TMemoryStream and writes those as *.iff file to zip-archive. | ||
+ | |||
+ | ==== TGorillaSkillsAsset ==== | ||
+ | Holds skill system configuration data in a TMemoryStream and writes those as *.ssf file to zip-archive. | ||
+ | |||
+ | ==== TGorillaScriptAsset ==== | ||
+ | Holds a script file in a TMemoryStream and writes those as *.pas file to zip-archive. | ||
+ | |||
+ | ==== TGorillaPrefabAsset ==== | ||
+ | Holds a prefab file in a TMemoryStream and writes those as *.prefab or *.prefabz file to zip-archive. | ||
===== DesignTime ===== | ===== DesignTime ===== | ||
Line 103: | Line 139: | ||
In the next step we need to create a new package in " | In the next step we need to create a new package in " | ||
+ | |||
+ | Setting the filename of a package will initiate the IDE to load the package into memory. | ||
+ | |||
+ | **WARNING**: | ||
+ | |||
+ | To use relative paths on packages, we provide a set of preset values: | ||
+ | |||
+ | ^Placeholder^Description^ | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |' | ||
+ | |||
+ | **Notice**: Called internal functions of TPath are platform dependent. | ||
+ | Please take a look at Embarcadero documentation for further information, | ||
+ | |||
+ | |||
+ | Set the " | ||
+ | |||
+ | //" | ||
+ | |||
+ | <file pascal> | ||
+ | TGorillaAssetsPackage.Filename := ' | ||
+ | </ | ||
===== Example ===== | ===== Example ===== | ||
Line 139: | Line 203: | ||
Of course you are allowed to store the assets package you've setup. | Of course you are allowed to store the assets package you've setup. | ||
Easily use the provided SaveToFile method of each package instance. | Easily use the provided SaveToFile method of each package instance. | ||
+ | |||
+ | //Notice: In case your are working with a file-based package and the destination location is the same, nothing will be stored. | ||
+ | If the destination differs from currently loaded package, it will create a copy of the file package.// | ||
+ | |||
+ | //Notice: In case you are working with an in-memory package, it will be stored to file, but it stays in memory for further work. | ||
+ | If you want to load the stored in-memory package, you have to use the TGorillaAssetsManager.LoadPackageFromFile() method.// | ||
<file pascal Form1.pas> | <file pascal Form1.pas> |