From 2379a50af88dd2e7ad48b0e9ee3820e471b7fe64 Mon Sep 17 00:00:00 2001 From: clairebb1005 Date: Wed, 30 Jun 2021 14:22:30 +0200 Subject: [PATCH] add restriction for moving --- src/js/viewer/ViewerPanoAPI.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/js/viewer/ViewerPanoAPI.js b/src/js/viewer/ViewerPanoAPI.js index f278a88..ca48555 100644 --- a/src/js/viewer/ViewerPanoAPI.js +++ b/src/js/viewer/ViewerPanoAPI.js @@ -218,6 +218,11 @@ export class ViewerPanoAPI { } onMouseMove(event){ + // get depth data + const raycaster = this.getRaycaster(event); + const distance = this.depthAtPointer(event); + const cursorLocation = raycaster.ray.origin.addScaledVector(raycaster.ray.direction, distance); + // get cursor data const currentPos = this.viewerAPI.image.currentImage.pos; const newLocalPos = this.getCursorLocation(event); @@ -236,10 +241,20 @@ export class ViewerPanoAPI { } }); + // limit distance to current mesh + const bestLocalPos = this.viewerAPI.toLocal(this.bestImg.pos); + const [dx, dy] = [this.camera.position.x - bestLocalPos.x, this.camera.position.y - bestLocalPos.y]; + const currDistance = Math.sqrt(dx * dx + dy * dy); + const [deepx, deepy] = [this.camera.position.x - cursorLocation.x, this.camera.position.y - cursorLocation.y] + const currDeepDistance = Math.sqrt(deepx * deepx + deepy * deepy); + + // difference between "camera to img" and "camera to raycaster" + const diff = Math.abs(currDistance-currDeepDistance) + // avoid duplication - // if the nearest image of mouse position is not the same as the previous one + // if the nearest image of mouse position is not the same as the previous one, and the diff is smaller than 1 // create new mesh and remove old mesh, and save latest mesh and image - if (this.bestImg != this.lastBestImg) { + if (this.bestImg != this.lastBestImg && diff < 1) { var x = 0, y = 0, z = -2 // clickable meshes are the bestImg