This is an old revision of the document!


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 with 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. 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.

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