Skip to content

Commit a7ed16e

Browse files
s-rigaudSamuel Rigaud
andauthored
Improve ArcballControls internal documentation (mrdoob#30372)
Co-authored-by: Samuel Rigaud <[email protected]>
1 parent 806d427 commit a7ed16e

File tree

1 file changed

+23
-21
lines changed

1 file changed

+23
-21
lines changed

examples/jsm/controls/ArcballControls.js

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,18 @@ const _offset = new Vector3();
7070
const _gizmoMatrixStateTemp = new Matrix4();
7171
const _cameraMatrixStateTemp = new Matrix4();
7272
const _scalePointTemp = new Vector3();
73-
/**
74-
*
75-
* @param {Camera} camera Virtual camera used in the scene
76-
* @param {HTMLElement} domElement Renderer's dom element
77-
* @param {Scene} scene The scene to be rendered
78-
*/
73+
74+
const _EPS = 0.000001;
75+
76+
7977
class ArcballControls extends Controls {
8078

79+
/**
80+
*
81+
* @param {Camera} camera Virtual camera used in the scene
82+
* @param {HTMLElement?} [domElement=null] Renderer's dom element
83+
* @param {Scene?} [scene=null] The scene to be rendered
84+
*/
8185
constructor( camera, domElement = null, scene = null ) {
8286

8387
super( camera, domElement );
@@ -1100,9 +1104,9 @@ class ArcballControls extends Controls {
11001104

11011105
/**
11021106
* Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one
1103-
* @param {String} operation The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV)
1104-
* @param {*} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1105-
* @param {*} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1107+
* @param {'PAN'|'ROTATE'|'ZOOM'|'FOV'} operation The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV')
1108+
* @param {0|1|2|'WHEEL'} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1109+
* @param {'CTRL'|'SHIFT'|null} [key=null] The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
11061110
* @returns {Boolean} True if the mouse action has been successfully added, false otherwise
11071111
*/
11081112
setMouseAction( operation, mouse, key = null ) {
@@ -1181,8 +1185,8 @@ class ArcballControls extends Controls {
11811185

11821186
/**
11831187
* Remove a mouse action by specifying its mouse/key combination
1184-
* @param {*} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1185-
* @param {*} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1188+
* @param {0|1|2|'WHEEL'} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1189+
* @param {'CTRL'|'SHIFT'|null} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
11861190
* @returns {Boolean} True if the operation has been successfully removed, false otherwise
11871191
*/
11881192
unsetMouseAction( mouse, key = null ) {
@@ -1206,7 +1210,7 @@ class ArcballControls extends Controls {
12061210
* Return the operation associated to a mouse/keyboard combination
12071211
* @param {0|1|2|'WHEEL'} mouse Mouse button index (0, 1, 2) or 'WHEEL' for wheel notches
12081212
* @param {'CTRL'|'SHIFT'|null} key Keyboard modifier
1209-
* @returns {string|null} The operation if it has been found, null otherwise
1213+
* @returns {'PAN'|'ROTATE'|'ZOOM'|'FOV'|null} The operation if it has been found, null otherwise
12101214
*/
12111215
getOpFromAction( mouse, key ) {
12121216

@@ -1246,7 +1250,7 @@ class ArcballControls extends Controls {
12461250
* Get the operation associated to mouse and key combination and returns the corresponding FSA state
12471251
* @param {0|1|2} mouse Mouse button index (0, 1, 2)
12481252
* @param {'CTRL'|'SHIFT'|null} key Keyboard modifier
1249-
* @returns {STATE|null} The FSA state obtained from the operation associated to mouse/keyboard combination
1253+
* @returns {STATE?} The FSA state obtained from the operation associated to mouse/keyboard combination
12501254
*/
12511255
getOpStateFromAction( mouse, key ) {
12521256

@@ -1478,7 +1482,7 @@ class ArcballControls extends Controls {
14781482
* Focus operation consist of positioning the point of interest in front of the camera and a slightly zoom in
14791483
* @param {Vector3} point The point of interest
14801484
* @param {Number} size Scale factor
1481-
* @param {Number} amount Amount of operation to be completed (used for focus animations, default is complete full operation)
1485+
* @param {Number} [amount=1] Amount of operation to be completed (used for focus animations, default is complete full operation)
14821486
*/
14831487
focus( point, size, amount = 1 ) {
14841488

@@ -1717,7 +1721,7 @@ class ArcballControls extends Controls {
17171721

17181722
/**
17191723
* Set gizmos radius factor and redraws gizmos
1720-
* @param {Float} value Value of radius factor
1724+
* @param {Number} value Value of radius factor
17211725
*/
17221726
setTbRadius( value ) {
17231727

@@ -2324,7 +2328,7 @@ class ArcballControls extends Controls {
23242328
*
23252329
* @param {Vector2} cursor Cursor coordinates in NDC
23262330
* @param {Camera} camera Virtual camera
2327-
* @returns {Vector3|null} The point of intersection with the model, if exist, null otherwise
2331+
* @returns {Vector3?} The point of intersection with the model, if exist, null otherwise
23282332
*/
23292333
unprojectOnObj( cursor, camera ) {
23302334

@@ -2485,7 +2489,7 @@ class ArcballControls extends Controls {
24852489
* @param {Number} cursorX Cursor horizontal coordinate on screen
24862490
* @param {Number} cursorY Cursor vertical coordinate on screen
24872491
* @param {HTMLElement} canvas The canvas where the renderer draws its output
2488-
* @param {Boolean} initialDistance If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only)
2492+
* @param {Boolean} [initialDistance=false] If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only)
24892493
* @returns {Vector3} The unprojected point on the trackball plane
24902494
*/
24912495
unprojectOnTbPlane( camera, cursorX, cursorY, canvas, initialDistance = false ) {
@@ -2600,8 +2604,6 @@ class ArcballControls extends Controls {
26002604

26012605
update() {
26022606

2603-
const EPS = 0.000001;
2604-
26052607
if ( this.target.equals( this._currentTarget ) === false ) {
26062608

26072609
this._gizmos.position.copy( this.target ); //for correct radius calculation
@@ -2627,7 +2629,7 @@ class ArcballControls extends Controls {
26272629
//check distance
26282630
const distance = this.object.position.distanceTo( this._gizmos.position );
26292631

2630-
if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
2632+
if ( distance > this.maxDistance + _EPS || distance < this.minDistance - _EPS ) {
26312633

26322634
const newDistance = MathUtils.clamp( distance, this.minDistance, this.maxDistance );
26332635
this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
@@ -2646,7 +2648,7 @@ class ArcballControls extends Controls {
26462648
const oldRadius = this._tbRadius;
26472649
this._tbRadius = this.calculateTbRadius( this.object );
26482650

2649-
if ( oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS ) {
2651+
if ( oldRadius < this._tbRadius - _EPS || oldRadius > this._tbRadius + _EPS ) {
26502652

26512653
const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
26522654
const newRadius = this._tbRadius / scale;

0 commit comments

Comments
 (0)