Class TCastleScene

Unit

Declaration

type TCastleScene = class(TCastleSceneCore)

Description

Complete loading, processing and rendering of a scene. This is a descendant of TCastleSceneCore that adds efficient rendering.

Hierarchy

Overview

Fields

Public InternalIgnoreFrustum: boolean;
Public InternalVisibilityTest: TTestShapeVisibility;

Methods

Protected function CreateShape(AGeometry: TAbstractGeometryNode; AState: TX3DGraphTraverseState; ParentInfo: PTraversingInfo): TShape; override;
Protected procedure InvalidateBackground; override;
Protected procedure LocalRender(const Params: TRenderParams); override;
Protected procedure LocalRenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4); override;
Public constructor Create(AOwner: TComponent); override;
Public destructor Destroy; override;
Public procedure GLContextClose; override;
Public procedure PrepareResources(const Options: TPrepareResourcesOptions; const ProgressStep: boolean; const Params: TPrepareParams); override;
Public procedure BeforeNodesFree(const InternalChangedAll: boolean = false); override;
Public procedure FreeResources(Resources: TSceneFreeResources); override;
Public function Background: TBackground;
Public function Attributes: TSceneRenderingAttributes;
Public procedure UpdateGeneratedTextures( const RenderFunc: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const OriginalViewport: TRectangle); override;
Public procedure ViewChangedSuddenly; override;
Public procedure VisibleChangeNotification(const Changes: TVisibleChanges); override;
Public procedure CameraChanged(ACamera: TCamera); override;
Public function ScreenEffects(Index: Integer): TGLSLProgram;
Public function ScreenEffectsCount: Integer;
Public function ScreenEffectsNeedDepth: boolean;
Public function Clone(const AOwner: TComponent): TCastleScene;

Properties

Public property BackgroundSkySphereRadius: Single read FBackgroundSkySphereRadius write SetBackgroundSkySphereRadius default 1;
Published property FrustumCulling: TFrustumCulling read FFrustumCulling write SetFrustumCulling default fcBox;
Published property OctreeFrustumCulling: TFrustumCulling read FOctreeFrustumCulling write SetOctreeFrustumCulling default fcBox;
Published property ReceiveShadowVolumes: boolean read FReceiveShadowVolumes write FReceiveShadowVolumes default true;
Published property DistanceCulling: Single read FDistanceCulling write FDistanceCulling default 0;

Description

Fields

Public InternalIgnoreFrustum: boolean;

Internal hack to avoid checking frustum at rendering in some situations.

Public InternalVisibilityTest: TTestShapeVisibility;

Internal override test visibility.

Methods

Protected function CreateShape(AGeometry: TAbstractGeometryNode; AState: TX3DGraphTraverseState; ParentInfo: PTraversingInfo): TShape; override;
 
Protected procedure InvalidateBackground; override;
 
Protected procedure LocalRender(const Params: TRenderParams); override;
 
Protected procedure LocalRenderShadowVolume( ShadowVolumeRenderer: TBaseShadowVolumeRenderer; const ParentTransformIsIdentity: boolean; const ParentTransform: TMatrix4); override;

Render shadow volume (sides and caps) of this scene, for shadow volume algorithm. Uses ShadowVolumeRenderer for rendering, and to detect if rendering is necessary at all. It will calculate current bounding box (looking at ParentTransform, ParentTransformIsIdentity and LocalBoundingBox method).

It always uses silhouette optimization. This is the usual, fast method of rendering shadow volumes. Will not do anything (treat scene like not casting shadows, like CastShadowVolumes = false) if the model is not perfect 2-manifold, i.e. has some BorderEdges (although we could handle some BorderEdges for some points of view, this could leading to rendering artifacts).

All shadow quads are generated from scene triangles transformed by ParentTransform. We must be able to correctly detect front and back facing triangles with respect to light position, so ShadowVolumeRenderer.LightPosition and "this scene transformed by ParentTransform" must be in the same coordinate system. If ParentTransformIsIdentity then ParentTransform value is ignored and everything works like ParentTransform = identity matrix (and is a little faster in this special case).

Uses TrianglesListShadowCasters and ManifoldEdges and BorderEdges (so you may prefer to prepare it before, e.g. by calling PrepareResources with prShadowVolume included).

We look at some Attributes, like Attributes.Blending, because transparent triangles have to be handled a little differently, and when Attributes.Blending = false then all triangles are forced to be opaque. In other words, this takes Attributes into account, to cooperate with our Render method.

