glrender

package
v0.0.0-...-a9b1306 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 20, 2024 License: BSD-3-Clause Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadBinarySTL

func ReadBinarySTL(r io.Reader) (output []ms3.Triangle, readErr error)

func RenderAll

func RenderAll(r Renderer, userData any) ([]ms3.Triangle, error)

RenderAll reads the full contents of a Renderer and returns the slice read. It does not return error on io.EOF, like the io.RenderAll implementation.

func WriteBinarySTL

func WriteBinarySTL(w io.Writer, model []ms3.Triangle) (int, error)

WriteBinarySTL writes model triangles to a writer in STL file format.

Types

type DualContourLeastSquares

type DualContourLeastSquares struct {
}

DualContourLeastSquares is a vertex placement strategy which solves the least squares problem to place vertices.

func (*DualContourLeastSquares) PlaceVertices

func (lsq *DualContourLeastSquares) PlaceVertices(cubes []DualCube, origin ms3.Vec, res float32, sdf gleval.SDF3, posbuf []ms3.Vec, distbuf []float32, userData any) error

type DualContourRenderer

type DualContourRenderer struct {
	// contains filtered or unexported fields
}

func (*DualContourRenderer) RenderAll

func (dcr *DualContourRenderer) RenderAll(dst []ms3.Triangle, userData any) ([]ms3.Triangle, error)

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) ActiveX

func (dc *DualCube) ActiveX() bool

func (*DualCube) ActiveY

func (dc *DualCube) ActiveY() bool

func (*DualCube) ActiveZ

func (dc *DualCube) ActiveZ() bool

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) FlipX

func (dc *DualCube) FlipX() bool

func (*DualCube) FlipY

func (dc *DualCube) FlipY() bool

func (*DualCube) FlipZ

func (dc *DualCube) FlipZ() bool

func (*DualCube) IsActive

func (dc *DualCube) IsActive() bool

func (*DualCube) IsectLinearX

func (dc *DualCube) IsectLinearX() float32

func (*DualCube) IsectLinearY

func (dc *DualCube) IsectLinearY() float32

func (*DualCube) IsectLinearZ

func (dc *DualCube) IsectLinearZ() float32

func (*DualCube) SizeAndOrigin

func (dc *DualCube) SizeAndOrigin(res float32, octreeOrigin ms3.Vec) (float32, ms3.Vec)

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

func NewOctreeRenderer(s gleval.SDF3, cubeResolution float32, evalBufferSize int) (*Octree, error)

NewOctreeRenderer instantiates a new Octree renderer for rendering triangles from an gleval.SDF3.

func (*Octree) ReadTriangles

func (oc *Octree) ReadTriangles(dst []ms3.Triangle, userData any) (n int, err error)

func (*Octree) Reset

func (oc *Octree) Reset(s gleval.SDF3, cubeResolution float32) error

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

func (oc *Octree) TotalPruned() uint64

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.

type Renderer

type Renderer interface {
	ReadTriangles(dst []ms3.Triangle, userData any) (n int, err error)
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL