From fdaa55621fc7f815c236520ff65033eb8c8c6ca0 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Tue, 30 Dec 2025 17:25:44 -0800 Subject: Parse diffuse texture from material --- include/model.h | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'include') diff --git a/include/model.h b/include/model.h index 9e93993..0730809 100644 --- a/include/model.h +++ b/include/model.h @@ -1,13 +1,20 @@ #pragma once +#include #include +constexpr size_t ModelPathLen = 256; + typedef uint16_t mdIdx; -typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert; +typedef struct mdVert { mdIdx position, texcoord, normal; } mdVert; typedef struct mdTri { mdVert v0, v1, v2; } mdTri; typedef struct mdVec2 { float x, y; } mdVec2; typedef struct mdVec3 { float x, y, z; } mdVec3; +typedef struct Material { + char diffuseTexture[ModelPathLen]; +} Material; + // Every three indices form a triangle, and each index indexes all attribute // arrays simultaneously. This is best for a fast, linear-scan rendering. // This is what you would render with glDrawElements(). @@ -18,13 +25,13 @@ typedef struct FlatModel { // Offsets. uint32_t offsetIdxs; uint32_t offsetPositions; - uint32_t offsetNormals; uint32_t offsetTexcoords; + uint32_t offsetNormals; /* [indices] -- numIdxs mdIdx [positions] -- numVerts mdVec3 - [normals] -- numVerts mdVec3 [texcoords] -- numVerts mdVec2 + [normals] -- numVerts mdVec3 */ uint8_t data[]; } FlatModel; @@ -38,18 +45,18 @@ typedef struct IndexedModel { // Counts. uint32_t numTris; uint32_t numPositions; - uint32_t numNormals; uint32_t numTexcoords; + uint32_t numNormals; // Offsets. uint32_t offsetTris; uint32_t offsetPositions; - uint32_t offsetNormals; uint32_t offsetTexcoords; + uint32_t offsetNormals; /* [triangles] -- numTris mdTri [positions] -- numPositions mdVec3 - [normals] -- numNormals mdVec3 [texcoords] -- numTexcoords mdVec2 + [normals] -- numNormals mdVec3 */ uint8_t data[]; } IndexedModel; @@ -61,6 +68,7 @@ typedef enum ModelType { typedef struct Model { uint32_t type; + Material material; union { FlatModel flat; IndexedModel indexed; -- cgit v1.2.3