diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-08 14:25:34 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-08 14:25:34 +0100 |
| commit | c68817059b882506bacc09694b0ac58dbe6c13a6 (patch) | |
| tree | e7989a3df7aa5769169ffa3477769db140688a2f /src/3d/scene_loader.cc | |
| parent | 50edd9f0e0565be643dda467bc240d9281277a8c (diff) | |
feat: Integrate plane_distance into renderer and scene loader
This commit integrates the plane_distance functionality by:
- Adding shared_user_data to Object3D for storing type-specific data.
- Modifying SceneLoader to read and store plane_distance in shared_user_data for PLANE objects.
- Updating ObjectData struct in renderer.h to use params.x for object type and params.y for plane_distance.
- Modifying Renderer3D::update_uniforms to populate ObjectData::params.y with plane_distance for PLANE objects.
- Adjusting blender_export.py to correctly export plane_distance and reorder quaternion components.
A manual step is required to update WGSL shaders to utilize ObjectData.params.y for plane distance calculations.
Diffstat (limited to 'src/3d/scene_loader.cc')
| -rw-r--r-- | src/3d/scene_loader.cc | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/src/3d/scene_loader.cc b/src/3d/scene_loader.cc index 669fac8..e9e769b 100644 --- a/src/3d/scene_loader.cc +++ b/src/3d/scene_loader.cc @@ -5,6 +5,13 @@ #include <cstdio> #include <cstring> #include <vector> +#include <memory> // For std::shared_ptr +#include <new> // For std::nothrow + +// Local struct to hold plane-specific data +struct PlaneData { + float distance; +}; bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { if (!data || size < 16) { // Header size check @@ -79,10 +86,16 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { offset += 4; float cb = *reinterpret_cast<const float*>(data + offset); offset += 4; - float ca = *reinterpret_cast<const float*>(data + offset); - offset += 4; vec4 color(cr, cg, cb, ca); + // Plane Distance (if type == PLANE) + float plane_distance = 0.0f; + if (type == ObjectType::PLANE) { + if (offset + 4 > size) return false; + plane_distance = *reinterpret_cast<const float*>(data + offset); + offset += 4; + } + // Mesh Asset Name Length if (offset + 4 > size) return false; @@ -132,6 +145,16 @@ bool SceneLoader::LoadScene(Scene& scene, const uint8_t* data, size_t size) { obj.is_static = is_static; // user_data is nullptr by default + // Store plane distance in shared_user_data if it's a plane + if (type == ObjectType::PLANE) { + // Allocate PlaneData on the heap and manage with shared_ptr + // Use std::make_shared for exception safety and efficiency + obj.shared_user_data = std::make_shared<PlaneData>(); + // Assign the plane distance + // Safely cast void* to PlaneData* using static_cast on the shared_ptr's get() + static_cast<PlaneData*>(obj.shared_user_data.get())->distance = plane_distance; + } + // Add to scene scene.add_object(obj); } |
