geometry

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2021 License: BSD-2-Clause Imports: 6 Imported by: 305

Documentation

Overview

Package geometry implements several primitive geometry generators.

Index

Constants

View Source
const MaxActiveMorphTargets = 8

MaxActiveMorphTargets is the maximum number of active morph targets.

Variables

This section is empty.

Functions

func CalculateNormals added in v0.2.0

func CalculateNormals(indices math32.ArrayU32, positions, normals math32.ArrayF32) math32.ArrayF32

Types

type Geometry

type Geometry struct {
	ShaderDefines gls.ShaderDefines // Geometry-specific shader defines
	// contains filtered or unexported fields
}

Geometry encapsulates a three-dimensional vertex-based geometry.

func NewBox

func NewBox(width, height, length float32) *Geometry

NewBox creates a box geometry with the specified width, height, and length.

func NewCone added in v0.2.0

func NewCone(radius, height float64, radialSegments, heightSegments int, bottom bool) *Geometry

NewCone creates a cone geometry with the specified base radius, height, number of radial segments, number of height segments, and presence of a bottom cap.

func NewConeSector added in v0.2.0

func NewConeSector(radius, height float64, radialSegments, heightSegments int, thetaStart, thetaLength float64, bottom bool) *Geometry

NewConeSector creates a cone sector geometry with the specified base radius, height, number of radial segments, number of height segments, sector start angle in radians, sector size angle in radians, and presence of a bottom cap.

func NewCube

func NewCube(size float32) *Geometry

NewCube creates a cube geometry with the specified size.

func NewCylinder

func NewCylinder(radius, height float64, radialSegments, heightSegments int, top, bottom bool) *Geometry

NewCylinder creates a cylinder geometry with the specified radius, height, number of radial segments, number of height segments, and presence of a top and/or bottom cap.

func NewCylinderSector added in v0.2.0

func NewCylinderSector(radius, height float64, radialSegments, heightSegments int, thetaStart, thetaLength float64, top, bottom bool) *Geometry

NewCylinderSector creates a cylinder sector geometry with the specified radius, height, number of radial segments, number of height segments, sector start angle in radians, sector size angle in radians, and presence of a top and/or bottom cap.

func NewDisk added in v0.2.0

func NewDisk(radius float64, segments int) *Geometry

NewDisk creates a disk (filled circle) geometry with the specified radius and number of radial segments/triangles (minimum 3).

func NewDiskSector added in v0.2.0

func NewDiskSector(radius float64, segments int, thetaStart, thetaLength float64) *Geometry

NewDiskSector creates a disk (filled circle) or disk sector geometry with the specified radius, number of radial segments/triangles (minimum 3), sector start angle in radians, and sector size angle in radians. The center of the disk is at the origin, and theta runs counter-clockwise on the XY plane, starting at (x,y,z)=(1,0,0).

func NewGeometry

func NewGeometry() *Geometry

NewGeometry creates and returns a pointer to a new Geometry.

func NewPlane

func NewPlane(width, height float32) *Geometry

NewPlane creates a plane geometry with the specified width and height. The plane is generated centered in the XY plane with Z=0.

func NewRibbon added in v0.2.0

func NewRibbon(paths [][]math32.Vector3, close bool) *Geometry

func NewSegmentedBox

func NewSegmentedBox(width, height, length float32, widthSegments, heightSegments, lengthSegments int) *Geometry

NewSegmentedBox creates a segmented box geometry with the specified width, height, length, and number of segments in each dimension.

func NewSegmentedCube

func NewSegmentedCube(size float32, segments int) *Geometry

NewSegmentedCube creates a segmented cube geometry with the specified size and number of segments.

func NewSegmentedPlane added in v0.2.0

func NewSegmentedPlane(width, height float32, widthSegments, heightSegments int) *Geometry

NewSegmentedPlane creates a segmented plane geometry with the specified width, height, and number of segments in each dimension (minimum 1 in each). The plane is generated centered in the XY plane with Z=0.

func NewSphere

func NewSphere(radius float64, widthSegments, heightSegments int) *Geometry

NewSphere creates a sphere geometry with the specified radius and number of radial segments in each dimension.

func NewSphereSector added in v0.2.0

func NewSphereSector(radius float64, widthSegments, heightSegments int, phiStart, phiLength, thetaStart, thetaLength float64) *Geometry

NewSphereSector creates a sphere sector geometry with the specified radius, number of radial segments in each dimension, elevation start angle in radians, elevation size angle in radians, sector start angle in radians, and sector size angle in radians.

func NewTorus

func NewTorus(radius, tubeRadius float64, radialSegments, tubularSegments int, arc float64) *Geometry

NewTorus creates a torus geometry with the specified revolution radius, tube radius, number of radial segments, number of tubular segments, and arc length angle in radians. TODO instead of 'arc' have thetaStart and thetaLength for consistency with other generators TODO then rename this to NewTorusSector and add a NewTorus constructor

func NewTruncatedCone added in v0.2.0

