Skip to main content

SdfNode

Enum SdfNode 

Source
pub enum SdfNode {
Show 23 variants Sphere { radius: f32, }, Box { half_extents: Vec3, }, RoundedBox { half_extents: Vec3, radius: f32, }, Torus { major_radius: f32, minor_radius: f32, }, Cylinder { radius: f32, half_height: f32, }, Capsule { start: Vec3, end: Vec3, radius: f32, }, Cone { radius: f32, height: f32, }, Plane { normal: Vec3, offset: f32, }, Union(Box<SdfNode>, Box<SdfNode>), Subtract(Box<SdfNode>, Box<SdfNode>), Intersect(Box<SdfNode>, Box<SdfNode>), SmoothUnion { left: Box<SdfNode>, right: Box<SdfNode>, k: f32, }, SmoothSubtract { left: Box<SdfNode>, right: Box<SdfNode>, k: f32, }, SmoothIntersect { left: Box<SdfNode>, right: Box<SdfNode>, k: f32, }, Translate { child: Box<SdfNode>, offset: Vec3, }, Rotate { child: Box<SdfNode>, rotation: Quat, }, Scale { child: Box<SdfNode>, factor: f32, }, Mirror { child: Box<SdfNode>, axes: [bool; 3], }, RepeatFinite { child: Box<SdfNode>, spacing: Vec3, limit: [u32; 3], }, Twist { child: Box<SdfNode>, rate: f32, }, Bend { child: Box<SdfNode>, rate: f32, }, Onion { child: Box<SdfNode>, thickness: f32, }, Displace { child: Box<SdfNode>, amplitude: f32, frequency: f32, },
}
Expand description

Composable Signed Distance Field (SDF) and Constructive Solid Geometry (CSG) expression tree.

Variants§

§

Sphere

Sphere centered at the origin with radius radius.

Fields

§radius: f32

Sphere radius.

§

Box

Axis-aligned box centered at the origin with half_extents.

Fields

§half_extents: Vec3

Half-size along (X, Y, Z).

§

RoundedBox

Beveled axis-aligned box with outer half_extents and corner rounding radius.

Fields

§half_extents: Vec3

Outer half-size along (X, Y, Z).

§radius: f32

Corner and edge bevel radius.

§

Torus

Torus in the XZ plane around the Y axis.

Fields

§major_radius: f32

Major ring radius.

§minor_radius: f32

Minor tube radius.

§

Cylinder

Capped vertical cylinder centered at the origin along Y.

Fields

§radius: f32

Cylinder radius.

§half_height: f32

Half height along Y.

§

Capsule

Capsule segment spanning from start to end with spherical cap radius.

Fields

§start: Vec3

Segment start endpoint.

§end: Vec3

Segment end endpoint.

§radius: f32

Capsule radius.

§

Cone

Bounded upright cone centered at the origin along Y with base radius radius and height height.

Fields

§radius: f32

Base disk radius.

§height: f32

Total cone height from base to apex.

§

Plane

Infinite half-space bounded by plane dot(p, normal) = offset.

Fields

§normal: Vec3

Outward unit plane normal.

§offset: f32

Signed plane offset along normal.

§

Union(Box<SdfNode>, Box<SdfNode>)

Exact CSG union (min(left, right)).

§

Subtract(Box<SdfNode>, Box<SdfNode>)

Exact CSG subtraction carving right out of left (max(left, -right)).

§

Intersect(Box<SdfNode>, Box<SdfNode>)

Exact CSG intersection (max(left, right)).

§

SmoothUnion

Polynomial smooth CSG union blending two fields across radius k.

Fields

§left: Box<SdfNode>

First child SDF.

§right: Box<SdfNode>

Second child SDF.

§k: f32

Smooth blend radius k > 0.

§

SmoothSubtract

Polynomial smooth CSG subtraction carving right out of left with fillet radius k.

Fields

§left: Box<SdfNode>

Base solid SDF.

§right: Box<SdfNode>

Carving solid SDF.

§k: f32

Smooth fillet radius k > 0.

§

SmoothIntersect

Polynomial smooth CSG intersection blending the overlap boundary across radius k.

Fields

§left: Box<SdfNode>

First child SDF.

§right: Box<SdfNode>

Second child SDF.

§k: f32

Smooth blend radius k > 0.

§

Translate

Translates child by offset.

Fields

§child: Box<SdfNode>

Transformed child SDF.

§offset: Vec3

World-space translation offset.

§

Rotate

Rotates child by unit quaternion rotation.

