Kemena3D
Loading...
Searching...
No Matches
kemena::kScene Class Reference

Holds all objects, lights, and rendering settings for one scene. More...

#include <kscene.h>

Public Member Functions

 kScene ()
 Constructs an empty scene with a default root node.
virtual ~kScene ()
 Destroys the scene. Does not free objects/meshes/lights held by pointer.
void setAssetManager (kAssetManager *manager)
 Sets the asset manager used to load resources into this scene.
kAssetManagergetAssetManager ()
 Returns the asset manager associated with this scene.
void setWorld (kWorld *newWorld)
 Associates this scene with a parent world.
kWorldgetWorld ()
 Returns the parent world.
bool getActive ()
 Returns whether this scene is active (rendered and updated).
void setActive (bool newActive)
 Activates or deactivates this scene.
void setFrustumCullingEnabled (bool enable)
 Enable or disable frustum culling for this scene (default: enabled).
bool getFrustumCullingEnabled () const
 Returns whether frustum culling is enabled for this scene.
kString getUuid ()
 Returns the UUID of this scene.
void setUuid (kString newUuid)
 Sets the UUID of this scene.
kString getName ()
 Returns the human-readable scene name.
void setName (kString newName)
 Sets the human-readable scene name.
unsigned int getIncrement ()
 Returns the auto-increment counter used to assign object IDs.
void setIncrement (unsigned int newIncrement)
 Sets the auto-increment counter (used when deserialising).
std::vector< kObject * > getObjects ()
 Returns all generic scene-graph objects.
std::vector< kMesh * > getMeshes ()
 Returns all mesh nodes in the scene.
std::vector< kLight * > getLights ()
 Returns all light nodes in the scene.
kObjectgetRootNode ()
 Returns the root node of the scene graph.
void addObject (kObject *object, kString objectUuid="")
 Adds a generic object to the scene graph.
kMeshaddMesh (kString fileName, kString objectUuid="")
 Loads a mesh asset and adds it to the scene.
void addMesh (kMesh *mesh, kString objectUuid="")
 Adds an existing mesh node to the scene graph.
kVec3 getAmbientLightColor ()
 Returns the scene-level ambient light colour.
void setAmbientLightColor (kVec3 newColor)
 Sets the scene-level ambient light colour.
kLightaddSunLight (kVec3 position=kVec3(0.0f, 0.0f, 0.0f), kVec3 direction=kVec3(0.0f, -1.0f, 0.0f), kVec3 diffuseColor=kVec3(1.0f, 1.0f, 1.0f), kVec3 specularColor=kVec3(1.0f, 1.0f, 1.0f), kString objectUuid="")
 Creates and adds a directional (sun) light.
kLightaddPointLight (kVec3 position=kVec3(0.0f, 0.0f, 0.0f), kVec3 diffuseColor=kVec3(1.0f, 1.0f, 1.0f), kVec3 specularColor=kVec3(1.0f, 1.0f, 1.0f), kString objectUuid="")
 Creates and adds an omnidirectional point light.
kLightaddSpotLight (kVec3 position=kVec3(0.0f, 0.0f, 0.0f), kVec3 diffuseColor=kVec3(1.0f, 1.0f, 1.0f), kVec3 specularColor=kVec3(1.0f, 1.0f, 1.0f), kString objectUuid="")
 Creates and adds a cone spotlight.
void removeObject (kObject *object)
 Removes a generic object from the scene graph.
void removeMesh (kMesh *mesh)
 Removes a mesh node from the scene graph.
void removeLight (kLight *light)
 Removes a light node from the scene graph and the light list.
void addLight (kLight *light)
 Re-attaches an existing light to the scene (used for undo).
bool getShadowsEnabled () const
 Returns whether the scene wants shadow rendering.
void setShadowsEnabled (bool enabled)
 Toggles shadow rendering for this scene.
float getShadowBias () const
 Returns the constant shadow bias used by lit shaders.
void setShadowBias (float bias)
 Sets the constant shadow bias used by lit shaders. Larger values reduce acne but can detach the shadow from its caster (peter-panning).
float getShadowNormalBias () const
 Returns the slope-scaled component of the shadow bias.
