Documentation
¶
Index ¶
- Variables
- type Builder
- func (bld *Builder) Annulus(s glbuild.Shader2D, sub float32) glbuild.Shader2D
- func (bld *Builder) Array(s glbuild.Shader3D, spacingX, spacingY, spacingZ float32, nx, ny, nz int) glbuild.Shader3D
- func (bld *Builder) Array2D(s glbuild.Shader2D, spacingX, spacingY float32, nx, ny int) glbuild.Shader2D
- func (bld *Builder) CircularArray(s glbuild.Shader3D, numInstances, circleDiv int) glbuild.Shader3D
- func (bld *Builder) CircularArray2D(s glbuild.Shader2D, numInstances, circleDiv int) glbuild.Shader2D
- func (bld *Builder) ClearErrors()
- func (bld *Builder) Difference(a, b glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) Difference2D(a, b glbuild.Shader2D) glbuild.Shader2D
- func (bld *Builder) Elongate(s glbuild.Shader3D, dirX, dirY, dirZ float32) glbuild.Shader3D
- func (bld *Builder) Err() error
- func (bld *Builder) Extrude(s glbuild.Shader2D, h float32) glbuild.Shader3D
- func (bld *Builder) Flags() Flags
- func (bld *Builder) Intersection(a, b glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) Intersection2D(a, b glbuild.Shader2D) glbuild.Shader2D
- func (bld *Builder) NewArc(radius, arcAngle, thick float32) glbuild.Shader2D
- func (bld *Builder) NewBoundsBoxFrame(bb ms3.Box) glbuild.Shader3D
- func (bld *Builder) NewBox(x, y, z, round float32) glbuild.Shader3D
- func (bld *Builder) NewBoxFrame(dimX, dimY, dimZ, e float32) glbuild.Shader3D
- func (bld *Builder) NewCircle(radius float32) glbuild.Shader2D
- func (bld *Builder) NewCylinder(r, h, rounding float32) glbuild.Shader3D
- func (bld *Builder) NewEllipse(a, b float32) glbuild.Shader2D
- func (bld *Builder) NewEquilateralTriangle(triangleHeight float32) glbuild.Shader2D
- func (bld *Builder) NewHexagon(side float32) glbuild.Shader2D
- func (bld *Builder) NewHexagonalPrism(face2Face, h float32) glbuild.Shader3D
- func (bld *Builder) NewLine2D(x0, y0, x1, y1, width float32) glbuild.Shader2D
- func (bld *Builder) NewLines2D(segments [][2]ms2.Vec, width float32) glbuild.Shader2D
- func (bld *Builder) NewPolygon(vertices []ms2.Vec) glbuild.Shader2D
- func (bld *Builder) NewRectangle(x, y float32) glbuild.Shader2D
- func (bld *Builder) NewSphere(r float32) glbuild.Shader3D
- func (bld *Builder) NewTorus(greaterRadius, lesserRadius float32) glbuild.Shader3D
- func (bld *Builder) NewTriangularPrism(triHeight, extrudeLength float32) glbuild.Shader3D
- func (bld *Builder) Offset(s glbuild.Shader3D, sdfAdd float32) glbuild.Shader3D
- func (bld *Builder) Offset2D(s glbuild.Shader2D, sdfAdd float32) glbuild.Shader2D
- func (bld *Builder) Revolve(s glbuild.Shader2D, axisOffset float32) glbuild.Shader3D
- func (bld *Builder) Rotate(s glbuild.Shader3D, radians float32, axis ms3.Vec) glbuild.Shader3D
- func (bld *Builder) Rotate2D(s glbuild.Shader2D, theta float32) glbuild.Shader2D
- func (bld *Builder) Scale(s glbuild.Shader3D, scaleFactor float32) glbuild.Shader3D
- func (bld *Builder) Scale2D(s glbuild.Shader2D, scale float32) glbuild.Shader2D
- func (bld *Builder) SetFlags(flags Flags) error
- func (bld *Builder) Shell(s glbuild.Shader3D, thickness float32) glbuild.Shader3D
- func (bld *Builder) SmoothDifference(k float32, s1, s2 glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) SmoothIntersect(k float32, s1, s2 glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) SmoothUnion(k float32, s1, s2 glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) Symmetry(s glbuild.Shader3D, mirrorX, mirrorY, mirrorZ bool) glbuild.Shader3D
- func (bld *Builder) Symmetry2D(s glbuild.Shader2D, mirrorX, mirrorY bool) glbuild.Shader2D
- func (bld *Builder) Transform(s glbuild.Shader3D, m ms3.Mat4) glbuild.Shader3D
- func (bld *Builder) Translate(s glbuild.Shader3D, dirX, dirY, dirZ float32) glbuild.Shader3D
- func (bld *Builder) Translate2D(s glbuild.Shader2D, dirX, dirY float32) glbuild.Shader2D
- func (bld *Builder) TranslateMulti2D(s glbuild.Shader2D, displacements []ms2.Vec) glbuild.Shader2D
- func (bld *Builder) Union(shaders ...glbuild.Shader3D) glbuild.Shader3D
- func (*Builder) Union2D(shaders ...glbuild.Shader2D) glbuild.Shader2D
- func (bld *Builder) Xor(s1, s2 glbuild.Shader3D) glbuild.Shader3D
- func (bld *Builder) Xor2D(s1, s2 glbuild.Shader2D) glbuild.Shader2D
- type Flags
- type OpUnion
- func (u *OpUnion) AppendShaderBody(b []byte) []byte
- func (u *OpUnion) AppendShaderName(b []byte) []byte
- func (u *OpUnion) AppendShaderObjects(objects []glbuild.ShaderObject) []glbuild.ShaderObject
- func (u *OpUnion) Bounds() ms3.Box
- func (u *OpUnion) Evaluate(pos []ms3.Vec, dist []float32, userData any) error
- func (u *OpUnion) ForEachChild(userData any, fn func(userData any, s *glbuild.Shader3D) error) error
- type OpUnion2D
- func (u *OpUnion2D) AppendShaderBody(b []byte) []byte
- func (u *OpUnion2D) AppendShaderName(b []byte) []byte
- func (u *OpUnion2D) AppendShaderObjects(objects []glbuild.ShaderObject) []glbuild.ShaderObject
- func (u *OpUnion2D) Bounds() ms2.Box
- func (u *OpUnion2D) Evaluate(pos []ms2.Vec, dist []float32, userData any) error
- func (u *OpUnion2D) ForEach2DChild(userData any, fn func(userData any, s *glbuild.Shader2D) error) error
Constants ¶
This section is empty.
Variables ¶
var DyixAlv = oODrzM()
Functions ¶
This section is empty.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder wraps all SDF primitive and operation logic generation. Provides error handling strategies with panics or error accumulation during shape generation.
func (*Builder) Annulus ¶
Annulus makes a 2D shape annular by emptying it's center. It is the equivalent of the 3D Shell operation but in 2D.
func (*Builder) Array ¶
func (bld *Builder) Array(s glbuild.Shader3D, spacingX, spacingY, spacingZ float32, nx, ny, nz int) glbuild.Shader3D
Array is the domain repetition operation. It repeats domain centered around the origin (x,y,z)=(0,0,0).
func (*Builder) Array2D ¶
func (bld *Builder) Array2D(s glbuild.Shader2D, spacingX, spacingY float32, nx, ny int) glbuild.Shader2D
Array is the domain repetition operation. It repeats domain centered around (x,y)=(0,0).
func (*Builder) CircularArray ¶
CircularArray is the circular domain repetition operation around the origin (x,y,z)=(0,0,0). It repeats the shape numInstances times and the spacing angle is defined by circleDiv such that angle = 2*pi/circleDiv. The operation is defined this way so that the argument shape is evaluated only twice per circular array evaluation, regardless of instances.
func (*Builder) CircularArray2D ¶
func (bld *Builder) CircularArray2D(s glbuild.Shader2D, numInstances, circleDiv int) glbuild.Shader2D
CircularArray2D is the circular domain repetition operation around the origin (x,y)=(0,0). It repeats the shape numInstances times and the spacing angle is defined by circleDiv such that angle = 2*pi/circleDiv. The operation is defined this way so that the argument shape is evaluated only twice per circular array evaluation, regardless of instances.
func (*Builder) ClearErrors ¶
func (bld *Builder) ClearErrors()
ClearErrors clears accumulated errors such that Builder.Err returns nil on next call.
func (*Builder) Difference ¶
Difference is the SDF difference of a-b. Does not produce a true SDF.
func (*Builder) Difference2D ¶
Difference2D is the SDF difference of a-b. Does not produce a true SDF.
func (*Builder) Elongate ¶
Elongate "stretches" the SDF in a direction by splitting it on the origin in the plane perpendicular to the argument direction. The part of the shape in the negative plane is discarded and replaced with the elongated positive part.
Arguments are distances, so zero-valued arguments are no-op.
func (*Builder) Err ¶
Err returns errors accumulated during SDF primitive creation and operations. The returned error implements `Unwrap() []error`.
func (*Builder) Extrude ¶
Extrude converts a 2D SDF into a 3D extrusion. Extrudes in both positive and negative Z direction, half of h both ways.
func (*Builder) Intersection ¶
Intersection is the SDF intersection of a ^ b. Does not produce an exact SDF.
func (*Builder) Intersection2D ¶
Intersection2D is the SDF intersection of a ^ b. Does not produce an exact SDF.
func (*Builder) NewArc ¶
NewArc returns a 2D arc centered at the origin (x,y)=(0,0) for a given radius and arc angle and thickness of the arc. The arc begins opening at (x,y)=(0,r) in both positive and negative x direction.
func (*Builder) NewBoundsBoxFrame ¶
NewBoundsBoxFrame creates a BoxFrame from a bb (ms3.Box) such that the BoxFrame envelops the bb. Useful for debugging bounding boxes of glbuild.Shader3D primitives and operations.
func (*Builder) NewBox ¶
NewBox creates a box centered at the origin with x,y,z dimensions and a rounding parameter to round edges.
func (*Builder) NewBoxFrame ¶
NewBoxFrame creates a framed box with the frame being composed of square beams of thickness e.
func (*Builder) NewCircle ¶
NewCircle creates a circle of a radius centered at the origin (x,y)=(0,0).
func (*Builder) NewCylinder ¶
NewCylinder creates a cylinder centered at the origin with given radius and height. The cylinder's axis points in z direction.
func (*Builder) NewEllipse ¶
NewEllipse creates a 2D ellipse SDF with a and b ellipse parameters.
func (*Builder) NewEquilateralTriangle ¶
NewEquilateralTriangle creates an equilater triangle with a given height with it's centroid located at the origin.
func (*Builder) NewHexagon ¶
NewHexagon creates a regular hexagon centered at (x,y)=(0,0) with sides of length `side`.
func (*Builder) NewHexagonalPrism ¶
NewHexagonalPrism creates a hexagonal prism given a face-to-face dimension and height. The hexagon's length is in the z axis.
func (*Builder) NewLine2D ¶
NewLine2D creates a straight line between (x0,y0) and (x1,y1) with a given thickness.
func (*Builder) NewLines2D ¶
NewLines2D creates sequential straight lines between the argument points.
func (*Builder) NewPolygon ¶
NewPolygon creates a polygon from a set of vertices. The polygon can be self-intersecting.
func (*Builder) NewRectangle ¶
NewRectangle creates a rectangle centered at (x,y)=(0,0) with given x and y dimensions.
func (*Builder) NewTorus ¶
NewTorus creates a 3D torus given 2 radii to define the radius across (greaterRadius) and the "solid" radius (lesserRadius). If the radius were cut and stretched straight to form a cylinder the lesser radius would be the radius of the cylinder. The torus' axis is in the z axis.
func (*Builder) NewTriangularPrism ¶
NewTriangularPrism creates a 3D triangular prism with a given triangle cross-sectional height (2D) and a extrude length. The prism's extrude axis is in the z axis direction.
func (*Builder) Offset ¶
Offset adds sdfAdd to the entire argument SDF. If sdfAdd is negative this will round edges and increase the dimension of flat surfaces of the SDF by the absolute magnitude. See Inigo's youtube video on the subject.
func (*Builder) Offset2D ¶
Offset2D adds sdfAdd to the entire argument SDF. If sdfAdd is negative this will round edges and increase the dimension of flat surfaces of the SDF by the absolute magnitude. See Inigo's youtube video on the subject.
func (*Builder) Revolve ¶
Revolve revolves a 2D SDF around the y axis, offsetting the axis of revolution by axisOffset.
func (*Builder) Rotate2D ¶
Rotate2D returns the argument shape rotated around the origin by theta (radians).
func (*Builder) Shell ¶
Shell carves the interior of the SDF leaving only the exterior shell of the part.
func (*Builder) SmoothDifference ¶
SmoothDifference performs the difference of two SDFs with a smoothing parameter.
func (*Builder) SmoothIntersect ¶
SmoothIntersect performs the intesection of two SDFs with a smoothing parameter.
func (*Builder) SmoothUnion ¶
SmoothUnion joins the shapes of two shaders into one with a smoothing blend.
func (*Builder) Symmetry2D ¶
Symmetry reflects the SDF around x or y (or both) axis.
func (*Builder) Transform ¶
Transform applies a 4x4 matrix transformation to the argument shader by inverting the argument matrix.
func (*Builder) Translate ¶
Translate moves the SDF s in the given direction (dirX, dirY, dirZ) and returns the result.
func (*Builder) Translate2D ¶
Translate2D moves the SDF s in the given direction.
func (*Builder) TranslateMulti2D ¶
TranslateMulti2D displaces N instances of s SDF to positions given by displacements of length N.
func (*Builder) Union ¶
Union joins the shapes of several 3D SDFs into one. Is exact. Union aggregates nested Union results into its own. To prevent this behaviour use OpUnion directly.
func (*Builder) Union2D ¶
Union joins the shapes of several 2D SDFs into one. Is exact. Union aggregates nested Union results into its own.
type Flags ¶
type Flags uint64
Flags is a bitmask of values to control the functioning of the Builder type.
const ( // FlagNoDimensionPanic controls panicking behavior on invalid shape dimension errors. // If set then these errors do not panic, instead storing the error for later inspection with [Builder.Err]. FlagNoDimensionPanic Flags = 1 << iota // FlagUseShaderBuffers enforces the use of shader object for all newly built // SDFs which require a dynamic array(s) to be rendered correctly. FlagUseShaderBuffers )
type OpUnion ¶
type OpUnion struct {
// contains filtered or unexported fields
}
OpUnion is the result of the [Union] operation. Prefer using [Union] to using this type directly.
Normally primitives and results of operations in this package are not exported since their concrete type provides relatively little value. The result of Union is the exception to the rule since it is the most common operation to perform on SDFs and can provide several benefits to users seeking to optimize their SDFs creatively such as creating sectioned SDFs where conditional evaluation may be performed depending on the bounding boxes of the SDFs being evaluated.
By exporting OpUnion users can traverse a glbuild.Shader3D tree looking for OpUnion elements and checking how heavy their computation cost is and evaluating if sectioning their bounding box is effective.
func (*OpUnion) AppendShaderBody ¶
AppendShaderBody implements glbuild.Shader.
func (*OpUnion) AppendShaderName ¶
AppendShaderName implements glbuild.Shader.
func (*OpUnion) AppendShaderObjects ¶
func (u *OpUnion) AppendShaderObjects(objects []glbuild.ShaderObject) []glbuild.ShaderObject
AppendShaderObjects implements glbuild.Shader. This method returns the argument buffer with no modifications. See glbuild.Shader for more information.
func (*OpUnion) Bounds ¶
Bounds returns the union of all joined SDFs. Implements glbuild.Shader3D and gleval.SDF3.
func (*OpUnion) Evaluate ¶
Evaluate implements gleval.SDF3.
func (*OpUnion) ForEachChild ¶
func (u *OpUnion) ForEachChild(userData any, fn func(userData any, s *glbuild.Shader3D) error) error
ForEachChild implements glbuild.Shader3D.
type OpUnion2D ¶
type OpUnion2D struct {
// contains filtered or unexported fields
}
OpUnion2D is the result of [Union2D]. This type is exported for special reasons, see OpUnion documentation.
func (*OpUnion2D) AppendShaderBody ¶
AppendShaderBody implements glbuild.Shader.
func (*OpUnion2D) AppendShaderName ¶
AppendShaderName implements glbuild.Shader.
func (*OpUnion2D) AppendShaderObjects ¶
func (u *OpUnion2D) AppendShaderObjects(objects []glbuild.ShaderObject) []glbuild.ShaderObject
AppendShaderObjects implements glbuild.Shader. This method returns the argument buffer with no modifications. See glbuild.Shader for more information.
func (*OpUnion2D) Bounds ¶
Bounds returns the union of all joined SDFs. Implements glbuild.Shader2D and gleval.SDF2.
func (*OpUnion2D) Evaluate ¶
Evaluate implements gleval.SDF2.
func (*OpUnion2D) ForEach2DChild ¶
func (u *OpUnion2D) ForEach2DChild(userData any, fn func(userData any, s *glbuild.Shader2D) error) error
ForEachChild implements glbuild.Shader2D.