Documentation ¶
Overview ¶
Package geometry implements several primitive geometry generators.
Index ¶
- Constants
- func CalculateNormals(indices math32.ArrayU32, positions, normals math32.ArrayF32) math32.ArrayF32
- type Geometry
- func NewBox(width, height, length float32) *Geometry
- func NewCone(radius, height float64, radialSegments, heightSegments int, bottom bool) *Geometry
- func NewConeSector(radius, height float64, radialSegments, heightSegments int, ...) *Geometry
- func NewCube(size float32) *Geometry
- func NewCylinder(radius, height float64, radialSegments, heightSegments int, top, bottom bool) *Geometry
- func NewCylinderSector(radius, height float64, radialSegments, heightSegments int, ...) *Geometry
- func NewDisk(radius float64, segments int) *Geometry
- func NewDiskSector(radius float64, segments int, thetaStart, thetaLength float64) *Geometry
- func NewGeometry() *Geometry
- func NewPlane(width, height float32) *Geometry
- func NewRibbon(paths [][]math32.Vector3, close bool) *Geometry
- func NewSegmentedBox(width, height, length float32, ...) *Geometry
- func NewSegmentedCube(size float32, segments int) *Geometry
- func NewSegmentedPlane(width, height float32, widthSegments, heightSegments int) *Geometry
- func NewSphere(radius float64, widthSegments, heightSegments int) *Geometry
- func NewSphereSector(radius float64, widthSegments, heightSegments int, ...) *Geometry
- func NewTorus(radius, tubeRadius float64, radialSegments, tubularSegments int, arc float64) *Geometry
- func NewTruncatedCone(radiusTop, radiusBottom, height float64, radialSegments, heightSegments int, ...) *Geometry
- func NewTruncatedConeSector(radiusTop, radiusBottom, height float64, radialSegments, heightSegments int, ...) *Geometry
- func NewTube(path []math32.Vector3, radius float32, radialSegments int, close bool) *Geometry
- func (g *Geometry) AddGroup(start, count, matIndex int) *Group
- func (g *Geometry) AddGroupList(groups []Group)
- func (g *Geometry) AddVBO(vbo *gls.VBO)
- func (g *Geometry) ApplyMatrix(m *math32.Matrix4)
- func (g *Geometry) Area() float32
- func (g *Geometry) AttributeName(atype gls.AttribType) string
- func (g *Geometry) BoundingBox() math32.Box3
- func (g *Geometry) BoundingSphere() math32.Sphere
- func (g *Geometry) Dispose()
- func (g *Geometry) GetGeometry() *Geometry
- func (g *Geometry) GroupAt(idx int) *Group
- func (g *Geometry) GroupCount() int
- func (g *Geometry) Incref() *Geometry
- func (g *Geometry) Indexed() bool
- func (g *Geometry) Indices() math32.ArrayU32
- func (g *Geometry) Init()
- func (g *Geometry) Items() int
- func (g *Geometry) OperateOnVertexNormals(cb func(normal *math32.Vector3) bool)
- func (g *Geometry) OperateOnVertices(cb func(vertex *math32.Vector3) bool)
- func (g *Geometry) ProjectOntoAxis(localAxis *math32.Vector3) (float32, float32)
- func (g *Geometry) ReadFaces(cb func(vA, vB, vC math32.Vector3) bool)
- func (g *Geometry) ReadVertexNormals(cb func(vertex math32.Vector3) bool)
- func (g *Geometry) ReadVertices(cb func(vertex math32.Vector3) bool)
- func (g *Geometry) RenderSetup(gs *gls.GLS)
- func (g *Geometry) RotationalInertia(mass float32) math32.Matrix3
- func (g *Geometry) SetAttributeName(atype gls.AttribType, attribName string)
- func (g *Geometry) SetIndices(indices math32.ArrayU32)
- func (g *Geometry) VBO(atype gls.AttribType) *gls.VBO
- func (g *Geometry) VBOName(name string) *gls.VBO
- func (g *Geometry) VBOs() []*gls.VBO
- func (g *Geometry) Volume() float32
- type Group
- type IGeometry
- type MorphGeometry
- func (mg *MorphGeometry) ActiveMorphTargets() ([]*Geometry, []float32)
- func (mg *MorphGeometry) AddMorphTargetDeltas(morphTargetDeltas ...*Geometry)
- func (mg *MorphGeometry) AddMorphTargets(morphTargets ...*Geometry)
- func (mg *MorphGeometry) ComputeMorphed(weights []float32) *Geometry
- func (mg *MorphGeometry) Dispose()
- func (mg *MorphGeometry) GetGeometry() *Geometry
- func (mg *MorphGeometry) RenderSetup(gs *gls.GLS)
- func (mg *MorphGeometry) SetIndices(indices math32.ArrayU32)
- func (mg *MorphGeometry) SetWeights(weights []float32)
- func (mg *MorphGeometry) UpdateTargetAttributes(morphTargets []*Geometry)
- func (mg *MorphGeometry) Weights() []float32
Constants ¶
const MaxActiveMorphTargets = 8
MaxActiveMorphTargets is the maximum number of active morph targets.
Variables ¶
This section is empty.
Functions ¶
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 NewCone ¶ added in v0.2.0
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 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
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
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 ¶
NewPlane creates a plane geometry with the specified width and height. The plane is generated centered in the XY plane with Z=0.
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 ¶
NewSegmentedCube creates a segmented cube geometry with the specified size and number of segments.
func NewSegmentedPlane ¶ added in v0.2.0
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 ¶
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 (*Geometry) AddGroupList ¶
AddGroupList adds the specified list of groups to this geometry.
func (*Geometry) ApplyMatrix ¶
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 ¶
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 ¶
BoundingBox computes the bounding box of the geometry if necessary and returns is value.
func (*Geometry) BoundingSphere ¶
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 ¶
GetGeometry satisfies the IGeometry interface.
func (*Geometry) GroupCount ¶
GroupCount returns the number of geometry groups (for multimaterial).
func (*Geometry) Incref ¶
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) Items ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
RenderSetup is called by the renderer before drawing the geometry.
func (*Geometry) RotationalInertia ¶
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 ¶
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 ¶
VBOName returns a pointer to this geometry's VBO which contain the specified attribute. Returns nil if the VBO is not found.
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 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.