laymur 0.2.11 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/elements/UIElement.d.ts +0 -12
- package/dist/elements/UINineSline.d.ts +136 -4
- package/dist/elements/UIProgress.d.ts +123 -1
- package/dist/elements/UIScene.d.ts +3 -12
- package/dist/elements/UIText.d.ts +7 -14
- package/dist/index.js +490 -242
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/layers/UILayer.d.ts +4 -2
- package/dist/materials/UINineSliceMaterial.d.ts +18 -5
- package/dist/materials/UIProgressMaterial.d.ts +2 -0
- package/dist/miscellaneous/UINineSliceBorder.d.ts +21 -0
- package/dist/wrappers/UISceneWrapper.d.ts +2 -1
- package/package.json +2 -1
- package/dist/materials/UIInstancedMaterial.d.ts +0 -0
package/dist/index.js
CHANGED
|
@@ -1826,7 +1826,12 @@ var UIAnchorMode;
|
|
|
1826
1826
|
UIAnchorMode[UIAnchorMode["POSITION_ROTATION_SCALE"] = 1] = "POSITION_ROTATION_SCALE";
|
|
1827
1827
|
})(UIAnchorMode || (UIAnchorMode = {}));
|
|
1828
1828
|
|
|
1829
|
-
|
|
1829
|
+
let originalClearColor = new Color();
|
|
1830
|
+
let originalClearAlpha = 0;
|
|
1831
|
+
let originalAutoClear = false;
|
|
1832
|
+
let originalAutoClearColor = false;
|
|
1833
|
+
let originalAutoClearDepth = false;
|
|
1834
|
+
let originalAutoClearStencil = false;
|
|
1830
1835
|
class UISceneWrapper {
|
|
1831
1836
|
constructor(w, h) {
|
|
1832
1837
|
this._private_scene = new Scene();
|
|
@@ -1893,14 +1898,13 @@ class UISceneWrapper {
|
|
|
1893
1898
|
getSortedVisibleElements() {
|
|
1894
1899
|
return Array.from(this._private_elements.keys()).sort((a, b) => this.getZIndex(a) - this.getZIndex(b));
|
|
1895
1900
|
}
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
const originalAutoClearStencil = renderer.autoClearStencil;
|
|
1901
|
+
prepareRender(renderer) {
|
|
1902
|
+
originalClearColor = renderer.getClearColor(originalClearColor);
|
|
1903
|
+
originalClearAlpha = renderer.getClearAlpha();
|
|
1904
|
+
originalAutoClear = renderer.autoClear;
|
|
1905
|
+
originalAutoClearColor = renderer.autoClearColor;
|
|
1906
|
+
originalAutoClearDepth = renderer.autoClearDepth;
|
|
1907
|
+
originalAutoClearStencil = renderer.autoClearStencil;
|
|
1904
1908
|
renderer.autoClear = false;
|
|
1905
1909
|
renderer.autoClearColor = false;
|
|
1906
1910
|
renderer.autoClearDepth = false;
|
|
@@ -1931,11 +1935,11 @@ class UISceneWrapper {
|
|
|
1931
1935
|
object.scale.x = width;
|
|
1932
1936
|
object.scale.y = height;
|
|
1933
1937
|
object.rotation.z = micro.rotation;
|
|
1934
|
-
element["onBeforeRenderInternal"](renderer, deltaTime);
|
|
1935
1938
|
}
|
|
1939
|
+
}
|
|
1940
|
+
render(renderer) {
|
|
1936
1941
|
renderer.clear(false, true, true);
|
|
1937
1942
|
renderer.render(this._private_scene, this._private_camera);
|
|
1938
|
-
renderer.setRenderTarget(originalRenderTarget);
|
|
1939
1943
|
renderer.setClearColor(originalClearColor);
|
|
1940
1944
|
renderer.setClearAlpha(originalClearAlpha);
|
|
1941
1945
|
renderer.autoClear = originalAutoClear;
|
|
@@ -2307,6 +2311,8 @@ var UILayerEvent;
|
|
|
2307
2311
|
UILayerEvent["ORIENTATION_CHANGE"] = "orientation_change";
|
|
2308
2312
|
/** Emitted when the layer's visibility/interaction mode changes. */
|
|
2309
2313
|
UILayerEvent["MODE_CHANGE"] = "mode_change";
|
|
2314
|
+
/** Emitted before the layer is rendered. */
|
|
2315
|
+
UILayerEvent["WILL_RENDER"] = "will_render";
|
|
2310
2316
|
})(UILayerEvent || (UILayerEvent = {}));
|
|
2311
2317
|
/**
|
|
2312
2318
|
* Abstract base class for UI layout containers with constraint solving and rendering.
|
|
@@ -2429,7 +2435,9 @@ class UILayer extends i {
|
|
|
2429
2435
|
*/
|
|
2430
2436
|
renderInternal(renderer, deltaTime) {
|
|
2431
2437
|
if (this.mode !== UIMode.HIDDEN) {
|
|
2432
|
-
this.sceneWrapper.
|
|
2438
|
+
this.sceneWrapper.prepareRender(renderer);
|
|
2439
|
+
this.emit(UILayerEvent.WILL_RENDER, renderer, deltaTime, this);
|
|
2440
|
+
this.sceneWrapper.render(renderer);
|
|
2433
2441
|
}
|
|
2434
2442
|
}
|
|
2435
2443
|
/**
|
|
@@ -4188,24 +4196,13 @@ class UIElement extends UIAnchor {
|
|
|
4188
4196
|
}
|
|
4189
4197
|
return isClicked;
|
|
4190
4198
|
}
|
|
4191
|
-
/**
|
|
4192
|
-
* Internal method called before rendering each frame.
|
|
4193
|
-
*
|
|
4194
|
-
* This is a hook method that can be overridden by subclasses to perform
|
|
4195
|
-
* pre-render operations such as updating animations, transforms, or
|
|
4196
|
-
* other dynamic properties.
|
|
4197
|
-
*
|
|
4198
|
-
* @param renderer - The WebGL renderer instance
|
|
4199
|
-
* @param deltaTime - Time elapsed since the last frame in seconds
|
|
4200
|
-
*/
|
|
4201
|
-
["onBeforeRenderInternal"](
|
|
4202
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- empty basic method, parameters unused
|
|
4203
|
-
renderer,
|
|
4204
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- empty basic method, parameters unused
|
|
4205
|
-
deltaTime) { }
|
|
4206
4199
|
}
|
|
4207
4200
|
|
|
4208
|
-
|
|
4201
|
+
var fragmentShader$2 = "uniform sampler2D map;\nuniform float opacity;\nuniform vec3 color;\nuniform float alphaTest;\nvarying vec2 vUv;\n\nvoid main() {\n vec4 diffuseColor = texture2D(map, vUv);\n #include <alphatest_fragment>\n gl_FragColor = vec4(diffuseColor.rgb * color, diffuseColor.a * opacity);\n #include <colorspace_fragment>\n}\n";
|
|
4202
|
+
|
|
4203
|
+
var vertexShader$2 = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
4204
|
+
|
|
4205
|
+
const DEFAULT_ALPHA_TEST$2 = 0.25;
|
|
4209
4206
|
class UIMaterial extends ShaderMaterial {
|
|
4210
4207
|
constructor(map) {
|
|
4211
4208
|
super({
|
|
@@ -4213,31 +4210,12 @@ class UIMaterial extends ShaderMaterial {
|
|
|
4213
4210
|
map: { value: map },
|
|
4214
4211
|
opacity: { value: 1.0 },
|
|
4215
4212
|
color: { value: new Color(1.0, 1.0, 1.0) },
|
|
4216
|
-
alphaTest: { value: DEFAULT_ALPHA_TEST$
|
|
4213
|
+
alphaTest: { value: DEFAULT_ALPHA_TEST$2 },
|
|
4217
4214
|
},
|
|
4218
|
-
vertexShader:
|
|
4219
|
-
|
|
4220
|
-
void main() {
|
|
4221
|
-
vUv = uv;
|
|
4222
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
4223
|
-
}
|
|
4224
|
-
`,
|
|
4225
|
-
fragmentShader: /* glsl */ `
|
|
4226
|
-
uniform sampler2D map;
|
|
4227
|
-
uniform float opacity;
|
|
4228
|
-
uniform vec3 color;
|
|
4229
|
-
uniform float alphaTest;
|
|
4230
|
-
varying vec2 vUv;
|
|
4231
|
-
|
|
4232
|
-
void main() {
|
|
4233
|
-
vec4 diffuseColor = texture2D(map, vUv);
|
|
4234
|
-
#include <alphatest_fragment>
|
|
4235
|
-
gl_FragColor = vec4(diffuseColor.rgb * color, diffuseColor.a * opacity);
|
|
4236
|
-
#include <colorspace_fragment>
|
|
4237
|
-
}
|
|
4238
|
-
`,
|
|
4215
|
+
vertexShader: vertexShader$2,
|
|
4216
|
+
fragmentShader: fragmentShader$2,
|
|
4239
4217
|
transparent: false,
|
|
4240
|
-
alphaTest: DEFAULT_ALPHA_TEST$
|
|
4218
|
+
alphaTest: DEFAULT_ALPHA_TEST$2,
|
|
4241
4219
|
lights: false,
|
|
4242
4220
|
fog: false,
|
|
4243
4221
|
depthWrite: false,
|
|
@@ -4274,7 +4252,7 @@ class UIMaterial extends ShaderMaterial {
|
|
|
4274
4252
|
setTransparency(value) {
|
|
4275
4253
|
if (this.transparent !== value) {
|
|
4276
4254
|
this.transparent = value;
|
|
4277
|
-
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$
|
|
4255
|
+
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$2 : 0;
|
|
4278
4256
|
this.needsUpdate = true;
|
|
4279
4257
|
this.uniformsNeedUpdate = true;
|
|
4280
4258
|
}
|
|
@@ -4400,8 +4378,11 @@ class UIImage extends UIElement {
|
|
|
4400
4378
|
}
|
|
4401
4379
|
}
|
|
4402
4380
|
|
|
4403
|
-
|
|
4404
|
-
|
|
4381
|
+
var fragmentShader$1 = "uniform sampler2D map;\nuniform vec3 color;\nuniform float opacity;\nuniform float alphaTest;\nuniform vec4 sliceBorders;\nuniform vec2 quadSize;\nuniform vec2 textureSize;\nvarying vec2 vUv;\n\nvec2 calculateNineSliceUV(vec2 uv) {\n vec2 localUV = uv;\n\n float left = sliceBorders.x;\n float right = sliceBorders.y;\n float top = sliceBorders.z;\n float bottom = sliceBorders.w;\n\n float leftPx = left * textureSize.x;\n float rightPx = right * textureSize.x;\n float topPx = top * textureSize.y;\n float bottomPx = bottom * textureSize.y;\n\n float lB = leftPx / quadSize.x;\n float rB = 1.0 - (rightPx / quadSize.x);\n float tB = topPx / quadSize.y;\n float bB = 1.0 - (bottomPx / quadSize.y);\n\n {\n float regionL = step(uv.x, lB);\n float regionR = step(rB, uv.x);\n float regionM = 1.0 - regionL - regionR;\n\n float xL = uv.x * (left / lB);\n float xR = 1.0 - right + ((uv.x - rB) / (1.0 - rB)) * right;\n float xM = left + ((uv.x - lB) / (rB - lB)) * (1.0 - left - right);\n\n localUV.x = regionL * xL + regionM * xM + regionR * xR;\n }\n\n {\n float regionT = step(uv.y, tB);\n float regionB = step(bB, uv.y);\n float regionC = 1.0 - regionT - regionB;\n\n float yT = uv.y * (top / tB);\n float yB = 1.0 - bottom + ((uv.y - bB) / (1.0 - bB)) * bottom;\n float yC = top + ((uv.y - tB) / (bB - tB)) * (1.0 - top - bottom);\n\n localUV.y = regionT * yT + regionC * yC + regionB * yB;\n }\n\n return localUV;\n}\n\nvoid main() {\n vec4 textureColor = texture2D(map, calculateNineSliceUV(vUv));\n if (textureColor.a < alphaTest) {\n discard;\n }\n gl_FragColor = vec4(textureColor.rgb * color, textureColor.a * opacity);\n #include <colorspace_fragment>\n}\n";
|
|
4382
|
+
|
|
4383
|
+
var vertexShader$1 = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
4384
|
+
|
|
4385
|
+
const DEFAULT_ALPHA_TEST$1 = 0.025;
|
|
4405
4386
|
class UINineSliceMaterial extends ShaderMaterial {
|
|
4406
4387
|
constructor(texture) {
|
|
4407
4388
|
super({
|
|
@@ -4409,93 +4390,41 @@ class UINineSliceMaterial extends ShaderMaterial {
|
|
|
4409
4390
|
map: { value: texture },
|
|
4410
4391
|
color: { value: new Color(0xffffff) },
|
|
4411
4392
|
opacity: { value: 1.0 },
|
|
4412
|
-
alphaTest: { value: DEFAULT_ALPHA_TEST },
|
|
4393
|
+
alphaTest: { value: DEFAULT_ALPHA_TEST$1 },
|
|
4413
4394
|
sliceBorders: {
|
|
4414
|
-
value: new Vector4(
|
|
4415
|
-
}, // left, right, top, bottom (
|
|
4416
|
-
|
|
4417
|
-
quadSize: { value: new Vector2(1, 1) },
|
|
4395
|
+
value: new Vector4(0, 0, 0, 0),
|
|
4396
|
+
}, // left, right, top, bottom (in UV)
|
|
4397
|
+
quadSize: { value: new Vector2(1, 1) }, // width, height (in World)
|
|
4418
4398
|
textureSize: {
|
|
4419
4399
|
value: new Vector2(texture.image.width, texture.image.height),
|
|
4420
4400
|
},
|
|
4421
4401
|
},
|
|
4422
|
-
vertexShader:
|
|
4423
|
-
|
|
4424
|
-
void main() {
|
|
4425
|
-
vUv = uv;
|
|
4426
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
4427
|
-
}
|
|
4428
|
-
`,
|
|
4429
|
-
fragmentShader: /* glsl */ `
|
|
4430
|
-
uniform sampler2D map;
|
|
4431
|
-
uniform vec3 color;
|
|
4432
|
-
uniform float opacity;
|
|
4433
|
-
uniform float alphaTest;
|
|
4434
|
-
uniform vec4 sliceBorders;
|
|
4435
|
-
uniform vec4 atlasRect;
|
|
4436
|
-
uniform vec2 quadSize;
|
|
4437
|
-
uniform vec2 textureSize;
|
|
4438
|
-
varying vec2 vUv;
|
|
4439
|
-
|
|
4440
|
-
vec2 calcNineSliceUV(vec2 uv) {
|
|
4441
|
-
vec2 localUV = uv;
|
|
4442
|
-
|
|
4443
|
-
float left = sliceBorders.x;
|
|
4444
|
-
float right = sliceBorders.y;
|
|
4445
|
-
float top = sliceBorders.z;
|
|
4446
|
-
float bottom = sliceBorders.w;
|
|
4447
|
-
|
|
4448
|
-
vec2 texPx = textureSize * atlasRect.zw;
|
|
4449
|
-
|
|
4450
|
-
float leftPx = left * texPx.x;
|
|
4451
|
-
float rightPx = right * texPx.x;
|
|
4452
|
-
float topPx = top * texPx.y;
|
|
4453
|
-
float bottomPx = bottom * texPx.y;
|
|
4454
|
-
|
|
4455
|
-
float lB = leftPx / quadSize.x;
|
|
4456
|
-
float rB = 1.0 - (rightPx / quadSize.x);
|
|
4457
|
-
float tB = topPx / quadSize.y;
|
|
4458
|
-
float bB = 1.0 - (bottomPx / quadSize.y);
|
|
4459
|
-
|
|
4460
|
-
float regionL = step(uv.x, lB);
|
|
4461
|
-
float regionR = step(rB, uv.x);
|
|
4462
|
-
float regionM = 1.0 - regionL - regionR;
|
|
4463
|
-
|
|
4464
|
-
float xL = uv.x * (left / lB);
|
|
4465
|
-
float xR = 1.0 - right + ((uv.x - rB) / (1.0 - rB)) * right;
|
|
4466
|
-
float xM = left + ((uv.x - lB) / (rB - lB)) * (1.0 - left - right);
|
|
4467
|
-
|
|
4468
|
-
localUV.x = regionL * xL + regionM * xM + regionR * xR;
|
|
4469
|
-
|
|
4470
|
-
float regionT = step(uv.y, tB);
|
|
4471
|
-
float regionBtm = step(bB, uv.y);
|
|
4472
|
-
float regionC = 1.0 - regionT - regionBtm;
|
|
4473
|
-
|
|
4474
|
-
float yT = uv.y * (top / tB);
|
|
4475
|
-
float yB = 1.0 - bottom + ((uv.y - bB) / (1.0 - bB)) * bottom;
|
|
4476
|
-
float yC = top + ((uv.y - tB) / (bB - tB)) * (1.0 - top - bottom);
|
|
4477
|
-
|
|
4478
|
-
localUV.y = regionT * yT + regionC * yC + regionBtm * yB;
|
|
4479
|
-
|
|
4480
|
-
return atlasRect.xy + localUV * atlasRect.zw;
|
|
4481
|
-
}
|
|
4482
|
-
|
|
4483
|
-
void main() {
|
|
4484
|
-
vec2 uv = calcNineSliceUV(vUv);
|
|
4485
|
-
vec4 texel = texture2D(map, uv);
|
|
4486
|
-
if (texel.a < alphaTest) discard;
|
|
4487
|
-
gl_FragColor = vec4(texel.rgb * color, texel.a * opacity);
|
|
4488
|
-
#include <colorspace_fragment>
|
|
4489
|
-
}
|
|
4490
|
-
`,
|
|
4402
|
+
vertexShader: vertexShader$1,
|
|
4403
|
+
fragmentShader: fragmentShader$1,
|
|
4491
4404
|
transparent: false,
|
|
4492
|
-
alphaTest: DEFAULT_ALPHA_TEST,
|
|
4405
|
+
alphaTest: DEFAULT_ALPHA_TEST$1,
|
|
4493
4406
|
lights: false,
|
|
4494
4407
|
fog: false,
|
|
4495
4408
|
depthWrite: true,
|
|
4496
4409
|
depthTest: true,
|
|
4497
4410
|
});
|
|
4498
4411
|
}
|
|
4412
|
+
getSliceBorderLeft() {
|
|
4413
|
+
return this.uniforms.sliceBorders.value.x;
|
|
4414
|
+
}
|
|
4415
|
+
getSliceBorderRight() {
|
|
4416
|
+
return this.uniforms.sliceBorders.value.y;
|
|
4417
|
+
}
|
|
4418
|
+
getSliceBorderTop() {
|
|
4419
|
+
return this.uniforms.sliceBorders.value.z;
|
|
4420
|
+
}
|
|
4421
|
+
getSliceBorderBottom() {
|
|
4422
|
+
return this.uniforms.sliceBorders.value.w;
|
|
4423
|
+
}
|
|
4424
|
+
getQuadSize() {
|
|
4425
|
+
const quadSize = this.uniforms.quadSize.value;
|
|
4426
|
+
return { w: quadSize.x, h: quadSize.y };
|
|
4427
|
+
}
|
|
4499
4428
|
getTexture() {
|
|
4500
4429
|
return this.uniforms.map.value;
|
|
4501
4430
|
}
|
|
@@ -4508,23 +4437,43 @@ class UINineSliceMaterial extends ShaderMaterial {
|
|
|
4508
4437
|
getTransparency() {
|
|
4509
4438
|
return this.transparent;
|
|
4510
4439
|
}
|
|
4511
|
-
|
|
4440
|
+
setSliceBorderLeft(l) {
|
|
4441
|
+
this.uniforms.sliceBorders.value.x = l;
|
|
4442
|
+
this.uniformsNeedUpdate = true;
|
|
4443
|
+
return this;
|
|
4444
|
+
}
|
|
4445
|
+
setSliceBorderRight(r) {
|
|
4446
|
+
this.uniforms.sliceBorders.value.y = r;
|
|
4447
|
+
this.uniformsNeedUpdate = true;
|
|
4448
|
+
return this;
|
|
4449
|
+
}
|
|
4450
|
+
setSliceBorderTop(t) {
|
|
4451
|
+
this.uniforms.sliceBorders.value.z = t;
|
|
4452
|
+
this.uniformsNeedUpdate = true;
|
|
4453
|
+
return this;
|
|
4454
|
+
}
|
|
4455
|
+
setSliceBorderBottom(b) {
|
|
4456
|
+
this.uniforms.sliceBorders.value.w = b;
|
|
4457
|
+
this.uniformsNeedUpdate = true;
|
|
4458
|
+
return this;
|
|
4459
|
+
}
|
|
4460
|
+
setSliceBorder(l, r, t, b) {
|
|
4512
4461
|
this.uniforms.sliceBorders.value.set(l, r, t, b);
|
|
4513
4462
|
this.uniformsNeedUpdate = true;
|
|
4514
4463
|
return this;
|
|
4515
4464
|
}
|
|
4516
|
-
setQuadSize(
|
|
4517
|
-
this.uniforms.quadSize.value.set(
|
|
4465
|
+
setQuadSize(w, h) {
|
|
4466
|
+
this.uniforms.quadSize.value.set(w, h);
|
|
4518
4467
|
this.uniformsNeedUpdate = true;
|
|
4519
4468
|
return this;
|
|
4520
4469
|
}
|
|
4521
|
-
|
|
4522
|
-
this.uniforms.
|
|
4470
|
+
setTexture(value) {
|
|
4471
|
+
this.uniforms.map.value = value;
|
|
4523
4472
|
this.uniformsNeedUpdate = true;
|
|
4524
4473
|
return this;
|
|
4525
4474
|
}
|
|
4526
4475
|
setColor(color) {
|
|
4527
|
-
this.uniforms.color.value.
|
|
4476
|
+
this.uniforms.color.value.setHex(color);
|
|
4528
4477
|
this.uniformsNeedUpdate = true;
|
|
4529
4478
|
return this;
|
|
4530
4479
|
}
|
|
@@ -4533,27 +4482,263 @@ class UINineSliceMaterial extends ShaderMaterial {
|
|
|
4533
4482
|
this.uniformsNeedUpdate = true;
|
|
4534
4483
|
return this;
|
|
4535
4484
|
}
|
|
4485
|
+
setTransparency(value) {
|
|
4486
|
+
if (this.transparent !== value) {
|
|
4487
|
+
this.transparent = value;
|
|
4488
|
+
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST$1 : 0;
|
|
4489
|
+
this.needsUpdate = true;
|
|
4490
|
+
this.uniformsNeedUpdate = true;
|
|
4491
|
+
}
|
|
4492
|
+
return this;
|
|
4493
|
+
}
|
|
4536
4494
|
}
|
|
4537
4495
|
|
|
4496
|
+
const DEFAULT_SLICE_BORDER = 0.25;
|
|
4497
|
+
/**
|
|
4498
|
+
* Resolves various nine-slice border inputs into a normalized border object.
|
|
4499
|
+
*
|
|
4500
|
+
* @param value - The border value to resolve (can be number, partial object, or full object)
|
|
4501
|
+
* @returns Normalized border object with left, right, top, bottom properties
|
|
4502
|
+
*/
|
|
4503
|
+
function resolveNineSliceBorder(value) {
|
|
4504
|
+
// Handle null/undefined
|
|
4505
|
+
if (value === null || value === undefined) {
|
|
4506
|
+
return {
|
|
4507
|
+
left: DEFAULT_SLICE_BORDER,
|
|
4508
|
+
right: DEFAULT_SLICE_BORDER,
|
|
4509
|
+
top: DEFAULT_SLICE_BORDER,
|
|
4510
|
+
bottom: DEFAULT_SLICE_BORDER,
|
|
4511
|
+
};
|
|
4512
|
+
}
|
|
4513
|
+
// Handle number
|
|
4514
|
+
if (typeof value === "number") {
|
|
4515
|
+
return {
|
|
4516
|
+
left: value,
|
|
4517
|
+
right: value,
|
|
4518
|
+
top: value,
|
|
4519
|
+
bottom: value,
|
|
4520
|
+
};
|
|
4521
|
+
}
|
|
4522
|
+
// Handle object
|
|
4523
|
+
if (typeof value === "object") {
|
|
4524
|
+
const obj = value;
|
|
4525
|
+
// Handle { horizontal, vertical } format
|
|
4526
|
+
if ("horizontal" in obj && "vertical" in obj) {
|
|
4527
|
+
const horizontal = typeof obj.horizontal === "number"
|
|
4528
|
+
? obj.horizontal
|
|
4529
|
+
: DEFAULT_SLICE_BORDER;
|
|
4530
|
+
const vertical = typeof obj.vertical === "number" ? obj.vertical : DEFAULT_SLICE_BORDER;
|
|
4531
|
+
return {
|
|
4532
|
+
left: horizontal,
|
|
4533
|
+
right: horizontal,
|
|
4534
|
+
top: vertical,
|
|
4535
|
+
bottom: vertical,
|
|
4536
|
+
};
|
|
4537
|
+
}
|
|
4538
|
+
// Handle { left, right, top, bottom } format
|
|
4539
|
+
const left = typeof obj.left === "number" ? obj.left : DEFAULT_SLICE_BORDER;
|
|
4540
|
+
const right = typeof obj.right === "number" ? obj.right : DEFAULT_SLICE_BORDER;
|
|
4541
|
+
const top = typeof obj.top === "number" ? obj.top : DEFAULT_SLICE_BORDER;
|
|
4542
|
+
const bottom = typeof obj.bottom === "number" ? obj.bottom : DEFAULT_SLICE_BORDER;
|
|
4543
|
+
return { left, right, top, bottom };
|
|
4544
|
+
}
|
|
4545
|
+
// Fallback to default
|
|
4546
|
+
return {
|
|
4547
|
+
left: DEFAULT_SLICE_BORDER,
|
|
4548
|
+
right: DEFAULT_SLICE_BORDER,
|
|
4549
|
+
top: DEFAULT_SLICE_BORDER,
|
|
4550
|
+
bottom: DEFAULT_SLICE_BORDER,
|
|
4551
|
+
};
|
|
4552
|
+
}
|
|
4553
|
+
|
|
4554
|
+
/**
|
|
4555
|
+
* Nine-slice UI element for scalable images with preserved border regions.
|
|
4556
|
+
*
|
|
4557
|
+
* Nine-slice scaling divides an image into 9 regions: 4 corners, 4 edges, and 1 center.
|
|
4558
|
+
* The corners maintain their original size, edges scale in one dimension, and the center
|
|
4559
|
+
* scales in both dimensions. This technique is commonly used for creating scalable UI
|
|
4560
|
+
* panels, buttons, and borders that maintain visual quality at any size.
|
|
4561
|
+
*/
|
|
4538
4562
|
class UINineSlice extends UIElement {
|
|
4539
|
-
|
|
4563
|
+
/**
|
|
4564
|
+
* Creates a new nine-slice UI element.
|
|
4565
|
+
*
|
|
4566
|
+
* @param layer - The UI layer to add this element to
|
|
4567
|
+
* @param texture - The texture to use for nine-slice rendering
|
|
4568
|
+
* @param options - Configuration options for the nine-slice element
|
|
4569
|
+
*/
|
|
4570
|
+
constructor(layer, texture, options = {}) {
|
|
4540
4571
|
const w = texture.image.width;
|
|
4541
4572
|
const h = texture.image.height;
|
|
4542
4573
|
const material = new UINineSliceMaterial(texture);
|
|
4543
4574
|
const object = new Mesh(geometry, material);
|
|
4544
|
-
super(layer, x, y, w, h, object);
|
|
4575
|
+
super(layer, options.x ?? 0, options.y ?? 0, w, h, object);
|
|
4576
|
+
/**
|
|
4577
|
+
* Internal render callback that updates the material's quad size.
|
|
4578
|
+
* This ensures the nine-slice scaling works correctly with micro transformations.
|
|
4579
|
+
*/
|
|
4580
|
+
this._private_onWillRenderInternal = () => {
|
|
4581
|
+
this._private_material.setQuadSize(this.width * this.micro.scaleX, this.height * this.micro.scaleY);
|
|
4582
|
+
};
|
|
4583
|
+
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
4545
4584
|
this._private_material = material;
|
|
4546
4585
|
this._private_textureInternal = texture;
|
|
4586
|
+
const sliceBorder = resolveNineSliceBorder(options.sliceBorder);
|
|
4587
|
+
this._private_material.setSliceBorder(sliceBorder.left, sliceBorder.right, sliceBorder.top, sliceBorder.bottom);
|
|
4588
|
+
}
|
|
4589
|
+
/**
|
|
4590
|
+
* Gets the left border size for nine-slice scaling.
|
|
4591
|
+
* @returns The left border size in texture UV coordinates
|
|
4592
|
+
*/
|
|
4593
|
+
get sliceBorderLeft() {
|
|
4594
|
+
return this._private_material.getSliceBorderLeft();
|
|
4595
|
+
}
|
|
4596
|
+
/**
|
|
4597
|
+
* Gets the right border size for nine-slice scaling.
|
|
4598
|
+
* @returns The right border size in texture UV coordinates
|
|
4599
|
+
*/
|
|
4600
|
+
get sliceBorderRight() {
|
|
4601
|
+
return this._private_material.getSliceBorderRight();
|
|
4602
|
+
}
|
|
4603
|
+
/**
|
|
4604
|
+
* Gets the top border size for nine-slice scaling.
|
|
4605
|
+
* @returns The top border size in texture UV coordinates
|
|
4606
|
+
*/
|
|
4607
|
+
get sliceBorderTop() {
|
|
4608
|
+
return this._private_material.getSliceBorderTop();
|
|
4609
|
+
}
|
|
4610
|
+
/**
|
|
4611
|
+
* Gets the bottom border size for nine-slice scaling.
|
|
4612
|
+
* @returns The bottom border size in texture UV coordinates
|
|
4613
|
+
*/
|
|
4614
|
+
get sliceBorderBottom() {
|
|
4615
|
+
return this._private_material.getSliceBorderBottom();
|
|
4616
|
+
}
|
|
4617
|
+
/**
|
|
4618
|
+
* Gets the current texture being displayed.
|
|
4619
|
+
* @returns The current Three.js texture
|
|
4620
|
+
*/
|
|
4621
|
+
get texture() {
|
|
4622
|
+
return this._private_textureInternal;
|
|
4623
|
+
}
|
|
4624
|
+
/**
|
|
4625
|
+
* Gets the current color tint applied to the image.
|
|
4626
|
+
* @returns The color value as a number (e.g., 0xFFFFFF for white)
|
|
4627
|
+
*/
|
|
4628
|
+
get color() {
|
|
4629
|
+
return this._private_material.getColor();
|
|
4547
4630
|
}
|
|
4631
|
+
/**
|
|
4632
|
+
* Gets the current opacity level of the image.
|
|
4633
|
+
* @returns The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4634
|
+
*/
|
|
4635
|
+
get opacity() {
|
|
4636
|
+
return this._private_material.getOpacity();
|
|
4637
|
+
}
|
|
4638
|
+
/**
|
|
4639
|
+
* Gets whether transparency is enabled for the image.
|
|
4640
|
+
* @returns True if transparency is enabled, false otherwise
|
|
4641
|
+
*/
|
|
4642
|
+
get transparency() {
|
|
4643
|
+
return this._private_material.getTransparency();
|
|
4644
|
+
}
|
|
4645
|
+
/**
|
|
4646
|
+
* Sets the left border size for nine-slice scaling.
|
|
4647
|
+
* @param value - The left border size in texture UV coordinates
|
|
4648
|
+
*/
|
|
4649
|
+
set sliceBorderLeft(value) {
|
|
4650
|
+
this._private_material.setSliceBorderLeft(value);
|
|
4651
|
+
}
|
|
4652
|
+
/**
|
|
4653
|
+
* Sets the right border size for nine-slice scaling.
|
|
4654
|
+
* @param value - The right border size in texture UV coordinates
|
|
4655
|
+
*/
|
|
4656
|
+
set sliceBorderRight(value) {
|
|
4657
|
+
this._private_material.setSliceBorderRight(value);
|
|
4658
|
+
}
|
|
4659
|
+
/**
|
|
4660
|
+
* Sets the top border size for nine-slice scaling.
|
|
4661
|
+
* @param value - The top border size in texture UV coordinates
|
|
4662
|
+
*/
|
|
4663
|
+
set sliceBorderTop(value) {
|
|
4664
|
+
this._private_material.setSliceBorderTop(value);
|
|
4665
|
+
}
|
|
4666
|
+
/**
|
|
4667
|
+
* Sets the bottom border size for nine-slice scaling.
|
|
4668
|
+
* @param value - The bottom border size in texture UV coordinates
|
|
4669
|
+
*/
|
|
4670
|
+
set sliceBorderBottom(value) {
|
|
4671
|
+
this._private_material.setSliceBorderBottom(value);
|
|
4672
|
+
}
|
|
4673
|
+
/**
|
|
4674
|
+
* Sets a new texture for the image.
|
|
4675
|
+
*
|
|
4676
|
+
* When setting a new texture, the image will automatically resize to match
|
|
4677
|
+
* the new texture's dimensions.
|
|
4678
|
+
*
|
|
4679
|
+
* @param value - The new Three.js texture to display
|
|
4680
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
4681
|
+
* @see {@link assertValidPositiveNumber}
|
|
4682
|
+
*/
|
|
4683
|
+
set texture(value) {
|
|
4684
|
+
const width = value.image.width;
|
|
4685
|
+
const height = value.image.height;
|
|
4686
|
+
assertValidPositiveNumber(width, "UINineSlice texture width");
|
|
4687
|
+
assertValidPositiveNumber(height, "UINineSlice texture height");
|
|
4688
|
+
this._private_material.setTexture(value);
|
|
4689
|
+
this.solverWrapper.suggestVariableValue(this.wVariable, width);
|
|
4690
|
+
this.solverWrapper.suggestVariableValue(this.hVariable, height);
|
|
4691
|
+
}
|
|
4692
|
+
/**
|
|
4693
|
+
* Sets the color tint applied to the image.
|
|
4694
|
+
* @param value - The color value as a number (e.g., 0xFFFFFF for white)
|
|
4695
|
+
*/
|
|
4696
|
+
set color(value) {
|
|
4697
|
+
this._private_material.setColor(value);
|
|
4698
|
+
}
|
|
4699
|
+
/**
|
|
4700
|
+
* Sets the opacity level of the image.
|
|
4701
|
+
* @param value - The opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4702
|
+
*/
|
|
4703
|
+
set opacity(value) {
|
|
4704
|
+
this._private_material.setOpacity(value);
|
|
4705
|
+
}
|
|
4706
|
+
/**
|
|
4707
|
+
* Sets whether transparency is enabled for the image.
|
|
4708
|
+
* @param value - True to enable transparency, false to disable
|
|
4709
|
+
*/
|
|
4710
|
+
set transparency(value) {
|
|
4711
|
+
this._private_material.setTransparency(value);
|
|
4712
|
+
}
|
|
4713
|
+
/**
|
|
4714
|
+
* Sets all four border sizes for nine-slice scaling at once.
|
|
4715
|
+
*
|
|
4716
|
+
* @param left - The left border size in texture UV coordinates
|
|
4717
|
+
* @param right - The right border size in texture UV coordinates
|
|
4718
|
+
* @param top - The top border size in texture UV coordinates
|
|
4719
|
+
* @param bottom - The bottom border size in texture UV coordinates
|
|
4720
|
+
*/
|
|
4721
|
+
setSliceBorders(left, right, top, bottom) {
|
|
4722
|
+
this._private_material.setSliceBorder(left, right, top, bottom);
|
|
4723
|
+
}
|
|
4724
|
+
/**
|
|
4725
|
+
* Destroys the nine-slice element and cleans up resources.
|
|
4726
|
+
*
|
|
4727
|
+
* This method removes event listeners, disposes of the material,
|
|
4728
|
+
* and calls the parent destroy method.
|
|
4729
|
+
*/
|
|
4548
4730
|
destroy() {
|
|
4731
|
+
this.layer.off(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
4549
4732
|
this._private_material.dispose();
|
|
4550
4733
|
super.destroy();
|
|
4551
4734
|
}
|
|
4552
|
-
["onBeforeRenderInternal"](renderer, deltaTime) {
|
|
4553
|
-
this._private_material.setQuadSize(this.width * this.micro.scaleX, this.height * this.micro.scaleY);
|
|
4554
|
-
}
|
|
4555
4735
|
}
|
|
4556
4736
|
|
|
4737
|
+
var fragmentShader = "uniform sampler2D background;\nuniform sampler2D foreground;\nuniform float progress;\nuniform vec3 backgroundColor;\nuniform vec3 foregroundColor;\nuniform float backgroundOpacity;\nuniform float foregroundOpacity;\nuniform float alphaTest;\nuniform float angle;\nuniform float direction;\nvarying vec2 vUv;\n\nvoid main() {\n vec4 backgroundTexture = texture2D(background, vUv);\n vec4 foregroundTexture = texture2D(foreground, vUv);\n\n // Apply common color and opacity\n vec3 finalBackgroundColor = backgroundTexture.rgb * backgroundColor;\n vec3 finalForegroundColor = foregroundTexture.rgb * foregroundColor;\n float finalBackgroundOpacity = backgroundTexture.a * backgroundOpacity;\n float finalForegroundOpacity = foregroundTexture.a * foregroundOpacity;\n\n vec4 backgroundColor = vec4(finalBackgroundColor, finalBackgroundOpacity);\n vec4 foregroundColor = vec4(finalForegroundColor, finalForegroundOpacity);\n\n // Calculate progress threshold with angle and direction\n float adjustedX = mix(vUv.x, 1.0 - vUv.x, step(0.0, -direction));\n float tanAngle = tan(angle);\n float threshold = adjustedX - (vUv.y - 0.5) * tanAngle * sign(direction);\n float progressMask = step(threshold, progress);\n\n vec4 mixedColor = backgroundColor * (1.0 - foregroundColor.a * progressMask)\n + foregroundColor * (foregroundColor.a * progressMask);\n\n if (mixedColor.a < alphaTest) {\n discard;\n }\n\n gl_FragColor = mixedColor;\n #include <colorspace_fragment>\n}\n";
|
|
4738
|
+
|
|
4739
|
+
var vertexShader = "varying vec2 vUv;\nvoid main() {\n vUv = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
4740
|
+
|
|
4741
|
+
const DEFAULT_ALPHA_TEST = 0.025;
|
|
4557
4742
|
class UIProgressMaterial extends ShaderMaterial {
|
|
4558
4743
|
constructor(foregroundTexture, backgroundTexture) {
|
|
4559
4744
|
super({
|
|
@@ -4564,58 +4749,15 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4564
4749
|
progress: { value: 1 },
|
|
4565
4750
|
backgroundColor: { value: new Color(1, 1, 1) },
|
|
4566
4751
|
foregroundColor: { value: new Color(1, 1, 1) },
|
|
4567
|
-
color: { value: new Color(1, 1, 1) },
|
|
4568
4752
|
backgroundOpacity: { value: 1 },
|
|
4569
4753
|
foregroundOpacity: { value: 1 },
|
|
4570
|
-
|
|
4754
|
+
alphaTest: { value: DEFAULT_ALPHA_TEST },
|
|
4571
4755
|
angle: { value: 0 },
|
|
4572
4756
|
direction: { value: 1 },
|
|
4573
4757
|
},
|
|
4574
4758
|
]),
|
|
4575
|
-
vertexShader
|
|
4576
|
-
|
|
4577
|
-
void main() {
|
|
4578
|
-
vUv = uv;
|
|
4579
|
-
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
4580
|
-
}
|
|
4581
|
-
`,
|
|
4582
|
-
fragmentShader: /* glsl */ `
|
|
4583
|
-
uniform sampler2D background;
|
|
4584
|
-
uniform sampler2D foreground;
|
|
4585
|
-
uniform float progress;
|
|
4586
|
-
uniform vec3 backgroundColor;
|
|
4587
|
-
uniform vec3 foregroundColor;
|
|
4588
|
-
uniform vec3 color;
|
|
4589
|
-
uniform float backgroundOpacity;
|
|
4590
|
-
uniform float foregroundOpacity;
|
|
4591
|
-
uniform float opacity;
|
|
4592
|
-
uniform float angle;
|
|
4593
|
-
uniform float direction;
|
|
4594
|
-
varying vec2 vUv;
|
|
4595
|
-
|
|
4596
|
-
void main() {
|
|
4597
|
-
vec4 backgroundTexture = texture2D(background, vUv);
|
|
4598
|
-
vec4 foregroundTexture = texture2D(foreground, vUv);
|
|
4599
|
-
|
|
4600
|
-
// Apply common color and opacity
|
|
4601
|
-
vec3 finalBackgroundColor = backgroundTexture.rgb * backgroundColor * color;
|
|
4602
|
-
vec3 finalForegroundColor = foregroundTexture.rgb * foregroundColor * color;
|
|
4603
|
-
float finalBackgroundOpacity = backgroundTexture.a * backgroundOpacity * opacity;
|
|
4604
|
-
float finalForegroundOpacity = foregroundTexture.a * foregroundOpacity * opacity;
|
|
4605
|
-
|
|
4606
|
-
vec4 backgroundColor = vec4(finalBackgroundColor, finalBackgroundOpacity);
|
|
4607
|
-
vec4 foregroundColor = vec4(finalForegroundColor, finalForegroundOpacity);
|
|
4608
|
-
|
|
4609
|
-
// Calculate progress threshold with angle and direction
|
|
4610
|
-
float adjustedX = mix(vUv.x, 1.0 - vUv.x, step(0.0, -direction));
|
|
4611
|
-
float tanAngle = tan(angle);
|
|
4612
|
-
float threshold = adjustedX - (vUv.y - 0.5) * tanAngle * sign(direction);
|
|
4613
|
-
float progressMask = smoothstep(threshold - 0.01, threshold + 0.01, progress);
|
|
4614
|
-
|
|
4615
|
-
gl_FragColor = mix(backgroundColor, foregroundColor, progressMask);
|
|
4616
|
-
#include <colorspace_fragment>
|
|
4617
|
-
}
|
|
4618
|
-
`,
|
|
4759
|
+
vertexShader,
|
|
4760
|
+
fragmentShader,
|
|
4619
4761
|
transparent: true,
|
|
4620
4762
|
lights: false,
|
|
4621
4763
|
fog: false,
|
|
@@ -4633,10 +4775,10 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4633
4775
|
return this.uniforms.foreground.value;
|
|
4634
4776
|
}
|
|
4635
4777
|
getBackgroundColor() {
|
|
4636
|
-
return this.uniforms.
|
|
4778
|
+
return this.uniforms.backgroundColor.value.getHex();
|
|
4637
4779
|
}
|
|
4638
4780
|
getForegroundColor() {
|
|
4639
|
-
return this.uniforms.
|
|
4781
|
+
return this.uniforms.foregroundColor.value.getHex();
|
|
4640
4782
|
}
|
|
4641
4783
|
getBackgroundOpacity() {
|
|
4642
4784
|
return this.uniforms.backgroundOpacity.value;
|
|
@@ -4644,6 +4786,9 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4644
4786
|
getForegroundOpacity() {
|
|
4645
4787
|
return this.uniforms.foregroundOpacity.value;
|
|
4646
4788
|
}
|
|
4789
|
+
getTransparency() {
|
|
4790
|
+
return this.transparent;
|
|
4791
|
+
}
|
|
4647
4792
|
getAngle() {
|
|
4648
4793
|
return this.uniforms.angle.value;
|
|
4649
4794
|
}
|
|
@@ -4663,11 +4808,11 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4663
4808
|
this.uniformsNeedUpdate = true;
|
|
4664
4809
|
}
|
|
4665
4810
|
setBackgroundColor(value) {
|
|
4666
|
-
this.uniforms.
|
|
4811
|
+
this.uniforms.backgroundColor.value.setHex(value);
|
|
4667
4812
|
this.uniformsNeedUpdate = true;
|
|
4668
4813
|
}
|
|
4669
4814
|
setForegroundColor(value) {
|
|
4670
|
-
this.uniforms.
|
|
4815
|
+
this.uniforms.foregroundColor.value.setHex(value);
|
|
4671
4816
|
this.uniformsNeedUpdate = true;
|
|
4672
4817
|
}
|
|
4673
4818
|
setBackgroundOpacity(value) {
|
|
@@ -4678,6 +4823,15 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4678
4823
|
this.uniforms.foregroundOpacity.value = value;
|
|
4679
4824
|
this.uniformsNeedUpdate = true;
|
|
4680
4825
|
}
|
|
4826
|
+
setTransparency(value) {
|
|
4827
|
+
if (this.transparent !== value) {
|
|
4828
|
+
this.transparent = value;
|
|
4829
|
+
this.uniforms.alphaTest.value = !value ? DEFAULT_ALPHA_TEST : 0;
|
|
4830
|
+
this.needsUpdate = true;
|
|
4831
|
+
this.uniformsNeedUpdate = true;
|
|
4832
|
+
}
|
|
4833
|
+
return this;
|
|
4834
|
+
}
|
|
4681
4835
|
setAngle(value) {
|
|
4682
4836
|
this.uniforms.angle.value = value;
|
|
4683
4837
|
this.uniformsNeedUpdate = true;
|
|
@@ -4688,7 +4842,24 @@ class UIProgressMaterial extends ShaderMaterial {
|
|
|
4688
4842
|
}
|
|
4689
4843
|
}
|
|
4690
4844
|
|
|
4845
|
+
/**
|
|
4846
|
+
* Progress bar UI element with customizable fill direction and appearance.
|
|
4847
|
+
*
|
|
4848
|
+
* UIProgress displays a progress bar that can be filled in various directions
|
|
4849
|
+
* (horizontal, vertical, or at custom angles). It supports separate background
|
|
4850
|
+
* and foreground textures with independent color tinting and opacity control.
|
|
4851
|
+
*
|
|
4852
|
+
* The progress value ranges from 0.0 (empty) to 1.0 (completely filled).
|
|
4853
|
+
* The fill direction can be controlled both by angle and forward/reverse direction.
|
|
4854
|
+
*/
|
|
4691
4855
|
class UIProgress extends UIElement {
|
|
4856
|
+
/**
|
|
4857
|
+
* Creates a new progress bar UI element.
|
|
4858
|
+
*
|
|
4859
|
+
* @param layer - The UI layer to add this element to
|
|
4860
|
+
* @param textureForeground - The texture used for the progress fill
|
|
4861
|
+
* @param options - Configuration options for the progress bar
|
|
4862
|
+
*/
|
|
4692
4863
|
constructor(layer, textureForeground, options = {}) {
|
|
4693
4864
|
const foregroundWidth = textureForeground.image?.width;
|
|
4694
4865
|
const foregroundHeight = textureForeground.image?.height;
|
|
@@ -4705,8 +4876,8 @@ class UIProgress extends UIElement {
|
|
|
4705
4876
|
if (options.progress !== undefined) {
|
|
4706
4877
|
material.setProgress(options.progress);
|
|
4707
4878
|
}
|
|
4708
|
-
if (options.
|
|
4709
|
-
material.setIsForwardDirection(options.
|
|
4879
|
+
if (options.isForwardDirection !== undefined) {
|
|
4880
|
+
material.setIsForwardDirection(options.isForwardDirection);
|
|
4710
4881
|
}
|
|
4711
4882
|
if (options.angle !== undefined) {
|
|
4712
4883
|
material.setAngle(MathUtils.degToRad(options.angle));
|
|
@@ -4728,72 +4899,168 @@ class UIProgress extends UIElement {
|
|
|
4728
4899
|
super(layer, options.x ?? 0, options.y ?? 0, imageWidth, imageHeight, object);
|
|
4729
4900
|
this._private_material = material;
|
|
4730
4901
|
}
|
|
4902
|
+
/**
|
|
4903
|
+
* Gets the current progress value.
|
|
4904
|
+
* @returns Progress value between 0.0 (empty) and 1.0 (full)
|
|
4905
|
+
*/
|
|
4731
4906
|
get progress() {
|
|
4732
4907
|
return this._private_material.getProgress();
|
|
4733
4908
|
}
|
|
4909
|
+
/**
|
|
4910
|
+
* Gets the background texture.
|
|
4911
|
+
* @returns The background texture, or undefined if none is set
|
|
4912
|
+
*/
|
|
4734
4913
|
get backgroundTexture() {
|
|
4735
4914
|
return this._private_material.getBackgroundTexture();
|
|
4736
4915
|
}
|
|
4916
|
+
/**
|
|
4917
|
+
* Gets the foreground (fill) texture.
|
|
4918
|
+
* @returns The foreground texture
|
|
4919
|
+
*/
|
|
4737
4920
|
get foregroundTexture() {
|
|
4738
4921
|
return this._private_material.getForegroundTexture();
|
|
4739
4922
|
}
|
|
4923
|
+
/**
|
|
4924
|
+
* Gets the background color tint.
|
|
4925
|
+
* @returns The background color as a hex number (e.g., 0xFFFFFF)
|
|
4926
|
+
*/
|
|
4740
4927
|
get backgroundColor() {
|
|
4741
4928
|
return this._private_material.getBackgroundColor();
|
|
4742
4929
|
}
|
|
4930
|
+
/**
|
|
4931
|
+
* Gets the foreground color tint.
|
|
4932
|
+
* @returns The foreground color as a hex number (e.g., 0xFFFFFF)
|
|
4933
|
+
*/
|
|
4743
4934
|
get foregroundColor() {
|
|
4744
4935
|
return this._private_material.getForegroundColor();
|
|
4745
4936
|
}
|
|
4937
|
+
/**
|
|
4938
|
+
* Gets the background opacity.
|
|
4939
|
+
* @returns Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4940
|
+
*/
|
|
4746
4941
|
get backgroundOpacity() {
|
|
4747
4942
|
return this._private_material.getBackgroundOpacity();
|
|
4748
4943
|
}
|
|
4944
|
+
/**
|
|
4945
|
+
* Gets the foreground opacity.
|
|
4946
|
+
* @returns Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
4947
|
+
*/
|
|
4749
4948
|
get foregroundOpacity() {
|
|
4750
4949
|
return this._private_material.getForegroundOpacity();
|
|
4751
4950
|
}
|
|
4951
|
+
/**
|
|
4952
|
+
* Gets whether transparency is enabled for the image.
|
|
4953
|
+
* @returns True if transparency is enabled, false otherwise
|
|
4954
|
+
*/
|
|
4955
|
+
get transparency() {
|
|
4956
|
+
return this._private_material.getTransparency();
|
|
4957
|
+
}
|
|
4958
|
+
/**
|
|
4959
|
+
* Gets the progress fill angle in degrees.
|
|
4960
|
+
* @returns Angle in degrees (0 = horizontal, 90 = vertical)
|
|
4961
|
+
*/
|
|
4752
4962
|
get angle() {
|
|
4753
4963
|
return MathUtils.radToDeg(this._private_material.getAngle());
|
|
4754
4964
|
}
|
|
4965
|
+
/**
|
|
4966
|
+
* Gets whether the progress fills in forward direction.
|
|
4967
|
+
* @returns True if filling forward, false if filling in reverse
|
|
4968
|
+
*/
|
|
4755
4969
|
get isForwardDirection() {
|
|
4756
4970
|
return this._private_material.getIsForwardDirection();
|
|
4757
4971
|
}
|
|
4972
|
+
/**
|
|
4973
|
+
* Sets the progress value.
|
|
4974
|
+
* @param value - Progress value between 0.0 (empty) and 1.0 (full)
|
|
4975
|
+
*/
|
|
4758
4976
|
set progress(value) {
|
|
4759
4977
|
this._private_material.setProgress(value);
|
|
4760
4978
|
}
|
|
4979
|
+
/**
|
|
4980
|
+
* Sets the background texture.
|
|
4981
|
+
* @param value - The background texture, or undefined to remove background
|
|
4982
|
+
*/
|
|
4761
4983
|
set backgroundTexture(value) {
|
|
4762
4984
|
if (value) {
|
|
4763
4985
|
const width = value.image.width;
|
|
4764
4986
|
const height = value.image.height;
|
|
4765
|
-
assertValidPositiveNumber(width, "
|
|
4766
|
-
assertValidPositiveNumber(height, "
|
|
4987
|
+
assertValidPositiveNumber(width, "UIProgress background texture width");
|
|
4988
|
+
assertValidPositiveNumber(height, "UIProgress background texture height");
|
|
4767
4989
|
}
|
|
4768
4990
|
this._private_material.setBackgroundTexture(value);
|
|
4769
4991
|
}
|
|
4992
|
+
/**
|
|
4993
|
+
* Sets the foreground (fill) texture.
|
|
4994
|
+
*
|
|
4995
|
+
* When setting a new texture, the progress bar will automatically resize
|
|
4996
|
+
* to match the new texture's dimensions.
|
|
4997
|
+
*
|
|
4998
|
+
* @param value - The new foreground texture
|
|
4999
|
+
* @throws Will throw an error if the texture dimensions are not valid positive numbers
|
|
5000
|
+
*/
|
|
4770
5001
|
set foregroundTexture(value) {
|
|
4771
5002
|
const width = value.image.width;
|
|
4772
5003
|
const height = value.image.height;
|
|
4773
|
-
assertValidPositiveNumber(width, "
|
|
4774
|
-
assertValidPositiveNumber(height, "
|
|
5004
|
+
assertValidPositiveNumber(width, "UIProgress foreground texture width");
|
|
5005
|
+
assertValidPositiveNumber(height, "UIProgress foreground texture height");
|
|
4775
5006
|
this._private_material.setForegroundTexture(value);
|
|
4776
5007
|
this.solverWrapper.suggestVariableValue(this.wVariable, width);
|
|
4777
5008
|
this.solverWrapper.suggestVariableValue(this.hVariable, height);
|
|
4778
5009
|
}
|
|
5010
|
+
/**
|
|
5011
|
+
* Sets the background color tint.
|
|
5012
|
+
* @param value - The background color as a hex number (e.g., 0xFFFFFF)
|
|
5013
|
+
*/
|
|
4779
5014
|
set backgroundColor(value) {
|
|
4780
5015
|
this._private_material.setBackgroundColor(value);
|
|
4781
5016
|
}
|
|
5017
|
+
/**
|
|
5018
|
+
* Sets the foreground color tint.
|
|
5019
|
+
* @param value - The foreground color as a hex number (e.g., 0xFFFFFF)
|
|
5020
|
+
*/
|
|
4782
5021
|
set foregroundColor(value) {
|
|
4783
5022
|
this._private_material.setForegroundColor(value);
|
|
4784
5023
|
}
|
|
5024
|
+
/**
|
|
5025
|
+
* Sets the background opacity.
|
|
5026
|
+
* @param value - Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5027
|
+
*/
|
|
4785
5028
|
set backgroundOpacity(value) {
|
|
4786
5029
|
this._private_material.setBackgroundOpacity(value);
|
|
4787
5030
|
}
|
|
5031
|
+
/**
|
|
5032
|
+
* Sets the foreground opacity.
|
|
5033
|
+
* @param value - Opacity value between 0.0 (transparent) and 1.0 (opaque)
|
|
5034
|
+
*/
|
|
4788
5035
|
set foregroundOpacity(value) {
|
|
4789
5036
|
this._private_material.setForegroundOpacity(value);
|
|
4790
5037
|
}
|
|
5038
|
+
/**
|
|
5039
|
+
* Sets whether transparency is enabled for the image.
|
|
5040
|
+
* @param value - True to enable transparency, false to disable
|
|
5041
|
+
*/
|
|
5042
|
+
set transparency(value) {
|
|
5043
|
+
this._private_material.setTransparency(value);
|
|
5044
|
+
}
|
|
5045
|
+
/**
|
|
5046
|
+
* Sets the progress fill angle.
|
|
5047
|
+
* @param value - Angle in degrees (0 = horizontal, 90 = vertical)
|
|
5048
|
+
*/
|
|
4791
5049
|
set angle(value) {
|
|
4792
5050
|
this._private_material.setAngle(MathUtils.degToRad(value));
|
|
4793
5051
|
}
|
|
5052
|
+
/**
|
|
5053
|
+
* Sets the progress fill direction.
|
|
5054
|
+
* @param value - True for forward direction, false for reverse
|
|
5055
|
+
*/
|
|
4794
5056
|
set isForwardDirection(value) {
|
|
4795
5057
|
this._private_material.setIsForwardDirection(value);
|
|
4796
5058
|
}
|
|
5059
|
+
/**
|
|
5060
|
+
* Destroys the progress bar element and cleans up resources.
|
|
5061
|
+
*
|
|
5062
|
+
* This method disposes of the material and calls the parent destroy method.
|
|
5063
|
+
*/
|
|
4797
5064
|
destroy() {
|
|
4798
5065
|
this._private_material.dispose();
|
|
4799
5066
|
super.destroy();
|
|
@@ -4889,6 +5156,22 @@ class UIScene extends UIElement {
|
|
|
4889
5156
|
this._private_propertyChanged = false;
|
|
4890
5157
|
/** Flag indicating if a manual render has been requested. */
|
|
4891
5158
|
this._private_renderRequired = false;
|
|
5159
|
+
this._private_onWillRenderInternal = (renderer) => {
|
|
5160
|
+
if (this._private_updateModeInternal === UISceneUpdateMode.EACH_FRAME ||
|
|
5161
|
+
(this._private_updateModeInternal === UISceneUpdateMode.EACH_SECOND_FRAME && this._private_frameBoolean) ||
|
|
5162
|
+
(this._private_updateModeInternal === UISceneUpdateMode.PROPERTY_CHANGED && this._private_propertyChanged) ||
|
|
5163
|
+
(this._private_updateModeInternal === UISceneUpdateMode.MANUAL && this._private_renderRequired)) {
|
|
5164
|
+
this._private_renderRequired = false;
|
|
5165
|
+
this._private_propertyChanged = false;
|
|
5166
|
+
this._private_frameBoolean = !this._private_frameBoolean;
|
|
5167
|
+
this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
|
|
5168
|
+
renderer.setClearColor(this._private_clearColorInternal, this.clearAlpha);
|
|
5169
|
+
renderer.setRenderTarget(this._private_renderTarget);
|
|
5170
|
+
renderer.clear(true, true, false);
|
|
5171
|
+
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
5172
|
+
}
|
|
5173
|
+
};
|
|
5174
|
+
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
4892
5175
|
this._private_material = material;
|
|
4893
5176
|
this._private_renderTarget = renderTarget;
|
|
4894
5177
|
this._private_sceneInternal = options.scene ?? new Scene();
|
|
@@ -5056,6 +5339,7 @@ class UIScene extends UIElement {
|
|
|
5056
5339
|
* After calling this method, the scene element should not be used anymore.
|
|
5057
5340
|
*/
|
|
5058
5341
|
destroy() {
|
|
5342
|
+
this.layer.off(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
5059
5343
|
this._private_material.dispose();
|
|
5060
5344
|
this._private_renderTarget.dispose();
|
|
5061
5345
|
super.destroy();
|
|
@@ -5069,30 +5353,6 @@ class UIScene extends UIElement {
|
|
|
5069
5353
|
requestRender() {
|
|
5070
5354
|
this._private_renderRequired = true;
|
|
5071
5355
|
}
|
|
5072
|
-
/**
|
|
5073
|
-
* Internal method called before rendering each frame.
|
|
5074
|
-
*
|
|
5075
|
-
* This method handles the conditional rendering of the 3D scene based on
|
|
5076
|
-
* the current update mode. It manages frame counting, property change detection,
|
|
5077
|
-
* and manual render requests to optimize performance.
|
|
5078
|
-
*
|
|
5079
|
-
* @param renderer - The WebGL renderer instance
|
|
5080
|
-
*/
|
|
5081
|
-
["onBeforeRenderInternal"](renderer) {
|
|
5082
|
-
if (this._private_updateModeInternal === UISceneUpdateMode.EACH_FRAME ||
|
|
5083
|
-
(this._private_updateModeInternal === UISceneUpdateMode.EACH_SECOND_FRAME && this._private_frameBoolean) ||
|
|
5084
|
-
(this._private_updateModeInternal === UISceneUpdateMode.PROPERTY_CHANGED && this._private_propertyChanged) ||
|
|
5085
|
-
(this._private_updateModeInternal === UISceneUpdateMode.MANUAL && this._private_renderRequired)) {
|
|
5086
|
-
this._private_renderRequired = false;
|
|
5087
|
-
this._private_propertyChanged = false;
|
|
5088
|
-
this._private_frameBoolean = !this._private_frameBoolean;
|
|
5089
|
-
this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
|
|
5090
|
-
renderer.setClearColor(this._private_clearColorInternal, this.clearAlpha);
|
|
5091
|
-
renderer.setRenderTarget(this._private_renderTarget);
|
|
5092
|
-
renderer.clear(true, true, false);
|
|
5093
|
-
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
5094
|
-
}
|
|
5095
|
-
}
|
|
5096
5356
|
}
|
|
5097
5357
|
|
|
5098
5358
|
function isUITextStyle(obj) {
|
|
@@ -5386,7 +5646,7 @@ class UIText extends UIElement {
|
|
|
5386
5646
|
* @param y - Initial y-coordinate position (defaults to 0)
|
|
5387
5647
|
* @throws Will throw an error if canvas context creation fails
|
|
5388
5648
|
*/
|
|
5389
|
-
constructor(layer, content, options = {}
|
|
5649
|
+
constructor(layer, content, options = {}) {
|
|
5390
5650
|
const canvas = document.createElement("canvas");
|
|
5391
5651
|
const context = canvas.getContext("2d");
|
|
5392
5652
|
if (!context) {
|
|
@@ -5395,11 +5655,18 @@ class UIText extends UIElement {
|
|
|
5395
5655
|
const texture = new CanvasTexture(canvas);
|
|
5396
5656
|
const material = new UIMaterial(texture);
|
|
5397
5657
|
const object = new Mesh(geometry, material);
|
|
5398
|
-
super(layer, x, y, 2, 2, object);
|
|
5658
|
+
super(layer, options.x ?? 0, options.y ?? 0, 2, 2, object);
|
|
5399
5659
|
/** Target aspect ratio for the text element based on content. */
|
|
5400
5660
|
this._private_targetAspectRatio = 1;
|
|
5401
5661
|
/** Last calculated aspect ratio for comparison during rendering. */
|
|
5402
5662
|
this._private_lastAspectRatio = 1;
|
|
5663
|
+
this._private_onWillRenderInternal = () => {
|
|
5664
|
+
if (this._private_lastAspectRatio !== this.width / this.height) {
|
|
5665
|
+
this._private_lastAspectRatio = this._private_targetAspectRatio;
|
|
5666
|
+
this.height = this.width / this._private_targetAspectRatio;
|
|
5667
|
+
}
|
|
5668
|
+
};
|
|
5669
|
+
this.layer.on(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
5403
5670
|
this._private_material = material;
|
|
5404
5671
|
this._private_texture = texture;
|
|
5405
5672
|
this._private_canvas = canvas;
|
|
@@ -5521,31 +5788,12 @@ class UIText extends UIElement {
|
|
|
5521
5788
|
* the text element should not be used anymore.
|
|
5522
5789
|
*/
|
|
5523
5790
|
destroy() {
|
|
5791
|
+
this.layer.off(UILayerEvent.WILL_RENDER, this._private_onWillRenderInternal);
|
|
5524
5792
|
this._private_material.dispose();
|
|
5525
5793
|
this._private_texture.dispose();
|
|
5526
5794
|
this._private_canvas.remove();
|
|
5527
5795
|
super.destroy();
|
|
5528
5796
|
}
|
|
5529
|
-
/**
|
|
5530
|
-
* Internal method called before rendering each frame.
|
|
5531
|
-
*
|
|
5532
|
-
* Updates the element's height to maintain the correct aspect ratio
|
|
5533
|
-
* based on the text content dimensions. This ensures the text is
|
|
5534
|
-
* displayed without distortion.
|
|
5535
|
-
*
|
|
5536
|
-
* @param renderer - The WebGL renderer instance
|
|
5537
|
-
* @param deltaTime - Time elapsed since the last frame in seconds
|
|
5538
|
-
*/
|
|
5539
|
-
["onBeforeRenderInternal"](
|
|
5540
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- parameter required by parent
|
|
5541
|
-
renderer,
|
|
5542
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars -- parameter required by parent
|
|
5543
|
-
deltaTime) {
|
|
5544
|
-
if (this._private_lastAspectRatio !== this.width / this.height) {
|
|
5545
|
-
this._private_lastAspectRatio = this._private_targetAspectRatio;
|
|
5546
|
-
this.height = this.width / this._private_targetAspectRatio;
|
|
5547
|
-
}
|
|
5548
|
-
}
|
|
5549
5797
|
/**
|
|
5550
5798
|
* Rebuilds the text canvas and texture based on current content and settings.
|
|
5551
5799
|
*
|