Class TCastleSceneCore

Unit

Declaration

type TCastleSceneCore = class(TX3DEventsEngine)

Description

Loading and processing of a scene. Almost everything visible in your game will be an instance of TCastleScene, which is a descendant of this class that adds rendering capabilities.

This class provides a lot of functionality, like loading of the scene (Load method), animating it, performing collisions with the scene, and calculating things (like LocalBoundingBox).

The actual scene information (visible and collidable things) is inside X3D nodes graph contained within the RootNode. During the lifetime of the scene, this X3D graph can change (e.g. because of animations), and you can always change it by code too. E.g. you can freely change TTransformNode.Translation or add children by RootNode.AddChildren. The X3D nodes graph works like a DOM tree for rendering HTML documents: it's typically initialized from a file (3D model), but during the game execution it is dynamic, always changing.

This class takes care of performing the X3D events and routes mechanism (if ProcessEvents is True). This is what allows X3D graph to be animated, or even be interactive (respond to user actions). For a simple way to play animations, use the PlayAnimation method.

This class maintains a Shapes tree is always synchronized with the X3D nodes tree in RootNode. The Shapes tree provides a little simple view at the scene, sometimes easier (or faster) to iterate over.

Many results are cached, so querying them multiple times is fast, if the scene does not change (in a significant way) between each query. So you can query information like LocalBoundingBox, BoundingBox, VerticesCount... as often as you want to.

Hierarchy

Overview

Nested Classes and Records

Protected TVisibilitySensors = class(specialize TDictionary<TVisibilitySensorNode,TVisibilitySensorInstanceList>)

Nested Types

Published TCompiledScriptHandler = procedure ( Value: TX3DField; const Time: TX3DTime) of object;
Protected TVisibilitySensorInstanceList = specialize TObjectList<TVisibilitySensorInstance>;

Fields

Protected ScreenEffectNodes: TX3DNodeList;
Protected IsVisibleNow: boolean;
Protected GeneratedTextures: TGeneratedTextureList;
Public nested const DefaultShadowMapsDefaultSize = 256;

Methods

