Skip to content

Commit efd48e4

Browse files
committed
Don't throw an error if decal map plugin can't be instantiated
1 parent 9e9e9da commit efd48e4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

packages/dev/core/src/Materials/PBR/pbrMaterial.decalMap.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import type { Nullable } from "core/types";
12
import { DecalMapConfiguration } from "../material.decalMapConfiguration";
23
import { PBRBaseMaterial } from "./pbrBaseMaterial";
34

45
declare module "./pbrBaseMaterial" {
56
export interface PBRBaseMaterial {
67
/** @internal */
7-
_decalMap: DecalMapConfiguration;
8+
_decalMap: Nullable<DecalMapConfiguration>;
89

910
/**
1011
* Defines the decal map parameters for the material.
1112
*/
12-
decalMap: DecalMapConfiguration;
13+
decalMap: Nullable<DecalMapConfiguration>;
1314
}
1415
}
1516

1617
Object.defineProperty(PBRBaseMaterial.prototype, "decalMap", {
1718
get: function (this: PBRBaseMaterial) {
1819
if (!this._decalMap) {
20+
if (this._uniformBufferLayoutBuilt) {
21+
// Material already used to display a mesh, so it's invalid to add the decal map plugin at that point
22+
// Returns null instead of having new DecalMapConfiguration throws an exception
23+
return null;
24+
}
25+
1926
this._decalMap = new DecalMapConfiguration(this);
2027
}
2128
return this._decalMap;

packages/dev/core/src/Materials/standardMaterial.decalMap.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1+
import type { Nullable } from "core/types";
12
import { DecalMapConfiguration } from "./material.decalMapConfiguration";
23
import { StandardMaterial } from "./standardMaterial";
34

45
declare module "./standardMaterial" {
56
export interface StandardMaterial {
67
/** @internal */
7-
_decalMap: DecalMapConfiguration;
8+
_decalMap: Nullable<DecalMapConfiguration>;
89

910
/**
1011
* Defines the decal map parameters for the material.
1112
*/
12-
decalMap: DecalMapConfiguration;
13+
decalMap: Nullable<DecalMapConfiguration>;
1314
}
1415
}
1516

1617
Object.defineProperty(StandardMaterial.prototype, "decalMap", {
1718
get: function (this: StandardMaterial) {
1819
if (!this._decalMap) {
20+
if (this._uniformBufferLayoutBuilt) {
21+
// Material already used to display a mesh, so it's invalid to add the decal map plugin at that point
22+
// Returns null instead of having new DecalMapConfiguration throws an exception
23+
return null;
24+
}
25+
1926
this._decalMap = new DecalMapConfiguration(this);
2027
}
2128
return this._decalMap;

0 commit comments

Comments
 (0)