Skip to content

Commit fd42cf1

Browse files
authored
Docs: More JSDoc. (#30649)
1 parent 8552d3a commit fd42cf1

12 files changed

+365
-59
lines changed

examples/jsm/effects/PeppersGhostEffect.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class PeppersGhostEffect {
1414
/**
1515
* Constructs a new peppers ghost effect.
1616
*
17-
* @param {(Renderer|WebGLRenderer)} renderer - The renderer.
17+
* @param {(WebGPURenderer|WebGLRenderer)} renderer - The renderer.
1818
*/
1919
constructor( renderer ) {
2020

examples/jsm/helpers/ViewHelper.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class ViewHelper extends Object3D {
144144
* Renders the helper in a separate view in the bottom-right corner
145145
* of the viewport.
146146
*
147-
* @param {WebgLRenderer|Renderer} renderer - The renderer.
147+
* @param {WebGLRenderer|WebGPURenderer} renderer - The renderer.
148148
*/
149149
this.render = function ( renderer ) {
150150

examples/jsm/interactive/HTMLMesh.js

+25
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,29 @@ import {
88
Color
99
} from 'three';
1010

11+
/**
12+
* This class can be used to render a DOM element onto a canvas and use it as a texture
13+
* for a plane mesh.
14+
*
15+
* A typical use case for this class is to render the GUI of `lil-gui` as a texture so it
16+
* is compatible for VR.
17+
*
18+
* ```js
19+
* const gui = new GUI( { width: 300 } ); // create lil-gui instance
20+
*
21+
* const mesh = new HTMLMesh( gui.domElement );
22+
* scene.add( mesh );
23+
* ```
24+
*
25+
* @augments Mesh
26+
*/
1127
class HTMLMesh extends Mesh {
1228

29+
/**
30+
* Constructs a new HTML mesh.
31+
*
32+
* @param {HTMLElement} dom - The DOM element to display as a plane mesh.
33+
*/
1334
constructor( dom ) {
1435

1536
const texture = new HTMLTexture( dom );
@@ -30,6 +51,10 @@ class HTMLMesh extends Mesh {
3051
this.addEventListener( 'mouseup', onEvent );
3152
this.addEventListener( 'click', onEvent );
3253

54+
/**
55+
* Frees the GPU-related resources allocated by this instance and removes all event listeners.
56+
* Call this method whenever this instance is no longer used in your app.
57+
*/
3358
this.dispose = function () {
3459

3560
geometry.dispose();

examples/jsm/interactive/InteractiveGroup.js

+65-5
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ import {
77
const _pointer = new Vector2();
88
const _event = { type: '', data: _pointer };
99

10-
// TODO: Dispatch pointerevents too
11-
12-
/**
13-
* The XR events that are mapped to "standard" pointer events
14-
*/
10+
// The XR events that are mapped to "standard" pointer events.
1511
const _events = {
1612
'move': 'mousemove',
1713
'select': 'click',
@@ -21,17 +17,58 @@ const _events = {
2117

2218
const _raycaster = new Raycaster();
2319

20+
/**
21+
* This class can be used to group 3D objects in an interactive group.
22+
* The group itself can listen to Pointer, Mouse or XR controller events to
23+
* detect selections of descendant 3D objects. If a 3D object is selected,
24+
* the respective event is going to dispatched to it.
25+
*
26+
* ```js
27+
* const group = new InteractiveGroup();
28+
* group.listenToPointerEvents( renderer, camera );
29+
* group.listenToXRControllerEvents( controller1 );
30+
* group.listenToXRControllerEvents( controller2 );
31+
* scene.add( group );
32+
*
33+
* // now add objects that should be interactive
34+
* group.add( mesh1, mesh2, mesh3 );
35+
* ```
36+
* @augments Group
37+
*/
2438
class InteractiveGroup extends Group {
2539

2640
constructor() {
2741

2842
super();
2943

44+
/**
45+
* The internal raycaster.
46+
*
47+
* @type {Raycaster}
48+
*/
3049
this.raycaster = new Raycaster();
3150

51+
/**
52+
* The internal raycaster.
53+
*
54+
* @type {?HTMLDOMElement}
55+
* @default null
56+
*/
3257
this.element = null;
58+
59+
/**
60+
* The camera used for raycasting.
61+
*
62+
* @type {?Camera}
63+
* @default null
64+
*/
3365
this.camera = null;
3466

67+
/**
68+
* An array of XR controllers.
69+
*
70+
* @type {Array<Group>}
71+
*/
3572
this.controllers = [];
3673

3774
this._onPointerEvent = this.onPointerEvent.bind( this );
@@ -92,6 +129,14 @@ class InteractiveGroup extends Group {
92129

93130
}
94131

132+
/**
133+
* Calling this method makes sure the interactive group listens to Pointer and Mouse events.
134+
* The taret is the `domElement` of the given renderer. The camera is required for the internal
135+
* raycasting so 3D objects can be detected based on the events.
136+
*
137+
* @param {(WebGPURenderer|WebGLRenderer)} renderer - The renderer.
138+
* @param {Camera} camera - The camera.
139+
*/
95140
listenToPointerEvents( renderer, camera ) {
96141

97142
this.camera = camera;
@@ -107,6 +152,9 @@ class InteractiveGroup extends Group {
107152

108153
}
109154

155+
/**
156+
* Disconnects this interactive group from all Pointer and Mouse Events.
157+
*/
110158
disconnectionPointerEvents() {
111159

112160
if ( this.element !== null ) {
@@ -123,6 +171,12 @@ class InteractiveGroup extends Group {
123171

124172
}
125173

174+
/**
175+
* Calling this method makes sure the interactive group listens to events of
176+
* the given XR controller.
177+
*
178+
* @param {Group} controller - The XR controller.
179+
*/
126180
listenToXRControllerEvents( controller ) {
127181

128182
this.controllers.push( controller );
@@ -133,6 +187,9 @@ class InteractiveGroup extends Group {
133187

134188
}
135189

190+
/**
191+
* Disconnects this interactive group from all XR controllers.
192+
*/
136193
disconnectXrControllerEvents() {
137194

138195
for ( const controller of this.controllers ) {
@@ -146,6 +203,9 @@ class InteractiveGroup extends Group {
146203

147204
}
148205

206+
/**
207+
* Disconnects this interactive group from the DOM and all XR controllers.
208+
*/
149209
disconnect() {
150210

151211
this.disconnectionPointerEvents();

examples/jsm/interactive/SelectionBox.js

+74-9
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@ import {
55
Quaternion,
66
} from 'three';
77

8-
/**
9-
* This is a class to check whether objects are in a selection area in 3D space
10-
*/
11-
128
const _frustum = new Frustum();
139
const _center = new Vector3();
1410

@@ -33,34 +29,103 @@ const _matrix = new Matrix4();
3329
const _quaternion = new Quaternion();
3430
const _scale = new Vector3();
3531

32+
/**
33+
* This class can be used to select 3D objects in a scene with a selection box.
34+
* It is recommended to visualize the selected area with the help of {@link SelectionHelper}.
35+
*
36+
* ```js
37+
* const selectionBox = new SelectionBox( camera, scene );
38+
* const selectedObjects = selectionBox.select( startPoint, endPoint );
39+
* ```
40+
*/
3641
class SelectionBox {
3742

43+
/**
44+
* Constructs a new selection box.
45+
*
46+
* @param {Camera} camera - The camera the scene is rendered with.
47+
* @param {Scene} scene - The scene.
48+
* @param {number} [deep=Number.MAX_VALUE] - How deep the selection frustum of perspective cameras should extend.
49+
*/
3850
constructor( camera, scene, deep = Number.MAX_VALUE ) {
3951

52+
/**
53+
* The camera the scene is rendered with.
54+
*
55+
* @type {Camera}
56+
*/
4057
this.camera = camera;
58+
59+
/**
60+
* The camera the scene is rendered with.
61+
*
62+
* @type {Scene}
63+
*/
4164
this.scene = scene;
65+
66+
/**
67+
* The start point of the selction.
68+
*
69+
* @type {Vector3}
70+
*/
4271
this.startPoint = new Vector3();
72+
73+
/**
74+
* The end point of the selction.
75+
*
76+
* @type {Vector3}
77+
*/
4378
this.endPoint = new Vector3();
79+
80+
/**
81+
* The selected 3D objects.
82+
*
83+
* @type {Array<Object3D>}
84+
*/
4485
this.collection = [];
86+
87+
/**
88+
* The selected instance IDs of instanced meshes.
89+
*
90+
* @type {Object}
91+
*/
4592
this.instances = {};
93+
94+
/**
95+
* How deep the selection frustum of perspective cameras should extend.
96+
*
97+
* @type {number}
98+
* @default Number.MAX_VALUE
99+
*/
46100
this.deep = deep;
47101

48102
}
49103

104+
/**
105+
* This method selects 3D objects in the scene based on the given start
106+
* and end point. If no parameters are provided, the method uses the start
107+
* and end values of the respective members.
108+
*
109+
* @param {Vector3} [startPoint] - The start point.
110+
* @param {Vector3} [endPoint] - The end point.
111+
* @return {Array<Object3D>} The selected 3D objects.
112+
*/
50113
select( startPoint, endPoint ) {
51114

52115
this.startPoint = startPoint || this.startPoint;
53116
this.endPoint = endPoint || this.endPoint;
54117
this.collection = [];
55118

56-
this.updateFrustum( this.startPoint, this.endPoint );
57-
this.searchChildInFrustum( _frustum, this.scene );
119+
this._updateFrustum( this.startPoint, this.endPoint );
120+
this._searchChildInFrustum( _frustum, this.scene );
58121

59122
return this.collection;
60123

61124
}
62125

63-
updateFrustum( startPoint, endPoint ) {
126+
// private
127+
128+
_updateFrustum( startPoint, endPoint ) {
64129

65130
startPoint = startPoint || this.startPoint;
66131
endPoint = endPoint || this.endPoint;
@@ -170,7 +235,7 @@ class SelectionBox {
170235

171236
}
172237

173-
searchChildInFrustum( frustum, object ) {
238+
_searchChildInFrustum( frustum, object ) {
174239

175240
if ( object.isMesh || object.isLine || object.isPoints ) {
176241

@@ -214,7 +279,7 @@ class SelectionBox {
214279

215280
for ( let x = 0; x < object.children.length; x ++ ) {
216281

217-
this.searchChildInFrustum( frustum, object.children[ x ] );
282+
this._searchChildInFrustum( frustum, object.children[ x ] );
218283

219284
}
220285

0 commit comments

Comments
 (0)