Skip to content

Commit d2b2082

Browse files
authored
F/update emit points (#1)
* updated emit points * built files * Fix issue
1 parent 33f6998 commit d2b2082

4 files changed

+95
-62
lines changed

dist/aframe-orbit-controls-component.js

+31-20
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,9 @@
158158
this.object = this.el.object3D;
159159
this.target = this.sceneEl.querySelector(this.data.target).object3D.position;
160160

161-
console.log('enabled: ', this.data.enabled);
161+
// console.log('enabled: ', this.data.enabled);
162+
this.endFlag = false;
163+
this.startFlag = false;
162164

163165
// Find the look-controls component on this camera, or create if it doesn't exist.
164166
this.isRunning = false;
@@ -241,7 +243,7 @@
241243
* Generally modifies the entity based on the data.
242244
*/
243245
update: function (oldData) {
244-
console.log('component update');
246+
// console.log('component update');
245247

246248
if (this.data.rotateTo) {
247249
var rotateToVec3 = new THREE.Vector3(this.data.rotateTo.x, this.data.rotateTo.y, this.data.rotateTo.z);
@@ -313,7 +315,7 @@
313315
*/
314316
pause: function () {
315317
// console.log("component pause");
316-
this.isRunning = false;
318+
this.isRunning = false;
317319
this.removeEventListeners();
318320
},
319321

@@ -393,20 +395,19 @@
393395
* Remove event listeners
394396
*/
395397
removeEventListeners: function () {
396-
397-
if(this.canvasEl){
398-
this.canvasEl.removeEventListener('contextmenu', this.onContextMenu, false);
399-
this.canvasEl.removeEventListener('mousedown', this.onMouseDown, false);
400-
this.canvasEl.removeEventListener('mousewheel', this.onMouseWheel, false);
401-
this.canvasEl.removeEventListener('MozMousePixelScroll', this.onMouseWheel, false); // firefox
402-
403-
this.canvasEl.removeEventListener('touchstart', this.onTouchStart, false);
404-
this.canvasEl.removeEventListener('touchend', this.onTouchEnd, false);
405-
this.canvasEl.removeEventListener('touchmove', this.onTouchMove, false);
406-
407-
this.canvasEl.removeEventListener('mousemove', this.onMouseMove, false);
408-
this.canvasEl.removeEventListener('mouseup', this.onMouseUp, false);
409-
this.canvasEl.removeEventListener('mouseout', this.onMouseUp, false);
398+
if (this.canvasEl) {
399+
this.canvasEl.removeEventListener('contextmenu', this.onContextMenu, false);
400+
this.canvasEl.removeEventListener('mousedown', this.onMouseDown, false);
401+
this.canvasEl.removeEventListener('mousewheel', this.onMouseWheel, false);
402+
this.canvasEl.removeEventListener('MozMousePixelScroll', this.onMouseWheel, false); // firefox
403+
404+
this.canvasEl.removeEventListener('touchstart', this.onTouchStart, false);
405+
this.canvasEl.removeEventListener('touchend', this.onTouchEnd, false);
406+
this.canvasEl.removeEventListener('touchmove', this.onTouchMove, false);
407+
408+
this.canvasEl.removeEventListener('mousemove', this.onMouseMove, false);
409+
this.canvasEl.removeEventListener('mouseup', this.onMouseUp, false);
410+
this.canvasEl.removeEventListener('mouseout', this.onMouseUp, false);
410411
}
411412

412413
window.removeEventListener('keydown', this.onKeyDown, false);
@@ -499,7 +500,7 @@
499500

500501
this.state = this.STATE.NONE;
501502

502-
this.el.emit('end-drag-orbit-controls', null, false);
503+
this.startFlag = true;
503504
},
504505

505506
/*
@@ -940,7 +941,7 @@
940941
var thetaDiff = desiredSpherical.theta - this.spherical.theta;
941942
this.sphericalDelta.set(this.spherical.radius, phiDiff * this.data.rotateToSpeed, thetaDiff * this.data.rotateToSpeed);
942943
}
943-
944+
// console.log("updating");
944945
var offset = new THREE.Vector3();
945946

946947
var quat = new THREE.Quaternion().setFromUnitVectors(this.dolly.up, new THREE.Vector3(0, 1, 0)); // so camera.up is the orbit axis
@@ -974,6 +975,7 @@
974975
if (this.data.enableDamping === true) {
975976
this.sphericalDelta.theta *= (1 - this.data.dampingFactor);
976977
this.sphericalDelta.phi *= (1 - this.data.dampingFactor);
978+
// console.log(this.sphericalDelta);
977979
} else {
978980
this.sphericalDelta.set(0, 0, 0);
979981
}
@@ -985,12 +987,14 @@
985987
// min(camera displacement, camera rotation in radians)^2 > EPS
986988
// using small-angle approximation cos(x/2) = 1 - x^2 / 8
987989

990+
this.endFlag = true;
991+
988992
if (forceUpdate === true ||
989993
this.zoomChanged ||
990994
this.lastPosition.distanceToSquared(this.dolly.position) > this.EPS ||
991995
8 * (1 - this.lastQuaternion.dot(this.dolly.quaternion)) > this.EPS) {
992996
// this.el.emit('change-drag-orbit-controls', null, false);
993-
997+
// console.log("updating");
994998
var hmdQuaternion = this.calculateHMDQuaternion();
995999
var hmdEuler = new THREE.Euler();
9961000
hmdEuler.setFromQuaternion(hmdQuaternion, 'YXZ');
@@ -1007,6 +1011,8 @@
10071011
z: radToDeg(hmdEuler.z)
10081012
});
10091013

1014+
this.endFlag = false;
1015+
10101016
this.lastPosition.copy(this.dolly.position);
10111017
this.lastQuaternion.copy(this.dolly.quaternion);
10121018

@@ -1015,6 +1021,11 @@
10151021
return true;
10161022
}
10171023

1024+
if (this.startFlag && this.endFlag) {
1025+
this.startFlag = false;
1026+
this.el.emit('end-drag-orbit-controls', null, false);
1027+
}
1028+
10181029
return false;
10191030
},
10201031

0 commit comments

Comments
 (0)