Skip to content

Commit b56c7c3

Browse files
committed
Use lazy-loading helper for PBR material imports
1 parent 48d9dee commit b56c7c3

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

packages/dev/loaders/src/glTF/2.0/glTFLoader.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ import type { IMaterialLoadingAdapter } from "./materialLoadingAdapter";
9292
// Caching these dynamic imports gives a surprising perf boost (compared to importing them directly each time).
9393
const LazyAnimationGroupModulePromise = new Lazy(() => import("core/Animations/animationGroup"));
9494
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"));
9599

96100
export { GLTFFileLoader };
97101

@@ -2226,16 +2230,16 @@ export class GLTFLoader implements IGLTFLoader {
22262230
*/
22272231
private async _ensurePbrMaterialClassesAsync(): Promise<void> {
22282232
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;
22322236
this._pbrMaterialAdapterClass = materialAdapterModule.OpenPBRMaterialLoadingAdapter;
2233-
const materialModule = await import("core/Materials/PBR/openPbrMaterial");
2237+
const materialModule = await LazyOpenPBRMaterialModulePromise.value;
22342238
this._pbrMaterialClass = materialModule.OpenPBRMaterial;
22352239
} else {
2236-
const materialAdapterModule = await import("./pbrMaterialLoadingAdapter");
2240+
const materialAdapterModule = await LazyPBRMaterialLoadingAdapterModulePromise.value;
22372241
this._pbrMaterialAdapterClass = materialAdapterModule.PBRMaterialLoadingAdapter;
2238-
const materialModule = await import("core/Materials/PBR/pbrMaterial");
2242+
const materialModule = await LazyPBRMaterialModulePromise.value;
22392243
this._pbrMaterialClass = materialModule.PBRMaterial;
22402244
}
22412245
}

0 commit comments

Comments
 (0)