Protected function InternalBuildNodeInside: TObject; override;
Protected function CreateShape(const AGeometry: TAbstractGeometryNode; const AState: TX3DGraphTraverseState; const ParentInfo: PTraversingInfo): TShape; virtual;
Protected procedure UpdateHeadlightOnFromNavigationInfo;
Protected procedure ChangedTransform; override;
Protected procedure ChangeWorld(const Value: TCastleAbstractRootTransform); override;
Protected procedure DoPointingDeviceSensorsChange; virtual;
Protected procedure ExecuteCompiledScript(const HandlerName: String; ReceivedValue: TX3DField); override;
Protected function LocalHeightCollision(const APosition, GravityUp: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: PTriangle): boolean; override;
Protected function LocalMoveCollision( const OldPos, ProposedNewPos: TVector3; out NewPos: TVector3; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;
Protected function LocalMoveCollision( const OldPos, NewPos: TVector3; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;
Protected function LocalSegmentCollision(const Pos1, Pos2: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;
Protected function LocalSphereCollision(const Pos: TVector3; const Radius: Single; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;
Protected function LocalSphereCollision2D(const Pos: TVector2; const Radius: Single; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; const Details: TCollisionDetails): boolean; override;
Protected function LocalPointCollision2D(const Point: TVector2; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;
Protected function LocalBoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;
Protected function LocalRayCollision(const RayOrigin, RayDirection: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): TRayCollision; override;
Protected procedure LocalRender(const Params: TRenderParams); override;
Protected procedure Loaded; override;
Protected procedure InternalMoveShapeAssociations( const OldNode, NewNode: TX3DNode; const ContainingShapes: TObject); override;
Protected function LocalBoundingBoxNoChildren: TBox3D;
Public constructor Create(AOwner: TComponent); override;
Public function PropertySections(const PropertyName: String): TPropertySections; override;
Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override;
Public procedure Load(const ARootNode: TX3DRootNode; const AOwnsRootNode: boolean; const AOptions: TSceneLoadOptions = []); overload;
Public procedure Load(const AUrl: String; const AOptions: TSceneLoadOptions = []); overload;
Public procedure Load(const AUrl: String; const AllowStdIn: boolean; const AResetTime: boolean = true); overload; deprecated 'use Load with (AUrl: String, AOptions: TSceneLoadOptions) parameters. AllowStdIn is not implemented anymore.';
Public procedure Save(const AUrl: String);
Public procedure BeforeDestruction; override;
Public destructor Destroy; override;
Public function ShapesActiveCount: Cardinal;
Public function ShapesActiveVisibleCount: Cardinal;
Public function VerticesCount: Cardinal; overload;
Public function TrianglesCount: Cardinal; overload;
Public function ViewpointsCount: Cardinal;
Public function GetViewpointNode(const Idx: integer): TAbstractViewpointNode;
Public function GetViewpointName(const Idx: integer): String;
Public procedure MoveToViewpoint(const Idx: integer; const Animated: boolean = true);
Public procedure AddViewpointFromNavigation(const Navigation: TCastleNavigation; const AName: String);
Public procedure BeforeNodesFree(const InternalChangedAll: boolean = false); override;
Public procedure NodeFreeRemovingFromAllParents(Node: TX3DNode);
Public procedure RemoveShape(Shape: TShape);
Public procedure ChangedAll(const OnlyAdditions: Boolean = false); override;
Public procedure DoGeometryChanged(const Change: TGeometryChange; LocalGeometryShape: TShape); virtual;
Public procedure DoViewpointsChanged;
Public procedure DoBoundViewpointVectorsChanged;
Public procedure DoBoundNavigationInfoFieldsChanged; virtual;
Public procedure ScheduleChangedAll(const OnlyAdditions: Boolean = false);
Public procedure BeginChangesSchedule;
Public procedure EndChangesSchedule;
Public function Info( ATriangleVerticesCounts, ABoundingBox: boolean; AManifoldAndBorderEdges: boolean): String; deprecated 'do not use this, better to construct a summary string yourself';
Public function InfoTriangleVerticesCounts: String; deprecated 'better to construct a string yourself, use TrianglesCount, VerticesCount';
Public function InfoBoundingBox: String; deprecated 'better to construct a string yourself, use BoundingBox.ToString';
Public function InfoManifoldAndBorderEdges: String; deprecated 'better to construct a string yourself, use EdgesCount';
Public procedure EdgesCount(out ManifoldEdges, BorderEdges: Cardinal);
Public function InternalOctreeRendering: TShapeOctree;
Public function InternalOctreeDynamicCollisions: TShapeOctree;
Public function InternalOctreeCollisions: TBaseTrianglesOctree;
Public function UseInternalOctreeCollisions: boolean;
Public function GetViewpoint( out ProjectionType: TProjectionType; out CamPos, CamDir, CamUp, GravityUp: TVector3; const ViewpointDescription: String = ''): TAbstractViewpointNode;
Public function GetPerspectiveViewpoint( out CamPos, CamDir, CamUp, GravityUp: TVector3; const ViewpointDescription: String = ''): TAbstractViewpointNode;
Public procedure FreeResources(Resources: TSceneFreeResources); virtual;
Public procedure UnregisterScene(Node: TX3DNode); deprecated 'use Node.UnregisterScene';
Public function Press(const Event: TInputPressRelease): boolean; override;
Public function Release(const Event: TInputPressRelease): boolean; override;
Public function PointingDevicePress(const Pick: TRayCollisionNode; const Distance: Single): Boolean; override;
Public function PointingDeviceRelease(const Pick: TRayCollisionNode; const Distance: Single; const CancelAction: Boolean): Boolean; override;
Public function PointingDeviceMove(const Pick: TRayCollisionNode; const Distance: Single): boolean; override;
Public function PointingDeviceSensors: TPointingDeviceSensorList;
Public procedure PointingDeviceClear;
Public function LocalBoundingBox: TBox3D; override;
Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;
Public procedure SetTime(const NewValue: TFloatTime);
Public procedure IncreaseTime(const TimeIncrease: TFloatTime);
Public procedure IncreaseTimeTick; deprecated 'it should not be necessary to call this, ever; using TX3DEvent.Send(...) or TX3DEvent.Send(..., NextEventTime) will automatically behave Ok.';
Public function Time: TFloatTime; override;
Public function NextEventTime: TX3DTime; override;
Public procedure ResetTime(const NewValue: TFloatTime);
Public procedure ResetTimeAtLoad;
Public function GetBackgroundStack: TX3DBindableStackBasic; override;
Public function GetFogStack: TX3DBindableStackBasic; override;
Public function GetNavigationInfoStack: TX3DBindableStackBasic; override;
Public function GetViewpointStack: TX3DBindableStackBasic; override;
Public procedure RegisterCompiledScript(const HandlerName: String; Handler: TCompiledScriptHandler);
Public procedure InternalUpdateNavigation( const Navigation: TCastleNavigation);
Public procedure CameraTransition(const Camera: TCastleCamera; const APosition, ADirection, AUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';
Public procedure CameraTransition(const Camera: TCastleCamera; const APosition, ADirection, AUp, GravityUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';
Public procedure CameraTransition(const Navigation: TCastleNavigation; const APosition, ADirection, AUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';
Public procedure CameraTransition(const Navigation: TCastleNavigation; const APosition, ADirection, AUp, GravityUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';
Public function CustomHeadlight: TAbstractLightNode;
Public procedure PrepareResources(const Options: TPrepareResourcesOptions; const Params: TPrepareParams); override;
Public function Caption: String;
Public function Node(const NodeClass: TX3DNodeClass; const NodeName: String; const Options: TFindNodeOptions = []): TX3DNode; overload;
Public function Node(const NodeName: String): TX3DNode; overload;
Public function Field(const NodeName, FieldName: String): TX3DField; overload;
Public function Event(const NodeName, EventName: String): TX3DEvent; overload;
Public function HasAnimation(const AnimationName: String): boolean;
Public function AnimationTimeSensor(const AnimationName: String): TTimeSensorNode; overload;
Public function AnimationTimeSensor(const Index: Integer): TTimeSensorNode; overload;
Public function ForceAnimationPose(const AnimationName: String; const TimeInAnimation: TFloatTime; const Loop: boolean; const Forward: boolean = true): boolean; overload;
Public function PlayAnimation(const Parameters: TPlayAnimationParameters): boolean; overload;
Public function PlayAnimation(const AnimationName: String; const Loop: boolean; const Forward: boolean = true): boolean; overload;
Public procedure ForceInitialAnimationPose;
Public function AnimationDuration(const AnimationName: String): TFloatTime;
Public procedure StopAnimation(const DisableStopNotification: Boolean = false);
Public procedure ResetAnimationState(const IgnoreAffectedBy: TTimeSensorNode = nil);
Public procedure FontChanged;
Public function Clone(const AOwner: TComponent): TCastleSceneCore;
Public procedure InternalIncShapesHash;
Public procedure ReloadUrl;

Properties

Protected property VisibilitySensors: TVisibilitySensors read FVisibilitySensors;
Public property Shapes: TShapeTree read FShapes;
Public property OnGeometryChanged: TSceneGeometryChanged read FOnGeometryChanged write FOnGeometryChanged;
Public property OnViewpointsChanged: TNotifyEvent read FOnViewpointsChanged write FOnViewpointsChanged;
Public property OnBoundViewpointVectorsChanged: TNotifyEvent read FOnBoundViewpointVectorsChanged write FOnBoundViewpointVectorsChanged;
Public property OnBoundNavigationInfoFieldsChanged: TNotifyEvent read FOnBoundNavigationInfoFieldsChanged write FOnBoundNavigationInfoFieldsChanged;
Public property RootNode: TX3DRootNode read FRootNode write SetRootNode;
Public property OwnsRootNode: boolean read FOwnsRootNode write FOwnsRootNode default true; deprecated 'set OwnsRootNode only at loading, do not depend on this property';
Public property PointingDeviceOverItem: PTriangle read FPointingDeviceOverItem write FPointingDeviceOverItem;
Public property PointingDeviceOverPoint: TVector3 read FPointingDeviceOverPoint write FPointingDeviceOverPoint;
Public property PointingDeviceActiveSensors: TX3DNodeList read FPointingDeviceActiveSensors;
Public property PointingDeviceActive: boolean read FPointingDeviceActive default false;
Public property OnPointingDeviceSensorsChange: TNotifyEvent read FOnPointingDeviceSensorsChange write FOnPointingDeviceSensorsChange;
Public property TimeAtLoad: TFloatTime read FTimeAtLoad;
Public property BackgroundStack: TBackgroundStack read FBackgroundStack;
Public property FogStack: TFogStack read FFogStack;
Public property NavigationInfoStack: TNavigationInfoStack read FNavigationInfoStack;
Public property ViewpointStack: TViewpointStack read FViewpointStack;
Public property CompiledScriptHandlers: TCompiledScriptHandlerInfoList read FCompiledScriptHandlers;
Public property HeadlightOn: boolean read FHeadlightOn write SetHeadlightOn;
Public property OnHeadlightOnChanged: TNotifyEvent read FOnHeadlightOnChanged write FOnHeadlightOnChanged;
Public property InternalGlobalLights: TLightInstancesList read FGlobalLights;
Public property AnimationsList: TStrings read FAnimationsList;
Public property AnimationPrefix: String read FAnimationPrefix write FAnimationPrefix; deprecated 'this property did not prove to be of much use; report if you need it, otherwise it may be removed one day';
Public property CurrentAnimation: TTimeSensorNode read FCurrentAnimation;
Public property FileName: String read FUrl write SetUrl; deprecated;
Public property InternalShapesHash: TShapesHash read FShapesHash;
Published property DefaultAnimationTransition: Single read FDefaultAnimationTransition write FDefaultAnimationTransition default 0.0;
Published property TimePlaying: boolean read FTimePlaying write FTimePlaying default true;
Published property TimePlayingSpeed: Single read FTimePlayingSpeed write FTimePlayingSpeed default 1.0;
Published property PreciseCollisions: Boolean read FPreciseCollisions write SetPreciseCollisions default false;
Published property ProcessEvents: boolean read FProcessEvents write SetProcessEvents default false;
Published property Url: String read FUrl write SetUrl;
Published property ShadowMaps: boolean read FShadowMaps write SetShadowMaps default true;
Published property ShadowMapsDefaultSize: Cardinal read FShadowMapsDefaultSize write SetShadowMapsDefaultSize default DefaultShadowMapsDefaultSize;
Published property InitialViewpointIndex: Cardinal read FInitialViewpointIndex write FInitialViewpointIndex default 0;
Published property InitialViewpointName: String read FInitialViewpointName write FInitialViewpointName;
Published property AnimateOnlyWhenVisible: boolean read FAnimateOnlyWhenVisible write FAnimateOnlyWhenVisible default false;
Published property AnimateSkipTicks: Cardinal read FAnimateSkipTicks write SetAnimateSkipTicks default 0;
Published property AutoAnimation: String read FAutoAnimation write SetAutoAnimation;
Published property AutoAnimationLoop: Boolean read FAutoAnimationLoop write SetAutoAnimationLoop default true; deprecated 'in future engine versions, AutoAnimationLoop may behave as always = true, and AutoAnimation will be renamed to just Animation and changing it will always cause a looping animation. Use PlayAnimation(''my_anim'',false) from code to play animation without looping.';
Published property ExposeTransforms: TStrings read FExposeTransforms write SetExposeTransforms;
Published property ExposeTransformsPrefix: String read FExposeTransformsPrefix write SetExposeTransformsPrefix;
Published property Cache: Boolean read FCache write FCache default false;

Description

Nested Types

Published TCompiledScriptHandler = procedure ( Value: TX3DField; const Time: TX3DTime) of object;

This item has no description.

Protected TVisibilitySensorInstanceList = specialize TObjectList<TVisibilitySensorInstance>;

This item has no description.

Fields

Protected ScreenEffectNodes: TX3DNodeList;

List of TScreenEffectNode nodes, collected by ChangedAll.

Protected IsVisibleNow: boolean;

Is the scene visible currently. Descendants may set this to True during TCastleTransform.LocalRender.

Protected GeneratedTextures: TGeneratedTextureList;

This item has no description.

Public nested const DefaultShadowMapsDefaultSize = 256;

This item has no description.

Methods

Protected function InternalBuildNodeInside: TObject; override;

This item has no description. Showing description inherited from TCastleTransform.InternalBuildNodeInside.

Helper for InternalBuildNode. Result must be TAbstractChildNode or Nil.

Protected function CreateShape(const AGeometry: TAbstractGeometryNode; const AState: TX3DGraphTraverseState; const ParentInfo: PTraversingInfo): TShape; virtual;

Create TShape (or descendant) instance suitable for this TCastleSceneCore descendant. In this class, this simply creates new TShape instance. If you make a descendant of TCastleSceneCore, you may need to store some per-shape information, and then it may be useful to have your own TShape descendant to carry this information. So you can override this to create your own descendant, and then you're sure that all leafs within Shapes tree are created using this.

Example: TCastleScene uses this to create TGLShape.

Protected procedure UpdateHeadlightOnFromNavigationInfo;

This item has no description.

Protected procedure ChangedTransform; override;

This item has no description. Showing description inherited from TCastleTransform.ChangedTransform.

Override to be notified about every transformation change. By default, this calls VisibleChangeHere, which causes the window to redraw.

Protected procedure ChangeWorld(const Value: TCastleAbstractRootTransform); override;

This item has no description. Showing description inherited from TCastleTransform.ChangeWorld.

Called when the current World that contains this object changes. In the usual case, World corresponds to a TCastleViewport.Items instance, and when this method is called it means that object is added/removed from a viewport.

You can ignore this when called with Value equal to current World.

Note that each TCastleTransform instance can only be part of one world (TCastleAbstractRootTransform) at a time. Although we may be present many times within the same world. Always remove the TCastleTransform from previous world before adding it to a new one.

Protected procedure DoPointingDeviceSensorsChange; virtual;

Called after PointingDeviceSensors or PointingDeviceActiveSensors lists (possibly) changed.

In this class, DoPointingDeviceSensorsChange updates Cursor and calls OnPointingDeviceSensorsChange.

Protected procedure ExecuteCompiledScript(const HandlerName: String; ReceivedValue: TX3DField); override;

This item has no description.

Protected function LocalHeightCollision(const APosition, GravityUp: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; out AboveHeight: Single; out AboveGround: PTriangle): boolean; override;

This item has no description.

Protected function LocalMoveCollision( const OldPos, ProposedNewPos: TVector3; out NewPos: TVector3; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;

This item has no description.

Protected function LocalMoveCollision( const OldPos, NewPos: TVector3; const IsRadius: boolean; const Radius: Single; const OldBox, NewBox: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;

This item has no description.

Protected function LocalSegmentCollision(const Pos1, Pos2: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; const ALineOfSight: boolean): boolean; override;

This item has no description.

Protected function LocalSphereCollision(const Pos: TVector3; const Radius: Single; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;

This item has no description.

Protected function LocalSphereCollision2D(const Pos: TVector2; const Radius: Single; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc; const Details: TCollisionDetails): boolean; override;

This item has no description.

Protected function LocalPointCollision2D(const Point: TVector2; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;

This item has no description.

Protected function LocalBoxCollision(const Box: TBox3D; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): boolean; override;

This item has no description.

Protected function LocalRayCollision(const RayOrigin, RayDirection: TVector3; const TrianglesToIgnoreFunc: TTriangleIgnoreFunc): TRayCollision; override;

This item has no description.

Protected procedure LocalRender(const Params: TRenderParams); override;

This item has no description. Showing description inherited from TCastleTransform.LocalRender.

Collect the things to be rendered now.

Override this method if you need to perform custom rendering, by direct OpenGL(ES) calls. Never call this method yourself – the rendering of TCastleViewport will call it when needed.

Warning: It is an advanced topic how to make such rendering work, and make it work in a cross-platform way. You will need to understand how OpenGL(ES) works, and you will need to account for how the engine renders things too, to not conflict with the engine – e.g. you will have to use RenderContext for some things. If you're not ready for this, then you're better off not overriding this method, instead just rely on the engine built-in rendering, done by TCastleScene and other components.

This method gets parameters (Params) including a full transformation of this scene.

In return, it should add the things to be rendered in this frame using Params.AddRenderEvent.

Internally: TCastleScene also adds X3D shapes to be rendered to TRenderParams.Collector. But you should not need to deal with TRenderParams.Collector in your own code.

TODO: The names LocalRender, TRenderParams are now confusing. LocalRender is not a method where one should "render" anymore. It's a "collection phase". Think of it as "TCastleTranssform.CollectThingsToRender(const Params: ...)" and bear with us as we figure out a non-confusing naming around this.

Protected procedure Loaded; override;

This item has no description.

Protected procedure InternalMoveShapeAssociations( const OldNode, NewNode: TX3DNode; const ContainingShapes: TObject); override;

Called before changing one node into another, when old node may have beeen associated with a shape using TShapeTree.AssociateNode.

Both OldNode and NewNode may be Nil, this method can handle it.

It is allowed to call this even when OldNode = NewNode, which means that nothing really changes.

Protected function LocalBoundingBoxNoChildren: TBox3D;

Local (not affected by our Translation, Rotation, Scale) bounding box. Takes into account loaded scene (in Url) but not children TCastleTransform bounding volumes.

Public constructor Create(AOwner: TComponent); override;

This item has no description.

Public function PropertySections(const PropertyName: String): TPropertySections; override;

This item has no description. Showing description inherited from TCastleComponent.PropertySections.

Section where to show property in the editor.

Public procedure CustomSerialization(const SerializationProcess: TSerializationProcess); override;

This item has no description. Showing description inherited from TCastleComponent.CustomSerialization.

Override this method to call various methods of SerializationProcess, which in turn allows to serialize/deserialize things that are not published. This allows to serialize/deserialize with more freedom, e.g. to serialize/deserialize some private field.

Public procedure Load(const ARootNode: TX3DRootNode; const AOwnsRootNode: boolean; const AOptions: TSceneLoadOptions = []); overload;

Load the given model. This replaces RootNode with new value.

Note that you should never load the same TX3DRootNode instance into multiple TCastleScene instances.

// DON'T DO THIS!
Node := LoadNode(Url);
Scene1 := TCastleScene.Create(Application);
Scene1.Load(Node, false);
Scene2 := TCastleScene.Create(Application);
Scene2.Load(Node, false);

If you need to load the same model into multiple scenes, it is best to use the Clone method:

SceneTemplate := TCastleScene.Create(Application);
SceneTemplate.Load(Url);
Scene1 := SceneTemplate.Clone(Application);
Scene2 := SceneTemplate.Clone(Application);

Using the Clone makes a copy of the underlying X3D graph, so it is roughly like doing:

Node := LoadNode(Url);
Scene1 := TCastleScene.Create(Application);
Scene1.Load(Node.DeepCopy as TX3DRootNode, false);
Scene2 := TCastleScene.Create(Application);
Scene2.Load(Node.DeepCopy as TX3DRootNode, false);

Note that sometimes you don't need to create multiple scenes to show the same model many times. You can simply insert the same TCastleScene instance multiple times to TCastleViewport.Items (TCastleRootTransform). See the manual: https://castle-engine.io/manual_scene.php#section_many_instances

Parameters
ARootNode
The model to load. This will become a new value of our RootNode property.
AOwnsRootNode
Should the scene take care of freeing this root node when it is no longer used. If False, you are expected to free it yourself, but only after the scene using it was freed.
AResetTime
If True then we will reset time at loading (using ResetTimeAtLoad), changing the Time. This is usually what you want when you load a new world.
Public procedure Load(const AUrl: String; const AOptions: TSceneLoadOptions = []); overload;

Load the 3D model from given URL.

We load a number of 3D model formats (X3D, VRML, Collada, Wavefront OBJ...) and some 2D model formats (Spine JSON). See https://castle-engine.io/creating_data_model_formats.php for the complete list.

URL is downloaded using the CastleDownload unit, so it supports files, http resources and more. See https://castle-engine.io/manual_network.php about supported URL schemes. If you all you care about is loading normal files, then just pass a normal filename (absolute or relative to the current directory) as the URL parameter.

Public procedure Load(const AUrl: String; const AllowStdIn: boolean; const AResetTime: boolean = true); overload; deprecated 'use Load with (AUrl: String, AOptions: TSceneLoadOptions) parameters. AllowStdIn is not implemented anymore.';

Warning: this symbol is deprecated: use Load with (AUrl: String, AOptions: TSceneLoadOptions) parameters. AllowStdIn is not implemented anymore.

This item has no description.

Public procedure Save(const AUrl: String);

Save the current 3D model (X3D nodes graph) to the given file (URL).

The X3D encoding is automatically guessed from the URL extension. By default it is XML, and we suggest using the .x3d extension. If you specify an extension indicating "classic encoding", we will use such encoding (use .x3dv for X3D in classic encoding, or .wrl for older VRML content).

The file may also be automatically gzip compressed if extension indicates it. Use .x3d.gz to indicated XML compressed with gzip, or use .x3dv.gz or .wrl.gz to indicate classic encoding compressed with gzip.

The Url property is also changed.

Public procedure BeforeDestruction; override;

This item has no description.

Public destructor Destroy; override;

This item has no description.

Public function ShapesActiveCount: Cardinal;

Number of active shapes in the Shapes tree. This is equivalent to Shapes.ShapesCount(true), except that this is faster (it's cached and reused in this instance, and automatically invalidated only when needed).

Public function ShapesActiveVisibleCount: Cardinal;

Number of active and visible (TShape.Visible) shapes in the Shapes tree.

See also
ShapesActiveCount
Number of active shapes in the Shapes tree.
Public function VerticesCount: Cardinal; overload;

Calculate the number of triangls and vertexes of all shapa states. For detailed specification of what these functions do see appropriate TAbstractGeometryNode methods. Here, we just sum their results for all shapes.

Public function TrianglesCount: Cardinal; overload;

This item has no description.

Public function ViewpointsCount: Cardinal;

Number of viewpoints (named camera position+orientation). -1 if none.

Public function GetViewpointNode(const Idx: integer): TAbstractViewpointNode;

Viewpoint node (TAbstractViewpointNode) from an index between 0 and ViewpointsCount.

Public function GetViewpointName(const Idx: integer): String;

Good name to show user for a viewpoint, defined by an index between 0 and ViewpointsCount.

Public procedure MoveToViewpoint(const Idx: integer; const Animated: boolean = true);

Move current camera of the enclosing TCastleViewport to reflect the given viewpoint. This changes the camera position and orientation.

In X3D terminology, the new viewpoint node becomes "bound" (current). Switching the viewpoint that is already bound (current) also has an effect, it will change the camera position and orientation to reflect the viewpoint defined position / orientation.

Public procedure AddViewpointFromNavigation(const Navigation: TCastleNavigation; const AName: String);

Add to scene nodes (graph in RootNode) new viewpoint node reflecting current camera and navigation settings. The new viewpoint increases ViewpointsCount, so it's also immediately available for switching to it.

Public procedure BeforeNodesFree(const InternalChangedAll: boolean = false); override;

Release all internal associations with your VRML/X3D nodes. In particular, this will release OpenGL resources connected to your nodes. You should always call this before you (may) free some nodes in RootNode.

You have to call ChangedAll or Load at sometime after BeforeNodesFree, and before you try actual rendering, events etc. Otherwise some stuff may not get recalculated.

The InternalChangedAll parameter is for internal use. It is set to True when ChangedAll calls this method at the beginning of it's work, and means that nothing is freed, and we only require necessary cleanup at the beginning of ChangedAll. This way ChangedAll (when it wasn't preceeded by explicit BeforeNodesFree(false)) produces events from stacks CheckForDeletedNodes.

Public procedure NodeFreeRemovingFromAllParents(Node: TX3DNode);

Call Node.FreeRemovingFromAllParents, making sure that changes to our VRML/X3D node graph are allowed. This makes sure we call BeforeNodesFree befor freeing, and ChangedAll afterwards.

This avoids a common pitfall with relying on TShape or such existence between BeforeNodesFree and ChangedAll. BeforeNodesFree may free all our TShape instances, so if you want to free TX3DNode from our graph — you typically want to get this TX3DNode instance *before* calling BeforeNodesFree. Using this method to free the node ensures this.

Public procedure RemoveShape(Shape: TShape);

Remove the shape node from the scene. In case of VRML 1.0 / Inventor, when the Shape doesn't have a node, we remove the geometry node.

Public procedure ChangedAll(const OnlyAdditions: Boolean = false); override;

Notify scene that potentially everything changed in the VRML/X3D graph. This includes adding/removal of some nodes within RootNode graph and changing their fields' values. (Before freeing the nodes, remember to also call BeforeNodesFree earlier.)

You usually never need to call this method explicitly. It's called by engine when necesssary. However, you need to call it yourself if you change the X3D graph directly through nodes' FdXxx fields, and you don't want to call for some reason FdXxx.Changed.

ChangedAll causes recalculation of all things dependent on RootNode, so it's very costly to call this. Avoid calling this. When you change a simple field, like by FdXxx.Value := ..., you should rather call FdXxx.Changed, and it may do something much faster than rebuilding the scene.

Descendant implementors notes: ChangedAll is virtual, when overriding it remember that it's called by constructor of this class, so you can put a lot of your initialization there (instead of in the constructor).

ChangedAll calls BeforeNodesFree(true) first, for safety (and TGLShape actually depends on it, see implementation comments).

Public procedure DoGeometryChanged(const Change: TGeometryChange; LocalGeometryShape: TShape); virtual;

Called when geometry changed. Does OnGeometryChanged, and does some other stuff necessary (mark some octrees for regenerating at next access).

This is public only for overloading (and for internal TShape access). Do not call this yourself — TShape and TCastleSceneCore implementations know when and how to call this.

Public procedure DoViewpointsChanged;

Call OnViewpointsChanged, if assigned.

Public procedure DoBoundViewpointVectorsChanged;

Call OnBoundViewpointVectorsChanged, if assigned.

Public procedure DoBoundNavigationInfoFieldsChanged; virtual;

This item has no description.

Public procedure ScheduleChangedAll(const OnlyAdditions: Boolean = false);

Mechanism to schedule ChangedAll calls.

Since these calls may be costly (traversing the hierarchy), and their results are often not immediately needed by TCastleSceneCore or TX3DNode hierarchy, it's sometimes not desirable to call them immediately when geometry changed / all changed.

So you can use ScheduleChangedAll instead of ChangedAll. All event handlers within TCastleSceneCore already do this.

When you're within Begin/EndChangesSchedule, then ScheduleChangedAll just sets an internal flag and actual ChangedAll will be done only once at EndChangesSchedule. Otherwise (when not within Begin/EndChangesSchedule), ScheduleChangedAll will immediately call ChangedAll.

Public procedure BeginChangesSchedule;

This item has no description.

Public procedure EndChangesSchedule;

This item has no description.

Public function Info( ATriangleVerticesCounts, ABoundingBox: boolean; AManifoldAndBorderEdges: boolean): String; deprecated 'do not use this, better to construct a summary string yourself';

Warning: this symbol is deprecated: do not use this, better to construct a summary string yourself

Returns short information about the scene. This consists of a few lines, separated by newlines. Last line also ends with CastleUtils.NL.

Public function InfoTriangleVerticesCounts: String; deprecated 'better to construct a string yourself, use TrianglesCount, VerticesCount';

Warning: this symbol is deprecated: better to construct a string yourself, use TrianglesCount, VerticesCount

This item has no description.

Public function InfoBoundingBox: String; deprecated 'better to construct a string yourself, use BoundingBox.ToString';

Warning: this symbol is deprecated: better to construct a string yourself, use BoundingBox.ToString

This item has no description.

Public function InfoManifoldAndBorderEdges: String; deprecated 'better to construct a string yourself, use EdgesCount';

Warning: this symbol is deprecated: better to construct a string yourself, use EdgesCount

This item has no description.

Public procedure EdgesCount(out ManifoldEdges, BorderEdges: Cardinal);

Edges count in the scene, for information purposes.

Public function InternalOctreeRendering: TShapeOctree;

A spatial structure containing all visible shapes. Set PreciseCollisions to True to have this non-nil.

This is used internally for "frustum culling", it will be automatically used by TCastleScene rendering to speed it up. You should not need to use this directly.

This octree will be automatically updated on dynamic scenes (when e.g. animation moves some shape by changing it's transformation).

Note that when VRML/X3D scene contains Collision nodes, this octree contains the visible (not necessarily collidable) objects.

Public function InternalOctreeDynamicCollisions: TShapeOctree;

A spatial structure containing all collidable shapes (and then collidable triangles for a specifc shape). Set PreciseCollisions to True to have this non-nil.

This is actually a hierarchy of octrees: scene is partitioned first into Shapes (each instance of VRML/X3D geometry node), and then each Shape has an octree of triangles inside. Thanks to this, merely transforming some Shape means that only one item needs to be moved in the top-level shape tree. So this is the most important structure for collision detection on dynamic scenes.

This octree is useful for all kinds of collision detection. This is automatically used by the XxxCollision methods in this class.

You should not usually use this directly. Instead use TCastleViewport and then use Viewport.Items.WorldXxxCollision methods like Viewport.Items.WorldRay or Viewport.Items.WorldSphereCollision.

Note that when VRML/X3D scene contains Collision nodes, this octree contains the collidable (not necessarily rendered) objects.

This is kept up-to-date automatically when the scene changes. TODO: Temporarily, this is updated simply by rebuilding.

Public function InternalOctreeCollisions: TBaseTrianglesOctree;

Octree for collisions.

This is equal to InternalOctreeDynamicCollisions now as we don't have other ways to check for collisions. Set PreciseCollisions to True to have this non-nil.

You should not usually use this directly. Instead use TCastleViewport and then use Viewport.Items.WorldXxxCollision methods like Viewport.Items.WorldRay or Viewport.Items.WorldSphereCollision.

Public function UseInternalOctreeCollisions: boolean;

This item has no description.

Public function GetViewpoint( out ProjectionType: TProjectionType; out CamPos, CamDir, CamUp, GravityUp: TVector3; const ViewpointDescription: String = ''): TAbstractViewpointNode;

Viewpoint defined in the 3D file (or some default camera settings if no viewpoint is found).

GetViewpoint seeks for VRML/X3D nodes like Viewpoint, OrthoViewpoint (actually, any X3DViewpointNode) and VRML 1.0 PerspectiveCamera and OrthographicCamera. GetPerspectiveViewpoint seeks only for perspective viewpoints.

If ViewpointDescription = '', they return the first found viewpoint node. Otherwise, they look for X3DViewpointNode with description field mathing given string.

If camera properties were found in some node, it returns this node. Otherwise it returns nil. This way you can optionally extract some additional info from used viewpoint node, or do something special if default values were used. Often you will just ignore result of this function — after all, the most important feature of this function is that you don't have to care about details of dealing with camera node.

Returned CamDir and CamUp and GravityUp are always normalized — reasons the same as for TAbstractViewpointNode.GetView.

Public function GetPerspectiveViewpoint( out CamPos, CamDir, CamUp, GravityUp: TVector3; const ViewpointDescription: String = ''): TAbstractViewpointNode;

This item has no description.

Public procedure FreeResources(Resources: TSceneFreeResources); virtual;

Frees some scene resources, to conserve memory. See TSceneFreeResources documentation.

Public procedure UnregisterScene(Node: TX3DNode); deprecated 'use Node.UnregisterScene';

Warning: this symbol is deprecated: use Node.UnregisterScene

Recursively unset node's TX3DNode.Scene.

Public function Press(const Event: TInputPressRelease): boolean; override;

Scene processes X3D key sensor nodes here, https://castle-engine.io/x3d_implementation_keydevicesensor.php . Remember to set ListenPressRelease to process the key sensor nodes.

Public function Release(const Event: TInputPressRelease): boolean; override;

This item has no description.

Public function PointingDevicePress(const Pick: TRayCollisionNode; const Distance: Single): Boolean; override;

This item has no description. Showing description inherited from TCastleTransform.PointingDevicePress.

Pointing device (mouse or touch) events, you can override these to handle pointing device events. These methods are automatically called by the TCastleViewport. They are exposed here only to allow overriding them. Return True if you handled the event.

  • PointingDevicePress signals that the picking button (usually, left mouse button) was pressed.

    Note that the exact key or mouse responsible for this is configurable in our engine by Input_Interact. By default it's the left mouse button, as is usual for VRML/X3D browsers. But it can be configured to be other mouse button or a key, for example most 3D games use "e" key to interact.

  • PointingDeviceRelease signals that the picking button is released.

    An extra parameter CancelAction indicates whether this pointing device "press and release" sequence may be considered a "click". When CancelAction = True, then you should not make a "click" event (e.g. TouchSensor should not send touchTime event etc.).

  • PointingDeviceMove signals that pointer moves over this object.

They receive Pick information (TRayCollisionNode) about what exactly is hit by the 3D ray corresponding to the current pointing device position. It contains the detailed information about the point, triangle and ray (all in local coordinate system of this TCastleTransform) that are indicated by the pointing device. TRayCollisionNode.Triangle is Nil when it was not possible to determine, and TRayCollisionNode.Point is undefined in this case.

They also receive Distance to the collision point, in world coordinates. See TRayCollision.Distance. The Distance may be MaxSingle when it was not possible to determine.

There is a concept of a TCastleTransform that is currently "capturing" the pointing device events. Once TCastleTransform handles TCastleTransform.PointingDevicePress (returns True for it), it captures the following PointingDeviceMove and PointingDeviceRelease events, regardless if ray still hits this TCastleTransform instance. The "capturing" instance of TCastleTransform is informed first about pointing device move/release.

After the "capturing" instance, every pointing device event (press, release or move) is send to the leaf in TCastleTransform hierarchy (usually a TCastleScene) that is under the mouse/touch position. If the event is not handled, it is passed to other objects under the mouse/touch position.

The PointingDeviceMove event is also always passed to TCastleRootTransform.MainScene at the end (if it wasn't already the "capturing" transform, or under the mouse/touch position). This way TCastleRootTransform.MainScene is always informed about pointing device movement.

These methods are called only if the object Exists. There's no need to check this condition inside the method implementation.

Public function PointingDeviceRelease(const Pick: TRayCollisionNode; const Distance: Single; const CancelAction: Boolean): Boolean; override;

This item has no description.

Public function PointingDeviceMove(const Pick: TRayCollisionNode; const Distance: Single): boolean; override;

Called when pointing device moves. This may generate the continuously-generated events like hitPoint_changed, also it updates PointingDeviceOverItem and PointingDeviceOverPoint, thus producing isOver and such events.

For pointing device sensors to work, you must have collision structures set up by setting PreciseCollisions to True.

Public function PointingDeviceSensors: TPointingDeviceSensorList;

Pointing-device sensors over which the pointing device is. This is just a shortcut for PointingDeviceOverItemˆ.State.PointingDeviceSensors, returning Nil if PointingDeviceOverItem = Nil.

Public procedure PointingDeviceClear;

Clear any references to PTriangle passed previously in TRayCollisionNode argument to PointingDevicePress, PointingDeviceRelease, PointingDeviceMove. This is internally used in case some of past seen PTriangle may become invalid, so any memory about them should be cleared.

This doesn't cause any X3D events (contrary to e.g. calling PointingDeviceMove with Pick.Triangle = Nil).

This method clears any references to saved PTriangle and PointingDeviceActiveSensors. Note that this still calls DoPointingDeviceSensorsChange (making OnPointingDeviceSensorsChange event), if PointingDeviceActiveSensors / PointingDeviceSensors possibly changed.

Public function LocalBoundingBox: TBox3D; override;

This item has no description. Showing description inherited from TCastleTransform.LocalBoundingBox.

Bounding box of this object, ignoring the transformations of this scene and parents.

Public procedure Update(const SecondsPassed: Single; var RemoveMe: TRemoveType); override;

This item has no description. Showing description inherited from TCastleTransform.Update.

Continuously occuring event, for various tasks.

Executed only on instances that have Exists (no need to check this in overridden Update implementation).

Public procedure SetTime(const NewValue: TFloatTime);

Change current scene time, setting Time. It is crucial that you call this continuously to have some VRML/X3D time-dependent features working, like TimeSensor and MovieTexture. See Time for details what is affected by this.

This is automatically taken care of if you added this scene to TCastleWindow.Controls or TCastleControl.Controls. Then our Update takes care of doing the job, according to TimePlaying and TimePlayingSpeed.

This causes time to be passed to appropriate time-dependent nodes, events will be called etc.

SetTime and IncreaseTime do exactly the same, the difference is only that for IncreaseTime you specify increase in the time (that is, NewTime = Time + TimeIncrease). Use whichever version is more handy.

Following X3D specification, time should only grow. So NewValue should be > Time (or TimeIncrease > 0). Otherwise we ignore this call. For resetting the time (when you don't necessarily want to grow Time) see ResetTime.

If a change of Time will produce some visible change in the VRML/X3D model (for example, MovieTexture will change, or TimeSensor change will be routed by interpolator to coordinates of some visible node) it will be reported by usual method, that is VisibleChangeHere.

Public procedure IncreaseTime(const TimeIncrease: TFloatTime);

This item has no description.

Public procedure IncreaseTimeTick; deprecated 'it should not be necessary to call this, ever; using TX3DEvent.Send(...) or TX3DEvent.Send(..., NextEventTime) will automatically behave Ok.';

Warning: this symbol is deprecated: it should not be necessary to call this, ever; using TX3DEvent.Send(...) or TX3DEvent.Send(..., NextEventTime) will automatically behave Ok.

This item has no description.

Public function Time: TFloatTime; override;

The time within this scene, in seconds. Increasing this "drives" the animations (by increasing time of time-dependent nodes like X3D TimeSensor, which in turn drive the rest of the animation).

You can use SetTime or IncreaseTime to move time forward manually. But usually there's no need for it: our Update method takes care of it automatically, you only need to place the scene inside TCastleViewport.Items.

You can start/stop time progress by TimePlaying and scale it by TimePlayingSpeed. These properties affect how the time is updated by the Update method (so if you use SetTime or IncreaseTime methods, you're working around these properties).

Default time value is 0.0 (zero). However it will be reset at load to a current time (seconds since Unix epoch — that's what X3D standard says to use, although you can change it by KambiNavigationInfo.timeOriginAtLoad, see https://castle-engine.io/x3d_implementation_navigation_extensions.php#section_ext_time_origin_at_load ). You can perform this "time reset" yourself by ResetTimeAtLoad or ResetTime.

Public function NextEventTime: TX3DTime; override;

Time that should be used for next event. You usually don't need to call this directly, this is automatically used by TX3DEvent.Send when you don't specify explicit time.

Public procedure ResetTime(const NewValue: TFloatTime);

Set Time to arbitrary value.

You should only use this when you loaded new VRML/X3D model.

Unlike SetTime and IncreaseTime, this doesn't require that Time grows. It still does some time-dependent events work, although some time-dependent nodes may be just unconditionally reset by this to starting value (as they keep local time, and so require TimeIncrease notion, without it we can only reset them).

Public procedure ResetTimeAtLoad;

Set Time to suitable initial value after loading a world.

This honours VRML/X3D specification about VRML/X3D time origin, and our extension [https://castle-engine.io/x3d_extensions.php#section_ext_time_origin_at_load].

Public function GetBackgroundStack: TX3DBindableStackBasic; override;

This item has no description.

Public function GetFogStack: TX3DBindableStackBasic; override;

This item has no description.

Public function GetNavigationInfoStack: TX3DBindableStackBasic; override;

This item has no description.

Public function GetViewpointStack: TX3DBindableStackBasic; override;

This item has no description.

Public procedure RegisterCompiledScript(const HandlerName: String; Handler: TCompiledScriptHandler);

Register compiled script handler, for VRML/X3D Script node with "compiled:" protocol. See [https://castle-engine.io/x3d_extensions.php#section_ext_script_compiled].

Public procedure InternalUpdateNavigation( const Navigation: TCastleNavigation);

Update TCastleNavigation properties based on currently bound TNavigationInfoNode.

Bound TNavigationInfoNode is taken from NavigationInfoStack.Top. If no such node is bound (NavigationInfoStack.Top is Nil) then we behave as if TNavigationInfoNode with all fields at default was active.

Note that, since some fields are only in some descendants (e.g. MoveSpeed is only at TCastleWalkNavigation) then some TNavigationInfoNode settings are just not transferred to all Navigation instances like TCastleExamineNavigation

Public procedure CameraTransition(const Camera: TCastleCamera; const APosition, ADirection, AUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';

Warning: this symbol is deprecated: use Camera.AnimateTo(APosition, ADirection, AUp)

Make Camera go to the view given by (world coordinates) APosition, ADirection, AUp.

Honours current NavigationInfo.transitionType and transitionTime. If transitionType indicates instanteneous transition, then jumps by simple Camera.SetWorldView(APosition, ADirection, AUp). Otherwise makes a smooth animation into new values by Camera.AnimateTo(APosition, ADirection, AUp, TransitionTime).

Will generate NavigationInfo.transitionComplete when transition ends.

Public procedure CameraTransition(const Camera: TCastleCamera; const APosition, ADirection, AUp, GravityUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';

Warning: this symbol is deprecated: use Camera.AnimateTo(APosition, ADirection, AUp)

This item has no description.

Public procedure CameraTransition(const Navigation: TCastleNavigation; const APosition, ADirection, AUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';

Warning: this symbol is deprecated: use Camera.AnimateTo(APosition, ADirection, AUp)

This item has no description.

Public procedure CameraTransition(const Navigation: TCastleNavigation; const APosition, ADirection, AUp, GravityUp: TVector3); overload; deprecated 'use Camera.AnimateTo(APosition, ADirection, AUp)';

Warning: this symbol is deprecated: use Camera.AnimateTo(APosition, ADirection, AUp)

This item has no description.

Public function CustomHeadlight: TAbstractLightNode;

Light node that should be used for headlight, or Nil if default directional headlight is suitable.

This never returns Nil. It's not concerned whether the headlight should actually be used — for this, see HeadlightOn.

Public procedure PrepareResources(const Options: TPrepareResourcesOptions; const Params: TPrepareParams); override;

This item has no description. Showing description inherited from TCastleTransform.PrepareResources.

Prepare resources, making various methods (like rendering and such) to execute fast.

It is usually simpler to call TCastleViewport.PrepareResources then this method. Calling Viewport.PrepareResources(MyScene) will automatically call MyScene.PrepareResources(...) underneath, with proper parameters.

It is best to call this when the rendering context is initailized, e.g. at Application.OnInitialize or later. Calling this method before the rendering context is initialized (e.g. from initializaton section of some unit) will have to skip some preparations, thus reducing the effectiveness of this method. But it is allowed to call this at any time, regardless of the context being initialized, just like e.g. TCastleContainer.LoadSettings (which may call this, to warmup cache).

This makes sure that appropriate methods execute as fast as possible. It's never required to call this method — everything will be prepared "as needed" anyway. But if you allow everything to be prepared "as needed", then e.g. the first Render call may take a long time because it may have to prepare resources that will be reused in next Render calls. This may make your program seem slow at the beginning (when rendering resources are being prepared, so at the first frame, or a couple of first animation frames). To avoid this, call this method, showing the user something like "now we're preparing the resources — please wait".

TODO: It is not possible to call this now without TPrepareParams, and to get params you need to access deprecated TCastleViewport.PrepareParams. We advise to call TCastleViewport.PrepareResources instead. We'd like to get rid of TPrepareParams eventually.

Public function Caption: String;

Nice scene caption. Uses the "title" of WorldInfo node inside the VRML/X3D scene. If there is no WorldInfo node (or it has empty title) then result is based on loaded URL.

Public function Node(const NodeClass: TX3DNodeClass; const NodeName: String; const Options: TFindNodeOptions = []): TX3DNode; overload;

Find a named X3D node in the current node graph.

By default it searches both active and inactive graph parts. Add fnOnlyActive to search only in active parts.

It searches only within nodes of given type (NodeClass). Specifying NodeClass helps to make search unambiguous (as name clashes are possible, some authoring tools may write models with duplicate names for materials, meshes etc. and both glTF and X3D allow it). This allows to safely write code like:

MyMaterial := Scene.Node(TNodePhysicalMaterial, 'MyMaterial') as TNodePhysicalMaterial;

TODO: An even better version, "MyMaterial := Scene.Node<TNodePhysicalMaterial>('MyMaterial')", may be available in the future, if FPC support for generic methods will improve. Define GENERIC_METHODS to try it out now, but heed the warnings in castleconf.inc .

Exceptions raised
EX3DNotFound
When node is not found. Unless fnNilOnMissing in Options, then it returns Nil on missing node, and EX3DNotFound is never raised.
Public function Node(const NodeName: String): TX3DNode; overload;

This item has no description.

Public function Field(const NodeName, FieldName: String): TX3DField; overload;

Find a named field within an X3D node in the current node graph.

Like Node, this searches all nodes (in active or not) graph parts.

Exceptions raised
EX3DNotFound
If given node or field could not be found.
Public function Event(const NodeName, EventName: String): TX3DEvent; overload;

Find a named event within an X3D node in the current node graph.

Like Node, this searches all nodes (in active or not) graph parts.

Exceptions raised
EX3DNotFound
If given node or event could not be found.
Public function HasAnimation(const AnimationName: String): boolean;

Does named animation with given name exist.

See also
AnimationsList
List the names of available animations in current scene.
PlayAnimation
Public function AnimationTimeSensor(const AnimationName: String): TTimeSensorNode; overload;

TimeSensor of this animation. Nil if this name not found.

Public function AnimationTimeSensor(const Index: Integer): TTimeSensorNode; overload;

TimeSensor of this animation, by animation index (index on AnimationsList). Nil if this index not found.

Public function ForceAnimationPose(const AnimationName: String; const TimeInAnimation: TFloatTime; const Loop: boolean; const Forward: boolean = true): boolean; overload;

Forcefully, immediately, set pose from given animation, with given time in animation.

This avoids the normal passage of time in X3D scenes, it ignores the ProcessEvents and AnimateOnlyWhenVisible properties, it ignores the current animation set by PlayAnimation, and forces the current time on TimeSensors by TTimeSensorNode.FakeTime.

Public function PlayAnimation(const Parameters: TPlayAnimationParameters): boolean; overload;

Play an animation specified by name.

You can specify the animation name, whether it should loop, and whether to play it forward or backward using parameters to this method.

Or you can specify even more parameters using TPlayAnimationParameters instance. TPlayAnimationParameters can additionally specify a stop notification, initial time and more. It is OK to create a short-lived TPlayAnimationParameters instance and destroy it right after calling this method. This method doesn't store the TPlayAnimationParameters instance reference.

To get the list of available animations, see AnimationsList.

This is one of the simplest way to play animations using Castle Game Engine. Alternative (that calls PlayAnimation under the hood) is to set AutoAnimation. See https://castle-engine.io/viewport_3d#_play_animation .

Playing an already-playing animation is guaranteed to restart it from the beginning (more precisely: from TPlayAnimationParameters.InitialTime, if you pass TPlayAnimationParameters).

If the given animation name exists, then we stop previously playing animation (if any), calling it's stop notification (see TPlayAnimationParameters.StopNotification), start playing the new animation, and return True. If the animation name does not exist then we return False, make a warning and the current animation is unchanged.

The change from previous to new animation can be smooth (using animation cross-fading) if you use TPlayAnimationParameters with TPlayAnimationParameters.TransitionDuration or if you set DefaultAnimationTransition to something non-zero.

This automatically turns on ProcessEvents, if it wasn't turned on already. Processing events is necessary for playing animations.

More details about how this works:

  • Calling this method does not change the scene immediately. There may be a delay between calling PlayAnimation and actually changing the scene to reflect the state at the beginning of the indicated animation. This delay is usually 1 frame (that is, the scene is updated at the next Update call), but it may be larger if you use the optimization AnimateSkipTicks.

    This is often a desirable optimization. There's often no "rush" to visually change the animation right now, and doing it at the nearest Update call is acceptable. It also means that calling PlayAnimation multiple times before a single Update call is not expensive.

    If you really need to change the scene immediately (for example, because you don't want to show user the initial scene state), simply call ForceInitialAnimationPose right after PlayAnimation.

  • The animation is performed using X3D TTimeSensorNode.

    For example, TTimeSensorNode may instruct a TCoordinateInterpolatorNode to update the TIndexedFaceSetNode coordinates, and in effect the animation can deform a mesh. Or TTimeSensorNode may instruct a TPositionInterpolatorNode to update TTransformNode.Translation, and in effect the animation can move something. See https://castle-engine.io/x3d_implementation_interpolation.php for a thorough description how the animation works in X3D.

    This means that during the animation, the X3D nodes graph (within RootNode) is being changed.

    If you load a model from a castle-anim-frames or MD3 format, note that it is animated using a special "node interpolator". This also works using a special (internal) X3D node that switches which node is visible.

  • Starting an animation effectively cancels any effect from any previous animation. That is, even if the new animation doesn't modify some transformations, these transformations are not left "as is", instead they are reset to the default model state using ResetAnimationState. This is usually the desired effect, corresponding to how the animations should intuitively behave, e.g. if you have "walk" and "idle" animations.

    If you want to simultaneously play multiple animations or if you want to simultaneously modify scene by code (while playing some animation) then you can control each time sensor using TTimeSensorNode.Start and TTimeSensorNode.Stop. See also the example in examples/animations/simultaneous_animations_one_scene .

Public function PlayAnimation(const AnimationName: String; const Loop: boolean; const Forward: boolean = true): boolean; overload;

This item has no description.

Public procedure ForceInitialAnimationPose;

Force the model to look like the initial animation frame now.

Use this after calling PlayAnimation. Calling this is simply ignored if no PlayAnimation was called earlier, of if the model already looks following the animation requested by PlayAnimation.

If you don't use this method, there may be a 1-frame delay between calling PlayAnimation and actually updating the rendered scene look. If during that time a rendering will happen, the user will see a scene in previous pose (not in the first pose of animation you requested by PlayAnimation). To avoid this, simply call this method right after PlayAnimation.

This sets first animation frame, unless you used TPlayAnimationParameters.InitialTime <> 0.

Public function AnimationDuration(const AnimationName: String): TFloatTime;

Duration, in seconds, of the named animation (named animations are detected by AnimationsList method). For a looping animation, this is the duration of a single cycle. 0 if not found.

Public procedure StopAnimation(const DisableStopNotification: Boolean = false);

Stop the CurrentAnimation, started by last PlayAnimation call. Note that this leaves the model in a state in the middle of the last animation.

You can use ResetAnimationState to reset the state afterwards. Calling ForceInitialAnimationPose also will do it.

Note that it is not necessary to stop the previous animation before starting a new one (by PlayAnimation). PlayAnimation will automatically stop the previous animation. Moreover, PlayAnimation may do animation blending (cross-fade) between old and new animation (if you use TPlayAnimationParameters.TransitionDuration), which only works if you did not call StopAnimation.

When animation is stopped (by this or any other means), by default it's TPlayAnimationParameters.StopNotification is called. You can use DisableStopNotification to avoid it, which should be used only in exceptional situations.

Public procedure ResetAnimationState(const IgnoreAffectedBy: TTimeSensorNode = nil);

Reset all the fields affected by animations. See TimeSensor.detectAffectedFields documentation (https://castle-engine.io/x3d_implementation_time_extensions.php#section_detect_affected_fields) for details how these fields are detected, and when this is useful. By default this is enabled, for all TimeSensor nodes.

If IgnoreAffectedBy <> nil, the fields affected by the given TimeSensor may not be reset. This is an optimization useful in case this TimeSensor will modify the scene very soon, so resetting its affected fields is a waste of time. Do not depend on 100% that the fields affected by given TimeSensor are left untouched (in the current implementation, this field is ignored).

Public procedure FontChanged;

Force recalculating the text shapes when font changed. For now, we don't detect font changes (e.g. when TFontStyleNode.CustomFont changed) automatically. This calls TTextNode.FontChanged and TAsciiTextNode_1.FontChanged on all appropriate nodes.

Public function Clone(const AOwner: TComponent): TCastleSceneCore;

Create a scene with the same contents (X3D scene graph) as this one. The created scene has exactly the same class as this one (we use ClassType.Create to call a virtual constructor).

Note that this does not copy other scene attributes, like ProcessEvents or TCastleScene.RenderOptions. It only copies the scene graph (RootNode) and also sets target URL based on source URL (for logging purposes, e.g. TCastleProfilerTime use this URL to report loading and preparation times).

Public procedure InternalIncShapesHash;

This item has no description.

Public procedure ReloadUrl;

Load again the model from current URL. This makes sense to be used when underlying file on disk changed, and you want to reload it.

TODO: If the file is cached using Cache, then it will not reload the version in cache, so effectively it will not load new version from disk. This will be fixed at some point.

Properties

Protected property VisibilitySensors: TVisibilitySensors read FVisibilitySensors;

This item has no description.

Public property Shapes: TShapeTree read FShapes;

Tree of shapes in the scene, acting as a simplfied mirror of the X3D node graph. Contents of this tree are read-only from outside.

Public property OnGeometryChanged: TSceneGeometryChanged read FOnGeometryChanged write FOnGeometryChanged;

Notification when geometry changed. "Geometry changed" means that the positions of triangles changed. This is not send when merely things like material changed.

It is not guaranteed that octrees are already recalculated when this is called. (They may be recalculated only on-demand, that is when you actually access them.) However, it is guaranteed that shape's transformation (like TShape.State.Transform) are already updated.

Public property OnViewpointsChanged: TNotifyEvent read FOnViewpointsChanged write FOnViewpointsChanged;

Notification when the list of viewpoints in the scene possibly changed.

Note that this doesn't necessarily mean that the current, bound viewpoint changed (although it could). If you only want to get notified when currently bound viewpoint changes, then what you seek is rather ViewpointStack.OnBoundChanged.

Public property OnBoundViewpointVectorsChanged: TNotifyEvent read FOnBoundViewpointVectorsChanged write FOnBoundViewpointVectorsChanged;

Notification when the currently bound viewpoint's vectors (position/orientation and such) changed.

More precisely, this is called whenever values generated by ViewpointStack.Top.GetView changed.

It cannot be called when ViewpointStack.Top = Nil. Note that this also doesn't notify you about changes to currently bound viewpoint, for this you rather want to use ViewpointStack.OnBoundChanged. This is called only when currently bound viewpoint stays the same, only it's vectors change.

Public property OnBoundNavigationInfoFieldsChanged: TNotifyEvent read FOnBoundNavigationInfoFieldsChanged write FOnBoundNavigationInfoFieldsChanged;

This item has no description.

Public property RootNode: TX3DRootNode read FRootNode write SetRootNode;

Actual VRML/X3D graph defining this scene.

It is allowed to change contents of RootNode. Just make sure the scene is notified about these changes. The simplest option is to use simple properties of nodes (not the ones starting with Fd... prefix), when possible. Then everything is notified automatically. If you must use fields through the FdXxx properties, then assign them using TX3DField.Send, or (if you need to assign field values directly, like TSFVec3f.Value := ...) call TX3DField.Changed.

It is also allowed to change the value of RootNode and even to set RootNode to Nil. Changing RootNode allows you to load and unload whole new VRML/X3D graph (for example from some 3D file) whenever you want, and keep the same TCastleSceneCore instance (with the same rendering settings and such).

Public property OwnsRootNode: boolean read FOwnsRootNode write FOwnsRootNode default true; deprecated 'set OwnsRootNode only at loading, do not depend on this property';

Warning: this symbol is deprecated: set OwnsRootNode only at loading, do not depend on this property

If True, RootNode will be freed by destructor of this class.

Public property PointingDeviceOverItem: PTriangle read FPointingDeviceOverItem write FPointingDeviceOverItem;

Current item over which the pointing device is. Nil if over none. For example, you can investigate it's pointing device sensors (in PointingDeviceOverItemˆ.State.PointingDeviceSensors), although there's a shortcut for just this in PointingDeviceSensors. You can change this by PointingDeviceMove and PointingDeviceClear.

Public property PointingDeviceOverPoint: TVector3 read FPointingDeviceOverPoint write FPointingDeviceOverPoint;

Current 3D point under the pointing device. Only meaningful when PointingDeviceOverItem <> nil, otherwise undefined.

Public property PointingDeviceActiveSensors: TX3DNodeList read FPointingDeviceActiveSensors;

Currently active pointing-device sensors. Only TAbstractPointingDeviceSensorNode instances. Always empty when PointingDeviceActive = False. Read-only from outside of this class.

Note that sensor specified here doesn't have to be one of the sensors of PointingDeviceOverItem. When some sensor is activated, it grabs further events until it's deactivated (e.g. when you set PointingDeviceActive := false, which means that user released mouse button). This means that when user moves the mouse while given sensors are active, he can move mouse over other items, even the ones where the active sensors aren't listed — but the sensors remain active.

Public property PointingDeviceActive: boolean read FPointingDeviceActive default false;

Is pointing device currently active (for example, mouse button is pressed down).

Public property OnPointingDeviceSensorsChange: TNotifyEvent read FOnPointingDeviceSensorsChange write FOnPointingDeviceSensorsChange;

Event called PointingDeviceSensors or PointingDeviceActiveSensors lists (possibly) changed.

Public property TimeAtLoad: TFloatTime read FTimeAtLoad;

Initial world time, set by the last ResetTimeAtLoad call.

Public property BackgroundStack: TBackgroundStack read FBackgroundStack;

Stack of background nodes. The node at the top is the current background. All nodes on this stack must descend from TAbstractBackgroundNode class.

Public property FogStack: TFogStack read FFogStack;

Stack of fog nodes. The node at the top is the current fog. All nodes on this stack must descend from TFogNode class.

Public property NavigationInfoStack: TNavigationInfoStack read FNavigationInfoStack;

Stack of NavigatinInfo nodes. The node at the top is the current NavigatinInfo. All nodes on this stack must descend from TNavigationInfoNode class.

Public property ViewpointStack: TViewpointStack read FViewpointStack;

Stack of viewpoint nodes. The node at the top is the current Viewpoint. All nodes on this stack must descend from TAbstractViewpointNode. Note that this includes also VRML 1.0/Inventor nodes.

Public property CompiledScriptHandlers: TCompiledScriptHandlerInfoList read FCompiledScriptHandlers;

List of handlers for VRML/X3D Script node with "compiled:" protocol. This is read-only, change this only by RegisterCompiledScript.

Public property HeadlightOn: boolean read FHeadlightOn write SetHeadlightOn;

Should we use headlight for this scene. Controls if containing TCastleViewport will use a headlight, if this is the main scene.

When you load a new model, this is always updated based on this model's NavigationInfo.headlight. (If no NavigationInfo node, then default is to use the headlight.) When you bind a new NavigationInfo node, this is also updated to follow NavigationInfo.headlight.

You can change the value of this property. If we have a NavigationInfo node, then NavigationInfo.headlight field will be always updated to correspond to this value. (It will be even updated using events mechanism if ProcessEvents, so scripts inside the VRML/X3D "know" when you turn on/off the headlight and may react to it, e.g. spawn a zombie monster when you turn on the flashlight.)

Public property OnHeadlightOnChanged: TNotifyEvent read FOnHeadlightOnChanged write FOnHeadlightOnChanged;

This item has no description.

Public property InternalGlobalLights: TLightInstancesList read FGlobalLights;

Global lights of this scene. Read-only. Useful to shine these lights on other scenes, if TCastleScene.CastGlobalLights.

Public property AnimationsList: TStrings read FAnimationsList;

List the names of available animations in current scene. Animations are detected looking for TimeSensor nodes. See https://castle-engine.io/x3d_implementation_interpolation.php for an overview how nodes are used to create animations.

Note that if you set AnimationPrefix property, we additionally filter TimeSensor nodes to show only the names starting with given prefix. In this case, not all TTimeSensorNode are reflected in this list.

You can get the corresponding TTimeSensorNode by AnimationTimeSensor. Note that the same TTimeSensorNode may occur multiple times on this list, in case X3D IMPORT mechanism was used to rename the imported animation.

The resulting TStringList instance is owned by this object, do not free it.

Note that the list of animations may change if you rebuild the underlying X3D nodes graph, for example if you start to delete / add some TimeSensor nodes.

Public property AnimationPrefix: String read FAnimationPrefix write FAnimationPrefix; deprecated 'this property did not prove to be of much use; report if you need it, otherwise it may be removed one day';

Warning: this symbol is deprecated: this property did not prove to be of much use; report if you need it, otherwise it may be removed one day

The prefix of an X3D TimeSensor node name to treat it as a "named animation". Named animation are used by methods AnimationsList, PlayAnimation, and AnimationDuration, HasAnimation. By default this is empty, which means we consider all TimeSensor nodes a "named animation".

You can set this to something like 'Anim_' or 'Animation_' or whatever your 3D export software produces. Only the TimeSensor nodes with names starting with this prefix will be available on AnimationsList, and this prefix will be stripped from the names you use with methods like PlayAnimation.

Public property CurrentAnimation: TTimeSensorNode read FCurrentAnimation;

Currently played animation by PlayAnimation, or Nil.

Note that, in a general case, you can have multiple active animations (multiple TimeSensor X3D nodes may be active) at the same time. Calling TTimeSensorNode.Start directly on multiple nodes is one way to make it happen. This property simply describes the animation controlled by the last PlayAnimation method.

Note that the animation may be started by PlayAnimation with a 1-frame delay, but this property hides it from you, it is changed immediately by the PlayAnimation call.

Public property FileName: String read FUrl write SetUrl; deprecated;

Warning: this symbol is deprecated.

Deprecated name for Url.

Public property InternalShapesHash: TShapesHash read FShapesHash;

This item has no description.

Published property DefaultAnimationTransition: Single read FDefaultAnimationTransition write FDefaultAnimationTransition default 0.0;

When using PlayAnimation without TPlayAnimationParameters, this value is used as the duration (in seconds) of animation cross-fade (blending of animations). Zero (default value) disables the smooth transition, animations will change without any transition by default.

This default transition is only used if some previous animation was playing. Otherwise, it would be applied even when starting the initial animation.

Published property TimePlaying: boolean read FTimePlaying write FTimePlaying default true;

When TimePlaying is True, the time of our 3D world will keep playing. More precisely, our Update will take care of increasing Time. Our Update is usually automatically called (if you added this scene to TCastleWindow.Controls or TCastleControl.Controls) so you don't have to do anything to make this work.

Published property TimePlayingSpeed: Single read FTimePlayingSpeed write FTimePlayingSpeed default 1.0;

Controls the time speed (if TimePlaying is True): 1.0 means that 1 second of real time equals to 1 unit of world time.

Published property PreciseCollisions: Boolean read FPreciseCollisions write SetPreciseCollisions default false;

Resolve collisions precisely with the scene triangles.

When this is False we will only consider the bounding box of this scene for collisions. We look at bounding box of model loaded in Url, not at children (TCastleTransform) bounding boxes.

More details: Setting this creates two spatial structures (octrees):

  1. To detect collisions in dynamic scenes.

    This allows to resolve collisions with the (collidable) triangles of the model. By default, every X3D Shape is collidable using it's exact mesh. You can use the X3D TCollisionNode to turn collisions off for some shapes, or replace some shapes with simpler objects for the collision-detection purposes.

    You can always toggle Collides to quickly make the scene not collidable. In summary:

    • Collides = False: the scene does not collide.

    • Collides = True and PreciseCollisions = True: the scene collides as it's bounding box (LocalBoundingBoxNoChildren to be precise, so the box of Url model is taken into account, but not children). This is the default situation after constructing TCastleScene.

    • Collides = True and PreciseCollisions = False: The scene collides as a set of triangles. The triangles are derived from information in X3D Shape and Collision nodes.

  2. To speedup frustum culling.

    This adds an additional optimization during rendering. It allows to use frustum culling with an octree. Whether the frustum culling is actually used depends on TCastleScene.ShapeFrustumCulling value (by default: yes).

    Without this flag, we can still use frustum culling, but it's less effective as it considers each shape separately. Whether the frustum culling is actually used also depends on TCastleScene.ShapeFrustumCulling value.

    Using frustum culling (preferably with PreciseCollisions = True) is highly adviced if your camera usually only sees only a part of the scene. For example, it a noticeable optimization if you have a camera walking/flying inside a typical game level/location.

Published property ProcessEvents: boolean read FProcessEvents write SetProcessEvents default false;

Should the event mechanism (a basic of animations and interactions) work.

If True, then events will be send and received through X3D routes, time dependent nodes (TTimeDependentFunctionality, like TTimeSensorNode) will be activated and updated from Time time property, Press, Release and other methods will activate key/mouse sensor nodes, scripts will be initialized and work, etc.

In other words, this makes the scene fully animated and interacting with the user.

If False, this all doesn't work, which makes the scene static.

Published property Url: String read FUrl write SetUrl;

Currently loaded scene URL. Change this property to load a scene from the given URL. We support many 3D and 2D scene formats, like X3D and glTF, see https://castle-engine.io/creating_data_model_formats.php .

Setting this property works just like using the Load method with a new URL. In fact, using directly the Load method will also change this URL property.

The only difference between Scene.Url := 'blah.x3d' and Scene.Load('blah.x3d') is that setting the URL will not reload the scene if you set it to the same value. That is, Scene.Url := Scene.Url; will not reload the scene (you have to use explicit Load for this.).

Pass Url = '' to load an empty scene, this sets RootNode to Nil.

Published property ShadowMaps: boolean read FShadowMaps write SetShadowMaps default true;

At loading, process the scene to support shadow maps. This happens at the Load method call, and it makes "receiveShadows" field automatically handled.

Note that this is not the only way to make shadow maps. VRML/X3D author can always make shadow maps by using lower-level nodes, see [https://castle-engine.io/x3d_extensions.php#section_ext_shadow_maps]. When using these lower-level nodes, this property does not matter This property (and related ones like ShadowMapsDefaultSize) is relevant only for handling shadows by the "receiveShadows" field.

Published property ShadowMapsDefaultSize: Cardinal read FShadowMapsDefaultSize write SetShadowMapsDefaultSize default DefaultShadowMapsDefaultSize;

Default shadow map texture size.

Affects how shadow maps are handled for the "receiveShadows" field. This is taken into account at the scene Load time, and only if ShadowMaps is True.

VRML/X3D author can always override this by placing a GeneratedShadowMap node inside light's defaultShadowMap field. In this case, GeneratedShadowMap.size determines shadow map size.

Published property InitialViewpointIndex: Cardinal read FInitialViewpointIndex write FInitialViewpointIndex default 0;

When loading new model, use this viewpoint index to initialize camera. VRML/X3D specification says to use the first (index = 0) viewpoint, you can change this property to bind 2nd, 3rd and so on viewpoints.

This is applied only at loading (actually, at ChangedAll). If you later want to bind another viewpoint, just send set_bind := true to it.

Published property InitialViewpointName: String read FInitialViewpointName write FInitialViewpointName;

When loading new model and looking for initial viewpoint, consider only viewpoints with this node name. Relevant only if non-empty.

This may cooperate with InitialViewpointIndex: InitialViewpointIndex specifies the index of viewpoint node that satisfies also InitialViewpointName condition. For example:

  • InitialViewpointIndex = 0 and InitialViewpointName = '' means to use the first viewpoint, ignoring nodes' names. This is the default behavior, also following VRML/X3D specification.

  • InitialViewpointIndex = 1 and InitialViewpointName = '' means to use the 2nd viewpoint. Node name doesn't matter.

  • InitialViewpointIndex = 1 and InitialViewpointName = 'blah' means to use the first viewpoint named 'blah'. That is, we are only counting nodes named 'blah' for this.

Published property AnimateOnlyWhenVisible: boolean read FAnimateOnlyWhenVisible write FAnimateOnlyWhenVisible default false;

When True, we animate (more precisely: process time pass in Update) only when the model is visible. This is a powerful optimization, but be careful if you depend on your animations for something else than just visual effect.

See examples/animations/optimize_animations_test for a demo of this.

Published property AnimateSkipTicks: Cardinal read FAnimateSkipTicks write SetAnimateSkipTicks default 0;

Non-zero values optimize the animation processing, by not updating the animation every frame. After updating the animation in one Update call, the next AnimateSkipTicks number of Update calls will go very quickly, as they will not actually change the scene at all.

This is an effective optimization if the scene is usually not large on the screen.

  • The animation is less smooth. For example, if AnimateSkipTicks = 1, then every other Update call does not change the scene. For example, if you have 60 FPS, and Update is called 60 times per second, then we will actually change the scene only 30 times per second.

    The "skip" within every scene has a little random shift, to avoid synchronizing this skip across many created scenes. This makes this a little harder to notice.

  • In exchange, the speedup is substantial. For example, if AnimateSkipTicks = 1, then the animation on CPU effectively costs 2x less. In general, AnimateSkipTicks = N means that the cost drops to 1 / (1 + N).

See examples/animations/optimize_animations_test for a demo of this.

Published property AutoAnimation: String read FAutoAnimation write SetAutoAnimation;

If AutoAnimation is set, this animation will be automatically played. It is useful to determine the initial animation, played once the model is loaded (each time URL changes). You can also change AutoAnimation at any other moment at runtime (set it to something non-empty to change to a new animation; set it to '' to stop any animation).

Note: Using AutoAnimation will under the hood call methods like PlayAnimation, StopAnimation and update CurrentAnimation. The reverse is not true: calling PlayAnimation doesn't change AutoAnimation. So you can think of AutoAnimation as "an initial animation, activated each time we load the model, even if later we can change it to something else using PlayAnimation".

Published property AutoAnimationLoop: Boolean read FAutoAnimationLoop write SetAutoAnimationLoop default true; deprecated 'in future engine versions, AutoAnimationLoop may behave as always = true, and AutoAnimation will be renamed to just Animation and changing it will always cause a looping animation. Use PlayAnimation(''my_anim'',false) from code to play animation without looping.';

Warning: this symbol is deprecated: in future engine versions, AutoAnimationLoop may behave as always = true, and AutoAnimation will be renamed to just Animation and changing it will always cause a looping animation. Use PlayAnimation('my_anim',false) from code to play animation without looping.

Does the animation indicated by AutoAnimation loops.

Published property ExposeTransforms: TStrings read FExposeTransforms write SetExposeTransforms;

Transformation nodes inside the model that are synchronized with automatically-created children TCastleTransform.

This allows to expose transformation nodes from glTF, X3D and other model formats as TCastleTransform. These transformation nodes include animated bones from skeletons (armatures). Such "exposed transformation" results in a creation of TCastleTransform child, with the same name and synchronized transformation (translation, rotation, scale).

This allows to expose e.g. "hand that may hold a weapon", or "slot of a vehicle where to attach a camera", as TCastleTransform. And this allows, in turn, to attach various things to (possibly animated) transformations, e.g. attach model of a weapon to a hand, or attach TCastleCamera to some bone. The attached things will be automatically animated when the scene skeleton animates.

Setting this property merely copies the contents using TStrings.Assign, as is usual for published TStrings properties. In CGE editor, there's a nice GUI editor to pick the transfomation nodes, click on "..." at this property.

Note: the owner of auto-created children is equal to this scene's Owner. This is most natural when you edit this in CGE editor, or load using TransformLoad.

See the engine example in: examples/animations/expose_transformations_to_animate_children/ .

See also
ExposeTransformsPrefix
Name prefix for all children created by ExposeTransforms.
Published property ExposeTransformsPrefix: String read FExposeTransformsPrefix write SetExposeTransformsPrefix;

Name prefix for all children created by ExposeTransforms. Useful to keep names unique in the scene.

Published property Cache: Boolean read FCache write FCache default false;

Use cache to load given scene. This makes sense when you have multiple TCastleScene instances using the same URL, loading them will be much faster if they share the cache, so set Cache to True for all of them.

If you have only one scene using given URL, using cache is not necessary and in fact it will result in a bit of wasted memory. So better to keep Cache at False then.


Generated by PasDoc 0.16.0-snapshot.