ADD: Update Docs
This commit is contained in:
@@ -640,7 +640,54 @@ void Engine::clear_all_instance_node_offsets(const std::string& instanceName)
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Lighting
|
||||
// Lighting - Directional (Sunlight)
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
void Engine::set_sunlight_direction(const glm::vec3& dir)
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
_engine->_sceneManager->setSunlightDirection(dir);
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Engine::get_sunlight_direction() const
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
return _engine->_sceneManager->getSunlightDirection();
|
||||
}
|
||||
return glm::vec3(0.0f, -1.0f, 0.0f);
|
||||
}
|
||||
|
||||
void Engine::set_sunlight_color(const glm::vec3& color, float intensity)
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
_engine->_sceneManager->setSunlightColor(color, intensity);
|
||||
}
|
||||
}
|
||||
|
||||
glm::vec3 Engine::get_sunlight_color() const
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
return _engine->_sceneManager->getSunlightColor();
|
||||
}
|
||||
return glm::vec3(1.0f);
|
||||
}
|
||||
|
||||
float Engine::get_sunlight_intensity() const
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
return _engine->_sceneManager->getSunlightIntensity();
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Lighting - Point Lights
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
size_t Engine::add_point_light(const PointLight& light)
|
||||
@@ -1139,6 +1186,19 @@ void Engine::hot_reload_shaders()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Time
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
float Engine::get_delta_time() const
|
||||
{
|
||||
if (_engine->_sceneManager)
|
||||
{
|
||||
return _engine->_sceneManager->getDeltaTime();
|
||||
}
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// Statistics
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
@@ -298,7 +298,20 @@ public:
|
||||
void clear_all_instance_node_offsets(const std::string& instanceName);
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Lighting
|
||||
// Lighting - Directional (Sunlight)
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Set sunlight direction (normalized automatically)
|
||||
void set_sunlight_direction(const glm::vec3& dir);
|
||||
glm::vec3 get_sunlight_direction() const;
|
||||
|
||||
// Set sunlight color and intensity
|
||||
void set_sunlight_color(const glm::vec3& color, float intensity);
|
||||
glm::vec3 get_sunlight_color() const;
|
||||
float get_sunlight_intensity() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Lighting - Point Lights
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Add point light (returns index)
|
||||
@@ -399,6 +412,13 @@ public:
|
||||
// Hot reload all changed shaders
|
||||
void hot_reload_shaders();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Time
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
// Get delta time in seconds for the current frame (clamped to 0.0-0.1)
|
||||
float get_delta_time() const;
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Statistics (read-only)
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
@@ -147,10 +147,13 @@ void SceneManager::update_scene()
|
||||
_camera_position_local = world_to_local(mainCamera.position_world, _origin_world);
|
||||
|
||||
// Simple per-frame dt (seconds) for animations
|
||||
static auto lastFrameTime = std::chrono::steady_clock::now();
|
||||
auto now = std::chrono::steady_clock::now();
|
||||
float dt = std::chrono::duration<float>(now - lastFrameTime).count();
|
||||
lastFrameTime = now;
|
||||
if (_lastFrameTime.time_since_epoch().count() == 0)
|
||||
{
|
||||
_lastFrameTime = now;
|
||||
}
|
||||
float dt = std::chrono::duration<float>(now - _lastFrameTime).count();
|
||||
_lastFrameTime = now;
|
||||
if (dt < 0.f)
|
||||
{
|
||||
dt = 0.f;
|
||||
@@ -159,6 +162,7 @@ void SceneManager::update_scene()
|
||||
{
|
||||
dt = 0.1f;
|
||||
}
|
||||
_deltaTime = dt;
|
||||
|
||||
auto tagOwner = [&](RenderObject::OwnerType type, const std::string &name,
|
||||
size_t opaqueBegin, size_t transpBegin)
|
||||
@@ -888,3 +892,29 @@ bool SceneManager::setGLTFInstanceAnimationLoop(const std::string &instanceName,
|
||||
it->second.animation.animationLoop = loop;
|
||||
return true;
|
||||
}
|
||||
|
||||
void SceneManager::setSunlightDirection(const glm::vec3& dir)
|
||||
{
|
||||
glm::vec3 normalized = glm::normalize(dir);
|
||||
sceneData.sunlightDirection = glm::vec4(normalized, sceneData.sunlightDirection.w);
|
||||
}
|
||||
|
||||
glm::vec3 SceneManager::getSunlightDirection() const
|
||||
{
|
||||
return glm::vec3(sceneData.sunlightDirection);
|
||||
}
|
||||
|
||||
void SceneManager::setSunlightColor(const glm::vec3& color, float intensity)
|
||||
{
|
||||
sceneData.sunlightColor = glm::vec4(color, intensity);
|
||||
}
|
||||
|
||||
glm::vec3 SceneManager::getSunlightColor() const
|
||||
{
|
||||
return glm::vec3(sceneData.sunlightColor);
|
||||
}
|
||||
|
||||
float SceneManager::getSunlightIntensity() const
|
||||
{
|
||||
return sceneData.sunlightColor.w;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include <unordered_map>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <chrono>
|
||||
#include <glm/vec2.hpp>
|
||||
#include <string>
|
||||
|
||||
@@ -85,6 +86,16 @@ public:
|
||||
void selectRect(const glm::vec2 &p0, const glm::vec2 &p1, std::vector<RenderObject> &outObjects) const;
|
||||
|
||||
const GPUSceneData &getSceneData() const { return sceneData; }
|
||||
|
||||
// Sunlight (directional light) access
|
||||
void setSunlightDirection(const glm::vec3& dir);
|
||||
glm::vec3 getSunlightDirection() const;
|
||||
void setSunlightColor(const glm::vec3& color, float intensity);
|
||||
glm::vec3 getSunlightColor() const;
|
||||
float getSunlightIntensity() const;
|
||||
|
||||
// Delta time (seconds) for the current frame
|
||||
float getDeltaTime() const { return _deltaTime; }
|
||||
DrawContext &getMainDrawContext() { return mainDrawContext; }
|
||||
|
||||
void loadScene(const std::string &name, std::shared_ptr<LoadedGLTF> scene);
|
||||
@@ -203,6 +214,8 @@ private:
|
||||
glm::vec3 _camera_position_local{0.0f, 0.0f, 0.0f};
|
||||
double _floating_origin_recenter_threshold = 1000.0;
|
||||
double _floating_origin_snap_size = 100.0;
|
||||
float _deltaTime = 0.0f;
|
||||
std::chrono::steady_clock::time_point _lastFrameTime{};
|
||||
|
||||
std::unordered_map<std::string, std::shared_ptr<LoadedGLTF> > loadedScenes;
|
||||
// Per-named static glTF scene animation state (independent of instances).
|
||||
|
||||
Reference in New Issue
Block a user