@@ -397,11 +397,14 @@ export class KHR_materials_transmission implements IGLTFLoaderExtension {
397
397
if ( ! ( babylonMaterial instanceof PBRMaterialClass ) ) {
398
398
throw new Error ( `${ context } : Material type not supported` ) ;
399
399
}
400
+ if ( useOpenPBR ) {
401
+ return Promise . resolve ( ) ;
402
+ }
400
403
401
404
let transmissionWeight = 0.0 ;
402
405
let transmissionWeightTexture : Nullable < BaseTexture > = null ;
403
406
404
- const promises = new Array < Promise < any > > ( ) ;
407
+ let texturePromise = new Promise < Nullable < BaseTexture > > ( ( resolve ) => resolve ( null ) ) ;
405
408
if ( extension . transmissionFactor !== undefined ) {
406
409
transmissionWeight = extension . transmissionFactor ;
407
410
} else {
@@ -410,43 +413,40 @@ export class KHR_materials_transmission implements IGLTFLoaderExtension {
410
413
if ( extension . transmissionTexture ) {
411
414
( extension . transmissionTexture as ITextureInfo ) . nonColorData = true ;
412
415
// eslint-disable-next-line github/no-then
413
- promises . push (
414
- this . _loader . loadTextureInfoAsync ( `${ context } /transmissionTexture` , extension . transmissionTexture , ( texture : BaseTexture ) => {
415
- texture . name = `${ babylonMaterial . name } (Transmission)` ;
416
- transmissionWeightTexture = texture ;
417
- } )
418
- ) ;
416
+ texturePromise = this . _loader . loadTextureInfoAsync ( `${ context } /transmissionTexture` , extension . transmissionTexture , ( texture : BaseTexture ) => {
417
+ texture . name = `${ babylonMaterial . name } (Transmission)` ;
418
+ transmissionWeightTexture = texture ;
419
+ } ) ;
419
420
}
420
421
421
- // eslint-disable-next-line github/no-then
422
- return Promise . all ( promises ) . then ( ( ) => {
423
- if ( useOpenPBR ) {
424
- return ;
425
- }
426
- const pbrMaterial = babylonMaterial as PBRMaterial ;
422
+ const pbrMaterial = babylonMaterial as PBRMaterial ;
427
423
428
- // Enables "refraction" texture which represents transmitted light.
429
- pbrMaterial . subSurface . isRefractionEnabled = transmissionWeight !== 0 ;
424
+ // Enables "refraction" texture which represents transmitted light.
425
+ pbrMaterial . subSurface . isRefractionEnabled = transmissionWeight !== 0 ;
430
426
431
- // Since this extension models thin-surface transmission only, we must make IOR = 1.0
432
- pbrMaterial . subSurface . volumeIndexOfRefraction = 1.0 ;
427
+ // Since this extension models thin-surface transmission only, we must make IOR = 1.0
428
+ pbrMaterial . subSurface . volumeIndexOfRefraction = 1.0 ;
433
429
434
- // Albedo colour will tint transmission.
435
- pbrMaterial . subSurface . useAlbedoToTintRefraction = true ;
430
+ // Albedo colour will tint transmission.
431
+ pbrMaterial . subSurface . useAlbedoToTintRefraction = true ;
436
432
437
- pbrMaterial . subSurface . refractionIntensity = transmissionWeight ;
433
+ pbrMaterial . subSurface . refractionIntensity = transmissionWeight ;
438
434
439
- if ( transmissionWeight ) {
440
- const scene = pbrMaterial . getScene ( ) as unknown as ITransmissionHelperHolder ;
441
- if ( pbrMaterial . subSurface . refractionIntensity && ! scene . _transmissionHelper ) {
442
- new TransmissionHelper ( { } , pbrMaterial . getScene ( ) ) ;
443
- } else if ( pbrMaterial . subSurface . refractionIntensity && ! scene . _transmissionHelper ?. _isRenderTargetValid ( ) ) {
444
- // If the render target is not valid, recreate it.
445
- scene . _transmissionHelper ?. _setupRenderTargets ( ) ;
446
- }
435
+ if ( transmissionWeight ) {
436
+ const scene = pbrMaterial . getScene ( ) as unknown as ITransmissionHelperHolder ;
437
+ if ( pbrMaterial . subSurface . refractionIntensity && ! scene . _transmissionHelper ) {
438
+ new TransmissionHelper ( { } , pbrMaterial . getScene ( ) ) ;
439
+ } else if ( pbrMaterial . subSurface . refractionIntensity && ! scene . _transmissionHelper ?. _isRenderTargetValid ( ) ) {
440
+ // If the render target is not valid, recreate it.
441
+ scene . _transmissionHelper ?. _setupRenderTargets ( ) ;
447
442
}
448
- pbrMaterial . subSurface . minimumThickness = 0.0 ;
449
- pbrMaterial . subSurface . maximumThickness = 0.0 ;
443
+ }
444
+
445
+ pbrMaterial . subSurface . minimumThickness = 0.0 ;
446
+ pbrMaterial . subSurface . maximumThickness = 0.0 ;
447
+
448
+ // eslint-disable-next-line github/no-then
449
+ return texturePromise . then ( ( ) => {
450
450
pbrMaterial . subSurface . refractionIntensityTexture = transmissionWeightTexture ;
451
451
pbrMaterial . subSurface . useGltfStyleTextures = true ;
452
452
} ) ;
0 commit comments