Skip to content

Commit 24a9602

Browse files
Merge pull request #214 from felixmariotto/fix-210
make sure no uniform get unset value
2 parents 1505a0c + 62fe771 commit 24a9602

File tree

3 files changed

+36
-26
lines changed

3 files changed

+36
-26
lines changed

src/components/core/MaterialManager.js

+16-16
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@ export default function MaterialManager( Base ) {
2525
super( options );
2626

2727
this.textUniforms = {
28-
u_texture: { value: null },
29-
u_color: { value: null },
30-
u_opacity: { value: null },
31-
u_pxRange: { value: null },
32-
u_useRGSS: { value: null },
28+
u_texture: { value: this.getFontTexture() },
29+
u_color: { value: this.getFontColor() },
30+
u_opacity: { value: this.getFontOpacity() },
31+
u_pxRange: { value: this.getFontPXRange() },
32+
u_useRGSS: { value: this.getFontSupersampling() },
3333
};
3434

3535
this.backgroundUniforms = {
36-
u_texture: { value: null },
37-
u_color: { value: null },
38-
u_opacity: { value: null },
39-
u_backgroundMapping: { value: null },
40-
u_borderWidth: { value: null },
41-
u_borderColor: { value: null },
42-
u_borderRadiusTopLeft: { value: null },
43-
u_borderRadiusTopRight: { value: null },
44-
u_borderRadiusBottomRight: { value: null },
45-
u_borderRadiusBottomLeft: { value: null },
46-
u_borderOpacity: { value: null },
36+
u_texture: { value: this.getBackgroundTexture() },
37+
u_color: { value: this.getBackgroundColor() },
38+
u_opacity: { value: this.getBackgroundOpacity() },
39+
u_backgroundMapping: { value: this.getBackgroundSize() },
40+
u_borderWidth: { value: this.getBorderWidth() },
41+
u_borderColor: { value: this.getBorderColor() },
42+
u_borderRadiusTopLeft: { value: this.getBorderRadius() },
43+
u_borderRadiusTopRight: { value: this.getBorderRadius() },
44+
u_borderRadiusBottomRight: { value: this.getBorderRadius() },
45+
u_borderRadiusBottomLeft: { value: this.getBorderRadius() },
46+
u_borderOpacity: { value: this.getBorderOpacity() },
4747
u_size: { value: new Vector2( 1, 1 ) },
4848
u_tSize: { value: new Vector2( 1, 1 ) }
4949
};

src/components/core/MeshUIComponent.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,17 @@ export default function MeshUIComponent( Base ) {
144144

145145
getFontTexture() {
146146

147-
return this._getProperty( 'fontTexture' );
147+
if ( this[ 'fontTexture' ] === undefined && this.parentUI ) {
148+
149+
return this.parent._getProperty( 'fontTexture' );
150+
151+
} else if ( this[ 'fontTexture' ] !== undefined ) {
152+
153+
return this[ 'fontTexture' ];
154+
155+
}
156+
157+
return DEFAULTS.getDefaultTexture();
148158

149159
}
150160

@@ -281,7 +291,7 @@ export default function MeshUIComponent( Base ) {
281291

282292
getBackgroundTexture() {
283293

284-
return this.backgroundTexture || DEFAULTS.backgroundTexture();
294+
return this.backgroundTexture || DEFAULTS.getDefaultTexture();
285295

286296
}
287297

src/utils/Defaults.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export default {
2121
contentDirection,
2222
alignItems,
2323
justifyContent,
24-
fontTexture: null,
2524
textAlign,
2625
textType: 'MSDF',
2726
fontColor: new Color( 0xffffff ),
@@ -38,28 +37,29 @@ export default {
3837
backgroundOpacity: 0.8,
3938
backgroundOpaqueOpacity: 1.0,
4039
// this default value is a function to avoid initialization issues (see issue #126)
41-
backgroundTexture: makeBackgroundTexture,
40+
getDefaultTexture,
4241
hiddenOverflow: false,
4342
letterSpacing: 0
4443
};
4544

4645
//
47-
let defaultBgTexture;
4846

49-
function makeBackgroundTexture() {
47+
let defaultTexture;
5048

51-
if ( !defaultBgTexture ) {
49+
function getDefaultTexture() {
50+
51+
if ( !defaultTexture ) {
5252

5353
const ctx = document.createElement( 'canvas' ).getContext( '2d' );
5454
ctx.canvas.width = 1;
5555
ctx.canvas.height = 1;
5656
ctx.fillStyle = '#ffffff';
5757
ctx.fillRect( 0, 0, 1, 1 );
58-
defaultBgTexture = new CanvasTexture( ctx.canvas );
59-
defaultBgTexture.isDefault = true;
58+
defaultTexture = new CanvasTexture( ctx.canvas );
59+
defaultTexture.isDefault = true;
6060

6161
}
6262

63-
return defaultBgTexture;
63+
return defaultTexture;
6464

6565
}

0 commit comments

Comments
 (0)