func NewTruncatedCone(radiusTop, radiusBottom, height float64, radialSegments, heightSegments int, top, bottom bool) *Geometry

NewTruncatedCone creates a truncated cone geometry with the specified top and bottom radii, height, number of radial segments, number of height segments, and presence of a top and/or bottom cap.

func NewTruncatedConeSector added in v0.2.0

func NewTruncatedConeSector(radiusTop, radiusBottom, height float64, radialSegments, heightSegments int, thetaStart, thetaLength float64, top, bottom bool) *Geometry

NewTruncatedConeSector creates a truncated cone sector geometry with the specified top and bottom radii, height, number of radial segments, number of height segments, sector start angle in radians, sector size angle in radians, and presence of a top and/or bottom cap.

func NewTube added in v0.2.0

func NewTube(path []math32.Vector3, radius float32, radialSegments int, close bool) *Geometry

func (*Geometry) AddGroup

func (g *Geometry) AddGroup(start, count, matIndex int) *Group

AddGroup adds a geometry group (for multimaterial).

func (*Geometry) AddGroupList

func (g *Geometry) AddGroupList(groups []Group)

AddGroupList adds the specified list of groups to this geometry.

func (*Geometry) AddVBO

func (g *Geometry) AddVBO(vbo *gls.VBO)

AddVBO adds a Vertex Buffer Object for this geometry.

func (*Geometry) ApplyMatrix

func (g *Geometry) ApplyMatrix(m *math32.Matrix4)

ApplyMatrix multiplies each of the geometry position vertices by the specified matrix and apply the correspondent normal transform matrix to the geometry normal vectors. The geometry's bounding box and sphere are recomputed if needed.

func (*Geometry) Area

func (g *Geometry) Area() float32

Area returns the surface area. NOTE: This only works for triangle-based meshes.

func (*Geometry) AttributeName

func (g *Geometry) AttributeName(atype gls.AttribType) string

AttributeName returns the name of the VBO attribute associated with the provided attribute type.

func (*Geometry) BoundingBox

func (g *Geometry) BoundingBox() math32.Box3

BoundingBox computes the bounding box of the geometry if necessary and returns is value.

func (*Geometry) BoundingSphere

func (g *Geometry) BoundingSphere() math32.Sphere

BoundingSphere computes the bounding sphere of this geometry if necessary and returns its value.

func (*Geometry) Dispose

func (g *Geometry) Dispose()

Dispose decrements this geometry reference count and if possible releases OpenGL resources, C memory and VBOs associated with this geometry.

func (*Geometry) GetGeometry

func (g *Geometry) GetGeometry() *Geometry

GetGeometry satisfies the IGeometry interface.

func (*Geometry) GroupAt

func (g *Geometry) GroupAt(idx int) *Group

GroupAt returns pointer to geometry group at the specified index.

func (*Geometry) GroupCount

func (g *Geometry) GroupCount() int

GroupCount returns the number of geometry groups (for multimaterial).

func (*Geometry) Incref

func (g *Geometry) Incref() *Geometry

Incref increments the reference count for this geometry and returns a pointer to the geometry. It should be used when this geometry is shared by another Graphic object.

func (*Geometry) Indexed

func (g *Geometry) Indexed() bool

Indexed returns whether the geometry is indexed or not.

func (*Geometry) Indices

func (g *Geometry) Indices() math32.ArrayU32

Indices returns the indices array for this geometry.

func (*Geometry) Init

func (g *Geometry) Init()

Init initializes the geometry.

func (*Geometry) Items

func (g *Geometry) Items() int

Items returns the number of items in the first VBO. (The number of items should be same for all VBOs) An item is a complete group of attributes in the VBO buffer.

func (*Geometry) OperateOnVertexNormals

func (g *Geometry) OperateOnVertexNormals(cb func(normal *math32.Vector3) bool)

OperateOnVertexNormals iterates over all the vertex normals and calls the specified callback function with a pointer to each normal. The vertex pointers can be modified inside the callback and the modifications will be applied to the buffer at each iteration. The callback function returns false to continue or true to break.

func (*Geometry) OperateOnVertices

func (g *Geometry) OperateOnVertices(cb func(vertex *math32.Vector3) bool)

OperateOnVertices iterates over all the vertices and calls the specified callback function with a pointer to each vertex. The vertex pointers can be modified inside the callback and the modifications will be applied to the buffer at each iteration. The callback function returns false to continue or true to break.

func (*Geometry) ProjectOntoAxis

func (g *Geometry) ProjectOntoAxis(localAxis *math32.Vector3) (float32, float32)

ProjectOntoAxis projects the geometry onto the specified axis, effectively squashing it into a line passing through the local origin. Returns the maximum and the minimum values on that line (i.e. signed distances from the local origin).

func (*Geometry) ReadFaces

func (g *Geometry) ReadFaces(cb func(vA, vB, vC math32.Vector3) bool)

ReadFaces iterates over all the vertices and calls the specified callback function with face-forming vertex triples. The callback function returns false to continue or true to break.

func (*Geometry) ReadVertexNormals

