diff options
Diffstat (limited to 'src/util')
| -rw-r--r-- | src/util/asset_manager.cc | 19 | ||||
| -rw-r--r-- | src/util/asset_manager.h | 16 |
2 files changed, 35 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) { diff --git a/src/util/asset_manager.h b/src/util/asset_manager.h index a78447d..0c2cc63 100644 --- a/src/util/asset_manager.h +++ b/src/util/asset_manager.h @@ -39,6 +39,22 @@ struct TextureAsset { const uint8_t* pixels; }; +struct MeshVertex { + float p[3]; + float n[3]; + float u[2]; +}; + +struct MeshAsset { + uint32_t num_vertices; + const MeshVertex* vertices; + uint32_t num_indices; + const uint32_t* indices; +}; + // Helper to retrieve and parse a simple texture asset (from packer's // [w][h][pixels] format) TextureAsset GetTextureAsset(AssetId asset_id); + +// Helper to retrieve and parse a mesh asset (from packer's binary format) +MeshAsset GetMeshAsset(AssetId asset_id); |
