Gorilla.Model Unit Reference
Overview
The Gorilla.Model unit provides the core model component for loading and managing 3D models in Gorilla3D. It contains the TGorillaModel class, which automatically manages sub-meshes, materials, animations, lights, cameras, and armatures.
Classes
TGorillaModel
Default model control for managing multi-mesh 3D models. The Gorilla3D model component differs significantly from the FMX equivalent, supporting multiple file formats and advanced features like vertex, skeleton, and skin animation.
Inheritance: TGorillaMesh → TGorillaModel
Platforms: All Gorilla3D supported platforms (Windows, macOS, Linux, Android, iOS)
Public Properties
| Property | Type | Description |
|---|---|---|
| Wireframe | Boolean | Get or set property to draw wireframe onto model. Warning: Performance intensive, use for debugging only. |
| WireframeMaterial | TMaterialSource | Material source used for rendering wireframe in post-processing. |
| ShowNormals | Boolean | Get or set property to draw normals in post-processing. Warning: Performance intensive. |
| NormalsColor | TAlphaColor | Normal color drawn if ShowNormals is active. |
| ShowJoints | Boolean | Render visual controllers for all joints. Only works if an armature exists. |
| JointsColor | TAlphaColor | Get or set joints color for rendering visual controllers. Applied only if ShowJoints is TRUE. |
| Interpolators | TGorillaInterpolatorList | Returns list of internally used interpolators for animation. Each interpolator defines animation step for a specific mesh. |
| Package | TGorillaAssetsPackage | Returns linked package. If no package linked, getter tries to find package by PackageName and AssetsManager. |
| AnimationManager | TGorillaAnimationManager | Integrated animation manager for holding animation instances and managing interactions (playing, switching, stopping). |
| MetaData | TModelMetaDef | Tries to receive metadata from embedded TModelDef. |
| DefStoredInPackage | Boolean | Indicates if Definition is stored in a package (needed because package might be destroyed before model). |
Published Properties
| Property | Type | Description |
|---|---|---|
| AssetsManager | TGorillaAssetsManager | Link to existing assets manager component. Use PackageName to define the used/requested assets package. |
| PackageName | String | Get or set assets package name to load/store model and texture data. |
| Source | TFileName | Get or set source filename for model file. If assets package linked, component tries to load from package, otherwise from file. |
Shadows:
TGorillaModelinheritsShadows(receives cascaded shadows) andCastShadows(defaultTrue; whether it is written into the shadow atlas) from TGorillaMesh. Because a model's sub-meshes and materials only exist after the file is loaded, the model re-appliesShadowsonce loading completes — so settingShadows := Truein the form designer (where it is streamed beforeSource) correctly switches every loaded material toCascadedShadowMapping. To stop a model from throwing a shadow, setCastShadows := False.
Constructor & Destructor
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
Standard component lifecycle methods.
Public Methods
Model Loading
procedure LoadFromFile(const APackage: TGorillaAssetsPackage;
const AFilename: String; const ACaching: TAnimationCachingFlags); overload;
procedure LoadFromFile(const AOptions: TGorillaLoadOptions); overload;
Loads model data with sub-meshes, materials, animations to existing instance.
Parameters:
APackage- Optional. If nil, loads from file. If assigned, looks up in assets package first.AFilename- Path to model fileACaching- Animation caching flagsAOptions- Advanced loading options structure
Example:
// Simple loading
GorillaModel1.LoadFromFile(nil, 'character.dae', []);
// With asset package
GorillaModel1.LoadFromFile(MyPackage, 'character.g3d',
[TAnimationCachingFlag.VertexPosition]);
// Advanced loading
var Options := TGorillaLoadOptions.Create('model.fbx', [], nil, nil);
Options.ImportLights := True;
GorillaModel1.LoadFromFile(Options);
procedure LoadFromStream(const APackage: TGorillaAssetsPackage;
const AStream: TStream; const APath: String;
const ACaching: TAnimationCachingFlags); overload;
procedure LoadFromStream(const AStream: TStream;
const AOptions: TGorillaLoadOptions); overload;
Loads model data from stream to existing instance.
Parameters:
APackage- Optional assets packageAStream- Stream containing model dataAPath- Path/filename for format detectionACaching- Animation caching flagsAOptions- Advanced loading options
class function LoadNewModelFromFile(const AOwner: TComponent;
const APackage: TGorillaAssetsPackage; const AFilename: String;
const ACaching: TAnimationCachingFlags): TGorillaModel; overload;
class function LoadNewModelFromFile(const AOwner: TComponent;
const AOptions: TGorillaLoadOptions): TGorillaModel; overload;
Loads model data from file and creates new instance.
Returns: New TGorillaModel instance
Example:
var MyModel := TGorillaModel.LoadNewModelFromFile(
Viewport,
nil,
'models\character.dae',
[]
);
MyModel.Parent := Viewport;
class function LoadNewModelFromOptions(const AOwner: TComponent;
const AOptions: TGorillaLoadOptions): TGorillaModel;
Alternative method for scripting compatibility where RTTI cannot detect correct overloaded method.
class function LoadNewModelFromStream(const AOwner: TComponent;
const APackage: TGorillaAssetsPackage; const AStream: TStream;
const APath: String; const ACaching: TAnimationCachingFlags): TGorillaModel; overload;
class function LoadNewModelFromStream(const AOwner: TComponent;
const AStream: TStream; const AOptions: TGorillaLoadOptions): TGorillaModel; overload;
Loads model data from stream and creates new instance.
class function LoadNewModelFromDef(const AOwner: TComponent;
const ADef: TModelDef; const ACaching: TAnimationCachingFlags): TGorillaModel; overload;
class function LoadNewModelFromDef(const AOwner: TComponent;
const ADef: TModelDef; const AOptions: TGorillaLoadOptions): TGorillaModel; overload;
Creates new instance and applies existing model definition with sub-meshes, materials, animations. Use for instancing predefined models without assets manager.
procedure LoadFromDefinition(const ADef: TModelDef); reintroduce;
Applies given ModelDefinition to model instance. Automatically instantiates meshes, materials, animations. Internal use - called when loading from stream or file.
procedure StoreToDefinition(const ADef: TCustomDef); override;
Stores all data from visual component back to definition object.
Animation Management
function AddAnimationFromFile(const AFilename: String;
const ACaching: TAnimationCachingFlags = []): TGorillaAnimation;
Loads animation data from file to existing model and returns created animation instance.
Requirements: Model data (meshes, materials, textures) must be loaded before adding animation.
Important: You can only add animations on an existing model, if the meta data from original model import is still available. Because after reloading a model, it's not loaded from the original file format again. So the meta data from a FBX or DAE is lost and animation data cannot be applied again.
Example:
var Anim := GorillaModel1.AddAnimationFromFile(
'character_run.dae',
[TAnimationCachingFlag.VertexPosition]
);
function AddAnimationFromStream(const AStream: TStream;
const AFileName: String;
const ACaching: TAnimationCachingFlags = []): TGorillaAnimation;
Loads animation data from stream to existing model and returns created animation instance.
Interpolator Management
Interpolators are controls that animate single parts of a model. For example they are used to animate joints inside of a skeleton mesh. It's helpful to request interpolators to modify behaviour of specific parts. For example to manually move a joint.
procedure AddInterpolator(const AName: String;
AInterpolator: TPropertyKeyAnimation);
Adds property key animation interpolator to model. Used while loading animated model from file.
function FindInterpolator(const AName: String): TPropertyKeyAnimation;
Tries to find specific property key animation interpolator by name. Returns nil if not found.
function FindInterpolatorByDef(const ADef: TCustomDef): TPropertyKeyAnimation;
Tries to find specific property key animation interpolator by its definition. Returns nil if not found.
Search Methods
function FindControlByDeepSearch(const AName: String): TComponent; override;
Searches for interpolator or sub-mesh inside model hierarchy by name. Searches all levels. Returns nil if not found.
function FindControlByDefDeepSearch(const ADef: TCustomDef): TComponent; override;
Searches for interpolator or sub-mesh inside model hierarchy by definition. Returns nil if not found.
procedure FindControlsByDeepSearch(const AName: String;
const AResult: TReferencedControlList); override;
Searches for all interpolators or sub-meshes with submitted name. Results added to AResult list. List stays empty if nothing found.
Utility Methods
procedure Clear();
Destroys all sub-meshes and animations.
procedure ResolvingSegment(AId: String; AObj: TGorillaTransform);
Used by sub-components to resolve segment instances. Segments created as dummies might be replaced by real instance later.
procedure UpdateBinaryData();
Clears internal binary data storage and stores model definition data to binary format. Called at design time to save model into DFM/FMX file.
function GetFirstArmature(): TComponent;
Tries to find armature instance and returns first one found.
procedure DebugOut(ACompHierarchy: Boolean = false);
Outputs model hierarchy into log. Useful to check hierarchy built after importing. Check event log for printed content.
Parameters:
ACompHierarchy- False = FMX hierarchy, True = Component hierarchy
function GetBoundingBox(): TBoundingBox; override;
function GetAbsoluteBoundingBox(): TBoundingBox; override;
Returns ABSOLUTE bounding box with applied mesh and local matrices. Union of all submeshes.
Helper Types
TGorillaInterpolatorList
Dictionary mapping interpolator names to TPropertyKeyAnimation instances.
TGorillaInterpolatorList = TDictionary<String, TPropertyKeyAnimation>;
Usage Examples
Basic Model Loading
var
Model: TGorillaModel;
begin
Model := TGorillaModel.LoadNewModelFromFile(
Viewport,
nil,
'models\spaceship.dae',
[TAnimationCachingFlag.VertexPosition]
);
Model.Parent := Viewport;
Model.Position.Point := Point3D(0, 0, 0);
end;
Loading with Asset Package
var
Model: TGorillaModel;
begin
Model := TGorillaModel.LoadNewModelFromFile(
Viewport,
AssetsPackage1,
'character.g3d',
[TAnimationCachingFlag.VertexPosition]
);
Model.Parent := Viewport;
end;
Adding Animation
// Load base model
GorillaModel1.LoadFromFile(nil, 'character.dae', []);
// Add additional animations
var WalkAnim := GorillaModel1.AddAnimationFromFile(
'character_walk.dae',
[TAnimationCachingFlag.VertexPosition]
);
var RunAnim := GorillaModel1.AddAnimationFromFile(
'character_run.dae',
[TAnimationCachingFlag.VertexPosition]
);
// Play animation
GorillaModel1.AnimationManager.PlayAnimation('Walk');
Advanced Loading Options
var
Options: TGorillaLoadOptions;
Model: TGorillaModel;
begin
Options := TGorillaLoadOptions.Create('scene.fbx', [], nil, nil);
// Configure import settings
Options.ImportLights := True;
Options.ImportCameras := True;
Options.ImportAnimations := True;
// Configure caching
Options.Caching := [TAnimationCachingFlag.VertexPosition];
// Limit texture sizes
Options.TextureLimits := TPoint.Create(2048, 2048);
// Load model
Model := TGorillaModel.LoadNewModelFromFile(Viewport, Options);
Model.Parent := Viewport;
end;
Searching Hierarchy
// Find specific mesh
var HeadMesh := GorillaModel1.FindControlByDeepSearch('Head') as TGorillaMesh;
if Assigned(HeadMesh) then
HeadMesh.MaterialSource := HeadMaterial;
// Find armature
var Armature := GorillaModel1.GetFirstArmature() as TGorillaArmature;
if Assigned(Armature) then
begin
Armature.ShowJoints := True;
Armature.JointsRenderColor := TAlphaColors.Yellow;
end;
// Find all meshes with specific name
var List := TReferencedControlList.Create;
try
GorillaModel1.FindControlsByDeepSearch('Wheel', List);
for var i := 0 to List.Count - 1 do
ShowMessage('Found: ' + TGorillaMesh(List[i]).Name);
finally
List.Free;
end;
Debug Output
// Output FMX hierarchy
GorillaModel1.DebugOut(False);
// Output component hierarchy
GorillaModel1.DebugOut(True);
Constants
Animation Caching
GORILLA_ANIMATION_CACHING_DEFAULT = [];
Default animation caching configuration (no caching).
Usage Notes
-
Loading Order: Model data must be loaded before adding animations for proper vertex-animation linking.
-
Asset Packages: Using asset packages improves IDE performance and enables model reuse across instances.
-
Memory Management: Models stored in packages are managed by TGorillaAssetsManager. Standalone models own their definitions.
-
Animation Caching: VertexPosition flag recommended for balanced performance/memory. AllAttributes uses more memory but provides maximum speed.
-
Binary Data: Design-time models stored as compressed G3D format in FMX files for efficient storage.
-
Deep Search: FindControlByDeepSearch methods search entire hierarchy including interpolators, useful for accessing specific parts.