Skip to content

Commit 0d0dcc2

Browse files
author
Samuel Rigaud
committed
Docs: improve Promise typing
1 parent 86c3bd3 commit 0d0dcc2

File tree

10 files changed

+65
-21
lines changed

10 files changed

+65
-21
lines changed

examples/jsm/exporters/GLTFExporter.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ const GLB_CHUNK_TYPE_BIN = 0x004E4942;
304304

305305
/**
306306
* Compare two arrays
307-
* @param {Array} array1 Array 1 to compare
308-
* @param {Array} array2 Array 2 to compare
307+
* @template {T}
308+
* @param {Array<T>} array1 Array 1 to compare
309+
* @param {Array<T>} array2 Array 2 to compare
309310
* @return {Boolean} Returns true if both arrays are equal
310311
*/
311312
function equalArray( array1, array2 ) {

src/nodes/code/ScriptableNode.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ class ScriptableNode extends Node {
416416
*
417417
* @param {String} name - The function name.
418418
* @param {...Any} params - A list of parameters.
419-
* @return {Any} The result of the function call.
419+
* @return {Promise<Any>} The result of the function call.
420420
*/
421421
async callAsync( name, ...params ) {
422422

src/renderers/common/Backend.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class Backend {
207207
*
208208
* @abstract
209209
* @param {RenderObject} renderObject - The render object.
210-
* @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
210+
* @param {Array<Promise<void>>} promises - An array of compilation promises which are used in `compileAsync()`.
211211
*/
212212
createRenderPipeline( /*renderObject, promises*/ ) { }
213213

src/renderers/common/Pipelines.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ class Pipelines extends DataMap {
343343
* @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader.
344344
* @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader.
345345
* @param {String} cacheKey - The cache key.
346-
* @param {Array} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
346+
* @param {Array<Promise<void>>?} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
347347
* @return {ComputePipeline} The compute pipeline.
348348
*/
349349
_getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises ) {

src/renderers/common/PostProcessing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class PostProcessing {
148148
* its animation loop (not the one from the renderer).
149149
*
150150
* @async
151-
* @return {Promise} A Promise that resolves when the render has been finished.
151+
* @return {Promise<void>} A Promise that resolves when the render has been finished.
152152
*/
153153
async renderAsync() {
154154

src/renderers/common/Renderer.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ class Renderer {
691691
* Initializes the renderer so it is ready for usage.
692692
*
693693
* @async
694-
* @return {Promise} A Promise that resolves when the renderer has been initialized.
694+
* @return {Promise<void>} A Promise that resolves when the renderer has been initialized.
695695
*/
696696
async init() {
697697

@@ -795,7 +795,7 @@ class Renderer {
795795
* @param {Object3D} scene - The scene or 3D object to precompile.
796796
* @param {Camera} camera - The camera that is used to render the scene.
797797
* @param {Scene} targetScene - If the first argument is a 3D object, this parameter must represent the scene the 3D object is going to be added.
798-
* @return {Promise} A Promise that resolves when the compile has been finished.
798+
* @return {Promise<Array<void>>} A Promise that resolves when the compile has been finished.
799799
*/
800800
async compileAsync( scene, camera, targetScene = null ) {
801801

@@ -927,7 +927,7 @@ class Renderer {
927927
* @async
928928
* @param {Object3D} scene - The scene or 3D object to render.
929929
* @param {Camera} camera - The camera.
930-
* @return {Promise} A Promise that resolves when the render has been finished.
930+
* @return {Promise<void>} A Promise that resolves when the render has been finished.
931931
*/
932932
async renderAsync( scene, camera ) {
933933

@@ -944,7 +944,7 @@ class Renderer {
944944
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
945945
*
946946
* @async
947-
* @return {Promise} A Promise that resolves when synchronization has been finished.
947+
* @return {Promise<void>} A Promise that resolves when synchronization has been finished.
948948
*/
949949
async waitForGPU() {
950950

@@ -1433,7 +1433,7 @@ class Renderer {
14331433
*
14341434
* @async
14351435
* @param {Function} callback - The application's animation loop.
1436-
* @return {Promise} A Promise that resolves when the set has been executed.
1436+
* @return {Promise<void>} A Promise that resolves when the set has been executed.
14371437
*/
14381438
async setAnimationLoop( callback ) {
14391439

@@ -1920,7 +1920,7 @@ class Renderer {
19201920
* @param {Boolean} [color=true] - Whether the color buffer should be cleared or not.
19211921
* @param {Boolean} [depth=true] - Whether the depth buffer should be cleared or not.
19221922
* @param {Boolean} [stencil=true] - Whether the stencil buffer should be cleared or not.
1923-
* @return {Promise} A Promise that resolves when the clear operation has been executed.
1923+
* @return {Promise<void>} A Promise that resolves when the clear operation has been executed.
19241924
*/
19251925
async clearAsync( color = true, depth = true, stencil = true ) {
19261926

@@ -2187,7 +2187,7 @@ class Renderer {
21872187
*
21882188
* @async
21892189
* @param {Node|Array<Node>} computeNodes - The compute node(s).
2190-
* @return {Promise?} A Promise that resolve when the compute has finished.
2190+
* @return {Promise<void>} A Promise that resolve when the compute has finished.
21912191
*/
21922192
async computeAsync( computeNodes ) {
21932193

@@ -2252,7 +2252,7 @@ class Renderer {
22522252
*
22532253
* @async
22542254
* @param {Texture} texture - The texture.
2255-
* @return {Promise} A Promise that resolves when the texture has been initialized.
2255+
* @return {Promise<void>} A Promise that resolves when the texture has been initialized.
22562256
*/
22572257
async initTextureAsync( texture ) {
22582258

src/renderers/common/extras/PMREMGenerator.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ class PMREMGenerator {
135135
* @param {Number} [far=100] - The far plane distance.
136136
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
137137
* @return {RenderTarget} The resulting PMREM.
138+
* @see fromSceneAsync
138139
*/
139140
fromScene( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) {
140141

@@ -175,6 +176,21 @@ class PMREMGenerator {
175176

176177
}
177178

179+
/**
180+
* Generates a PMREM from a supplied Scene, which can be faster than using an
181+
* image if networking bandwidth is low. Optional sigma specifies a blur radius
182+
* in radians to be applied to the scene before PMREM generation. Optional near
183+
* and far planes ensure the scene is rendered in its entirety (the cubeCamera
184+
* is placed at the origin).
185+
*
186+
* @param {Scene} scene - The scene to be captured.
187+
* @param {Number} [sigma=0] - The blur radius in radians.
188+
* @param {Number} [near=0.1] - The near plane distance.
189+
* @param {Number} [far=100] - The far plane distance.
190+
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
191+
* @return {Promise<RenderTarget>} The resulting PMREM.
192+
* @see fromScene
193+
*/
178194
async fromSceneAsync( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) {
179195

180196
if ( this._hasInitialized === false ) await this._renderer.init();
@@ -191,6 +207,7 @@ class PMREMGenerator {
191207
* @param {Texture} equirectangular - The equirectangular texture to be converted.
192208
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
193209
* @return {RenderTarget} The resulting PMREM.
210+
* @see fromEquirectangularAsync
194211
*/
195212
fromEquirectangular( equirectangular, renderTarget = null ) {
196213

@@ -212,6 +229,16 @@ class PMREMGenerator {
212229

213230
}
214231

232+
/**
233+
* Generates a PMREM from an equirectangular texture, which can be either LDR
234+
* or HDR. The ideal input image size is 1k (1024 x 512),
235+
* as this matches best with the 256 x 256 cubemap output.
236+
*
237+
* @param {Texture} equirectangular - The equirectangular texture to be converted.
238+
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
239+
* @return {Promise<RenderTarget>} The resulting PMREM.
240+
* @see fromEquirectangular
241+
*/
215242
async fromEquirectangularAsync( equirectangular, renderTarget = null ) {
216243

217244
if ( this._hasInitialized === false ) await this._renderer.init();
@@ -228,6 +255,7 @@ class PMREMGenerator {
228255
* @param {Texture} cubemap - The cubemap texture to be converted.
229256
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
230257
* @return {RenderTarget} The resulting PMREM.
258+
* @see fromCubemapAsync
231259
*/
232260
fromCubemap( cubemap, renderTarget = null ) {
233261

@@ -249,6 +277,16 @@ class PMREMGenerator {
249277

250278
}
251279

280+
/**
281+
* Generates a PMREM from an cubemap texture, which can be either LDR
282+
* or HDR. The ideal input cube size is 256 x 256,
283+
* with the 256 x 256 cubemap output.
284+
*
285+
* @param {Texture} cubemap - The cubemap texture to be converted.
286+
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
287+
* @return {Promise<RenderTarget>} The resulting PMREM.
288+
* @see fromCubemap
289+
*/
252290
async fromCubemapAsync( cubemap, renderTarget = null ) {
253291

254292
if ( this._hasInitialized === false ) await this._renderer.init();
@@ -260,6 +298,8 @@ class PMREMGenerator {
260298
/**
261299
* Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
262300
* your texture's network fetch for increased concurrency.
301+
*
302+
* @returns {Promise<void>}
263303
*/
264304
async compileCubemapShader() {
265305

@@ -275,6 +315,8 @@ class PMREMGenerator {
275315
/**
276316
* Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
277317
* your texture's network fetch for increased concurrency.
318+
*
319+
* @returns {Promise<void>}
278320
*/
279321
async compileEquirectangularShader() {
280322

src/renderers/webgl-fallback/WebGLBackend.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ class WebGLBackend extends Backend {
276276
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
277277
*
278278
* @async
279-
* @return {Promise} A Promise that resolves when synchronization has been finished.
279+
* @return {Promise<void>} A Promise that resolves when synchronization has been finished.
280280
*/
281281
async waitForGPU() {
282282

@@ -1247,7 +1247,7 @@ class WebGLBackend extends Backend {
12471247
* Creates a render pipeline for the given render object.
12481248
*
12491249
* @param {RenderObject} renderObject - The render object.
1250-
* @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
1250+
* @param {Array<Promise<void>>} promises - An array of compilation promises which are used in `compileAsync()`.
12511251
*/
12521252
createRenderPipeline( renderObject, promises ) {
12531253

src/renderers/webgpu/WebGPUBackend.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ class WebGPUBackend extends Backend {
150150
*
151151
* @async
152152
* @param {Renderer} renderer - The renderer.
153-
* @return {Promise} A Promise that resolves when the backend has been initialized.
153+
* @return {Promise<void>} A Promise that resolves when the backend has been initialized.
154154
*/
155155
async init( renderer ) {
156156

@@ -764,6 +764,7 @@ class WebGPUBackend extends Backend {
764764
*
765765
* @async
766766
* @param {RenderContext} renderContext - The render context.
767+
* @return {Promise<void>} A Promise that resolves when the occlusion query results have been processed.
767768
*/
768769
async resolveOccludedAsync( renderContext ) {
769770

@@ -1063,7 +1064,7 @@ class WebGPUBackend extends Backend {
10631064
* the CPU waits for the GPU to complete its operation (e.g. a compute task).
10641065
*
10651066
* @async
1066-
* @return {Promise} A Promise that resolves when synchronization has been finished.
1067+
* @return {Promise<void>} A Promise that resolves when synchronization has been finished.
10671068
*/
10681069
async waitForGPU() {
10691070

@@ -1539,7 +1540,7 @@ class WebGPUBackend extends Backend {
15391540
* @async
15401541
* @param {RenderContext} renderContext - The render context.
15411542
* @param {String} type - The render context.
1542-
* @return {Promise} A Promise that resolves when the time stamp has been computed.
1543+
* @return {Promise<void>} A Promise that resolves when the time stamp has been computed.
15431544
*/
15441545
async resolveTimestampAsync( renderContext, type = 'render' ) {
15451546

@@ -1617,7 +1618,7 @@ class WebGPUBackend extends Backend {
16171618
* Creates a render pipeline for the given render object.
16181619
*
16191620
* @param {RenderObject} renderObject - The render object.
1620-
* @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
1621+
* @param {Array<Promise<void>>} promises - An array of compilation promises which are used in `compileAsync()`.
16211622
*/
16221623
createRenderPipeline( renderObject, promises ) {
16231624

src/renderers/webgpu/utils/WebGPUPipelineUtils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class WebGPUPipelineUtils {
5555
* Creates a render pipeline for the given render object.
5656
*
5757
* @param {RenderObject} renderObject - The render object.
58-
* @param {Array<Promise>} promises - An array of compilation promises which are used in `compileAsync()`.
58+
* @param {Array<Promise<void>>} promises - An array of compilation promises which are used in `compileAsync()`.
5959
*/
6060
createRenderPipeline( renderObject, promises ) {
6161

0 commit comments

Comments
 (0)