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/util/asset_manager.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/util/asset_manager.cc') diff --git a/src/util/asset_manager.cc b/src/util/asset_manager.cc index d4dd5c7..c12331c 100644 --- a/src/util/asset_manager.cc +++ b/src/util/asset_manager.cc @@ -153,6 +153,25 @@ TextureAsset GetTextureAsset(AssetId asset_id) { return {(int)header[0], (int)header[1], data + 8}; } +MeshAsset GetMeshAsset(AssetId asset_id) { + size_t size = 0; + const uint8_t* data = GetAsset(asset_id, &size); + if (!data || size < 8) { + return {0, nullptr, 0, nullptr}; + } + + const uint8_t* ptr = data; + uint32_t num_vertices = *reinterpret_cast(ptr); + ptr += sizeof(uint32_t); + const MeshVertex* vertices = reinterpret_cast(ptr); + ptr += num_vertices * sizeof(MeshVertex); + uint32_t num_indices = *reinterpret_cast(ptr); + ptr += sizeof(uint32_t); + const uint32_t* indices = reinterpret_cast(ptr); + + return {num_vertices, vertices, num_indices, indices}; +} + void DropAsset(AssetId asset_id, const uint8_t* asset) { uint16_t index = (uint16_t)asset_id; if (index >= (uint16_t)AssetId::ASSET_LAST_ID) { -- cgit v1.2.3