Socket
Socket
Sign inDemoInstall

lore-engine

Package Overview
Dependencies
0
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.1.0 to 1.1.5

2

package.json
{
"name": "lore-engine",
"version": "1.1.0",
"version": "1.1.5",
"description": "A WebGL based 3D data visualization engine.",

@@ -5,0 +5,0 @@ "main": "./app.js",

//@ts-check
const ControlsBase = require('../Controls/ControlsBase')
const Vector3f = require('../Math/Vector3f');
const SphericalCoords = require('../Math/SphericalCoords');
const ControlsBase = require("../Controls/ControlsBase");
const Vector3f = require("../Math/Vector3f");
const SphericalCoords = require("../Math/SphericalCoords");
/**
/**
* A class representing orbital controls.
*
*
* @property {Vector3f} up The global up vector.

@@ -18,319 +18,365 @@ * @property {Number} radius The distance from the camera to the lookat vector.

class OrbitalControls extends ControlsBase {
/**
* Creates an instance of OrbitalControls.
* @param {Renderer} renderer An instance of a Lore renderer.
* @param {Number} radius The distance of the camera to the lookat vector.
* @param {Vector3f} lookAt The lookat vector.
*/
constructor(renderer, radius, lookAt = new Vector3f(0.0, 0.0, 0.0)) {
super(renderer, lookAt);
/**
* Creates an instance of OrbitalControls.
* @param {Renderer} renderer An instance of a Lore renderer.
* @param {Number} radius The distance of the camera to the lookat vector.
* @param {Vector3f} lookAt The lookat vector.
*/
constructor(renderer, radius, lookAt = new Vector3f(0.0, 0.0, 0.0)) {
super(renderer, lookAt);
this.up = Vector3f.up();
this.radius = radius;
this.up = Vector3f.up();
this.radius = radius;
this.yRotationLimit = Math.PI;
this.yRotationLimit = Math.PI;
this._dPhi = 0.0;
this._dTheta = 0.0;
this._dPan = new Vector3f(0.0, 0.0, 0.0);
this._dPhi = 0.0;
this._dTheta = 0.0;
this._dPan = new Vector3f(0.0, 0.0, 0.0);
this.spherical = new SphericalCoords();
this.spherical = new SphericalCoords();
this.scale = 0.95;
this.camera.position = new Vector3f(radius, radius, radius);
this.camera.updateProjectionMatrix();
this.camera.updateViewMatrix();
this.scale = 0.95;
this.rotationLocked = false;
this.camera.position = new Vector3f(radius, radius, radius);
this.camera.updateProjectionMatrix();
this.camera.updateViewMatrix();
let that = this;
this.rotationLocked = false;
this.addEventListener('mousedrag', function (e) {
that.update(e.e, e.source);
});
let that = this;
this.addEventListener('touch', function (e) {
that.update(e.e, e.source);
});
this.addEventListener("mousedrag", function(e) {
that.update(e.e, e.source);
});
this.addEventListener('mousewheel', function (e) {
that.update({
x: 0,
y: -e.e
}, 'wheel');
});
this.addEventListener("touch", function(e) {
that.update(e.e, e.source);
});
// Initial update
this.update({
x: 0,
y: 0
}, 'left');
}
this.addEventListener("mousewheel", function(e) {
that.update(
{
x: 0,
y: -e.e
},
"wheel"
);
});
/**
* Limit the vertical rotation to the horizon (the upper hemisphere).
*
* @param {Boolean} limit A boolean indicating whether or not to limit the vertical rotation to the horizon.
* @returns {OrbitalControls} Returns itself.
*/
limitRotationToHorizon(limit) {
if (limit) {
this.yRotationLimit = 0.5 * Math.PI;
} else {
this.yRotationLimit = Math.PI;
}
// Initial update
this.update(
{
x: 0,
y: 0
},
"left"
);
}
return this;
/**
* Limit the vertical rotation to the horizon (the upper hemisphere).
*
* @param {Boolean} limit A boolean indicating whether or not to limit the vertical rotation to the horizon.
* @returns {OrbitalControls} Returns itself.
*/
limitRotationToHorizon(limit) {
if (limit) {
this.yRotationLimit = 0.5 * Math.PI;
} else {
this.yRotationLimit = Math.PI;
}
/**
* Sets the distance (radius of the sphere) from the lookat vector to the camera.
*
* @param {Number} radius The radius.
* @returns {OrbitalControls} Returns itself.
*/
setRadius(radius) {
this.radius = radius;
this.camera.position = new Vector3f(0, 0, radius);
return this;
}
/**
* Sets the distance (radius of the sphere) from the lookat vector to the camera.
*
* @param {Number} radius The radius.
* @returns {OrbitalControls} Returns itself.
*/
setRadius(radius) {
this.radius = radius;
this.camera.position = new Vector3f(0, 0, radius);
this.camera.updateProjectionMatrix();
this.camera.updateViewMatrix();
this.update();
return this;
}
/**
* Update the camera (on mouse move, touch drag, mousewheel scroll, ...).
*
* @param {*} [e=null] A mouse or touch events data.
* @param {String} [source=null] The source of the input ('left', 'middle', 'right', 'wheel', ...).
* @returns {OrbitalControls} Returns itself.
*/
update(e = null, source = null) {
if (source == "left" && !this.rotationLocked) {
// Rotate
this._dTheta =
(-2 * Math.PI * e.x) / (this.canvas.clientWidth * this.camera.zoom);
this._dPhi =
(-2 * Math.PI * e.y) / (this.canvas.clientHeight * this.camera.zoom);
// It's just to fast like this ...
// this._dTheta = -2 * Math.PI * e.x / this.canvas.clientWidth;
// this._dPhi = -2 * Math.PI * e.y / this.canvas.clientHeight;
} else if (source == "right" || (source == "left" && this.rotationLocked)) {
// Translate
let x =
(e.x * (this.camera.right - this.camera.left)) /
this.camera.zoom /
this.canvas.clientWidth;
let y =
(e.y * (this.camera.top - this.camera.bottom)) /
this.camera.zoom /
this.canvas.clientHeight;
let u = this.camera.getUpVector().components;
let r = this.camera.getRightVector().components;
this._dPan.components[0] = r[0] * -x + u[0] * y;
this._dPan.components[1] = r[1] * -x + u[1] * y;
this._dPan.components[2] = r[2] * -x + u[2] * y;
} else if (source == "middle" || source == "wheel" || source == "pinch") {
if (e.y > 0) {
// Zoom Out
this.camera.zoom = Math.max(0, this.camera.zoom * this.scale);
this.camera.updateProjectionMatrix();
this.camera.updateViewMatrix();
this.update();
return this;
this.raiseEvent("zoomchanged", this.camera.zoom);
} else if (e.y < 0) {
// Zoom In
this.camera.zoom = Math.max(0, this.camera.zoom / this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent("zoomchanged", this.camera.zoom);
}
}
/**
* Update the camera (on mouse move, touch drag, mousewheel scroll, ...).
*
* @param {*} [e=null] A mouse or touch events data.
* @param {String} [source=null] The source of the input ('left', 'middle', 'right', 'wheel', ...).
* @returns {OrbitalControls} Returns itself.
*/
update(e = null, source = null) {
if (source == 'left' && !this.rotationLocked) {
// Rotate
this._dTheta = -2 * Math.PI * e.x / (this.canvas.clientWidth * this.camera.zoom);
this._dPhi = -2 * Math.PI * e.y / (this.canvas.clientHeight * this.camera.zoom);
// It's just to fast like this ...
// this._dTheta = -2 * Math.PI * e.x / this.canvas.clientWidth;
// this._dPhi = -2 * Math.PI * e.y / this.canvas.clientHeight;
} else if (source == 'right' || source == 'left' && this.rotationLocked) {
// Translate
let x = e.x * (this.camera.right - this.camera.left) /
this.camera.zoom / this.canvas.clientWidth;
let y = e.y * (this.camera.top - this.camera.bottom) /
this.camera.zoom / this.canvas.clientHeight;
// Update the camera
let offset = this.camera.position.clone().subtract(this.lookAt);
let u = this.camera.getUpVector().components;
let r = this.camera.getRightVector().components;
this.spherical.setFromVector(offset);
this.spherical.components[1] += this._dPhi;
this.spherical.components[2] += this._dTheta;
this.spherical.limit(0, this.yRotationLimit, -Infinity, Infinity);
this.spherical.secure();
this._dPan.components[0] = r[0] * -x + u[0] * y;
this._dPan.components[1] = r[1] * -x + u[1] * y;
this._dPan.components[2] = r[2] * -x + u[2] * y;
} else if (source == 'middle' || source == 'wheel' || source == 'pinch') {
if (e.y > 0) {
// Zoom Out
this.camera.zoom = Math.max(0, this.camera.zoom * this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent('zoomchanged', this.camera.zoom);
} else if (e.y < 0) {
// Zoom In
this.camera.zoom = Math.max(0, this.camera.zoom / this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent('zoomchanged', this.camera.zoom);
}
}
// Limit radius here
this.lookAt.add(this._dPan);
offset.setFromSphericalCoords(this.spherical);
// Update the camera
let offset = this.camera.position.clone().subtract(this.lookAt);
this.camera.position.copyFrom(this.lookAt).add(offset);
this.camera.setLookAt(this.lookAt);
this.camera.updateViewMatrix();
this.spherical.setFromVector(offset);
this.spherical.components[1] += this._dPhi;
this.spherical.components[2] += this._dTheta;
this.spherical.limit(0, this.yRotationLimit, -Infinity, Infinity);
this.spherical.secure();
this._dPhi = 0.0;
this._dTheta = 0.0;
this._dPan.set(0, 0, 0);
// Limit radius here
this.lookAt.add(this._dPan);
offset.setFromSphericalCoords(this.spherical);
this.raiseEvent("updated");
this.camera.position.copyFrom(this.lookAt).add(offset);
this.camera.setLookAt(this.lookAt);
this.camera.updateViewMatrix();
return this;
}
this._dPhi = 0.0;
this._dTheta = 0.0;
this._dPan.set(0, 0, 0);
/**
* Moves the camera around the sphere by spherical coordinates.
*
* @param {Number} phi The phi component of the spherical coordinates.
* @param {Number} theta The theta component of the spherical coordinates.
* @returns {OrbitalControls} Returns itself.
*/
setView(phi, theta) {
let offset = this.camera.position.clone().subtract(this.lookAt);
this.raiseEvent('updated');
this.spherical.setFromVector(offset);
this.spherical.components[1] = phi;
this.spherical.components[2] = theta;
this.spherical.secure();
return this;
}
offset.setFromSphericalCoords(this.spherical);
/**
* Moves the camera around the sphere by spherical coordinates.
*
* @param {Number} phi The phi component of the spherical coordinates.
* @param {Number} theta The theta component of the spherical coordinates.
* @returns {OrbitalControls} Returns itself.
*/
setView(phi, theta) {
let offset = this.camera.position.clone().subtract(this.lookAt);
this.camera.position.copyFrom(this.lookAt).add(offset);
this.camera.setLookAt(this.lookAt);
this.camera.updateViewMatrix();
this.raiseEvent("updated");
this.spherical.setFromVector(offset);
this.spherical.components[1] = phi;
this.spherical.components[2] = theta;
this.spherical.secure();
return this;
}
offset.setFromSphericalCoords(this.spherical);
/**
* Zoom in on the lookat vector.
*
* @returns {OrbitalControls} Returns itself.
*/
zoomIn() {
this.camera.zoom = Math.max(0, this.camera.zoom / this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent("zoomchanged", this.camera.zoom);
this.raiseEvent("updated");
this.camera.position.copyFrom(this.lookAt).add(offset);
this.camera.setLookAt(this.lookAt);
this.camera.updateViewMatrix();
this.raiseEvent('updated');
return this;
}
return this;
}
/**
* Zoom out from the lookat vector.
*
* @returns {OrbitalControls} Returns itself.
*/
zoomOut() {
this.camera.zoom = Math.max(0, this.camera.zoom * this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent("zoomchanged", this.camera.zoom);
this.raiseEvent("updated");
/**
* Zoom in on the lookat vector.
*
* @returns {OrbitalControls} Returns itself.
*/
zoomIn() {
this.camera.zoom = Math.max(0, this.camera.zoom / this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent('zoomchanged', this.camera.zoom);
this.raiseEvent('updated');
return this;
}
/**
* Zoom out from the lookat vector.
*
* @returns {OrbitalControls} Returns itself.
*/
zoomOut() {
this.camera.zoom = Math.max(0, this.camera.zoom * this.scale);
this.camera.updateProjectionMatrix();
this.raiseEvent('zoomchanged', this.camera.zoom);
this.raiseEvent('updated');
return this;
}
return this;
}
/**
* Set the zoom to a given value.
*
* @param {Number} zoom The zoom value.
* @returns {OrbitalControls} Returns itself.
*/
setZoom(zoom) {
this.camera.zoom = zoom;
this.camera.updateProjectionMatrix();
this.raiseEvent("zoomchanged", this.camera.zoom);
this.update();
/**
* Set the zoom to a given value.
*
* @param {Number} zoom The zoom value.
* @returns {OrbitalControls} Returns itself.
*/
setZoom(zoom) {
this.camera.zoom = zoom;
this.camera.updateProjectionMatrix();
this.raiseEvent('zoomchanged', this.camera.zoom);
this.update();
return this;
}
return this;
}
/**
* Get the zoom.
*
* @returns {Number} The zoom value.
*/
getZoom() {
return this.camera.zoom;
}
/**
* Get the zoom.
*
* @returns {Number} The zoom value.
*/
getZoom() {
return this.camera.zoom;
/**
* Sets the view by name (left, right, top, bottom, back, front, free)
*
* @param {String} viewName The name of the view.
*
* @returns {OrbitalControls} Returns itself.
*/
setViewByName(viewName) {
switch (viewName) {
case "left":
this.setLeftView();
break;
case "right":
this.setRightView();
break;
case "top":
this.setTopView();
break;
case "bottom":
this.setBottomView();
break;
case "back":
this.setBackView();
break;
case "front":
this.setFrontView();
break;
default:
this.setFreeView();
}
/**
* Set the camera to the top view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setTopView() {
this.setView(0.0, 2.0 * Math.PI);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the top view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setTopView() {
this.setView(0.0, 2.0 * Math.PI);
this.rotationLocked = true;
/**
* Set the camera to the bottom view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setBottomView() {
this.setView(0.0, 0.0);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the bottom view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setBottomView() {
this.setView(0.0, 0.0);
this.rotationLocked = true;
/**
* Set the camera to the right view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setRightView() {
this.setView(0.5 * Math.PI, 0.5 * Math.PI);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the right view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setRightView() {
this.setView(0.5 * Math.PI, 0.5 * Math.PI);
this.rotationLocked = true;
/**
* Set the camera to the left view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setLeftView() {
this.setView(0.5 * Math.PI, -0.5 * Math.PI);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the left view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setLeftView() {
this.setView(0.5 * Math.PI, -0.5 * Math.PI);
this.rotationLocked = true;
/**
* Set the camera to the front view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setFrontView() {
this.setView(0.5 * Math.PI, 2.0 * Math.PI);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the front view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setFrontView() {
this.setView(0.5 * Math.PI, 2.0 * Math.PI);
this.rotationLocked = true;
/**
* Set the camera to the back view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setBackView() {
this.setView(0.5 * Math.PI, Math.PI);
this.rotationLocked = true;
return this;
}
return this;
}
/**
* Set the camera to the back view (locks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setBackView() {
this.setView(0.5 * Math.PI, Math.PI);
this.rotationLocked = true;
/**
* Set the camera to free view (unlocks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setFreeView() {
this.setView(0.25 * Math.PI, 0.25 * Math.PI);
this.rotationLocked = false
return this;
}
return this;
}
/**
* Set the camera to free view (unlocks rotation).
*
* @returns {OrbitalControls} Returns itself.
*/
setFreeView() {
this.setView(0.25 * Math.PI, 0.25 * Math.PI);
this.rotationLocked = false;
return this;
}
}
module.exports = OrbitalControls;
module.exports = OrbitalControls;

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc