Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Simulation

The main entrypoint of a visualization.

This class wraps a THREE.js scene, controls, skybox, etc in an animated Simulation.

example
const sim = new Spacekit.Simulation(document.getElementById('my-container'), {
 basePath: '../path/to/assets',
 startDate: Date.now(),
 jd: 0.0,
 jdDelta: 10.0,
 jdPerSecond: 100.0,  // overrides jdDelta
 startPaused: false,
 unitsPerAu: 1.0,
 maxNumParticles: 2**16,
 camera: {
   initialPosition: [0, -10, 5],
   enableDrift: false,
 },
 debug: {
   showAxes: false,
   showGrid: false,
   showStats: false,
 },
});

Hierarchy

  • Simulation

Index

Constructors

constructor

  • new Simulation(simulationElt: HTMLCanvasElement, options: SpacekitOptions): Simulation
  • Parameters

    • simulationElt: HTMLCanvasElement

      The container for this simulation.

    • options: SpacekitOptions

      for simulation

    Returns Simulation

Properties

Private camera

camera: default

Private cameraDefaultPos

cameraDefaultPos: Coordinate3d

Private Optional composer

composer: any

Private enableCameraDrift

enableCameraDrift: boolean

Private fps

fps: number

Private initialRenderComplete

initialRenderComplete: boolean

Private isPaused

isPaused: boolean

Private jd

jd: number

Private Optional jdDelta

jdDelta: number

Private jdPerSecond

jdPerSecond: number

Private lastResizeUpdateTime

lastResizeUpdateTime: number

Private lastStaticCameraUpdateTime

lastStaticCameraUpdateTime: number

Private lastUpdatedTime

lastUpdatedTime: number

Private Optional lightPosition

lightPosition: Vector3

Optional onTick

onTick: () => void

Type declaration

    • (): void
    • Returns void

Private options

options: SpacekitOptions

Private particles

particles: KeplerParticles

Private renderEnabled

renderEnabled: boolean

Private renderer

renderer: WebGL1Renderer

Private scene

scene: Scene

Private simulationElt

simulationElt: HTMLCanvasElement

Private Optional stats

stats: Stats

Private subscribedObjects

subscribedObjects: Record<string, SimulationObject>

Private useLightSources

useLightSources: boolean

Methods

addObject

  • Add a spacekit object (usually a SpaceObject) to the visualization.

    see

    SpaceObject

    Parameters

    • obj: SimulationObject

      Object to add to visualization

    • noUpdate: boolean = false

      Set to true if object does not need to be animated.

    Returns void

Private animate

  • animate(): void

createAmbientLight

  • createAmbientLight(color?: number): void
  • Creates an ambient light source. This will dimly light everything in the visualization.

    Parameters

    • color: number = 0x333333

      Color of light, default 0x333333

    Returns void

createLight

  • createLight(pos?: undefined | Coordinate3d, color?: number): void
  • Creates a light source. This will make the shape of your objects visible and provide some contrast.

    Parameters

    • pos: undefined | Coordinate3d = ...

      Position of light source. Defaults to moving with camera.

    • color: number = 0xffffff

      Color of light, default 0xFFFFFF

    Returns void

createObject

  • Shortcut for creating a new SpaceObject belonging to this visualization. Takes any SpaceObject arguments.

    see

    SpaceObject

    Parameters

    • Rest ...args: any[]

    Returns SpaceObject

createShape

  • Shortcut for creating a new ShapeObject belonging to this visualization. Takes any ShapeObject arguments.

    see

    ShapeObject

    Parameters

    • Rest ...args: any[]

    Returns ShapeObject

createSkybox

  • createSkybox(...args: any[]): Skybox
  • Shortcut for creating a new Skybox belonging to this visualization. Takes any Skybox arguments.

    see

    Skybox

    Parameters

    • Rest ...args: any[]

    Returns Skybox

createSphere

  • Shortcut for creating a new SphereOjbect belonging to this visualization. Takes any SphereObject arguments.

    see

    SphereObject

    Parameters

    • Rest ...args: any[]

    Returns SphereObject

createStars

  • createStars(...args: any[]): Stars
  • Shortcut for creating a new Stars object belonging to this visualization. Takes any Stars arguments.

    see

    Stars

    Parameters

    • Rest ...args: any[]

    Returns Stars

