@@ -92,6 +92,10 @@ import type { IMaterialLoadingAdapter } from "./materialLoadingAdapter";
92
92
// Caching these dynamic imports gives a surprising perf boost (compared to importing them directly each time).
93
93
const LazyAnimationGroupModulePromise = new Lazy ( ( ) => import ( "core/Animations/animationGroup" ) ) ;
94
94
const LazyLoaderAnimationModulePromise = new Lazy ( ( ) => import ( "./glTFLoaderAnimation" ) ) ;
95
+ const LazyOpenPBRMaterialLoadingAdapterModulePromise = new Lazy ( ( ) => import ( "./openPbrMaterialLoadingAdapter" ) ) ;
96
+ const LazyPBRMaterialLoadingAdapterModulePromise = new Lazy ( ( ) => import ( "./pbrMaterialLoadingAdapter" ) ) ;
97
+ const LazyOpenPBRMaterialModulePromise = new Lazy ( ( ) => import ( "core/Materials/PBR/openPbrMaterial" ) ) ;
98
+ const LazyPBRMaterialModulePromise = new Lazy ( ( ) => import ( "core/Materials/PBR/pbrMaterial" ) ) ;
95
99
96
100
export { GLTFFileLoader } ;
97
101
@@ -2226,16 +2230,16 @@ export class GLTFLoader implements IGLTFLoader {
2226
2230
*/
2227
2231
private async _ensurePbrMaterialClassesAsync ( ) : Promise < void > {
2228
2232
if ( ! this . _pbrMaterialClass || ! this . _pbrMaterialAdapterClass ) {
2229
- const openpbrExt = this . _extensions . find ( ( extension ) => extension . name === "KHR_materials_openpbr" ) ;
2230
- if ( this . parent . useOpenPBR || openpbrExt ) {
2231
- const materialAdapterModule = await import ( "./openPbrMaterialLoadingAdapter" ) ;
2233
+ const isOpenPbr = this . isExtensionUsed ( "KHR_materials_openpbr" ) ;
2234
+ if ( this . parent . useOpenPBR || isOpenPbr ) {
2235
+ const materialAdapterModule = await LazyOpenPBRMaterialLoadingAdapterModulePromise . value ;
2232
2236
this . _pbrMaterialAdapterClass = materialAdapterModule . OpenPBRMaterialLoadingAdapter ;
2233
- const materialModule = await import ( "core/Materials/PBR/openPbrMaterial" ) ;
2237
+ const materialModule = await LazyOpenPBRMaterialModulePromise . value ;
2234
2238
this . _pbrMaterialClass = materialModule . OpenPBRMaterial ;
2235
2239
} else {
2236
- const materialAdapterModule = await import ( "./pbrMaterialLoadingAdapter" ) ;
2240
+ const materialAdapterModule = await LazyPBRMaterialLoadingAdapterModulePromise . value ;
2237
2241
this . _pbrMaterialAdapterClass = materialAdapterModule . PBRMaterialLoadingAdapter ;
2238
- const materialModule = await import ( "core/Materials/PBR/pbrMaterial" ) ;
2242
+ const materialModule = await LazyPBRMaterialModulePromise . value ;
2239
2243
this . _pbrMaterialClass = materialModule . PBRMaterial ;
2240
2244
}
2241
2245
}
0 commit comments