shape

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Sep 9, 2024 License: BSD-3-Clause Imports: 6 Imported by: 0

README

shape: Compositional 3D shape library

shape provides a library of 3D shapes, built from indexed triangle meshes, which can be added together in ShapeGroup lists. Each Shape can report the number of points and indexes based on configured parameters, and keeps track of its offset within an overall math32.ArrayF32 allocated based on total numbers.

The Mesh interface defines the set of functions that render shapes to arrays of vertex, normal, and texture coordinate points, which each different specific shape type implements. This interface is used in the phong system for setting meshes.

It only has a dependency on the math32 package and could be used for anything.

Basic building blocks (e.g., Plane, SphereSector) have standalone methods, in addition to Shape elements.

Here are the shapes:

  • Plane
  • Box
  • Sphere (including various partial segments thereof)
  • Cylinder, Cone (including different size top and bottom radii, e.g., Cones)
  • Capsule: a cylinder with half-sphere caps -- good for simple body segments
  • Torus
  • Lines: uses a box to draw 3D lines
  • Group: combines multiple shapes.

Documentation

Overview

Package shape provides a library of 3D shapes, built from indexed triangle meshes, which can be added together in `ShapeGroup` lists. Each `Shape` can report the number of points and indexes based on configured parameters, and keeps track of its offset within an overall math32.ArrayF32 allocated based on total numbers. In this way, separate Allocate then Configure phases are supported, as required by the gpu Memory allocation system.

Basic building blocks (e.g., Plane, SphereSector) have standalone methods, in addition to Shape elements.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BBoxFromVtxs

func BBoxFromVtxs(vertex math32.ArrayF32, vtxOff int, numVertex int) math32.Box3

BBoxFromVtxs returns the bounding box updated from the range of vertex points

func BoxN

func BoxN(segs math32.Vector3i) (numVertex, nIndex int)

PlaneN returns the N's for a single plane's worth of vertex and index data with given number of segments. Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array).

func CylinderSectorN

func CylinderSectorN(radialSegs, heightSegs int, top, bottom bool) (numVertex, nIndex int)

CylinderSectorN returns the N's for the cylinder (truncated cone) sector vertex and index data with given parameters

func DiskSectorN

func DiskSectorN(segs int) (numVertex, nIndex int)

DiskSectorN returns the N's for a disk sector's vertex and index data with given number of segments. Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array).

func LinesN

func LinesN(npoints int, closed bool) (numVertex, nIndex int)

LinesN returns number of vertex and idx points

func MiterPts

func MiterPts(ax, ay, bx, by, cx, cy, w2 float32) math32.Vector2

MiterPts returns the miter points

func PlaneN

func PlaneN(wsegs, hsegs int) (numVertex, nIndex int)

PlaneN returns the N's for a single plane's worth of vertex and index data with given number of segments. Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array). numVertex = (wsegs + 1) * (hsegs + 1) nIndex = wsegs * hsegs * 6.

func QuadN

func QuadN() (numVertex, nIndex int)

QuadN returns 4, 6

func SetBox

func SetBox(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, size math32.Vector3, segs math32.Vector3i, pos math32.Vector3) math32.Vector3

SetBox sets box vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index. for given 3D size, and given number of segments per side. finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). pos is a 3D position offset. returns 3D size of plane.

func SetColor

func SetColor(clrs math32.ArrayF32, vtxOff int, numVertex int, clr math32.Vector4)

SetColor sets color for given range of vertex indexes

func SetCone

func SetCone(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, height, radius float32, radialSegs, heightSegs int, bottom bool, pos math32.Vector3) math32.Box3

SetCone creates a cone mesh with the specified base radius, height, vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), number of radial segments, number of height segments, and presence of a bottom cap. Height is along the Y axis. pos is an arbitrary offset (for composing shapes).

func SetCylinderSector

func SetCylinderSector(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, height, topRad, botRad float32, radialSegs, heightSegs int, angStart, angLen float32, top, bottom bool, pos math32.Vector3) math32.Box3

SetCylinderSector creates a generalized cylinder (truncated cone) sector vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), with the specified top and bottom radii, height, number of radial segments, number of height segments, sector start angle in degrees (start = -1,0,0) sector size angle in degrees, and presence of a top and/or bottom cap. Height is along the Y axis. pos is an arbitrary offset (for composing shapes).

func SetDiskSector

func SetDiskSector(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, radius float32, segs int, angStart, angLen float32, pos math32.Vector3) math32.Box3

SetDiskSector sets a disk sector vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index, with the specified radius, number of radial segments (minimum 3), sector start angle and angle length in degrees. The center of the disk is at the origin, and angle runs counter-clockwise on the XY plane, starting at (x,y,z)=(1,0,0). pos is an arbitrary offset (for composing shapes), returns bounding box.

func SetLines

func SetLines(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, points []math32.Vector3, width math32.Vector2, closed bool, pos math32.Vector3) math32.Box3

SetLines sets lines rendered as long thin boxes defined by points and width parameters. The Mesh must be drawn in the XY plane (i.e., use Z = 0 or a constant unless specifically relevant to have full 3D variation). Rotate to put into other planes.

func SetPlane

func SetPlane(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, waxis, haxis math32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, pos math32.Vector3)

SetPlane sets plane vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index. waxis, haxis = width, height axis, wdir, hdir are the directions for width and height dimensions. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis. pos is a 3D position offset.

func SetPlaneAxisSize

func SetPlaneAxisSize(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, normalAxis math32.Dims, normalNeg bool, size math32.Vector2, segs math32.Vector2i, offset float32, pos math32.Vector3) math32.Vector3

SetPlaneAxisSize sets plane vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index. using Normal Axis, offset, and size params. wsegs, hsegs = number of segments to create in each dimension -- more finely subdividing a plane allows for higher-quality lighting and texture rendering (minimum of 1 will be enforced). offset is the distance to place the plane along the orthogonal axis. pos is a 3D position offset. returns 3D size of plane. returns bounding box.

func SetQuad

func SetQuad(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, vtxs []math32.Vector3, texs []math32.Vector2, pos math32.Vector3) math32.Box3

SetQuad sets quad vertex data (optionally texUV, color, and indexes) at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index. Normal is auto-computed, and bbox expanded by points. pos is a 3D position offset. returns 3D size of plane. returns bounding box.

func SetSphereSector

func SetSphereSector(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, radius float32, widthSegs, heightSegs int, angStart, angLen, elevStart, elevLen float32, pos math32.Vector3) math32.Box3

SetSphereSector sets a sphere sector vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index, with the specified radius, number of radial segments in each dimension (min 3), radial sector start angle and length in degrees (0 - 360), start = -1,0,0, elevation start angle and length in degrees (0 - 180), top = 0, bot = 180. pos is an arbitrary offset (for composing shapes), returns bounding box.

func SetTorusSector

func SetTorusSector(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, radius, tubeRadius float32, radialSegs, tubeSegs int, angStart, angLen float32, pos math32.Vector3) math32.Box3

SetTorusSector sets torus sector vertex, normal, tex, index data at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index, with the specified revolution radius, tube radius, number of radial segments, number of tubular segments, radial sector start angle and length in degrees (0 - 360) pos is an arbitrary offset (for composing shapes), returns bounding box.

func SetTriangle

func SetTriangle(vertex, normal, texcoord math32.ArrayF32, index math32.ArrayU32, vtxOff, idxOff int, a, b, c math32.Vector3, texs []math32.Vector2, pos math32.Vector3) math32.Box3

SetTriangle sets one triangle of vertex data indexes, and optionally texUV coords, at given starting *vertex* index (i.e., multiply this *3 to get actual float offset in Vtx array), and starting Index index. Normal is auto-computed, and bounds expanded. pos is a 3D position offset. returns 3D size of plane. returns bounding box.

func SphereSectorN

func SphereSectorN(widthSegs, heightSegs int, elevStart, elevLen float32) (numVertex, nIndex int)

SphereSectorN returns the N's for a sphere sector's vertex and index data with given number of segments. Note: In *vertex* units, not float units (i.e., x3 to get actual float offset in Vtx array).

func TorusSectorN

func TorusSectorN(radialSegs, tubeSegs int) (numVertex, nIndex int)

TorusSectorN returns N's for a torus geometry with number of radial segments, number of tubular segments, radial sector start angle and length in degrees (0 - 360)

func TriangleN

func TriangleN() (numVertex, nIndex int)

