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

Heightfield

Extends:

SignedDistanceFunction → Heightfield

Indirect Implements:

A Signed Distance Function that describes a heightfield.

Constructor Summary

Public Constructor
public

constructor(parameters: Object, material: Number)

Constructs a new heightfield SDF.

Method Summary

Public Methods
public

Calculates the bounding box of this SDF.

public

createTransferList(transferList: Array): Transferable[]

Creates a list of transferable items.

public

fromImage(image: Image): Heightfield

Reads the image data of a given heightmap and converts it into a greyscale data array.

public

Retrives the height value for the given coordinates.

public

sample(position: Vector3): Number

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

public

serialize(deflate: Boolean): Object

Serialises this SDF.

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.

Public Constructors

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

Constructs a new heightfield SDF.

Override:

SignedDistanceFunction#constructor

Params:

NameTypeAttributeDescription
parameters Object

The parameters.

parameters.width Array
  • optional
  • default: 1

The width of the heightfield.

parameters.height Array
  • optional
  • default: 1

The height of the heightfield.

parameters.smooth Boolean
  • optional
  • default: true

Whether the height data should be smoothed.

parameters.data Uint8ClampedArray
  • optional
  • default: null

The heightmap image data.

parameters.image Image
  • optional

The heightmap image.

material Number
  • optional

A material index.

Public Methods

public computeBoundingBox(): Box3 source

Calculates the bounding box of this SDF.

Override:

SignedDistanceFunction#computeBoundingBox

Return:

Box3

The bounding box.

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

Creates a list of transferable items.

Override:

SignedDistanceFunction#createTransferList

Params:

NameTypeAttributeDescription
transferList Array
  • optional

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

Return:

Transferable[]

The transfer list.

public fromImage(image: Image): Heightfield source

Reads the image data of a given heightmap and converts it into a greyscale data array.

Params:

NameTypeAttributeDescription
image Image

The heightmap image.

Return:

Heightfield

This heightfield.

public getHeight(x: Number, z: Number): Number source

Retrives the height value for the given coordinates.

Params:

NameTypeAttributeDescription
x Number

The x coordinate.

z Number

The z coordinate.

Return:

Number

The height.

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.