From b68c8d8cbe9274e42a89888186152d4ded1a2962 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 06:51:16 +0100 Subject: feat(3d): Implement basic OBJ mesh asset pipeline Added support for loading and rendering OBJ meshes. - Updated asset_packer to parse .obj files into a binary format. - Added MeshAsset and GetMeshAsset helper to asset_manager. - Extended Object3D with mesh_asset_id and ObjectType::MESH. - Implemented mesh rasterization pipeline in Renderer3D. - Added a sample cube mesh and verified in test_3d_render. --- src/3d/renderer.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'src/3d/renderer.h') diff --git a/src/3d/renderer.h b/src/3d/renderer.h index db86b72..5caf19b 100644 --- a/src/3d/renderer.h +++ b/src/3d/renderer.h @@ -8,6 +8,7 @@ #include "3d/scene.h" #include "3d/bvh.h" #include "gpu/gpu.h" +#include #include #if !defined(STRIP_ALL) @@ -65,11 +66,19 @@ class Renderer3D { void SetBvhEnabled(bool enabled) { bvh_enabled_ = enabled; } private: + struct MeshGpuData { + WGPUBuffer vertex_buffer; + WGPUBuffer index_buffer; + uint32_t num_indices; + }; + void create_pipeline(); WGPURenderPipeline create_pipeline_impl(bool use_bvh); + void create_mesh_pipeline(); void create_skybox_pipeline(); void create_default_resources(); void update_uniforms(const Scene& scene, const Camera& camera, float time); + const MeshGpuData* get_or_create_mesh(AssetId asset_id); WGPUDevice device_ = nullptr; WGPUQueue queue_ = nullptr; @@ -78,6 +87,7 @@ class Renderer3D { WGPURenderPipeline pipeline_ = nullptr; // BVH enabled WGPURenderPipeline pipeline_no_bvh_ = nullptr; // BVH disabled WGPUBindGroup bind_group_ = nullptr; + WGPURenderPipeline mesh_pipeline_ = nullptr; WGPURenderPipeline skybox_pipeline_ = nullptr; WGPUBindGroup skybox_bind_group_ = nullptr; WGPUBuffer global_uniform_buffer_ = nullptr; @@ -87,6 +97,8 @@ class Renderer3D { BVH cpu_bvh_; // Keep a CPU-side copy for building/uploading bool bvh_enabled_ = true; + std::map mesh_cache_; + WGPUTextureView noise_texture_view_ = nullptr; WGPUTextureView sky_texture_view_ = nullptr; WGPUSampler default_sampler_ = nullptr; -- cgit v1.2.3