func (g *Geometry) ReadVertexNormals(cb func(vertex math32.Vector3) bool)

ReadVertexNormals iterates over all the vertex normals and calls the specified callback function with the value of each normal. The callback function returns false to continue or true to break.

func (*Geometry) ReadVertices

func (g *Geometry) ReadVertices(cb func(vertex math32.Vector3) bool)

ReadVertices iterates over all the vertices and calls the specified callback function with the value of each vertex. The callback function returns false to continue or true to break.

func (*Geometry) RenderSetup

func (g *Geometry) RenderSetup(gs *gls.GLS)

RenderSetup is called by the renderer before drawing the geometry.

func (*Geometry) RotationalInertia

func (g *Geometry) RotationalInertia(mass float32) math32.Matrix3

RotationalInertia returns the rotational inertia tensor, also known as the moment of inertia. This assumes constant density of 1 (kg/m^2). To adjust for a different constant density simply scale the returning matrix by the density.

func (*Geometry) SetAttributeName

func (g *Geometry) SetAttributeName(atype gls.AttribType, attribName string)

SetAttributeName sets the name of the VBO attribute associated with the provided attribute type.

func (*Geometry) SetIndices

func (g *Geometry) SetIndices(indices math32.ArrayU32)

SetIndices sets the indices array for this geometry.

func (*Geometry) VBO

func (g *Geometry) VBO(atype gls.AttribType) *gls.VBO

VBO returns a pointer to this geometry's VBO which contain the specified attribute. Returns nil if the VBO is not found.

func (*Geometry) VBOName

func (g *Geometry) VBOName(name string) *gls.VBO

VBOName returns a pointer to this geometry's VBO which contain the specified attribute. Returns nil if the VBO is not found.

func (*Geometry) VBOs

func (g *Geometry) VBOs() []*gls.VBO

VBOs returns all of this geometry's VBOs.

func (*Geometry) Volume

func (g *Geometry) Volume() float32

Volume returns the volume. NOTE: This only works for closed triangle-based meshes.

type Group

type Group struct {
	Start    int    // Index of first element of the group
	Count    int    // Number of elements in the group
	Matindex int    // Material index for this group
	Matid    string // Material id used when loading external models
}

Group is a geometry group object.

type IGeometry

type IGeometry interface {
	GetGeometry() *Geometry
	RenderSetup(gs *gls.GLS)
	Dispose()
}

IGeometry is the interface for all geometries.

type MorphGeometry

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

MorphGeometry represents a base geometry and its morph targets.

func NewMorphGeometry

func NewMorphGeometry(baseGeometry *Geometry) *MorphGeometry

NewMorphGeometry creates and returns a pointer to a new MorphGeometry.

func (*MorphGeometry) ActiveMorphTargets

func (mg *MorphGeometry) ActiveMorphTargets() ([]*Geometry, []float32)

ActiveMorphTargets sorts the morph targets by weight and returns the top n morph targets with largest weight.

func (*MorphGeometry) AddMorphTargetDeltas

func (mg *MorphGeometry) AddMorphTargetDeltas(morphTargetDeltas ...*Geometry)

AddMorphTargetDeltas add multiple morph target deltas to the morph geometry.

func (*MorphGeometry) AddMorphTargets

func (mg *MorphGeometry) AddMorphTargets(morphTargets ...*Geometry)

AddMorphTargets add multiple morph targets to the morph geometry. Morph target deltas are calculated internally and the morph target geometries are altered to hold the deltas instead.

func (*MorphGeometry) ComputeMorphed

func (mg *MorphGeometry) ComputeMorphed(weights []float32) *Geometry

ComputeMorphed computes a morphed geometry from the provided morph target weights. Note that morphing is usually computed by the GPU in shaders. This CPU implementation allows users to obtain an instance of a morphed geometry if so desired (loosing morphing ability).

func (*MorphGeometry) Dispose

func (mg *MorphGeometry) Dispose()

Dispose releases, if possible, OpenGL resources, C memory and VBOs associated with the base geometry and morph targets.

func (*MorphGeometry) GetGeometry

func (mg *MorphGeometry) GetGeometry() *Geometry

GetGeometry satisfies the IGeometry interface.

func (*MorphGeometry) RenderSetup

func (mg *MorphGeometry) RenderSetup(gs *gls.GLS)

RenderSetup is called by the renderer before drawing the geometry.

func (*MorphGeometry) SetIndices

func (mg *MorphGeometry) SetIndices(indices math32.ArrayU32)

SetIndices sets the indices array for this geometry.

func (*MorphGeometry) SetWeights

func (mg *MorphGeometry) SetWeights(weights []float32)

SetWeights sets the morph target weights.

func (*MorphGeometry) UpdateTargetAttributes

func (mg *MorphGeometry) UpdateTargetAttributes(morphTargets []*Geometry)

UpdateTargetAttributes updates the attribute names of the specified morph targets in order.

func (*MorphGeometry) Weights

func (mg *MorphGeometry) Weights() []float32

Weights returns the morph target weights.

Jump to

Keyboard shortcuts

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