Kemena3D
Loading...
Searching...
No Matches
kscene.h
Go to the documentation of this file.
1
5
6#ifndef KSCENE_H
7#define KSCENE_H
8
9#include "kexport.h"
10
11#include <string>
12#include <iostream>
13#include <vector>
14#include <typeinfo>
15
16#include "kdatatype.h"
17#include "kassetmanager.h"
18#include "kworld.h"
19#include "kobject.h"
20#include "kmesh.h"
21#include "kcamera.h"
22#include "klight.h"
23
24namespace kemena
25{
26 class kWorld;
27
36 {
37 public:
40
42 virtual ~kScene();
43
49
55
60 void setWorld(kWorld *newWorld);
61
67
72 bool getActive();
73
78 void setActive(bool newActive);
79
81 void setFrustumCullingEnabled(bool enable) { frustumCullingEnabled = enable; }
82
84 bool getFrustumCullingEnabled() const { return frustumCullingEnabled; }
85
91
96 void setUuid(kString newUuid);
97
103
108 void setName(kString newName);
109
114 unsigned int getIncrement();
115
120 void setIncrement(unsigned int newIncrement);
121
126 std::vector<kObject *> getObjects();
127
132 std::vector<kMesh *> getMeshes();
133
138 std::vector<kLight *> getLights();
139
145
151 void addObject(kObject *object, kString objectUuid = "");
152
159 kMesh *addMesh(kString fileName, kString objectUuid = "");
160
166 void addMesh(kMesh *mesh, kString objectUuid = "");
167
173
179
189 kLight *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 = "");
190
199 kLight *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 = "");
200
209 kLight *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 = "");
210
215 void removeObject(kObject *object);
216
221 void removeMesh(kMesh *mesh);
222
227 void removeLight(kLight *light);
228
233 void addLight(kLight *light);
234
242 bool getShadowsEnabled() const;
243
247 void setShadowsEnabled(bool enabled);
248
252 float getShadowBias() const;
253
258 void setShadowBias(float bias);
259
263 float getShadowNormalBias() const;
264
269 void setShadowNormalBias(float bias);
270
275
280 void setShadowMapResolution(int resolution);
281
285 float getShadowSoftness() const;
286
291 void setShadowSoftness(float softness);
292
297
301 void setSkyboxAmbientEnabled(bool enabled);
302
307
311 void setSkyboxAmbientStrength(float strength);
312
318 void setSkybox(kMaterial *newMaterial, kMesh *newMesh);
319
325
331
336 virtual json serialize();
337
342 virtual void deserialize(json data);
343
344 protected:
345 private:
346 kAssetManager *assetManager = nullptr;
347 kWorld *world = nullptr;
348
349 bool isActive = true;
350 bool frustumCullingEnabled = true;
351
352 kString uuid;
353 kString name;
354
355 std::vector<kObject *> objects;
356 std::vector<kMesh *> meshes;
357 std::vector<kLight *> lights;
358
359 kObject *rootNode = nullptr;
360
361 kVec3 ambientLightColor = kVec3(0.1f, 0.1f, 0.1f);
362
363 bool shadowsEnabled = true;
364 float shadowBias = 0.0008f;
365 float shadowNormalBias = 0.003f;
366 int shadowMapResolution = 2048;
367 float shadowSoftness = 1.5f;
368 bool skyboxAmbientEnabled = false;
369 float skyboxAmbientStrength = 1.0f;
370
371 kMaterial *skyMaterial = nullptr;
372 kMesh *skyMesh = nullptr;
373 };
374}
375
376#endif // KSCENE_H
Central asset-loading and cache manager.
Definition kassetmanager.h:55
Scene-graph node that emits light.
Definition klight.h:28
Groups a shader program with textures and surface parameters.
Definition kmaterial.h:27
Scene-graph node that holds renderable geometry.
Definition kmesh.h:35
Base scene-graph node.
Definition kobject.h:43
std::vector< kObject * > getObjects()
Returns all generic scene-graph objects.
bool getShadowsEnabled() const
Returns whether the scene wants shadow rendering.
void removeMesh(kMesh *mesh)
Removes a mesh node from the scene graph.
void setSkybox(kMaterial *newMaterial, kMesh *newMesh)
Sets the skybox material and mesh.
kScene()
Constructs an empty scene with a default root node.
void setIncrement(unsigned int newIncrement)
Sets the auto-increment counter (used when deserialising).
kMesh * addMesh(kString fileName, kString objectUuid="")
Loads a mesh asset and adds it to the scene.
void setShadowMapResolution(int resolution)
Sets the per-cascade shadow map resolution (e.g. 512, 1024, 2048, 4096). Reallocates the shadow textu...
void setActive(bool newActive)
Activates or deactivates this scene.
kMesh * getSkyboxMesh()
Returns the skybox mesh.
float getShadowSoftness() const
Returns the PCF tap spacing (in shadow-map texels).
kMaterial * getSkyboxMaterial()
Returns the skybox material.
void addMesh(kMesh *mesh, kString objectUuid="")
Adds an existing mesh node to the scene graph.
kString getUuid()
Returns the UUID of this scene.
float getShadowNormalBias() const
Returns the slope-scaled component of the shadow bias.
void removeObject(kObject *object)
Removes a generic object from the scene graph.
void setName(kString newName)
Sets the human-readable scene name.
void setAssetManager(kAssetManager *manager)
Sets the asset manager used to load resources into this scene.
void setShadowsEnabled(bool enabled)
Toggles shadow rendering for this scene.
void setShadowSoftness(float softness)
Sets the PCF tap spacing in shadow-map texels. Larger = softer edges but more bleeding of small occlu...
void setShadowNormalBias(float bias)
Sets the slope-scaled component of the shadow bias. Multiplied by (1 - N·L); only affects grazing-ang...
virtual void deserialize(json data)
Restores the scene from a JSON object.
int getShadowMapResolution() const
Returns the per-cascade shadow map resolution in pixels.
std::vector< kLight * > getLights()
Returns all light nodes in the scene.
kLight * 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.
void setSkyboxAmbientEnabled(bool enabled)
Enables or disables skybox image-based ambient lighting.
unsigned int getIncrement()
Returns the auto-increment counter used to assign object IDs.
kLight * 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.
kLight * 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.
bool getActive()
Returns whether this scene is active (rendered and updated).
void addLight(kLight *light)
Re-attaches an existing light to the scene (used for undo).
kString getName()
Returns the human-readable scene name.
void setSkyboxAmbientStrength(float strength)
Sets the skybox ambient strength multiplier.
void removeLight(kLight *light)
Removes a light node from the scene graph and the light list.
void setShadowBias(float bias)
Sets the constant shadow bias used by lit shaders. Larger values reduce acne but can detach the shado...
void addObject(kObject *object, kString objectUuid="")
Adds a generic object to the scene graph.
kObject * getRootNode()
Returns the root node of the scene graph.
void setUuid(kString newUuid)
Sets the UUID of this scene.
virtual ~kScene()
Destroys the scene. Does not free objects/meshes/lights held by pointer.
float getShadowBias() const
Returns the constant shadow bias used by lit shaders.
void setAmbientLightColor(kVec3 newColor)
Sets the scene-level ambient light colour.
virtual json serialize()
Serialises the scene to JSON.
void setWorld(kWorld *newWorld)
Associates this scene with a parent world.
bool getFrustumCullingEnabled() const
Returns whether frustum culling is enabled for this scene.
Definition kscene.h:84
void setFrustumCullingEnabled(bool enable)
Enable or disable frustum culling for this scene (default: enabled).
Definition kscene.h:81
kAssetManager * getAssetManager()
Returns the asset manager associated with this scene.
float getSkyboxAmbientStrength()
Returns the skybox ambient strength multiplier.
std::vector< kMesh * > getMeshes()
Returns all mesh nodes in the scene.
bool getSkyboxAmbientEnabled()
Returns whether skybox image-based ambient is enabled.
kVec3 getAmbientLightColor()
Returns the scene-level ambient light colour.
kWorld * getWorld()
Returns the parent world.
Root container for the entire simulation environment.
Definition kworld.h:54
Loads and manages textures, meshes, shaders, materials, and animations.
Perspective camera node (free-look or look-at).
Core type aliases, enumerations, structs, and utility functions used throughout the engine.
Symbol visibility / linkage macro for the Kemena3D library.
#define KEMENA3D_API
Definition kexport.h:35
Light source scene-graph node (point, directional, spotlight).
Polygonal mesh node with skeletal animation support.
Base class for all scene-graph nodes in the Kemena3D engine.
nlohmann::json json
Definition kobject.h:30
Top-level container holding scenes and cameras.
Top-level Kemena3D engine namespace.
Definition kanimation.h:23
std::string kString
Standard string alias.
Definition kdatatype.h:42
glm::vec3 kVec3
3-component float vector.
Definition kdatatype.h:33