Skip to content

Commit

Permalink
PMREMGenerator: Add fromSceneAsync() (#29951)
Browse files Browse the repository at this point in the history
* Add `fromSceneAsync`

* move _hasInitialized to private
  • Loading branch information
sunag authored Nov 24, 2024
1 parent 05cfdd9 commit 34ba512
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions src/renderers/common/extras/PMREMGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,12 @@ class PMREMGenerator {

}

get _hasInitialized() {

return this._renderer.hasInitialized();

}

/**
* 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
Expand All @@ -125,6 +131,14 @@ class PMREMGenerator {
*/
fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {

if ( this._hasInitialized === false ) {

console.warn( 'THREE.PMREMGenerator: .fromScene() called before the backend is initialized. Try using .fromSceneAsync() instead.' );

return this.fromSceneAsync( scene, sigma, near, far );

}

_oldTarget = this._renderer.getRenderTarget();
_oldActiveCubeFace = this._renderer.getActiveCubeFace();
_oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
Expand All @@ -150,13 +164,37 @@ class PMREMGenerator {

}

async fromSceneAsync( scene, sigma = 0, near = 0.1, far = 100 ) {

if ( this._hasInitialized === false ) await this._renderer.init();

return this.fromScene( scene, sigma, near, far );

}

/**
* 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.
*/
fromEquirectangular( equirectangular, renderTarget = null ) {

if ( this._hasInitialized === false ) {

console.warn( 'THREE.PMREMGenerator: .fromEquirectangular() called before the backend is initialized. Try using .fromEquirectangularAsync() instead.' );

return this.fromEquirectangularAsync( equirectangular, renderTarget );

}

return this._fromTexture( equirectangular, renderTarget );

}

async fromEquirectangularAsync( equirectangular, renderTarget = null ) {

if ( this._hasInitialized === false ) await this._renderer.init();

return this._fromTexture( equirectangular, renderTarget );

}
Expand All @@ -168,6 +206,22 @@ class PMREMGenerator {
*/
fromCubemap( cubemap, renderTarget = null ) {

if ( this._hasInitialized === false ) {

console.warn( 'THREE.PMREMGenerator: .fromCubemap() called before the backend is initialized. Try using .fromCubemapAsync() instead.' );

return this.fromCubemapAsync( cubemap, renderTarget );

}

return this._fromTexture( cubemap, renderTarget );

}

async fromCubemapAsync( cubemap, renderTarget = null ) {

if ( this._hasInitialized === false ) await this._renderer.init();

return this._fromTexture( cubemap, renderTarget );

}
Expand Down

0 comments on commit 34ba512

Please sign in to comment.