face

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Jul 15, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NEXT_UNIQUE_ID int

Functions

func UniqueId

func UniqueId() int

Returns an ID which is unique to this instance of the library

Types

type Coordinates

type Coordinates struct {
	// Face is a reference to the Face that is being rendered.
	// The reference is retained so it can be checked for the Dirty flag.
	// When the Dirty flag is set, the rendering needs to be regenerated.
	Face *Face

	// Model to World space transformation
	Model      matrix.Matrix
	WorldSpace struct {
		Points     point.Points
		Barycenter point.Point
		Normal     point.Point
	}

	// World to View space transformation
	Projection    matrix.Matrix
	InViewFrustum bool

	// View to Screen space transformation
	Viewport    matrix.Matrix
	ScreenSpace struct {
		Points     point.Points
		Barycenter point.Point
		Normal     point.Point
	}
}

Coordinates contains the transformed and projected points of a face as well as a reference back to the original face.

Once initialized, the object will have a constant memory footprint down to `Number` primitives. Also, we compare each transform and projection to prevent unnecessary re-computation.

If you need to force a re-computation, mark the face as 'dirty'.

func (*Coordinates) MaybeUpdate

func (r *Coordinates) MaybeUpdate(points point.Points, model, projection, viewport matrix.Matrix) bool

func (*Coordinates) Update

func (r *Coordinates) Update(points point.Points, model, projection, viewport matrix.Matrix)

type Face

type Face struct {
	// Points contain a list of vertices of the planar polygon that defines the
	// outline of the face.
	Points point.Points

	// Id holds a unique identifier for the face.
	// We store a unique Id for every face so we can look them up quickly
	// with the render face cache.
	Id int

	// ShowBackfaces when set to true will override backface culling, which is useful if your
	// material is transparent. See comment in Scene.
	ShowBackfaces bool

	// FillMaterial may be a Material object which defines the color and
	// finish of the object and are rendered using the scene's shader.
	// If not material is set a Material(C.gray) will be used.
	FillMaterial *shader.Material

	// StrokeMaterial may be a Material object that defines the color when
	// an object is stroked. By default no stroke material will be set.
	StrokeMaterial *shader.Material

	// Dirty flag can be set to force the Coordinates generated from the face to
	// be regenerated.
	Dirty bool

	// Options is a map of additional options that can be specified for a face.
	// The option with key "stroke-width" is passed in the style map parameter to
	// PathPainter.Stroke() call.
	// The keys "font" and "anchor" are passed in as keys "font" and "text-anchor" in
	// the style map parameter to TextPainter.FillText() call.
	Options map[string]string
}

Face is a defined as a planar object in 3D space. These paths don't necessarily need to be convex, but they should be non-degenerate.

func FaceWith

func FaceWith(points point.Points) Face

FaceWith takes a slice of points and uses it in constructing a face. The array backing this points slice is integrated into the face.

func (*Face) Coordinates

func (face *Face) Coordinates(model, projection, viewport matrix.Matrix) Coordinates

func (*Face) SetFill

func (face *Face) SetFill(value any) (err error)

func (*Face) SetStroke

func (face *Face) SetStroke(value any) (err error)

type Faces

type Faces []Face

func (Faces) SetColorFrom

func (s Faces) SetColorFrom(source color.Source) (err error)

SetColorFrom sets a color on every face by reading it from the passed in colors.Source.

func (Faces) SetFill

func (s Faces) SetFill(value any) (err error)

SetFill applies the supplied fill Material to each face

func (Faces) SetShowBackfaces

func (s Faces) SetShowBackfaces(value bool)

SetShowBackfaces will set the ShowBackfaces bool on the faces.

func (Faces) SetStroke

func (s Faces) SetStroke(value any) (err error)

SetStroke applies the supplied stroke Material to each face

func (Faces) SetStrokeWidth

func (s Faces) SetStrokeWidth(value int)

SetStrokeWidth sets the supplied stroke-width option on each face

type Facet

type Facet []int

type Facets

type Facets []Facet

func (Facets) FacesWith

func (facets Facets) FacesWith(points point.Points) (faces Faces)

FacesWith creates faces from points and facets. A facet is a list of indexes into the list of points. Note that a point referenced in multiple facets will be inserted into multiple faces. Because of this points shared by multiple faces will be transformed multiple times instead of only once.

Jump to

Keyboard shortcuts

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