Skip to content

Commit b4c1fd9

Browse files
Make selection logic smoother (#563)
* Try to make selection logic smoother * I was missing this * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 709c792 commit b4c1fd9

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

packages/base/src/3dview/mainview.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,10 @@ export class MainView extends React.Component<IProps, IStates> {
296296
this._controls.enableDamping = true;
297297
this._controls.dampingFactor = 0.15;
298298

299+
const startMousePosition = new THREE.Vector2();
300+
const endMousePosition = new THREE.Vector2();
301+
const clickThreshold = 5;
302+
299303
this._controls.addEventListener('start', () => {
300304
this._hasOrbited = false;
301305
});
@@ -307,10 +311,27 @@ export class MainView extends React.Component<IProps, IStates> {
307311
this._disabledNextClick = true;
308312
}
309313
});
314+
310315
this._controls.addEventListener('change', () => {
311316
this._hasOrbited = true;
312317
this._updateAnnotation();
313318
});
319+
320+
this._renderer.domElement.addEventListener('mousedown', e => {
321+
startMousePosition.set(e.clientX, e.clientY);
322+
});
323+
324+
this._renderer.domElement.addEventListener('mouseup', e => {
325+
endMousePosition.set(e.clientX, e.clientY);
326+
const distance = endMousePosition.distanceTo(startMousePosition);
327+
328+
if (distance !== 0 && distance <= clickThreshold) {
329+
this._onClick(e);
330+
} else if (this._disabledNextClick) {
331+
this._disabledNextClick = false;
332+
}
333+
});
334+
314335
this._controls.addEventListener(
315336
'change',
316337
throttle(() => {

0 commit comments

Comments
 (0)