Model

SafiEngine::Model loads and renders 3D models from glTF/GLB files using modern OpenGL (VAOs + shaders).

Header: Core/include/Core/Model.h

MeshData

struct MeshData {
  std::vector<float> positions;   // 3 floats per vertex
  std::vector<float> normals;     // 3 floats per vertex
  std::vector<float> texcoords;   // 2 floats per vertex
  std::vector<uint32_t> indices;
};

A plain data struct holding raw vertex data for constructing a Model programmatically. Used internally by ProceduralMesh to generate primitive shapes.

FieldTypeDescription
positionsstd::vector<float>Vertex positions (3 per vertex)
normalsstd::vector<float>Vertex normals (3 per vertex)
texcoordsstd::vector<float>Texture coords (2 per vertex)
indicesstd::vector<uint32_t>Triangle indices

Methods

Load

bool Load(const std::string &path)

Loads a .glb (binary glTF) file. For each mesh primitive, it creates a VAO and extracts:

  • POSITION: vertex positions → VBO, vertex attrib location 0
  • NORMAL: vertex normals → VBO, vertex attrib location 1
  • TEXCOORD_0: texture coordinates → VBO, vertex attrib location 2
  • Indices: uploaded to an EBO (supports u8, u16, u32)
  • Material: PBR base color factor and base color texture

Returns true on success, false on failure (prints error to stderr).

ParameterTypeDescription
pathconst std::string&Path to the .glb file

GetCenter

glm::vec3 GetCenter() const

Returns the geometric center of the model's bounding box, computed from glTF accessor min/max values during Load(). The render system uses this to rotate entities around their visual center rather than the model origin.

Draw

void Draw(const Shader &shader) const

Renders all loaded meshes using the provided shader:

  • Sets uBaseColor uniform per mesh from the material's base color factor
  • Sets uHasTexture and binds the base color texture to sampler uTexture
  • Binds the mesh VAO and calls glDrawElements
ParameterTypeDescription
shaderconst Shader &The shader to set material uniforms on

CreateFromMeshData

static std::shared_ptr<Model> CreateFromMeshData(const MeshData &data);

Creates a Model from raw vertex data without loading any file. This is used internally by ProceduralMesh to build primitive shapes, but can also be used directly to create custom geometry.

ParameterTypeDescription
dataconst MeshData &Raw vertex and index data

Returns a shared_ptr<Model> ready for rendering, or nullptr on failure.

Supported glTF Features

FeatureStatus
Binary glTF (.glb)Supported
Triangle primitivesSupported
Positions & normalsSupported
Texture coordinatesSupported
PBR base color factorSupported
Base color textureSupported
AnimationsNot yet
SkinningNot yet
Multiple texture setsNot yet