Home Reference Source
import {SignedDistanceFunction} from 'rabbit-hole'
public class | source

SignedDistanceFunction

An abstract Signed Distance Function.

An SDF describes the signed Euclidean distance to the surface of an object, effectively describing its density at every point in 3D space. It yields negative values for points that lie inside the volume and positive values for points outside. The value is zero at the exact boundary of the object.

Constructor Summary

Public Constructor
public

constructor(type: SDFType, material: Number)

Constructs a new base SDF.

Member Summary

Public Members
public

The inverted transformation matrix.

public

A material index.

public

The operation type.

public

position: Vector3

The positional translation.

public

quaternion: Quaternion

The rotation.

public

scale: Vector3

The scale.

public

The type of this SDF.

Protected Members
protected

boundingBox: Box3

The axis-aligned bounding box of this SDF.

Method Summary

Public Methods
public

createTransferList(transferList: Array): Transferable[]

Creates a list of transferable items.

public

getBoundingBox(recursive: Boolean): Box3

Calculates the AABB of this SDF if it doesn't exist yet and returns it.

public

getTransformation(matrix: Matrix4): Matrix4

Composes a transformation matrix using the translation, rotation and scale of this SDF.

public

Intersects the given SDF with this one.

public

sample(position: Vector3): Number

Samples the volume's density at the given point in space.

public

serialize(deflate: Boolean): Object

Serialises this SDF.

public

Sets the material.

public

Sets the CSG operation type of this SDF.

public

Subtracts the given SDF from this one.

public

Translates this SDF into a CSG expression.

public

Returns a plain object that describes this SDF.

public

Adds the given SDF to this one.

public

Updates the inverse transformation matrix.

Protected Methods
protected

Calculates the bounding box of this SDF.

Public Constructors

public constructor(type: SDFType, material: Number) source

Constructs a new base SDF.

Params:

NameTypeAttributeDescription
type SDFType

The type of the SDF.

material Number
  • optional
  • default: Material.SOLID

A material index. Must be an integer in the range of 1 to 255.

Public Members

public inverseTransformation: Matrix4 source

The inverted transformation matrix.

public material: Number source

A material index.

public operation: OperationType source

The operation type.

public position: Vector3 source

The positional translation.

Call updateInverseTransformation after changing this field.

public quaternion: Quaternion source

The rotation.

Call updateInverseTransformation after changing this field.

public scale: Vector3 source

The scale.

Call updateInverseTransformation after changing this field.

public type: SDFType source

The type of this SDF.

Protected Members

protected boundingBox: Box3 source

The axis-aligned bounding box of this SDF.

Public Methods

public createTransferList(transferList: Array): Transferable[] source

Creates a list of transferable items.

Params:

NameTypeAttributeDescription
transferList Array
  • optional

An optional target list. The transferable items will be added to this list.

Return:

Transferable[]

The transfer list.

public getBoundingBox(recursive: Boolean): Box3 source

Calculates the AABB of this SDF if it doesn't exist yet and returns it.

Params:

NameTypeAttributeDescription
recursive Boolean
  • optional
  • default: false

Whether the child SDFs should be taken into account.

Return:

Box3

The bounding box.

public getTransformation(matrix: Matrix4): Matrix4 source

Composes a transformation matrix using the translation, rotation and scale of this SDF.

The transformation matrix is not needed for most SDF calculations and is therefore not stored explicitly to save space.

Params:

NameTypeAttributeDescription
matrix Matrix4
  • optional

A matrix to store the transformation in.

Return:

Matrix4

The transformation matrix.

public intersect(sdf: SignedDistanceFunction): SignedDistanceFunction source

Intersects the given SDF with this one.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

Return:

SignedDistanceFunction

This SDF.

public sample(position: Vector3): Number source

Samples the volume's density at the given point in space.

Params:

NameTypeAttributeDescription
position Vector3

A position.

Return:

Number

The Euclidean distance to the surface.

Throw:

Error

An error is thrown if the method is not overridden.

public serialize(deflate: Boolean): Object source

Serialises this SDF.

Params:

NameTypeAttributeDescription
deflate Boolean
  • optional
  • default: false

Whether the data should be compressed if possible.

Return:

Object

The serialised data.

public setMaterial(material: Material): SignedDistanceFunction source

Sets the material.

Params:

NameTypeAttributeDescription
material Material

The material. Must be an integer in the range of 1 to 255.

Return:

SignedDistanceFunction

This SDF.

public setOperationType(operation: OperationType): SignedDistanceFunction source

Sets the CSG operation type of this SDF.

Params:

NameTypeAttributeDescription
operation OperationType

The CSG operation type.

Return:

SignedDistanceFunction

This SDF.

public subtract(sdf: SignedDistanceFunction): SignedDistanceFunction source

Subtracts the given SDF from this one.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

Return:

SignedDistanceFunction

This SDF.

public toCSG(): Operation source

Translates this SDF into a CSG expression.

Return:

Operation

A CSG operation.

Example:

a.union(b.intersect(c)).union(d).subtract(e) => Difference(Union(a, Intersection(b, c), d), e)

public toJSON(): Object source

Returns a plain object that describes this SDF.

Return:

Object

A simple description of this SDF.

public union(sdf: SignedDistanceFunction): SignedDistanceFunction source

Adds the given SDF to this one.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

Return:

SignedDistanceFunction

This SDF.

public updateInverseTransformation(): SignedDistanceFunction source

Updates the inverse transformation matrix.

This method should be called after the position, quaternion or scale has changed. The bounding box will be updated automatically.

Return:

SignedDistanceFunction

This SDF.

Protected Methods

protected computeBoundingBox(): Box3 source

Calculates the bounding box of this SDF.

Return:

Box3

The bounding box.

Throw:

Error

An error is thrown if the method is not overridden.