Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docs: Add more JSDoc. #30573

Merged
merged 1 commit into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions src/cameras/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,59 @@ import { WebGLCoordinateSystem } from '../constants.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Object3D } from '../core/Object3D.js';

/**
* Abstract base class for cameras. This class should always be inherited
* when you build a new camera.
*
* @abstract
* @augments Object3D
*/
class Camera extends Object3D {

/**
* Constructs a new camera.
*/
constructor() {

super();

/**
* This flag can be used for type testing.
*
* @type {boolean}
* @readonly
* @default true
*/
this.isCamera = true;

this.type = 'Camera';

/**
* The inverse of the camera's world matrix.
*
* @type {Matrix4}
*/
this.matrixWorldInverse = new Matrix4();

/**
* The camera's projection matrix.
*
* @type {Matrix4}
*/
this.projectionMatrix = new Matrix4();

/**
* The inverse of the camera's prjection matrix.
*
* @type {Matrix4}
*/
this.projectionMatrixInverse = new Matrix4();

/**
* The coordinate system in which the camrea is used.
*
* @type {(WebGLCoordinateSystem|WebGPUCoordinateSystem)}
*/
this.coordinateSystem = WebGLCoordinateSystem;

}
Expand All @@ -36,6 +74,15 @@ class Camera extends Object3D {

}

/**
* Returns a vector representing the ("look") direction of the 3D object in world space.
*
* This method is overwritten since cameras have a different forward vector compared to other
* 3D objects. A camera looks down its local, negative z-axis by default.
*
* @param {Vector3} target - The target vector the result is stored to.
* @return {Vector3} The 3D object's direction in world space.
*/
getWorldDirection( target ) {

return super.getWorldDirection( target ).negate();
Expand Down
72 changes: 72 additions & 0 deletions src/extras/Controls.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,102 @@
import { EventDispatcher } from '../core/EventDispatcher.js';

/**
* Abstract base class for controls.
*
* @abstract
* @augments EventDispatcher
*/
class Controls extends EventDispatcher {

/**
* Constructs a new controls instance.
*
* @param {Object3D} object - The object that is managed by the controls.
* @param {?HTMLDOMElement} domElement - The HTML element used for event listeners.
*/
constructor( object, domElement = null ) {

super();

/**
* The object that is managed by the controls.
*
* @type {Object3D}
*/
this.object = object;

/**
* The HTML element used for event listeners.
*
* @type {?HTMLDOMElement}
* @default null
*/
this.domElement = domElement;

/**
* Whether the controls responds to user input or not.
*
* @type {boolean}
* @default true
*/
this.enabled = true;

/**
* The internal state of the controls.
*
* @type {number}
* @default -1
*/
this.state = - 1;

/**
* This object defines the keyboard input of the controls.
*
* @type {Object}
*/
this.keys = {};

/**
* This object defines what type of actions are assigned to the available mouse buttons.
* It depends on the control implementation what kind of mouse buttons and actions are supported.
*
* @type {{LEFT: ?number, MIDDLE: ?number, RIGHT: ?number}}
*/
this.mouseButtons = { LEFT: null, MIDDLE: null, RIGHT: null };

/**
* This object defines what type of actions are assigned to what kind of touch interaction.
* It depends on the control implementation what kind of touch interaction and actions are supported.
*
* @type {{ONE: ?number, TWO: ?number}}
*/
this.touches = { ONE: null, TWO: null };

}

/**
* Connects the controls to the DOM. This method has so called "side effects" since
* it adds the module's event listeners to the DOM.
*/
connect() {}

/**
* Disconnects the controls from the DOM.
*/
disconnect() {}

/**
* Call this method if you no longer want use to the controls. It frees all internal
* resources and removes all event listeners.
*/
dispose() {}

/**
* Controls should implement this method if they have to update their internal state
* per simulation step.
*
* @param {number} [delta] - The time delta in seconds.
*/
update( /* delta */ ) {}

}
Expand Down
Loading
Loading