Skip to content
Draft
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: 29 additions & 25 deletions packages/dev/loaders/src/glTF/2.0/glTFLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -433,16 +433,18 @@ export class GLTFLoader implements IGLTFLoader {

await this._loadExtensionsAsync();

if (this.parent.useOpenPBR) {
const materialAdapterModule = await import("./openPbrMaterialLoadingAdapter");
this._pbrMaterialAdapterClass = materialAdapterModule.OpenPBRMaterialLoadingAdapter;
const materialModule = await import("core/Materials/PBR/openPbrMaterial");
this._pbrMaterialClass = materialModule.OpenPBRMaterial;
} else {
const materialAdapterModule = await import("./pbrMaterialLoadingAdapter");
this._pbrMaterialAdapterClass = materialAdapterModule.PBRMaterialLoadingAdapter;
const materialModule = await import("core/Materials/PBR/pbrMaterial");
this._pbrMaterialClass = materialModule.PBRMaterial;
if (!this.parent.skipMaterials) {
if (this.parent.useOpenPBR) {
const materialAdapterModule = await import("./openPbrMaterialLoadingAdapter");
this._pbrMaterialAdapterClass = materialAdapterModule.OpenPBRMaterialLoadingAdapter;
const materialModule = await import("core/Materials/PBR/openPbrMaterial");
this._pbrMaterialClass = materialModule.OpenPBRMaterial;
} else {
const materialAdapterModule = await import("./pbrMaterialLoadingAdapter");
this._pbrMaterialAdapterClass = materialAdapterModule.PBRMaterialLoadingAdapter;
const materialModule = await import("core/Materials/PBR/pbrMaterial");
this._pbrMaterialClass = materialModule.PBRMaterial;
}
}

const loadingToReadyCounterName = `${GLTFLoaderState[GLTFLoaderState.LOADING]} => ${GLTFLoaderState[GLTFLoaderState.READY]}`;
Expand Down Expand Up @@ -1109,22 +1111,24 @@ export class GLTFLoader implements IGLTFLoader {
})
);

const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
if (primitive.material == undefined) {
let babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
if (!babylonMaterial) {
babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
if (!this.parent.skipMaterials) {
const babylonDrawMode = GLTFLoader._GetDrawMode(context, primitive.mode);
if (primitive.material == undefined) {
let babylonMaterial = this._defaultBabylonMaterialData[babylonDrawMode];
if (!babylonMaterial) {
babylonMaterial = this._createDefaultMaterial("__GLTFLoader._default", babylonDrawMode);
this._parent.onMaterialLoadedObservable.notifyObservers(babylonMaterial);
this._defaultBabylonMaterialData[babylonDrawMode] = babylonMaterial;
}
babylonMesh.material = babylonMaterial;
} else {
const material = ArrayItem.Get(`${context}/material`, this._gltf.materials, primitive.material);
promises.push(
this._loadMaterialAsync(`/materials/${material.index}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {
babylonMesh.material = babylonMaterial;
})
);
}
babylonMesh.material = babylonMaterial;
} else if (!this.parent.skipMaterials) {
const material = ArrayItem.Get(`${context}/material`, this._gltf.materials, primitive.material);
promises.push(
this._loadMaterialAsync(`/materials/${material.index}`, material, babylonMesh, babylonDrawMode, (babylonMaterial) => {
babylonMesh.material = babylonMaterial;
})
);
}

promise = Promise.all(promises);
Expand Down