Fields

§child: Box<SdfNode>

Transformed child SDF.

§rotation: Quat

Object rotation quaternion.

§

Scale

Uniformly scales child by positive factor with exact distance compensation.

Fields

§child: Box<SdfNode>

Transformed child SDF.

§factor: f32

Uniform scale multiplier.

§

Mirror

Mirrors child across any combination of the X, Y, and Z coordinate planes.

Fields

§child: Box<SdfNode>

Mirrored child SDF.

§axes: [bool; 3]

Per-axis mirror flags [mirror_x, mirror_y, mirror_z].

§

RepeatFinite

Repeats child on a finite 3D lattice with cell spacing and half-count limit.

Fields

§child: Box<SdfNode>

Repeated child SDF.

§spacing: Vec3

Lattice cell spacing (sx, sy, sz).

§limit: [u32; 3]

Maximum cell index extent [lx, ly, lz] on each side of the origin.

§

Twist

Twists child smoothly around the Y axis at rate radians per unit height.

Fields

§child: Box<SdfNode>

Deformed child SDF.

§rate: f32

Twist angle rate in radians per unit Y.

§

Bend

Bends child smoothly in the XY plane at rate radians per unit X.

Fields

§child: Box<SdfNode>

Deformed child SDF.

§rate: f32

Bend curvature rate in radians per unit X.

§

Onion

Hollows child into a thin shell of wall half-thickness thickness (|d| - thickness).

Fields

§child: Box<SdfNode>

Shelled child SDF.

§thickness: f32

Shell half-thickness.

§

Displace

Perturbs child with deterministic analytic trigonometric displacement.

Fields

§child: Box<SdfNode>

Displaced child SDF.

§amplitude: f32

Peak displacement amplitude.

§frequency: f32

Spatial angular frequency.

Implementations§

Source§

impl SdfNode

Composable constructors, zero-allocation signed-distance evaluation, and analytic gradients for SdfNode.

Source

pub fn sphere(radius: f32) -> Self

Creates a sphere primitive centered at the origin.

§Arguments
  • f32 - Sphere radius.
§Returns
  • Self - Sphere SdfNode.
Source

pub fn box_shape(half_extents: Vec3) -> Self

Creates an axis-aligned box primitive centered at the origin.

§Arguments
  • Vec3 - Half extents (hx, hy, hz).
§Returns
  • Self - Box SdfNode.
Source

pub fn rounded_box(half_extents: Vec3, radius: f32) -> Self

Creates a rounded box primitive with outer half_extents and bevel radius.

§Arguments
  • Vec3 - Outer half extents (hx, hy, hz).
  • f32 - Corner bevel radius.
§Returns
  • Self - Rounded box SdfNode.
Source

pub fn torus(major_radius: f32, minor_radius: f32) -> Self

Creates a torus primitive lying in the XZ plane around the Y axis.

§Arguments
  • f32 - Major ring radius.
  • f32 - Minor tube radius.
§Returns
  • Self - Torus SdfNode.
Source

pub fn cylinder(radius: f32, half_height: f32) -> Self

Creates a capped vertical cylinder centered at the origin.

§Arguments
  • f32 - Cylinder radius.
  • f32 - Half height along Y.
§Returns
  • Self - Cylinder SdfNode.
Source

pub fn capsule(start: Vec3, end: Vec3, radius: f32) -> Self

Creates a capsule segment primitive between start and end.

§Arguments
  • Vec3 - Start endpoint.
  • Vec3 - End endpoint.
  • f32 - Capsule radius.
§Returns
  • Self - Capsule SdfNode.
Source

pub fn cone(radius: f32, height: f32) -> Self

Creates a bounded vertical cone centered at the origin.

§Arguments
  • f32 - Base radius.
  • f32 - Total height along Y.
§Returns
  • Self - Cone SdfNode.
Source

pub fn plane(normal: Vec3, offset: f32) -> Self

Creates an infinite half-space plane primitive.

§Arguments
  • Vec3 - Outward plane normal.
  • f32 - Signed offset along the normal.
§Returns
  • Self - Plane SdfNode.
Source

pub fn union(self, other: Self) -> Self

Combines self and other with exact CSG union.

§Arguments
  • Self - Other SDF operand.
§Returns
  • Self - Union CSG node.
Source

pub fn subtract(self, other: Self) -> Self

Subtracts other from self (self \ other).

§Arguments
  • Self - Carving SDF operand.
§Returns
  • Self - Subtract CSG node.
Source

