obj

package
v1.17.11 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2026 License: BSD-3-Clause Imports: 14 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 obj reads Wavefront OBJ files, with the subset of MTL that matters to a viewer, into a model.Model (SPEC §27.9).

Positions, texture coordinates and normals are read with negative indices (counted back from the last one read), polygons are cut into triangles (a fan when they are convex, ear clipping when not), `o` and `g` make the nodes, `usemtl` splits the faces of a node into one mesh for each material, and `l` and `p` make meshes of lines and of points. The material library named by `mtllib` is read through the same file system as the OBJ file; Kd, Ks, Ns, d and map_Kd are taken, and a library that is not there gives the default material and one line in the log. A position may have colors after it (`v x y z r g b`).

The texture coordinate v is turned (v becomes 1-v) so that the model's texture coordinates have their origin at the top left, like the images of Glutter.

Index

Constants

View Source
const TagOBJInvalid = "OBJInvalid"

TagOBJInvalid is the tag of the error of a file that is not a valid OBJ file: a number that is not one, an index that is zero or beyond the data, a face with fewer than three corners. The metadata has "line" and "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 an OBJ file from r. It checks ctx while it reads and parses.

It fails with model.TagModelReadFailed when the reader fails or ctx is done, and with TagOBJInvalid for a file that is not OBJ.

Flutter: no counterpart

func Load

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

Load reads the OBJ file name of fsys, and the material libraries and images that it names 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 and of the node that holds the faces that come before any `o` or `g`. Load sets the base name of
	// the file when it is empty.
	Name string
	// Float64 keeps the positions in float64 when some of them have more digits than a float32 holds.
	Float64 bool
	// FS is where `mtllib` files and the images of materials are read from; Dir is the directory in it that paths are relative to.
	// Load sets both from its arguments. Without FS, a material library is not read, with one line in the log.
	FS  fs.FS
	Dir string
	// Logger gets the notes of the loader (a material library that cannot be read); 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