TriangleN returns 3, 3

Types

type Box

type Box struct {
	ShapeBase

	// size along each dimension
	Size math32.Vector3

	// number of segments to divide each plane into
	// (enforced to be at least 1).
	// Can generally increase rendering quality to have > 1.
	Segs math32.Vector3i
}

Box is a rectangular-shaped solid (cuboid)

func NewBox

func NewBox(width, height, depth float32) *Box

NewBox returns a Box shape with given size.

func (*Box) Defaults

func (bx *Box) Defaults()

func (*Box) MeshSize

func (bx *Box) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Box) Set

func (bx *Box) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

SetBox sets points in given allocated arrays.

func (*Box) SetSegs

func (t *Box) SetSegs(v math32.Vector3i) *Box

SetSegs sets the [Box.Segs]: number of segments to divide each plane into (enforced to be at least 1). Can generally increase rendering quality to have > 1.

func (*Box) SetSize

func (t *Box) SetSize(v math32.Vector3) *Box

SetSize sets the [Box.Size]: size along each dimension

type Capsule

type Capsule struct {
	ShapeBase

	// height of the cylinder portion
	Height float32

	// radius of the top -- set to 0 to omit top cap
	TopRad float32

	// radius of the bottom -- set to 0 to omit bottom cap
	BotRad float32

	// number of radial segments (32 is a reasonable default for full circle)
	RadialSegs int `min:"1"`

	// number of height segments
	HeightSegs int

	// number of segments in the hemisphere cap ends (16 is a reasonable default)
	CapSegs int

	// starting angle in degrees, relative to -1,0,0 left side starting point
	AngStart float32 `min:"0" max:"360" step:"5"`

	// total angle to generate in degrees (max 360)
	AngLen float32 `min:"0" max:"360" step:"5"`
}

Capsule is a generalized capsule shape: a cylinder with hemisphere end caps. Supports different radii on each end. Height is along the Y axis -- total height is Height + TopRad + BotRad.

func NewCapsule

func NewCapsule(height, radius float32, segs, heightSegs int) *Capsule

NewCapsule returns a Capsule shape with given radius, height, number of radial segments, number of height segments, and presence of a top and/or bottom cap. Height is along the Y axis.

func (*Capsule) Defaults

func (cp *Capsule) Defaults()

func (*Capsule) MeshSize

func (cp *Capsule) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Capsule) Set

func (cp *Capsule) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

SetCapsuleSector sets points in given allocated arrays

func (*Capsule) SetAngLen

func (t *Capsule) SetAngLen(v float32) *Capsule

SetAngLen sets the [Capsule.AngLen]: total angle to generate in degrees (max 360)

func (*Capsule) SetAngStart

func (t *Capsule) SetAngStart(v float32) *Capsule

SetAngStart sets the [Capsule.AngStart]: starting angle in degrees, relative to -1,0,0 left side starting point

func (*Capsule) SetBotRad

func (t *Capsule) SetBotRad(v float32) *Capsule

SetBotRad sets the [Capsule.BotRad]: radius of the bottom -- set to 0 to omit bottom cap

func (*Capsule) SetCapSegs

func (t *Capsule) SetCapSegs(v int) *Capsule

SetCapSegs sets the [Capsule.CapSegs]: number of segments in the hemisphere cap ends (16 is a reasonable default)

func (*Capsule) SetHeight

func (t *Capsule) SetHeight(v float32) *Capsule

SetHeight sets the [Capsule.Height]: height of the cylinder portion

func (*Capsule) SetHeightSegs

func (t *Capsule) SetHeightSegs(v int) *Capsule

SetHeightSegs sets the [Capsule.HeightSegs]: number of height segments

func (*Capsule) SetRadialSegs

func (t *Capsule) SetRadialSegs(v int) *Capsule

SetRadialSegs sets the [Capsule.RadialSegs]: number of radial segments (32 is a reasonable default for full circle)

func (*Capsule) SetTopRad

func (t *Capsule) SetTopRad(v float32) *Capsule

SetTopRad sets the [Capsule.TopRad]: radius of the top -- set to 0 to omit top cap

type Cylinder

