Table of Contents

Class Scene3D

Namespace
LibGFX.Core
Assembly
LibGFX.dll

Represents a 3D scene for rendering 3D objects and lights.

public class Scene3D : BaseScene, IIdentifier, ISerialization
Inheritance
Scene3D
Implements
Inherited Members

Constructors

Scene3D()

Creates a new 3D scene

public Scene3D()

Properties

DirectionalLight

Sets the directional light for the scene

public DirectionalLight3D DirectionalLight { get; set; }

Property Value

DirectionalLight3D

Elements

Gets or sets the collection of game elements contained in this instance.

public List<GameElement> Elements { get; set; }

Property Value

List<GameElement>

Enviroment

The enviroment texture of the scene

public IEnviroment Enviroment { get; set; }

Property Value

IEnviroment

LightManager

The light manager for the 3D scene

public override ILightManager LightManager { get; }

Property Value

ILightManager

PerformShadowPass

Determines if the scene should perform a shadow pass

public bool PerformShadowPass { get; set; }

Property Value

bool

RenderEnviromentTexture

Determines if the enviroment texture should be rendered

public bool RenderEnviromentTexture { get; set; }

Property Value

bool

RenderTarget

Gets the render target associated with this scene instance.

public override IRenderTarget RenderTarget { get; }

Property Value

IRenderTarget

Samples

The number of samples for the scene rendering

public uint Samples { get; set; }

Property Value

uint

Methods

AddEnqueEntry(IEnqueEntry)

Adds an enque entry to the scene which gets processed during the enque phase

public override void AddEnqueEntry(IEnqueEntry entry)

Parameters

entry IEnqueEntry

Exceptions

ArgumentException

AddGameElement(GameElement)

Adds a game element to the scene

public override void AddGameElement(GameElement element)

Parameters

element GameElement

Exceptions

ArgumentNullException

AddLight<T>(T)

Adds a light to the scene. Supports point and directional lights.

public override void AddLight<T>(T light) where T : Light

Parameters

light T

The light instance to add to the scene. Must be a supported light type.

Type Parameters

T

The type of the light to add. Must be either PointLight3D or DirectionalLight3D.

Remarks

Only PointLight3D and DirectionalLight3D types are supported. Attempting to add other light types will result in a NotSupportedException.

Exceptions

NotSupportedException

Thrown if the specified light type is not supported by the scene.

ClearElements()

Clrears all elements from the scene

public override void ClearElements()

CreateDefaultScene()

Creates a new 3D scene with a default configuration, including a directional light source.

public static Scene3D CreateDefaultScene()

Returns

Scene3D

A new instance of Scene3D preconfigured with default lighting and settings.

Deserialize(JObject, SerializationContext, Func<JObject, bool>)

Deserializes the scene from JSON

public override void Deserialize(JObject obj, SerializationContext serializationContext, Func<JObject, bool> callback = null)

Parameters

obj JObject
serializationContext SerializationContext
callback Func<JObject, bool>

Exceptions

Exception

DisposeScene(IRenderDevice)

Disposes the scene and all its layers

public override void DisposeScene(IRenderDevice renderer)

Parameters

renderer IRenderDevice

EnqueElements()

Processes the enque entries and adds the elements to the scene. Clears the enque entries after processing.

public override void EnqueElements()

Exceptions

InvalidOperationException

FindElement<T>(string)

Finds a game element by its name

public override T? FindElement<T>(string name) where T : GameElement

Parameters

name string

Returns

T

Type Parameters

T

FindElementsWithBehavior<T>()

Finds all game elements with the specified behavior

public override ICollection<GameElement> FindElementsWithBehavior<T>() where T : IGameBehavior

Returns

ICollection<GameElement>

Type Parameters

T

FindElementsWithTag(string)

Finds all game elements with the specified tag

public override ICollection<GameElement> FindElementsWithTag(string tag)

Parameters

tag string

Returns

ICollection<GameElement>

ForEachElement(Action<GameElement>)

For each game element in the scene, perform the specified action

public override void ForEachElement(Action<GameElement> action)

Parameters

action Action<GameElement>

FreeScene(IRenderDevice)

Frees the scene from the game elements

public override void FreeScene(IRenderDevice renderer)

Parameters

renderer IRenderDevice

GetAllElements()

Gets all game elements in the scene

public override IEnumerable<GameElement> GetAllElements()

Returns

IEnumerable<GameElement>

GetElementByID(string)

Gets a game element by its unique identifier (UUID)

public override GameElement? GetElementByID(string uuid)

Parameters

uuid string

Returns

GameElement

GetElements<T>()

Gets all game elements of the specified type

public override ICollection<GameElement> GetElements<T>() where T : GameElement

Returns

ICollection<GameElement>

Type Parameters

T

GetLight<T>()

Retrieves the scene's directional light if the specified type is supported.

public override T GetLight<T>() where T : Light

Returns

T

The directional light instance cast to the specified type T.

Type Parameters

T

