Prefabs

Prefabs are containers with a number of components and presets. They are comparable to *.fmx files in regular Delphi applications.

Prefabs are very helpful on storing and reusing sceneries in projects. You can store complex component hierarchies like in a default FMX formular file (*.fmx). We use the read/write mechanisms for prefabs with some additional functionality.

So it is also possible to store complete models with textures and animations.

Recommendation

For consistent working process, we recommend to push all exported components (3D controls) into a TGorillaGroup component and set it as owner-component in the prefab item.

The system will store the group itself and all child components into the prefab file.

When loading the prefab again from file, you have to ensure the owner component of the same class type is available.

This means: You should place an empty TGorillaGroup component in your scene, where everything is getting loaded into.

Remarks: It's of course possible to use another type of “container” for prefabs, but components might have unexpected handling or behaviour during the loading process, which might cause issues.

DesignTime

Since v1.1 you can use the TGorillaPrefabSystem on the formular at design time.

Load Prefabs From File

This function will open a dialog to select a *.prefab file from disk.

Afterwards it will ask you to select the owner component, to load the prefab data into.

It is recommended to use the same kind of component as the prefab was stored.

In most cases this will be a TGorillaGroup.

Save Prefab To File

This function allows to store a single prefab from the selected prefab system to file.

You will need to select a prefab from the available list and then select the destination file.

The destination do not need to be the same file, as set in the prefab item.

Save All Prefabs

This function will save all prefabs inside the selected prefab system to file.

But only if a filename was set in the prefab item, this function is able to store the data.

Otherwise an error will occur.

Web Assets Store (Beta)

During development process prefabs became very handy and useful. Like in other 3D DevTools (Unity, Unreal, …) it is common to share those over a platform.

We present https://my.gorilla3d.de/prefabs/ to you!

In our assets store you can download prefabs and integrate them in your application. On downloading a prefab you will receive a *.prefab or a *.prefabz file. Both types can be integrated in the TGorillaPrefabSystem. Have a look at the code snippets above.

WARNING: Please take care of licensing restrictions before publishing them.

WARNING: The assets store is still in beta mode! Errors may occur!

Embedded AssetsStore (Beta)

Since 0.8.3.2265 we integrated the assets store also directly in the Delphi IDE.

  1. Drop a TGorillaPrefabSystem component onto your form.
  2. Right-Click on the component in the object inspector
  3. Click “AssetsStore” to open the embedded formular
  4. Browse through the assets and click to directly embed them in your form

WARNING: Please take care of licensing restrictions before publishing them.

WARNING: Some prefabs are very large in size or produce large output due to textures or animations. This can exceed your memory in IDE very fast!

WARNING: The assets store is still in beta mode! Errors may occur!

To unify the structure within a prefab, all components are grouped within a parent TGorillaGroup component inside the prefab file. Therefore you need to create a corresponding TGorillaGroup component to load data into.

Sketchfab Browser

We've updated our sketchfab plugin support, so you can now search for models on Sketchfab by the embedded WebView2 Browser inside the IDE.

Remark: WebView2Loader.dll (x86) is needed in your Delphi IDE bin\ directory!

To use Sketchfab, you'll need a Sketchfab account. Go to https://sketchfab.com/ and register for a new account, if you haven't already.

Instructions

Right-Click on the TGorillaPrefabSystem component in object inspector and select “Import From Sketchfab”

Search for the model by filtering with keywords, license or other options.

Select the model you wish to download and confirm the embedding process.

Login with your account and grant access by the Gorilla 3D Framework plugin.

The download may take a while, depending on the size of the model. Afterwards a dialog is shown to you with meta data containing the licensing information.

The meta data was automatically copied to clipboard. Do not forget to place it somewhere in your project for author-attribution.

Runtime Usage

Is a simple management component to prepare prefab loading. You can setup prefabs with their corresponding file location and load them on running the application.

var LList : TObjectList<TComponent>;
 
LList := TObjectList<TComponent>.Create(false);
try
  GorillaPrefabSystem1.LoadAllPrefabs(LList);
finally
  FreeAndNil(LList);
end;

Example

When projects getting very large, prefabs need to be loaded at runtime. Take a look at the following function on how to do it.

uses 
  Gorilla.Prefab, Gorilla.Group, Gorilla.Model;
 
procedure TForm1.FormCreate(Sender: TObject);
var LPrefab : TGorillaPrefab;
    LGroup  : TGorillaGroup;
    LModel  : TGorillaModel;
begin
  // create a group, because models inside the prefabs are stored within a group
  LGroup := TGorillaGroup.Create(GorillaViewport1);
  LGroup.Parent := GorillaViewport1;
 
  // load firemonkey from prefab file by creating a prefab in the prefab-system
  LPrefab := GorillaPrefabSystem1.AddPrefab('Firemonkey', LGroup,
    'C:\Users\Public\Downloads\e6e820751021493fb350d190c279e8aa.prefabz');
  // then we load the prefab, which will generate a TGorillaModel instance for us
  LPrefab.Load();
 
  // afterwards we try to find the instance
  LModel := LGroup.FindComponentDeepSearchByClass(TGorillaModel) as TGorillaModel;
  if not Assigned(LModel) then
    Exit;
 
  // at last rotate and scale the model to suit our view
  LModel.RotationAngle.X := 180;
  LModel.WrapMode := TMeshWrapMode.Fit;
  LModel.Scale.Point := Point3D(5, 5, 5);
 
  // check if animations are available
  if not (LModel.AnimationManager.Animations.Count > 0) then
    Exit;
 
  // execute the animation found
  LModel.AnimationManager.Current.Start;
end;

Next step: Android