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

Terrain

Extends:

three~EventDispatcher → Terrain

Implements:

The terrain system.

Manages volume modifications and mesh generation.

Constructor Summary

Public Constructor
public

constructor(options: Object)

Constructs a new terrain.

Member Summary

Public Members
public

A clipmap.

public

object: Group

The terrain mesh.

public

A thread pool.

public

The world octree.

Method Summary

Public Methods
public

Executes the given SDF.

public

clear()

Resets this terrain by removing all data and closing active worker threads.

public

Frees internal resources.

public

handleEvent(event: Event)

Handles events.

public

Executes the given SDF and discards the volume data that doesn't overlap with the generated data.

public

load(data: String)

Loads a volume data description.

public

raycast(ray: Ray): WorldOctant[]

Finds the world cells that intersect with the given ray.

public

save(): DOMString

Saves a description of the current volume data.

public

Executes the given SDF and subtracts the generated data from the volume.

public

Executes the given SDF and adds the generated data to the volume.

public

update(position: Vector3)

Updates the terrain geometry.

Public Constructors

public constructor(options: Object) source

Constructs a new terrain.

Params:

NameTypeAttributeDescription
options Object
  • optional

The options.

options.workers Number
  • optional
  • default: navigator.hardwareConcurrency

Limits the amount of active workers. Cannot exceed the amount of logical processors.

options.resolution Number
  • optional
  • default: 32

The resolution of the volume data.

options.world Number
  • optional

Additional world octree settings. See WorldOctree for details.

Public Members

public clipmap: Clipmap source

A clipmap.

public object: Group source

The terrain mesh. Add this object to your scene.

public threadPool: ThreadPool source

A thread pool. Each worker from this pool is capable of performing isosurface extractions as well as CSG operations on discrete volume data.

public world: WorldOctree source

The world octree.

Public Methods

public applyCSG(sdf: SignedDistanceFunction) source

Executes the given SDF.

SDFs without a valid CSG operation type will be ignored. See OperationType for a list of available CSG operation types.

Instead of using this method directly, it's recommended to use the convenience methods union, subtract and intersect.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

public clear() source

Resets this terrain by removing all data and closing active worker threads.

public dispose() source

Frees internal resources.

By calling this method the terrain system will become unoperative.

public handleEvent(event: Event) source

Handles events.

Params:

NameTypeAttributeDescription
event Event

An event.

public intersect(sdf: SignedDistanceFunction) source

Executes the given SDF and discards the volume data that doesn't overlap with the generated data.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

public load(data: String) source

Loads a volume data description.

A load event will be dispatched when the loading process has finished.

Params:

NameTypeAttributeDescription
data String

A stringified list of SDF descriptions.

public raycast(ray: Ray): WorldOctant[] source

Finds the world cells that intersect with the given ray.

Params:

NameTypeAttributeDescription
ray Ray

A ray.

Return:

WorldOctant[]

A list of intersecting world octants. Sorted by distance, closest first.

public save(): DOMString source

Saves a description of the current volume data.

Return:

DOMString

A URL to the exported save data, or null if there is no data.

public subtract(sdf: SignedDistanceFunction) source

Executes the given SDF and subtracts the generated data from the volume.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

public union(sdf: SignedDistanceFunction) source

Executes the given SDF and adds the generated data to the volume.

Params:

NameTypeAttributeDescription
sdf SignedDistanceFunction

An SDF.

public update(position: Vector3) source

Updates the terrain geometry.

This method should be called every time the position has changed.

Params:

NameTypeAttributeDescription
position Vector3

A position.