@@ -38,9 +38,6 @@ const PERSP_CAMERA_FOV_VERTICAL = 70;
38
38
const PERSP_CAMERA_NEAR_CLIP_PLANE = 0.01 ;
39
39
const PERSP_CAMERA_FAR_CLIP_PLANE = 100 ;
40
40
const ORTHO_CAMERA_FRUSTUM_HALF_EXTENT = 1.2 ;
41
- // Key presses.
42
- const SHIFT_KEY = 16 ;
43
- const CTRL_KEY = 17 ;
44
41
const ORBIT_MOUSE_ROTATION_SPEED = 1 ;
45
42
const ORBIT_ANIMATION_ROTATION_CYCLE_IN_SECONDS = 7 ;
46
43
export type OnCameraMoveListener = (
@@ -85,7 +82,7 @@ export class ScatterPlot {
85
82
private cameraDef : CameraDef | null = null ;
86
83
private camera : THREE . Camera ;
87
84
private orbitAnimationOnNextCameraCreation : boolean = false ;
88
- private orbitCameraControls : any ;
85
+ private orbitCameraControls : OrbitControls ;
89
86
private orbitAnimationId : number | null ;
90
87
private worldSpacePointPositions : Float32Array ;
91
88
private pointColors : Float32Array ;
@@ -133,7 +130,7 @@ export class ScatterPlot {
133
130
window . addEventListener ( 'keydown' , this . onKeyDown . bind ( this ) , false ) ;
134
131
window . addEventListener ( 'keyup' , this . onKeyUp . bind ( this ) , false ) ;
135
132
}
136
- private addCameraControlsEventListeners ( cameraControls : any ) {
133
+ private addCameraControlsEventListeners ( cameraControls : OrbitControls ) {
137
134
// Start is called when the user stars interacting with
138
135
// controls.
139
136
cameraControls . addEventListener ( 'start' , ( ) => {
@@ -158,7 +155,7 @@ export class ScatterPlot {
158
155
if ( this . orbitCameraControls != null ) {
159
156
this . orbitCameraControls . dispose ( ) ;
160
157
}
161
- const occ = new OrbitControls ( camera , this . renderer . domElement ) as any ;
158
+ const occ = new OrbitControls ( camera , this . renderer . domElement ) ;
162
159
occ . target0 = new THREE . Vector3 (
163
160
cameraDef . target [ 0 ] ,
164
161
cameraDef . target [ 1 ] ,
@@ -170,11 +167,11 @@ export class ScatterPlot {
170
167
occ . autoRotate = false ;
171
168
occ . rotateSpeed = ORBIT_MOUSE_ROTATION_SPEED ;
172
169
if ( cameraIs3D ) {
173
- occ . mouseButtons . ORBIT = THREE . MOUSE . LEFT ;
174
- occ . mouseButtons . PAN = THREE . MOUSE . RIGHT ;
170
+ occ . mouseButtons . LEFT = THREE . MOUSE . ROTATE ;
171
+ occ . mouseButtons . RIGHT = THREE . MOUSE . PAN ;
175
172
} else {
176
- occ . mouseButtons . ORBIT = null ;
177
- occ . mouseButtons . PAN = THREE . MOUSE . LEFT ;
173
+ occ . mouseButtons . RIGHT = null ;
174
+ occ . mouseButtons . LEFT = THREE . MOUSE . PAN ;
178
175
}
179
176
occ . reset ( ) ;
180
177
this . camera = camera ;
@@ -312,28 +309,10 @@ export class ScatterPlot {
312
309
this . orbitCameraControls . enabled = false ;
313
310
this . rectangleSelector . onMouseDown ( e . offsetX , e . offsetY ) ;
314
311
this . setNearestPointToMouse ( e ) ;
315
- } else if (
316
- ! e . ctrlKey &&
317
- this . sceneIs3D ( ) &&
318
- this . orbitCameraControls . mouseButtons . ORBIT === THREE . MOUSE . RIGHT
319
- ) {
320
- // The user happened to press the ctrl key when the tab was active,
321
- // unpressed the ctrl when the tab was inactive, and now he/she
322
- // is back to the projector tab.
323
- this . orbitCameraControls . mouseButtons . ORBIT = THREE . MOUSE . LEFT ;
324
- this . orbitCameraControls . mouseButtons . PAN = THREE . MOUSE . RIGHT ;
325
- } else if (
326
- e . ctrlKey &&
327
- this . sceneIs3D ( ) &&
328
- this . orbitCameraControls . mouseButtons . ORBIT === THREE . MOUSE . LEFT
329
- ) {
330
- // Similarly to the situation above.
331
- this . orbitCameraControls . mouseButtons . ORBIT = THREE . MOUSE . RIGHT ;
332
- this . orbitCameraControls . mouseButtons . PAN = THREE . MOUSE . LEFT ;
333
312
}
334
313
}
335
314
/** When we stop dragging/zooming, return to normal behavior. */
336
- private onMouseUp ( e : any ) {
315
+ private onMouseUp ( e : MouseEvent ) {
337
316
if ( this . selecting ) {
338
317
this . orbitCameraControls . enabled = true ;
339
318
this . rectangleSelector . onMouseUp ( ) ;
@@ -356,27 +335,18 @@ export class ScatterPlot {
356
335
this . projectorEventContext . notifyHoverOverPoint ( this . nearestPoint ! ) ;
357
336
}
358
337
}
359
- /** For using ctrl + left click as right click, and for circle select */
360
- private onKeyDown ( e : any ) {
361
- // If ctrl is pressed, use left click to orbit
362
- if ( e . keyCode === CTRL_KEY && this . sceneIs3D ( ) ) {
363
- this . orbitCameraControls . mouseButtons . ORBIT = THREE . MOUSE . RIGHT ;
364
- this . orbitCameraControls . mouseButtons . PAN = THREE . MOUSE . LEFT ;
365
- }
338
+ /** For for circle select */
339
+ private onKeyDown ( e : KeyboardEvent ) {
366
340
// If shift is pressed, start selecting
367
- if ( e . keyCode === SHIFT_KEY ) {
341
+ if ( e . shiftKey ) {
368
342
this . selecting = true ;
369
343
this . container . style . cursor = 'crosshair' ;
370
344
}
371
345
}
372
- /** For using ctrl + left click as right click, and for circle select */
373
- private onKeyUp ( e : any ) {
374
- if ( e . keyCode === CTRL_KEY && this . sceneIs3D ( ) ) {
375
- this . orbitCameraControls . mouseButtons . ORBIT = THREE . MOUSE . LEFT ;
376
- this . orbitCameraControls . mouseButtons . PAN = THREE . MOUSE . RIGHT ;
377
- }
346
+ /** For for circle select */
347
+ private onKeyUp ( e : KeyboardEvent ) {
378
348
// If shift is released, stop selecting
379
- if ( e . keyCode === SHIFT_KEY ) {
349
+ if ( e . shiftKey ) {
380
350
this . selecting = this . getMouseMode ( ) === MouseMode . AREA_SELECT ;
381
351
if ( ! this . selecting ) {
382
352
this . container . style . cursor = 'default' ;
@@ -468,7 +438,7 @@ export class ScatterPlot {
468
438
return axes ;
469
439
}
470
440
private add3dAxis ( ) {
471
- const axes = new ( THREE as any ) . AxesHelper ( ) ;
441
+ const axes = new THREE . AxesHelper ( ) ;
472
442
axes . name = 'axes' ;
473
443
this . scene . add ( axes ) ;
474
444
}
@@ -493,7 +463,7 @@ export class ScatterPlot {
493
463
def . orthographic = ! this . sceneIs3D ( ) ;
494
464
def . position = [ pos . x , pos . y , pos . z ] ;
495
465
def . target = [ tgt . x , tgt . y , tgt . z ] ;
496
- def . zoom = ( this . camera as any ) . zoom ;
466
+ def . zoom = this . camera . zoom ;
497
467
return def ;
498
468
}
499
469
/** Sets parameters for the next camera recreation. */
@@ -705,7 +675,7 @@ export class ScatterPlot {
705
675
const renderCanvasSize = new THREE . Vector2 ( ) ;
706
676
// TODO(stephanwlee): Remove casting to any after three.js typing is
707
677
// proper.
708
- ( this . renderer as any ) . getSize ( renderCanvasSize ) ;
678
+ this . renderer . getSize ( renderCanvasSize ) ;
709
679
const pixelRatio = this . renderer . getPixelRatio ( ) ;
710
680
this . pickingTexture = new THREE . WebGLRenderTarget (
711
681
renderCanvasSize . width * pixelRatio ,
0 commit comments