Skip to content

Commit bcdb914

Browse files
authored
Renderer: Document more modules. (#30188)
* Renderer: Document more modules. * Update BundleGroup.js
1 parent 8b6d4c3 commit bcdb914

File tree

11 files changed

+383
-22
lines changed

11 files changed

+383
-22
lines changed

src/renderers/common/Animation.js

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,63 @@
1+
2+
/**
3+
* This module manages the internal animation loop of the renderer.
4+
*
5+
* @private
6+
*/
17
class Animation {
28

9+
/**
10+
* Constructs a new animation loop management component.
11+
*
12+
* @param {Nodes} nodes - Renderer component for managing nodes relatd logic.
13+
* @param {Info} info - Renderer component for managing metrics and monitoring data.
14+
*/
315
constructor( nodes, info ) {
416

17+
/**
18+
* Renderer component for managing nodes relatd logic.
19+
*
20+
* @type {Nodes}
21+
*/
522
this.nodes = nodes;
23+
24+
/**
25+
* Renderer component for managing metrics and monitoring data.
26+
*
27+
* @type {Info}
28+
*/
629
this.info = info;
730

31+
/**
32+
* A reference to the context from `requestAnimationFrame()` can
33+
* be called (usually `window`).
34+
*
35+
* @type {Window|XRSession}
36+
*/
837
this._context = self;
38+
39+
/**
40+
* The user-defined animation loop.
41+
*
42+
* @type {Function?}
43+
* @default null
44+
*/
945
this._animationLoop = null;
46+
47+
/**
48+
* The requestId whic is returned from the `requestAnimationFrame()` call.
49+
* Can be used to cancel the stop the animation loop.
50+
*
51+
* @type {Number?}
52+
* @default null
53+
*/
1054
this._requestId = null;
1155

1256
}
1357

58+
/**
59+
* Starts the internal animation loop.
60+
*/
1461
start() {
1562

1663
const update = ( time, frame ) => {
@@ -31,6 +78,9 @@ class Animation {
3178

3279
}
3380

81+
/**
82+
* Stops the internal animation loop.
83+
*/
3484
stop() {
3585

3686
this._context.cancelAnimationFrame( this._requestId );
@@ -39,18 +89,31 @@ class Animation {
3989

4090
}
4191

92+
/**
93+
* Defines the user-level animation loop.
94+
*
95+
* @param {Function} callback - The animation loop.
96+
*/
4297
setAnimationLoop( callback ) {
4398

4499
this._animationLoop = callback;
45100

46101
}
47102

103+
/**
104+
* Defines the context in which `requestAnimationFrame()` is executed.
105+
*
106+
* @param {Window|XRSession} context - The context to set.
107+
*/
48108
setContext( context ) {
49109

50110
this._context = context;
51111

52112
}
53113

114+
/**
115+
* Frees all internal resources and stops the animation loop.
116+
*/
54117
dispose() {
55118

56119
this.stop();

src/renderers/common/Attributes.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,38 @@ import { AttributeType } from './Constants.js';
33

44
import { DynamicDrawUsage } from '../../constants.js';
55

6+
/**
7+
* This renderer module manages geometry attributes.
8+
*
9+
* @private
10+
* @augments DataMap
11+
*/
612
class Attributes extends DataMap {
713

14+
/**
15+
* Constructs a new attribute management component.
16+
*
17+
* @param {Backend} backend - The renderer's backend.
18+
*/
819
constructor( backend ) {
920

1021
super();
1122

23+
/**
24+
* The renderer's backend.
25+
*
26+
* @type {Backend}
27+
*/
1228
this.backend = backend;
1329

1430
}
1531

32+
/**
33+
* Deletes the data for the given attribute.
34+
*
35+
* @param {BufferAttribute} attribute - The attribute.
36+
* @return {Object} The deleted attribute data.
37+
*/
1638
delete( attribute ) {
1739

1840
const attributeData = super.delete( attribute );
@@ -27,6 +49,13 @@ class Attributes extends DataMap {
2749

2850
}
2951

52+
/**
53+
* Updates the given attribute. This method creates attribute buffers
54+
* for new attributes and updates data for existing ones.
55+
*
56+
* @param {BufferAttribute} attribute - The attribute to update.
57+
* @param {Number} type - The attribute type.
58+
*/
3059
update( attribute, type ) {
3160

3261
const data = this.get( attribute );
@@ -69,6 +98,13 @@ class Attributes extends DataMap {
6998

7099
}
71100

101+
/**
102+
* Utility method for handling interleaved buffer attributes correctly.
103+
* To process them, their `InterleavedBuffer` is returned.
104+
*
105+
* @param {BufferAttribute} attribute - The attribute.
106+
* @return {BufferAttribute|InterleavedBuffer}
107+
*/
72108
_getBufferAttribute( attribute ) {
73109

74110
if ( attribute.isInterleavedBufferAttribute ) attribute = attribute.data;

src/renderers/common/Background.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,50 @@ import { BackSide, LinearSRGBColorSpace } from '../../constants.js';
99

1010
const _clearColor = /*@__PURE__*/ new Color4();
1111

12+
/**
13+
* This renderer module manages the background.
14+
*
15+
* @private
16+
* @augments DataMap
17+
*/
1218
class Background extends DataMap {
1319

20+
/**
21+
* Constructs a new background management component.
22+
*
23+
* @param {Renderer} renderer - The renderer.
24+
* @param {Nodes} nodes - Renderer component for managing nodes relatd logic.
25+
*/
1426
constructor( renderer, nodes ) {
1527

1628
super();
1729

30+
/**
31+
* The renderer.
32+
*
33+
* @type {Renderer}
34+
*/
1835
this.renderer = renderer;
36+
37+
/**
38+
* Renderer component for managing nodes relatd logic.
39+
*
40+
* @type {Nodes}
41+
*/
1942
this.nodes = nodes;
2043

2144
}
2245

46+
/**
47+
* Updates the background for the given scene. Depending on how `Scene.background`
48+
* or `Scene.backgroundNode` are configured, this method might configure a simple clear
49+
* or add a mesh to the render list for rendering the background as a textured plane
50+
* or skybox.
51+
*
52+
* @param {Scene} scene - The scene.
53+
* @param {RenderList} renderList - The current render list.
54+
* @param {RenderContext} renderContext - The current render context.
55+
*/
2356
update( scene, renderList, renderContext ) {
2457

2558
const renderer = this.renderer;

src/renderers/common/BundleGroup.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,77 @@
11
import { Group } from '../../objects/Group.js';
22

3+
/**
4+
* A specialized group which eanbles applications access to the
5+
* Render Bundle API of WebGPU. The group with all its descendant nodes
6+
* are considered as one render bundle and processed as such by
7+
* the renderer.
8+
*
9+
* This module is only fully supported by `WebGPURenderer` with a WebGPU backend.
10+
* With a WebGL backend, the group can technically be rendered but without
11+
* any performance improvements.
12+
*
13+
* @augments Group
14+
*/
315
class BundleGroup extends Group {
416

17+
/**
18+
* Constructs a new bundle group.
19+
*/
520
constructor() {
621

722
super();
823

24+
/**
25+
* This flag can be used for type testing.
26+
*
27+
* @type {Boolean}
28+
* @readonly
29+
* @default true
30+
*/
931
this.isBundleGroup = true;
1032

33+
/**
34+
* This property is only relevant for detecting types
35+
* during serialization/deserialization. It should always
36+
* match the class name.
37+
*
38+
* @type {String}
39+
* @readonly
40+
* @default 'BundleGroup'
41+
*/
1142
this.type = 'BundleGroup';
1243

44+
/**
45+
* Whether the bundle is static or not. When set to `true`, the structure
46+
* is assumed to be static and does not change. E.g. no new objects are
47+
* added to the group
48+
*
49+
* If a change is required, an update can still be forced by setting the
50+
* `needsUpdate` flag to `true`.
51+
*
52+
* @type {Boolean}
53+
* @default true
54+
*/
1355
this.static = true;
56+
57+
/**
58+
* The bundle group's version.
59+
*
60+
* @type {Number}
61+
* @readonly
62+
* @default 0
63+
*/
1464
this.version = 0;
1565

1666
}
1767

68+
/**
69+
* Set this property to `true` when the bundle group has changed.
70+
*
71+
* @type {Boolean}
72+
* @default false
73+
* @param {Boolean} value
74+
*/
1875
set needsUpdate( value ) {
1976

2077
if ( value === true ) this.version ++;

src/renderers/common/ChainMap.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1+
/**
2+
* Data structure for the renderer. It allows defining values
3+
* with chained, hierarchical keys. Keys are meant to be
4+
* objects since the module internally works with Weak Maps
5+
* for perforamnce reasons.
6+
*
7+
* @private
8+
*/
19
export default class ChainMap {
210

11+
/**
12+
* Constructs a new chained map.
13+
*/
314
constructor() {
415

16+
/**
17+
* The root Weak Map.
18+
*
19+
* @type {WeakMap}
20+
*/
521
this.weakMap = new WeakMap();
622

723
}
824

25+
/**
26+
* Returns the value for the given array of keys.
27+
*
28+
* @param {Array<Object>} keys - List of keys.
29+
* @return {Any} The value. Returns `undefined` if no value was found.
30+
*/
931
get( keys ) {
1032

1133
let map = this.weakMap;
@@ -22,6 +44,13 @@ export default class ChainMap {
2244

2345
}
2446

47+
/**
48+
* Sets the value for the given keys.
49+
*
50+
* @param {Array<Object>} keys - List of keys.
51+
* @param {Any} value - The value to set.
52+
* @return {ChainMap} A reference to this chain map.
53+
*/
2554
set( keys, value ) {
2655

2756
let map = this.weakMap;
@@ -36,10 +65,18 @@ export default class ChainMap {
3665

3766
}
3867

39-
return map.set( keys[ keys.length - 1 ], value );
68+
map.set( keys[ keys.length - 1 ], value );
69+
70+
return this;
4071

4172
}
4273

74+
/**
75+
* Deletes a value for the given keys.
76+
*
77+
* @param {Array<Object>} keys - The keys.
78+
* @return {Boolean} Returns `true` if the value has been removed successfully and `false` if the value has not be found.
79+
*/
4380
delete( keys ) {
4481

4582
let map = this.weakMap;

0 commit comments

Comments
 (0)