shadoof

package module
v0.0.0-...-2e6d090 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2022 License: MIT Imports: 4 Imported by: 0

README

ShaDooF

ShaDooF is a hodgepodge library of helpers for use with deadsy/sdfx for programmatic CAD via signed distance fields.

These utilities are intended to be pragmatic tools for quick hacking, which means that they often come with caveats, and these caveats are documented as thoroughly as possible.

In particular, some of the SDFs in this library do not produce correct signs, but incorrect magnitudes when evaluated. This means that they will render correctly in isolation, but some more complex operations like sdf.Shell3D will not produce exactly correct results. This is the same caveat that applies to sdf.Transform3D for scale transforms.

Transforms

transform.go provides a number of convenience functions for positioning SDFs. Most of these deal with centering and aligning two SDFs based on their bounding boxes. It is important to note that these functions will only work correctly if the bounding boxes are minimal, and that this is not guaranteed for all SDFs.

Bounding boxes are fundamentally a performance facility, not a measurement facility. For example, rotations by non-integer multiples of π/2 will always cause an SDFs bounding box to expand, even if the minimal bounding box is unchanged. Even a sphere, which has rotational symmetry in every direction will see its bounding box expand under rotation. In these cases, the alignment functions will not behave as you expect.

Nonetheless, as a pragmatic tool, alignment via bounding boxes is extremely convenient and useful, so long as you understand its limitations.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AbutWith2D

func AbutWith2D(s1, s2 sdf.SDF2, side Side) sdf.SDF2

Move s2 so that its bounding box abuts the given side of s1's bounding box. Only one coordinate is ever translated.

func AbutWith3D

func AbutWith3D(s1, s2 sdf.SDF3, side Side) sdf.SDF3

Move s2 so that its bounding box abuts the given side of s1's bounding box. Only one coordinate is ever translated. Note that "Top" and "Bottom" refer to the Z coordinate, unlike in the 2D case where they refer to the Y coordinate. For the 3D case, "Front" refers to negative Y.

func AlignWith2D

func AlignWith2D(s1, s2 sdf.SDF2, side Side) sdf.SDF2

Move s2 so that the given side of its bounding box aligns with the same side of s1's bounding box.

func AlignWith3D

func AlignWith3D(s1, s2 sdf.SDF3, side Side) sdf.SDF3

Move s2 so that the given side of its bounding box aligns with the same side of s1's bounding box. Note that "Top" and "Bottom" refer to the Z coordinate, unlike in the 2D case where they refer to the Y coordinate. For the 3D case, "Front" refers to negative Y.

func Center2DWith3D

func Center2DWith3D(s1 sdf.SDF3, s2 sdf.SDF2) sdf.SDF2

Move s2 so that its bounding box is centered on s1's bounding box. That is, it centers the X and Y coordinates, ignoring s1's Z coordinate.

func CenterWith2D

func CenterWith2D(s1, s2 sdf.SDF2) sdf.SDF2

Move s2 so that its bounding box is centered on s1's bounding box.

func CenterWith3D

func CenterWith3D(s1, s2 sdf.SDF3) sdf.SDF3

Move s2 so that its bounding box is centered on s1's bounding box.

func SetOnXYPlane

func SetOnXYPlane(s sdf.SDF3) sdf.SDF3

Set an SDF on the XY plane.

func Translate2D

func Translate2D(s sdf.SDF2, x float64, y float64) sdf.SDF2

Convenience function for translating a 2D SDF, with less boilerplate

func Translate3D

func Translate3D(s sdf.SDF3, x float64, y float64, z float64) sdf.SDF3

Convenience function for translating a 3D SDF, with less boilerplate

func WrapAroundCylinder

func WrapAroundCylinder(sdf2d sdf.SDF2, innerRadius, thickness, roundInside, roundOutside float64) sdf.SDF3

Create an SDF3 by wrapping an SDF2 around a cylinder with a given thickness.

Lengths are preserved on the inside of the wrapped SDF, and points are sampled for -r/2 < x < r/2, where r is the inner radius, so if the 2D SDF is wider than the circumference of the cylinder, it will be clipped.

Both the inside and outside can be rounded independently via PolyMax.

Note that if you wish to subtract this from a cylinder (for embossing, for example), you will need to subtract the thickness from the radius you provide. So if you are trying to create a seamless embossing around the entire cylinder, you must ensure that the 2D SDF's width is the 2*pi*r, where r is that adjusted radius.

Types

type Side

type Side int
const (
	Left Side = iota
	Right
	Top
	Bottom
	Front
	Back
)

type WrapSylinderSDF

type WrapSylinderSDF struct {
	SDF2 sdf.SDF2
	// contains filtered or unexported fields
}

An SDF2 wrapped around a cylinder

func (*WrapSylinderSDF) BoundingBox

func (s *WrapSylinderSDF) BoundingBox() sdf.Box3

func (*WrapSylinderSDF) Evaluate

func (s *WrapSylinderSDF) Evaluate(p v3.Vec) float64

Jump to

Keyboard shortcuts

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