SDF

SDF()

Abstract base class for Signed Distance Functions.

An SDF represents geometry implicitly as a function f(p) -> distance, where: - f(p) < 0: point p is inside the shape - f(p) = 0: point p is on the surface - f(p) > 0: point p is outside the shape

Attributes

Name Type Description
params dict[str, Parameter] Dictionary of Parameter objects for this SDF operation

SDF classes are thin wrappers around pure functions: - Provide fluent API: .translate().rotate() chaining - Enable operators: sphere | box, sphere & box - Store parameters for later compilation - Actual computation happens in pure functions

Each SDF instance should store its parameters in self.params dictionary: self.params = { ‘radius’: Scalar(value=1.0, free=True, name=‘radius’), ‘offset’: Vector(value=[0, 0, 0], free=False), }

Subclasses must implement: - @staticmethod def sdf(…): Pure function for computation (CONVENTION) - call(p): Evaluate SDF (delegates to sdf())

Pattern for primitives

@staticmethod def sdf(p: Array, param1: float, param2: float) -> Array: # Pure computation here

def call(self, p: Array) -> Array: return ClassName.sdf(p, self.params[‘param1’].value, self.params[‘param2’].value)

Pattern for transforms

@staticmethod def sdf(child_sdf: Callable, p: Array, param: float) -> Array: # Transform computation here

def call(self, p: Array) -> Array: return ClassName.sdf(self.child_sdf, p, self.params[‘param’].value)

Methods

Name Description
material_at Return material properties at point p.
patch_fields Return this node’s smooth patch fields in its own frame, if known.

material_at

SDF.material_at(_p)

Return material properties at point p.

Default implementation returns a white, matte, opaque material. Subclasses override this to return per-primitive or blended materials.

Parameters

Name Type Description Default
p Query point, shape (3,). required

Returns

Name Type Description
dict Dict with keys ‘color’, ‘roughness’, ‘metallic’, ‘opacity’.

patch_fields

SDF.patch_fields()

Return this node’s smooth patch fields in its own frame, if known.

A patch field decomposition expresses the node’s surface as pieces of the zero sets of smooth scalar fields f_i — the node’s SDF is internally a min/max composition over them (Box: six face half-space distances; Cylinder: side plus two caps). A surface point p belongs to patch argmin_i |f_i(p)|, and the node’s exact feature edges are exactly where that ownership switches.

Transforms forward the protocol by mapping the query point into the child frame exactly as their sdf does. Nodes without an exact decomposition return None (the default), which consumers treat gracefully as “one opaque patch”.

Returns

Name Type Description
list[Callable[[Array], Array]] | None List of callables f_i(p) accepting points shaped (..., 3)
list[Callable[[Array], Array]] | None in this node’s frame and returning values shaped (...), or
list[Callable[[Array], Array]] | None None when no exact decomposition is available.