Documentation
¶
Index ¶
- func ReadBinarySTL(r io.Reader) (output []ms3.Triangle, readErr error)
- func RenderAll(r Renderer, userData any) ([]ms3.Triangle, error)
- func WriteBinarySTL(w io.Writer, model []ms3.Triangle) (int, error)
- type DualContourLeastSquares
- type DualContourRenderer
- type DualContourer
- type DualCube
- func (dc *DualCube) ActiveX() bool
- func (dc *DualCube) ActiveY() bool
- func (dc *DualCube) ActiveZ() bool
- func (dc *DualCube) EdgeNeighborsX() [4]ivec
- func (dc *DualCube) EdgeNeighborsY() [4]ivec
- func (dc *DualCube) EdgeNeighborsZ() [4]ivec
- func (dc *DualCube) FlipX() bool
- func (dc *DualCube) FlipY() bool
- func (dc *DualCube) FlipZ() bool
- func (dc *DualCube) IsActive() bool
- func (dc *DualCube) IsectLinearX() float32
- func (dc *DualCube) IsectLinearY() float32
- func (dc *DualCube) IsectLinearZ() float32
- func (dc *DualCube) SizeAndOrigin(res float32, octreeOrigin ms3.Vec) (float32, ms3.Vec)
- type ImageRendererSDF2
- type Octree
- type Renderer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type DualContourLeastSquares ¶
type DualContourLeastSquares struct { }
DualContourLeastSquares is a vertex placement strategy which solves the least squares problem to place vertices.
type DualContourRenderer ¶
type DualContourRenderer struct {
// contains filtered or unexported fields
}
func (*DualContourRenderer) Reset ¶
func (dcr *DualContourRenderer) Reset(sdf gleval.SDF3, res float32, vertexPlacer DualContourer, userData any) error
type DualContourer ¶
type DualContourer interface { // PlaceVertices should edit the FinalVertex field of all [DualCube]s in the cubes buffer. // These resulting vertices are then used for quad/triangle meshing. PlaceVertices(cubes []DualCube, origin ms3.Vec, res float32, sdf gleval.SDF3, posbuf []ms3.Vec, distbuf []float32, userData any) error }
type DualCube ¶
type DualCube struct { // Neighbors contains neighboring index into dualCube buffer and contributing edge intersect axis. // - Neighbors[0]: Index into dualCube buffer to cube neighbor with edge. // - Neighbors[1]: Intersecting axis. 0 is x; 1 is y; 2 is z. // - Neighbors[2]: Auxiliary index for use by user, such as normal indexing. Neighbors [][3]int // Distance from cube origin to SDF. OrigDist float32 // Distance from (x,y,z) edge vertices to SDF. These edges are coincident with cube origin. XDist, YDist, ZDist float32 // FinalVertex set by vertex placement strategy. Decides the final resting place of the vertex of the cube // which will be the vertex meshed. FinalVertex ms3.Vec // contains filtered or unexported fields }
DualCube corresponds to a voxel anmd contains both cube and edge data.
func (*DualCube) EdgeNeighborsX ¶
func (dc *DualCube) EdgeNeighborsX() [4]ivec
func (*DualCube) EdgeNeighborsY ¶
func (dc *DualCube) EdgeNeighborsY() [4]ivec
func (*DualCube) EdgeNeighborsZ ¶
func (dc *DualCube) EdgeNeighborsZ() [4]ivec
func (*DualCube) IsectLinearX ¶
func (*DualCube) IsectLinearY ¶
func (*DualCube) IsectLinearZ ¶
type ImageRendererSDF2 ¶
type ImageRendererSDF2 struct {
// contains filtered or unexported fields
}
ImageRendererSDF2 converts 2D SDFs to images.
func NewImageRendererSDF2 ¶
func NewImageRendererSDF2(evalBufferSize int, conversion func(float32) color.Color) (*ImageRendererSDF2, error)
NewImageRendererSDF2 instances a new ImageRendererSDF2 to render images from 2D SDFs. A nil float->color conversion function results in a simple black-white color scheme where black is the interior of the SDF (negative distance).
Below is Inigo Quilez's famous color conversion for debugging SDF's:
func colorConversion(d float32) color.Color { // d /= bb.Size().Max()/4 // Normalize distances using bounding box dimensions to get consistent visuals. var one = ms3.Vec{1, 1, 1} var c ms3.Vec if d > 0 { c = ms3.Vec{0.9, 0.6, 0.3} } else { c = ms3.Vec{0.65, 0.85, 1.0} } c = ms3.Scale(1-math32.Exp(-6*math32.Abs(d)), c) c = ms3.Scale(0.8+0.2*math32.Cos(150*d), c) max := 1 - ms1.SmoothStep(0, 0.01, math32.Abs(d)) c = ms3.InterpElem(c, one, ms3.Vec{max, max, max}) return color.RGBA{ R: uint8(c.X * 255), G: uint8(c.Y * 255), B: uint8(c.Z * 255), A: 255, } }
func (*ImageRendererSDF2) Render ¶
func (ir *ImageRendererSDF2) Render(sdf gleval.SDF2, img setImage, userData any) error
Render maps the SDF2 to the input Image and renders it. It uses userData as an argument to all gleval.SDF2.Evaluate calls.
type Octree ¶
type Octree struct {
// contains filtered or unexported fields
}
Octree is a marching-triangles Octree implementation with sub-cube pruning.
func NewOctreeRenderer ¶
NewOctreeRenderer instantiates a new Octree renderer for rendering triangles from an gleval.SDF3.
func (*Octree) ReadTriangles ¶
func (*Octree) Reset ¶
Reset switched the underlying SDF3 for a new one with a new cube resolution. It reuses the same evaluation buffers and cube buffer if it can.
func (*Octree) TotalPruned ¶
TotalPruned returns the amount of minimum resolution cubes pruned throughout the rendering of the current SDF3. This number is reset on a call to Reset.