ShadowVolumeRenderer.LightPosition is the light position. ShadowVolumeRenderer.LightPosition[3] must be 1 (to indicate positional light) or 0 (a directional light). It's expected that ShadowVolumeRenderer is already initialized by ShadowVolumeRenderer.InitFrustumAndLight.

Faces (both shadow quads and caps) are rendered such that CCW <=> you're looking at it from outside (i.e. it's considered front face of this shadow volume).

Public constructor Create(AOwner: TComponent); override;
 
Public destructor Destroy; override;
 
Public procedure GLContextClose; override;

Destroy any associations of this object with current OpenGL context. For example, release any allocated texture names.

Generally speaking, destroys everything that is allocated by PrepareResources call. It's harmless to call this method when there are already no associations with current OpenGL context. This is called automatically from the destructor.

Public procedure PrepareResources(const Options: TPrepareResourcesOptions; const ProgressStep: boolean; const Params: TPrepareParams); override;
 
Public procedure BeforeNodesFree(const InternalChangedAll: boolean = false); override;
 
Public procedure FreeResources(Resources: TSceneFreeResources); override;
 
Public function Background: TBackground;

TBackground instance to render current background. Current background is the top node on the BackgroundStack of this scene, following VRML/X3D specifications, and can be dynamic. The scene manager should use this to render background.

You should not access the background this way in your own code. This is public only because our own TCastleSceneManager needs to access it. And this is not marked "internal" because you may want to implement custom TCastleScene descendants that override this.

If you simply use TCastleScene to render 3D stuff, and want to change background properties, then do not use this method. To change the background, find (or add) an X3D Background node (TBackgroundNode instance) in the X3D graph in RootNode, and change it's properties or "bind" to change current backround.

We use the current value of BackgroundSkySphereRadius.

Returns Nil if there is no currently bound background node in this scene, or if the bound background is not supported for now (the latter case right now happens with TextureBakckground).

This instance is managed (automatically created/freed and so on) by this TCastleScene instance. It is cached (so that it's recreated only when relevant things change, like VRML/X3D nodes affecting this background, or changes to BackgroundSkySphereRadius, or OpenGL context is closed).

Public function Attributes: TSceneRenderingAttributes;

Rendering attributes.

You are free to change them all at any time. Although note that changing some attributes (the ones defined in base TRenderingAttributes class) may be a costly operation (next PrepareResources with prRender, or Render call, may need to recalculate some things).

Public procedure UpdateGeneratedTextures( const RenderFunc: TRenderFromViewFunction; const ProjectionNear, ProjectionFar: Single; const OriginalViewport: TRectangle); override;
 
Public procedure ViewChangedSuddenly; override;
 
Public procedure VisibleChangeNotification(const Changes: TVisibleChanges); override;
 
Public procedure CameraChanged(ACamera: TCamera); override;
 
Public function ScreenEffects(Index: Integer): TGLSLProgram;

Screen effects information, used by TCastleAbstractViewport.ScreenEffects. ScreenEffectsCount may actually prepare screen effects.

Public function ScreenEffectsCount: Integer;
 
Public function ScreenEffectsNeedDepth: boolean;
 
Public function Clone(const AOwner: TComponent): TCastleScene;

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 Spatial or rendering attributes in Attributes.

Properties

Public property BackgroundSkySphereRadius: Single read FBackgroundSkySphereRadius write SetBackgroundSkySphereRadius default 1;
 
Published property FrustumCulling: TFrustumCulling read FFrustumCulling write SetFrustumCulling default fcBox;

Fine-tune performance of rendering when ssRendering is not in TCastleSceneCore.Spatial.

Render tests each Shape for collision with given Frustum before rendering this Shape. It can use Shape.BoundingBox or Shape.BoundingSphere or both. See TFrustumCulling.

Shape.BoundingBox is (in a current implementation) always a better approximation of shape geometry than Shape.BoundingSphere. So advantage of using Shape.BoundingBox is that more Shapes may be eliminated. Advantage of using Shape.BoundingSphere is that checking for collision Frustum<->Sphere is faster, so you don't waste so much time on testing for collisions between frustum and Shape.

Published property OctreeFrustumCulling: TFrustumCulling read FOctreeFrustumCulling write SetOctreeFrustumCulling default fcBox;

Fine-tune performance of rendering when ssRendering is included in TCastleSceneCore.Spatial.

See TFrustumCulling.

Published property ReceiveShadowVolumes: boolean read FReceiveShadowVolumes write FReceiveShadowVolumes default true;
 
Published property DistanceCulling: Single read FDistanceCulling write FDistanceCulling default 0;

Cull things farther than this distance. Ignored if <= 0.


Generated by PasDoc 0.15.0.