Class GltfLoader¶
Defined in File gltf_loader.h
Inheritance Relationships¶
Base Type¶
public portal::resources::ResourceLoader(Class ResourceLoader)
Class Documentation¶
-
class GltfLoader : public portal::resources::ResourceLoader¶
Loader for GLTF composite resources.
The GltfLoader handles loading GLTF (.gltf, .glb) files, which are composite resources that contain multiple embedded assets within a single file. A GLTF file can contain:
Multiple textures (PNG, JPEG embedded or referenced)
Multiple materials (PBR material definitions)
Multiple meshes (vertex data, primitives)
Multiple scenes (entity hierarchies with transforms)
GLTF loading happens in two phases:
Metadata Enrichment: The database calls enrich_metadata() during filesystem scanning to discover child resources. This parses the GLTF file and creates SourceMetadata entries for each texture, material, mesh, and scene found. These are stored in CompositeMetadata::children.
Resource Loading: When the registry loads the GLTF, load() is called. It iterates through the children and loads each one by dispatching jobs through the registry. The main composite resource tracks these child references.
Usage Example:
// Loading a GLTF creates a composite with child resources auto gltf_ref = registry.load<Composite>(STRING_ID("models/character.gltf")); // Wait for loading to complete while (!gltf_ref.is_valid()) { // Show loading screen } // Access child resources through the composite auto& composite = gltf_ref.get(); auto mesh_ref = composite.get_mesh("character_body"); auto material_ref = composite.get_material("skin_material"); auto scene_ref = composite.get_scene("default_scene");
Dependencies:
Uses fastgltf library for GLTF parsing (https://github.com/spnda/fastgltf)
Requires RendererContext for creating GPU resources
See also
enrich_metadata() for the metadata discovery phase
See also
load() for the loading phase
See also
CompositeMetadata for how children are stored
See also
ResourceType::Composite for the composite resource type
Public Functions
-
GltfLoader(ResourceRegistry ®istry, const renderer::vulkan::VulkanContext &context)¶
Constructor.
- Parameters:
registry – Reference to ResourceRegistry for loading child resources
context – Reference to VulkanContext
-
virtual Reference<Resource> load(const SourceMetadata &meta, const ResourceSource &source) override¶
Load a GLTF composite resource and all its children.
Note
This method blocks until the GLTF is parsed and child jobs are dispatched
Note
Child resources load asynchronously on the job system
- Parameters:
meta – Metadata with CompositeMetadata::children populated by enrich_metadata()
source – ResourceSource for reading the GLTF file bytes
- Returns:
Reference to Composite resource, or nullptr on error
Public Static Functions
-
static void enrich_metadata(SourceMetadata &meta, const ResourceSource &source)¶
Enrich metadata by discovering child resources in a GLTF file.
This static method is called during database filesystem scanning. It parses the GLTF file to discover all embedded assets and creates SourceMetadata entries for each child resource. These are stored in CompositeMetadata::children.
Discovered children include:
Textures: Each image in the GLTF creates a texture child
Materials: Each material creates a material child with texture dependencies
Meshes: Each mesh creates a mesh child
Scenes: Each scene creates a scene child with mesh/material dependencies
Note
This is called during database scanning, before any loading occurs
Note
The metadata is persisted to .portal-db to avoid re-parsing on startup
- Parameters:
meta – SourceMetadata to enrich (will be updated with CompositeMetadata)
source – ResourceSource for reading the GLTF file
Protected Functions
-
Job load_texture(SourceMetadata texture_meta, const fastgltf::Asset &asset, const fastgltf::Texture &texture) const¶
-
Job load_material(SourceMetadata material_meta, const fastgltf::Asset &asset, const fastgltf::Material &material) const¶
-
Job load_mesh(SourceMetadata mesh_meta, const fastgltf::Asset &asset, const fastgltf::Mesh &mesh) const¶
-
void load_scenes(SourceMetadata meta, const fastgltf::Asset &asset) const¶
Protected Attributes
-
const renderer::vulkan::VulkanContext &context¶
-
Reference<renderer::vulkan::VulkanPipeline> g_transparent_pipeline¶
-
Reference<renderer::vulkan::VulkanPipeline> g_color_pipeline¶
Protected Static Functions
-
static fastgltf::Asset load_asset(const SourceMetadata &meta, fastgltf::GltfDataGetter &data)¶
-
static std::pair<SourceMetadata, std::unique_ptr<ResourceSource>> find_image_source(const std::filesystem::path &base_name, const std::filesystem::path &base_path, const fastgltf::Asset &asset, const fastgltf::Texture &texture)¶