Gorilla.Animation Unit Reference
Overview
The Gorilla.Animation unit provides a comprehensive animation system for Gorilla3D, supporting skeletal/joint animation, vertex (mesh) animation, and property-based keyframe animation. It extends FireMonkey's animation framework with 3D-specific functionality and synchronization mechanisms.
Architecture
The animation system is built on a hierarchical structure:
TGorillaAnimationManager
└─ TGorillaAnimation
└─ TSkeletonKeyAnimation
└─ TPropertyKeyAnimation (abstract base)
├─ TPoint3DKeyAnimation
├─ TVector3DKeyAnimation
├─ TQuaternion3DKeyAnimation
├─ TTransformationKeyAnimation
└─ TCoordinateKeyAnimation
Core Classes
TPropertyKeyAnimation
Abstract base class for all keyframe-based animations in Gorilla3D.
Inheritance: TCustomPropertyAnimation → TPropertyKeyAnimation
Platforms: All Gorilla3D supported platforms
Public Properties
| Property | Type | Description |
|---|---|---|
| QualifiedName | String | Qualified identifier from definition import. |
| Elements | TReferencedComponentList | Hashmap of linked components. |
| Def | TObject | Linked Gorilla3D definition structure. |
| TransitionTime | Single | Latest computed normalized time (read-only). |
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
| Keys | TKeys | - | Collection of keyframes. |
| StartFromCurrent | Boolean | False | Start animation from current property value. |
| AnimationType | TAnimationType | In | Easing type: In, Out, InOut. |
| AutoReverse | Boolean | False | Reverse playback at end. |
| Enabled | Boolean | False | Enable/disable animation. |
| Delay | Single | 0.0 | Delay before starting (seconds). |
| Duration | Single | - | Total animation duration (required). |
| Interpolation | TInterpolationType | Linear | Interpolation algorithm. |
| Inverse | Boolean | False | Start from end to beginning. |
| Loop | Boolean | False | Repeat animation continuously. |
| PropertyName | String | - | Target property name (supports dot notation). |
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure Stop(); override;
Stops the animation and clears internal caches.
procedure AddElements(const AElements: TReferencedComponentList);
Applies animation to multiple components.
Parameters:
AElements- List of components to animate
Example:
var
Elements: TReferencedComponentList;
begin
Elements := TReferencedComponentList.Create();
Elements.AddOrSetValue(Cube1, True);
Elements.AddOrSetValue(Sphere1, True);
Animation.AddElements(Elements);
end;
procedure AddElement(const AElement: TComponent; const AValue: Boolean);
Applies animation to a single component.
Parameters:
AElement- Component to animateAValue- Enable flag (typically True)
Example:
Animation.AddElement(Cube1, True);
procedure LoadFromInterpolatorDef(ADef: TCustomDef); virtual; abstract;
Loads animation from a definition structure. Must be implemented by derived classes.
Parameters:
ADef- Definition object (TPoint3DInterpolatorDef, TVector3DInterpolatorDef, etc.)
procedure ResetCaching();
Resets animation values manipulated during caching.
procedure ProcessCachingTick(time, deltaTime: Single);
Processes animation tick during caching operations.
Parameters:
time- Current animation timedeltaTime- Time since last tick
procedure Transform(const AMat: TMatrix3D); virtual; abstract;
Transforms all keyframe data by a matrix (e.g., for mirroring).
Parameters:
AMat- Transformation matrix to apply
Example:
var
MirrorMatrix: TMatrix3D;
begin
MirrorMatrix := TMatrix3D.CreateScaling(Point3D(-1, 1, 1));
Animation.Transform(MirrorMatrix);
end;
TPoint3DKeyAnimation
Keyframe animation for TPoint3D properties (Position, Rotation, Scale).
Inheritance: TPropertyKeyAnimation → TPoint3DKeyAnimation
Platforms: All Gorilla3D supported platforms
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from TPoint3DInterpolatorDef.
procedure Transform(const AMat: TMatrix3D); override;
Transforms all keyframe points by matrix.
Usage Example
var
Anim: TPoint3DKeyAnimation;
Key: TPoint3DKey;
begin
Anim := TPoint3DKeyAnimation.Create(Self);
Anim.PropertyName := 'Position.Point';
Anim.Duration := 2.0;
Anim.Loop := True;
Anim.AddElement(Cube1, True);
Key := TPoint3DKey(Anim.Keys.Add);
Key.Time := 0.0;
Key.Value[Cube1] := Point3D(0, 0, 0);
Key := TPoint3DKey(Anim.Keys.Add);
Key.Time := 1.0;
Key.Value[Cube1] := Point3D(10, 5, 0);
Anim.Start();
end;
TVector3DKeyAnimation
Keyframe animation for TVector3D properties.
Inheritance: TPropertyKeyAnimation → TVector3DKeyAnimation
Platforms: All Gorilla3D supported platforms
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from TVector3DInterpolatorDef.
procedure Transform(const AMat: TMatrix3D); override;
Transforms all keyframe vectors by matrix.
TQuaternion3DKeyAnimation
Keyframe animation for quaternion-based rotations.
Inheritance: TPropertyKeyAnimation → TQuaternion3DKeyAnimation
Platforms: All Gorilla3D supported platforms
Features:
- Smooth rotation interpolation (SLERP)
- No gimbal lock
- Efficient for complex rotations
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from TQuaternion3DInterpolatorDef.
procedure Transform(const AMat: TMatrix3D); override;
Transforms all keyframe quaternions by matrix.
Usage Example
var
Anim: TQuaternion3DKeyAnimation;
Key: TQuaternion3DKey;
Quat: TQuaternion3D;
begin
Anim := TQuaternion3DKeyAnimation.Create(Self);
Anim.PropertyName := 'RotationAngle';
Anim.Duration := 3.0;
Anim.AddElement(Cube1, True);
Quat := TQuaternion3D.Create(Vector3D(0, 0, 0));
Key := TQuaternion3DKey(Anim.Keys.Add);
Key.Time := 0.0;
Key.Value[Cube1] := Quat;
Quat := TQuaternion3D.Create(Vector3D(0, 180, 0));
Key := TQuaternion3DKey(Anim.Keys.Add);
Key.Time := 1.0;
Key.Value[Cube1] := Quat;
Anim.Start();
end;
TTransformationKeyAnimation
Keyframe animation for TMatrix3D transformations (primarily skeletal animation).
Inheritance: TPropertyKeyAnimation → TTransformationKeyAnimation
Platforms: All Gorilla3D supported platforms
Use Cases:
- Joint/bone animation
- Complex combined transforms
- Skeletal rigs
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from TTransformationInterpolatorDef.
procedure Transform(const AMat: TMatrix3D); override;
Transforms all keyframe matrices by matrix.
Usage Example
var
Anim: TTransformationKeyAnimation;
Key: TTransformationKey;
Matrix: TMatrix3D;
begin
Anim := TTransformationKeyAnimation.Create(Self);
Anim.PropertyName := 'LocalMatrix';
Anim.AddElement(Joint1, True);
Matrix := TMatrix3D.CreateTranslation(Point3D(0, 0, 0));
Key := TTransformationKey(Anim.Keys.Add);
Key.Time := 0.0;
Key.Value[Joint1] := Matrix;
Matrix := TMatrix3D.CreateTranslation(Point3D(0, 5, 0)) *
TMatrix3D.CreateRotationY(DegToRad(45));
Key := TTransformationKey(Anim.Keys.Add);
Key.Time := 1.0;
Key.Value[Joint1] := Matrix;
Anim.Start();
end;
TCoordinateKeyAnimation
Keyframe animation for vertex positions (mesh morphing).
Inheritance: TPropertyKeyAnimation → TCoordinateKeyAnimation
Platforms: All Gorilla3D supported platforms
Use Cases:
- Vertex animation
- Morph targets
- Facial animation
- Organic deformations
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from TMeshInterpolatorDef.
procedure Transform(const AMat: TMatrix3D); override;
Transforms all keyframe vertices by matrix.
Usage Example
var
Anim: TCoordinateKeyAnimation;
Key: TCoordinateKey;
Vertices: TPoint3DDynArray;
begin
Anim := TCoordinateKeyAnimation.Create(Self);
Anim.PropertyName := 'Data.Vertices';
Anim.Duration := 2.0;
Anim.AddElement(CustomMesh1, True);
SetLength(Vertices, CustomMesh1.Data.VertexBuffer.Length);
// ... populate vertices array
Key := TCoordinateKey(Anim.Keys.Add);
Key.Time := 0.0;
Key.Vertices[CustomMesh1] := Vertices;
// ... add more keys
Anim.Start();
end;
TSkeletonKeyAnimation
Container for synchronized animation of multiple property key animations.
Inheritance: TPropertyKeyAnimation → TSkeletonKeyAnimation
Platforms: All Gorilla3D supported platforms
Purpose:
- Synchronize multiple joint animations
- Group related property animations
- Eliminate timing offsets between joints
- Centralized control of complex animations
Public Properties
| Property | Type | Description |
|---|---|---|
| Interpolators | TGorillaPropertyKeyAnimationList | Collection of grouped property animations (read-only). |
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
| AutoRepaint | Boolean | True | Automatically call Repaint() after each ProcessAnimation(). |
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure LoadFromInterpolatorDef(ADef: TCustomDef); override;
Loads from animation definition.
procedure AddInterpolator(AInter: TPropertyKeyAnimation);
Adds and enables an interpolator.
Important: Use this method instead of Interpolators.Add() to properly initialize the interpolator.
Parameters:
AInter- Property key animation to add
Example:
var
SkeletonAnim: TSkeletonKeyAnimation;
JointAnim: TTransformationKeyAnimation;
begin
SkeletonAnim := TSkeletonKeyAnimation.Create(Self);
JointAnim := TTransformationKeyAnimation.Create(Self);
JointAnim.PropertyName := 'LocalMatrix';
JointAnim.AddElement(Joint1, True);
// ... configure JointAnim
SkeletonAnim.AddInterpolator(JointAnim);
SkeletonAnim.Start();
end;
procedure Reset();
Resets all child interpolators to starting position by calling ProcessTick(0, 0).
procedure SetSpeed(const ASpeed: Single);
Sets animation speed for all child interpolators.
Parameters:
ASpeed- Speed multiplier (1.0 = normal, 2.0 = double speed, 0.5 = half speed)
Example:
SkeletonAnim.SetSpeed(1.5); // 50% faster playback
procedure Start(); override;
procedure Stop(); override;
Start/stop all child animations synchronously.
procedure ProcessAnimationRemote(ATime, ADeltaTime: Single);
Manually process animation tick (for external control).
Parameters:
ATime- Current animation timeADeltaTime- Time delta since last tick
procedure Transform(const AMat: TMatrix3D); override;
Transforms all child interpolators by matrix.
Parameters:
AMat- Transformation matrix
TGorillaAnimation
High-level animation instance representing a complete animation (e.g., "Walk", "Run").
Inheritance: TFmxObject → TGorillaAnimation
Platforms: All Gorilla3D supported platforms
Interfaces: IDuplicatable
Public Properties
| Property | Type | Description |
|---|---|---|
| Def | TAnimationDef | Associated animation definition (read-only). |
| Id | String | Registered animation identifier (read-only). |
| Skeleton | TSkeletonKeyAnimation | Skeleton helper interpolator holding sub-interpolators (read-only). |
| IsRunning | Boolean | True if animation is playing (read-only). |
| IsPaused | Boolean | True if animation is paused (read-only). |
| FrameCount | Integer | Total number of frames (read-only). |
| FrameRate | Integer | Frames per second (read-only). |
Published Properties
| Property | Type | Description |
|---|---|---|
| UseTransform | Boolean | Enable/disable TransformMatrix application. |
| TransformMatrix | TMatrix3D | Transformation matrix for animated vertices. |
| Manager | TGorillaAnimationManager | Owner AnimationManager component. |
| Source | String | Animation file source path. |
Public Methods
constructor Create(AOwner: TComponent); override;
Standard constructor.
constructor CreateEx(const AManager: TGorillaAnimationManager); virtual;
Creates animation with linked manager.
Parameters:
AManager- Parent animation manager
destructor Destroy(); override;
procedure LoadFromAnimationDef(ADef: TAnimationDef); virtual;
Loads animation from definition structure.
Parameters:
ADef- Animation definition from model import
Example:
var
Animation: TGorillaAnimation;
begin
Animation := TGorillaAnimation.CreateEx(Manager);
Animation.LoadFromAnimationDef(ModelDef.Animations[0]);
end;
procedure Start(); virtual;
procedure Stop(); virtual;
procedure Reset(); virtual;
Control animation playback.
procedure SetSpeed(const ASpeed: Single);
Sets playback speed.
Parameters:
ASpeed- Speed multiplier
procedure SetFixedCacheFrame(AFrameNr: Integer);
Sets a fixed frame number for cache debugging.
Parameters:
AFrameNr- Frame number to display
procedure UnsetFixedCacheFrame();
Deactivates fixed frame rendering.
function GetCurrentCachedFrame(const AMeshDef: TMeshDef): TMeshBufferObject;
Returns current mesh buffer object if caching is active.
Parameters:
AMeshDef- Mesh definition
Returns: Cached mesh buffer for current frame, or nil
TGorillaAnimationManager
Central manager for all animations associated with a 3D model or character.
Inheritance: TComponent → TGorillaAnimationManager
Platforms: All Gorilla3D supported platforms
Interfaces: IDuplicatable
Public Properties
| Property | Type | Description |
|---|---|---|
| Mesh | TObject | Associated mesh/model object. |
| Animations | TGorillaAnimationMap | Hashmap of id-to-animation relationships (read-only). |
| Current | TGorillaAnimation | Currently active animation instance. |
Published Properties
| Property | Type | Description |
|---|---|---|
| CurrentAnimationName | String | Name of currently active animation. |
Public Methods
constructor Create(AOwner: TComponent); override;
destructor Destroy(); override;
procedure Clear(); virtual;
Clears all animations from manager.
function GetFirstAnimation(): TGorillaAnimation;
Returns first animation in collection (order not guaranteed).
Returns: First animation or nil
function GetLastAnimation(): TGorillaAnimation;
Returns last animation in collection (order not guaranteed).
Returns: Last animation or nil
function GetAnimation(const AId: String = ''): TGorillaAnimation; overload;
Returns animation by identifier.
Parameters:
AId- Animation identifier (empty string returns Current)
Returns: Animation instance or nil
Example:
var
WalkAnim: TGorillaAnimation;
begin
WalkAnim := Manager.GetAnimation('Walk');
if Assigned(WalkAnim) then
WalkAnim.Start();
end;
function GetAnimation(const ADef: TAnimationDef): TGorillaAnimation; overload;
Returns animation by definition.
Parameters:
ADef- Animation definition
Returns: Animation instance or nil
function AddAnimation(const AId: String; const AAnimation: TGorillaAnimation): TGorillaAnimation;
Adds animation to manager.
Parameters:
AId- Unique identifierAAnimation- Animation instance
Returns: Added animation, or existing animation if AId already exists
Example:
var
Animation: TGorillaAnimation;
begin
Animation := TGorillaAnimation.CreateEx(Manager);
Animation.LoadFromAnimationDef(AnimDef);
Manager.AddAnimation('Walk', Animation);
end;
function PlayAnimation(const AId: String): TGorillaAnimation; overload;
Plays animation by identifier.
Parameters:
AId- Animation identifier
Returns: Playing animation or nil if not found
Behavior:
- If already current: starts or continues
- If different: stops current and starts new
- If not found: returns nil
Example:
Manager.PlayAnimation('Run');
function PlayAnimation(const AAnim: TGorillaAnimation): TGorillaAnimation; overload;
Plays specific animation instance.
Parameters:
AAnim- Animation instance
Returns: Playing animation
function PlayNextAnimation(): TGorillaAnimation;
Plays next animation in sequence.
Returns: Next animation or first animation if at end
function PlayPreviousAnimation(): TGorillaAnimation;
Plays previous animation in sequence.
Returns: Previous animation or last animation if at beginning
class function ForceStep(AMinDeltaTime: Double = 0.01): Boolean;
Forces animation update outside FMX message loop.
Parameters:
AMinDeltaTime- Minimum time since last update (default: 0.01 seconds)
Returns: True if step was forced, False if skipped
Example:
// In rendering loop or timer
if TGorillaAnimationManager.ForceStep(0.01) then
Viewport.EndUpdate()
else
Viewport.EndUpdateWithoutInvalidate();
TPoint3DAnimation
Simple property animation for TPoint3D without keyframes.
Inheritance: TCustomPropertyAnimation → TPoint3DAnimation
Platforms: All Gorilla3D supported platforms
Published Properties
| Property | Type | Default | Description |
|---|---|---|---|
| StartValue | TPosition3D | - | Starting point. |
| StopValue | TPosition3D | - | Ending point. |
| StartFromCurrent | Boolean | False | Start from current property value. |
| AnimationType | TAnimationType | In | Easing type. |
| AutoReverse | Boolean | False | Reverse at end. |
| Enabled | Boolean | False | Enable/disable. |
| Delay | Single | 0.0 | Start delay. |
| Duration | Single | - | Animation duration. |
| Interpolation | TInterpolationType | Linear | Interpolation type. |
| Inverse | Boolean | False | Reverse direction. |
| Loop | Boolean | False | Loop playback. |
| PropertyName | String | - | Target property. |
Usage Example
var
Anim: TPoint3DAnimation;
begin
Anim := TPoint3DAnimation.Create(Self);
Anim.Parent := Cube1;
Anim.PropertyName := 'Position.Point';
Anim.StartValue.Point := Point3D(0, 0, 0);
Anim.StopValue.Point := Point3D(10, 5, 0);
Anim.Duration := 2.0;
Anim.Loop := True;
Anim.Start();
end;
Data Structures
TPoint3DKey
Single keyframe for TPoint3D animation.
Inheritance: TKey → TPoint3DKey
Properties
| Property | Type | Description |
|---|---|---|
| Value[Index: TComponent] | TPoint3D | Point value for specific component. |
Methods
procedure SetDefaultValue(AValue: TPoint3D);
function GetDefaultValue(): TPoint3D;
TVector3DKey
Single keyframe for TVector3D animation.
Inheritance: TKey → TVector3DKey
Properties
| Property | Type | Description |
|---|---|---|
| Value[Index: TComponent] | TVector3D | Vector value for specific component. |
TQuaternion3DKey
Single keyframe for quaternion animation.
Inheritance: TKey → TQuaternion3DKey
Properties
| Property | Type | Description |
|---|---|---|
| Value[Index: TComponent] | TQuaternion3D | Quaternion value for specific component. |
TTransformationKey
Single keyframe for matrix transformation.
Inheritance: TKey → TTransformationKey
Properties
| Property | Type | Description |
|---|---|---|
| Value[Index: TComponent] | TMatrix3D | Matrix value for specific component. |
TCoordinateKey
Single keyframe for vertex positions.
Inheritance: TKey → TCoordinateKey
Properties
| Property | Type | Description |
|---|---|---|
| Vertices[Index: TComponent] | TPoint3DDynArray | Vertex array for specific component. |
Type Definitions
TGorillaInterpolatorList
TGorillaInterpolatorList = TDictionary<String, TPropertyKeyAnimation>;
Hashmap of identifier-to-animation pairs.
TGorillaAnimationMap
TGorillaAnimationMap = TDictionary<String, TGorillaAnimation>;
Hashmap of identifier-to-TGorillaAnimation pairs.
TElementPoints
TElementPoints = TDictionary<TComponent, TPoint3D>;
Component-to-Point3D hashmap for keys.
TElementVectors
TElementVectors = TDictionary<TComponent, TVector3D>;
Component-to-Vector3D hashmap for keys.
TElementQuaternions
TElementQuaternions = TDictionary<TComponent, TQuaternion3D>;
Component-to-Quaternion3D hashmap for keys.
TElementMatrices
TElementMatrices = TDictionary<TComponent, TMatrix3D>;
Component-to-Matrix3D hashmap for keys.
TElementCoordinates
TElementCoordinates = TDictionary<TComponent, TPoint3DDynArray>;
Component-to-vertex-array hashmap for keys.
Important Notes
-
Synchronization: Use
TSkeletonKeyAnimationto group related animations for synchronized playback without timing offsets. -
Performance: Use
ForceStep()in rendering loops to avoid FMX timer jitter for smoother animation. -
Caching: Complex vertex animations benefit from frame caching to reduce CPU load.
-
Property Names: Supports dot notation for nested properties (e.g., "Position.Point.X").
-
Multiple Elements: Single animation can control multiple components with different values per keyframe.
-
Interpolation: All animations support standard FireMonkey interpolation types (Linear, Quadratic, Cubic, etc.).
-
Transform Matrices: Animations can be transformed (mirrored, scaled) by applying matrices to all keyframes.
-
AutoRepaint: Disable
AutoRepaintonTSkeletonKeyAnimationfor manual viewport control and better performance. -
Memory Management: Always properly stop and free animations to prevent memory leaks.
-
Thread Safety: Animation updates occur on main thread via FMX timer or DisplayLink service.