Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
364 changes: 182 additions & 182 deletions build/spacekit.cjs.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/spacekit.cjs.js.map

Large diffs are not rendered by default.

362 changes: 181 additions & 181 deletions build/spacekit.esm.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/spacekit.esm.js.map

Large diffs are not rendered by default.

364 changes: 182 additions & 182 deletions build/spacekit.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions build/spacekit.js.map

Large diffs are not rendered by default.

5 changes: 2 additions & 3 deletions build/typescript/Camera.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,13 @@ export default class Camera {
private context;
private camera;
private cameraControls;
private followMesh?;
private followTarget?;
/**
* @param {Object} context The simulation context
*/
constructor(context: SimulationContext);
/**
* Move the camera to follow a SpaceObject as it moves. Currently only works
* for non-particlesystems.
* Move the camera to follow a SpaceObject as it moves.
* @param {SpaceObject} obj SpaceObject to follow.
* @param {Array.<Number>} position Position of the camera with respect to
* the object.
Expand Down
20 changes: 9 additions & 11 deletions build/typescript/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var Camera = /** @class */ (function () {
function Camera(context) {
// TODO(ian): Accept either context or container
this.context = context;
// Optional mesh that we are following.
this.followMesh = undefined;
// Optional object that we are following.
this.followTarget = undefined;
var containerWidth = this.context.container.width;
var containerHeight = this.context.container.height;
var camera = new THREE.PerspectiveCamera(50, containerWidth / containerHeight, (0, Scale_1.rescaleNumber)(0.00001), (0, Scale_1.rescaleNumber)(2000));
Expand Down Expand Up @@ -67,35 +67,32 @@ var Camera = /** @class */ (function () {
this.cameraControls = controls;
}
/**
* Move the camera to follow a SpaceObject as it moves. Currently only works
* for non-particlesystems.
* Move the camera to follow a SpaceObject as it moves.
* @param {SpaceObject} obj SpaceObject to follow.
* @param {Array.<Number>} position Position of the camera with respect to
* the object.
*/
Camera.prototype.followObject = function (obj, position) {
var followMesh = obj.get3jsObjects()[0];
this.cameraControls.enablePan = false;
var rescaled = (0, Scale_1.rescaleArray)(position);
this.camera.position.add(new THREE.Vector3(rescaled[0], rescaled[1], rescaled[2]));
this.cameraControls.update();
this.followMesh = followMesh;
this.followTarget = obj;
};
/**
* Stop the camera from following the object.
*/
Camera.prototype.stopFollowingObject = function () {
if (this.followMesh) {
this.followMesh.remove(this.camera);
this.followMesh = undefined;
if (this.followTarget) {
this.followTarget = undefined;
this.cameraControls.enablePan = true;
}
};
/**
* @returns {boolean} True if camera is following object.
*/
Camera.prototype.isFollowingObject = function () {
return !!this.followMesh;
return !!this.followTarget;
};
/**
* @returns {THREE.PerspectiveCamera} The THREE.js camera object.
Expand All @@ -114,7 +111,8 @@ var Camera = /** @class */ (function () {
*/
Camera.prototype.update = function () {
if (this.isFollowingObject()) {
var newpos = this.followMesh.position.clone();
var _a = this.followTarget.getPosition(this.context.simulation.getJd()), x = _a[0], y = _a[1], z = _a[2];
var newpos = new THREE.Vector3(x, y, z);
var offset = newpos.clone().sub(this.cameraControls.target);
this.camera.position.add(offset);
this.cameraControls.target.set(newpos.x, newpos.y, newpos.z);
Expand Down
2 changes: 1 addition & 1 deletion build/typescript/Coordinates.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var Coordinates = /** @class */ (function () {
Coordinates.getNutationAndObliquity = function (jd) {
if (jd === void 0) { jd = J2000; }
var t = (jd - J2000) / 36525;
var omega = Units_1["default"].rad(125.04452 - 1934.136261 * t + 0.0020708 * t * t + (t * t + t) / 450000);
var omega = Units_1["default"].rad(125.04452 - 1934.136261 * t + 0.0020708 * t * t + (t * t * t) / 450000);
var Lsun = Units_1["default"].rad(280.4665 + 36000.7698 * t);
var Lmoon = Units_1["default"].rad(218.3165 + 481267.8813 * t);
var nutation = (-17.2 / 3600) * Math.sin(omega) -
Expand Down
18 changes: 9 additions & 9 deletions build/typescript/Ephem.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,16 +217,16 @@ var Ephem = /** @class */ (function () {
var n = this.getUnsafe('n');
var GM = this.getUnsafe('GM');
var period = this.getUnsafe('period');
if (!isDef(period) && isDef(a)) {
if (!isDef(GM)) {
throw new Error('Expected ephemeris attribute GM to be set');
}
period =
(2 * Math.PI * Math.sqrt((aMeters * aMeters * aMeters) / GM)) /
SECONDS_IN_DAY;
this.set('period', period);
}
if (e < 1.0) {
if (!isDef(period) && isDef(a)) {
if (!isDef(GM)) {
throw new Error('Expected ephemeris attribute GM to be set');
}
period =
(2 * Math.PI * Math.sqrt((aMeters * aMeters * aMeters) / GM)) /
SECONDS_IN_DAY;
this.set('period', period);
}
// Only work with mean motion for elliptical orbits.
if (isDef(period) && !isDef(n)) {
// Set radians
Expand Down
2 changes: 1 addition & 1 deletion build/typescript/EphemPresets.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ exports.EphemPresets = {
}, 'deg', true /* locked */),
MOON: new Ephem_1.Ephem({
// https://nssdc.gsfc.nasa.gov/planetary/factsheet/moonfact.html
GM: 0.3986e15,
GM: Ephem_1.GM.EARTH_MOON,
// Geocentric
// https://ssd.jpl.nasa.gov/horizons.cgi#results
epoch: 2458621.5,
Expand Down
7 changes: 5 additions & 2 deletions build/typescript/EphemerisTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ var EphemerisTable = /** @class */ (function () {
var stopIndex = startIndex + Number(this.interpolationOrder);
if (stopIndex >= this.data.length) {
stopIndex = this.data.length - 1;
if (this.data.length > halfSampleSize) {
startIndex = stopIndex - halfSampleSize;
if (this.data.length > this.interpolationOrder) {
startIndex = stopIndex - this.interpolationOrder;
}
else {
startIndex = 0;
}
}
return { startIndex: startIndex, stopIndex: stopIndex };
Expand Down
23 changes: 23 additions & 0 deletions build/typescript/Interaction.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import type { Coordinate3d } from './Coordinates';
import type { SpaceObject } from './SpaceObject';
export interface ScreenPosition {
x: number;
y: number;
}
export interface PickCandidate {
object: SpaceObject;
point?: Coordinate3d;
radiusPx: number;
screen: ScreenPosition;
}
interface Object3dLike {
parent?: Object3dLike | null;
uuid: string;
}
export declare function getNormalizedPointer(screen: ScreenPosition, width: number, height: number): ScreenPosition;
export declare function findParentPickMatch(target: Object3dLike | null | undefined, objectsByUuid: Map<string, SpaceObject>): SpaceObject | undefined;
export declare function findClosestPickCandidate(screen: ScreenPosition, candidates: PickCandidate[]): {
candidate: PickCandidate;
distancePx: number;
} | undefined;
export {};
42 changes: 42 additions & 0 deletions build/typescript/Interaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"use strict";
exports.__esModule = true;
exports.findClosestPickCandidate = exports.findParentPickMatch = exports.getNormalizedPointer = void 0;
function getNormalizedPointer(screen, width, height) {
return {
x: (screen.x / width) * 2 - 1,
y: -(screen.y / height) * 2 + 1
};
}
exports.getNormalizedPointer = getNormalizedPointer;
function findParentPickMatch(target, objectsByUuid) {
var _a;
var current = target;
while (current) {
var matched = objectsByUuid.get(current.uuid);
if (matched) {
return matched;
}
current = (_a = current.parent) !== null && _a !== void 0 ? _a : undefined;
}
return undefined;
}
exports.findParentPickMatch = findParentPickMatch;
function findClosestPickCandidate(screen, candidates) {
var bestMatch;
candidates.forEach(function (candidate) {
var dx = candidate.screen.x - screen.x;
var dy = candidate.screen.y - screen.y;
var distancePx = Math.hypot(dx, dy);
if (distancePx > candidate.radiusPx) {
return;
}
if (!bestMatch || distancePx < bestMatch.distancePx) {
bestMatch = {
candidate: candidate,
distancePx: distancePx
};
}
});
return bestMatch;
}
exports.findClosestPickCandidate = findClosestPickCandidate;
1 change: 1 addition & 0 deletions build/typescript/RotatingObject.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export declare class RotatingObject extends SpaceObject {
* @return {Array.<THREE.Object>} A list of THREE.js objects
*/
get3jsObjects(): THREE.Object3D[];
getPrimaryObject3js(): THREE.Object3D | undefined;
/**
* Begin rotating this object.
*/
Expand Down
3 changes: 3 additions & 0 deletions build/typescript/RotatingObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ var RotatingObject = /** @class */ (function (_super) {
ret.unshift(this._obj);
return ret;
};
RotatingObject.prototype.getPrimaryObject3js = function () {
return this._obj;
};
/**
* Begin rotating this object.
*/
Expand Down
86 changes: 86 additions & 0 deletions build/typescript/Simulation.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,25 @@ interface DebugOptions {
showGrid?: boolean;
showStats?: boolean;
}
export interface InteractionOptions {
enableClick?: boolean;
enableHover?: boolean;
pickRadiusPx?: number;
particlePickRadiusPx?: number;
}
export declare type PickSource = 'raycast' | 'screen-proximity';
export declare type PickKind = 'object';
export interface PickResult {
object: SpaceObject;
source: PickSource;
kind: PickKind;
point?: Coordinate3d;
screen: {
x: number;
y: number;
};
distancePx: number;
}
interface SpacekitOptions {
basePath: string;
startDate?: Date;
Expand Down Expand Up @@ -97,6 +116,7 @@ export declare class Simulation {
private useLightSources;
private lightPosition?;
private subscribedObjects;
private objectRegistry;
private particles;
private stats?;
private fps;
Expand All @@ -108,6 +128,14 @@ export declare class Simulation {
private scene;
private renderer;
private composer?;
onObjectClick?: (result: PickResult, ev: MouseEvent) => void;
onObjectHover?: (result: PickResult | undefined, ev: PointerEvent) => void;
private interactionOptions;
private hoveredObject?;
private selectedObject?;
private interactionListenersInstalled;
private raycaster;
private pointerNdc;
/**
* @param {HTMLCanvasElement} simulationElt The container for this simulation.
* @param {Object} options for simulation
Expand Down Expand Up @@ -163,6 +191,31 @@ export declare class Simulation {
* @private
*/
private initPasses;
/**
* @private
* Installs DOM event handlers for object interaction.
*/
private installInteractionListeners;
/**
* @private
* Gets the pointer position relative to the renderer's canvas.
*/
private getCanvasRelativePosition;
/**
* @private
* Handles click selection on the renderer canvas.
*/
private handleCanvasClick;
/**
* @private
* Handles hover interactions on the renderer canvas.
*/
private handleCanvasPointerMove;
/**
* @private
* Clears hover state when the pointer leaves the renderer canvas.
*/
private handleCanvasPointerLeave;
/**
* @private
*/
Expand Down Expand Up @@ -261,6 +314,39 @@ export declare class Simulation {
* @see {NaturalSatellites}
*/
loadNaturalSatellites(): Promise<NaturalSatellites>;
/**
* Configures interaction handlers for the simulation canvas.
* @param {Object} options Interaction options
*/
configureInteraction(options?: InteractionOptions): void;
/**
* Gets the current list of registered space objects in the visualization.
* @return {SpaceObject[]} Space objects currently managed by the simulation
*/
getObjects(): SpaceObject[];
/**
* Gets a registered space object by id.
* @param {String} id Space object id
* @return {SpaceObject | undefined} Matching object, if any
*/
getObjectById(id: string): SpaceObject | undefined;
/**
* Attempts to pick a space object at the given screen coordinates.
* @param {Number} clientX Pointer x position in client coordinates
* @param {Number} clientY Pointer y position in client coordinates
* @return {PickResult | undefined} Picked object details
*/
pick(clientX: number, clientY: number): PickResult | undefined;
/**
* Sets the selected space object, or clears selection if target is omitted.
* @param {SpaceObject | String | undefined} target SpaceObject or id
*/
selectObject(target?: SpaceObject | string): void;
/**
* Gets the currently selected space object.
* @return {SpaceObject | undefined} Selected object, if any
*/
getSelectedObject(): SpaceObject | undefined;
/**
* Installs a scroll handler that only renders the visualization while it is
* in the user's viewport.
Expand Down
Loading