stl

package
v1.17.6 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: BSD-3-Clause Imports: 17 Imported by: ? modules, 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 stl reads STL files, the binary and the ASCII kind (SPEC §27.9), into a model.Model.

The kind is told by the content, not by the header: a binary file is one whose size is 84 bytes plus 50 for each triangle that its count says, even when its header begins with "solid" (a habit of some writers). Binary files may give a color for each triangle in the two attribute bytes, by the VisCAM and SolidView convention. Equal vertices are welded (exactly, or within a tolerance), and the normals are smooth across edges whose faces differ by less than a crease angle.

Index

Constants

View Source
const DefaultCreaseAngle = math.Pi / 6

DefaultCreaseAngle is the angle between the normals of two triangles at a vertex above which the vertex is split in two, so that the edge stays sharp: 30 degrees.

Flutter: no counterpart

View Source
const TagSTLInvalid = "STLInvalid"

TagSTLInvalid is the tag of the error of a file that is not a valid STL file: a truncated binary file, a number that is not one or that is not finite, a keyword in the wrong place, a file with no triangle. The metadata has "offset" (the byte, for a binary file) or "line" (for an ASCII file), 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 STL 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 TagSTLInvalid for a file that is not STL.

Flutter: no counterpart

func Load

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

Load reads the STL file name of fsys. 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, its node and its mesh. Load sets the base name of the file when it is empty.
	Name string
	// Float64 keeps the positions of an ASCII file in float64 when some of them have more digits than a float32 holds. A binary file
	// is float32 and is not changed by it.
	Float64 bool
	// WeldTolerance welds vertices that fall in the same cell of a grid of this size, in the units of the file. Zero welds the
	// vertices that are equal bit for bit (and -0 with 0), which is what CAD writers produce.
	WeldTolerance float64
	// Flat gives every triangle three vertices of its own with the normal of the triangle: nothing is welded and no normal is
	// smoothed.
	Flat bool
	// CreaseAngle is the angle in radians between the normals of two triangles at a vertex above which they do not share the
	// vertex. Zero is DefaultCreaseAngle; a negative angle smooths every edge that is shared.
	CreaseAngle float64
	// Logger gets the notes of the loader (triangles that were dropped); 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