56 size_t len = strlen(tex.
name);
57 while (len > 0 && (tex.
name[len - 1] ==
'\0' || tex.
name[len - 1] ==
' ' || tex.
name[len - 1] ==
'\r'))
59 tex.
name[--len] =
'\0';
68 uint32_t byteLength = 0;
70 if (fread(imgName, 1, 32, f) != 32 || fread(&byteLength,
sizeof(uint32_t), 1, f) != 1)
80 size_t alignedWords = (
static_cast<size_t>(byteLength) + 3) / 4;
81 uint32_t* alignedBuffer =
static_cast<uint32_t*
>(malloc(alignedWords * 4));
88 if (fread(alignedBuffer, 1, byteLength, f) !=
static_cast<size_t>(byteLength))
100 GL_TEXTURE_TYPE_ENUM texType = tex.
isRGBA ? GL_RGBA : GL_RGB16;
105 TEXGEN_TEXCOORD | GL_TEXTURE_WRAP_S | GL_TEXTURE_WRAP_T,
117 if (meshFilePath ==
nullptr)
123 FILE* f = fopen(meshFilePath->c_str(),
"rb");
130 model = std::make_unique<MDL3Model>();
141 if (memcmp(rawHeader.
magic,
"MDL3", 4) != 0)
161 for (uint32_t i = 0; i <
model->texCount; ++i)
173 for (uint32_t i = 0; i <
model->nodeCount; ++i)
189 if (fread(&sl.
texSlot,
sizeof(int32_t), 1, f) != 1 || fread(&sl.
dlSize,
sizeof(uint32_t), 1, f) != 1)
199 uint32_t* displayList =
new uint32_t[sl.
dlSize + 1];
200 displayList[0] = sl.
dlSize;
201 if (fread(&displayList[1],
sizeof(std::uint32_t), sl.
dlSize, f) !=
static_cast<size_t>(sl.
dlSize))
209 model->nodes[i].subLists.push_back(std::move(sl));
223 for (uint32_t i = 0; i <
model->texCount; ++i)
Orchestrates rendering models from a 3D model file.
void drawMesh()
Draws the loaded mesh to the screen.
std::unique_ptr< MDL3Model > model
void update(ae::q20_12_t) override
Draws the mesh to the screen every frame.
void destroy() override
Sets active to false on component destruction.
bool loadMesh(std::string *meshFilePath)
Loads a mesh from a file into memory.
bool loadTextureHeader(FILE *f, MDL3Texture &tex)
Loads a texture header from the file buffer into memory.
bool loadTexture(FILE *f, MDL3Texture &tex)
Loads an embedded texture from the file buffer and uploads it to the GPU.
void logMessage(LogSeverity severity, std::string_view message, std::source_location location)
Logs a diagnostic message and halts only for fatal messages.
Util to handle error logging.
Represents a texture used in a 3D model.
Represents a node in the 3D model.
etl::vector< SubList_N, 64 > subLists
Represents a sublist of a node in the 3D model.
const uint32_t * displayList