void setShadowNormalBias (float bias)
 Sets the slope-scaled component of the shadow bias. Multiplied by (1 - N·L); only affects grazing-angle surfaces.
int getShadowMapResolution () const
 Returns the per-cascade shadow map resolution in pixels.
void setShadowMapResolution (int resolution)
 Sets the per-cascade shadow map resolution (e.g. 512, 1024, 2048, 4096). Reallocates the shadow texture on the renderer.
float getShadowSoftness () const
 Returns the PCF tap spacing (in shadow-map texels).
void setShadowSoftness (float softness)
 Sets the PCF tap spacing in shadow-map texels. Larger = softer edges but more bleeding of small occluders.
bool getSkyboxAmbientEnabled ()
 Returns whether skybox image-based ambient is enabled.
void setSkyboxAmbientEnabled (bool enabled)
 Enables or disables skybox image-based ambient lighting.
float getSkyboxAmbientStrength ()
 Returns the skybox ambient strength multiplier.
void setSkyboxAmbientStrength (float strength)
 Sets the skybox ambient strength multiplier.
void setSkybox (kMaterial *newMaterial, kMesh *newMesh)
 Sets the skybox material and mesh.
kMaterialgetSkyboxMaterial ()
 Returns the skybox material.
kMeshgetSkyboxMesh ()
 Returns the skybox mesh.
virtual json serialize ()
 Serialises the scene to JSON.
virtual void deserialize (json data)
 Restores the scene from a JSON object.

Detailed Description

Holds all objects, lights, and rendering settings for one scene.

A kScene owns a root scene-graph node under which all kObject, kMesh, and kLight instances are organised. Multiple scenes can coexist inside a kWorld; only active scenes are rendered.

Constructor & Destructor Documentation

◆ kScene()

kemena::kScene::kScene ( )

Constructs an empty scene with a default root node.

◆ ~kScene()

virtual kemena::kScene::~kScene ( )
virtual

Destroys the scene. Does not free objects/meshes/lights held by pointer.

Member Function Documentation

◆ addLight()

void kemena::kScene::addLight ( kLight * light)

Re-attaches an existing light to the scene (used for undo).

Parameters
lightLight to re-add; must already have its UUID set.

◆ addMesh() [1/2]

void kemena::kScene::addMesh ( kMesh * mesh,
kString objectUuid = "" )

Adds an existing mesh node to the scene graph.

Parameters
meshPre-constructed mesh to add.
objectUuidOptional UUID override.

◆ addMesh() [2/2]

kMesh * kemena::kScene::addMesh ( kString fileName,
kString objectUuid = "" )

Loads a mesh asset and adds it to the scene.

Parameters
fileNamePath to the mesh asset file.
objectUuidOptional UUID for the new mesh node.
Returns
Pointer to the created kMesh.

◆ addObject()

void kemena::kScene::addObject ( kObject * object,
kString objectUuid = "" )

Adds a generic object to the scene graph.

Parameters
objectObject to add; ownership is not transferred.
objectUuidOptional UUID to assign; auto-generated if empty.

◆ addPointLight()

kLight * kemena::kScene::addPointLight ( kVec3 position = kVec3(0.0f, 0.0f, 0.0f),
kVec3 diffuseColor = kVec3(1.0f, 1.0f, 1.0f),
kVec3 specularColor = kVec3(1.0f, 1.0f, 1.0f),
kString objectUuid = "" )

Creates and adds an omnidirectional point light.

Parameters
positionWorld-space position.
diffuseColorDiffuse colour component.
specularColorSpecular colour component.
objectUuidOptional UUID for the new node.
Returns
Pointer to the created kLight.

◆ addSpotLight()

kLight * kemena::kScene::addSpotLight ( kVec3 position = kVec3(0.0f, 0.0f, 0.0f),
kVec3 diffuseColor = kVec3(1.0f, 1.0f, 1.0f),
kVec3 specularColor = kVec3(1.0f, 1.0f, 1.0f),
kString objectUuid = "" )

Creates and adds a cone spotlight.

