@@ -64,12 +64,17 @@ export class SceneManager {
64
64
this . spawnSound ( ) ;
65
65
}
66
66
67
+ /**
68
+ * Render the current frame.
69
+ */
67
70
private animate ( ) : void {
68
71
const delta = this . clock . getDelta ( ) ;
69
- this . animateGrid ( delta ) ;
70
- this . animateTitle ( delta ) ;
71
- this . animateModels ( delta ) ;
72
+
72
73
this . syncRendererSize ( ) ;
74
+ this . moveGridsInfinitely ( delta ) ;
75
+ this . moveTitleUntilRest ( delta ) ;
76
+ this . moveSpawnedModels ( delta ) ;
77
+
73
78
this . renderer . render ( this . scene , this . camera ) ;
74
79
requestAnimationFrame ( this . animate . bind ( this ) ) ;
75
80
}
@@ -78,7 +83,7 @@ export class SceneManager {
78
83
* Move grids closer to the camera. To make grids appear "infinite", reset
79
84
* their position once they have travelled one grid row of distance.
80
85
*/
81
- private animateGrid ( delta : number ) : void {
86
+ private moveGridsInfinitely ( delta : number ) : void {
82
87
this . gridTop . position . z = this . gridBottom . position . z =
83
88
this . gridTop . position . z < GRID_SIZE / GRID_DIVISIONS
84
89
? this . gridTop . position . z + 100 * delta
@@ -88,14 +93,14 @@ export class SceneManager {
88
93
/**
89
94
* Move the title away from the camera until it reaches its resting position.
90
95
*/
91
- private animateTitle ( delta : number ) : void {
96
+ private moveTitleUntilRest ( delta : number ) : void {
92
97
this . title . position . z = Math . max ( this . title . position . z - 350 * delta , 0 ) ;
93
98
}
94
99
95
100
/**
96
101
* Move models closer to the camera and destroy them when they travel past it.
97
102
*/
98
- private animateModels ( delta : number ) : void {
103
+ private moveSpawnedModels ( delta : number ) : void {
99
104
if ( this . title . position . z > 0 ) return ;
100
105
101
106
this . spawnedModels . forEach ( ( model ) => {
@@ -113,6 +118,9 @@ export class SceneManager {
113
118
}
114
119
}
115
120
121
+ /**
122
+ * Spawn a new model at a random position.
123
+ */
116
124
private spawnModel ( ) : void {
117
125
const model = sample ( [ ...this . assetCache . models . values ( ) ] ) ! . scene . clone ( ) ;
118
126
model . position . set ( ...this . computeModelSpawnPosition ( ) ) ;
@@ -126,14 +134,17 @@ export class SceneManager {
126
134
this . scene . add ( model ) ;
127
135
}
128
136
137
+ /**
138
+ * Spawn a new sound and start playing it. The audio may loop several times.
139
+ */
129
140
private spawnSound ( ) : void {
130
141
const sound = sample (
131
142
[ ...this . assetCache . sounds . values ( ) ] . filter (
132
143
( sound ) => ! this . spawnedSounds . has ( sound )
133
144
)
134
145
) ! ;
135
146
136
- const timeListener = ( ) => {
147
+ const timeListener = ( ) : void => {
137
148
if ( sound . currentTime >= sound . duration * 0.65 ) {
138
149
this . spawnSound ( ) ;
139
150
sound . removeEventListener ( 'timeupdate' , timeListener ) ;
@@ -142,7 +153,7 @@ export class SceneManager {
142
153
sound . addEventListener ( 'timeupdate' , timeListener ) ;
143
154
144
155
let loops = random ( 0 , 2 ) ;
145
- const endListener = ( ) => {
156
+ const endListener = ( ) : void => {
146
157
if ( loops > 0 ) {
147
158
void sound . play ( ) ;
148
159
loops -- ;
0 commit comments