type Cylinder struct {
	ShapeBase

	// height of the cylinder
	Height float32

	// radius of the top -- set to 0 for a cone
	TopRad float32

	// radius of the bottom
	BotRad float32

	// number of radial segments (32 is a reasonable default for full circle)
	RadialSegs int `min:"1"`

	// number of height segments
	HeightSegs int

	// render the top disc
	Top bool

	// render the bottom disc
	Bottom bool

	// starting angle in degrees, relative to -1,0,0 left side starting point
	AngStart float32 `min:"0" max:"360" step:"5"`

	// total angle to generate in degrees (max 360)
	AngLen float32 `min:"0" max:"360" step:"5"`
}

Cylinder is a generalized cylinder shape, including a cone or truncated cone by having different size circles at either end. Height is up along the Y axis.

func NewCone

func NewCone(height, radius float32, radialSegs, heightSegs int, bottom bool) *Cylinder

NewCone returns a cone shape with the specified base radius, height, number of radial segments, number of height segments, and presence of a bottom cap. Height is along the Y axis.

func NewCylinder

func NewCylinder(height, radius float32, radialSegs, heightSegs int, top, bottom bool) *Cylinder

NewCylinder returns a Cylinder shape with given radius, height, number of radial segments, number of height segments, and presence of a top and/or bottom cap. Height is along the Y axis.

func (*Cylinder) Defaults

func (cy *Cylinder) Defaults()

func (*Cylinder) MeshSize

func (cy *Cylinder) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Cylinder) Set

func (cy *Cylinder) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

SetCylinderSector sets points in given allocated arrays

func (*Cylinder) SetAngLen

func (t *Cylinder) SetAngLen(v float32) *Cylinder

SetAngLen sets the [Cylinder.AngLen]: total angle to generate in degrees (max 360)

func (*Cylinder) SetAngStart

func (t *Cylinder) SetAngStart(v float32) *Cylinder

SetAngStart sets the [Cylinder.AngStart]: starting angle in degrees, relative to -1,0,0 left side starting point

func (*Cylinder) SetBotRad

func (t *Cylinder) SetBotRad(v float32) *Cylinder

SetBotRad sets the [Cylinder.BotRad]: radius of the bottom

func (*Cylinder) SetBottom

func (t *Cylinder) SetBottom(v bool) *Cylinder

SetBottom sets the [Cylinder.Bottom]: render the bottom disc

func (*Cylinder) SetHeight

func (t *Cylinder) SetHeight(v float32) *Cylinder

SetHeight sets the [Cylinder.Height]: height of the cylinder

func (*Cylinder) SetHeightSegs

func (t *Cylinder) SetHeightSegs(v int) *Cylinder

SetHeightSegs sets the [Cylinder.HeightSegs]: number of height segments

func (*Cylinder) SetRadialSegs

func (t *Cylinder) SetRadialSegs(v int) *Cylinder

SetRadialSegs sets the [Cylinder.RadialSegs]: number of radial segments (32 is a reasonable default for full circle)

func (*Cylinder) SetTop

func (t *Cylinder) SetTop(v bool) *Cylinder

SetTop sets the [Cylinder.Top]: render the top disc

func (*Cylinder) SetTopRad

func (t *Cylinder) SetTopRad(v float32) *Cylinder

SetTopRad sets the [Cylinder.TopRad]: radius of the top -- set to 0 for a cone

type Lines

type Lines struct {
	ShapeBase

	// line points (must be 2 or more)
	Points []math32.Vector3

	// line width, Y = height perpendicular to line direction, and X = depth
	Width math32.Vector2

	// optional colors for each point -- actual color interpolates between
	Colors []color.Color

	// if true, connect the first and last points to form a closed shape
	Closed bool
}

Lines are lines rendered as long thin boxes defined by points and width parameters. The Mesh must be drawn in the XY plane (i.e., use Z = 0 or a constant unless specifically relevant to have full 3D variation). Rotate the solid to put into other planes.

func NewLines

func NewLines(points []math32.Vector3, width math32.Vector2, closed bool) *Lines

NewLines returns a Lines shape with given size

func (*Lines) Defaults

func (ln *Lines) Defaults()

func (*Lines) MeshSize

func (ln *Lines) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Lines) Set

func (ln *Lines) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

Set sets points in given allocated arrays

func (*Lines) SetClosed

func (t *Lines) SetClosed(v bool) *Lines

