summaryrefslogtreecommitdiff
path: root/src/util/asset_manager.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-06 06:51:16 +0100
committerskal <pascal.massimino@gmail.com>2026-02-06 06:51:16 +0100
commitb68c8d8cbe9274e42a89888186152d4ded1a2962 (patch)
tree0d0d64ecaad2dadd29a4eff3daeb96867437d1ae /src/util/asset_manager.cc
parent32a6d4f516b2ff45e25ddc7870e5400c2973fb9a (diff)
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.
Diffstat (limited to 'src/util/asset_manager.cc')
-rw-r--r--src/util/asset_manager.cc19
1 files changed, 19 insertions, 0 deletions
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<const uint32_t*>(ptr);
+ ptr += sizeof(uint32_t);
+ const MeshVertex* vertices = reinterpret_cast<const MeshVertex*>(ptr);
+ ptr += num_vertices * sizeof(MeshVertex);
+ uint32_t num_indices = *reinterpret_cast<const uint32_t*>(ptr);
+ ptr += sizeof(uint32_t);
+ const uint32_t* indices = reinterpret_cast<const uint32_t*>(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) {