@@ -59,6 +59,9 @@ interface IProps {
59
59
const CAMERA_NEAR = 1e-6 ;
60
60
const CAMERA_FAR = 1e27 ;
61
61
62
+ // The amount of pixels a mouse move can do until we stop considering it's a click
63
+ const CLICK_THRESHOLD = 5 ;
64
+
62
65
interface IStates {
63
66
id : string ; // ID of the component, it is used to identify which component
64
67
//is the source of awareness updates.
@@ -265,13 +268,6 @@ export class MainView extends React.Component<IProps, IStates> {
265
268
'pointermove' ,
266
269
this . _onPointerMove . bind ( this )
267
270
) ;
268
- this . _renderer . domElement . addEventListener ( 'mouseup' , e => {
269
- if ( ! this . _disabledNextClick ) {
270
- this . _onClick ( e ) ;
271
- }
272
-
273
- this . _disabledNextClick = false ;
274
- } ) ;
275
271
276
272
this . _renderer . domElement . addEventListener ( 'contextmenu' , e => {
277
273
e . preventDefault ( ) ;
@@ -296,42 +292,25 @@ export class MainView extends React.Component<IProps, IStates> {
296
292
this . _controls . enableDamping = true ;
297
293
this . _controls . dampingFactor = 0.15 ;
298
294
299
- const startMousePosition = new THREE . Vector2 ( ) ;
300
- const endMousePosition = new THREE . Vector2 ( ) ;
301
- const clickThreshold = 5 ;
302
-
303
- this . _controls . addEventListener ( 'start' , ( ) => {
304
- this . _hasOrbited = false ;
305
- } ) ;
306
- this . _controls . addEventListener ( 'end' , ( ) => {
307
- // This "change" event here happens before the "mouseup" event on the renderer,
308
- // we need to disable that next "mouseup" event that's coming to not deselect
309
- // any currently selected mesh un-intentionally
310
- if ( this . _hasOrbited ) {
311
- this . _disabledNextClick = true ;
312
- }
313
- } ) ;
314
-
315
- this . _controls . addEventListener ( 'change' , ( ) => {
316
- this . _hasOrbited = true ;
317
- this . _updateAnnotation ( ) ;
318
- } ) ;
319
-
320
295
this . _renderer . domElement . addEventListener ( 'mousedown' , e => {
321
- startMousePosition . set ( e . clientX , e . clientY ) ;
296
+ this . _startMousePosition . set ( e . clientX , e . clientY ) ;
322
297
} ) ;
323
298
324
299
this . _renderer . domElement . addEventListener ( 'mouseup' , e => {
325
- endMousePosition . set ( e . clientX , e . clientY ) ;
326
- const distance = endMousePosition . distanceTo ( startMousePosition ) ;
300
+ this . _endMousePosition . set ( e . clientX , e . clientY ) ;
301
+ const distance = this . _endMousePosition . distanceTo (
302
+ this . _startMousePosition
303
+ ) ;
327
304
328
- if ( distance !== 0 && distance <= clickThreshold ) {
305
+ if ( distance <= CLICK_THRESHOLD ) {
329
306
this . _onClick ( e ) ;
330
- } else if ( this . _disabledNextClick ) {
331
- this . _disabledNextClick = false ;
332
307
}
333
308
} ) ;
334
309
310
+ this . _controls . addEventListener ( 'change' , ( ) => {
311
+ this . _updateAnnotation ( ) ;
312
+ } ) ;
313
+
335
314
this . _controls . addEventListener (
336
315
'change' ,
337
316
throttle ( ( ) => {
@@ -818,6 +797,13 @@ export class MainView extends React.Component<IProps, IStates> {
818
797
}
819
798
820
799
if ( selected ) {
800
+ const boundingBox = meshGroup ?. getObjectByName (
801
+ SELECTION_BOUNDING_BOX
802
+ ) as THREE . Mesh ;
803
+ if ( boundingBox ) {
804
+ boundingBox . visible = true ;
805
+ }
806
+
821
807
this . _selectedMeshes . push ( mainMesh ) ;
822
808
}
823
809
edgesMeshes . forEach ( el => {
@@ -857,6 +843,8 @@ export class MainView extends React.Component<IProps, IStates> {
857
843
} ) ;
858
844
this . _meshGroup ?. add ( meshGroup ) ;
859
845
}
846
+
847
+ this . _updateTransformControls ( selectedNames ) ;
860
848
} ) ;
861
849
862
850
// Update the reflength.
@@ -1132,9 +1120,6 @@ export class MainView extends React.Component<IProps, IStates> {
1132
1120
if ( material ?. linewidth ) {
1133
1121
material . linewidth = DEFAULT_LINEWIDTH ;
1134
1122
}
1135
-
1136
- // Detach TransformControls from the previous selection
1137
- this . _transformControls . detach ( ) ;
1138
1123
}
1139
1124
1140
1125
// Set new selection
@@ -1185,8 +1170,15 @@ export class MainView extends React.Component<IProps, IStates> {
1185
1170
}
1186
1171
}
1187
1172
1188
- if ( selectedNames . length === 1 ) {
1189
- const selectedMeshName = selectedNames [ 0 ] ;
1173
+ this . _updateTransformControls ( selectedNames ) ;
1174
+ }
1175
+
1176
+ /*
1177
+ * Attach the transform controls to the current selection, or detach it
1178
+ */
1179
+ private _updateTransformControls ( selection : string [ ] ) {
1180
+ if ( selection . length === 1 ) {
1181
+ const selectedMeshName = selection [ 0 ] ;
1190
1182
const matchingChild = this . _meshGroup ?. children . find ( child =>
1191
1183
child . name . startsWith ( selectedMeshName )
1192
1184
) ;
@@ -1208,8 +1200,16 @@ export class MainView extends React.Component<IProps, IStates> {
1208
1200
1209
1201
this . _transformControls . visible = true ;
1210
1202
this . _transformControls . enabled = true ;
1203
+
1204
+ return ;
1211
1205
}
1212
1206
}
1207
+
1208
+ // Detach TransformControls from the previous selection
1209
+ this . _transformControls . detach ( ) ;
1210
+
1211
+ this . _transformControls . visible = false ;
1212
+ this . _transformControls . enabled = false ;
1213
1213
}
1214
1214
1215
1215
private _onSharedMetadataChanged = (
@@ -1712,9 +1712,9 @@ export class MainView extends React.Component<IProps, IStates> {
1712
1712
private _geometry : THREE . BufferGeometry ; // Threejs BufferGeometry
1713
1713
private _refLength : number | null = null ; // Length of bounding box of current object
1714
1714
private _sceneAxe : THREE . Object3D | null ; // Array of X, Y and Z axe
1715
- private _controls : OrbitControls ; // Mouse controls
1716
- private _hasOrbited = false ; // Whether the last orbit control run has actually orbited
1717
- private _disabledNextClick = false ; // We set this when we stop orbiting, to prevent the next click event
1715
+ private _controls : OrbitControls ; // Camera controls
1716
+ private _startMousePosition = new THREE . Vector2 ( ) ; // Start mouse position when dragging the camera controls
1717
+ private _endMousePosition = new THREE . Vector2 ( ) ; // End mouse position when dragging the camera controls
1718
1718
private _clipPlaneTransformControls : TransformControls ; // Clip plane position/rotation controls
1719
1719
private _transformControls : TransformControls ; // Mesh position controls
1720
1720
private _pointer3D : IPointer | null = null ;
0 commit comments