SetClosed sets the [Lines.Closed]: if true, connect the first and last points to form a closed shape

func (*Lines) SetColors

func (t *Lines) SetColors(v ...color.Color) *Lines

SetColors sets the [Lines.Colors]: optional colors for each point -- actual color interpolates between

func (*Lines) SetPoints

func (t *Lines) SetPoints(v ...math32.Vector3) *Lines

SetPoints sets the [Lines.Points]: line points (must be 2 or more)

func (*Lines) SetWidth

func (t *Lines) SetWidth(v math32.Vector2) *Lines

SetWidth sets the [Lines.Width]: line width, Y = height perpendicular to line direction, and X = depth

type Mesh

type Mesh interface {
	// MeshSize returns number of vertex, index points in this shape element,
	// and whether it has per-vertex color values.
	MeshSize() (numVertex, nIndex int, hasColor bool)

	// Set sets points in given allocated arrays.
	Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

	// Offsets returns starting offset for vertices, indexes in full shape array,
	// in terms of points, not floats.
	Offsets() (vtxOffset, idxOffset int)

	// SetOffsets sets starting offset for vertices, indexes in full shape array,
	// in terms of points, not floats.
	SetOffsets(vtxOffset, idxOffset int)

	// MeshBBox returns the bounding box for the shape vertex points,
	// typically centered around 0.
	// This is only valid after Set has been called.
	MeshBBox() math32.Box3
}

Mesh is an interface for specifying the triangle Mesh data for 3D shapes. This is used for all mesh / shape data in the phong system.

type MeshData

type MeshData struct {
	// number of vertex points allocated for the Vertex, Normal, TexCoord,
	// and optional Colors data (if HasColor).
	NumVertex int

	// number of indexes.
	NumIndex int

	// whether this mech has per-vertex colors, as math32.Vector4 per vertex.
	HasColor bool

	// MeshBBox is the bounding box for the shape vertex points,
	// typically centered around 0.
	MeshBBox math32.Box3

	//	buffers that hold mesh data for the [Mesh.Set] method.
	Vertex, Normal, TexCoord, Colors math32.ArrayF32
	Index                            math32.ArrayU32
}

MeshData provides storage buffers for shapes specified using the Mesh interface.

func NewMeshData

func NewMeshData(mesh Mesh) *MeshData

NewMeshData returns a new MeshData and sets our buffer data from Mesh interface.

func (*MeshData) Set

func (md *MeshData) Set(mesh Mesh) *MeshData

Set sets mesh data into our buffers, from shape.Mesh.

type Plane

type Plane struct {
	ShapeBase

	// axis along which the normal perpendicular to the plane points.
	// E.g., if the Y axis is specified, then it is a standard X-Z ground plane.
	// See also NormalNeg for whether it is facing in the positive or
	// negative of the given axis.
	NormalAxis math32.Dims

	// if false, the plane normal is facing in the positive direction
	// along specified NormalAxis, otherwise it faces in the negative.
	NormalNeg bool

	// 2D size of plane
	Size math32.Vector2

	// number of segments to divide plane into (enforced to be at least 1).
	// Can generally increase rendering quality to have > 1.
	Segs math32.Vector2i

	// offset from origin along direction of normal to the plane.
	Offset float32
}

Plane is a flat 2D plane, which can be oriented along any axis facing either positive or negative

func NewPlane

func NewPlane(axis math32.Dims, width, height float32) *Plane

NewPlane returns a Plane shape with given size.

func (*Plane) Defaults

func (pl *Plane) Defaults()

func (*Plane) MeshSize

func (pl *Plane) MeshSize() (numVertex, nIndex int, hasColor bool)

MeshSize returns number of vertex, index points in this shape element

func (*Plane) Set

func (pl *Plane) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

Set sets points in given allocated arrays.

func (*Plane) SetNormalAxis

func (t *Plane) SetNormalAxis(v math32.Dims) *Plane

SetNormalAxis sets the [Plane.NormalAxis]: axis along which the normal perpendicular to the plane points. E.g., if the Y axis is specified, then it is a standard X-Z ground plane. See also NormalNeg for whether it is facing in the positive or negative of the given axis.

func (*Plane) SetNormalNeg

func (t *Plane) SetNormalNeg(v bool) *Plane

