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. |
| ShowBoundingBox | Boolean | Inherited from TGorillaControl. Renders a box around the current pose of the model (main render pass only). Unlike the designer selection box (IsMarked) it follows skin, vertex and sub-mesh animations. See GetAnimatedBoundingBox(). Default: False. |
| BoundingBoxColor | TAlphaColor | Inherited from TGorillaControl. Line color of the box drawn by ShowBoundingBox. Default: TAlphaColorRec.Orange. |
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.
procedure RecacheAnimations(const ACaching: TAnimationCachingFlags = []); virtual;
procedure RecacheAnimationsByName(const AIds: Array of String;
const ACaching: TAnimationCachingFlags = []); virtual;
Throws the cached frames of all animations (or of the animations whose id is in AIds,
case-insensitive, unknown ids are ignored) away and bakes them again.
ACaching = [] keeps the flags each animation was cached with before - animations that
were never cached stay uncached. Pass flags (f.e. GORILLA_ANIMATION_CACHING_DEFAULT) to
cache all of them. Animations that were playing are restarted afterwards.
Takes as long as the initial caching did - for a character with many clips that is seconds.
Example:
GorillaModel1.RecacheAnimations(GORILLA_ANIMATION_CACHING_DEFAULT);
GorillaModel1.RecacheAnimationsByName(['walk', 'run']);
procedure DiscardAnimationCache(); virtual;
procedure DiscardAnimationCacheByName(const AIds: Array of String); virtual;
Throws the cached frames of all animations (or of the animations whose id is in AIds)
away. They play skinned on the CPU afterwards, like animations added without caching - a
playing animation keeps playing.
The animations are not cacheable any more afterwards, so RecacheAnimations() without
flags leaves them uncached - pass the flags to bake them again:
GorillaModel1.DiscardAnimationCache();
GorillaModel1.RecacheAnimations(GORILLA_ANIMATION_CACHING_DEFAULT);
Important: The frames belong to the model definition: other model instances sharing it (f.e. loaded from the same assets package) lose them too.
Animation State
procedure ResetToBindPose();
Stops all animations and returns the model to its unanimated pose, for cached and CPU
skinned animations alike. Shortcut for AnimationManager.ResetToBindPose.
function HasCurrentAnimation(): Boolean;
True if the model has an animation manager with a current animation - short for
Assigned(AnimationManager) and Assigned(AnimationManager.Current). The current animation
does not need to be playing, see IsAnimationPlaying.
function TryGetCurrentAnimation(out AAnim: TGorillaAnimation): Boolean;
Returns the current animation in AAnim, or nil and False if there is none.
Example:
if GorillaModel1.TryGetCurrentAnimation(LAnim) then
Label1.Text := LAnim.Id;
function IsAnimationPlaying(): Boolean; overload;
function IsAnimationPlaying(const AId: String): Boolean; overload;
True if the current animation (or the animation with id AId) is playing at the moment.
With AId it does not matter whether it is the current animation or not (f.e. while
blending). The id is looked up like AnimationManager.GetAnimation does; unknown ids give
False.
Example:
if GorillaModel1.IsAnimationPlaying('walk') then
GorillaModel1.ResetToBindPose();
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.
function GetAnimatedBoundingBox(): TBoundingBox; override;
Declared in TGorillaControl, implemented by TGorillaMesh (see Gorilla.Mesh). Returns the bounding box of the CURRENT (animated) pose in local model space, i.e. relative to AbsoluteMatrix. Unlike GetBoundingBox(), which is built from the static vertex data, it follows skin, vertex and node animations.
For each sub-mesh the source is: the box stored with the current cached animation frame, otherwise the live CPU-animated vertex buffer, otherwise the static vertex data of the definition. Without animation caching all vertices are iterated, so avoid calling it needlessly every frame on large models. Returns TBoundingBox.Empty if no mesh has vertices.
var
LWorld: TBoundingBox;
begin
LWorld := GorillaModel1.GetAnimatedBoundingBox().Transform(GorillaModel1.AbsoluteMatrix);
end;
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. Skins that drive several meshes (glTF meshes with several primitives, skins shared by several mesh nodes) keep the joint weights of every mesh. Models embedded with an older version, where only one part animated at runtime, have to be loaded again at design time.
-
Deep Search: FindControlByDeepSearch methods search entire hierarchy including interpolators, useful for accessing specific parts.