The type of light to retrieve. Only DirectionalLight3D is supported.

Remarks

This method only supports retrieval of the directional light. Attempting to request other light types will result in an exception.

Exceptions

NotSupportedException

Thrown if T is not DirectionalLight3D.

Init(Viewport, IRenderDevice)

Initializes the scene and all its layers

public override void Init(Viewport viewport, IRenderDevice renderer)

Parameters

viewport Viewport
renderer IRenderDevice

InitializeElements(Viewport, IRenderDevice)

Initializes the scene elements

public override void InitializeElements(Viewport viewport, IRenderDevice renderer)

Parameters

viewport Viewport
renderer IRenderDevice

RemoveElement(GameElement)

Removes a game element from the scene

public override void RemoveElement(GameElement element)

Parameters

element GameElement

Exceptions

ArgumentNullException

RemoveLight<T>(T)

Removes a directional light from the scene if it is currently present.

public override void RemoveLight<T>(T light) where T : Light

Parameters

light T

The light instance to remove from the scene. Must be a DirectionalLight3D that is part of the scene.

Type Parameters

T

The type of light to remove. Must be a DirectionalLight3D.

Remarks

Only directional lights are supported for removal. Attempting to remove other light types will result in a NotSupportedException.

Exceptions

InvalidOperationException

Thrown if the specified directional light is not part of the scene.

NotSupportedException

Thrown if the specified light type is not supported by Scene3D.

Render(Viewport, IRenderDevice, Camera)

Renders the scene and all its layers

public override void Render(Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

viewport Viewport
renderer IRenderDevice
camera Camera

RenderShadowMaps(Viewport, IRenderDevice, Camera)

Renders the shadow maps for the scene

public override void RenderShadowMaps(Viewport viewport, IRenderDevice renderer, Camera camera)

Parameters

viewport Viewport
renderer IRenderDevice
camera Camera

Serialize(JsonWriter, SerializationContext, Action<JsonWriter>)

Serializes the scene to JSON

public override void Serialize(JsonWriter writer, SerializationContext serializationContext, Action<JsonWriter> callback = null)

Parameters

writer JsonWriter
serializationContext SerializationContext
callback Action<JsonWriter>

Update(float)

Updates the scene and all its layers

public override void Update(float dt)

Parameters

dt float

UpdatePhysics(float)

Updates the physics of the scene

public override void UpdatePhysics(float dt)

Parameters

dt float

Events

AfterLightCulling

Called after light culling has been performed

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> AfterLightCulling

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

AfterRenderTargetCreation

Called after the render target for the scene has been created

public override event Action<BaseScene, Viewport, IRenderDevice> AfterRenderTargetCreation

Event Type

Action<BaseScene, Viewport, IRenderDevice>

OnDispose

Called when the scene gets disposed

public override event Action<BaseScene, IRenderDevice> OnDispose

Event Type

Action<BaseScene, IRenderDevice>

OnDisposeEnd

Called after the scene has been disposed

public override event Action<BaseScene, IRenderDevice> OnDisposeEnd

Event Type

Action<BaseScene, IRenderDevice>

OnDisposeStart

Called before the scene is disposed

public override event Action<BaseScene, IRenderDevice> OnDisposeStart

Event Type

Action<BaseScene, IRenderDevice>

OnInitEnd

Called when the scene has been initialized

public override event Action<BaseScene, Viewport, IRenderDevice> OnInitEnd

Event Type

Action<BaseScene, Viewport, IRenderDevice>

OnInitStart

Called when the scene is initializing

public override event Action<BaseScene, Viewport, IRenderDevice> OnInitStart

Event Type

Action<BaseScene, Viewport, IRenderDevice>

OnPhysicsUpdateEnd

Called when the physics update ends

public override event Action<BaseScene, float> OnPhysicsUpdateEnd

Event Type

Action<BaseScene, float>

OnPhysicsUpdateStart

Called when the physics update starts

public override event Action<BaseScene, float> OnPhysicsUpdateStart

Event Type

Action<BaseScene, float>

OnRenderEnd

Called at the end of the render process

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnRenderEnd

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnRenderPassBegin

Called before the game elements get rendered

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnRenderPassBegin

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnRenderPassEnd

Called when all game elements have been rendered before the render target blitting

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnRenderPassEnd

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnRenderStart

Called immediately on the start of the render process

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnRenderStart

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnShadowPassEnd

Called when the shadow pass ends

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnShadowPassEnd

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnShadowPassStart

Called when the shadow pass starts

public override event Action<BaseScene, Viewport, IRenderDevice, Camera> OnShadowPassStart

Event Type

Action<BaseScene, Viewport, IRenderDevice, Camera>

OnUpdateEnd

Called when the scene has been updated

public override event Action<BaseScene, float> OnUpdateEnd

Event Type

Action<BaseScene, float>

OnUpdateStart

Called when the scene is updating

public override event Action<BaseScene, float> OnUpdateStart

Event Type

Action<BaseScene, float>