From a790b16638a525c9383a8c6234d0ddc9d17923a4 Mon Sep 17 00:00:00 2001 From: flyandi Date: Thu, 18 Feb 2021 23:29:56 -0800 Subject: [PATCH] Adds position debug via event --- src/viewer/Viewer.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/viewer/Viewer.js b/src/viewer/Viewer.js index 664183a7..6e475bcd 100644 --- a/src/viewer/Viewer.js +++ b/src/viewer/Viewer.js @@ -34,7 +34,7 @@ import TWEEN from '@tweenjs/tween.js'; * @param {boolean} [options.autoReticleSelect=true] - Auto select a clickable target after dwellTime * @param {boolean} [options.viewIndicator=false] - Adds an angle view indicator in upper left corner * @param {number} [options.indicatorSize=30] - Size of View Indicator - * @param {string} [options.output='none'] - Whether and where to output raycast position. Could be 'console' or 'overlay' + * @param {string} [options.output='none'] - Whether and where to output raycast position. Could be 'event', 'console' or 'overlay'. * @param {boolean} [options.autoRotate=false] - Auto rotate * @param {number} [options.autoRotateSpeed=2.0] - Auto rotate speed as in degree per second. Positive is counter-clockwise and negative is clockwise. * @param {number} [options.autoRotateActivationDuration=5000] - Duration before auto rotatation when no user interactivity in ms @@ -1306,12 +1306,22 @@ Viewer.prototype = Object.assign( Object.create( THREE.EventDispatcher.prototype const world = this.panorama.getWorldPosition( new THREE.Vector3() ); point.sub( world ).multiply( converter ); - const message = `${point.x.toFixed(2)}, ${point.y.toFixed(2)}, ${point.z.toFixed(2)}`; + const position = { + x: point.x.toFixed(2), + y: point.y.toFixed(2), + z: point.z.toFixed(2), + }; + + const message = `${position.x}, ${position.y}, ${position.z}`; if ( point.length() === 0 ) { return; } switch ( this.options.output ) { + case 'event': + this.dispatchEvent( { type: 'position-update', position: position } ); + break; + case 'console': console.info( message ); break;