Home Reference Source
import {Simulation} from 'spacekit/src/Simulation.js'
public class | source

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,
 },
});

Constructor Summary

Public Constructor
public

constructor(simulationElt: HTMLElement, options: Object)

Member Summary

Public Members
public

onTick: *

Method Summary

Public Methods
public

addObject(obj: Object, noUpdate: boolean)

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

public

Creates an ambient light source.

public

createLight(pos: Array<Number>, color: Number)

Creates a light source.

public

createObject(args: ...*): *

Shortcut for creating a new SpaceObject belonging to this visualization.

public

createShape(args: ...*): *

Shortcut for creating a new ShapeObject belonging to this visualization.

public

createSkybox(args: ...*): *

Shortcut for creating a new Skybox belonging to this visualization.

public

createSphere(args: ...*): *

Shortcut for creating a new SphereOjbect belonging to this visualization.

public

createStars(args: ...*): *

Shortcut for creating a new Stars object belonging to this visualization.

public

createStaticParticles(args: ...*): *

Shortcut for creating a new StaticParticles object belonging to this visualization.

public

Get an object that contains useful context for this visualization

public

Get a date object representing local date and time of the simulation.

public

Gets the current JD date of the simulation

public

getJdDelta(): *

Get the JD per frame of the visualization.

public

Get the JD change per second of the visualization.

public
public

getScene(): THREE.Scene

Get the three.js scene object

public

getSimulationElement(): HTMLElement

Get the element containing this simulation

public

Get the Camera and CameraControls wrapper object

public
public

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

public

Removes an object from the visualization.

public

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.

public

Enable or disable camera drift.

public

setDate(date: Date)

Set the local date and time of the simulation.

public

setJd(val: Number)

Sets the JD date of the simulation.

public

setJdDelta(delta: Number)

Set the JD per frame of the visualization.

public

Set the JD change per second of the visualization.

public

start()

Run the animation

public

stop()

Stop the animation

public

zoomToFit(spaceObj: SpaceObject, offset: Number)

Adjust camera position so that the object fits within the viewport.

Public Constructors

public constructor(simulationElt: HTMLElement, options: Object) source

Params:

NameTypeAttributeDescription
simulationElt HTMLElement

The container for this simulation.

options Object

for simulation

options.basePath String

Path to simulation assets and data

options.startDate Date

The start date and time for this simulation.

options.jd Number

The JD date of this simulation. Defaults to 0

options.jdDelta Number

The number of JD to add every tick of the simulation.

options.jdPerSecond Number

The number of jd to add every second. Use this instead of jdDelta for constant motion that does not vary with framerate. Defaults to 100.

options.unitsPerAu Number

The number of "position" units in the simulation that represent an AU. This is an optional setting that you may use if the default (1 unit = 1 AU) is too small for your simulation (e.g. if you are representing a planetary system). Depending on your graphics card, you may begin to notice inaccuracies at fractional scales of GL units, so it becomes necessary to scale the whole visualization. Defaults to 1.0.

options.startPaused boolean

Whether the simulation should start in a paused state.

options.maxNumParticles Number

The maximum number of particles in the visualization. Try choosing a number that is larger than your particles, but not too much larger. It's usually good enough to choose the next highest power of 2. If you're not showing many particles (tens of thousands+), you don't need to worry about this.

options.particleTextureUrl String

The texture for the default particle system.

options.particleDefaultSize Number

The default size for the particle system.

options.camera Object

Options for camera

options.camera.initialPosition Array<Number>

Initial X, Y, Z coordinates of the camera. Defaults to [0, -10, 5].

options.camera.enableDrift boolean

Set true to have the camera float around slightly. False by default.

options.debug Object

Options dictating debug state.

options.debug.showAxes boolean

Show X, Y, and Z axes

options.debug.showGrid boolean

Show grid on XY plane

options.debug.showStats boolean

Show FPS and other stats (requires stats.js).

Public Members

public onTick: * source

Public Methods

public addObject(obj: Object, noUpdate: boolean) source

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

Params:

NameTypeAttributeDescription
obj Object

Object to add to visualization

noUpdate boolean

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

See:

public createAmbientLight(color: Number) source

Creates an ambient light source. This will dimly light everything in the visualization.

Params:

NameTypeAttributeDescription
color Number

Color of light, default 0x333333

public createLight(pos: Array<Number>, color: Number) source

Creates a light source. This will make the shape of your objects visible and provide some contrast.

Params:

NameTypeAttributeDescription
pos Array<Number>

Position of light source. Defaults to moving with camera.

color Number

Color of light, default 0xFFFFFF

public createObject(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public createShape(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public createSkybox(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public createSphere(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public createStars(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public createStaticParticles(args: ...*): * source

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

Params:

NameTypeAttributeDescription
args ...*

Return:

*

See:

public getContext(): Object source

Get an object that contains useful context for this visualization

Return:

Object

Context object

public getDate(): Date source

Get a date object representing local date and time of the simulation.

Return:

Date

Date of simulation

public getJd(): Number source

Gets the current JD date of the simulation

Return:

Number

JD date

public getJdDelta(): * source

Get the JD per frame of the visualization.

Return:

*

public getJdPerSecond(): Number source

Get the JD change per second of the visualization.

Return:

Number

JD per second

public getLightPosition(): * source

Return:

*

public getScene(): THREE.Scene source

Get the three.js scene object

Return:

THREE.Scene

The THREE.js scene object

public getSimulationElement(): HTMLElement source

Get the element containing this simulation

Return:

HTMLElement

The html container of this simulation

public getViewer(): Camera source

Get the Camera and CameraControls wrapper object

Return:

Camera

The Camera wrapper

public isUsingLightSources(): * source

Return:

*

public loadNaturalSatellites(): * source

Returns a promise that receives a NaturalSatellites object when it is resolved. @return {Promise<NaturalSatellites>} NaturalSatellites object that is ready to load.

Return:

*

See:

public removeObject(obj: Object) source

Removes an object from the visualization.

Params:

NameTypeAttributeDescription
obj Object

Object to remove

public renderOnlyInViewport() source

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.

public setCameraDrift(driftOn: boolean) source

Enable or disable camera drift.

Params:

NameTypeAttributeDescription
driftOn boolean

True if you want the camera to float around a bit

public setDate(date: Date) source

Set the local date and time of the simulation.

Params:

NameTypeAttributeDescription
date Date

Date of simulation

public setJd(val: Number) source

Sets the JD date of the simulation.

Params:

NameTypeAttributeDescription
val Number

JD date

public setJdDelta(delta: Number) source

Set the JD per frame of the visualization. This will override any existing "JD per second" setting.

Params:

NameTypeAttributeDescription
delta Number

JD per frame

public setJdPerSecond(x: *): Number source

Set the JD change per second of the visualization.

Params:

NameTypeAttributeDescription
x *

Return:

Number

x JD per second

public start() source

Run the animation

public stop() source

Stop the animation

public zoomToFit(spaceObj: SpaceObject, offset: Number) source

Adjust camera position so that the object fits within the viewport. If applicable, this function will fit around the object's orbit.

Params:

NameTypeAttributeDescription
spaceObj SpaceObject

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.