• Stars
    star
    527
  • Rank 84,091 (Top 2 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created almost 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Javascript library for 3D space visualizations

spacekit

Build Status npm

Spacekit is a JavaScript library for creating interactive 3D space visualizations - whether of the Earth/moon system, solar system, or beyond.

You can check out an editable live example on jsfiddle, or look at a variety of live examples on SpaceReference.org. This library generalizes work that is currently used on Asterank, Meteor Showers, Ancient Earth, and many other things into a single open-source 3D engine for space that is both accurate and visually stunning.

See the full documentation

Note that this library is a work in progress and the API might change!

spacekit examples

Usage

Install via npm:

npm install spacekit.js

And then use require or import:

const Spacekit = require('spacekit.js');
// or
import Spacekit from 'spacekit.js';

You can also download a raw build or use the latest build in a script tag:

<script src="https://typpo.github.io/spacekit/build/spacekit.js"></script>

Terminology and components

Simulation: the main container for your visualization. A simulation is comprised by a Camera plus whatever you choose to put in it. See documentation for full options.

const sim = new Spacekit.Simulation(document.getElementById('my-container'), {
 // Required
 basePath: '../path/to/asset',
 // Optional
 camera: {
   initialPosition: [0, -10, 5],
   enableDrift: false,
 },
 debug: {
   showAxes: false,
   showGrid: false,
   showStats: false,
 },
});

Skybox: the image background of the visualization. The "universe" of the visualization is contained within a large sphere, so "skysphere" may be a better (less conventional) way to describe it. Some skybox assets are provided, including starry milky way background from ESA and NASA Tycho. See documentation for full preset options.

// Use an existing skybox preset.
const skybox = sim.createSkybox(Spacekit.SkyboxPresets.NASA_TYCHO);

// Add a skybox preset
const skybox = sim.createSkybox({
  textureUrl: '../path/to/image.png'
});

Stars: an alternative to a skybox. Instead of showing an image, this class loads real star data and positions the stars accordingly in the simulation. Usually this is more performant but less visually stunning.

// Use an existing skybox preset.
const skybox = sim.createStars({minSize /* optional */: 0.75 /* default */});

// Add a skybox preset
const skybox = sim.createSkybox({
  textureUrl: '../path/to/image.png'
});

SpaceObject: an object that can be added to the visualization (SpaceObjects can sometimes be referred to as simply "Object"). SpaceObjects can orbit, rotate, etc. Subclasses include RotatingObject (has a defined spin axis), ShapeObject (has a 3D shapefile), and SphereObject (is spherical, like the Earth).

// Create objects using presets. The presets include scientific ephem params and/or position.
const sun = viz.createObject('sun', Spacekit.SpaceObjectPresets.SUN);
viz.createObject('mercury', Spacekit.SpaceObjectPresets.MERCURY);
viz.createObject('venus', Spacekit.SpaceObjectPresets.VENUS);

// Create a stationary object at [3, 1, -5] position.
const obj = viz.createObject('myobj', {
  position: [3, 1, -5],
};

// Create an object that orbits.

// Ephem is a class representing Kepler ephemerides, which defines the trajectory of astronomical objects as well
// as artificial satellites in the sky, i.e., the position (and possibly velocity) over time.
const ephem = new Spacekit.Ephem({
  epoch: 2458600.5,
  a: 5.38533,
  e: 0.19893,
  i: 22.11137,
  om: 294.42992,
  w: 314.28890,
  ma: 229.14238,
}, 'deg');

const asteroid = sim.createObject('Asteroid Aci', {
  ephem,
});

// Create a shape object
const obj = viz.createShape('myobj', {
  position: [3, 1, -5],
  shape: {
    // Example shape file -
    // http://astro.troja.mff.cuni.cz/projects/asteroids3D/web.php?page=db_asteroid_detail&asteroid_id=1046
    shapeUrl: '../path/to/shape.obj', // Cacus
  },
  rotation: {
    lambdaDeg: 251,
    betaDeg: -63,
    period: 3.755067,
    yorp: 1.9e-8,
    phi0: 0,
    jd0: 2443568.0,
  },
  debug: {
    showAxes: true,
  },
});

// Create a sphere object
sim.createSphere('earth', {
  textureUrl: './earth_66mya.jpg',
  radius: 2 /* default to 1 */
  debug: {
    showAxes: true,
  },
});

KeplerParticles: an optimized class for creating many particles that follow Kepler orbits. These particles don't have a specific shape or size. Instead, they share a 2D texture. This is useful for when you want to show many objects at once, such as the asteroid belt.

Dependencies

Spacekit relies on some image and data assets that are not included in the Javascript file.

By default, these dependencies are hosted on the spacekit site (typpo.github.io/spacekit). If you want to host these assets yourself, you can set the Simulation's basePath parameter to a folder that contains these files:

For example:

const viz = new Spacekit.Simulation({
  basePath: 'https://mysite.com/static/spacekit',
});

If you want to contribute to this project, you will also need to install Python (2.7 or 3).

Running an Example

Running ./server.sh will start a basic Python webserver. Go to http://localhost:8001/examples/index.html to load a simple example.

If you're making changes to the code, run yarn build to update the build outputs. yarn build:watch will continuously watch for your changes and update the build and also host a server on localhost:8001 (so you don't have to start the Python server separately).

Usage

See the examples directory for full usage examples. For now, here's some example code that will build an interactive visualization of a couple planets:

// Create the visualization and put it in our div.
const viz = new Spacekit.Simulation(document.getElementById('main-container'), {
  assetPath: '../src/assets',
});

// Create a skybox using NASA TYCHO artwork.
const skybox = viz.createSkybox(Spacekit.SkyboxPresets.NASA_TYCHO);

// Create our first object - the sun - using a preset space object.
const sun = viz.createObject('sun', Spacekit.SpaceObjectPresets.SUN);

// Then add some planets
viz.createObject('mercury', Spacekit.SpaceObjectPresets.MERCURY);
viz.createObject('venus', Spacekit.SpaceObjectPresets.VENUS);
viz.createObject('earth', Spacekit.SpaceObjectPresets.EARTH);
viz.createObject('mars', Spacekit.SpaceObjectPresets.MARS);
viz.createObject('jupiter', Spacekit.SpaceObjectPresets.JUPITER);
viz.createObject('saturn', Spacekit.SpaceObjectPresets.SATURN);
viz.createObject('uranus', Spacekit.SpaceObjectPresets.URANUS);
viz.createObject('neptune', Spacekit.SpaceObjectPresets.NEPTUNE);

example

More Repositories

1

textbelt

Free API for outgoing SMS
JavaScript
3,046
star
2

asterank

asteroid database, interactive visualizations, and discovery tools
HTML
330
star
3

ad-detector

Detects articles with corporate sponsors.
JavaScript
197
star
4

codenav

Better code navigation in github
JavaScript
134
star
5

arkose

GPT-enhanced document editor
TypeScript
99
star
6

ca-property-tax

CA property tax visualization
Python
87
star
7

showers

Rendering of debris clouds in the solar system that cause meteor showers.
JavaScript
58
star
8

ancient-earth

Earth through the ages
JavaScript
53
star
9

call-congress

Jupyter Notebook
48
star
10

quickchart-js

Javascript client for quickchart.io
TypeScript
39
star
11

quickchart-python

Python client for quickchart.io image charts web service
Python
35
star
12

google-charts-node

Render Google Charts to image
JavaScript
32
star
13

web-workers-fallback

html5 web worker api compatibility for browsers that don't support them
JavaScript
25
star
14

chartjs-to-image

Simple library for converting Chart.js to image on backend and frontend
JavaScript
23
star
15

gaia

ESA GAIA webgl data visualization
JavaScript
23
star
16

autoreload

standalone autoreload script
JavaScript
19
star
17

quickchart-php

PHP client for QuickChart chart API
PHP
19
star
18

fb-unsee

Stops people you talk to on Facebook from seeing "βœ” Seen" messages.
JavaScript
15
star
19

astrokit

web app for conducting lightcurve photometry
Python
13
star
20

outwar-dca

Automation for Outwar, a web-based MMORPG.
C#
12
star
21

quickchart-csharp

C# client for QuickChart chart API
C#
11
star
22

gilded-age

Language analysis platform for historical documents from the Reconstruction and Gilded Age eras of American history.
Python
11
star
23

political-annotations

JavaScript
9
star
24

mjml-qr-code

Embed QR codes in your emails
JavaScript
8
star
25

dartmouth-lastchances

App for making connections during Dartmouth senior week...
Python
8
star
26

github-participation-graph

makes the participation graph darker and adds difference between owner and contributor commits
JavaScript
8
star
27

advice

Job and interview advice database for Dartmouth CS majors.
Python
8
star
28

call-congress-example

JavaScript
8
star
29

tweetmap

Geolocated and sentiment-rated tweets
JavaScript
7
star
30

pluto

3d webgl globe of Pluto
JavaScript
6
star
31

voicebox

record audio to your Dropbox with your Android phone
Java
6
star
32

mars

JavaScript
6
star
33

connect-autoreload

Connect middleware that refreshes your site when you update files.
JavaScript
6
star
34

quickchart-ruby

Ruby client for quickchart.io chart API
Ruby
6
star
35

quickchart-java

Java client for quickchart.io chart API
Java
6
star
36

mixpanel-export-cli

Command line tool for mixpanel data export API.
JavaScript
6
star
37

tensorflow-calc

Python
5
star
38

moonviz

JavaScript
5
star
39

node-skeleton

Basic structure for writing quick apps in node.js
JavaScript
5
star
40

hcompress-unix

Version of hcompress that compiles on Ubuntu 12.04
C
5
star
41

bbmobile

an html5 mobile app for a popular social site at dartmouth
JavaScript
4
star
42

google-pagerank

npm module for getting pagerank
JavaScript
4
star
43

batb-chrome-extension

Chrome extension for de-anonymizing Dartmouth realtime chat site
JavaScript
4
star
44

fb-less-stupid

JavaScript
4
star
45

vote-banner

Add a voter registration CTA to your website
HTML
4
star
46

apple-monitor

Tells you when things are available at nearby apple stores
JavaScript
4
star
47

world-of-loot

Python
4
star
48

rapchat

CSS
4
star
49

chrome-firefox-inject-boilerplate

Generic boilerplate for a Chrome and Firefox extension that injects js and css into a page.
Shell
4
star
50

threejs-playground

JavaScript
4
star
51

facebook-friend-monitor

Facebook application that notifies users when they've been defriended.
Python
3
star
52

leafstorm

Python
3
star
53

quickchart-docs

Documentation for QuickChart (https://quickchart.io/documentation/)
JavaScript
3
star
54

lok

vim-based journal/private editing
C
3
star
55

ceres

JavaScript
3
star
56

gifthorse

JavaScript
3
star
57

gith

Maintains an encrypted mirror of your git repo
Python
3
star
58

price-detector

JavaScript
3
star
59

millenium-viz

Visualization of the supercomputer Millenium Simulation
JavaScript
3
star
60

mjml-chartjs

Embed charts in your emails with Chart.js and MJML
JavaScript
3
star
61

node-poll-proxy

Websocket wrapper for ajax polling implementations.
JavaScript
3
star
62

dreamon

Dream logs & reminders.
JavaScript
3
star
63

my-site

JavaScript
3
star
64

wowzer

Arbitrage in a virtual crafted item economy...
Python
3
star
65

imgrag

TypeScript
3
star
66

AIM-was-better

converts google hangouts pings to AOL instant messenger pings
JavaScript
2
star
67

prettier-worker

A Cloudflare Worker that formats code using prettier
JavaScript
2
star
68

this-or-that

JavaScript
2
star
69

mysky

JavaScript
2
star
70

speaklouder

CSS
2
star
71

beadpile

JavaScript
2
star
72

gmail-bumpit

Chrome extension to bump gmail threads in X days
Python
2
star
73

circle-of-life

spice up your browsing
JavaScript
2
star
74

interviewclub

HTML
2
star
75

dinobot-discord

JavaScript
2
star
76

schooldata

CSS
2
star
77

test-repo

A test repository
2
star
78

verified-facts

Python
2
star
79

nunjucks-phone-filter

phone number formatting filter for nunjucks templating engine
JavaScript
2
star
80

gpu.js

JavaScript
2
star
81

empty-package.json

This repo contains an empty package.json
2
star
82

ceres2

JavaScript
2
star
83

wololo

JavaScript
2
star
84

blog

JavaScript
2
star
85

rapchat-phonegap

Java
2
star
86

talkthen

Python
2
star
87

neutralgas

HTML
2
star
88

wowhead-autocomplete

simple redis based autocomplete for item db
Python
2
star
89

bowie

six degrees of david bowie
Python
2
star
90

shouldileave-web

JavaScript
1
star
91

azoo-testbed

Python
1
star
92

Inflation-Calculator

An inflation calculator for iOS and watchOS written in Swift
Swift
1
star
93

harvest

CSS
1
star
94

watchtower

Python
1
star
95

hide-blue-checks

Hide blue check marks on Twitter
JavaScript
1
star
96

gpt3-writer

1
star
97

eating-trainer

JavaScript
1
star
98

stories

CSS
1
star
99

temperatures

JavaScript
1
star
100

ghost-blog

JavaScript
1
star