Skip to content

Commit 29c43fa

Browse files
committed
Solving bug of unintentionally highlighting when navigating
1 parent 5c7b64e commit 29c43fa

File tree

4 files changed

+103
-18
lines changed

4 files changed

+103
-18
lines changed

source/engine/viewer/navigation.js

+20-1
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,12 @@ export class Navigation
249249
this.clickDetector = new ClickDetector ();
250250

251251
this.onMouseClick = null;
252-
this.onMouseMove = null;
252+
this.onMouseMove = callbacks.onMouseMove || null;
253253
this.onContext = null;
254254

255+
this.onMouseDown = callbacks.onMouseDown || null;
256+
this.onMouseUp = callbacks.onMouseUp || null;
257+
255258
if (this.canvas.addEventListener) {
256259
this.canvas.addEventListener ('mousedown', this.OnMouseDown.bind (this));
257260
this.canvas.addEventListener ('wheel', this.OnMouseWheel.bind (this));
@@ -266,6 +269,7 @@ export class Navigation
266269
document.addEventListener ('mouseup', this.OnMouseUp.bind (this));
267270
document.addEventListener ('mouseleave', this.OnMouseLeave.bind (this));
268271
}
272+
269273
}
270274

271275
SetMouseClickHandler (onMouseClick)
@@ -378,6 +382,11 @@ export class Navigation
378382
if (!this.enableCameraMovement) {
379383
this.isMouseDown = true;
380384
}
385+
386+
if (this.onMouseDown) {
387+
let mouseCoords = this.mouse.GetPosition();
388+
this.onMouseDown(mouseCoords);
389+
}
381390
}
382391

383392
OnMouseMove (ev)
@@ -397,6 +406,11 @@ export class Navigation
397406
return;
398407
}
399408

409+
if (this.onMouseMove) {
410+
let mouseCoords = this.mouse.GetPosition();
411+
this.onMouseMove(mouseCoords);
412+
}
413+
400414
let moveDiff = this.mouse.GetMoveDiff ();
401415
let mouseButton = this.mouse.GetButton ();
402416
let navigationType = NavigationType.None;
@@ -440,6 +454,11 @@ export class Navigation
440454
if (!this.enableCameraMovement) {
441455
this.isMouseDown = false;
442456
}
457+
458+
if (this.onMouseUp) {
459+
let mouseCoords = this.mouse.GetPosition();
460+
this.onMouseUp(mouseCoords);
461+
}
443462
}
444463

445464
OnMouseLeave (ev)

source/engine/viewer/viewer.js

+32-3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,8 @@ export class Viewer
175175
this.settings = {
176176
animationSteps : 40
177177
};
178+
this.isNavigating = false;
179+
178180
}
179181

180182
Init (canvas)
@@ -211,6 +213,18 @@ export class Viewer
211213
this.navigation.SetMouseClickHandler (onMouseClick);
212214
}
213215

