diff options
| author | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
|---|---|---|
| committer | 3gg <3gg@shellblade.net> | 2025-12-27 12:03:39 -0800 |
| commit | 5a079a2d114f96d4847d1ee305d5b7c16eeec50e (patch) | |
| tree | 8926ab44f168acf787d8e19608857b3af0f82758 /include/model.h | |
Initial commit
Diffstat (limited to 'include/model.h')
| -rw-r--r-- | include/model.h | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/include/model.h b/include/model.h new file mode 100644 index 0000000..9e93993 --- /dev/null +++ b/include/model.h | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | #pragma once | ||
| 2 | |||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | typedef uint16_t mdIdx; | ||
| 6 | typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert; | ||
| 7 | typedef struct mdTri { mdVert v0, v1, v2; } mdTri; | ||
| 8 | typedef struct mdVec2 { float x, y; } mdVec2; | ||
| 9 | typedef struct mdVec3 { float x, y, z; } mdVec3; | ||
| 10 | |||
| 11 | // Every three indices form a triangle, and each index indexes all attribute | ||
| 12 | // arrays simultaneously. This is best for a fast, linear-scan rendering. | ||
| 13 | // This is what you would render with glDrawElements(). | ||
| 14 | typedef struct FlatModel { | ||
| 15 | // Counts. | ||
| 16 | uint32_t numIdxs; | ||
| 17 | uint32_t numVerts; | ||
| 18 | // Offsets. | ||
| 19 | uint32_t offsetIdxs; | ||
| 20 | uint32_t offsetPositions; | ||
| 21 | uint32_t offsetNormals; | ||
| 22 | uint32_t offsetTexcoords; | ||
| 23 | /* | ||
| 24 | [indices] -- numIdxs mdIdx | ||
| 25 | [positions] -- numVerts mdVec3 | ||
| 26 | [normals] -- numVerts mdVec3 | ||
| 27 | [texcoords] -- numVerts mdVec2 | ||
| 28 | */ | ||
| 29 | uint8_t data[]; | ||
| 30 | } FlatModel; | ||
| 31 | |||
| 32 | // Every triangle is made up of three vertices, and each vertex holds one index | ||
| 33 | // for each of the attribute arrays. This allows for a smaller representation of | ||
| 34 | // some models by virtue of being able to re-use attributes across vertices. | ||
| 35 | // This is the sort of format that OBJ follows, where the indices to each array | ||
| 36 | // given by a face may be non-uniform. | ||
| 37 | typedef struct IndexedModel { | ||
| 38 | // Counts. | ||
| 39 | uint32_t numTris; | ||
| 40 | uint32_t numPositions; | ||
| 41 | uint32_t numNormals; | ||
| 42 | uint32_t numTexcoords; | ||
| 43 | // Offsets. | ||
| 44 | uint32_t offsetTris; | ||
| 45 | uint32_t offsetPositions; | ||
| 46 | uint32_t offsetNormals; | ||
| 47 | uint32_t offsetTexcoords; | ||
| 48 | /* | ||
| 49 | [triangles] -- numTris mdTri | ||
| 50 | [positions] -- numPositions mdVec3 | ||
| 51 | [normals] -- numNormals mdVec3 | ||
| 52 | [texcoords] -- numTexcoords mdVec2 | ||
| 53 | */ | ||
| 54 | uint8_t data[]; | ||
| 55 | } IndexedModel; | ||
| 56 | |||
| 57 | typedef enum ModelType { | ||
| 58 | ModelTypeFlat, | ||
| 59 | ModelTypeIndexed | ||
| 60 | } ModelType; | ||
| 61 | |||
| 62 | typedef struct Model { | ||
| 63 | uint32_t type; | ||
| 64 | union { | ||
| 65 | FlatModel flat; | ||
| 66 | IndexedModel indexed; | ||
| 67 | }; | ||
| 68 | } Model; | ||
