Skip to content

Commit 6acabbd

Browse files
authored
Docs: More JSDoc. (#30574)
1 parent e44bf7c commit 6acabbd

File tree

10 files changed

+552
-42
lines changed

10 files changed

+552
-42
lines changed

src/cameras/ArrayCamera.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,41 @@
11
import { PerspectiveCamera } from './PerspectiveCamera.js';
22

3+
/**
4+
* This type of camera can be used in order to efficiently render a scene with a
5+
* predefined set of cameras. This is an important performance aspect for
6+
* rendering VR scenes.
7+
*
8+
* An instance of `ArrayCamera` always has an array of sub cameras. It's mandatory
9+
* to define for each sub camera the `viewport` property which determines the
10+
* part of the viewport that is rendered with this camera.
11+
*
12+
* @augments PerspectiveCamera
13+
*/
314
class ArrayCamera extends PerspectiveCamera {
415

16+
/**
17+
* Constructs a new array camera.
18+
*
19+
* @param {Array<PerspectiveCamera>} [array=[]] - An array of perspective sub cameras.
20+
*/
521
constructor( array = [] ) {
622

723
super();
824

25+
/**
26+
* This flag can be used for type testing.
27+
*
28+
* @type {boolean}
29+
* @readonly
30+
* @default true
31+
*/
932
this.isArrayCamera = true;
1033

34+
/**
35+
* An array of perspective sub cameras.
36+
*
37+
* @type {Array<PerspectiveCamera>}
38+
*/
1139
this.cameras = array;
1240
this.index = 0;
1341

src/cameras/CubeCamera.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,72 @@ import { PerspectiveCamera } from './PerspectiveCamera.js';
55
const fov = - 90; // negative fov is not an error
66
const aspect = 1;
77

8+
/**
9+
* A special type of camera that is positioned in 3D space to render its surroundings into a
10+
* cube render target. The render target can then be used as an environment map for rendering
11+
* realtime reflections in your scene.
12+
*
13+
* ```js
14+
* // Create cube render target
15+
* const cubeRenderTarget = new THREE.WebGLCubeRenderTarget( 256, { generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter } );
16+
*
17+
* // Create cube camera
18+
* const cubeCamera = new THREE.CubeCamera( 1, 100000, cubeRenderTarget );
19+
* scene.add( cubeCamera );
20+
*
21+
* // Create car
22+
* const chromeMaterial = new THREE.MeshLambertMaterial( { color: 0xffffff, envMap: cubeRenderTarget.texture } );
23+
* const car = new THREE.Mesh( carGeometry, chromeMaterial );
24+
* scene.add( car );
25+
*
26+
* // Update the render target cube
27+
* car.visible = false;
28+
* cubeCamera.position.copy( car.position );
29+
* cubeCamera.update( renderer, scene );
30+
*
31+
* // Render the scene
32+
* car.visible = true;
33+
* renderer.render( scene, camera );
34+
* ```
35+
*
36+
* @augments Object3D
37+
*/
838
class CubeCamera extends Object3D {
939

40+
/**
41+
* Constructs a new cube camera.
42+
*
43+
* @param {number} near - The camera's near plane.
44+
* @param {number} far - The camera's far plane.
45+
* @param {WebGLCubeRenderTarget} renderTarget - The cube render target.
46+
*/
1047
constructor( near, far, renderTarget ) {
1148

1249
super();
1350

1451
this.type = 'CubeCamera';
1552

53+
/**
54+
* A reference to the cube render target.
55+
*
56+
* @type {WebGLCubeRenderTarget}
57+
*/
1658
this.renderTarget = renderTarget;
59+
60+
/**
61+
* The current active coordinate system.
62+
*
63+
* @type {?(WebGLCoordinateSystem|WebGPUCoordinateSystem)}
64+
* @default null
65+
*/
1766
this.coordinateSystem = null;
67+
68+
/**
69+
* The current active mipmap level
70+
*
71+
* @type {number}
72+
* @default 0
73+
*/
1874
this.activeMipmapLevel = 0;
1975

2076
const cameraPX = new PerspectiveCamera( fov, aspect, near, far );
@@ -43,6 +99,9 @@ class CubeCamera extends Object3D {
4399

44100
}
45101

102+
/**
103+
* Must be called when the coordinate system of the cube camera is changed.
104+
*/
46105
updateCoordinateSystem() {
47106

48107
const coordinateSystem = this.coordinateSystem;
@@ -109,6 +168,13 @@ class CubeCamera extends Object3D {
109168

110169
}
111170

171+
/**
172+
* Calling this method will render the given scene with the given renderer
173+
* into the cube render target of the camera.
174+
*
175+
* @param {(Renderer|WebGLRenderer)} renderer - The renderer.
176+
* @param {Scene} scene - The scene to render.
177+
*/
112178
update( renderer, scene ) {
113179

114180
if ( this.parent === null ) this.updateMatrixWorld();

src/cameras/OrthographicCamera.js

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,109 @@
11
import { Camera } from './Camera.js';
22

3+
/**
4+
* Camera that uses [orthographic projection]{@link https://en.wikipedia.org/wiki/Orthographic_projection}.
5+
*
6+
* In this projection mode, an object's size in the rendered image stays
7+
* constant regardless of its distance from the camera. This can be useful
8+
* for rendering 2D scenes and UI elements, amongst other things.
9+
*
10+
* @augments Camera
11+
*/
312
class OrthographicCamera extends Camera {
413

14+
/**
15+
* Constructs a new orthographic camera.
16+
*
17+
* @param {number} [left=-1] - The left plane of the camera's frustum.
18+
* @param {number} [right=1] - The right plane of the camera's frustum.
19+
* @param {number} [top=1] - The top plane of the camera's frustum.
20+
* @param {number} [bottom=-1] - The bottom plane of the camera's frustum.
21+
* @param {number} [near=0.1] - The camera's near plane.
22+
* @param {number} [far=2000] - The camera's far plane.
23+
*/
524
constructor( left = - 1, right = 1, top = 1, bottom = - 1, near = 0.1, far = 2000 ) {
625

726
super();
827

28+
/**
29+
* This flag can be used for type testing.
30+
*
31+
* @type {boolean}
32+
* @readonly
33+
* @default true
34+
*/
935
this.isOrthographicCamera = true;
1036

1137
this.type = 'OrthographicCamera';
1238

39+
/**
40+
* The zoom factor of the camera.
41+
*
42+
* @type {number}
43+
* @default 1
44+
*/
1345
this.zoom = 1;
46+
47+
/**
48+
* Represents the frustum window specification. This property should not be edited
49+
* directly but via {@link PerspectiveCamera#setViewOffset} and {@link PerspectiveCamera#clearViewOffset}.
50+
*
51+
* @type {?Object}
52+
* @default null
53+
*/
1454
this.view = null;
1555

56+
/**
57+
* The left plane of the camera's frustum.
58+
*
59+
* @type {number}
60+
* @default -1
61+
*/
1662
this.left = left;
63+
64+
/**
65+
* The right plane of the camera's frustum.
66+
*
67+
* @type {number}
68+
* @default 1
69+
*/
1770
this.right = right;
71+
72+
/**
73+
* The top plane of the camera's frustum.
74+
*
75+
* @type {number}
76+
* @default 1
77+
*/
1878
this.top = top;
79+
80+
/**
81+
* The bottom plane of the camera's frustum.
82+
*
83+
* @type {number}
84+
* @default -1
85+
*/
1986
this.bottom = bottom;
2087

88+
/**
89+
* The camera's near plane. The valid range is greater than `0`
90+
* and less than the current value of {@link OrthographicCamera#far}.
91+
*
92+
* Note that, unlike for the {@link PerspectiveCamera}, `0` is a
93+
* valid value for an orthographic camera's near plane.
94+
*
95+
* @type {number}
96+
* @default 0.1
97+
*/
2198
this.near = near;
99+
100+
/**
101+
* The camera's far plane. Must be greater than the
102+
* current value of {@link OrthographicCamera#near}.
103+
*
104+
* @type {number}
105+
* @default 2000
106+
*/
22107
this.far = far;
23108

24109
this.updateProjectionMatrix();
@@ -43,6 +128,18 @@ class OrthographicCamera extends Camera {
43128

44129
}
45130

131+
/**
132+
* Sets an offset in a larger frustum. This is useful for multi-window or
133+
* multi-monitor/multi-machine setups.
134+
*
135+
* @param {number} fullWidth - The full width of multiview setup.
136+
* @param {number} fullHeight - The full height of multiview setup.
137+
* @param {number} x - The horizontal offset of the subcamera.
138+
* @param {number} y - The vertical offset of the subcamera.
139+
* @param {number} width - The width of subcamera.
140+
* @param {number} height - The height of subcamera.
141+
* @see {@link PerspectiveCamera#setViewOffset}
142+
*/
46143
setViewOffset( fullWidth, fullHeight, x, y, width, height ) {
47144

48145
if ( this.view === null ) {
@@ -71,6 +168,9 @@ class OrthographicCamera extends Camera {
71168

72169
}
73170

171+
/**
172+
* Removes the view offset from the projection matrix.
173+
*/
74174
clearViewOffset() {
75175

76176
if ( this.view !== null ) {
@@ -83,6 +183,10 @@ class OrthographicCamera extends Camera {
83183

84184
}
85185

186+
/**
187+
* Updates the camera's projection matrix. Must be called after any change of
188+
* camera properties.
189+
*/
86190
updateProjectionMatrix() {
87191

88192
const dx = ( this.right - this.left ) / ( 2 * this.zoom );

0 commit comments

Comments
 (0)