216+
SetMouseDownHandler(handler) {
217+
if (this.navigation) {
218+
this.navigation.onMouseDown = handler;
219+
}
220+
}
221+
222+
SetMouseUpHandler(handler) {
223+
if (this.navigation) {
224+
this.navigation.onMouseUp = handler;
225+
}
226+
}
227+
214228
SetMouseMoveHandler (onMouseMove)
215229
{
216230
this.navigation.SetMouseMoveHandler (onMouseMove);
@@ -544,9 +558,24 @@ export class Viewer
544558
this.scene.add (this.camera);
545559

546560
let canvasElem = this.renderer.domElement;
547-
this.navigation = new Navigation (canvasElem, camera, {
548-
onUpdate : () => {
549-
this.Render ();
561+
this.navigation = new Navigation(canvasElem, camera, {
562+
onUpdate: () => {
563+
this.Render();
564+
},
565+
onMouseDown: (mouseCoordinates) => {
566+
if (this.mouseDownHandler) {
567+
this.mouseDownHandler(mouseCoordinates);
568+
}
569+
},
570+
onMouseMove: (mouseCoordinates) => {
571+
if (this.mouseMoveHandler) {
572+
this.mouseMoveHandler(mouseCoordinates);
573+
}
574+
},
575+
onMouseUp: (mouseCoordinates) => {
576+
if (this.mouseUpHandler) {
577+
this.mouseUpHandler(mouseCoordinates);
578+
}
550579
}
551580
});
552581

source/engine/viewer/viewermodel.js

+16
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ export class ViewerMainModel
145145
this.edgeSettings = new EdgeSettings (false, new RGBColor (0, 0, 0), 1);
146146
this.hasLines = false;
147147
this.hasPolygonOffset = false;
148+
149+
this.mouseDownHandler = null;
150+
this.mouseMoveHandler = null;
151+
this.mouseUpHandler = null;
152+
}
153+
154+
SetMouseDownHandler(handler) {
155+
this.mouseDownHandler = handler;
156+
}
157+
158+
SetMouseMoveHandler(handler) {
159+
this.mouseMoveHandler = handler;
160+
}
161+
162+
SetMouseUpHandler(handler) {
163+
this.mouseUpHandler = handler;
148164
}
149165

150166
SetMainObject (mainObject)

source/website/website.js

+35-14
Original file line numberDiff line numberDiff line change
@@ -382,20 +382,6 @@ export class Website
382382
}
383383
}
384384

385-
OnModelMouseMove(mouseCoordinates) {
386-
if (this.highlightTool.IsActive()) {
387-
let meshUserData = this.viewer.GetMeshUserDataUnderMouse(IntersectionMode.MeshAndLine, mouseCoordinates);
388-
if (meshUserData === null) {
389-
// No intersection with model, allow navigation
390-
this.viewer.navigation.EnableCameraMovement(true);
391-
} else {
392-
// Intersection with model, use highlight tool
393-
this.highlightTool.MouseMove(mouseCoordinates);
394-
this.viewer.navigation.EnableCameraMovement(false);
395-
}
396-
}
397-
}
398-
399385
OnModelContextMenu (globalMouseCoordinates, mouseCoordinates)
400386
{
401387
if (this.highlightTool.IsActive()) {
@@ -681,6 +667,41 @@ export class Website
681667
ShowSharingDialog(this.settings, this.viewer);
682668
});
683669

670+
this.viewer.SetMouseDownHandler(this.OnModelMouseDown.bind(this));
671+
this.viewer.SetMouseMoveHandler(this.OnModelMouseMove.bind(this));
672+
this.viewer.SetMouseUpHandler(this.OnModelMouseUp.bind(this));
673+
674+
}
675+
OnModelMouseDown(mouseCoordinates) {
676+
if (this.highlightTool.IsActive()) {
677+
let meshUserData = this.viewer.GetMeshUserDataUnderMouse(IntersectionMode.MeshAndLine, mouseCoordinates);
678+
if (meshUserData === null) {
679+
// No intersection with model, allow navigation
680+
this.viewer.navigation.EnableCameraMovement(true);
681+
this.isNavigating = true;
682+
} else {
683+
// Intersection with model, use highlight tool
684+
this.viewer.navigation.EnableCameraMovement(false);
685+
}
686+
}
687+
}
688+
689+
OnModelMouseMove(mouseCoordinates) {
690+
if (this.highlightTool.IsActive() && !this.isNavigating) {
691+
let meshUserData = this.viewer.GetMeshUserDataUnderMouse(IntersectionMode.MeshAndLine, mouseCoordinates);
692+
if (meshUserData !== null) {
693+
this.highlightTool.MouseMove(mouseCoordinates);
694+
}
695+
}
696+
}
697+
698+
OnModelMouseUp(mouseCoordinates) {
699+
if (this.highlightTool.IsActive()) {
700+
if (!this.isNavigating) {
701+
this.highlightTool.Click(mouseCoordinates);
702+
}
703+
this.isNavigating = false;
704+
}
684705
}
685706

686707
InitToolbar ()

0 commit comments

Comments
 (0)