gltf

package
v1.15.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: BSD-3-Clause Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

View Source
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

func Decode(ctx context.Context, r io.Reader, opts ...Options) (*model.Model, error)

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

func Load

func Load(ctx context.Context, fsys fs.FS, name string, opts ...Options) (*model.Model, error)

Load reads the glTF file name of fsys (.gltf or .glb), and the buffers and images that it names by a path from the same file system, in the directory of the file. The model's name is the file's base name without its extension, unless the options give one.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL