1+
2+ /**
3+ * This module manages the internal animation loop of the renderer.
4+ *
5+ * @private
6+ */
17class 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 ( ) ;
0 commit comments