Parameters
positionWorld-space position.
diffuseColorDiffuse colour component.
specularColorSpecular colour component.
objectUuidOptional UUID for the new node.
Returns
Pointer to the created kLight.

◆ addSunLight()

kLight * kemena::kScene::addSunLight ( kVec3 position = kVec3(0.0f, 0.0f, 0.0f),
kVec3 direction = kVec3(0.0f, -1.0f, 0.0f),
kVec3 diffuseColor = kVec3(1.0f, 1.0f, 1.0f),
kVec3 specularColor = kVec3(1.0f, 1.0f, 1.0f),
kString objectUuid = "" )

Creates and adds a directional (sun) light.

Parameters
positionWorld-space position of the light node.
directionNormalised light direction.
diffuseColorDiffuse colour component.
specularColorSpecular colour component.
objectUuidOptional UUID for the new node.
Returns
Pointer to the created kLight.

◆ deserialize()

virtual void kemena::kScene::deserialize ( json data)
virtual

Restores the scene from a JSON object.

Parameters
dataJSON produced by serialize().

◆ getActive()

bool kemena::kScene::getActive ( )

Returns whether this scene is active (rendered and updated).

Returns
true if active.

◆ getAmbientLightColor()

kVec3 kemena::kScene::getAmbientLightColor ( )

Returns the scene-level ambient light colour.

Returns
RGB ambient colour.

◆ getAssetManager()

kAssetManager * kemena::kScene::getAssetManager ( )

Returns the asset manager associated with this scene.

Returns
Pointer to the asset manager, or nullptr if not set.

◆ getFrustumCullingEnabled()

bool kemena::kScene::getFrustumCullingEnabled ( ) const
inline

Returns whether frustum culling is enabled for this scene.

◆ getIncrement()

unsigned int kemena::kScene::getIncrement ( )

Returns the auto-increment counter used to assign object IDs.

Returns
Current counter value.

◆ getLights()

std::vector< kLight * > kemena::kScene::getLights ( )

Returns all light nodes in the scene.

Returns
Copy of the internal light vector.

◆ getMeshes()

std::vector< kMesh * > kemena::kScene::getMeshes ( )

Returns all mesh nodes in the scene.

Returns
Copy of the internal mesh vector.

◆ getName()

kString kemena::kScene::getName ( )

Returns the human-readable scene name.

Returns
Scene name kString.

◆ getObjects()

std::vector< kObject * > kemena::kScene::getObjects ( )

Returns all generic scene-graph objects.

Returns
Copy of the internal object vector.

◆ getRootNode()

kObject * kemena::kScene::getRootNode ( )

Returns the root node of the scene graph.

Returns
Pointer to the root kObject.

◆ getShadowBias()

float kemena::kScene::getShadowBias ( ) const

Returns the constant shadow bias used by lit shaders.

◆ getShadowMapResolution()

int kemena::kScene::getShadowMapResolution ( ) const

Returns the per-cascade shadow map resolution in pixels.

◆ getShadowNormalBias()

float kemena::kScene::getShadowNormalBias ( ) const

Returns the slope-scaled component of the shadow bias.

◆ getShadowsEnabled()

bool kemena::kScene::getShadowsEnabled ( ) const

Returns whether the scene wants shadow rendering.

The renderer reads this each frame; turning it off skips the shadow map pass entirely and tells lit shaders to drop the shadow term. Default: true.

◆ getShadowSoftness()

float kemena::kScene::getShadowSoftness ( ) const

Returns the PCF tap spacing (in shadow-map texels).

◆ getSkyboxAmbientEnabled()

bool kemena::kScene::getSkyboxAmbientEnabled ( )

Returns whether skybox image-based ambient is enabled.

◆ getSkyboxAmbientStrength()

float kemena::kScene::getSkyboxAmbientStrength ( )

Returns the skybox ambient strength multiplier.

◆ getSkyboxMaterial()

kMaterial * kemena::kScene::getSkyboxMaterial ( )

Returns the skybox material.

Returns
Pointer to the skybox material, or nullptr if not set.

◆ getSkyboxMesh()

kMesh * kemena::kScene::getSkyboxMesh ( )

Returns the skybox mesh.