createStaticParticles

  • Shortcut for creating a new StaticParticles object belonging to this visualization. Takes any StaticParticles arguments.

    see

    SphereObject

    Parameters

    • Rest ...args: any[]

    Returns StaticParticles

Private doCameraDrift

  • doCameraDrift(): void

Private doZoomToFit

  • doZoomToFit(obj: Object3D, offset: number): void
  • Parameters

    • obj: Object3D

      Three.js object to fit within viewport.

    • offset: number

      Add some extra room in the viewport. Increase to be further zoomed out, decrease to be closer. Default 3.0.

    Returns void

getContext

getDate

  • getDate(): Date
  • Get a date object representing local date and time of the simulation.

    Returns Date

    Date of simulation

getJd

  • getJd(): number
  • Gets the current JD date of the simulation

    Returns number

    JD date

getJdDelta

  • getJdDelta(): number
  • Get the JD per frame of the visualization.

    Returns number

getJdPerSecond

  • getJdPerSecond(): undefined | number
  • Get the JD change per second of the visualization.

    Returns undefined | number

    JD per second, undefined if jd per second is not set.

getLightPosition

  • getLightPosition(): undefined | Vector3

getRenderer

  • getRenderer(): WebGL1Renderer
  • Get the three.js renderer

    Returns WebGL1Renderer

    The THREE.js renderer

getScene

  • getScene(): Scene
  • Get the three.js scene object

    Returns Scene

    The THREE.js scene object

getSimulationElement

  • getSimulationElement(): HTMLCanvasElement
  • Get the element containing this simulation

    Returns HTMLCanvasElement

    The html container of this simulation

getViewer

  • getViewer(): default
  • Get the Camera and CameraControls wrapper object

    Returns default

    The Camera wrapper

Private init

  • init(): void

Private initPasses

  • initPasses(): void

Private initRenderer

  • initRenderer(): WebGL1Renderer

isUsingLightSources

  • isUsingLightSources(): boolean

loadNaturalSatellites

  • Returns a promise that receives a NaturalSatellites object when it is resolved.

    see

    {NaturalSatellites}

    Returns Promise<NaturalSatellites>

    NaturalSatellites object that is ready to load.

removeObject

renderOnlyInViewport

  • renderOnlyInViewport(): void
  • Installs a scroll handler that only renders the visualization while it is in the user's viewport.

    The scroll handler currently binds to the window object only.

    Returns void

Private resizeUpdate

  • resizeUpdate(): void

setCameraDrift

  • setCameraDrift(driftOn: boolean): void
  • Enable or disable camera drift.

    Parameters

    • driftOn: boolean

      True if you want the camera to float around a bit

    Returns void

setDate

  • setDate(date: Date): void
  • Set the local date and time of the simulation.

    Parameters

    • date: Date

      Date of simulation

    Returns void

setJd

  • setJd(val: number): void
  • Sets the JD date of the simulation.

    Parameters

    • val: number

      JD date

    Returns void

setJdDelta

  • setJdDelta(delta: number): void
  • Set the JD per frame of the visualization. This will override any existing "JD per second" setting.

    Parameters

    • delta: number

      JD per frame

    Returns void

setJdPerSecond

  • setJdPerSecond(x: number): void
  • Set the JD change per second of the visualization.

    Parameters

    • x: number

      JD per second

    Returns void

start

  • start(): void

Private staticForcedUpdate

  • staticForcedUpdate(): void
  • Performs a forced update of all elements in the view. This is used for when the system isn't animating but the objects need to update their data to properly capture things like updated label positions.

    Returns void

stop

  • stop(): void

Private update

  • update(force?: boolean): void

zoomToFit

  • zoomToFit(spaceObj: SpaceObject, offset?: number): Promise<boolean>
  • Adjust camera position so that the object fits within the viewport. If applicable, this function will fit around the object's orbit.

    Parameters

    • spaceObj: SpaceObject

      Object to fit within viewport.

    • offset: number = 3.0

      Add some extra room in the viewport. Increase to be further zoomed out, decrease to be closer. Default 3.0.

    Returns Promise<boolean>

Generated using TypeDoc