An asteroid field is basically a collection of instance chunks that can be created and destroyed depending on where the player is. This allows to only render the asteroids close to the player, saving immense resources.

Implements

  • IDisposable

Constructors

  • Creates a new asteroid field around a given transform

    Parameters

    • seed: number

      The seed of the asteroid field

    • parent: TransformNode

      A parent transform node for the asteroids

    • averageRadius: number

      The average distance to the parent of the asteroids

    • spread: number

      The spread of the distance to the parent around the average distance

    • scene: Scene

      The scene where the asteroid field exists

    Returns AsteroidField

Properties

averageRadius: number
maxRadius: number
minRadius: number
neighborCellsRenderRadius: 2
parent: TransformNode
patchSize: 30000
patchThickness: 2000
resolution: 15
rng: (step: number) => number
scene: Scene
seed: number
spread: number

Methods

  • Updates the asteroid field. The position of the camera is used to determine which chunks to load and unload. The delta seconds are used to fade in and out the chunks

    Parameters

    • cameraWorldPosition: Vector3

      The position of the camera in world space

    • deltaSeconds: number

      The seconds elapsed since last frame

    Returns void

  • Creates a matrix buffer for an asteroid patch. The patch has a given square size, subdivided in cells by the resolution parameter. Each cell contains one instance. The min and max radius ensure the asteroid don't spread to far

    Parameters

    • position: Vector3

      The position of the patch in the local space of the parent transform of any field

    • resolution: number

      The subdivision of the chunk, each cell contains a single instance

    • patchSize: number

      The overall planar size of the patch

    • patchThickness: number

      The vertical spread of the patch

    • minRadius: number

      The minimum radius at which the field starts

    • maxRadius: number

      The maximum radius at which the field ends

    • rng: (index: number) => number

      A random number generator

    Returns [Vector3[], Quaternion[], number[], Vector3[], number[]]

    A new matrix 4x4 buffer