model-gltf

Garnet glTF importer

require "garnet-model-gltf" decodes glTF 2.0 and GLB into Garnet::Model::Asset. Positions, UVs, normals, indices, node transforms, base color textures, skins and animation share the procedural model API. The importer reads interleaved and sparse accessors. It bakes default morph weights once and samples animated position and normal morphs before skinning. Clip fades blend morph weights and joint transforms together.

require "garnet-model-gltf"
require "garnet-graphics-stb"

source = Garnet::Content::FileSource.new("prop.glb")
asset = Garnet::GLTF.load(source, decoder: Garnet::Graphics::STBDecoder.new)

Requiring the shard registers a default "model" importer for .glb (GLTF::IMPORTER, see content). It decodes textures with Graphics::ImageDecoder.default? (set by garnet-graphics-stb), resolves external images next to the file, and makes thumbnails by rendering the model's meshes on the CPU (Graphics::Thumbnail.render). .gltf files usually reference external buffers, so track embedded ones explicitly with database.track(path, "model").

Embedded image bytes and external references use the caller's decoder. Pass resolve: Proc(String, Garnet::Content::Source) for external URIs. The caller owns the dependency namespace, so loading from an archive or bundle works through the same interface. Unsupported required extensions produce errors. Handled omissions are reported in asset.warnings. The built-in material shades base color, metallic and roughness factors, and emissive color and strength. It supports cutout, blended alpha, and unlit materials. With an image decoder, it binds untransformed primary-UV normal, metallic/roughness, occlusion, and emissive textures using their authored samplers. Data maps remain linear and emissive images use sRGB. primitive.surface_inputs retains the encoded references, UV sets and transforms for other material pipelines.

The binary layout and accessor conventions follow the Khronos glTF 2.0 specification.

Repository

model-gltf

Owner
Statistic
  • 0
  • 0
  • 0
  • 1
  • 2
  • about 17 hours ago
  • November 30, 2026
License

MIT License

Links
Synced at

Wed, 02 Dec 2026 13:44:45 GMT

Languages