From 5a079a2d114f96d4847d1ee305d5b7c16eeec50e Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 27 Dec 2025 12:03:39 -0800 Subject: Initial commit --- include/model.h | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 include/model.h (limited to 'include') 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 @@ +#pragma once + +#include + +typedef uint16_t mdIdx; +typedef struct mdVert { mdIdx position, normal, texcoord; } mdVert; +typedef struct mdTri { mdVert v0, v1, v2; } mdTri; +typedef struct mdVec2 { float x, y; } mdVec2; +typedef struct mdVec3 { float x, y, z; } mdVec3; + +// 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(). +typedef struct FlatModel { + // Counts. + uint32_t numIdxs; + uint32_t numVerts; + // Offsets. + uint32_t offsetIdxs; + uint32_t offsetPositions; + uint32_t offsetNormals; + uint32_t offsetTexcoords; + /* + [indices] -- numIdxs mdIdx + [positions] -- numVerts mdVec3 + [normals] -- numVerts mdVec3 + [texcoords] -- numVerts mdVec2 + */ + uint8_t data[]; +} FlatModel; + +// Every triangle is made up of three vertices, and each vertex holds one index +// for each of the attribute arrays. This allows for a smaller representation of +// some models by virtue of being able to re-use attributes across vertices. +// This is the sort of format that OBJ follows, where the indices to each array +// given by a face may be non-uniform. +typedef struct IndexedModel { + // Counts. + uint32_t numTris; + uint32_t numPositions; + uint32_t numNormals; + uint32_t numTexcoords; + // Offsets. + uint32_t offsetTris; + uint32_t offsetPositions; + uint32_t offsetNormals; + uint32_t offsetTexcoords; + /* + [triangles] -- numTris mdTri + [positions] -- numPositions mdVec3 + [normals] -- numNormals mdVec3 + [texcoords] -- numTexcoords mdVec2 + */ + uint8_t data[]; +} IndexedModel; + +typedef enum ModelType { + ModelTypeFlat, + ModelTypeIndexed +} ModelType; + +typedef struct Model { + uint32_t type; + union { + FlatModel flat; + IndexedModel indexed; + }; +} Model; -- cgit v1.2.3