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 `mat32.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 BoxN(segs mat32.Vec3i) (nVtx, nIdx int)
- func CylinderSectorN(radialSegs, heightSegs int, top, bottom bool) (nVtx, nIdx int)
- func DiskSectorN(segs int) (nVtx, nIdx int)
- func PlaneN(wsegs, hsegs int) (nVtx, nIdx int)
- func SetBox(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Vec3
- func SetCone(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Box3
- func SetCylinderSector(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Box3
- func SetDiskSector(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Box3
- func SetPlane(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...)
- func SetPlaneAxisSize(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Vec3
- func SetSphereSector(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, ...) mat32.Box3
- func SphereSectorN(widthSegs, heightSegs int, elevStart, elevLen float32) (nVtx, nIdx int)
- type Box
- type Capsule
- type Cylinder
- type Plane
- type Shape
- type ShapeBase
- type ShapeGroup
- type Sphere
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
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). nVtx = (wsegs + 1) * (hsegs + 1) nIdx = wsegs * hsegs * 6
func SetBox ¶
func SetBox(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, size mat32.Vec3, segs mat32.Vec3i, pos mat32.Vec3) mat32.Vec3
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 Idx 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(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, height, radius float32, radialSegs, heightSegs int, bottom bool, pos mat32.Vec3) mat32.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(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, height, topRad, botRad float32, radialSegs, heightSegs int, angStart, angLen float32, top, bottom bool, pos mat32.Vec3) mat32.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(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, radius float32, segs int, angStart, angLen float32, pos mat32.Vec3) mat32.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 Idx 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 SetPlane ¶
func SetPlane(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, waxis, haxis mat32.Dims, wdir, hdir int, width, height, woff, hoff, zoff float32, wsegs, hsegs int, pos mat32.Vec3)
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 Idx 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(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, normAxis mat32.Dims, normNeg bool, size mat32.Vec2, segs mat32.Vec2i, offset float32, pos mat32.Vec3) mat32.Vec3
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 Idx 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.
func SetSphereSector ¶
func SetSphereSector(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32, vtxOff, idxOff int, radius float32, widthSegs, heightSegs int, angStart, angLen, elevStart, elevLen float32, pos mat32.Vec3) mat32.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 Idx 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 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).
Types ¶
type Box ¶
type Box struct {
ShapeBase
Size mat32.Vec3 `desc:"size along each dimension"`
Segs mat32.Vec3i `` /* 137-byte string literal not displayed */
}
Box is a rectangular-shaped solid (cuboid)
type Capsule ¶
type Capsule struct {
ShapeBase
Height float32 `desc:"height of the cylinder portion"`
TopRad float32 `desc:"radius of the top -- set to 0 to omit top cap"`
BotRad float32 `desc:"radius of the bottom -- set to 0 to omit bottom cap"`
RadialSegs int `min:"1" desc:"number of radial segments (32 is a reasonable default for full circle)"`
HeightSegs int `desc:"number of height segments"`
CapSegs int `desc:"number of segments in the hemisphere cap ends (16 is a reasonable default)"`
AngStart float32 `min:"0" max:"360" step:"5" desc:"starting angle in degrees, relative to -1,0,0 left side starting point"`
AngLen float32 `min:"0" max:"360" step:"5" desc:"total angle to generate in degrees (max 360)"`
}
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 float32 `desc:"height of the cylinder"`
TopRad float32 `desc:"radius of the top -- set to 0 for a cone"`
BotRad float32 `desc:"radius of the bottom"`
RadialSegs int `min:"1" desc:"number of radial segments (32 is a reasonable default for full circle)"`
HeightSegs int `desc:"number of height segments"`
Top bool `desc:"render the top disc"`
Bottom bool `desc:"render the bottom disc"`
AngStart float32 `min:"0" max:"360" step:"5" desc:"starting angle in degrees, relative to -1,0,0 left side starting point"`
AngLen float32 `min:"0" max:"360" step:"5" desc:"total angle to generate in degrees (max 360)"`
}
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 Plane ¶
type Plane struct {
ShapeBase
NormAxis mat32.Dims `` /* 235-byte string literal not displayed */
NormNeg bool `` /* 135-byte string literal not displayed */
Size mat32.Vec2 `desc:"2D size of plane"`
Segs mat32.Vec2i `` /* 132-byte string literal not displayed */
Offset float32 `desc:"offset from origin along direction of normal to the plane"`
}
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() (nVtx, nIdx int)
// Offs returns starting offset for verticies, indexes in full shape array,
// in terms of points, not floats
Offs() (vtxOff, idxOff int)
// SetOffs sets starting offset for verticies, indexes in full shape array,
// in terms of points, not floats
SetOffs(vtxOff, idxOff int)
// Set sets points in given allocated arrays
Set(vtxAry, normAry, texAry mat32.ArrayF32, idxAry mat32.ArrayU32)
// BBox returns the bounding box for the shape, typically centered around 0
// This is only valid after Set has been called.
BBox() mat32.Box3
}
Shape is an interface for all shape-constructing elements
type ShapeBase ¶
type ShapeBase struct {
VtxOff int `desc:"vertex offset, in points"`
IdxOff int `desc:"index offset, in points"`
CBBox mat32.Box3 `desc:"cubic bounding box in local coords"`
Pos mat32.Vec3 `desc:"all shapes take a 3D position offset to enable composition"`
}
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() (nVtx, nIdx int)
N returns number of vertex, index points in this shape element.
type Sphere ¶
type Sphere struct {
ShapeBase
Radius float32 `desc:"radius of the sphere"`
WidthSegs int `min:"3" desc:"number of segments around the width of the sphere (32 is reasonable default for full circle)"`
HeightSegs int `min:"3" desc:"number of height segments (32 is reasonable default for full height)"`
AngStart float32 `min:"0" max:"360" step:"5" desc:"starting radial angle in degrees, relative to -1,0,0 left side starting point"`
AngLen float32 `min:"0" max:"360" step:"5" desc:"total radial angle to generate in degrees (max = 360)"`
ElevStart float32 `min:"0" max:"180" step:"5" desc:"starting elevation (height) angle in degrees - 0 = top of sphere, and Pi is bottom"`
ElevLen float32 `min:"0" max:"180" step:"5" desc:"total angle to generate in degrees (max = 180)"`
}
Sphere is a sphere shape (can be a partial sphere too)