Socket
Socket
Sign inDemoInstall

three-pointer-controls

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

three-pointer-controls - npm Package Compare versions

Comparing version 0.4.0 to 0.5.0

lib/devices/Mouse.js

107

lib/controls.js
// Generated by CoffeeScript 1.9.2
(function() {
var Animation, BUTTON, Dolly, KEY, Orbit, Pan, STATE, UP, addWheelListener, clone, defaults, preventDefault, ref, registerEventListeners,
var Animation, BUTTON, Dolly, KEY, Mouse, Orbit, Pan, STATE, Touch, UP, addWheelListener, clone, defaults, preventDefault, ref, registerEventListeners,
bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };

@@ -22,2 +22,6 @@

Mouse = require('./devices/Mouse');
Touch = require('./devices/Touch');
UP = {

@@ -38,2 +42,4 @@ x: 0,

this.setHome = bind(this.setHome, this);
this.endInteraction = bind(this.endInteraction, this);
this.startInteraction = bind(this.startInteraction, this);
this.onMouseWheel = bind(this.onMouseWheel, this);

@@ -43,2 +49,3 @@ this.onPointerUp = bind(this.onPointerUp, this);

this.onPointerDown = bind(this.onPointerDown, this);
this.getDeviceFor = bind(this.getDeviceFor, this);
this.listenTo = bind(this.listenTo, this);

@@ -82,3 +89,15 @@ this.control = bind(this.control, this);

PointerControls.prototype.getDeviceFor = function(event) {
switch (event.pointerType) {
case 'touch':
return Touch;
case 'mouse':
return Mouse;
case 'pen':
return Mouse;
}
};
PointerControls.prototype.onPointerDown = function(event) {
var Device;
if (!this.config.enabled) {

@@ -88,68 +107,24 @@ return;

preventDefault(event);
switch (event.buttons) {
case this.config.pan.button:
if (!this.config.pan.enabled) {
return;
}
this.state = STATE.PAN;
this.start.set(event.clientX, event.clientY);
break;
case this.config.dolly.button:
if (!this.config.dolly.enabled) {
return;
}
this.state = STATE.DOLLY;
this.start.set(event.clientX, event.clientY);
break;
case this.config.orbit.button:
if (!this.config.orbit.enabled) {
return;
}
this.state = STATE.ORBIT;
this.start.set(event.clientX, event.clientY);
break;
default:
return;
}
this.animation.setStatus(this.config.animation.onInteraction);
this.element = event.target;
document.addEventListener('pointermove', this.onPointerMove);
document.addEventListener('pointerup', this.onPointerUp);
Device = this.getDeviceFor(event);
Device.onPointerDown.call(this, event);
};
PointerControls.prototype.onPointerMove = function(event) {
var Device;
if (!this.config.enabled) {
return;
}
preventDefault(event);
switch (this.state) {
case STATE.PAN:
this.end.set(event.clientX, event.clientY);
this.delta.subVectors(this.end, this.start);
this.pan.panBy(this.delta);
this.start.copy(this.end);
break;
case STATE.DOLLY:
this.end.set(event.clientX, event.clientY);
this.delta.subVectors(this.end, this.start);
this.dolly.dollyBy(this.delta);
this.start.copy(this.end);
break;
case STATE.ORBIT:
this.end.set(event.clientX, event.clientY);
this.delta.subVectors(this.end, this.start);
this.orbit.orbitBy(this.delta);
this.start.copy(this.end);
break;
default:
return;
}
this.animation.setStatus(this.config.animation.onInteraction);
this.update();
Device = this.getDeviceFor(event);
Device.onPointerMove.call(this, event);
};
PointerControls.prototype.onPointerUp = function(event) {
var Device;
if (!this.config.enabled) {
return;
}
preventDefault(event);
this.animation.setStatus(this.config.animation.onInteraction);
document.removeEventListener('pointermove', this.onPointerMove);
document.removeEventListener('pointerup', this.onPointerUp);
this.element = void 0;
this.state = STATE.NONE;
Device = this.getDeviceFor(event);
Device.onPointerUp.call(this, event);
};

@@ -163,2 +138,16 @@

PointerControls.prototype.startInteraction = function(event) {
this.animation.setStatus(this.config.animation.onInteraction);
this.element = event.target;
document.addEventListener('pointermove', this.onPointerMove);
document.addEventListener('pointerup', this.onPointerUp);
};
PointerControls.prototype.endInteraction = function(event) {
this.animation.setStatus(this.config.animation.afterInteraction);
this.element = void 0;
document.removeEventListener('pointermove', this.onPointerMove);
document.removeEventListener('pointerup', this.onPointerUp);
};
PointerControls.prototype.setHome = function(arg) {

@@ -165,0 +154,0 @@ var position, target, up;

@@ -12,2 +12,6 @@ // Generated by CoffeeScript 1.9.2

button: BUTTON.MIDDLE,
touchPoints: {
min: 2,
max: 2
},
scale: 1.0,

@@ -21,2 +25,6 @@ scrollScale: 0.95,

button: BUTTON.LEFT,
touchPoints: {
min: 1,
max: 1
},
speed: 1.0,

@@ -31,2 +39,6 @@ minYaw: -Infinity,

button: BUTTON.RIGHT,
touchPoints: {
min: 3,
max: 10
},
key: {

@@ -43,2 +55,3 @@ left: KEY.LEFT,

onInteraction: ANIMATION.STOP,
afterInteraction: ANIMATION.STOP,
loop: true

@@ -45,0 +58,0 @@ }

@@ -5,3 +5,3 @@ {

"license": "MIT",
"version": "0.4.0",
"version": "0.5.0",
"main": "./lib/controls.js",

@@ -8,0 +8,0 @@ "scripts": {

@@ -1,2 +0,2 @@

// Generated by CoffeeScript 1.9.2
// Generated by CoffeeScript 1.9.3
(function() {

@@ -45,2 +45,3 @@ var PointerControls, THREE, addAxis, addCube, buildCanvasApp, camera, controls, render, renderer, resize, scene, start;

start = function(gl, width, height) {
gl.canvas.setAttribute('touch-action', 'none');
renderer = new THREE.WebGLRenderer({

@@ -47,0 +48,0 @@ canvas: gl.canvas

Sorry, the diff of this file is not supported yet

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc