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

      This section is empty.

      Types

      type Box

      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

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

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

          func NewCube

          func NewCube(size float32) *Box

            NewCube creates a new cube geometry of the specified size.

            func NewSegmentedBox

            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

              func NewSegmentedCube(size float32, segments int) *Box

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

                type Circle

                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

                  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

                    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

                      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

                        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

                          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

                            func NewGeometry() *Geometry

                              NewGeometry creates and returns a pointer to a new 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) SetVAO

                                                                                    func (g *Geometry) SetVAO(handle uint32)

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

                                                                                      func (*Geometry) VAO

                                                                                      func (g *Geometry) VAO() uint32

                                                                                        VAO returns the Vertex Array Object handle associated with 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.

                                                                                                                              type Plane

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

                                                                                                                                Plane represents a plane geometry

                                                                                                                                func NewPlane

                                                                                                                                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

                                                                                                                                  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

                                                                                                                                    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

                                                                                                                                      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

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

                                                                                                                                          NewTorus returns a pointer to a new torus geometry