GltfLoader class final

Decodes glTF 2.0 and GLB into engine geometry.

Scope: geometry, node hierarchy, metal-rough materials, skinning and animation. This paragraph said for a long time that the last two were "parsed as far as the node graph but not yet turned into engine data", and two thirds of that had stopped being true: JOINTS_0/WEIGHTS_0 become a ModelSkin and the skinned vertex stage, and a channel becomes an AnimationClip an AnimationPlayer runs.

Morph targets are the third, and this paragraph also used to say they were read past and dropped. A primitive's targets become MeshData.morphTargets, its extras.targetNames become their names, and a target with no POSITION — legal glTF, meaning "morphs only normals", which nothing here blends — is skipped with a warning through GltfAsset.warnings rather than silently, the same channel every other non-fatal gap in this loader already reports through.

Compressed geometry is decoded, both kinds. EXT_meshopt_compression lives on a buffer view and is undone by GltfAccessorReader before an accessor reads a byte. KHR_draco_mesh_compression lives on a primitive and is undone in gltf_loader_mesh.dart, which puts the decoded values behind the primitive's own accessors. A payload that does not decode is reported through GltfAsset.warnings with the decoder's reason rather than thrown, so one bad primitive — or a file that merely offers a compressed variant beside an uncompressed one — still loads.

Implemented types

Constructors

GltfLoader({VertexLayout layout = VertexLayout.standard, VertexLayout skinnedLayout = VertexLayout.skinned, bool generateFlatNormalsWhenMissing = true})

Properties

generateFlatNormalsWhenMissing → bool
glTF says a primitive without NORMAL must be shaded flat. Flat shading needs per-face normals, which forces the mesh to be de-indexed. Set false to leave normals at zero instead.
final
hashCode → int
The hash code for this object.
no setterinherited
layout → VertexLayout
Target vertex layout. Attributes the layout does not declare are skipped during decode instead of being read and thrown away.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
skinnedLayout → VertexLayout
Used instead of layout for a primitive that carries JOINTS_0 and WEIGHTS_0.
final

Methods

decode(Uint8List bytes, ModelLoadRequest request, AssetUriResolver resolveUri) → Future<ModelDocument>
Reads bytes into a document.
override
handles(String fileName, Uint8List bytes) → bool
A .gltf or .glb by name, or a GLB by its glTF magic.
override
load(Uint8List bytes, {AssetUriResolver? resolveUri}) → Future<GltfAsset>
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited