Skip to content

Commit 3961078

Browse files
Improve selection logic (#542)
* Improve selection logic * [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 9bf440d commit 3961078

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

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

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,11 @@ export class MainView extends React.Component<IProps, IStates> {
266266
this._onPointerMove.bind(this)
267267
);
268268
this._renderer.domElement.addEventListener('mouseup', e => {
269-
this._onClick.bind(this)(e);
269+
if (!this._disabledNextClick) {
270+
this._onClick(e);
271+
}
272+
273+
this._disabledNextClick = false;
270274
});
271275

272276
this._renderer.domElement.addEventListener('contextmenu', e => {
@@ -276,24 +280,35 @@ export class MainView extends React.Component<IProps, IStates> {
276280
});
277281

278282
document.addEventListener('keydown', e => {
279-
this._onKeyDown.bind(this)(e);
283+
this._onKeyDown(e);
280284
});
281285

282-
const controls = new OrbitControls(
286+
this._controls = new OrbitControls(
283287
this._camera,
284288
this._renderer.domElement
285289
);
286290

287-
controls.target.set(
291+
this._controls.target.set(
288292
this._scene.position.x,
289293
this._scene.position.y,
290294
this._scene.position.z
291295
);
292-
this._controls = controls;
293-
controls.enableDamping = true;
294-
controls.dampingFactor = 0.15;
296+
this._controls.enableDamping = true;
297+
this._controls.dampingFactor = 0.15;
295298

299+
this._controls.addEventListener('start', () => {
300+
this._hasOrbited = false;
301+
});
302+
this._controls.addEventListener('end', () => {
303+
// This "change" event here happens before the "mouseup" event on the renderer,
304+
// we need to disable that next "mouseup" event that's coming to not deselect
305+
// any currently selected mesh un-intentionally
306+
if (this._hasOrbited) {
307+
this._disabledNextClick = true;
308+
}
309+
});
296310
this._controls.addEventListener('change', () => {
311+
this._hasOrbited = true;
297312
this._updateAnnotation();
298313
});
299314
this._controls.addEventListener(
@@ -644,6 +659,9 @@ export class MainView extends React.Component<IProps, IStates> {
644659
}
645660
this._updateSelected(newSelection);
646661
this._model.syncSelected(newSelection, this._mainViewModel.id);
662+
} else {
663+
this._updateSelected({});
664+
this._model.syncSelected({}, this._mainViewModel.id);
647665
}
648666
}
649667

@@ -1575,6 +1593,8 @@ export class MainView extends React.Component<IProps, IStates> {
15751593
private _refLength: number | null = null; // Length of bounding box of current object
15761594
private _sceneAxe: THREE.Object3D | null; // Array of X, Y and Z axe
15771595
private _controls: OrbitControls; // Mouse controls
1596+
private _hasOrbited = false; // Whether the last orbit control run has actually orbited
1597+
private _disabledNextClick = false; // We set this when we stop orbiting, to prevent the next click event
15781598
private _transformControls: TransformControls; // Mesh position/rotation controls
15791599
private _pointer3D: IPointer | null = null;
15801600
private _clock: THREE.Clock;

0 commit comments

Comments
 (0)