Returns
Pointer to the skybox mesh, or nullptr if not set.

◆ getUuid()

kString kemena::kScene::getUuid ( )

Returns the UUID of this scene.

Returns
UUID v4 kString.

◆ getWorld()

kWorld * kemena::kScene::getWorld ( )

Returns the parent world.

Returns
Pointer to the owning kWorld.

◆ removeLight()

void kemena::kScene::removeLight ( kLight * light)

Removes a light node from the scene graph and the light list.

Parameters
lightLight to detach; memory is NOT freed.

◆ removeMesh()

void kemena::kScene::removeMesh ( kMesh * mesh)

Removes a mesh node from the scene graph.

Parameters
meshMesh to detach; memory is NOT freed.

◆ removeObject()

void kemena::kScene::removeObject ( kObject * object)

Removes a generic object from the scene graph.

Parameters
objectObject to detach; memory is NOT freed.

◆ serialize()

virtual json kemena::kScene::serialize ( )
virtual

Serialises the scene to JSON.

Returns
JSON object with all scene data.

◆ setActive()

void kemena::kScene::setActive ( bool newActive)

Activates or deactivates this scene.

Parameters
newActivefalse to skip this scene during rendering.

◆ setAmbientLightColor()

void kemena::kScene::setAmbientLightColor ( kVec3 newColor)

Sets the scene-level ambient light colour.

Parameters
newColorRGB ambient colour.

◆ setAssetManager()

void kemena::kScene::setAssetManager ( kAssetManager * manager)

Sets the asset manager used to load resources into this scene.

Parameters
managerPointer to the asset manager; must outlive the scene.

◆ setFrustumCullingEnabled()

void kemena::kScene::setFrustumCullingEnabled ( bool enable)
inline

Enable or disable frustum culling for this scene (default: enabled).

◆ setIncrement()

void kemena::kScene::setIncrement ( unsigned int newIncrement)

Sets the auto-increment counter (used when deserialising).

Parameters
newIncrementNew counter value.

◆ setName()

void kemena::kScene::setName ( kString newName)

Sets the human-readable scene name.

Parameters
newNameNew name kString.

◆ setShadowBias()

void kemena::kScene::setShadowBias ( float bias)

Sets the constant shadow bias used by lit shaders. Larger values reduce acne but can detach the shadow from its caster (peter-panning).

◆ setShadowMapResolution()

void kemena::kScene::setShadowMapResolution ( int resolution)

Sets the per-cascade shadow map resolution (e.g. 512, 1024, 2048, 4096). Reallocates the shadow texture on the renderer.

◆ setShadowNormalBias()

void kemena::kScene::setShadowNormalBias ( float bias)

Sets the slope-scaled component of the shadow bias. Multiplied by (1 - N·L); only affects grazing-angle surfaces.

◆ setShadowsEnabled()

void kemena::kScene::setShadowsEnabled ( bool enabled)

Toggles shadow rendering for this scene.

◆ setShadowSoftness()

void kemena::kScene::setShadowSoftness ( float softness)

Sets the PCF tap spacing in shadow-map texels. Larger = softer edges but more bleeding of small occluders.

◆ setSkybox()

void kemena::kScene::setSkybox ( kMaterial * newMaterial,
kMesh * newMesh )

Sets the skybox material and mesh.

Parameters
newMaterialMaterial with a cube-map texture.
newMeshUnit-cube mesh used to render the skybox.

◆ setSkyboxAmbientEnabled()

void kemena::kScene::setSkyboxAmbientEnabled ( bool enabled)

Enables or disables skybox image-based ambient lighting.

◆ setSkyboxAmbientStrength()

void kemena::kScene::setSkyboxAmbientStrength ( float strength)

Sets the skybox ambient strength multiplier.

◆ setUuid()

void kemena::kScene::setUuid ( kString newUuid)

Sets the UUID of this scene.

Parameters
newUuidUUID v4 kString.

◆ setWorld()

void kemena::kScene::setWorld ( kWorld * newWorld)

Associates this scene with a parent world.

Parameters
newWorldOwning world instance.

The documentation for this class was generated from the following file: