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

SuperPrimitive

Extends:

SignedDistanceFunction → SuperPrimitive

Indirect Implements:

The super primitive.

A function that is able to represent a wide range of conic/rectangular-radial primitives of genus 0 and 1: (round) box, sphere, cylinder, capped cone, torus, capsule, pellet, pipe, etc.

Reference: https://www.shadertoy.com/view/MsVGWG

Static Method Summary

Static Public Methods
public static

Creates a new primitive using the specified preset.

Constructor Summary

Public Constructor
public

constructor(parameters: Object, material: Number)

Constructs a new super primitive.

Method Summary

Public Methods
public

Calculates the bounding box of this SDF.

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 corner radii.

public

Sets the size and genus weight.

Inherited Summary

From class SignedDistanceFunction
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

boundingBox: Box3

The axis-aligned bounding box of this SDF.

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

Calculates the bounding box of this SDF.

Static Public Methods

public static create(preset: SuperPrimitivePreset): * source

Creates a new primitive using the specified preset.

Params:

NameTypeAttributeDescription
preset SuperPrimitivePreset

The super primitive preset.

Return:

*

Public Constructors

public constructor(parameters: Object, material: Number) source

Constructs a new super primitive.

See SuperPrimitivePreset for a list of default configurations.

Override:

SignedDistanceFunction#constructor

Params:

NameTypeAttributeDescription
parameters Object

The parameters.

parameters.s Array

The size and genus weight [x, y, z, w].

parameters.r Array

The corner radii [x, y, z].

material Number
  • optional

A material index.

Example:

const cube = SuperPrimitive.create(SuperPrimitivePreset.CUBE);

Public Methods

public computeBoundingBox(): Box3 source

Calculates the bounding box of this SDF.

Override:

SignedDistanceFunction#computeBoundingBox

Return:

Box3

The bounding box.

public sample(position: Vector3): Number source

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

Override:

SignedDistanceFunction#sample

Params:

NameTypeAttributeDescription
position Vector3

A position.

Return:

Number

The euclidean distance to the surface.

public serialize(deflate: Boolean): Object source

Serialises this SDF.

Override:

SignedDistanceFunction#serialize

Params:

NameTypeAttributeDescription
deflate Boolean
  • optional
  • default: false

Whether the data should be compressed if possible.

Return:

Object

The serialised data.

public setRadii(x: Number, y: Number, z: Number): SuperPrimitive source

Sets the corner radii.

Params:

NameTypeAttributeDescription
x Number

X.

y Number

Y.

z Number

Z.

Return:

SuperPrimitive

This instance.

public setSize(x: Number, y: Number, z: Number, w: Number): SuperPrimitive source

Sets the size and genus weight.

Params:

NameTypeAttributeDescription
x Number

X.

y Number

Y.

z Number

Z.

w Number

W.

Return:

SuperPrimitive

This instance.