Documentation
¶
Overview ¶
Package gltf reads glTF 2.0 files, the text kind (.gltf, with its buffers and images in files or in data: URIs) and the binary kind (.glb), into a model.Model (SPEC §28.5).
It reads meshes (every kind of primitive, made into lists of triangles, segments or points), materials of the metallic-roughness model with their textures and samplers, nodes, cameras, skins, morph targets, animations (as data: viewport3d plays them) and scenes. Accessors may be strided, sparse, normalized and quantized. The extensions that it reads are KHR_mesh_quantization, KHR_texture_transform, KHR_materials_emissive_strength, KHR_materials_unlit, KHR_lights_punctual and EXT_meshopt_compression. An extension that the file requires and that the package does not know (Draco, KTX2 and Basis among them) is an error; one that the file only uses is left out and noted once in the log.
The format is the specification of the Khronos Group (https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html) and of its extensions; the decoder of EXT_meshopt_compression is internal/meshopt.
Index ¶
Constants ¶
const TagGLTFExtensionUnsupported = "GLTFExtensionUnsupported"
TagGLTFExtensionUnsupported is the tag of the error of a file that requires an extension that this package does not read (Draco and KTX2 or Basis textures among them). The metadata has "extension", its name, and "path", "/extensionsRequired/<index>".
Flutter: no counterpart
const TagGLTFInvalid = "GLTFInvalid"
TagGLTFInvalid is the tag of the error of a file that is not valid glTF 2.0: a container or JSON that is malformed, an index that points nowhere, an accessor that reaches past its buffer, a component type that the attribute cannot have, data that does not decode. The metadata has "path", the JSON pointer of the place of the failure ("/meshes/0/primitives/1/attributes/NORMAL", empty for the whole file), and "reason"; "offset" is the byte of a binary container or of the JSON, "file" the name of the file that Load read, and a failure of a compressed buffer has "cause" with the decoder's reason.
Flutter: no counterpart
Variables ¶
This section is empty.
Functions ¶
func Decode ¶
Decode reads a glTF file, text or binary (it is told by the first four bytes), from r. It checks ctx while it reads and builds.
It fails with model.TagModelReadFailed when the reader or the file system fails or ctx is done, with TagGLTFInvalid for a file that is not valid glTF 2.0, and with TagGLTFExtensionUnsupported for a file that requires an extension that is not read.
Flutter: no counterpart
Types ¶
type Options ¶
type Options struct {
// Name is the name of the model. Load sets the base name of the file when it is empty.
Name string
// FS is where the buffers and the images that a .gltf file names by a path are read from; Dir is the directory in it that the
// paths are relative to. Load sets both from its arguments. Without FS, a file that names a path fails with
// model.TagModelReadFailed (a .glb file and data: URIs need none).
FS fs.FS
Dir string
// Logger gets the notes of the loader (an extension that is left out, a primitive that has nothing to draw);
// slog.Default() when nil.
Logger *slog.Logger
}
Options are the options of Decode and Load.
Flutter: no counterpart