mesh

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewMeshFn creates a mesh node. Set by root package.
	NewMeshFn func(name string, img *ebiten.Image, verts []ebiten.Vertex, inds []uint16) *node.Node
)

Function pointers wired by root to break dependency on constructors.

Functions

func BuildPolygonFan

func BuildPolygonFan(points []types.Vec2, textured bool, img *ebiten.Image) ([]ebiten.Vertex, []uint16)

BuildPolygonFan generates vertices and indices for an arbitrary simple polygon.

func ComputeMeshAABB

func ComputeMeshAABB(verts []ebiten.Vertex) types.Rect

ComputeMeshAABB scans DstX/DstY of the given vertices and returns the axis-aligned bounding box in local space.

func EarClipIndices

func EarClipIndices(pts []types.Vec2) []uint16

EarClipIndices triangulates a simple polygon using ear-clipping.

func EnsureTransformedVerts

func EnsureTransformedVerts(n *node.Node) []ebiten.Vertex

EnsureTransformedVerts grows the node's transformedVerts buffer to fit len(n.Mesh.Vertices), using a high-water-mark strategy (never shrinks).

func EnsureWhitePixel

func EnsureWhitePixel() *ebiten.Image

EnsureWhitePixel returns a lazily-initialized 1x1 white pixel image.

func MeshWorldAABB

func MeshWorldAABB(n *node.Node, transform [6]float64, worldAABBFn func([6]float64, float64, float64) types.Rect) types.Rect

MeshWorldAABB computes the world-space AABB for a mesh node, accounting for the fact that mesh vertices may not start at origin (0,0).

func MeshWorldAABBOffset

func MeshWorldAABBOffset(n *node.Node, transform [6]float64) types.Rect

MeshWorldAABBOffset computes mesh world AABB by transforming the four corners.

func NewPolygon

func NewPolygon(name string, points []types.Vec2) *node.Node

NewPolygon creates an untextured polygon mesh from the given vertices.

func NewPolygonTextured

func NewPolygonTextured(name string, img *ebiten.Image, points []types.Vec2) *node.Node

NewPolygonTextured creates a textured polygon mesh.

func NewRegularPolygon

func NewRegularPolygon(name string, sides int, radius float64) *node.Node

NewRegularPolygon creates an untextured regular polygon with the given number of sides, centered at the origin with the specified radius.

func NewStar

func NewStar(name string, outerR, innerR float64, points int) *node.Node

NewStar creates an untextured star polygon.

func Perpendicular

func Perpendicular(a, b types.Vec2) (float64, float64)

Perpendicular returns the unit left-perpendicular of the segment from a to b.

func Poly2DCross

func Poly2DCross(o, a, b types.Vec2) float64

Poly2DCross returns (a-o) × (b-o). Positive = CCW turn.

func PtInTriangle

func PtInTriangle(p, a, b, c types.Vec2) bool

PtInTriangle reports whether p lies inside triangle (a, b, c).

func RecomputeMeshAABB

func RecomputeMeshAABB(n *node.Node)

RecomputeMeshAABB recomputes the cached local-space AABB if dirty.

func SetPolygonPoints

func SetPolygonPoints(n *node.Node, points []types.Vec2)

SetPolygonPoints updates the polygon's vertices.

func TransformVertices

func TransformVertices(src, dst []ebiten.Vertex, transform [6]float64, tint types.Color)

TransformVertices applies an affine transform and color tint to src vertices, writing the result into dst. dst must be at least len(src) in length.

Types

type DistortionGrid

type DistortionGrid struct {
	// contains filtered or unexported fields
}

DistortionGrid provides a grid mesh that can be deformed per-vertex.

func NewDistortionGrid

func NewDistortionGrid(name string, img *ebiten.Image, cols, rows int) *DistortionGrid

NewDistortionGrid creates a grid mesh over the given image. cols and rows define the number of cells (vertices = (cols+1) * (rows+1)).

func (*DistortionGrid) Cols

func (g *DistortionGrid) Cols() int

Cols returns the number of grid columns.

func (*DistortionGrid) Node

func (g *DistortionGrid) Node() *node.Node

Node returns the underlying mesh node.

func (*DistortionGrid) Reset

func (g *DistortionGrid) Reset()

Reset returns all vertices to their original positions.

func (*DistortionGrid) Rows

func (g *DistortionGrid) Rows() int

Rows returns the number of grid rows.

func (*DistortionGrid) SetAllVertices

func (g *DistortionGrid) SetAllVertices(fn func(col, row int, restX, restY float64) (dx, dy float64))

SetAllVertices calls fn for each vertex, passing (col, row, restX, restY). fn returns the (dx, dy) displacement from the rest position.

func (*DistortionGrid) SetVertex

func (g *DistortionGrid) SetVertex(col, row int, dx, dy float64)

SetVertex offsets a single grid vertex by (dx, dy) from its rest position.

type Rope

type Rope struct {
	// contains filtered or unexported fields
}

Rope generates a ribbon/rope mesh that follows a polyline path.

func NewRope

func NewRope(name string, img *ebiten.Image, points []types.Vec2, cfg RopeConfig) *Rope

NewRope creates a rope mesh node that renders a textured ribbon along the given points.

func (*Rope) Config

func (r *Rope) Config() *RopeConfig

Config returns a pointer to the rope's configuration.

func (*Rope) Node

func (r *Rope) Node() *node.Node

Node returns the underlying mesh node.

func (*Rope) SetPoints

func (r *Rope) SetPoints(points []types.Vec2)

SetPoints updates the rope's path. For N points: 2N vertices, 6(N-1) indices.

func (*Rope) Update

func (r *Rope) Update()

Update recomputes the rope's point path from the current RopeConfig and rebuilds the mesh.

type RopeConfig

type RopeConfig struct {
	Width     float64
	JoinMode  RopeJoinMode
	CurveMode RopeCurveMode
	Segments  int // number of subdivisions (default 20)
	Start     *types.Vec2
	End       *types.Vec2
	Sag       float64
	Controls  [2]*types.Vec2
	Amplitude float64
	Frequency float64
	Phase     float64
	// Custom callback. Receives a preallocated buffer; must return the slice to use.
	PointsFunc func(buf []types.Vec2) []types.Vec2
}

RopeConfig configures a Rope mesh.

type RopeCurveMode

type RopeCurveMode uint8

RopeCurveMode selects the curve algorithm used by Rope.Update().

const (
	RopeCurveLine RopeCurveMode = iota
	RopeCurveCatenary
	RopeCurveQuadBezier
	RopeCurveCubicBezier
	RopeCurveWave
	RopeCurveCustom
)

type RopeJoinMode

type RopeJoinMode uint8

RopeJoinMode controls how segments join in a Rope mesh.

const (
	RopeJoinMiter RopeJoinMode = iota
	RopeJoinBevel
)

Jump to

Keyboard shortcuts

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