pub fn intersect(self, other: Self) -> Self

Intersects self with other.

§Arguments
  • Self - Other SDF operand.
§Returns
  • Self - Intersect CSG node.
Source

pub fn smooth_union(self, other: Self, k: f32) -> Self

Smoothly blends the union of self and other across blend radius k.

§Arguments
  • Self - Other SDF operand.
  • f32 - Smooth blend radius k.
§Returns
  • Self - Smooth union CSG node.
Source

pub fn smooth_subtract(self, other: Self, k: f32) -> Self

Smoothly subtracts other from self with fillet radius k.

§Arguments
  • Self - Carving SDF operand.
  • f32 - Smooth fillet radius k.
§Returns
  • Self - Smooth subtract CSG node.
Source

pub fn smooth_intersect(self, other: Self, k: f32) -> Self

Smoothly intersects self and other with blend radius k.

§Arguments
  • Self - Other SDF operand.
  • f32 - Smooth blend radius k.
§Returns
  • Self - Smooth intersect CSG node.
Source

pub fn translate(self, offset: Vec3) -> Self

Translates self by offset.

§Arguments
  • Vec3 - Translation vector.
§Returns
  • Self - Translated SDF node.
Source

pub fn rotate(self, rotation: Quat) -> Self

Rotates self by quaternion rotation.

§Arguments
  • Quat - Rotation quaternion.
§Returns
  • Self - Rotated SDF node.
Source

pub fn scale(self, factor: f32) -> Self

Uniformly scales self by positive factor.

§Arguments
  • f32 - Scale factor.
§Returns
  • Self - Scaled SDF node.
Source

pub fn mirror(self, axes: [bool; 3]) -> Self

Mirrors self across the enabled coordinate planes [x, y, z].

§Arguments
  • [bool; 3] - Per-axis mirror flags.
§Returns
  • Self - Mirrored SDF node.
Source

pub fn repeat_finite(self, spacing: Vec3, limit: [u32; 3]) -> Self

Repeats self on a bounded lattice of spacing spacing and half-extent limit.

§Arguments
  • Vec3 - Cell spacing per axis.
  • [u32; 3] - Half-repetition count per axis.
§Returns
  • Self - Finitely repeated SDF node.
Source

pub fn twist(self, rate: f32) -> Self

Twists self around the Y axis by rate radians per unit Y.

§Arguments
  • f32 - Twist rate in radians per unit height.
§Returns
  • Self - Twisted SDF node.
Source

pub fn bend(self, rate: f32) -> Self

Bends self in the XY plane by rate radians per unit X.

§Arguments
  • f32 - Bend rate in radians per unit X.
§Returns
  • Self - Bent SDF node.
Source

pub fn shell(self, thickness: f32) -> Self

Shells self into a hollow wall of half-thickness thickness.

§Arguments
  • f32 - Shell half-thickness.
§Returns
  • Self - Shelled (Onion) SDF node.
Source

pub fn displace(self, amplitude: f32, frequency: f32) -> Self

Applies deterministic trigonometric surface displacement to self.

§Arguments
  • f32 - Peak displacement amplitude.
  • f32 - Spatial angular frequency.
§Returns
  • Self - Displaced SDF node.
Source

pub fn evaluate(&self, point: Vec3) -> f32

Evaluates the signed distance at point with zero heap allocations (< 0 inside, > 0 outside).

§Arguments
  • Vec3 - Query point in world space.
§Returns
  • f32 - Finite signed distance value.
Source

pub fn gradient(&self, point: Vec3, epsilon: f32) -> Vec3

Computes the unit outward surface normal via central finite differences around point.

§Arguments
  • Vec3 - Query point near the zero isosurface.
  • f32 - Finite difference step size (clamped to >= 1e-5).
§Returns
  • Vec3 - Unit outward normal vector.

Trait Implementations§

Source§

impl Clone for SdfNode

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SdfNode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for SdfNode

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SdfNode

Auto Trait Implementations§

§

impl Forget for SdfNode

§

impl Freeze for SdfNode

§

impl Move for SdfNode

§

impl RefUnwindSafe for SdfNode

§

impl Send for SdfNode
where BoxRaw<SdfNode>: Send,

§

impl Sync for SdfNode
where BoxRaw<SdfNode>: Sync,

§

impl Unpin for SdfNode
where Box<SdfNode>: Unpin,

§

impl UnsafeUnpin for SdfNode

§

impl UnwindSafe for SdfNode
where BoxRaw<SdfNode>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.