Giter Site home page Giter Site logo

typpo / spacekit Goto Github PK

View Code? Open in Web Editor NEW
509.0 15.0 38.0 65.22 MB

Javascript library for 3D space visualizations

Home Page: https://typpo.github.io/spacekit/

License: MIT License

JavaScript 52.07% Python 0.29% Shell 0.08% HTML 1.06% TypeScript 46.50%
space visualization hacktoberfest

spacekit's Introduction

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

spacekit's People

Contributors

dependabot[bot] avatar hankg avatar judymou avatar srikanthnv avatar szymonsuchanowski avatar trevnorris avatar typpo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spacekit's Issues

Just wanted to say hi as I've done something similar

First, cool stuff in this repo 👍

Just wanted to give you a heads up that I did something similar in 2017/18, although in JavaScript, as
TypeScript wasn't really that mature or "hip" when I started my side project called "solar system explorer":

Latest demo of what I've implemented:
http://www.ocbnet.ch/solsys-preview-19 (chrome only)
FWIW the corresponding tweet with some screenshots:
https://twitter.com/mgreter/status/1402713051015565324

Unfortunately I haven't gotten around to publish much on GitHub, beside:

Anyway, found your repo just now as I'm slowly trying to publish my code on GitHub too.
Main reason that is hindering me is that I need to do proper asset copyright attribution yet.
Will probably poke around your repo a little to see if I can incorporate a thing or two into my project.
If you want to poke around my code, I also made an uncompressed version available at:
http://www.ocbnet.ch/solsys-preview-19/three-app-build/demo/solsys.dev.html

Hope you don't mind me opening an issue just to mention that.

Background stars in the wrong position

Hello,
I am using the Stars background generated by Spacekit. I noticed that the position of background stars is not correct. Stars are in the wrong position and/or duplicated. The arrangement suggests a 180-degrees error in the software. Could you suggest if I can somehow rotate the background to correct the star positions with respect to Earth?

No rings in the visualization of the Saturn system

There are no rings displayed when the Saturn example is run on the following configuration:

  • Firefox 69 and 70
  • Windows 10 x64
  • i5-5200U
  • integrated GPU

зображення

Firefox JS console shows the following errors:

spacekit.js:18227:13

THREE.WebGLProgram: shader error:  0 35715 false gl.getProgramInfoLog C:\fakepath(100,90-116): internal error: invalid access of unbound variable

Warning: D3D shader compilation failed with default flags. (ps_5_0)
 Retrying with skip validation
C:\fakepath(100,90-116): internal error: invalid access of unbound variable

Warning: D3D shader compilation failed with skip validation flags. (ps_5_0)
 Retrying with skip optimization
C:\fakepath(100,90-116): internal error: invalid access of unbound variable

Warning: D3D shader compilation failed with skip optimization flags. (ps_5_0)

Failed to create D3D Shaders  spacekit.js:18227:13
    WebGLProgram https://typpo.github.io/spacekit/build/spacekit.js:18227
    acquireProgram https://typpo.github.io/spacekit/build/spacekit.js:18606
    initMaterial https://typpo.github.io/spacekit/build/spacekit.js:24575
    setProgram https://typpo.github.io/spacekit/build/spacekit.js:24716
    renderBufferDirect https://typpo.github.io/spacekit/build/spacekit.js:23775
    renderObject https://typpo.github.io/spacekit/build/spacekit.js:24492
    renderObjects https://typpo.github.io/spacekit/build/spacekit.js:24462
    render https://typpo.github.io/spacekit/build/spacekit.js:24264
    animate https://typpo.github.io/spacekit/build/spacekit.js:58819

I'm going to check some Chromium-based browser to check whether the problem is Firefox-specific or it's something missing in Intel's GPU drivers.

Ring shader not working on SphereObjects with Ephem

First of all, this project looks fantastic and has a ton of potential. Kudos.

It appears that when rings are added to a SphereObject with ephem (i.e. being propagated around the scene), the rings become unlit. It seems to be related to the ring shader, but I'm no Three.js expert.

Example:
image

My project uses webpack, but I can replicate the issue on a static page using the code below.

const viz = new Spacekit.Simulation(document.getElementById('main-container'), {
  jdPerSecond: 0.05,
  unitsPerAu: 100.0,
});

viz.createObject('sun', Spacekit.SpaceObjectPresets.SUN);
viz.createAmbientLight();
viz.createLight([0, 0, 0]);

const saturn = viz.createSphere('saturn', {
  textureUrl: './saturn.jpg',
  ephem: Spacekit.EphemPresets.SATURN,
  radius: 58232.503 / 149598000,
});
saturn.addRings(74270.580913, 140478.924731, './saturn_ring.png');
viz.getViewer().followObject(saturn, [-0.75, -0.75, 0.5]);

Labels dont' show properly for objects without ephem

const asteroid = viz.createObject('Asteroid', {
position: [3, 1, -5],
labelText: 'My asteroid',
textureUrl: planets[0].img
});

This will not show the label over the asteroid

Same happens with createSphere

Note: this issue only happens if the simulation is not paused

Scene suddenly stopped working in Safari and on iOS

Hi! We have been in touch before. I am the maintainer of the Starlink Simulation based on SpaceKit. Today I found out that it's broken in Safari and Safari-based browsers (iOS). I am getting these errors (Safari 15.1 (17612.2.9.1.20)):

THREE.WebGLProgram: Shader Error 1282 - VALIDATE_STATUS false

Program Info Log: Internal error compiling shader with Metal backend.
Please submit this shader, or website as a bug to https://bugs.webkit.org
WebGL: INVALID_OPERATION: useProgram: program not valid

What could have caused this?

Thanks!

addObject() not working

I have an spaceObject that I store in an array[ ] of spaceObjects, which I use the remove from the simulation upon a button click, an then make the spaceObjects reappear on another button click using the array of spaceObjects and it does not work at all :/

can't see cloud

this is strictly speaking not a problem of spacekit, but I have following issue:

it concerrns https://www.meteorshowers.org/

on a mobile device (Samsung S4 mini with Chrome that is no longer updated) I can perfectly see the meteor cloud (I guess implemented as particles):

image

on Ubuntu 16 running on an XPS-13 I don't see the cloud:

image

the planets aren't visible either.

and when I run the example https://typpo.github.io/spacekit/examples/meteor-shower/index.html

I do see planets, and particles:

image

could it be that there is an issue on https://www.meteorshowers.org/ ?

thx

(I couldn't find contact info on that site.)

Add probe object with mass, velocity and direction vector?

Hello,
I was wondering if it would be possible to add an object (for example, a probe) to the system that has a velocity and direction and is bound to gravitational influences?
For example: Insert a probe in an earth object, accelerate towards the moon, slingshot around the moon and return back to earth?

If there are no space physics currently available in the simulation, would it be possible to attach my own calculations how that object should move and update the simulation accordingly?

Thanks for any help on this matter!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.