Class GltfLoader#

Class Documentation#

class GltfLoader#

Loads .gltf/.glb geometry into the SAME CPU-side arrays ObjLoader produces, so it plugs into Model/Mesh and the AsyncModelParse worker unchanged. Touches no Vulkan - that is the point, the parse is the expensive part worth moving off the render thread.

Increment b: geometry (positions/normals/UVs, indices, baked node transforms) plus a single neutral material. Per-material import and texture resolution are follow-ups (see BACKLOG glTF increments c/d).

Public Functions

GltfLoader(std::shared_ptr<VulkanDevice> device, vk::CommandPool command_pool)#

Device-owning: loadModel can upload. parseCpu alone needs no device, so the default constructor stays available for the CPU-only path.

GltfLoader() = default#
std::shared_ptr<Model> loadModel(const std::string &modelFile)#

Parses modelFile then builds the Vulkan-side Model from it - i.e. parseCpu + uploadParsed. Returns nullptr on a device-free loader or a failed parse.

std::shared_ptr<Model> uploadParsed()#

Builds the Vulkan-side Model from the LAST parseCpu result - the GPU half, separated so a device-free worker can parse and a device-owning loader upload (the async split). Must run on the thread owning the device; returns nullptr on a device-free loader or before a successful parse. Mirrors ObjLoader so AsyncModelParse can drive glTF the same way.

void adoptParsed(GltfLoader &&other)#

Moves another loader’s parse results in, so a device-owning loader can upload what a device-free worker produced without copying the arrays.

bool parseCpu(const std::string &modelFile)#

Parses the document into vertices/indices/materials/materialIndex. Returns false on a missing or malformed file, leaving the instance empty.

inline const std::vector<Vertex> &getVertices() const#
inline const std::vector<unsigned int> &getIndices() const#
inline const std::vector<ObjMaterial> &getMaterials() const#
inline const std::vector<unsigned int> &getMaterialIndices() const#
inline const std::vector<std::vector<unsigned char>> &getTextureImages() const#

Encoded base-colour image bytes (PNG/JPG…), one entry per distinct image; materials sharing an image share a slot, indexed by that material’s textureID. loadModel decodes and uploads them via Texture::createFromMemory; a test can assert the CPU extraction without a device.

inline const std::vector<GltfSamplerDesc> &getTextureSamplerDescs() const#

The glTF sampler (wrap modes + filters) each entry of getTextureImages() was authored with, index-parallel with it. Two textures sharing one image but naming different samplers get distinct slots (see parseCpu’s dedup key), so this stays index-parallel rather than needing its own lookup.

inline const std::vector<unsigned char> &getTextureSrgbFlags() const#

Colour space each entry of getTextureImages() was authored in, index-parallel with it: 1 for sRGB (base colour, emissive), 0 for linear (normal maps). unsigned char, not std::vector<bool> - the proxy reference is a trap in a parallel-array getter. An image used as both base colour and normal map gets two slots, one per colour space, since a slot can only carry one image format.

inline const std::vector<MeshRange> &getMeshRanges() const#