Skip to content

Commit c9481ce

Browse files
author
Babylon.js Platform
committed
Merge remote-tracking branch 'origin/master'
2 parents 12c4851 + 2c653e9 commit c9481ce

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

packages/dev/core/src/node.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,10 @@ export class Node implements IBehaviorAware<Node> {
400400
if (this._scene.isLoading && !attachImmediately) {
401401
// We defer the attach when the scene will be loaded
402402
this._scene.onDataLoadedObservable.addOnce(() => {
403-
behavior.attach(this);
403+
// Make sure the behavior has not been removed.
404+
if (this._behaviors.includes(behavior)) {
405+
behavior.attach(this);
406+
}
404407
});
405408
} else {
406409
behavior.attach(this);

packages/tools/viewer/src/viewer.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -918,7 +918,6 @@ export class Viewer implements IDisposable {
918918
defaultMaterial.metallic = 0;
919919
defaultMaterial.roughness = 1;
920920
defaultMaterial.baseDiffuseRoughness = 1;
921-
defaultMaterial.environmentIntensity = 0.7;
922921
defaultMaterial.microSurface = 0;
923922
scene.defaultMaterial = defaultMaterial;
924923

@@ -1695,8 +1694,11 @@ export class Viewer implements IDisposable {
16951694
}
16961695
});
16971696

1698-
// If there are PBR materials after the model load operation and an environment texture is not loaded, load the default environment.
1699-
if (!this._scene.environmentTexture && this._loadedModels.some((model) => model.assetContainer.materials.some((material) => material instanceof PBRMaterial))) {
1697+
const hasPBRMaterials = this._loadedModels.some((model) => model.assetContainer.materials.some((material) => material instanceof PBRMaterial));
1698+
const usesDefaultMaterial = this._loadedModels.some((model) => model.assetContainer.meshes.some((mesh) => !mesh.material));
1699+
// If PBR is used (either explicitly, or implicitly by a mesh not having a material and therefore using the default PBRMaterial)
1700+
// and an environment texture is not already loaded, then load the default environment.
1701+
if (!this._scene.environmentTexture && (hasPBRMaterials || usesDefaultMaterial)) {
17001702
await this.resetEnvironment({ lighting: true }, abortSignal);
17011703
}
17021704

@@ -2875,13 +2877,12 @@ export class Viewer implements IDisposable {
28752877
} else {
28762878
const hasModelProvidedLights = this._loadedModels.some((model) => model.assetContainer.lights.length > 0);
28772879
const hasImageBasedLighting = !!this._reflectionTexture;
2878-
const hasMaterials = this._loadedModels.some((model) => model.assetContainer.materials.length > 0);
28792880
const hasNonPBRMaterials = this._loadedModels.some((model) => model.assetContainer.materials.some((material) => !(material instanceof PBRMaterial)));
28802881

28812882
if (hasModelProvidedLights) {
28822883
shouldHaveDefaultLight = false;
28832884
} else {
2884-
shouldHaveDefaultLight = !hasImageBasedLighting || !hasMaterials || hasNonPBRMaterials;
2885+
shouldHaveDefaultLight = !hasImageBasedLighting || hasNonPBRMaterials;
28852886
}
28862887
}
28872888

0 commit comments

Comments
 (0)