SetNormalNeg sets the [Plane.NormalNeg]: if false, the plane normal is facing in the positive direction along specified NormalAxis, otherwise it faces in the negative.

func (*Plane) SetOffset

func (t *Plane) SetOffset(v float32) *Plane

SetOffset sets the [Plane.Offset]: offset from origin along direction of normal to the plane.

func (*Plane) SetSegs

func (t *Plane) SetSegs(v math32.Vector2i) *Plane

SetSegs sets the [Plane.Segs]: number of segments to divide plane into (enforced to be at least 1). Can generally increase rendering quality to have > 1.

func (*Plane) SetSize

func (t *Plane) SetSize(v math32.Vector2) *Plane

SetSize sets the [Plane.Size]: 2D size of plane

type ShapeBase

type ShapeBase struct {
	// vertex offset, in points
	VertexOffset int

	// index offset, in points
	IndexOffset int

	// cubic bounding box in local coords
	CBBox math32.Box3

	// all shapes take a 3D position offset to enable composition
	Pos math32.Vector3
}

ShapeBase is the base shape element

func (*ShapeBase) MeshBBox

func (sb *ShapeBase) MeshBBox() math32.Box3

MeshBBox returns the bounding box for the shape, typically centered around 0 This is only valid after Set has been called.

func (*ShapeBase) Offsets

func (sb *ShapeBase) Offsets() (vtxOffset, idxOffset int)

Offs returns starting offset for vertices, indexes in full shape array, in terms of points, not floats

func (*ShapeBase) SetCBBox

func (t *ShapeBase) SetCBBox(v math32.Box3) *ShapeBase

SetCBBox sets the [ShapeBase.CBBox]: cubic bounding box in local coords

func (*ShapeBase) SetIndexOffset

func (t *ShapeBase) SetIndexOffset(v int) *ShapeBase

SetIndexOffset sets the [ShapeBase.IndexOffset]: index offset, in points

func (*ShapeBase) SetOffsets

func (sb *ShapeBase) SetOffsets(vtxOffset, idxOffset int)

SetOffs sets starting offsets for vertices, indexes in full shape array

func (*ShapeBase) SetPos

func (t *ShapeBase) SetPos(v math32.Vector3) *ShapeBase

SetPos sets the [ShapeBase.Pos]: all shapes take a 3D position offset to enable composition

func (*ShapeBase) SetVertexOffset

func (t *ShapeBase) SetVertexOffset(v int) *ShapeBase

SetVertexOffset sets the [ShapeBase.VertexOffset]: vertex offset, in points

type ShapeGroup

type ShapeGroup struct {
	ShapeBase

	// list of shapes in group
	Shapes []Mesh
}

ShapeGroup is a group of shapes. Returns summary data for shape elements.

func (*ShapeGroup) Set

func (sb *ShapeGroup) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

Set sets points in given allocated arrays, also updates offsets

func (*ShapeGroup) SetShapes

func (t *ShapeGroup) SetShapes(v ...Mesh) *ShapeGroup

SetShapes sets the [ShapeGroup.Shapes]: list of shapes in group

func (*ShapeGroup) Size

func (sb *ShapeGroup) Size() (numVertex, numIndex int, hasColor bool)

Size returns number of vertex, index points in this shape element.

type Sphere

type Sphere struct {
	ShapeBase

	// radius of the sphere
	Radius float32

	// number of segments around the width of the sphere (32 is reasonable default for full circle)
	WidthSegs int `min:"3"`

	// number of height segments (32 is reasonable default for full height)
	HeightSegs int `min:"3"`

	// starting radial angle in degrees, relative to -1,0,0 left side starting point
	AngStart float32 `min:"0" max:"360" step:"5"`

	// total radial angle to generate in degrees (max = 360)
	AngLen float32 `min:"0" max:"360" step:"5"`

	// starting elevation (height) angle in degrees - 0 = top of sphere, and Pi is bottom
	ElevStart float32 `min:"0" max:"180" step:"5"`

	// total angle to generate in degrees (max = 180)
	ElevLen float32 `min:"0" max:"180" step:"5"`
}

Sphere is a sphere shape (can be a partial sphere too)

func NewSphere

func NewSphere(radius float32, segs int) *Sphere

NewSphere returns a Sphere shape with given size

func (*Sphere) Defaults

