engine: github.com/g3n/engine/geometry Index | Files

package geometry

import "github.com/g3n/engine/geometry"

Package geometry implements several primitive geometry generators.

Index

Package Files

box.go circle.go cylinder.go doc.go geometry.go logger.go morph.go plane.go sphere.go torus.go

Constants

const MaxActiveMorphTargets = 8

MaxActiveMorphTargets is the maximum number of active morph targets.

type Box Uses

type Box struct {
    Geometry
    Width          float32
    Height         float32
    Length         float32
    WidthSegments  int // > 0
    HeightSegments int // > 0
    LengthSegments int // > 0
}

Box represents the geometry of a rectangular cuboid. See https://en.wikipedia.org/wiki/Cuboid#Rectangular_cuboid for more details. A Box geometry is defined by its width, height, and length and also by the number of segments in each dimension.

func NewBox Uses

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

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

func NewCube Uses

func NewCube(size float32) *Box

NewCube creates a new cube geometry of the specified size.

func NewSegmentedBox Uses

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

NewSegmentedBox creates a box geometry of the specified size and with the specified number of segments in each dimension. This is the Box constructor with most tunable parameters.

func NewSegmentedCube Uses

func NewSegmentedCube(size float32, segments int) *Box

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

type Circle Uses

type Circle struct {
    Geometry
    Radius      float64
    Segments    int // >= 3
    ThetaStart  float64
    ThetaLength float64
}

Circle represents the geometry of a filled circle (i.e. a disk) The center of the circle is at the origin, and theta runs counter-clockwise on the XY plane, starting at (x,y,z)=(1,0,0).

func NewCircle Uses

func NewCircle(radius float64, segments int) *Circle

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

func NewCircleSector Uses

func NewCircleSector(radius float64, segments int, thetaStart, thetaLength float64) *Circle

NewCircleSector creates a new circle or circular sector geometry with the specified radius, number of radial segments/triangles (minimum 3), sector start angle in radians (thetaStart), and sector size angle in radians (thetaLength). This is the Circle constructor with most tunable parameters.

type Cylinder Uses

type Cylinder struct {
    Geometry
    RadiusTop      float64
    RadiusBottom   float64
    Height         float64
    RadialSegments int
    HeightSegments int
    ThetaStart     float64
    ThetaLength    float64
    Top            bool
    Bottom         bool
}

Cylinder represents a cylinder geometry

func NewCylinder Uses

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

NewCylinder creates and returns a pointer to a new Cylinder geometry object.

type Geometry Uses

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

Geometry encapsulates a three-dimensional vertex-based geometry.

func NewGeometry Uses

func NewGeometry() *Geometry

NewGeometry creates and returns a pointer to a new Geometry.

func (*Geometry) AddGroup Uses

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

AddGroup adds a geometry group (for multimaterial).

func (*Geometry) AddGroupList Uses

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

AddGroupList adds the specified list of groups to this geometry.

func (*Geometry) AddVBO Uses

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

AddVBO adds a Vertex Buffer Object for this geometry.

func (*Geometry) ApplyMatrix Uses

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 Uses

func (g *Geometry) Area() float32

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

func (*Geometry) AttributeName Uses

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 Uses

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

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

func (*Geometry) BoundingSphere Uses

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

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

func (*Geometry) Dispose Uses

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 Uses

func (g *Geometry) GetGeometry() *Geometry

GetGeometry satisfies the IGeometry interface.

func (*Geometry) GroupAt Uses

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

GroupAt returns pointer to geometry group at the specified index.

func (*Geometry) GroupCount Uses

func (g *Geometry) GroupCount() int

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

func (*Geometry) Incref Uses

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 Uses

func (g *Geometry) Indexed() bool

Indexed returns whether the geometry is indexed or not.

func (*Geometry) Indices Uses

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

Indices returns the indices array for this geometry.

func (*Geometry) Init Uses

func (g *Geometry) Init()

Init initializes the geometry.

func (*Geometry) Items Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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 Uses

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

RenderSetup is called by the renderer before drawing the geometry.

func (*Geometry) RotationalInertia Uses

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 Uses

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 Uses

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

SetIndices sets the indices array for this geometry.

func (*Geometry) SetVAO Uses

func (g *Geometry) SetVAO(handle uint32)

SetVAO sets the Vertex Array Object handle associated with this geometry.

func (*Geometry) VAO Uses

func (g *Geometry) VAO() uint32

VAO returns the Vertex Array Object handle associated with this geometry.

func (*Geometry) VBO Uses

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 Uses

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 Uses

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

VBOs returns all of this geometry's VBOs.

func (*Geometry) Volume Uses

func (g *Geometry) Volume() float32

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

type Group Uses

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 Uses

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

IGeometry is the interface for all geometries.

type MorphGeometry Uses

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

MorphGeometry represents a base geometry and its morph targets.

func NewMorphGeometry Uses

func NewMorphGeometry(baseGeometry *Geometry) *MorphGeometry

NewMorphGeometry creates and returns a pointer to a new MorphGeometry.

func (*MorphGeometry) ActiveMorphTargets Uses

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 Uses

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

AddMorphTargetDeltas add multiple morph target deltas to the morph geometry.

func (*MorphGeometry) AddMorphTargets Uses

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 Uses

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 Uses

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 Uses

func (mg *MorphGeometry) GetGeometry() *Geometry

GetGeometry satisfies the IGeometry interface.

func (*MorphGeometry) RenderSetup Uses

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

RenderSetup is called by the renderer before drawing the geometry.

func (*MorphGeometry) SetIndices Uses

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

SetIndices sets the indices array for this geometry.

func (*MorphGeometry) SetWeights Uses

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

SetWeights sets the morph target weights.

func (*MorphGeometry) UpdateTargetAttributes Uses

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

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

func (*MorphGeometry) Weights Uses

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

Weights returns the morph target weights.

type Plane Uses

type Plane struct {
    Geometry
    Width          float32
    Height         float32
    WidthSegments  int
    HeightSegments int
}

Plane represents a plane geometry

func NewPlane Uses

func NewPlane(width, height float32, widthSegments, heightSegments int) *Plane

NewPlane creates and returns a pointer to a Plane Geometry. The plane is defined by its width, height and the number of width and height segments. The minimum number of segments for the width and/or the height is 1. The plane is generated centered in the XY plane with Z=0.

type Sphere Uses

type Sphere struct {
    Geometry
    Radius         float64
    WidthSegments  int
    HeightSegments int
    PhiStart       float64
    PhiLength      float64
    ThetaStart     float64
    ThetaLength    float64
}

Sphere represents a sphere geometry

func NewSphere Uses

func NewSphere(radius float64, widthSegments, heightSegments int, phiStart, phiLength, thetaStart, thetaLength float64) *Sphere

NewSphere returns a pointer to a new Sphere geometry object

type Torus Uses

type Torus struct {
    Geometry                // embedded geometry
    Radius          float64 // Torus radius
    Tube            float64 // Diameter of the torus tube
    RadialSegments  int     // Number of radial segments
    TubularSegments int     // Number of tubular segments
    Arc             float64 // Central angle
}

Torus represents a torus geometry

func NewTorus Uses

func NewTorus(radius, tube float64, radialSegments, tubularSegments int, arc float64) *Torus

NewTorus returns a pointer to a new torus geometry

Package geometry imports 6 packages (graph) and is imported by 23 packages. Updated 2018-08-17. Refresh now. Tools for package owners.