spacekit
    Preparing search index...

    Class Simulation

    The main entrypoint of a visualization.

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

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

      • simulationElt: HTMLCanvasElement

        The container for this simulation.

      • options: SpacekitOptions

        for simulation

        • basePath

          Path to simulation assets and data

        • startDate

          The start date and time for this simulation.

        • jd

          The JD date of this simulation. Defaults to 0

        • jdDelta

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

        • jdPerSecond

          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.

        • unitsPerAu

          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.

        • startPaused

          Whether the simulation should start in a paused state.

        • maxNumParticles

          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.

        • particleTextureUrl

          The texture for the default particle system.

        • particleDefaultSize

          The default size for the particle system.

        • camera

          Options for camera

        • camera.initialPosition

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

        • camera.enableDrift

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

        • debug

          Options dictating debug state.

        • debug.showAxes

          Show X, Y, and Z axes

        • debug.showGrid

          Show grid on XY plane

        • debug.showStats

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

      Returns Simulation

    onTick?: () => void
    • Add a spacekit object (usually a SpaceObject) to the visualization.

      Parameters

      • obj: SimulationObject

        Object to add to visualization

      • noUpdate: boolean = false

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

      Returns void

      SpaceObject

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

      Parameters

      • color: number = 0x333333

        Color of light, default 0x333333

      Returns void

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

      Parameters

      • pos: Coordinate3d | undefined = undefined

        Position of light source. Defaults to moving with camera.

      • color: number = 0xffffff

        Color of light, default 0xFFFFFF

      Returns void

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

      Parameters

      • ...args: any[]

      Returns SpaceObject

      SpaceObject

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

      Parameters

      • ...args: any[]

      Returns ShapeObject

      ShapeObject

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

      Parameters

      • ...args: any[]

      Returns Skybox

      Skybox

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

      Parameters

      • ...args: any[]

      Returns SphereObject

      SphereObject

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

      Parameters

      • ...args: any[]

      Returns Stars

      Stars

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

      Parameters

      • ...args: any[]

      Returns StaticParticles

      SphereObject

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

      Returns Date

      Date of simulation

    • Gets the current JD date of the simulation

      Returns number

      JD date

    • Get the JD per frame of the visualization.

      Returns number

    • Get the JD change per second of the visualization.

      Returns number | undefined

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

    • Returns Vector3 | undefined

    • Get the three.js renderer

      Returns WebGLRenderer

      The THREE.js renderer

    • Get the three.js scene object

      Returns Scene

      The THREE.js scene object

    • Get the element containing this simulation

      Returns HTMLCanvasElement

      The html container of this simulation

    • Get the Camera and CameraControls wrapper object

      Returns Camera

      The Camera wrapper

    • Returns boolean

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

      Returns Promise<NaturalSatellites>

      NaturalSatellites object that is ready to load.

    • Removes an object from the visualization.

      Parameters

      Returns 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

    • Enable or disable camera drift.

      Parameters

      • driftOn: boolean

        True if you want the camera to float around a bit

      Returns void

    • Set the local date and time of the simulation.

      Parameters

      • date: Date

        Date of simulation

      Returns void

    • Sets the JD date of the simulation.

      Parameters

      • val: number

        JD date

      Returns 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

    • Set the JD change per second of the visualization.

      Parameters

      • x: number

        JD per second

      Returns void

    • Run the animation

      Returns void

    • Stop the animation

      Returns void

    • 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>