Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PMREMGenerator: Add fromSceneAsync() #29951

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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