Skip to content

Commit

Permalink
Docs: improve Promise typing (#30317)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Rigaud <[email protected]>
  • Loading branch information
s-rigaud and Samuel Rigaud authored Jan 13, 2025
1 parent 86c3bd3 commit acc17c6
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/nodes/code/ScriptableNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ class ScriptableNode extends Node {
*
* @param {String} name - The function name.
* @param {...Any} params - A list of parameters.
* @return {Any} The result of the function call.
* @return {Promise<Any>} The result of the function call.
*/
async callAsync( name, ...params ) {

Expand Down
2 changes: 1 addition & 1 deletion src/renderers/common/Pipelines.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ class Pipelines extends DataMap {
* @param {ProgrammableStage} stageVertex - The programmable stage representing the vertex shader.
* @param {ProgrammableStage} stageFragment - The programmable stage representing the fragment shader.
* @param {String} cacheKey - The cache key.
* @param {Array} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @param {Array<Promise>?} promises - An array of compilation promises which is only relevant in context of `Renderer.compileAsync()`.
* @return {ComputePipeline} The compute pipeline.
*/
_getRenderPipeline( renderObject, stageVertex, stageFragment, cacheKey, promises ) {
Expand Down
4 changes: 2 additions & 2 deletions src/renderers/common/Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -795,7 +795,7 @@ class Renderer {
* @param {Object3D} scene - The scene or 3D object to precompile.
* @param {Camera} camera - The camera that is used to render the scene.
* @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.
* @return {Promise} A Promise that resolves when the compile has been finished.
* @return {Promise<Array>} A Promise that resolves when the compile has been finished.
*/
async compileAsync( scene, camera, targetScene = null ) {

Expand Down Expand Up @@ -2187,7 +2187,7 @@ class Renderer {
*
* @async
* @param {Node|Array<Node>} computeNodes - The compute node(s).
* @return {Promise?} A Promise that resolve when the compute has finished.
* @return {Promise} A Promise that resolve when the compute has finished.
*/
async computeAsync( computeNodes ) {

Expand Down
42 changes: 42 additions & 0 deletions src/renderers/common/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class PMREMGenerator {
* @param {Number} [far=100] - The far plane distance.
* @param {RenderTarget?} [renderTarget=null] - The render target to use.
* @return {RenderTarget} The resulting PMREM.
* @see fromSceneAsync
*/
fromScene( scene, sigma = 0, near = 0.1, far = 100, renderTarget = null ) {

Expand Down Expand Up @@ -175,6 +176,21 @@ class PMREMGenerator {

}

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

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

Expand All @@ -212,6 +229,16 @@ class PMREMGenerator {

}

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

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

Expand All @@ -249,6 +277,16 @@ class PMREMGenerator {

}

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

if ( this._hasInitialized === false ) await this._renderer.init();
Expand All @@ -260,6 +298,8 @@ class PMREMGenerator {
/**
* Pre-compiles the cubemap shader. You can get faster start-up by invoking this method during
* your texture's network fetch for increased concurrency.
*
* @returns {Promise}
*/
async compileCubemapShader() {

Expand All @@ -275,6 +315,8 @@ class PMREMGenerator {
/**
* Pre-compiles the equirectangular shader. You can get faster start-up by invoking this method during
* your texture's network fetch for increased concurrency.
*
* @returns {Promise}
*/
async compileEquirectangularShader() {

Expand Down
1 change: 1 addition & 0 deletions src/renderers/webgpu/WebGPUBackend.js
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ class WebGPUBackend extends Backend {
*
* @async
* @param {RenderContext} renderContext - The render context.
* @return {Promise} A Promise that resolves when the occlusion query results have been processed.
*/
async resolveOccludedAsync( renderContext ) {

Expand Down

0 comments on commit acc17c6

Please sign in to comment.