SignedDistanceFunction
Direct Subclass:
Implements:
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 |
inverseTransformation: Matrix4 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 |
Samples the volume's density at the given point in space. |
|
public |
Serialises this SDF. |
|
public |
setMaterial(material: Material): SignedDistanceFunction Sets the material. |
|
public |
setOperationType(operation: OperationType): SignedDistanceFunction 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 |
computeBoundingBox(): Box3 Calculates the bounding box of this SDF. |
Public Constructors
Public Members
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.
Protected Members
Public Methods
public createTransferList(transferList: Array): Transferable[] source
Creates a list of transferable items.
Params:
Name | Type | Attribute | Description |
transferList | Array |
|
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:
Name | Type | Attribute | Description |
recursive | Boolean |
|
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:
Name | Type | Attribute | Description |
matrix | Matrix4 |
|
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:
Name | Type | Attribute | Description |
sdf | SignedDistanceFunction | An SDF. |
public sample(position: Vector3): Number source
Samples the volume's density at the given point in space.
Params:
Name | Type | Attribute | Description |
position | Vector3 | A position. |
Throw:
An error is thrown if the method is not overridden. |
public serialize(deflate: Boolean): Object source
Serialises this SDF.
Params:
Name | Type | Attribute | Description |
deflate | Boolean |
|
Whether the data should be compressed if possible. |
public setMaterial(material: Material): SignedDistanceFunction source
Sets the material.
Params:
Name | Type | Attribute | Description |
material | Material | The material. Must be an integer in the range of 1 to 255. |
public setOperationType(operation: OperationType): SignedDistanceFunction source
Sets the CSG operation type of this SDF.
Params:
Name | Type | Attribute | Description |
operation | OperationType | The CSG operation type. |
public subtract(sdf: SignedDistanceFunction): SignedDistanceFunction source
Subtracts the given SDF from this one.
Params:
Name | Type | Attribute | Description |
sdf | SignedDistanceFunction | An SDF. |
public toCSG(): Operation source
Translates this SDF into a CSG expression.
Example:
a.union(b.intersect(c)).union(d).subtract(e) => Difference(Union(a, Intersection(b, c), d), e)
public union(sdf: SignedDistanceFunction): SignedDistanceFunction source
Adds the given SDF to this one.
Params:
Name | Type | Attribute | Description |
sdf | SignedDistanceFunction | An 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.