Documentation ¶
Overview ¶
vshape 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 vgpu Memory allocation system.
Basic building blocks (e.g., Plane, SphereSector) have standalone methods, in addition to Shape elements.
Index ¶
- func BBoxFromVtxs(vertexArray math32.ArrayF32, vtxOff int, numVertex int) math32.Box3
- func BoxN(segs math32.Vector3i) (numVertex, nIndex int)
- func CylinderSectorN(radialSegs, heightSegs int, top, bottom bool) (numVertex, nIndex int)
- func DiskSectorN(segs int) (numVertex, nIndex int)
- func LinesN(npoints int, closed bool) (numVertex, nIndex int)
- func MiterPts(ax, ay, bx, by, cx, cy, w2 float32) math32.Vector2
- func PlaneN(wsegs, hsegs int) (numVertex, nIndex int)
- func QuadN() (numVertex, nIndex int)
- func SetBox(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Vector3
- func SetColor(colorArray math32.ArrayF32, vtxOff int, numVertex int, clr math32.Vector4)
- func SetCone(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetCylinderSector(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetDiskSector(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetLines(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetPlane(vertexArray, normArray, textureArray math32.ArrayF32, ...)
- func SetPlaneAxisSize(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Vector3
- func SetQuad(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetSphereSector(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetTorusSector(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SetTriangle(vertexArray, normArray, textureArray math32.ArrayF32, ...) math32.Box3
- func SphereSectorN(widthSegs, heightSegs int, elevStart, elevLen float32) (numVertex, nIndex int)
- func TorusSectorN(radialSegs, tubeSegs int) (numVertex, nIndex int)
- func TriangleN() (numVertex, nIndex int)
- type Box
- type Capsule
- type Cylinder
- type Lines
- type Plane
- type Shape
- type ShapeBase
- type ShapeGroup
- type Sphere
- type Torus
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BBoxFromVtxs ¶
BBoxFromVtxs returns the bounding box updated from the range of vertex points
func BoxN ¶
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 ¶
CylinderSectorN returns the N's for the cylinder (truncated cone) sector vertex and index data with given parameters
func DiskSectorN ¶
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 PlaneN ¶
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 SetBox ¶
func SetBox(vertexArray, normArray, textureArray math32.ArrayF32, indexArray math32.ArrayU32, vtxOff, idxOff int, size math32.Vector3, segs math32.Vector3i, pos math32.Vector3) math32.Vector3
SetBox sets box vertex, norm, 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 SetCone ¶
func SetCone(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray math32.ArrayU32, vtxOff, idxOff int, radius float32, segs int, angStart, angLen float32, pos math32.Vector3) math32.Box3
SetDiskSector sets a disk sector vertex, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray math32.ArrayU32, vtxOff, idxOff int, normAxis math32.Dims, normNeg bool, size math32.Vector2, segs math32.Vector2i, offset float32, pos math32.Vector3) math32.Vector3
SetPlaneAxisSize sets plane vertex, norm, 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 Norm 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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. Norm 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray math32.ArrayU32, vtxOff, idxOff int, radius, tubeRadius float32, radialSegs, tubeSegs int, angStart, angLen float32, pos math32.Vector3) math32.Box3
SetTorusSector sets torus sector vertex, norm, 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(vertexArray, normArray, textureArray math32.ArrayF32, indexArray 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. Norm is auto-computed, and bounds expanded. pos is a 3D position offset. returns 3D size of plane. returns bounding box.
func SphereSectorN ¶
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 ¶
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)
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) -- may potentially increase rendering quality to have > 1 Segs math32.Vector3i }
Box is a rectangular-shaped solid (cuboid)
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 ¶
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.
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 ¶
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 ¶
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.
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.
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 NormNeg for whether it is facing in the positive or negative of the given axis. NormAxis math32.Dims // if false, the plane normal facing in the positive direction along specified NormAxis, otherwise it faces in the negative if true NormNeg bool // 2D size of plane Size math32.Vector2 // number of segments to divide plane into (enforced to be at least 1) -- may potentially 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
type Shape ¶
type Shape interface { // N returns number of vertex, index points in this shape element N() (numVertex, nIndex int) // Offs returns starting offset for vertices, indexes in full shape array, // in terms of points, not floats Offs() (vtxOff, idxOff int) // SetOffs sets starting offset for vertices, indexes in full shape array, // in terms of points, not floats SetOffs(vtxOff, idxOff int) // Set sets points in given allocated arrays Set(vertexArray, normArray, textureArray math32.ArrayF32, indexArray math32.ArrayU32) // BBox returns the bounding box for the shape, typically centered around 0 // This is only valid after Set has been called. BBox() math32.Box3 }
Shape is an interface for all shape-constructing elements
type ShapeBase ¶
type ShapeBase struct { // vertex offset, in points VtxOff int // index offset, in points IndexOff 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) BBox ¶
BBox returns the bounding box for the shape, typically centered around 0 This is only valid after Set has been called.
type ShapeGroup ¶
ShapeGroup is a group of shapes -- returns summary data for shape elements
func (*ShapeGroup) N ¶
func (sb *ShapeGroup) N() (numVertex, nIndex int)
N 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)
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.