func (sp *Sphere) Defaults()

func (*Sphere) MeshSize

func (sp *Sphere) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Sphere) Set

func (sp *Sphere) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

SetSphereSector sets points in given allocated arrays

func (*Sphere) SetAngLen

func (t *Sphere) SetAngLen(v float32) *Sphere

SetAngLen sets the [Sphere.AngLen]: total radial angle to generate in degrees (max = 360)

func (*Sphere) SetAngStart

func (t *Sphere) SetAngStart(v float32) *Sphere

SetAngStart sets the [Sphere.AngStart]: starting radial angle in degrees, relative to -1,0,0 left side starting point

func (*Sphere) SetElevLen

func (t *Sphere) SetElevLen(v float32) *Sphere

SetElevLen sets the [Sphere.ElevLen]: total angle to generate in degrees (max = 180)

func (*Sphere) SetElevStart

func (t *Sphere) SetElevStart(v float32) *Sphere

SetElevStart sets the [Sphere.ElevStart]: starting elevation (height) angle in degrees - 0 = top of sphere, and Pi is bottom

func (*Sphere) SetHeightSegs

func (t *Sphere) SetHeightSegs(v int) *Sphere

SetHeightSegs sets the [Sphere.HeightSegs]: number of height segments (32 is reasonable default for full height)

func (*Sphere) SetRadius

func (t *Sphere) SetRadius(v float32) *Sphere

SetRadius sets the [Sphere.Radius]: radius of the sphere

func (*Sphere) SetWidthSegs

func (t *Sphere) SetWidthSegs(v int) *Sphere

SetWidthSegs sets the [Sphere.WidthSegs]: number of segments around the width of the sphere (32 is reasonable default for full circle)

type Torus

type Torus struct {
	ShapeBase

	// larger radius of the torus ring
	Radius float32

	// radius of the solid tube
	TubeRadius float32

	// number of segments around the radius of the torus (32 is reasonable default for full circle)
	RadialSegs int `min:"1"`

	// number of segments for the tube itself (32 is reasonable default for full height)
	TubeSegs int `min:"1"`

	// starting radial angle in degrees relative to 1,0,0 starting point
	AngStart float32 `min:"0" max:"360" step:"5"`

	// total radial angle to generate in degrees (max = 360)
	AngLen float32 `min:"0" max:"360" step:"5"`
}

Torus is a torus mesh, defined by the radius of the solid tube and the larger radius of the ring.

func NewTorus

func NewTorus(radius, tubeRadius float32, segs int) *Torus

NewTorus returns a Torus mesh with the specified outer ring radius, solid tube radius, and number of segments (resolution).

func (*Torus) Defaults

func (tr *Torus) Defaults()

func (*Torus) MeshSize

func (tr *Torus) MeshSize() (numVertex, nIndex int, hasColor bool)

func (*Torus) Set

func (tr *Torus) Set(vertex, normal, texcoord, clrs math32.ArrayF32, index math32.ArrayU32)

Set sets points for torus in given allocated arrays

func (*Torus) SetAngLen

func (t *Torus) SetAngLen(v float32) *Torus

SetAngLen sets the [Torus.AngLen]: total radial angle to generate in degrees (max = 360)

func (*Torus) SetAngStart

func (t *Torus) SetAngStart(v float32) *Torus

SetAngStart sets the [Torus.AngStart]: starting radial angle in degrees relative to 1,0,0 starting point

func (*Torus) SetRadialSegs

func (t *Torus) SetRadialSegs(v int) *Torus

SetRadialSegs sets the [Torus.RadialSegs]: number of segments around the radius of the torus (32 is reasonable default for full circle)

func (*Torus) SetRadius

func (t *Torus) SetRadius(v float32) *Torus

SetRadius sets the [Torus.Radius]: larger radius of the torus ring

func (*Torus) SetTubeRadius

func (t *Torus) SetTubeRadius(v float32) *Torus

SetTubeRadius sets the [Torus.TubeRadius]: radius of the solid tube

func (*Torus) SetTubeSegs

func (t *Torus) SetTubeSegs(v int) *Torus

SetTubeSegs sets the [Torus.TubeSegs]: number of segments for the tube itself (32 is reasonable default for full height)

Jump to

Keyboard shortcuts

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