laymur 0.11.5 → 0.13.0
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/README.md +33 -29
- package/dist/constraints/UIAspectConstraint/UIAspectConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIAspectConstraint/UIAspectConstraint.d.ts +1 -1
- package/dist/constraints/UIConstraint.d.ts +3 -3
- package/dist/constraints/UICustomConstraint.d.ts +3 -3
- package/dist/constraints/UIHeightConstraint/UIHeightConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIHeightConstraint/UIHeightConstraint.d.ts +1 -1
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIHorizontalDistanceConstraint/UIHorizontalDistanceConstraint.d.ts +1 -1
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.d.ts +1 -1
- package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIHorizontalProportionConstraint/UIHorizontalProportionConstraint.d.ts +1 -1
- package/dist/constraints/{UISingleParameterConstraint.Internal.d.ts → UISingleParameterConstraint/UISingleParameterConstraint.Internal.d.ts} +5 -3
- package/dist/constraints/{UISingleParameterConstraint.d.ts → UISingleParameterConstraint/UISingleParameterConstraint.d.ts} +5 -5
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIVerticalDistanceConstraint/UIVerticalDistanceConstraint.d.ts +1 -1
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.d.ts +1 -1
- package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIVerticalProportionConstraint/UIVerticalProportionConstraint.d.ts +1 -1
- package/dist/constraints/UIWidthConstraint/UIWidthConstraint.Internal.d.ts +1 -1
- package/dist/constraints/UIWidthConstraint/UIWidthConstraint.d.ts +1 -1
- package/dist/elements/UIAnchor/UIAnchor.d.ts +2 -2
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.Internal.d.ts +15 -3
- package/dist/elements/UIAnimatedImage/UIAnimatedImage.d.ts +23 -13
- package/dist/elements/UIElement/UIElement.Internal.d.ts +1 -1
- package/dist/elements/UIElement/UIElement.d.ts +5 -5
- package/dist/elements/UIGraphics/UIGraphics.Internal.d.ts +4 -0
- package/dist/elements/UIGraphics/UIGraphics.d.ts +12 -8
- package/dist/elements/UIImage/UIImage.d.ts +7 -3
- package/dist/elements/UIInputDummy/UIInputDummy.Internal.d.ts +1 -1
- package/dist/elements/UIInputDummy/UIInputDummy.d.ts +4 -4
- package/dist/elements/UINineSlice/UINineSlice.d.ts +26 -11
- package/dist/elements/UIProgress/UIProgress.d.ts +14 -6
- package/dist/elements/UIScene/UIScene.Internal.d.ts +1 -1
- package/dist/elements/UIScene/UIScene.d.ts +19 -12
- package/dist/elements/UIText/UIText.d.ts +14 -6
- package/dist/index.d.ts +3 -2
- package/dist/index.js +994 -627
- 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/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +9 -0
- package/dist/layers/{UIFullscreenLayer.d.ts → UIFullscreenLayer/UIFullscreenLayer.d.ts} +8 -10
- package/dist/layers/UILayer/UILayer.Internal.d.ts +29 -0
- package/dist/layers/{UILayer.d.ts → UILayer/UILayer.d.ts} +4 -9
- package/dist/miscellaneous/asserts.d.ts +1 -1
- package/dist/miscellaneous/color/UIColor.d.ts +37 -1
- package/dist/miscellaneous/generic-plane/{UIGenericInstancedPlane.Internal.d.ts → UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts} +6 -6
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.d.ts +1 -0
- package/dist/miscellaneous/generic-plane/UIGenericPlane/UIGenericPlane.Internal.d.ts +6 -0
- package/dist/miscellaneous/generic-plane/UIGenericPlane/UIGenericPlane.d.ts +1 -0
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +12 -0
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.d.ts +1 -0
- package/dist/miscellaneous/generic-plane/shared.d.ts +21 -10
- package/dist/miscellaneous/insets/UIInsets.Internal.d.ts +1 -1
- package/dist/miscellaneous/insets/UIInsets.d.ts +2 -0
- package/dist/miscellaneous/shared.d.ts +1 -1
- package/dist/wrappers/{UISceneWrapper.Internal.d.ts → UISceneWrapper/UISceneWrapper.Internal.d.ts} +4 -4
- package/dist/wrappers/{UISceneWrapper.d.ts → UISceneWrapper/UISceneWrapper.d.ts} +7 -6
- package/dist/wrappers/{UISolverWrapper.Internal.d.ts → UISolverWrapper/UISolverWrapper.Internal.d.ts} +3 -3
- package/dist/wrappers/{UISolverWrapper.d.ts → UISolverWrapper/UISolverWrapper.d.ts} +3 -3
- package/package.json +1 -1
- package/dist/layers/UILayer.Internal.d.ts +0 -15
- package/dist/miscellaneous/generic-plane/UIGenericInstancedPlane.d.ts +0 -36
- package/dist/miscellaneous/generic-plane/UIGenericPlane.Internal.d.ts +0 -5
- package/dist/miscellaneous/generic-plane/UIGenericPlane.d.ts +0 -23
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry.Internal.d.ts +0 -6
- package/dist/miscellaneous/generic-plane/UIGenericPlaneRegistry.d.ts +0 -27
- /package/dist/wrappers/{UIInputWrapper.Internal.d.ts → UIInputWrapper/UIInputWrapper.Internal.d.ts} +0 -0
- /package/dist/wrappers/{UIInputWrapper.d.ts → UIInputWrapper/UIInputWrapper.d.ts} +0 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MathUtils, Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture, SRGBColorSpace, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, Ray } from 'three';
|
|
2
2
|
|
|
3
3
|
class t{constructor(t,i,r=0){this.t=new WeakMap,this.i=new Map,void 0!==t&&(void 0===i?this.i.set(t,r):this.t.set(i,new Map([[t,r]])));}insert(t,i,r=0){if(void 0===i){if(this.i.has(t))return;return void this.i.set(t,r)}const s=this.t.get(i);void 0===s?this.t.set(i,new Map([[t,r]])):s.has(t)||s.set(t,r);}remove(t,i){if(void 0===i)return void this.i.delete(t);const r=this.t.get(i);void 0!==r&&(r.delete(t),0===r.size&&this.t.delete(i));}has(t,i){if(void 0===i)return this.i.has(t);const r=this.t.get(i);return void 0!==r&&r.has(t)}getPriority(t,i){if(void 0===i)return this.i.get(t);const r=this.t.get(i);return void 0!==r?r.get(t):void 0}}class i{constructor(){this.o=new Map;}on(t,i,r,s=0){return this.h(t,false,s,i,r),this}once(t,i,r,s=0){return this.h(t,true,s,i,r),this}off(t,i,r){const s=this.o.get(t);if(void 0===s)return this;s.u&&(s.u=false,s.v=s.v.slice());const o=s.v;if(0===o.length)return this.o.delete(t),this;if(void 0===i){this.o.delete(t);for(let t=0;o.length>t;t++){const i=o[t];s.l.remove(i._,i.p);}return this}{const e=o.length;if(o[0]._===i&&o[0].p===r)return 1===e?this.o.delete(t):o.shift(),this;const n=e-1;if(o[n]._===i&&o[n].p===r)return o.pop(),this;if(10>e||o[0].M===o[n].M)for(let t=1;n>t;t++){const s=o[t];if(s._===i&&s.p===r)return o.splice(t,1),this}else {const t=s.l.getPriority(i,r);if(void 0===t)return this;let e=0,n=o.length-1;for(;n>=e;){const i=e+n>>>1;t>o[i].M?e=i+1:n=i-1;}const c=e;for(n=o.length-1;n>=e;){const i=e+n>>>1;o[i].M>t?n=i-1:e=i+1;}const h=n;for(let t=c;h>=t;t++)if(o[t]._===i&&o[t].p===r)return o.splice(t,1),this}}return this}emit(t,...i){const r=this.o.get(t);if(void 0===r)return false;if(0===r.v.length)return false;r.u?r.v=r.v.slice():r.u=true;const s=r.v;let o=false;for(let t=0;s.length>t;t++){const r=s[t];r._.apply(r.p,i),r.k&&(o=true,r.m=true);}const e=this.o.get(t);if(void 0===e)return true;e.v===s&&(e.u=false);const n=e.v;if(o){let i=0;for(let t=0;n.length>t;t++){const r=n[t];r.m?e.l.remove(r._,r.p):n[i++]=r;}0===i?this.o.delete(t):n.length=i;}return true}h(i,r,s,o,e){let n=this.o.get(i);if(void 0===n)return void this.o.set(i,{v:[{_:o,p:e,M:s,k:r,m:false}],u:false,l:new t(o,e,s)});if(n.l.has(o,e))throw Error("Event listener already exists");n.l.insert(o,e,s);const c={_:o,p:e,M:s,k:r,m:false};n.u&&(n.u=false,n.v=n.v.slice());{const t=n.v,i=c.M;if(0===t.length||i>=t[t.length-1].M)return void t.push(c);if(t[0].M>=i)return void t.unshift(c);{let r=0,s=t.length;for(;s>r;){const o=r+s>>>1;i>t[o].M?r=o+1:s=o;}t.splice(r,0,c);}}}}
|
|
4
4
|
|
|
@@ -1598,7 +1598,7 @@ function convertPriority(priority) {
|
|
|
1598
1598
|
case UIPriority.P7:
|
|
1599
1599
|
return Strength.create(0, 0, 1);
|
|
1600
1600
|
default:
|
|
1601
|
-
throw new Error(`convertPriority: invalid priority`);
|
|
1601
|
+
throw new Error(`convertPriority.priority: invalid priority`);
|
|
1602
1602
|
}
|
|
1603
1603
|
}
|
|
1604
1604
|
/**
|
|
@@ -1635,7 +1635,7 @@ class UIInputWrapper {
|
|
|
1635
1635
|
destroyInputCatcher(handler) {
|
|
1636
1636
|
const index = this._private_catchers.findIndex((item) => item.handler === handler);
|
|
1637
1637
|
if (index === -1) {
|
|
1638
|
-
throw new Error("UIInputWrapper.destroyInputCatcher: handler not found");
|
|
1638
|
+
throw new Error("UIInputWrapper.destroyInputCatcher.handler: handler not found");
|
|
1639
1639
|
}
|
|
1640
1640
|
this._private_catchers.splice(index, 1);
|
|
1641
1641
|
}
|
|
@@ -1643,14 +1643,14 @@ class UIInputWrapper {
|
|
|
1643
1643
|
this._private_ensureSorted();
|
|
1644
1644
|
const found = this._private_catchers.find((item) => item.handler === handler);
|
|
1645
1645
|
if (!found) {
|
|
1646
|
-
throw new Error("UIInputWrapper.getZIndex: handler not found");
|
|
1646
|
+
throw new Error("UIInputWrapper.getZIndex.handler: handler not found");
|
|
1647
1647
|
}
|
|
1648
1648
|
return found.zIndex;
|
|
1649
1649
|
}
|
|
1650
1650
|
setZIndex(handler, zIndex) {
|
|
1651
1651
|
const found = this._private_catchers.find((item) => item.handler === handler);
|
|
1652
1652
|
if (!found) {
|
|
1653
|
-
throw new Error("UIInputWrapper.setZIndex: handler not found");
|
|
1653
|
+
throw new Error("UIInputWrapper.setZIndex.handler: handler not found");
|
|
1654
1654
|
}
|
|
1655
1655
|
if (found.zIndex !== zIndex) {
|
|
1656
1656
|
found.zIndex = zIndex;
|
|
@@ -1661,14 +1661,14 @@ class UIInputWrapper {
|
|
|
1661
1661
|
getActive(handler) {
|
|
1662
1662
|
const found = this._private_catchers.find((item) => item.handler === handler);
|
|
1663
1663
|
if (!found) {
|
|
1664
|
-
throw new Error("UIInputWrapper.getActive: handler not found");
|
|
1664
|
+
throw new Error("UIInputWrapper.getActive.handler: handler not found");
|
|
1665
1665
|
}
|
|
1666
1666
|
return found.active;
|
|
1667
1667
|
}
|
|
1668
1668
|
setActive(handler, active) {
|
|
1669
1669
|
const found = this._private_catchers.find((item) => item.handler === handler);
|
|
1670
1670
|
if (!found) {
|
|
1671
|
-
throw new Error("UIInputWrapper.setActive: handler not found");
|
|
1671
|
+
throw new Error("UIInputWrapper.setActive.handler: handler not found");
|
|
1672
1672
|
}
|
|
1673
1673
|
if (found.active !== active) {
|
|
1674
1674
|
found.active = active;
|
|
@@ -1717,17 +1717,6 @@ class UIInputWrapper {
|
|
|
1717
1717
|
}
|
|
1718
1718
|
}
|
|
1719
1719
|
|
|
1720
|
-
/** Transparency rendering modes */
|
|
1721
|
-
var UITransparencyMode;
|
|
1722
|
-
(function (UITransparencyMode) {
|
|
1723
|
-
/** Binary transparency. Best performance. */
|
|
1724
|
-
UITransparencyMode[UITransparencyMode["CLIP"] = 0] = "CLIP";
|
|
1725
|
-
/** Dithered transparency. Good performance. */
|
|
1726
|
-
UITransparencyMode[UITransparencyMode["HASH"] = 1] = "HASH";
|
|
1727
|
-
/** Alpha blending. Best quality, requires depth sorting. */
|
|
1728
|
-
UITransparencyMode[UITransparencyMode["BLEND"] = 2] = "BLEND";
|
|
1729
|
-
})(UITransparencyMode || (UITransparencyMode = {}));
|
|
1730
|
-
|
|
1731
1720
|
function SRGBToLinear( c ) {
|
|
1732
1721
|
|
|
1733
1722
|
return ( c < 0.04045 ) ? c * 0.0773993808 : Math.pow( c * 0.9478672986 + 0.0521327014, 2.4 );
|
|
@@ -1794,39 +1783,8 @@ class UIColor {
|
|
|
1794
1783
|
this._private_dirtyInternal = false;
|
|
1795
1784
|
this._private_rgbDirty = false;
|
|
1796
1785
|
this._private_hslDirty = false;
|
|
1797
|
-
if (args.length
|
|
1798
|
-
|
|
1799
|
-
this._private_rInternal = r;
|
|
1800
|
-
this._private_gInternal = g;
|
|
1801
|
-
this._private_bInternal = b;
|
|
1802
|
-
this._private_aInternal = a;
|
|
1803
|
-
}
|
|
1804
|
-
else if (args.length >= 1 && args[0] !== undefined) {
|
|
1805
|
-
const [firstArgument, a = 1] = args;
|
|
1806
|
-
if (typeof firstArgument === "string") {
|
|
1807
|
-
if (firstArgument.startsWith("#")) {
|
|
1808
|
-
this.setHexString(firstArgument);
|
|
1809
|
-
}
|
|
1810
|
-
else {
|
|
1811
|
-
this.setColorName(firstArgument, a);
|
|
1812
|
-
}
|
|
1813
|
-
}
|
|
1814
|
-
else if (firstArgument instanceof UIColor) {
|
|
1815
|
-
firstArgument._private_ensureRGBUpdatedFromHSL();
|
|
1816
|
-
this._private_rInternal = firstArgument._private_rInternal;
|
|
1817
|
-
this._private_gInternal = firstArgument._private_gInternal;
|
|
1818
|
-
this._private_bInternal = firstArgument._private_bInternal;
|
|
1819
|
-
this._private_aInternal = firstArgument._private_aInternal;
|
|
1820
|
-
}
|
|
1821
|
-
else if (firstArgument instanceof Color) {
|
|
1822
|
-
this._private_rInternal = firstArgument.r;
|
|
1823
|
-
this._private_gInternal = firstArgument.g;
|
|
1824
|
-
this._private_bInternal = firstArgument.b;
|
|
1825
|
-
this._private_aInternal = a;
|
|
1826
|
-
}
|
|
1827
|
-
else if (typeof firstArgument === "number") {
|
|
1828
|
-
this.setHexRGB(firstArgument, a);
|
|
1829
|
-
}
|
|
1786
|
+
if (args.length > 0) {
|
|
1787
|
+
this.set(...args);
|
|
1830
1788
|
}
|
|
1831
1789
|
}
|
|
1832
1790
|
/** Black (0x000000) */
|
|
@@ -2098,12 +2056,37 @@ class UIColor {
|
|
|
2098
2056
|
setDirtyFalse() {
|
|
2099
2057
|
this._private_dirtyInternal = false;
|
|
2100
2058
|
}
|
|
2101
|
-
|
|
2102
|
-
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2059
|
+
set(...args) {
|
|
2060
|
+
if (args.length === 0 || args[0] === undefined) {
|
|
2061
|
+
return this.setRGBA(1, 1, 1, 1);
|
|
2062
|
+
}
|
|
2063
|
+
if (args.length >= 3 && typeof args[0] === "number") {
|
|
2064
|
+
const [r, g, b, a = 1] = args;
|
|
2065
|
+
return this.setRGBA(r, g, b, a);
|
|
2066
|
+
}
|
|
2067
|
+
const [firstArgument, a = 1] = args;
|
|
2068
|
+
if (typeof firstArgument === "string") {
|
|
2069
|
+
return firstArgument.startsWith("#")
|
|
2070
|
+
? this.setHexString(firstArgument)
|
|
2071
|
+
: this.setColorName(firstArgument, a);
|
|
2072
|
+
}
|
|
2073
|
+
if (firstArgument instanceof UIColor) {
|
|
2074
|
+
return this.copy(firstArgument);
|
|
2075
|
+
}
|
|
2076
|
+
if (firstArgument instanceof Color) {
|
|
2077
|
+
return this.setThreeColor(firstArgument, a);
|
|
2078
|
+
}
|
|
2079
|
+
if (typeof firstArgument === "number") {
|
|
2080
|
+
return this.setHexRGB(firstArgument, a);
|
|
2081
|
+
}
|
|
2082
|
+
throw new Error("UIColor.set: cannot create color from provided arguments");
|
|
2083
|
+
}
|
|
2084
|
+
/** Sets RGBA components directly */
|
|
2085
|
+
setRGBA(r, g, b, a = this._private_aInternal) {
|
|
2086
|
+
assertValidNumber(r, "UIColor.setRGBA.r");
|
|
2087
|
+
assertValidNumber(g, "UIColor.setRGBA.g");
|
|
2088
|
+
assertValidNumber(b, "UIColor.setRGBA.b");
|
|
2089
|
+
assertValidNumber(a, "UIColor.setRGBA.a");
|
|
2107
2090
|
r = MathUtils.clamp(r, 0, 1);
|
|
2108
2091
|
g = MathUtils.clamp(g, 0, 1);
|
|
2109
2092
|
b = MathUtils.clamp(b, 0, 1);
|
|
@@ -2418,63 +2401,162 @@ class UIColor {
|
|
|
2418
2401
|
}
|
|
2419
2402
|
|
|
2420
2403
|
const DEFAULT_ALPHA_TEST = 0.5;
|
|
2404
|
+
const GLSL_TYPE_INFO_FLOAT = Object.freeze({
|
|
2405
|
+
glslTypeName: "float",
|
|
2406
|
+
bufferSize: 1,
|
|
2407
|
+
instantiable: true,
|
|
2408
|
+
});
|
|
2409
|
+
const GLSL_TYPE_INFO_SAMPLER2D = Object.freeze({
|
|
2410
|
+
glslTypeName: "sampler2D",
|
|
2411
|
+
bufferSize: -1,
|
|
2412
|
+
instantiable: false,
|
|
2413
|
+
});
|
|
2414
|
+
const GLSL_TYPE_INFO_VEC2 = Object.freeze({
|
|
2415
|
+
glslTypeName: "vec2",
|
|
2416
|
+
bufferSize: 2,
|
|
2417
|
+
instantiable: true,
|
|
2418
|
+
});
|
|
2419
|
+
const GLSL_TYPE_INFO_VEC3 = Object.freeze({
|
|
2420
|
+
glslTypeName: "vec3",
|
|
2421
|
+
bufferSize: 3,
|
|
2422
|
+
instantiable: true,
|
|
2423
|
+
});
|
|
2424
|
+
const GLSL_TYPE_INFO_VEC4 = Object.freeze({
|
|
2425
|
+
glslTypeName: "vec4",
|
|
2426
|
+
bufferSize: 4,
|
|
2427
|
+
instantiable: true,
|
|
2428
|
+
});
|
|
2429
|
+
const GLSL_TYPE_INFO_MAT3 = Object.freeze({
|
|
2430
|
+
glslTypeName: "mat3",
|
|
2431
|
+
bufferSize: 9,
|
|
2432
|
+
instantiable: true,
|
|
2433
|
+
});
|
|
2434
|
+
const GLSL_TYPE_INFO_MAT4 = Object.freeze({
|
|
2435
|
+
glslTypeName: "mat4",
|
|
2436
|
+
bufferSize: 16,
|
|
2437
|
+
instantiable: true,
|
|
2438
|
+
});
|
|
2421
2439
|
function resolveGLSLTypeInfo(value) {
|
|
2440
|
+
if (typeof value === "string") {
|
|
2441
|
+
switch (value) {
|
|
2442
|
+
case "number":
|
|
2443
|
+
return GLSL_TYPE_INFO_FLOAT;
|
|
2444
|
+
case "Texture":
|
|
2445
|
+
return GLSL_TYPE_INFO_SAMPLER2D;
|
|
2446
|
+
case "UIColor":
|
|
2447
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2448
|
+
case "Vector2":
|
|
2449
|
+
return GLSL_TYPE_INFO_VEC2;
|
|
2450
|
+
case "Vector3":
|
|
2451
|
+
return GLSL_TYPE_INFO_VEC3;
|
|
2452
|
+
case "Vector4":
|
|
2453
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2454
|
+
case "Matrix3":
|
|
2455
|
+
return GLSL_TYPE_INFO_MAT3;
|
|
2456
|
+
case "Matrix4":
|
|
2457
|
+
return GLSL_TYPE_INFO_MAT4;
|
|
2458
|
+
default:
|
|
2459
|
+
throw new Error(`resolveGLSLTypeInfo.value: unsupported property type name`);
|
|
2460
|
+
}
|
|
2461
|
+
}
|
|
2462
|
+
if (typeof value === "function") {
|
|
2463
|
+
if (value === Number) {
|
|
2464
|
+
return GLSL_TYPE_INFO_FLOAT;
|
|
2465
|
+
}
|
|
2466
|
+
if (value === Texture) {
|
|
2467
|
+
return GLSL_TYPE_INFO_SAMPLER2D;
|
|
2468
|
+
}
|
|
2469
|
+
if (value === UIColor) {
|
|
2470
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2471
|
+
}
|
|
2472
|
+
if (value === Vector2) {
|
|
2473
|
+
return GLSL_TYPE_INFO_VEC2;
|
|
2474
|
+
}
|
|
2475
|
+
if (value === Vector3) {
|
|
2476
|
+
return GLSL_TYPE_INFO_VEC3;
|
|
2477
|
+
}
|
|
2478
|
+
if (value === Vector4) {
|
|
2479
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2480
|
+
}
|
|
2481
|
+
if (value === Matrix3) {
|
|
2482
|
+
return GLSL_TYPE_INFO_MAT3;
|
|
2483
|
+
}
|
|
2484
|
+
if (value === Matrix4) {
|
|
2485
|
+
return GLSL_TYPE_INFO_MAT4;
|
|
2486
|
+
}
|
|
2487
|
+
throw new Error(`resolveGLSLTypeInfo.value: unsupported property type constructor`);
|
|
2488
|
+
}
|
|
2422
2489
|
if (typeof value === "number") {
|
|
2423
|
-
return
|
|
2490
|
+
return GLSL_TYPE_INFO_FLOAT;
|
|
2424
2491
|
}
|
|
2425
2492
|
if (value instanceof Texture) {
|
|
2426
|
-
return
|
|
2493
|
+
return GLSL_TYPE_INFO_SAMPLER2D;
|
|
2427
2494
|
}
|
|
2428
2495
|
if (value instanceof UIColor) {
|
|
2429
|
-
return
|
|
2496
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2430
2497
|
}
|
|
2431
2498
|
if (value instanceof Vector2) {
|
|
2432
|
-
return
|
|
2499
|
+
return GLSL_TYPE_INFO_VEC2;
|
|
2433
2500
|
}
|
|
2434
2501
|
if (value instanceof Vector3) {
|
|
2435
|
-
return
|
|
2502
|
+
return GLSL_TYPE_INFO_VEC3;
|
|
2436
2503
|
}
|
|
2437
2504
|
if (value instanceof Vector4) {
|
|
2438
|
-
return
|
|
2505
|
+
return GLSL_TYPE_INFO_VEC4;
|
|
2439
2506
|
}
|
|
2440
2507
|
if (value instanceof Matrix3) {
|
|
2441
|
-
return
|
|
2508
|
+
return GLSL_TYPE_INFO_MAT3;
|
|
2442
2509
|
}
|
|
2443
2510
|
if (value instanceof Matrix4) {
|
|
2444
|
-
return
|
|
2511
|
+
return GLSL_TYPE_INFO_MAT4;
|
|
2445
2512
|
}
|
|
2446
2513
|
throw new Error(`resolveGLSLTypeInfo.value: unsupported property type`);
|
|
2447
2514
|
}
|
|
2448
|
-
function
|
|
2515
|
+
function resolvePropertyUniform(name, material) {
|
|
2449
2516
|
const uniform = material.uniforms[`p_${name}`];
|
|
2450
2517
|
if (uniform === undefined) {
|
|
2451
|
-
throw new Error(`
|
|
2518
|
+
throw new Error(`resolvePropertyUniform.name: unknown uniform`);
|
|
2452
2519
|
}
|
|
2453
2520
|
return uniform;
|
|
2454
2521
|
}
|
|
2455
|
-
function
|
|
2456
|
-
const
|
|
2457
|
-
|
|
2458
|
-
if (currentKeys.length !== newKeys.length) {
|
|
2459
|
-
return false;
|
|
2460
|
-
}
|
|
2461
|
-
for (const newKey of newKeys) {
|
|
2462
|
-
if (!(newKey in currentProperties)) {
|
|
2522
|
+
function arePropertiesPartiallyCompatible(full, partial) {
|
|
2523
|
+
for (const key in partial) {
|
|
2524
|
+
if (!(key in full)) {
|
|
2463
2525
|
return false;
|
|
2464
2526
|
}
|
|
2465
|
-
const
|
|
2466
|
-
const
|
|
2467
|
-
if (
|
|
2527
|
+
const infoFull = full[key].glslTypeInfo;
|
|
2528
|
+
const infoPartial = partial[key].glslTypeInfo;
|
|
2529
|
+
if (infoFull.glslTypeName !== infoPartial.glslTypeName) {
|
|
2468
2530
|
return false;
|
|
2469
2531
|
}
|
|
2470
2532
|
// Non-instantiable (textures) must match by reference
|
|
2471
|
-
if (!
|
|
2472
|
-
newProperties[newKey] !== currentProperties[newKey]) {
|
|
2533
|
+
if (!infoFull.instantiable && full[key] !== partial[key]) {
|
|
2473
2534
|
return false;
|
|
2474
2535
|
}
|
|
2475
2536
|
}
|
|
2476
2537
|
return true;
|
|
2477
2538
|
}
|
|
2539
|
+
function convertUIPropertiesToGLProperties(uiProperties) {
|
|
2540
|
+
const glProperties = {};
|
|
2541
|
+
for (const name in uiProperties) {
|
|
2542
|
+
const value = uiProperties[name];
|
|
2543
|
+
glProperties[name] = { value, glslTypeInfo: resolveGLSLTypeInfo(value) };
|
|
2544
|
+
}
|
|
2545
|
+
return glProperties;
|
|
2546
|
+
}
|
|
2547
|
+
function cloneProperty(property) {
|
|
2548
|
+
if (typeof property === "number" || property instanceof Texture) {
|
|
2549
|
+
return property;
|
|
2550
|
+
}
|
|
2551
|
+
return property.clone();
|
|
2552
|
+
}
|
|
2553
|
+
function cloneProperties(properties) {
|
|
2554
|
+
const result = {};
|
|
2555
|
+
for (const name in properties) {
|
|
2556
|
+
result[name] = cloneProperty(properties[name]);
|
|
2557
|
+
}
|
|
2558
|
+
return result;
|
|
2559
|
+
}
|
|
2478
2560
|
function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source) {
|
|
2479
2561
|
return `
|
|
2480
2562
|
// Defines
|
|
@@ -2515,6 +2597,17 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
|
|
|
2515
2597
|
`;
|
|
2516
2598
|
}
|
|
2517
2599
|
|
|
2600
|
+
/** Transparency rendering modes */
|
|
2601
|
+
var UITransparencyMode;
|
|
2602
|
+
(function (UITransparencyMode) {
|
|
2603
|
+
/** Binary transparency. Best performance. */
|
|
2604
|
+
UITransparencyMode[UITransparencyMode["CLIP"] = 0] = "CLIP";
|
|
2605
|
+
/** Dithered transparency. Good performance. */
|
|
2606
|
+
UITransparencyMode[UITransparencyMode["HASH"] = 1] = "HASH";
|
|
2607
|
+
/** Alpha blending. Best quality, requires depth sorting. */
|
|
2608
|
+
UITransparencyMode[UITransparencyMode["BLEND"] = 2] = "BLEND";
|
|
2609
|
+
})(UITransparencyMode || (UITransparencyMode = {}));
|
|
2610
|
+
|
|
2518
2611
|
const INSTANCED_PLANE_GEOMETRY = (() => {
|
|
2519
2612
|
const planeGeometry = new PlaneGeometry(1, 1);
|
|
2520
2613
|
planeGeometry.translate(0.5, 0.5, 0);
|
|
@@ -2575,7 +2668,7 @@ function buildEmptyInstancedBufferAttribute(value, capacity) {
|
|
|
2575
2668
|
if (!info.instantiable) {
|
|
2576
2669
|
throw new Error(`buildEmptyInstancedBufferAttribute.value: cannot create instanced attribute for non-instantiable type`);
|
|
2577
2670
|
}
|
|
2578
|
-
return new InstancedBufferAttribute(new Float32Array(capacity * info.
|
|
2671
|
+
return new InstancedBufferAttribute(new Float32Array(capacity * info.bufferSize), info.bufferSize);
|
|
2579
2672
|
}
|
|
2580
2673
|
function buildMaterial(source, uniformProperties, varyingProperties, transparency) {
|
|
2581
2674
|
const uniforms = {};
|
|
@@ -2583,17 +2676,17 @@ function buildMaterial(source, uniformProperties, varyingProperties, transparenc
|
|
|
2583
2676
|
const attributeDeclarations = [];
|
|
2584
2677
|
const varyingDeclarations = [];
|
|
2585
2678
|
const vertexAssignments = [];
|
|
2586
|
-
for (const
|
|
2587
|
-
const
|
|
2679
|
+
for (const name in uniformProperties) {
|
|
2680
|
+
const { value, glslTypeInfo } = uniformProperties[name];
|
|
2588
2681
|
uniforms[`p_${name}`] = {
|
|
2589
2682
|
value: value instanceof UIColor ? value.toGLSLColor() : value,
|
|
2590
2683
|
};
|
|
2591
|
-
uniformDeclarations.push(`uniform ${
|
|
2684
|
+
uniformDeclarations.push(`uniform ${glslTypeInfo.glslTypeName} p_${name};`);
|
|
2592
2685
|
}
|
|
2593
|
-
for (const
|
|
2594
|
-
const
|
|
2595
|
-
attributeDeclarations.push(`attribute ${
|
|
2596
|
-
varyingDeclarations.push(`varying ${
|
|
2686
|
+
for (const name in varyingProperties) {
|
|
2687
|
+
const { glslTypeInfo } = varyingProperties[name];
|
|
2688
|
+
attributeDeclarations.push(`attribute ${glslTypeInfo.glslTypeName} a_${name};`);
|
|
2689
|
+
varyingDeclarations.push(`varying ${glslTypeInfo.glslTypeName} p_${name};`);
|
|
2597
2690
|
vertexAssignments.push(`p_${name} = a_${name};`);
|
|
2598
2691
|
}
|
|
2599
2692
|
const vertexShader = `
|
|
@@ -2665,20 +2758,34 @@ function reconstructValue(referenceValue, array, offset) {
|
|
|
2665
2758
|
throw new Error(`reconstructValue.referenceValue: cannot reconstruct value for type`);
|
|
2666
2759
|
}
|
|
2667
2760
|
|
|
2761
|
+
/**
|
|
2762
|
+
* Instanced shader plane mesh for batched rendering.
|
|
2763
|
+
*
|
|
2764
|
+
* Copies property values into internal buffers. No external references
|
|
2765
|
+
* are retained after method calls return.
|
|
2766
|
+
*
|
|
2767
|
+
* @internal
|
|
2768
|
+
*/
|
|
2668
2769
|
class UIGenericInstancedPlane extends Mesh {
|
|
2669
|
-
constructor(source, properties, transparency
|
|
2770
|
+
constructor(source, properties, transparency, initialCapacity = CAPACITY_STEP) {
|
|
2670
2771
|
const uniformProperties = {};
|
|
2671
2772
|
const varyingProperties = {
|
|
2672
|
-
instanceVisibility:
|
|
2673
|
-
|
|
2773
|
+
instanceVisibility: {
|
|
2774
|
+
value: 1,
|
|
2775
|
+
glslTypeInfo: resolveGLSLTypeInfo("number"),
|
|
2776
|
+
},
|
|
2777
|
+
instanceTransform: {
|
|
2778
|
+
value: new Matrix4().identity(),
|
|
2779
|
+
glslTypeInfo: resolveGLSLTypeInfo("Matrix4"),
|
|
2780
|
+
},
|
|
2674
2781
|
};
|
|
2675
|
-
for (const
|
|
2676
|
-
const
|
|
2677
|
-
if (
|
|
2678
|
-
varyingProperties[name] =
|
|
2782
|
+
for (const name in properties) {
|
|
2783
|
+
const descriptor = properties[name];
|
|
2784
|
+
if (descriptor.glslTypeInfo.instantiable) {
|
|
2785
|
+
varyingProperties[name] = descriptor;
|
|
2679
2786
|
}
|
|
2680
2787
|
else {
|
|
2681
|
-
uniformProperties[name] =
|
|
2788
|
+
uniformProperties[name] = descriptor;
|
|
2682
2789
|
}
|
|
2683
2790
|
}
|
|
2684
2791
|
const instancedGeometry = INSTANCED_PLANE_GEOMETRY.clone();
|
|
@@ -2699,35 +2806,48 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2699
2806
|
this._private_varyingProperties = varyingProperties;
|
|
2700
2807
|
this._private_capacity = Math.max(Math.ceil(initialCapacity / CAPACITY_STEP) * CAPACITY_STEP, CAPACITY_STEP);
|
|
2701
2808
|
{
|
|
2702
|
-
for (const
|
|
2809
|
+
for (const name in this._private_varyingProperties) {
|
|
2810
|
+
const { value } = this._private_varyingProperties[name];
|
|
2703
2811
|
const attribute = buildEmptyInstancedBufferAttribute(value, this._private_capacity);
|
|
2704
2812
|
this._private_instancedGeometry.setAttribute(`a_${name}`, attribute);
|
|
2705
2813
|
this._private_propertyBuffers.set(name, attribute);
|
|
2706
2814
|
}
|
|
2707
2815
|
}
|
|
2708
2816
|
{
|
|
2709
|
-
for (const
|
|
2710
|
-
const
|
|
2817
|
+
for (const name in this._private_uniformProperties) {
|
|
2818
|
+
const { value } = this._private_uniformProperties[name];
|
|
2819
|
+
const uniform = resolvePropertyUniform(name, this._private_shaderMaterial);
|
|
2711
2820
|
uniform.value = value;
|
|
2712
2821
|
}
|
|
2713
2822
|
this._private_shaderMaterial.uniformsNeedUpdate = true;
|
|
2714
2823
|
}
|
|
2715
2824
|
}
|
|
2825
|
+
/** Current number of active instances */
|
|
2716
2826
|
get instanceCount() {
|
|
2717
2827
|
return this._private_instancedGeometry.instanceCount;
|
|
2718
2828
|
}
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2829
|
+
/**
|
|
2830
|
+
* Creates new instance with default values.
|
|
2831
|
+
* @returns Instance handler for subsequent operations
|
|
2832
|
+
*/
|
|
2722
2833
|
createInstance() {
|
|
2723
2834
|
const handler = this._private_lastHandler++;
|
|
2724
2835
|
const index = this._private_instancedGeometry.instanceCount;
|
|
2725
|
-
|
|
2726
|
-
|
|
2727
|
-
|
|
2728
|
-
|
|
2836
|
+
{
|
|
2837
|
+
this._private_ensureCapacity(index + 1);
|
|
2838
|
+
this._private_handlerToIndex.set(handler, index);
|
|
2839
|
+
this._private_instancedGeometry.instanceCount++;
|
|
2840
|
+
}
|
|
2841
|
+
{
|
|
2842
|
+
const visibilityBufferAttribute = this._private_propertyBuffers.get("instanceVisibility");
|
|
2843
|
+
const transformBufferAttribute = this._private_propertyBuffers.get("instanceTransform");
|
|
2844
|
+
writeInstanceDefaults(visibilityBufferAttribute.array, transformBufferAttribute.array, index);
|
|
2845
|
+
visibilityBufferAttribute.needsUpdate = true;
|
|
2846
|
+
transformBufferAttribute.needsUpdate = true;
|
|
2847
|
+
}
|
|
2729
2848
|
return handler;
|
|
2730
2849
|
}
|
|
2850
|
+
/** Removes instance and compacts buffer */
|
|
2731
2851
|
destroyInstance(handler) {
|
|
2732
2852
|
const index = this._private_resolveIndex(handler);
|
|
2733
2853
|
this._private_handlerToIndex.delete(handler);
|
|
@@ -2738,23 +2858,25 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2738
2858
|
}
|
|
2739
2859
|
this._private_instancedGeometry.instanceCount--;
|
|
2740
2860
|
}
|
|
2861
|
+
/** Updates instance properties. Values are copied into buffers. */
|
|
2741
2862
|
setProperties(handler, properties) {
|
|
2742
2863
|
const index = this._private_resolveIndex(handler);
|
|
2743
|
-
for (const
|
|
2744
|
-
const
|
|
2745
|
-
if (
|
|
2864
|
+
for (const name in properties) {
|
|
2865
|
+
const { value, glslTypeInfo } = properties[name];
|
|
2866
|
+
if (glslTypeInfo.instantiable) {
|
|
2746
2867
|
const attribute = this._private_resolveAttribute(name);
|
|
2747
2868
|
const offset = index * attribute.itemSize;
|
|
2748
2869
|
writePropertyToArray(value, attribute.array, offset);
|
|
2749
2870
|
attribute.needsUpdate = true;
|
|
2750
2871
|
}
|
|
2751
2872
|
else {
|
|
2752
|
-
const uniform =
|
|
2873
|
+
const uniform = resolvePropertyUniform(name, this._private_shaderMaterial);
|
|
2753
2874
|
uniform.value = value;
|
|
2754
2875
|
this._private_shaderMaterial.uniformsNeedUpdate = true;
|
|
2755
2876
|
}
|
|
2756
2877
|
}
|
|
2757
2878
|
}
|
|
2879
|
+
/** Updates instance transform. Matrix is copied into buffer. */
|
|
2758
2880
|
setTransform(handler, transform) {
|
|
2759
2881
|
const index = this._private_resolveIndex(handler);
|
|
2760
2882
|
const attribute = this._private_resolveAttribute("instanceTransform");
|
|
@@ -2766,6 +2888,7 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2766
2888
|
}
|
|
2767
2889
|
attribute.needsUpdate = true;
|
|
2768
2890
|
}
|
|
2891
|
+
/** Updates instance visibility */
|
|
2769
2892
|
setVisibility(handler, visible) {
|
|
2770
2893
|
const index = this._private_resolveIndex(handler);
|
|
2771
2894
|
const attribute = this._private_resolveAttribute("instanceVisibility");
|
|
@@ -2773,39 +2896,53 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2773
2896
|
array[index] = visible ? 1 : 0;
|
|
2774
2897
|
attribute.needsUpdate = true;
|
|
2775
2898
|
}
|
|
2776
|
-
|
|
2777
|
-
|
|
2899
|
+
/** Checks if plane can accept given properties without reconstruction */
|
|
2900
|
+
isPartiallyCompatible(source, properties, transparency = UITransparencyMode.BLEND) {
|
|
2901
|
+
if (this.transparency !== transparency || this.source !== source) {
|
|
2778
2902
|
return false;
|
|
2779
2903
|
}
|
|
2780
|
-
return
|
|
2904
|
+
return arePropertiesPartiallyCompatible({ ...this._private_uniformProperties, ...this._private_varyingProperties }, properties);
|
|
2781
2905
|
}
|
|
2782
|
-
|
|
2783
|
-
|
|
2906
|
+
/** Checks if properties are compatible with current plane configuration */
|
|
2907
|
+
arePropertiesPartiallyCompatible(properties) {
|
|
2908
|
+
return arePropertiesPartiallyCompatible({ ...this._private_uniformProperties, ...this._private_varyingProperties }, properties);
|
|
2784
2909
|
}
|
|
2910
|
+
/** Returns reconstructed instance data with new object instances */
|
|
2785
2911
|
extractInstanceData(handler) {
|
|
2786
2912
|
return {
|
|
2787
2913
|
source: this.source,
|
|
2788
|
-
properties: this.
|
|
2914
|
+
properties: this._private_extractProperties(handler),
|
|
2789
2915
|
transparency: this.transparency,
|
|
2790
|
-
transform: this.
|
|
2791
|
-
visibility: this.
|
|
2916
|
+
transform: this._private_extractTransform(handler),
|
|
2917
|
+
visibility: this._private_extractVisibility(handler),
|
|
2792
2918
|
};
|
|
2793
2919
|
}
|
|
2794
|
-
|
|
2920
|
+
/** Disposes geometry, material, and clears buffers */
|
|
2921
|
+
destroy() {
|
|
2922
|
+
this._private_instancedGeometry.dispose();
|
|
2923
|
+
this._private_shaderMaterial.dispose();
|
|
2924
|
+
this._private_propertyBuffers.clear();
|
|
2925
|
+
this._private_handlerToIndex.clear();
|
|
2926
|
+
}
|
|
2927
|
+
_private_extractProperties(handler) {
|
|
2795
2928
|
const index = this._private_resolveIndex(handler);
|
|
2796
2929
|
const result = {};
|
|
2797
|
-
for (const
|
|
2798
|
-
result[name] =
|
|
2930
|
+
for (const name in this._private_uniformProperties) {
|
|
2931
|
+
result[name] = this._private_uniformProperties[name];
|
|
2799
2932
|
}
|
|
2800
|
-
for (const
|
|
2933
|
+
for (const name in this._private_varyingProperties) {
|
|
2934
|
+
const { value, glslTypeInfo } = this._private_varyingProperties[name];
|
|
2801
2935
|
const attribute = this._private_propertyBuffers.get(name);
|
|
2802
2936
|
const array = attribute.array;
|
|
2803
2937
|
const offset = index * attribute.itemSize;
|
|
2804
|
-
result[name] =
|
|
2938
|
+
result[name] = {
|
|
2939
|
+
value: reconstructValue(value, array, offset),
|
|
2940
|
+
glslTypeInfo,
|
|
2941
|
+
};
|
|
2805
2942
|
}
|
|
2806
2943
|
return result;
|
|
2807
2944
|
}
|
|
2808
|
-
|
|
2945
|
+
_private_extractTransform(handler) {
|
|
2809
2946
|
const index = this._private_resolveIndex(handler);
|
|
2810
2947
|
const attribute = this._private_propertyBuffers.get("instanceTransform");
|
|
2811
2948
|
const array = attribute.array;
|
|
@@ -2813,31 +2950,18 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2813
2950
|
matrix.fromArray(array, index * 16);
|
|
2814
2951
|
return matrix;
|
|
2815
2952
|
}
|
|
2816
|
-
|
|
2953
|
+
_private_extractVisibility(handler) {
|
|
2817
2954
|
const index = this._private_resolveIndex(handler);
|
|
2818
2955
|
const attribute = this._private_propertyBuffers.get("instanceVisibility");
|
|
2819
2956
|
const array = attribute.array;
|
|
2820
2957
|
return array[index] >= 0.5;
|
|
2821
2958
|
}
|
|
2822
|
-
destroy() {
|
|
2823
|
-
this._private_instancedGeometry.dispose();
|
|
2824
|
-
this._private_shaderMaterial.dispose();
|
|
2825
|
-
this._private_propertyBuffers.clear();
|
|
2826
|
-
this._private_handlerToIndex.clear();
|
|
2827
|
-
}
|
|
2828
|
-
_private_initializeInstanceDefaults(index) {
|
|
2829
|
-
const visibilityAttr = this._private_propertyBuffers.get("instanceVisibility");
|
|
2830
|
-
const transformAttr = this._private_propertyBuffers.get("instanceTransform");
|
|
2831
|
-
writeInstanceDefaults(visibilityAttr.array, transformAttr.array, index);
|
|
2832
|
-
visibilityAttr.needsUpdate = true;
|
|
2833
|
-
transformAttr.needsUpdate = true;
|
|
2834
|
-
}
|
|
2835
2959
|
_private_ensureCapacity(requiredCapacity) {
|
|
2836
2960
|
if (requiredCapacity <= this._private_capacity) {
|
|
2837
2961
|
return;
|
|
2838
2962
|
}
|
|
2839
2963
|
const newCapacity = Math.ceil(requiredCapacity / CAPACITY_STEP) * CAPACITY_STEP;
|
|
2840
|
-
for (const [name, oldAttribute] of this._private_propertyBuffers
|
|
2964
|
+
for (const [name, oldAttribute] of this._private_propertyBuffers) {
|
|
2841
2965
|
const itemSize = oldAttribute.itemSize;
|
|
2842
2966
|
const newArray = new Float32Array(newCapacity * itemSize);
|
|
2843
2967
|
newArray.set(oldAttribute.array);
|
|
@@ -2884,18 +3008,18 @@ class UIGenericInstancedPlane extends Mesh {
|
|
|
2884
3008
|
}
|
|
2885
3009
|
|
|
2886
3010
|
const PLANE_GEOMETRY = new PlaneGeometry(1, 1).translate(0.5, 0.5, 0);
|
|
2887
|
-
function buildGenericPlaneMaterial(source, properties, transparency) {
|
|
3011
|
+
function buildGenericPlaneMaterial(source, properties, transparency, transform) {
|
|
2888
3012
|
const uniforms = {
|
|
2889
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
2890
|
-
p_transform: { value:
|
|
3013
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention -- unform name
|
|
3014
|
+
p_transform: { value: transform },
|
|
2891
3015
|
};
|
|
2892
3016
|
const uniformDeclarations = [];
|
|
2893
|
-
for (const
|
|
2894
|
-
const
|
|
3017
|
+
for (const name in properties) {
|
|
3018
|
+
const { value, glslTypeInfo } = properties[name];
|
|
2895
3019
|
uniforms[`p_${name}`] = {
|
|
2896
3020
|
value: value instanceof UIColor ? value.toGLSLColor() : value,
|
|
2897
3021
|
};
|
|
2898
|
-
uniformDeclarations.push(`uniform ${
|
|
3022
|
+
uniformDeclarations.push(`uniform ${glslTypeInfo.glslTypeName} p_${name};`);
|
|
2899
3023
|
}
|
|
2900
3024
|
const vertexShader = `
|
|
2901
3025
|
// Default uniform declarations
|
|
@@ -2929,53 +3053,67 @@ function buildGenericPlaneMaterial(source, properties, transparency) {
|
|
|
2929
3053
|
return material;
|
|
2930
3054
|
}
|
|
2931
3055
|
|
|
3056
|
+
/**
|
|
3057
|
+
* Single shader plane mesh.
|
|
3058
|
+
*
|
|
3059
|
+
* Does not clone inputs. Caller must ensure properties and transform
|
|
3060
|
+
* are not shared with external code.
|
|
3061
|
+
*
|
|
3062
|
+
* @internal
|
|
3063
|
+
*/
|
|
2932
3064
|
class UIGenericPlane extends Mesh {
|
|
2933
|
-
constructor(
|
|
2934
|
-
const shaderMaterial = buildGenericPlaneMaterial(
|
|
3065
|
+
constructor(_private_source, properties, transform, visibility, transparency) {
|
|
3066
|
+
const shaderMaterial = buildGenericPlaneMaterial(_private_source, properties, transparency, transform);
|
|
2935
3067
|
super(PLANE_GEOMETRY, shaderMaterial);
|
|
2936
|
-
this.
|
|
2937
|
-
this.
|
|
3068
|
+
this._private_source = _private_source;
|
|
3069
|
+
this._private_shaderMaterial = shaderMaterial;
|
|
3070
|
+
this._private_properties = properties;
|
|
3071
|
+
this._private_transparencyInternal = transparency;
|
|
3072
|
+
this._private_transform = transform;
|
|
3073
|
+
this.visible = visibility;
|
|
2938
3074
|
this.frustumCulled = false;
|
|
2939
3075
|
this.matrixAutoUpdate = false;
|
|
2940
3076
|
this.matrixWorldAutoUpdate = false;
|
|
2941
|
-
this._private_shaderMaterial = shaderMaterial;
|
|
2942
|
-
this._private_propertiesInternal = { ...properties };
|
|
2943
|
-
this._private_transparencyInternal = transparency;
|
|
2944
|
-
}
|
|
2945
|
-
get properties() {
|
|
2946
|
-
return { ...this._private_propertiesInternal };
|
|
2947
|
-
}
|
|
2948
|
-
get transform() {
|
|
2949
|
-
return this._private_transformInternal;
|
|
2950
|
-
}
|
|
2951
|
-
get visibility() {
|
|
2952
|
-
return this.visible;
|
|
2953
3077
|
}
|
|
3078
|
+
/** Current transparency mode */
|
|
2954
3079
|
get transparency() {
|
|
2955
3080
|
return this._private_transparencyInternal;
|
|
2956
3081
|
}
|
|
3082
|
+
/** Updates properties. Values are copied via .copy() methods. */
|
|
2957
3083
|
setProperties(properties) {
|
|
2958
|
-
for (const
|
|
2959
|
-
const
|
|
2960
|
-
|
|
2961
|
-
|
|
3084
|
+
for (const name in properties) {
|
|
3085
|
+
const descriptor = properties[name];
|
|
3086
|
+
const uniform = resolvePropertyUniform(name, this._private_shaderMaterial);
|
|
3087
|
+
const descriptorValue = descriptor.value;
|
|
3088
|
+
if (descriptor.value instanceof UIColor) {
|
|
3089
|
+
descriptor.value.toGLSLColor(uniform.value);
|
|
3090
|
+
this._private_properties[name].value.copy(descriptor.value);
|
|
3091
|
+
}
|
|
3092
|
+
else if (typeof descriptorValue === "number" ||
|
|
3093
|
+
descriptorValue instanceof Texture) {
|
|
3094
|
+
uniform.value = descriptor.value;
|
|
3095
|
+
this._private_properties[name].value = descriptor.value;
|
|
2962
3096
|
}
|
|
2963
3097
|
else {
|
|
2964
|
-
|
|
3098
|
+
const value = descriptor.value;
|
|
3099
|
+
uniform.value.copy(value);
|
|
3100
|
+
this._private_properties[name].value.copy(value);
|
|
2965
3101
|
}
|
|
2966
|
-
this._private_propertiesInternal[name] = value;
|
|
2967
3102
|
}
|
|
2968
3103
|
this._private_shaderMaterial.uniformsNeedUpdate = true;
|
|
2969
3104
|
}
|
|
3105
|
+
/** Updates transform. Matrix is copied. */
|
|
2970
3106
|
setTransform(transform) {
|
|
2971
|
-
const uniform =
|
|
3107
|
+
const uniform = resolvePropertyUniform("transform", this._private_shaderMaterial);
|
|
2972
3108
|
uniform.value.copy(transform);
|
|
2973
3109
|
this._private_shaderMaterial.uniformsNeedUpdate = true;
|
|
2974
|
-
this.
|
|
3110
|
+
this._private_transform.copy(transform);
|
|
2975
3111
|
}
|
|
3112
|
+
/** Updates visibility */
|
|
2976
3113
|
setVisibility(visibility) {
|
|
2977
3114
|
this.visible = visibility;
|
|
2978
3115
|
}
|
|
3116
|
+
/** Updates transparency mode */
|
|
2979
3117
|
setTransparency(transparency) {
|
|
2980
3118
|
if (this._private_transparencyInternal !== transparency) {
|
|
2981
3119
|
this._private_shaderMaterial.transparent =
|
|
@@ -2989,266 +3127,239 @@ class UIGenericPlane extends Mesh {
|
|
|
2989
3127
|
this._private_transparencyInternal = transparency;
|
|
2990
3128
|
}
|
|
2991
3129
|
}
|
|
2992
|
-
|
|
3130
|
+
/** Returns cloned plane data for reconstruction */
|
|
3131
|
+
extractPlaneData() {
|
|
2993
3132
|
return {
|
|
2994
|
-
source: this.
|
|
2995
|
-
properties: this.
|
|
2996
|
-
|
|
2997
|
-
transform: this._private_transformInternal.clone(),
|
|
3133
|
+
source: this._private_source,
|
|
3134
|
+
properties: { ...this._private_properties },
|
|
3135
|
+
transform: this._private_transform.clone(),
|
|
2998
3136
|
visibility: this.visible,
|
|
3137
|
+
transparency: this._private_transparencyInternal,
|
|
2999
3138
|
};
|
|
3000
3139
|
}
|
|
3001
|
-
|
|
3002
|
-
|
|
3140
|
+
/** Checks if plane can accept given properties without reconstruction */
|
|
3141
|
+
isPartiallyCompatible(source, properties, transparency) {
|
|
3142
|
+
if (this._private_transparencyInternal !== transparency || this._private_source !== source) {
|
|
3003
3143
|
return false;
|
|
3004
3144
|
}
|
|
3005
|
-
return
|
|
3145
|
+
return arePropertiesPartiallyCompatible(this._private_properties, properties);
|
|
3006
3146
|
}
|
|
3007
|
-
|
|
3008
|
-
|
|
3147
|
+
/** Checks if properties are compatible with current plane configuration */
|
|
3148
|
+
arePropertiesPartiallyCompatible(properties) {
|
|
3149
|
+
return arePropertiesPartiallyCompatible(this._private_properties, properties);
|
|
3009
3150
|
}
|
|
3151
|
+
/** Disposes shader material */
|
|
3010
3152
|
destroy() {
|
|
3011
3153
|
this._private_shaderMaterial.dispose();
|
|
3012
3154
|
}
|
|
3013
3155
|
}
|
|
3014
3156
|
|
|
3157
|
+
function isSinglePlaneDescriptor(descriptor) {
|
|
3158
|
+
return !("instanceHandler" in descriptor);
|
|
3159
|
+
}
|
|
3160
|
+
function isInstancedPlaneDescriptor(descriptor) {
|
|
3161
|
+
return "instanceHandler" in descriptor;
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
/**
|
|
3165
|
+
* Manages shader plane instances with automatic batching.
|
|
3166
|
+
*
|
|
3167
|
+
* Clones all incoming properties and transforms. No external references
|
|
3168
|
+
* are retained after method calls return.
|
|
3169
|
+
*
|
|
3170
|
+
* @internal
|
|
3171
|
+
*/
|
|
3015
3172
|
class UIPlaneRegistry {
|
|
3016
3173
|
constructor(_private_scene) {
|
|
3017
3174
|
this._private_scene = _private_scene;
|
|
3018
|
-
this._private_descriptors = new Map();
|
|
3019
3175
|
this._private_lastHandler = 0;
|
|
3176
|
+
this._private_handlerToPlaneDescriptor = new Map();
|
|
3020
3177
|
}
|
|
3021
|
-
|
|
3178
|
+
/**
|
|
3179
|
+
* Creates plane with given shader and properties.
|
|
3180
|
+
* Properties and transform are cloned; originals can be safely modified.
|
|
3181
|
+
* @returns Plane handler for subsequent operations
|
|
3182
|
+
*/
|
|
3183
|
+
createPlane(source, properties, transform, visibility, transparency) {
|
|
3022
3184
|
const handler = this._private_lastHandler++;
|
|
3023
|
-
|
|
3024
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3025
|
-
plane: undefined,
|
|
3026
|
-
};
|
|
3027
|
-
this._private_descriptors.set(handler, descriptor);
|
|
3028
|
-
this._private_placeInstance(descriptor, {
|
|
3185
|
+
this._private_insertPlane(handler, {
|
|
3029
3186
|
source,
|
|
3030
|
-
properties,
|
|
3187
|
+
properties: convertUIPropertiesToGLProperties(cloneProperties(properties)),
|
|
3188
|
+
transform: transform.clone(),
|
|
3189
|
+
visibility,
|
|
3031
3190
|
transparency,
|
|
3032
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
3033
|
-
transform: undefined,
|
|
3034
|
-
visibility: true,
|
|
3035
3191
|
});
|
|
3036
3192
|
return handler;
|
|
3037
3193
|
}
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
this.
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
const descriptor = this._private_resolveDescriptor(handler);
|
|
3045
|
-
if (descriptor.plane instanceof UIGenericInstancedPlane &&
|
|
3046
|
-
descriptor.instanceHandler !== undefined) {
|
|
3047
|
-
descriptor.plane.setTransform(descriptor.instanceHandler, transform);
|
|
3194
|
+
/** Removes plane and frees resources */
|
|
3195
|
+
destroyPlane(handler) {
|
|
3196
|
+
const planeDescriptor = this._private_resolvePlaneDescriptor(handler);
|
|
3197
|
+
if (isSinglePlaneDescriptor(planeDescriptor)) {
|
|
3198
|
+
this._private_scene.remove(planeDescriptor.plane);
|
|
3199
|
+
planeDescriptor.plane.destroy();
|
|
3048
3200
|
}
|
|
3049
|
-
else
|
|
3050
|
-
|
|
3201
|
+
else {
|
|
3202
|
+
const instancedPlane = planeDescriptor.plane;
|
|
3203
|
+
if (instancedPlane.instanceCount === 1) {
|
|
3204
|
+
this._private_scene.remove(instancedPlane);
|
|
3205
|
+
instancedPlane.destroy();
|
|
3206
|
+
}
|
|
3207
|
+
else if (instancedPlane.instanceCount === 2) {
|
|
3208
|
+
this._private_demoteInstancedPlaneToSinglePlane(instancedPlane, planeDescriptor);
|
|
3209
|
+
}
|
|
3210
|
+
else {
|
|
3211
|
+
instancedPlane.destroyInstance(planeDescriptor.instanceHandler);
|
|
3212
|
+
}
|
|
3051
3213
|
}
|
|
3214
|
+
this._private_handlerToPlaneDescriptor.delete(handler);
|
|
3052
3215
|
}
|
|
3216
|
+
/**
|
|
3217
|
+
* Updates plane properties.
|
|
3218
|
+
* Values are copied; originals can be safely modified.
|
|
3219
|
+
*/
|
|
3053
3220
|
setProperties(handler, properties) {
|
|
3054
|
-
const
|
|
3055
|
-
const
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
this._private_removeFromCurrentPlane(descriptor);
|
|
3060
|
-
this._private_placeInstance(descriptor, {
|
|
3061
|
-
...currentData,
|
|
3062
|
-
properties: newProperties,
|
|
3063
|
-
});
|
|
3064
|
-
}
|
|
3065
|
-
else {
|
|
3066
|
-
this._private_updatePropertiesInPlace(descriptor, properties);
|
|
3221
|
+
const planeDescriptor = this._private_resolvePlaneDescriptor(handler);
|
|
3222
|
+
const glProperties = convertUIPropertiesToGLProperties(properties);
|
|
3223
|
+
if (isSinglePlaneDescriptor(planeDescriptor)) {
|
|
3224
|
+
planeDescriptor.plane.setProperties(glProperties);
|
|
3225
|
+
return;
|
|
3067
3226
|
}
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
descriptor.instanceHandler !== undefined) {
|
|
3073
|
-
descriptor.plane.setVisibility(descriptor.instanceHandler, visible);
|
|
3227
|
+
const arePropertiesCompatible = planeDescriptor.plane.arePropertiesPartiallyCompatible(glProperties);
|
|
3228
|
+
if (arePropertiesCompatible) {
|
|
3229
|
+
planeDescriptor.plane.setProperties(planeDescriptor.instanceHandler, glProperties);
|
|
3230
|
+
return;
|
|
3074
3231
|
}
|
|
3075
|
-
|
|
3076
|
-
|
|
3232
|
+
const planeData = planeDescriptor.plane.extractInstanceData(planeDescriptor.instanceHandler);
|
|
3233
|
+
for (const name in glProperties) {
|
|
3234
|
+
planeData.properties[name] = {
|
|
3235
|
+
value: cloneProperty(glProperties[name].value),
|
|
3236
|
+
glslTypeInfo: glProperties[name].glslTypeInfo,
|
|
3237
|
+
};
|
|
3077
3238
|
}
|
|
3239
|
+
this.destroyPlane(handler);
|
|
3240
|
+
this._private_insertPlane(handler, planeData);
|
|
3078
3241
|
}
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3242
|
+
/**
|
|
3243
|
+
* Updates plane transform matrix.
|
|
3244
|
+
* Matrix is copied; original can be safely modified.
|
|
3245
|
+
*/
|
|
3246
|
+
setTransform(handler, transform) {
|
|
3247
|
+
const planeDescriptor = this._private_resolvePlaneDescriptor(handler);
|
|
3248
|
+
if (isSinglePlaneDescriptor(planeDescriptor)) {
|
|
3249
|
+
planeDescriptor.plane.setTransform(transform);
|
|
3083
3250
|
return;
|
|
3084
3251
|
}
|
|
3085
|
-
|
|
3086
|
-
if (needsRelocation) {
|
|
3087
|
-
this._private_removeFromCurrentPlane(descriptor);
|
|
3088
|
-
this._private_placeInstance(descriptor, {
|
|
3089
|
-
...currentData,
|
|
3090
|
-
transparency,
|
|
3091
|
-
});
|
|
3092
|
-
}
|
|
3093
|
-
else if (descriptor.plane instanceof UIGenericPlane) {
|
|
3094
|
-
descriptor.plane.setTransparency(transparency);
|
|
3095
|
-
}
|
|
3252
|
+
planeDescriptor.plane.setTransform(planeDescriptor.instanceHandler, transform);
|
|
3096
3253
|
}
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
const
|
|
3100
|
-
if (
|
|
3101
|
-
|
|
3254
|
+
/** Updates plane visibility */
|
|
3255
|
+
setVisibility(handler, visibility) {
|
|
3256
|
+
const planeDescriptor = this._private_resolvePlaneDescriptor(handler);
|
|
3257
|
+
if (isSinglePlaneDescriptor(planeDescriptor)) {
|
|
3258
|
+
planeDescriptor.plane.setVisibility(visibility);
|
|
3102
3259
|
return;
|
|
3103
3260
|
}
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3261
|
+
planeDescriptor.plane.setVisibility(planeDescriptor.instanceHandler, visibility);
|
|
3262
|
+
}
|
|
3263
|
+
/** Updates plane transparency mode */
|
|
3264
|
+
setTransparency(handler, transparency) {
|
|
3265
|
+
const planeDescriptor = this._private_resolvePlaneDescriptor(handler);
|
|
3266
|
+
if (planeDescriptor.plane.transparency === transparency) {
|
|
3108
3267
|
return;
|
|
3109
3268
|
}
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
if (descriptor.plane instanceof UIGenericInstancedPlane &&
|
|
3114
|
-
descriptor.instanceHandler !== undefined) {
|
|
3115
|
-
return descriptor.plane.extractInstanceData(descriptor.instanceHandler);
|
|
3269
|
+
if (isSinglePlaneDescriptor(planeDescriptor)) {
|
|
3270
|
+
planeDescriptor.plane.setTransparency(transparency);
|
|
3271
|
+
return;
|
|
3116
3272
|
}
|
|
3117
|
-
|
|
3273
|
+
const planeData = planeDescriptor.plane.extractInstanceData(planeDescriptor.instanceHandler);
|
|
3274
|
+
this.destroyPlane(handler);
|
|
3275
|
+
this._private_insertPlane(handler, {
|
|
3276
|
+
...planeData,
|
|
3277
|
+
transparency,
|
|
3278
|
+
});
|
|
3118
3279
|
}
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3280
|
+
_private_promoteSinglePlaneToInstancedPlane(handler, planeDescriptor) {
|
|
3281
|
+
const { source, properties, transform, visibility, transparency } = planeDescriptor.plane.extractPlaneData();
|
|
3282
|
+
this.destroyPlane(handler);
|
|
3283
|
+
const plane = new UIGenericInstancedPlane(source, properties, transparency);
|
|
3284
|
+
const instanceHandler = plane.createInstance();
|
|
3285
|
+
plane.setProperties(instanceHandler, properties);
|
|
3286
|
+
plane.setTransform(instanceHandler, transform);
|
|
3287
|
+
plane.setVisibility(instanceHandler, visibility);
|
|
3288
|
+
this._private_scene.add(plane);
|
|
3289
|
+
this._private_handlerToPlaneDescriptor.set(handler, { plane, instanceHandler });
|
|
3290
|
+
return plane;
|
|
3291
|
+
}
|
|
3292
|
+
_private_demoteInstancedPlaneToSinglePlane(instancedPlane, removedDescriptor) {
|
|
3293
|
+
let remainingPair;
|
|
3294
|
+
for (const [handler, planeDescriptor] of this._private_handlerToPlaneDescriptor) {
|
|
3295
|
+
if (isInstancedPlaneDescriptor(planeDescriptor) &&
|
|
3296
|
+
planeDescriptor !== removedDescriptor &&
|
|
3297
|
+
planeDescriptor.plane === instancedPlane) {
|
|
3298
|
+
remainingPair = [handler, planeDescriptor];
|
|
3299
|
+
break;
|
|
3130
3300
|
}
|
|
3131
3301
|
}
|
|
3132
|
-
|
|
3133
|
-
|
|
3134
|
-
descriptor.plane.destroy();
|
|
3302
|
+
if (!remainingPair) {
|
|
3303
|
+
throw new Error("UIGenericPlaneRegistry.demoteInstancedPlaneToSinglePlane.instancedPlane: remaining pair not found");
|
|
3135
3304
|
}
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3305
|
+
const { source, properties, transform, visibility, transparency } = instancedPlane.extractInstanceData(remainingPair[1].instanceHandler);
|
|
3306
|
+
this._private_scene.remove(instancedPlane);
|
|
3307
|
+
instancedPlane.destroy();
|
|
3308
|
+
const plane = new UIGenericPlane(source, properties, transform, visibility, transparency);
|
|
3309
|
+
this._private_scene.add(plane);
|
|
3310
|
+
this._private_handlerToPlaneDescriptor.set(remainingPair[0], { plane });
|
|
3139
3311
|
}
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3145
|
-
|
|
3146
|
-
|
|
3147
|
-
|
|
3312
|
+
_private_attachToInstancedPlane(handler, instancedPlane, properties, transform, visibility) {
|
|
3313
|
+
const instanceHandler = instancedPlane.createInstance();
|
|
3314
|
+
instancedPlane.setProperties(instanceHandler, properties);
|
|
3315
|
+
instancedPlane.setTransform(instanceHandler, transform);
|
|
3316
|
+
instancedPlane.setVisibility(instanceHandler, visibility);
|
|
3317
|
+
this._private_handlerToPlaneDescriptor.set(handler, {
|
|
3318
|
+
plane: instancedPlane,
|
|
3319
|
+
instanceHandler,
|
|
3320
|
+
});
|
|
3148
3321
|
}
|
|
3149
|
-
|
|
3150
|
-
const
|
|
3151
|
-
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
return !descriptor.plane.arePropertiesCompatible(newProperties);
|
|
3156
|
-
}
|
|
3157
|
-
const compatibleInstanced = this._private_findCompatibleInstancedPlane(currentData.source, newProperties, newTransparency);
|
|
3158
|
-
if (compatibleInstanced) {
|
|
3159
|
-
return true;
|
|
3322
|
+
_private_insertPlane(handler, planeData) {
|
|
3323
|
+
const { source, properties, transparency, transform, visibility } = planeData;
|
|
3324
|
+
const compatibleInstancedPlane = this._private_findCompatibleInstancedPlane(source, properties, transparency);
|
|
3325
|
+
if (compatibleInstancedPlane) {
|
|
3326
|
+
this._private_attachToInstancedPlane(handler, compatibleInstancedPlane, properties, transform, visibility);
|
|
3327
|
+
return;
|
|
3160
3328
|
}
|
|
3161
|
-
const
|
|
3162
|
-
if (
|
|
3163
|
-
|
|
3329
|
+
const compatibleSinglePlanePair = this._private_findCompatibleSinglePlane(source, properties, transparency);
|
|
3330
|
+
if (compatibleSinglePlanePair) {
|
|
3331
|
+
const instancedPlane = this._private_promoteSinglePlaneToInstancedPlane(compatibleSinglePlanePair[0], compatibleSinglePlanePair[1]);
|
|
3332
|
+
this._private_attachToInstancedPlane(handler, instancedPlane, properties, transform, visibility);
|
|
3333
|
+
return;
|
|
3164
3334
|
}
|
|
3165
|
-
|
|
3335
|
+
const plane = new UIGenericPlane(source, properties, transform, visibility, transparency);
|
|
3336
|
+
this._private_scene.add(plane);
|
|
3337
|
+
this._private_handlerToPlaneDescriptor.set(handler, { plane });
|
|
3166
3338
|
}
|
|
3167
|
-
|
|
3168
|
-
const
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
instancedPlane.setVisibility(instanceHandler, visibility);
|
|
3174
|
-
descriptor.plane = instancedPlane;
|
|
3175
|
-
descriptor.instanceHandler = instanceHandler;
|
|
3176
|
-
}
|
|
3177
|
-
_private_createSinglePlane(descriptor, source, properties, transparency, transform, visibility) {
|
|
3178
|
-
const singlePlane = new UIGenericPlane(source, properties, transparency);
|
|
3179
|
-
singlePlane.setProperties(properties);
|
|
3180
|
-
if (transform) {
|
|
3181
|
-
singlePlane.setTransform(transform);
|
|
3182
|
-
}
|
|
3183
|
-
singlePlane.setVisibility(visibility);
|
|
3184
|
-
this._private_scene.add(singlePlane);
|
|
3185
|
-
descriptor.plane = singlePlane;
|
|
3186
|
-
delete descriptor.instanceHandler;
|
|
3187
|
-
}
|
|
3188
|
-
_private_findCompatibleSinglePlane(source, properties, transparency, excludeDescriptor) {
|
|
3189
|
-
for (const descriptor of this._private_descriptors.values()) {
|
|
3190
|
-
if (descriptor === excludeDescriptor) {
|
|
3191
|
-
continue;
|
|
3192
|
-
}
|
|
3193
|
-
if (descriptor.plane instanceof UIGenericPlane &&
|
|
3194
|
-
descriptor.plane.isCompatible(source, properties, transparency)) {
|
|
3195
|
-
return descriptor;
|
|
3339
|
+
_private_findCompatibleSinglePlane(source, properties, transparency) {
|
|
3340
|
+
for (const handlerPlaneDescriptorPair of this._private_handlerToPlaneDescriptor) {
|
|
3341
|
+
const planeDescriptor = handlerPlaneDescriptorPair[1];
|
|
3342
|
+
if (isSinglePlaneDescriptor(planeDescriptor) &&
|
|
3343
|
+
planeDescriptor.plane.isPartiallyCompatible(source, properties, transparency)) {
|
|
3344
|
+
return [handlerPlaneDescriptorPair[0], planeDescriptor];
|
|
3196
3345
|
}
|
|
3197
3346
|
}
|
|
3198
3347
|
return undefined;
|
|
3199
3348
|
}
|
|
3200
3349
|
_private_findCompatibleInstancedPlane(source, properties, transparency) {
|
|
3201
|
-
for (const
|
|
3202
|
-
|
|
3203
|
-
|
|
3204
|
-
|
|
3350
|
+
for (const handlerPlaneDescriptorPair of this._private_handlerToPlaneDescriptor) {
|
|
3351
|
+
const planeDescriptor = handlerPlaneDescriptorPair[1];
|
|
3352
|
+
if (isInstancedPlaneDescriptor(planeDescriptor) &&
|
|
3353
|
+
planeDescriptor.plane.isPartiallyCompatible(source, properties, transparency)) {
|
|
3354
|
+
return planeDescriptor.plane;
|
|
3205
3355
|
}
|
|
3206
3356
|
}
|
|
3207
3357
|
return undefined;
|
|
3208
3358
|
}
|
|
3209
|
-
|
|
3210
|
-
const
|
|
3211
|
-
const oldData = oldPlane.extractInstanceData();
|
|
3212
|
-
const instancedPlane = new UIGenericInstancedPlane(oldData.source, templateProperties, oldData.transparency);
|
|
3213
|
-
const oldInstanceHandler = instancedPlane.createInstance();
|
|
3214
|
-
instancedPlane.setProperties(oldInstanceHandler, oldData.properties);
|
|
3215
|
-
instancedPlane.setTransform(oldInstanceHandler, oldData.transform);
|
|
3216
|
-
instancedPlane.setVisibility(oldInstanceHandler, oldData.visibility);
|
|
3217
|
-
promotableDescriptor.plane = instancedPlane;
|
|
3218
|
-
promotableDescriptor.instanceHandler = oldInstanceHandler;
|
|
3219
|
-
this._private_scene.remove(oldPlane);
|
|
3220
|
-
oldPlane.destroy();
|
|
3221
|
-
this._private_scene.add(instancedPlane);
|
|
3222
|
-
return instancedPlane;
|
|
3223
|
-
}
|
|
3224
|
-
_private_demoteToSingle(instancedPlane, removedDescriptor) {
|
|
3225
|
-
let remainingDescriptor;
|
|
3226
|
-
for (const descriptor of this._private_descriptors.values()) {
|
|
3227
|
-
if (descriptor !== removedDescriptor &&
|
|
3228
|
-
descriptor.plane === instancedPlane &&
|
|
3229
|
-
descriptor.instanceHandler !== undefined) {
|
|
3230
|
-
remainingDescriptor = descriptor;
|
|
3231
|
-
break;
|
|
3232
|
-
}
|
|
3233
|
-
}
|
|
3234
|
-
if (!remainingDescriptor) {
|
|
3235
|
-
return;
|
|
3236
|
-
}
|
|
3237
|
-
const data = instancedPlane.extractInstanceData(remainingDescriptor.instanceHandler);
|
|
3238
|
-
const singlePlane = new UIGenericPlane(data.source, data.properties, data.transparency);
|
|
3239
|
-
singlePlane.setProperties(data.properties);
|
|
3240
|
-
singlePlane.setTransform(data.transform);
|
|
3241
|
-
singlePlane.setVisibility(data.visibility);
|
|
3242
|
-
this._private_scene.remove(instancedPlane);
|
|
3243
|
-
instancedPlane.destroy();
|
|
3244
|
-
this._private_scene.add(singlePlane);
|
|
3245
|
-
remainingDescriptor.plane = singlePlane;
|
|
3246
|
-
delete remainingDescriptor.instanceHandler;
|
|
3247
|
-
}
|
|
3248
|
-
_private_resolveDescriptor(handler) {
|
|
3249
|
-
const descriptor = this._private_descriptors.get(handler);
|
|
3359
|
+
_private_resolvePlaneDescriptor(handler) {
|
|
3360
|
+
const descriptor = this._private_handlerToPlaneDescriptor.get(handler);
|
|
3250
3361
|
if (!descriptor) {
|
|
3251
|
-
throw new Error(`UIGenericPlaneRegistry.
|
|
3362
|
+
throw new Error(`UIGenericPlaneRegistry.resolvePlaneDescriptor.handler: descriptor not found`);
|
|
3252
3363
|
}
|
|
3253
3364
|
return descriptor;
|
|
3254
3365
|
}
|
|
@@ -3263,26 +3374,26 @@ let originalAutoClearStencil = false;
|
|
|
3263
3374
|
class UISceneWrapper {
|
|
3264
3375
|
constructor(width, height) {
|
|
3265
3376
|
this._private_scene = new Scene();
|
|
3266
|
-
this.
|
|
3377
|
+
this._private_planeRegistry = new UIPlaneRegistry(this._private_scene);
|
|
3267
3378
|
this._private_camera = new OrthographicCamera(0, width, height, 0, -1024, 1024);
|
|
3268
3379
|
}
|
|
3269
|
-
createPlane(source, properties, transparency) {
|
|
3270
|
-
return this.
|
|
3380
|
+
createPlane(source, properties, transform, visibility, transparency) {
|
|
3381
|
+
return this._private_planeRegistry.createPlane(source, properties, transform, visibility, transparency);
|
|
3271
3382
|
}
|
|
3272
3383
|
destroyPlane(handler) {
|
|
3273
|
-
this.
|
|
3384
|
+
this._private_planeRegistry.destroyPlane(handler);
|
|
3274
3385
|
}
|
|
3275
3386
|
setTransform(handler, transform) {
|
|
3276
|
-
this.
|
|
3387
|
+
this._private_planeRegistry.setTransform(handler, transform);
|
|
3277
3388
|
}
|
|
3278
3389
|
setProperties(handler, properties) {
|
|
3279
|
-
this.
|
|
3390
|
+
this._private_planeRegistry.setProperties(handler, properties);
|
|
3280
3391
|
}
|
|
3281
3392
|
setVisibility(handler, visible) {
|
|
3282
|
-
this.
|
|
3393
|
+
this._private_planeRegistry.setVisibility(handler, visible);
|
|
3283
3394
|
}
|
|
3284
3395
|
setTransparency(handler, transparency) {
|
|
3285
|
-
this.
|
|
3396
|
+
this._private_planeRegistry.setTransparency(handler, transparency);
|
|
3286
3397
|
}
|
|
3287
3398
|
insertCustomObject(object) {
|
|
3288
3399
|
this._private_scene.add(object);
|
|
@@ -3472,7 +3583,7 @@ function convertRelation(relation) {
|
|
|
3472
3583
|
case UIRelation.GREATER_THAN:
|
|
3473
3584
|
return Operator.Ge;
|
|
3474
3585
|
default:
|
|
3475
|
-
throw new Error(`convertRelation: invalid relation`);
|
|
3586
|
+
throw new Error(`convertRelation.relation: invalid relation`);
|
|
3476
3587
|
}
|
|
3477
3588
|
}
|
|
3478
3589
|
/**
|
|
@@ -3950,7 +4061,7 @@ class UISolverWrapper {
|
|
|
3950
4061
|
.map(([variableIndex, coefficient]) => {
|
|
3951
4062
|
const description = this._private_variables.get(variableIndex);
|
|
3952
4063
|
if (description === undefined) {
|
|
3953
|
-
throw new Error(`UISolverWrapper.convertExpression: variable does not exist`);
|
|
4064
|
+
throw new Error(`UISolverWrapper.convertExpression.expression: variable does not exist`);
|
|
3954
4065
|
}
|
|
3955
4066
|
return [coefficient, description.variable];
|
|
3956
4067
|
}), expression.constant);
|
|
@@ -3995,28 +4106,35 @@ var UILayerEvent;
|
|
|
3995
4106
|
/** Fired during rendering */
|
|
3996
4107
|
UILayerEvent["RENDERING"] = "rendering";
|
|
3997
4108
|
})(UILayerEvent || (UILayerEvent = {}));
|
|
4109
|
+
const LAYER_DEFAULT_SIZE = 1024;
|
|
4110
|
+
const LAYER_DEFAULT_NAME = "";
|
|
4111
|
+
const LAYER_DEFAULT_MODE = UIMode.VISIBLE;
|
|
3998
4112
|
|
|
3999
4113
|
/** Base layer for UI rendering and layout management */
|
|
4000
4114
|
class UILayer extends i {
|
|
4001
|
-
|
|
4002
|
-
* @param w Initial width in world units
|
|
4003
|
-
* @param h Initial height in world units
|
|
4004
|
-
* @param mode Initial visibility and interactivity mode
|
|
4005
|
-
*/
|
|
4006
|
-
constructor(w, h, mode) {
|
|
4115
|
+
constructor(options) {
|
|
4007
4116
|
super();
|
|
4008
4117
|
/** Optional layer name */
|
|
4009
4118
|
this.name = "";
|
|
4010
4119
|
this.inputWrapperInternal = new UIInputWrapper();
|
|
4011
4120
|
this._private_solverWrapperInternal = new UISolverWrapper();
|
|
4012
|
-
|
|
4013
|
-
|
|
4121
|
+
if (options.width !== undefined) {
|
|
4122
|
+
assertValidPositiveNumber(options.width, "UILayer.constructor.options.width");
|
|
4123
|
+
}
|
|
4124
|
+
if (options.height !== undefined) {
|
|
4125
|
+
assertValidPositiveNumber(options.height, "UILayer.constructor.options.height");
|
|
4126
|
+
}
|
|
4127
|
+
const width = options.width ?? LAYER_DEFAULT_SIZE;
|
|
4128
|
+
const height = options.height ?? LAYER_DEFAULT_SIZE;
|
|
4129
|
+
this._private_sceneWrapperInternal = new UISceneWrapper(width, height);
|
|
4130
|
+
this.name = options.name ?? LAYER_DEFAULT_NAME;
|
|
4131
|
+
this._private_modeInternal = options.mode ?? LAYER_DEFAULT_MODE;
|
|
4014
4132
|
this._private_orientationInternal =
|
|
4015
|
-
|
|
4133
|
+
width > height ? UIOrientation.HORIZONTAL : UIOrientation.VERTICAL;
|
|
4016
4134
|
this.xVariable = this._private_solverWrapperInternal.createVariable(0, UIPriority.P0);
|
|
4017
4135
|
this.yVariable = this._private_solverWrapperInternal.createVariable(0, UIPriority.P0);
|
|
4018
|
-
this.wVariable = this._private_solverWrapperInternal.createVariable(
|
|
4019
|
-
this.hVariable = this._private_solverWrapperInternal.createVariable(
|
|
4136
|
+
this.wVariable = this._private_solverWrapperInternal.createVariable(width, UIPriority.P0);
|
|
4137
|
+
this.hVariable = this._private_solverWrapperInternal.createVariable(height, UIPriority.P0);
|
|
4020
4138
|
}
|
|
4021
4139
|
/** @internal */
|
|
4022
4140
|
get sceneWrapper() {
|
|
@@ -4271,29 +4389,28 @@ function assertValidInterpolationConstraintArguments(subject, a, b, c, anchorA,
|
|
|
4271
4389
|
}
|
|
4272
4390
|
return layerA;
|
|
4273
4391
|
}
|
|
4274
|
-
if (a instanceof UILayer) {
|
|
4275
|
-
return a;
|
|
4276
|
-
}
|
|
4277
4392
|
if (isUILayerElement(a)) {
|
|
4278
4393
|
return a.layer;
|
|
4279
4394
|
}
|
|
4280
|
-
if (b instanceof UILayer) {
|
|
4281
|
-
return b;
|
|
4282
|
-
}
|
|
4283
4395
|
if (isUILayerElement(b)) {
|
|
4284
4396
|
return b.layer;
|
|
4285
4397
|
}
|
|
4398
|
+
if (a instanceof UILayer) {
|
|
4399
|
+
return a;
|
|
4400
|
+
}
|
|
4401
|
+
if (b instanceof UILayer) {
|
|
4402
|
+
return b;
|
|
4403
|
+
}
|
|
4286
4404
|
throw new Error(`${subject}: no valid subjects found`);
|
|
4287
4405
|
}
|
|
4288
4406
|
|
|
4289
4407
|
/** Base class for layout constraints */
|
|
4290
4408
|
class UIConstraint {
|
|
4291
4409
|
/** @param layer Layer containing this constraint */
|
|
4292
|
-
constructor(layer) {
|
|
4410
|
+
constructor(layer, name) {
|
|
4293
4411
|
this.layer = layer;
|
|
4294
|
-
/** Optional constraint name */
|
|
4295
|
-
this.name = "";
|
|
4296
4412
|
this.solverWrapper = this.layer.solverWrapper;
|
|
4413
|
+
this.name = name ?? "";
|
|
4297
4414
|
}
|
|
4298
4415
|
}
|
|
4299
4416
|
|
|
@@ -4304,7 +4421,7 @@ class UISingleParameterConstraint extends UIConstraint {
|
|
|
4304
4421
|
* @param options Constraint configuration
|
|
4305
4422
|
*/
|
|
4306
4423
|
constructor(layer, options) {
|
|
4307
|
-
super(layer);
|
|
4424
|
+
super(layer, options?.name);
|
|
4308
4425
|
/** Updates constraint enabled state when layer orientation changes */
|
|
4309
4426
|
this._private_onOrientationChange = () => {
|
|
4310
4427
|
this.solverWrapper.setConstraintEnabled(this.constraint, this.isConstraintEnabled());
|
|
@@ -5894,7 +6011,7 @@ class UIInputDummy extends UIAnchor {
|
|
|
5894
6011
|
assertValidPositiveNumber(w, "UIInputDummy.constructor.width");
|
|
5895
6012
|
assertValidPositiveNumber(h, "UIInputDummy.constructor.height");
|
|
5896
6013
|
super(layer, options);
|
|
5897
|
-
this.
|
|
6014
|
+
this._private_wasPointerInside = false;
|
|
5898
6015
|
this.catchPointerDown = (x, y, identifier) => {
|
|
5899
6016
|
return this.handleInputEvent(x, y, identifier, UIInputEvent.PRESSED);
|
|
5900
6017
|
};
|
|
@@ -6003,16 +6120,14 @@ class UIInputDummy extends UIAnchor {
|
|
|
6003
6120
|
if (isPointerInside) {
|
|
6004
6121
|
this.emit(inputEvent, x, y, identifier, this);
|
|
6005
6122
|
}
|
|
6006
|
-
if (this.
|
|
6123
|
+
if (this._private_wasPointerInside && !isPointerInside) {
|
|
6007
6124
|
this.emit(UIInputEvent.LEFT, x, y, identifier, this);
|
|
6008
6125
|
}
|
|
6009
|
-
else if (!this.
|
|
6126
|
+
else if (!this._private_wasPointerInside && isPointerInside) {
|
|
6010
6127
|
this.emit(UIInputEvent.ENTERED, x, y, identifier, this);
|
|
6011
6128
|
}
|
|
6012
|
-
this.
|
|
6013
|
-
return this.modeInternal
|
|
6014
|
-
? false
|
|
6015
|
-
: isPointerInside;
|
|
6129
|
+
this._private_wasPointerInside = isPointerInside;
|
|
6130
|
+
return (this.modeInternal !== UIMode.INTERACTIVE_TRANSPARENT && isPointerInside);
|
|
6016
6131
|
}
|
|
6017
6132
|
}
|
|
6018
6133
|
|
|
@@ -6036,10 +6151,7 @@ class UIElement extends UIInputDummy {
|
|
|
6036
6151
|
this._private_transparencyModeInternal =
|
|
6037
6152
|
options?.transparencyMode ?? ELEMENT_DEFAULT_TRANSPARENCY_MODE;
|
|
6038
6153
|
this.sceneWrapper = this.layer.sceneWrapper;
|
|
6039
|
-
this.planeHandler = this.sceneWrapper.createPlane(source, properties, this._private_transparencyModeInternal);
|
|
6040
|
-
if (options?.mode !== undefined && !isUIModeVisible(options.mode)) {
|
|
6041
|
-
this._private_visibilityDirty = true;
|
|
6042
|
-
}
|
|
6154
|
+
this.planeHandler = this.sceneWrapper.createPlane(source, properties, new Matrix4().identity(), isUIModeVisible(options?.mode ?? this.mode), this._private_transparencyModeInternal);
|
|
6043
6155
|
this.layer.on(UILayerEvent.RENDERING, this.onWillRender, this);
|
|
6044
6156
|
}
|
|
6045
6157
|
/** Alpha blending mode */
|
|
@@ -6098,8 +6210,19 @@ var UIAnimatedImageEvent;
|
|
|
6098
6210
|
/** Animation stopped and reset */
|
|
6099
6211
|
UIAnimatedImageEvent[UIAnimatedImageEvent["STOPPED"] = 2] = "STOPPED";
|
|
6100
6212
|
})(UIAnimatedImageEvent || (UIAnimatedImageEvent = {}));
|
|
6213
|
+
/** Animation loop behavior */
|
|
6214
|
+
var UIAnimatedImageLoopMode;
|
|
6215
|
+
(function (UIAnimatedImageLoopMode) {
|
|
6216
|
+
/** No looping, stops at boundary frame */
|
|
6217
|
+
UIAnimatedImageLoopMode[UIAnimatedImageLoopMode["NONE"] = 0] = "NONE";
|
|
6218
|
+
/** Loops back to opposite frame */
|
|
6219
|
+
UIAnimatedImageLoopMode[UIAnimatedImageLoopMode["LOOP"] = 1] = "LOOP";
|
|
6220
|
+
/** Reverses direction at boundaries */
|
|
6221
|
+
UIAnimatedImageLoopMode[UIAnimatedImageLoopMode["PING_PONG"] = 2] = "PING_PONG";
|
|
6222
|
+
})(UIAnimatedImageLoopMode || (UIAnimatedImageLoopMode = {}));
|
|
6101
6223
|
const ANIMATED_IMAGE_DEFAULT_FRAME_RATE = 24;
|
|
6102
|
-
const
|
|
6224
|
+
const ANIMATED_IMAGE_DEFAULT_TIME_SCALE = 1;
|
|
6225
|
+
const ANIMATED_IMAGE_DEFAULT_LOOP_MODE = UIAnimatedImageLoopMode.LOOP;
|
|
6103
6226
|
|
|
6104
6227
|
/** Frame-based texture animation element */
|
|
6105
6228
|
class UIAnimatedImage extends UIElement {
|
|
@@ -6134,32 +6257,56 @@ class UIAnimatedImage extends UIElement {
|
|
|
6134
6257
|
this.height = height;
|
|
6135
6258
|
}
|
|
6136
6259
|
};
|
|
6260
|
+
this._private_colorInternal = color;
|
|
6137
6261
|
this._private_sequenceInternal = uiTextures;
|
|
6138
6262
|
this._private_textureTransform = textureTransform;
|
|
6139
6263
|
this._private_frameRateInternal =
|
|
6140
6264
|
options.frameRate ?? ANIMATED_IMAGE_DEFAULT_FRAME_RATE;
|
|
6141
|
-
this.
|
|
6142
|
-
|
|
6265
|
+
this._private_timeScaleInternal =
|
|
6266
|
+
options.timeScale ?? ANIMATED_IMAGE_DEFAULT_TIME_SCALE;
|
|
6267
|
+
this._private_loopModeInternal =
|
|
6268
|
+
options.loopMode ?? ANIMATED_IMAGE_DEFAULT_LOOP_MODE;
|
|
6143
6269
|
this._private_subscribeSequenceEvents();
|
|
6144
6270
|
if (options.playByDefault === true) {
|
|
6145
6271
|
this.play();
|
|
6146
6272
|
}
|
|
6147
6273
|
}
|
|
6148
|
-
/**
|
|
6149
|
-
get
|
|
6150
|
-
return this.
|
|
6274
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6275
|
+
get color() {
|
|
6276
|
+
return this._private_colorInternal;
|
|
6277
|
+
}
|
|
6278
|
+
/** Total animation duration in seconds */
|
|
6279
|
+
get duration() {
|
|
6280
|
+
return this._private_sequenceInternal.length / this._private_frameRateInternal;
|
|
6151
6281
|
}
|
|
6152
6282
|
/** Animation speed in frames per second */
|
|
6153
6283
|
get frameRate() {
|
|
6154
6284
|
return this._private_frameRateInternal;
|
|
6155
6285
|
}
|
|
6156
|
-
/**
|
|
6157
|
-
get
|
|
6158
|
-
return this.
|
|
6286
|
+
/** Loop behavior */
|
|
6287
|
+
get loopMode() {
|
|
6288
|
+
return this._private_loopModeInternal;
|
|
6159
6289
|
}
|
|
6160
|
-
/**
|
|
6161
|
-
get
|
|
6162
|
-
return this._private_sequenceInternal
|
|
6290
|
+
/** Animation frames as readonly array */
|
|
6291
|
+
get sequence() {
|
|
6292
|
+
return this._private_sequenceInternal;
|
|
6293
|
+
}
|
|
6294
|
+
/** Playback speed multiplier. Can be negative for reverse playback. */
|
|
6295
|
+
get timeScale() {
|
|
6296
|
+
return this._private_timeScaleInternal;
|
|
6297
|
+
}
|
|
6298
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6299
|
+
set color(value) {
|
|
6300
|
+
this._private_colorInternal.set(value);
|
|
6301
|
+
}
|
|
6302
|
+
/** Animation speed in frames per second */
|
|
6303
|
+
set frameRate(value) {
|
|
6304
|
+
assertValidPositiveNumber(value, "UIAnimatedImage.frameRate");
|
|
6305
|
+
this._private_frameRateInternal = value;
|
|
6306
|
+
}
|
|
6307
|
+
/** Loop behavior */
|
|
6308
|
+
set loopMode(value) {
|
|
6309
|
+
this._private_loopModeInternal = value;
|
|
6163
6310
|
}
|
|
6164
6311
|
/** Replaces animation frames. Stops playback. */
|
|
6165
6312
|
set sequence(sequence) {
|
|
@@ -6180,14 +6327,10 @@ class UIAnimatedImage extends UIElement {
|
|
|
6180
6327
|
}
|
|
6181
6328
|
this._private_subscribeSequenceEvents();
|
|
6182
6329
|
}
|
|
6183
|
-
/**
|
|
6184
|
-
set
|
|
6185
|
-
|
|
6186
|
-
this.
|
|
6187
|
-
}
|
|
6188
|
-
/** Whether animation repeats after completion */
|
|
6189
|
-
set loop(value) {
|
|
6190
|
-
this._private_loopInternal = value;
|
|
6330
|
+
/** Playback speed multiplier. Can be negative for reverse playback. */
|
|
6331
|
+
set timeScale(value) {
|
|
6332
|
+
assertValidNumber(value, "UIAnimatedImage.timeScale");
|
|
6333
|
+
this._private_timeScaleInternal = value;
|
|
6191
6334
|
}
|
|
6192
6335
|
/** Removes element and frees resources */
|
|
6193
6336
|
destroy() {
|
|
@@ -6221,32 +6364,64 @@ class UIAnimatedImage extends UIElement {
|
|
|
6221
6364
|
}
|
|
6222
6365
|
}
|
|
6223
6366
|
onWillRender(renderer, deltaTime) {
|
|
6224
|
-
if (this._private_isPlaying) {
|
|
6225
|
-
this._private_accumulatedTime += deltaTime;
|
|
6367
|
+
if (this._private_isPlaying && this._private_timeScaleInternal !== 0) {
|
|
6368
|
+
this._private_accumulatedTime += deltaTime * this._private_timeScaleInternal;
|
|
6226
6369
|
const frameDuration = 1 / this._private_frameRateInternal;
|
|
6227
|
-
|
|
6228
|
-
|
|
6229
|
-
|
|
6230
|
-
|
|
6231
|
-
this.
|
|
6370
|
+
const sequenceLength = this._private_sequenceInternal.length;
|
|
6371
|
+
const lastFrameIndex = sequenceLength - 1;
|
|
6372
|
+
if (this._private_timeScaleInternal > 0) {
|
|
6373
|
+
while (this._private_accumulatedTime >= frameDuration) {
|
|
6374
|
+
this._private_accumulatedTime -= frameDuration;
|
|
6375
|
+
this._private_sequenceFrameIndex += 1;
|
|
6376
|
+
if (this._private_sequenceFrameIndex >= sequenceLength) {
|
|
6377
|
+
if (this._private_loopModeInternal === UIAnimatedImageLoopMode.LOOP) {
|
|
6378
|
+
this._private_sequenceFrameIndex = 0;
|
|
6379
|
+
}
|
|
6380
|
+
else if (this._private_loopModeInternal === UIAnimatedImageLoopMode.PING_PONG) {
|
|
6381
|
+
this._private_sequenceFrameIndex = lastFrameIndex;
|
|
6382
|
+
this._private_timeScaleInternal = -this._private_timeScaleInternal;
|
|
6383
|
+
}
|
|
6384
|
+
else {
|
|
6385
|
+
this._private_sequenceFrameIndex = lastFrameIndex;
|
|
6386
|
+
this._private_isPlaying = false;
|
|
6387
|
+
this.emit(UIAnimatedImageEvent.PAUSED);
|
|
6388
|
+
break;
|
|
6389
|
+
}
|
|
6390
|
+
}
|
|
6391
|
+
this._private_currentFrameIndexDirty = true;
|
|
6232
6392
|
}
|
|
6233
|
-
|
|
6234
|
-
|
|
6235
|
-
|
|
6236
|
-
this.
|
|
6237
|
-
|
|
6393
|
+
}
|
|
6394
|
+
else {
|
|
6395
|
+
while (this._private_accumulatedTime <= -frameDuration) {
|
|
6396
|
+
this._private_accumulatedTime += frameDuration;
|
|
6397
|
+
this._private_sequenceFrameIndex -= 1;
|
|
6398
|
+
if (this._private_sequenceFrameIndex < 0) {
|
|
6399
|
+
if (this._private_loopModeInternal === UIAnimatedImageLoopMode.LOOP) {
|
|
6400
|
+
this._private_sequenceFrameIndex = lastFrameIndex;
|
|
6401
|
+
}
|
|
6402
|
+
else if (this._private_loopModeInternal === UIAnimatedImageLoopMode.PING_PONG) {
|
|
6403
|
+
this._private_sequenceFrameIndex = 0;
|
|
6404
|
+
this._private_timeScaleInternal = -this._private_timeScaleInternal;
|
|
6405
|
+
}
|
|
6406
|
+
else {
|
|
6407
|
+
this._private_sequenceFrameIndex = 0;
|
|
6408
|
+
this._private_isPlaying = false;
|
|
6409
|
+
this.emit(UIAnimatedImageEvent.PAUSED);
|
|
6410
|
+
break;
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6413
|
+
this._private_currentFrameIndexDirty = true;
|
|
6238
6414
|
}
|
|
6239
|
-
this._private_currentFrameIndexDirty = true;
|
|
6240
6415
|
}
|
|
6241
6416
|
}
|
|
6242
6417
|
super.onWillRender(renderer, deltaTime);
|
|
6243
6418
|
}
|
|
6244
6419
|
setPlaneTransform() {
|
|
6245
6420
|
let properties;
|
|
6246
|
-
if (this.
|
|
6421
|
+
if (this._private_colorInternal.dirty) {
|
|
6247
6422
|
properties ?? (properties = {});
|
|
6248
|
-
properties["color"] = this.
|
|
6249
|
-
this.
|
|
6423
|
+
properties["color"] = this._private_colorInternal;
|
|
6424
|
+
this._private_colorInternal.setDirtyFalse();
|
|
6250
6425
|
}
|
|
6251
6426
|
const frame = this._private_sequenceInternal[this._private_sequenceFrameIndex];
|
|
6252
6427
|
if (frame.textureDirty || this._private_currentFrameIndexDirty) {
|
|
@@ -6288,6 +6463,10 @@ class UIAnimatedImage extends UIElement {
|
|
|
6288
6463
|
}
|
|
6289
6464
|
}
|
|
6290
6465
|
|
|
6466
|
+
const GRAPHICS_DEFAULT_WIDTH = 2;
|
|
6467
|
+
const GRAPHICS_DEFAULT_HEIGHT = 2;
|
|
6468
|
+
const GRAPHICS_TEMP_COLOR = new UIColor();
|
|
6469
|
+
|
|
6291
6470
|
/** Canvas-based 2D drawing element */
|
|
6292
6471
|
class UIGraphics extends UIElement {
|
|
6293
6472
|
/**
|
|
@@ -6297,8 +6476,8 @@ class UIGraphics extends UIElement {
|
|
|
6297
6476
|
* @param options - Configuration options
|
|
6298
6477
|
*/
|
|
6299
6478
|
constructor(layer, options) {
|
|
6300
|
-
const w = options?.width ??
|
|
6301
|
-
const h = options?.height ??
|
|
6479
|
+
const w = options?.width ?? GRAPHICS_DEFAULT_WIDTH;
|
|
6480
|
+
const h = options?.height ?? GRAPHICS_DEFAULT_HEIGHT;
|
|
6302
6481
|
const color = new UIColor(options?.color);
|
|
6303
6482
|
const canvas = new OffscreenCanvas(w, h);
|
|
6304
6483
|
const context = canvas.getContext("2d");
|
|
@@ -6312,13 +6491,21 @@ class UIGraphics extends UIElement {
|
|
|
6312
6491
|
texture.needsUpdate = true;
|
|
6313
6492
|
super(layer, source$4, {
|
|
6314
6493
|
texture: texture,
|
|
6315
|
-
textureTransform:
|
|
6494
|
+
textureTransform: new Matrix4(),
|
|
6316
6495
|
color,
|
|
6317
6496
|
}, options);
|
|
6318
6497
|
this._private_canvas = canvas;
|
|
6319
6498
|
this._private_context = context;
|
|
6320
6499
|
this._private_texture = texture;
|
|
6321
|
-
this.
|
|
6500
|
+
this._private_colorInternal = color;
|
|
6501
|
+
}
|
|
6502
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6503
|
+
get color() {
|
|
6504
|
+
return this._private_colorInternal;
|
|
6505
|
+
}
|
|
6506
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6507
|
+
set color(value) {
|
|
6508
|
+
this._private_colorInternal.set(value);
|
|
6322
6509
|
}
|
|
6323
6510
|
/**
|
|
6324
6511
|
* Clears canvas. Optionally fills with color.
|
|
@@ -6328,7 +6515,7 @@ class UIGraphics extends UIElement {
|
|
|
6328
6515
|
clear(color) {
|
|
6329
6516
|
this._private_context.clearRect(0, 0, this._private_canvas.width, this._private_canvas.height);
|
|
6330
6517
|
if (color !== undefined) {
|
|
6331
|
-
this._private_context.fillStyle = color.toCSSColor();
|
|
6518
|
+
this._private_context.fillStyle = GRAPHICS_TEMP_COLOR.set(color).toCSSColor();
|
|
6332
6519
|
this._private_context.fillRect(0, 0, this._private_canvas.width, this._private_canvas.height);
|
|
6333
6520
|
}
|
|
6334
6521
|
this._private_texture.needsUpdate = true;
|
|
@@ -6336,14 +6523,14 @@ class UIGraphics extends UIElement {
|
|
|
6336
6523
|
}
|
|
6337
6524
|
/** Draws filled rectangle */
|
|
6338
6525
|
drawRect(x, y, width, height, color) {
|
|
6339
|
-
this._private_context.fillStyle = color.toCSSColor();
|
|
6526
|
+
this._private_context.fillStyle = GRAPHICS_TEMP_COLOR.set(color).toCSSColor();
|
|
6340
6527
|
this._private_context.fillRect(x, y, width, height);
|
|
6341
6528
|
this._private_texture.needsUpdate = true;
|
|
6342
6529
|
return this;
|
|
6343
6530
|
}
|
|
6344
6531
|
/** Draws filled circle */
|
|
6345
6532
|
drawCircle(x, y, radius, color) {
|
|
6346
|
-
this._private_context.fillStyle = color.toCSSColor();
|
|
6533
|
+
this._private_context.fillStyle = GRAPHICS_TEMP_COLOR.set(color).toCSSColor();
|
|
6347
6534
|
this._private_context.beginPath();
|
|
6348
6535
|
this._private_context.arc(x, y, radius, 0, Math.PI * 2);
|
|
6349
6536
|
this._private_context.fill();
|
|
@@ -6357,7 +6544,7 @@ class UIGraphics extends UIElement {
|
|
|
6357
6544
|
* @param endAngle - End angle in radians
|
|
6358
6545
|
*/
|
|
6359
6546
|
drawArc(x, y, radius, startAngle, endAngle, color) {
|
|
6360
|
-
this._private_context.fillStyle = color.toCSSColor();
|
|
6547
|
+
this._private_context.fillStyle = GRAPHICS_TEMP_COLOR.set(color).toCSSColor();
|
|
6361
6548
|
this._private_context.beginPath();
|
|
6362
6549
|
this._private_context.arc(x, y, radius, startAngle, endAngle);
|
|
6363
6550
|
this._private_context.fill();
|
|
@@ -6374,7 +6561,7 @@ class UIGraphics extends UIElement {
|
|
|
6374
6561
|
if (points.length < 2) {
|
|
6375
6562
|
return this;
|
|
6376
6563
|
}
|
|
6377
|
-
this._private_context.strokeStyle = color.toCSSColor();
|
|
6564
|
+
this._private_context.strokeStyle = GRAPHICS_TEMP_COLOR.set(color).toCSSColor();
|
|
6378
6565
|
this._private_context.lineWidth = lineWidth;
|
|
6379
6566
|
this._private_context.beginPath();
|
|
6380
6567
|
this._private_context.moveTo(points[0][0], points[0][1]);
|
|
@@ -6391,9 +6578,11 @@ class UIGraphics extends UIElement {
|
|
|
6391
6578
|
super.destroy();
|
|
6392
6579
|
}
|
|
6393
6580
|
onWillRender(renderer, deltaTime) {
|
|
6394
|
-
if (this.
|
|
6395
|
-
this.sceneWrapper.setProperties(this.planeHandler, {
|
|
6396
|
-
|
|
6581
|
+
if (this._private_colorInternal.dirty) {
|
|
6582
|
+
this.sceneWrapper.setProperties(this.planeHandler, {
|
|
6583
|
+
color: this._private_colorInternal,
|
|
6584
|
+
});
|
|
6585
|
+
this._private_colorInternal.setDirtyFalse();
|
|
6397
6586
|
}
|
|
6398
6587
|
super.onWillRender(renderer, deltaTime);
|
|
6399
6588
|
}
|
|
@@ -6427,9 +6616,17 @@ class UIImage extends UIElement {
|
|
|
6427
6616
|
};
|
|
6428
6617
|
this.texture = textureView;
|
|
6429
6618
|
this._private_textureTransform = textureTransform;
|
|
6430
|
-
this.
|
|
6619
|
+
this._private_colorInternal = color;
|
|
6431
6620
|
this.texture.on(UITextureViewEvent.DIMENSIONS_CHANGED, this._private_onTextureDimensionsChanged);
|
|
6432
6621
|
}
|
|
6622
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6623
|
+
get color() {
|
|
6624
|
+
return this._private_colorInternal;
|
|
6625
|
+
}
|
|
6626
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6627
|
+
set color(value) {
|
|
6628
|
+
this._private_colorInternal.set(value);
|
|
6629
|
+
}
|
|
6433
6630
|
/** Removes image and frees resources */
|
|
6434
6631
|
destroy() {
|
|
6435
6632
|
this.texture.off(UITextureViewEvent.DIMENSIONS_CHANGED, this._private_onTextureDimensionsChanged);
|
|
@@ -6437,10 +6634,10 @@ class UIImage extends UIElement {
|
|
|
6437
6634
|
}
|
|
6438
6635
|
setPlaneTransform() {
|
|
6439
6636
|
let properties;
|
|
6440
|
-
if (this.
|
|
6637
|
+
if (this._private_colorInternal.dirty) {
|
|
6441
6638
|
properties ?? (properties = {});
|
|
6442
|
-
properties["color"] = this.
|
|
6443
|
-
this.
|
|
6639
|
+
properties["color"] = this._private_colorInternal;
|
|
6640
|
+
this._private_colorInternal.setDirtyFalse();
|
|
6444
6641
|
}
|
|
6445
6642
|
if (this.texture.textureDirty) {
|
|
6446
6643
|
properties ?? (properties = {});
|
|
@@ -6479,44 +6676,12 @@ class UIInsets {
|
|
|
6479
6676
|
* @param config - Insets configuration
|
|
6480
6677
|
*/
|
|
6481
6678
|
constructor(config) {
|
|
6679
|
+
this._private_lInternal = INSETS_DEFAULT_VALUE;
|
|
6680
|
+
this._private_rInternal = INSETS_DEFAULT_VALUE;
|
|
6681
|
+
this._private_tInternal = INSETS_DEFAULT_VALUE;
|
|
6682
|
+
this._private_bInternal = INSETS_DEFAULT_VALUE;
|
|
6482
6683
|
this._private_dirtyInternal = false;
|
|
6483
|
-
|
|
6484
|
-
this._private_lInternal = INSETS_DEFAULT_VALUE;
|
|
6485
|
-
this._private_rInternal = INSETS_DEFAULT_VALUE;
|
|
6486
|
-
this._private_tInternal = INSETS_DEFAULT_VALUE;
|
|
6487
|
-
this._private_bInternal = INSETS_DEFAULT_VALUE;
|
|
6488
|
-
}
|
|
6489
|
-
else if (typeof config === "number") {
|
|
6490
|
-
assertValidNonNegativeNumber(config, "UIInsets.constructor.config");
|
|
6491
|
-
this._private_lInternal = config;
|
|
6492
|
-
this._private_rInternal = config;
|
|
6493
|
-
this._private_tInternal = config;
|
|
6494
|
-
this._private_bInternal = config;
|
|
6495
|
-
}
|
|
6496
|
-
else if ("left" in config) {
|
|
6497
|
-
const left = config.left;
|
|
6498
|
-
const right = config.right;
|
|
6499
|
-
const top = config.top;
|
|
6500
|
-
const bottom = config.bottom;
|
|
6501
|
-
assertValidNonNegativeNumber(left, "UIInsets.constructor.config.left");
|
|
6502
|
-
assertValidNonNegativeNumber(right, "UIInsets.constructor.config.right");
|
|
6503
|
-
assertValidNonNegativeNumber(top, "UIInsets.constructor.config.top");
|
|
6504
|
-
assertValidNonNegativeNumber(bottom, "UIInsets.constructor.config.bottom");
|
|
6505
|
-
this._private_lInternal = left;
|
|
6506
|
-
this._private_rInternal = right;
|
|
6507
|
-
this._private_tInternal = top;
|
|
6508
|
-
this._private_bInternal = bottom;
|
|
6509
|
-
}
|
|
6510
|
-
else {
|
|
6511
|
-
const horizontal = config.horizontal;
|
|
6512
|
-
const vertical = config.vertical;
|
|
6513
|
-
assertValidNonNegativeNumber(horizontal, "UIInsets.constructor.config.horizontal");
|
|
6514
|
-
assertValidNonNegativeNumber(vertical, "UIInsets.constructor.config.vertical");
|
|
6515
|
-
this._private_lInternal = horizontal;
|
|
6516
|
-
this._private_rInternal = horizontal;
|
|
6517
|
-
this._private_tInternal = vertical;
|
|
6518
|
-
this._private_bInternal = vertical;
|
|
6519
|
-
}
|
|
6684
|
+
this.set(config);
|
|
6520
6685
|
}
|
|
6521
6686
|
/** Left inset */
|
|
6522
6687
|
get left() {
|
|
@@ -6602,6 +6767,82 @@ class UIInsets {
|
|
|
6602
6767
|
this._private_dirtyInternal = true;
|
|
6603
6768
|
}
|
|
6604
6769
|
}
|
|
6770
|
+
/** Sets insets */
|
|
6771
|
+
set(config) {
|
|
6772
|
+
const lOld = this._private_lInternal;
|
|
6773
|
+
const rOld = this._private_rInternal;
|
|
6774
|
+
const tOld = this._private_tInternal;
|
|
6775
|
+
const bOld = this._private_bInternal;
|
|
6776
|
+
if (config === undefined) {
|
|
6777
|
+
this._private_lInternal = INSETS_DEFAULT_VALUE;
|
|
6778
|
+
this._private_rInternal = INSETS_DEFAULT_VALUE;
|
|
6779
|
+
this._private_tInternal = INSETS_DEFAULT_VALUE;
|
|
6780
|
+
this._private_bInternal = INSETS_DEFAULT_VALUE;
|
|
6781
|
+
}
|
|
6782
|
+
else if (typeof config === "number") {
|
|
6783
|
+
assertValidNonNegativeNumber(config, "UIInsets.set.config");
|
|
6784
|
+
this._private_lInternal = config;
|
|
6785
|
+
this._private_rInternal = config;
|
|
6786
|
+
this._private_tInternal = config;
|
|
6787
|
+
this._private_bInternal = config;
|
|
6788
|
+
}
|
|
6789
|
+
else if (Array.isArray(config)) {
|
|
6790
|
+
if (config.length === 2) {
|
|
6791
|
+
const horizontal = config[0];
|
|
6792
|
+
const vertical = config[1];
|
|
6793
|
+
assertValidNonNegativeNumber(horizontal, "UIInsets.set.config[0]");
|
|
6794
|
+
assertValidNonNegativeNumber(vertical, "UIInsets.set.config[1]");
|
|
6795
|
+
this._private_lInternal = horizontal;
|
|
6796
|
+
this._private_rInternal = horizontal;
|
|
6797
|
+
this._private_tInternal = vertical;
|
|
6798
|
+
this._private_bInternal = vertical;
|
|
6799
|
+
}
|
|
6800
|
+
else {
|
|
6801
|
+
const left = config[0];
|
|
6802
|
+
const right = config[1];
|
|
6803
|
+
const top = config[2];
|
|
6804
|
+
const bottom = config[3];
|
|
6805
|
+
assertValidNonNegativeNumber(left, "UIInsets.set.config[0]");
|
|
6806
|
+
assertValidNonNegativeNumber(right, "UIInsets.set.config[1]");
|
|
6807
|
+
assertValidNonNegativeNumber(top, "UIInsets.set.config[2]");
|
|
6808
|
+
assertValidNonNegativeNumber(bottom, "UIInsets.set.config[3]");
|
|
6809
|
+
this._private_lInternal = left;
|
|
6810
|
+
this._private_rInternal = right;
|
|
6811
|
+
this._private_tInternal = top;
|
|
6812
|
+
this._private_bInternal = bottom;
|
|
6813
|
+
}
|
|
6814
|
+
}
|
|
6815
|
+
else if ("left" in config) {
|
|
6816
|
+
const left = config.left;
|
|
6817
|
+
const right = config.right;
|
|
6818
|
+
const top = config.top;
|
|
6819
|
+
const bottom = config.bottom;
|
|
6820
|
+
assertValidNonNegativeNumber(left, "UIInsets.set.config.left");
|
|
6821
|
+
assertValidNonNegativeNumber(right, "UIInsets.set.config.right");
|
|
6822
|
+
assertValidNonNegativeNumber(top, "UIInsets.set.config.top");
|
|
6823
|
+
assertValidNonNegativeNumber(bottom, "UIInsets.set.config.bottom");
|
|
6824
|
+
this._private_lInternal = left;
|
|
6825
|
+
this._private_rInternal = right;
|
|
6826
|
+
this._private_tInternal = top;
|
|
6827
|
+
this._private_bInternal = bottom;
|
|
6828
|
+
}
|
|
6829
|
+
else {
|
|
6830
|
+
const horizontal = config.horizontal;
|
|
6831
|
+
const vertical = config.vertical;
|
|
6832
|
+
assertValidNonNegativeNumber(horizontal, "UIInsets.set.config.horizontal");
|
|
6833
|
+
assertValidNonNegativeNumber(vertical, "UIInsets.set.config.vertical");
|
|
6834
|
+
this._private_lInternal = horizontal;
|
|
6835
|
+
this._private_rInternal = horizontal;
|
|
6836
|
+
this._private_tInternal = vertical;
|
|
6837
|
+
this._private_bInternal = vertical;
|
|
6838
|
+
}
|
|
6839
|
+
if (this._private_lInternal !== lOld ||
|
|
6840
|
+
this._private_rInternal !== rOld ||
|
|
6841
|
+
this._private_tInternal !== tOld ||
|
|
6842
|
+
this._private_bInternal !== bOld) {
|
|
6843
|
+
this._private_dirtyInternal = true;
|
|
6844
|
+
}
|
|
6845
|
+
}
|
|
6605
6846
|
/** Sets from Vector4 (x=left, y=right, z=top, w=bottom) */
|
|
6606
6847
|
setVector4(vector) {
|
|
6607
6848
|
assertValidNonNegativeNumber(vector.x, "UIInsets.setVector4.vector.x");
|
|
@@ -6688,24 +6929,45 @@ class UINineSlice extends UIElement {
|
|
|
6688
6929
|
sliceBorders: sliceBordersVector,
|
|
6689
6930
|
sliceRegions: sliceRegionsVector,
|
|
6690
6931
|
}, options);
|
|
6691
|
-
this._private_regionModeDirty =
|
|
6932
|
+
this._private_regionModeDirty = true;
|
|
6692
6933
|
this._private_sliceBordersVector = new Vector4();
|
|
6693
6934
|
this._private_sliceRegionsVector = new Vector4();
|
|
6935
|
+
this._private_textureDimensionsDirty = true;
|
|
6936
|
+
this._private_onTextureDimensionsChanged = () => {
|
|
6937
|
+
this._private_textureDimensionsDirty = true;
|
|
6938
|
+
};
|
|
6694
6939
|
this.texture = textureView;
|
|
6695
6940
|
this._private_textureTransform = textureTransform;
|
|
6696
|
-
this.
|
|
6697
|
-
this.
|
|
6698
|
-
this.
|
|
6941
|
+
this._private_colorInternal = color;
|
|
6942
|
+
this._private_sliceBordersInternal = sliceBorders;
|
|
6943
|
+
this._private_sliceRegionsInternal = sliceRegions;
|
|
6699
6944
|
this._private_regionModeInternal = regionMode;
|
|
6700
6945
|
this._private_sliceBordersVector = sliceBordersVector;
|
|
6701
6946
|
this._private_sliceRegionsVector = sliceRegionsVector;
|
|
6702
|
-
this.
|
|
6703
|
-
this.
|
|
6947
|
+
this._private_lastElementWidth = this.width;
|
|
6948
|
+
this._private_lastElementHeight = this.height;
|
|
6949
|
+
this.texture.on(UITextureViewEvent.DIMENSIONS_CHANGED, this._private_onTextureDimensionsChanged);
|
|
6950
|
+
}
|
|
6951
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6952
|
+
get color() {
|
|
6953
|
+
return this._private_colorInternal;
|
|
6704
6954
|
}
|
|
6705
6955
|
/** Controls how sliceRegions values are interpreted */
|
|
6706
6956
|
get regionMode() {
|
|
6707
6957
|
return this._private_regionModeInternal;
|
|
6708
6958
|
}
|
|
6959
|
+
/** Border size in normalized texture coordinates (0 to 1) */
|
|
6960
|
+
get sliceBorders() {
|
|
6961
|
+
return this._private_sliceBordersInternal;
|
|
6962
|
+
}
|
|
6963
|
+
/** Region size. Interpretation depends on regionMode. */
|
|
6964
|
+
get sliceRegions() {
|
|
6965
|
+
return this._private_sliceRegionsInternal;
|
|
6966
|
+
}
|
|
6967
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
6968
|
+
set color(value) {
|
|
6969
|
+
this._private_colorInternal.set(value);
|
|
6970
|
+
}
|
|
6709
6971
|
/** Controls how sliceRegions values are interpreted */
|
|
6710
6972
|
set regionMode(value) {
|
|
6711
6973
|
if (this._private_regionModeInternal !== value) {
|
|
@@ -6713,44 +6975,68 @@ class UINineSlice extends UIElement {
|
|
|
6713
6975
|
this._private_regionModeDirty = true;
|
|
6714
6976
|
}
|
|
6715
6977
|
}
|
|
6978
|
+
/** Border size in normalized texture coordinates (0 to 1) */
|
|
6979
|
+
set sliceBorders(value) {
|
|
6980
|
+
this._private_sliceBordersInternal.set(value);
|
|
6981
|
+
}
|
|
6982
|
+
/** Region size. Interpretation depends on regionMode. */
|
|
6983
|
+
set sliceRegions(value) {
|
|
6984
|
+
this._private_sliceRegionsInternal.set(value);
|
|
6985
|
+
}
|
|
6986
|
+
/** Removes nine slice and frees resources */
|
|
6987
|
+
destroy() {
|
|
6988
|
+
this.texture.off(UITextureViewEvent.DIMENSIONS_CHANGED, this._private_onTextureDimensionsChanged);
|
|
6989
|
+
super.destroy();
|
|
6990
|
+
}
|
|
6716
6991
|
setPlaneTransform() {
|
|
6717
|
-
|
|
6718
|
-
|
|
6719
|
-
this.
|
|
6720
|
-
this.texture.trimDirty
|
|
6721
|
-
|
|
6722
|
-
|
|
6723
|
-
this.
|
|
6992
|
+
let properties;
|
|
6993
|
+
const sliceBordersDirty = this._private_textureDimensionsDirty ||
|
|
6994
|
+
this._private_sliceBordersInternal.dirty ||
|
|
6995
|
+
this.texture.trimDirty;
|
|
6996
|
+
if (sliceBordersDirty) {
|
|
6997
|
+
properties ?? (properties = {});
|
|
6998
|
+
properties["sliceBorders"] = this._private_calculateSliceBordersForShader(this._private_sliceBordersVector);
|
|
6999
|
+
this._private_sliceBordersInternal.setDirtyFalse();
|
|
7000
|
+
this._private_textureDimensionsDirty = false;
|
|
7001
|
+
}
|
|
7002
|
+
const sliceRegionsDirty = this._private_sliceRegionsInternal.dirty || this._private_regionModeDirty ||
|
|
6724
7003
|
(this._private_regionModeInternal === UINineSliceRegionMode.WORLD &&
|
|
6725
|
-
this.
|
|
6726
|
-
|
|
6727
|
-
|
|
6728
|
-
this.
|
|
6729
|
-
|
|
6730
|
-
textureTransform: this.texture.calculateUVTransform(this._private_textureTransform),
|
|
6731
|
-
color: this.color,
|
|
6732
|
-
sliceBorders: this._private_sliceBordersVector,
|
|
6733
|
-
sliceRegions: this._private_sliceRegionsVector,
|
|
6734
|
-
});
|
|
7004
|
+
this._private_checkElementDimensionsDirty());
|
|
7005
|
+
if (sliceRegionsDirty) {
|
|
7006
|
+
properties ?? (properties = {});
|
|
7007
|
+
properties["sliceRegions"] = this._private_calculateSliceRegionsForShader(this._private_sliceRegionsVector);
|
|
7008
|
+
this._private_sliceRegionsInternal.setDirtyFalse();
|
|
6735
7009
|
this._private_regionModeDirty = false;
|
|
6736
|
-
this.
|
|
6737
|
-
|
|
6738
|
-
|
|
6739
|
-
|
|
7010
|
+
this._private_setElementDimensionsDirtyFalse();
|
|
7011
|
+
}
|
|
7012
|
+
if (this._private_colorInternal.dirty) {
|
|
7013
|
+
properties ?? (properties = {});
|
|
7014
|
+
properties["color"] = this._private_colorInternal;
|
|
7015
|
+
this._private_colorInternal.setDirtyFalse();
|
|
7016
|
+
}
|
|
7017
|
+
if (this.texture.textureDirty) {
|
|
7018
|
+
properties ?? (properties = {});
|
|
7019
|
+
properties["texture"] = this.texture.texture;
|
|
7020
|
+
this.texture.setTextureDirtyFalse();
|
|
7021
|
+
}
|
|
7022
|
+
if (this.texture.uvTransformDirty) {
|
|
7023
|
+
properties ?? (properties = {});
|
|
7024
|
+
properties["textureTransform"] = this.texture.calculateUVTransform(this._private_textureTransform);
|
|
7025
|
+
this.texture.setUVTransformDirtyFalse();
|
|
6740
7026
|
}
|
|
6741
|
-
if (
|
|
6742
|
-
this.
|
|
7027
|
+
if (properties) {
|
|
7028
|
+
this.sceneWrapper.setProperties(this.planeHandler, properties);
|
|
7029
|
+
}
|
|
7030
|
+
const isTransformDirty = this.micro.dirty ||
|
|
6743
7031
|
this.texture.trimDirty ||
|
|
6744
|
-
this.micro.dirty ||
|
|
6745
7032
|
this.inputWrapper.dirty ||
|
|
6746
|
-
this.solverWrapper.dirty
|
|
6747
|
-
|
|
7033
|
+
this.solverWrapper.dirty;
|
|
7034
|
+
if (isTransformDirty) {
|
|
6748
7035
|
const micro = this.micro;
|
|
6749
|
-
|
|
6750
|
-
this.
|
|
6751
|
-
this.texture.setUVTransformDirtyFalse();
|
|
6752
|
-
this.texture.setTrimDirtyFalse();
|
|
7036
|
+
const textureTrim = this.texture.trim;
|
|
7037
|
+
this.sceneWrapper.setTransform(this.planeHandler, computeTrimmedTransformMatrix(this.x, this.y, this.width, this.height, this.zIndex, micro.x, micro.y, micro.anchorX, micro.anchorY, micro.scaleX, micro.scaleY, micro.rotation, micro.anchorMode, textureTrim.left, textureTrim.right, textureTrim.top, textureTrim.bottom));
|
|
6753
7038
|
this.micro.setDirtyFalse();
|
|
7039
|
+
this.texture.setTrimDirtyFalse();
|
|
6754
7040
|
}
|
|
6755
7041
|
}
|
|
6756
7042
|
_private_calculateSliceBordersForShader(result) {
|
|
@@ -6765,10 +7051,10 @@ class UINineSlice extends UIElement {
|
|
|
6765
7051
|
const trimNBottom = trim.bottom / sourceHeight;
|
|
6766
7052
|
const trimmedWidthNorm = trimmedWidth / sourceWidth;
|
|
6767
7053
|
const trimmedHeightNorm = trimmedHeight / sourceHeight;
|
|
6768
|
-
const srcLeft = this.
|
|
6769
|
-
const srcRight = this.
|
|
6770
|
-
const srcTop = this.
|
|
6771
|
-
const srcBottom = this.
|
|
7054
|
+
const srcLeft = this._private_sliceBordersInternal.left;
|
|
7055
|
+
const srcRight = this._private_sliceBordersInternal.right;
|
|
7056
|
+
const srcTop = this._private_sliceBordersInternal.top;
|
|
7057
|
+
const srcBottom = this._private_sliceBordersInternal.bottom;
|
|
6772
7058
|
const left = Math.max(0, srcLeft - trimNLeft) / trimmedWidthNorm;
|
|
6773
7059
|
const right = Math.max(0, srcRight - trimNRight) / trimmedWidthNorm;
|
|
6774
7060
|
const top = Math.max(0, srcTop - trimNTop) / trimmedHeightNorm;
|
|
@@ -6777,20 +7063,20 @@ class UINineSlice extends UIElement {
|
|
|
6777
7063
|
}
|
|
6778
7064
|
_private_calculateSliceRegionsForShader(result) {
|
|
6779
7065
|
if (this._private_regionModeInternal === UINineSliceRegionMode.NORMALIZED) {
|
|
6780
|
-
return result.set(this.
|
|
7066
|
+
return result.set(this._private_sliceRegionsInternal.left, this._private_sliceRegionsInternal.right, this._private_sliceRegionsInternal.top, this._private_sliceRegionsInternal.bottom);
|
|
6781
7067
|
}
|
|
6782
7068
|
const width = this.width;
|
|
6783
7069
|
const height = this.height;
|
|
6784
|
-
return result.set(this.
|
|
7070
|
+
return result.set(this._private_sliceRegionsInternal.left / width, this._private_sliceRegionsInternal.right / width, this._private_sliceRegionsInternal.top / height, this._private_sliceRegionsInternal.bottom / height);
|
|
6785
7071
|
}
|
|
6786
|
-
|
|
7072
|
+
_private_checkElementDimensionsDirty() {
|
|
6787
7073
|
return (this.solverWrapper.dirty &&
|
|
6788
|
-
(this.
|
|
6789
|
-
this.
|
|
7074
|
+
(this._private_lastElementWidth !== Math.round(this.width) ||
|
|
7075
|
+
this._private_lastElementHeight !== Math.round(this.height)));
|
|
6790
7076
|
}
|
|
6791
|
-
|
|
6792
|
-
this.
|
|
6793
|
-
this.
|
|
7077
|
+
_private_setElementDimensionsDirtyFalse() {
|
|
7078
|
+
this._private_lastElementWidth = Math.round(this.width);
|
|
7079
|
+
this._private_lastElementHeight = Math.round(this.height);
|
|
6794
7080
|
}
|
|
6795
7081
|
}
|
|
6796
7082
|
|
|
@@ -6903,15 +7189,34 @@ class UIProgress extends UIElement {
|
|
|
6903
7189
|
this.texture = textureView;
|
|
6904
7190
|
this._private_textureTransform = textureTransform;
|
|
6905
7191
|
this._private_textureResolution = textureResolution;
|
|
6906
|
-
this.
|
|
7192
|
+
this._private_colorInternal = color;
|
|
6907
7193
|
this._private_progressInternal = progress;
|
|
6908
|
-
this.
|
|
7194
|
+
this._private_maskFunctionInternal = maskFunction;
|
|
6909
7195
|
this.texture.on(UITextureViewEvent.DIMENSIONS_CHANGED, this._private_onTextureDimensionsChanged);
|
|
6910
7196
|
}
|
|
7197
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
7198
|
+
get color() {
|
|
7199
|
+
return this._private_colorInternal;
|
|
7200
|
+
}
|
|
7201
|
+
/** Function controlling fill direction and shape */
|
|
7202
|
+
get maskFunction() {
|
|
7203
|
+
return this._private_maskFunctionInternal;
|
|
7204
|
+
}
|
|
6911
7205
|
/** Progress from 0 (empty) to 1 (full) */
|
|
6912
7206
|
get progress() {
|
|
6913
7207
|
return this._private_progressInternal;
|
|
6914
7208
|
}
|
|
7209
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
7210
|
+
set color(value) {
|
|
7211
|
+
this._private_colorInternal.set(value);
|
|
7212
|
+
}
|
|
7213
|
+
/** Function controlling fill direction and shape */
|
|
7214
|
+
set maskFunction(value) {
|
|
7215
|
+
if (this._private_maskFunctionInternal !== value) {
|
|
7216
|
+
this._private_maskFunctionInternal = value;
|
|
7217
|
+
this._private_rebuildPlane();
|
|
7218
|
+
}
|
|
7219
|
+
}
|
|
6915
7220
|
/** Progress from 0 (empty) to 1 (full). Clamped. */
|
|
6916
7221
|
set progress(value) {
|
|
6917
7222
|
assertValidNumber(value, "UIProgress.progress");
|
|
@@ -6923,10 +7228,10 @@ class UIProgress extends UIElement {
|
|
|
6923
7228
|
}
|
|
6924
7229
|
setPlaneTransform() {
|
|
6925
7230
|
let properties;
|
|
6926
|
-
if (this.
|
|
7231
|
+
if (this._private_colorInternal.dirty) {
|
|
6927
7232
|
properties ?? (properties = {});
|
|
6928
|
-
properties["color"] = this.
|
|
6929
|
-
this.
|
|
7233
|
+
properties["color"] = this._private_colorInternal;
|
|
7234
|
+
this._private_colorInternal.setDirtyFalse();
|
|
6930
7235
|
}
|
|
6931
7236
|
if (this.texture.textureDirty) {
|
|
6932
7237
|
properties ?? (properties = {});
|
|
@@ -6971,13 +7276,34 @@ class UIProgress extends UIElement {
|
|
|
6971
7276
|
this.texture.setTrimDirtyFalse();
|
|
6972
7277
|
}
|
|
6973
7278
|
}
|
|
7279
|
+
_private_rebuildPlane() {
|
|
7280
|
+
this.sceneWrapper.destroyPlane(this.planeHandler);
|
|
7281
|
+
const micro = this.micro;
|
|
7282
|
+
const textureTrim = this.texture.trim;
|
|
7283
|
+
this.planeHandler = this.sceneWrapper.createPlane(this._private_maskFunctionInternal.source + source$1, {
|
|
7284
|
+
texture: this.texture.texture,
|
|
7285
|
+
textureTransform: this.texture.calculateUVTransform(this._private_textureTransform),
|
|
7286
|
+
textureResolution: this.texture.getResolution(this._private_textureResolution),
|
|
7287
|
+
color: this._private_colorInternal,
|
|
7288
|
+
progress: this._private_progressInternal,
|
|
7289
|
+
...this._private_maskFunctionInternal.enumerateProperties(),
|
|
7290
|
+
}, computeTrimmedTransformMatrix(this.x, this.y, this.width, this.height, this.zIndex, micro.x, micro.y, micro.anchorX, micro.anchorY, micro.scaleX, micro.scaleY, micro.rotation, micro.anchorMode, textureTrim.left, textureTrim.right, textureTrim.top, textureTrim.bottom), isUIModeVisible(this.mode), this.transparencyMode);
|
|
7291
|
+
this._private_colorInternal.setDirtyFalse();
|
|
7292
|
+
this.texture.setTextureDirtyFalse();
|
|
7293
|
+
this.texture.setUVTransformDirtyFalse();
|
|
7294
|
+
this.texture.setTrimDirtyFalse();
|
|
7295
|
+
this._private_progressDirty = false;
|
|
7296
|
+
this._private_textureResolutionDirty = false;
|
|
7297
|
+
this._private_maskFunctionInternal.setDirtyFalse();
|
|
7298
|
+
this.micro.setDirtyFalse();
|
|
7299
|
+
}
|
|
6974
7300
|
}
|
|
6975
7301
|
|
|
6976
7302
|
/** Controls when scene re-renders */
|
|
6977
7303
|
var UISceneUpdateMode;
|
|
6978
7304
|
(function (UISceneUpdateMode) {
|
|
6979
7305
|
/** Re-render every frame */
|
|
6980
|
-
UISceneUpdateMode[UISceneUpdateMode["
|
|
7306
|
+
UISceneUpdateMode[UISceneUpdateMode["EVERY_FRAME"] = 1] = "EVERY_FRAME";
|
|
6981
7307
|
/** Re-render every other frame */
|
|
6982
7308
|
UISceneUpdateMode[UISceneUpdateMode["EVERY_SECOND_FRAME"] = 2] = "EVERY_SECOND_FRAME";
|
|
6983
7309
|
/** Re-render when scene, camera, or updateMode changes */
|
|
@@ -7031,8 +7357,8 @@ class UIScene extends UIElement {
|
|
|
7031
7357
|
this._private_updateRequired = false;
|
|
7032
7358
|
this._private_resolutionFactorDirty = false;
|
|
7033
7359
|
this._private_propertyDirty = false;
|
|
7034
|
-
this.
|
|
7035
|
-
this.
|
|
7360
|
+
this._private_colorInternal = color;
|
|
7361
|
+
this._private_clearColorInternal = new UIColor(options.clearColor ?? SCENE_DEFAULT_CLEAR_COLOR);
|
|
7036
7362
|
this._private_renderTarget = renderTarget;
|
|
7037
7363
|
this._private_sceneInternal = options.scene ?? new Scene();
|
|
7038
7364
|
this._private_cameraInternal =
|
|
@@ -7042,28 +7368,29 @@ class UIScene extends UIElement {
|
|
|
7042
7368
|
this._private_updateModeInternal = options.updateMode ?? SCENE_DEFAULT_UPDATE_MODE;
|
|
7043
7369
|
this._private_propertyDirty = options.updateMode !== UISceneUpdateMode.MANUAL;
|
|
7044
7370
|
}
|
|
7045
|
-
/** Three.js scene to render */
|
|
7046
|
-
get scene() {
|
|
7047
|
-
return this._private_sceneInternal;
|
|
7048
|
-
}
|
|
7049
7371
|
/** Camera used for rendering */
|
|
7050
7372
|
get camera() {
|
|
7051
7373
|
return this._private_cameraInternal;
|
|
7052
7374
|
}
|
|
7053
|
-
/**
|
|
7054
|
-
get
|
|
7055
|
-
return this.
|
|
7375
|
+
/** Background color for render target */
|
|
7376
|
+
get clearColor() {
|
|
7377
|
+
return this._private_clearColorInternal;
|
|
7378
|
+
}
|
|
7379
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
7380
|
+
get color() {
|
|
7381
|
+
return this._private_colorInternal;
|
|
7056
7382
|
}
|
|
7057
7383
|
/** Render target resolution multiplier. Range 0.1 to 2.0. */
|
|
7058
7384
|
get resolutionFactor() {
|
|
7059
7385
|
return this._private_resolutionFactorInternal;
|
|
7060
7386
|
}
|
|
7061
7387
|
/** Three.js scene to render */
|
|
7062
|
-
|
|
7063
|
-
|
|
7064
|
-
|
|
7065
|
-
|
|
7066
|
-
|
|
7388
|
+
get scene() {
|
|
7389
|
+
return this._private_sceneInternal;
|
|
7390
|
+
}
|
|
7391
|
+
/** Controls when scene re-renders */
|
|
7392
|
+
get updateMode() {
|
|
7393
|
+
return this._private_updateModeInternal;
|
|
7067
7394
|
}
|
|
7068
7395
|
/** Camera used for rendering */
|
|
7069
7396
|
set camera(value) {
|
|
@@ -7072,12 +7399,13 @@ class UIScene extends UIElement {
|
|
|
7072
7399
|
this._private_propertyDirty = true;
|
|
7073
7400
|
}
|
|
7074
7401
|
}
|
|
7075
|
-
/**
|
|
7076
|
-
set
|
|
7077
|
-
|
|
7078
|
-
|
|
7079
|
-
|
|
7080
|
-
|
|
7402
|
+
/** Background color for render target */
|
|
7403
|
+
set clearColor(value) {
|
|
7404
|
+
this._private_clearColorInternal.set(value);
|
|
7405
|
+
}
|
|
7406
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
7407
|
+
set color(value) {
|
|
7408
|
+
this._private_colorInternal.set(value);
|
|
7081
7409
|
}
|
|
7082
7410
|
/** Render target resolution multiplier. Range 0.1 to 2.0. */
|
|
7083
7411
|
set resolutionFactor(value) {
|
|
@@ -7088,6 +7416,20 @@ class UIScene extends UIElement {
|
|
|
7088
7416
|
this._private_resolutionFactorDirty = true;
|
|
7089
7417
|
}
|
|
7090
7418
|
}
|
|
7419
|
+
/** Three.js scene to render */
|
|
7420
|
+
set scene(value) {
|
|
7421
|
+
if (this._private_sceneInternal !== value) {
|
|
7422
|
+
this._private_sceneInternal = value;
|
|
7423
|
+
this._private_propertyDirty = true;
|
|
7424
|
+
}
|
|
7425
|
+
}
|
|
7426
|
+
/** Controls when scene re-renders */
|
|
7427
|
+
set updateMode(value) {
|
|
7428
|
+
if (this._private_updateModeInternal !== value) {
|
|
7429
|
+
this._private_updateModeInternal = value;
|
|
7430
|
+
this._private_propertyDirty = true;
|
|
7431
|
+
}
|
|
7432
|
+
}
|
|
7091
7433
|
/** Removes element and frees resources */
|
|
7092
7434
|
destroy() {
|
|
7093
7435
|
this._private_renderTarget.dispose();
|
|
@@ -7100,11 +7442,11 @@ class UIScene extends UIElement {
|
|
|
7100
7442
|
onWillRender(renderer, deltaTime) {
|
|
7101
7443
|
this._private_evenFrame = !this._private_evenFrame;
|
|
7102
7444
|
const isFramebufferDirty = this._private_updateRequired ||
|
|
7103
|
-
this._private_updateModeInternal === UISceneUpdateMode.
|
|
7445
|
+
this._private_updateModeInternal === UISceneUpdateMode.EVERY_FRAME ||
|
|
7104
7446
|
(this._private_updateModeInternal === UISceneUpdateMode.EVERY_SECOND_FRAME && this._private_evenFrame) ||
|
|
7105
7447
|
(this._private_updateModeInternal === UISceneUpdateMode.ON_PROPERTIES_CHANGE && this._private_propertyDirty) ||
|
|
7106
|
-
this.
|
|
7107
|
-
this.
|
|
7448
|
+
this._private_colorInternal.dirty ||
|
|
7449
|
+
this._private_clearColorInternal.dirty ||
|
|
7108
7450
|
(this._private_updateModeInternal === UISceneUpdateMode.ON_DIMENSIONS_CHANGE &&
|
|
7109
7451
|
(this._private_resolutionFactorDirty || this.solverWrapper.dirty));
|
|
7110
7452
|
if (isFramebufferDirty) {
|
|
@@ -7112,13 +7454,13 @@ class UIScene extends UIElement {
|
|
|
7112
7454
|
this._private_renderTarget.setSize(this.width * this._private_resolutionFactorInternal, this.height * this._private_resolutionFactorInternal);
|
|
7113
7455
|
this._private_resolutionFactorDirty = false;
|
|
7114
7456
|
}
|
|
7115
|
-
if (this.
|
|
7457
|
+
if (this._private_colorInternal.dirty) {
|
|
7116
7458
|
this.sceneWrapper.setProperties(this.planeHandler, {
|
|
7117
|
-
color: this.
|
|
7459
|
+
color: this._private_colorInternal,
|
|
7118
7460
|
});
|
|
7119
|
-
this.
|
|
7461
|
+
this._private_colorInternal.setDirtyFalse();
|
|
7120
7462
|
}
|
|
7121
|
-
renderer.setClearColor(this.
|
|
7463
|
+
renderer.setClearColor(this._private_clearColorInternal.getHexRGB(), this._private_clearColorInternal.a);
|
|
7122
7464
|
renderer.setRenderTarget(this._private_renderTarget);
|
|
7123
7465
|
renderer.clear(true, true, false);
|
|
7124
7466
|
renderer.render(this._private_sceneInternal, this._private_cameraInternal);
|
|
@@ -7802,8 +8144,8 @@ class UIText extends UIElement {
|
|
|
7802
8144
|
this._private_resizeModeDirty = false;
|
|
7803
8145
|
this._private_textChunks = [];
|
|
7804
8146
|
this._private_textChunksDirty = false;
|
|
7805
|
-
this.
|
|
7806
|
-
this.
|
|
8147
|
+
this._private_colorInternal = color;
|
|
8148
|
+
this._private_paddingInternal = new UIInsets(options.padding);
|
|
7807
8149
|
this.commonStyle = new UITextStyle(options.commonStyle);
|
|
7808
8150
|
this._private_maxLineWidthInternal =
|
|
7809
8151
|
options.maxLineWidth ?? TEXT_DEFAULT_MAX_LINE_WIDTH;
|
|
@@ -7815,7 +8157,7 @@ class UIText extends UIElement {
|
|
|
7815
8157
|
this._private_lastWidth = this.width;
|
|
7816
8158
|
this._private_lastHeight = this.height;
|
|
7817
8159
|
if (options.padding === undefined) {
|
|
7818
|
-
this.
|
|
8160
|
+
this._private_paddingInternal.setUnified(this.content.reduce((a, b) => Math.max(a, b.style.calculatePadding()), this.commonStyle.calculatePadding()));
|
|
7819
8161
|
}
|
|
7820
8162
|
switch (this._private_resizeModeInternal) {
|
|
7821
8163
|
case UITextResizeMode.SCALE:
|
|
@@ -7826,6 +8168,10 @@ class UIText extends UIElement {
|
|
|
7826
8168
|
break;
|
|
7827
8169
|
}
|
|
7828
8170
|
}
|
|
8171
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
8172
|
+
get color() {
|
|
8173
|
+
return this._private_colorInternal;
|
|
8174
|
+
}
|
|
7829
8175
|
/** Text content as array of styled spans */
|
|
7830
8176
|
get content() {
|
|
7831
8177
|
return this._private_contentInternal;
|
|
@@ -7834,10 +8180,18 @@ class UIText extends UIElement {
|
|
|
7834
8180
|
get maxLineWidth() {
|
|
7835
8181
|
return this._private_maxLineWidthInternal;
|
|
7836
8182
|
}
|
|
8183
|
+
/** Text padding in world units */
|
|
8184
|
+
get padding() {
|
|
8185
|
+
return this._private_paddingInternal;
|
|
8186
|
+
}
|
|
7837
8187
|
/** Controls how text adapts to element size */
|
|
7838
8188
|
get resizeMode() {
|
|
7839
8189
|
return this._private_resizeModeInternal;
|
|
7840
8190
|
}
|
|
8191
|
+
/** Multiplicative tint. Alpha channel controls opacity. */
|
|
8192
|
+
set color(value) {
|
|
8193
|
+
this._private_colorInternal.set(value);
|
|
8194
|
+
}
|
|
7841
8195
|
/** Text content as string, span config, or array */
|
|
7842
8196
|
set content(value) {
|
|
7843
8197
|
if (this._private_contentInternal !== value) {
|
|
@@ -7873,6 +8227,10 @@ class UIText extends UIElement {
|
|
|
7873
8227
|
this._private_maxLineWidthDirty = true;
|
|
7874
8228
|
}
|
|
7875
8229
|
}
|
|
8230
|
+
/** Text padding in world units */
|
|
8231
|
+
set padding(value) {
|
|
8232
|
+
this._private_paddingInternal.set(value);
|
|
8233
|
+
}
|
|
7876
8234
|
/** Controls how text adapts to size constraints */
|
|
7877
8235
|
set resizeMode(value) {
|
|
7878
8236
|
if (this._private_resizeModeInternal !== value) {
|
|
@@ -7886,10 +8244,6 @@ class UIText extends UIElement {
|
|
|
7886
8244
|
super.destroy();
|
|
7887
8245
|
}
|
|
7888
8246
|
onWillRender(renderer, deltaTime) {
|
|
7889
|
-
if (this.color.dirty) {
|
|
7890
|
-
this.sceneWrapper.setProperties(this.planeHandler, { color: this.color });
|
|
7891
|
-
this.color.setDirtyFalse();
|
|
7892
|
-
}
|
|
7893
8247
|
switch (this._private_resizeModeInternal) {
|
|
7894
8248
|
case UITextResizeMode.SCALE:
|
|
7895
8249
|
this._private_tryToRenderTextScaleMode();
|
|
@@ -7903,7 +8257,7 @@ class UIText extends UIElement {
|
|
|
7903
8257
|
_private_tryToRenderTextScaleMode() {
|
|
7904
8258
|
if (!this._private_resizeModeDirty &&
|
|
7905
8259
|
!this._private_maxLineWidthDirty &&
|
|
7906
|
-
!this.
|
|
8260
|
+
!this._private_paddingInternal.dirty &&
|
|
7907
8261
|
!(this.solverWrapper.dirty &&
|
|
7908
8262
|
this._private_lastWidth / this._private_lastHeight !==
|
|
7909
8263
|
Math.round(this.width) / Math.round(this.height)) &&
|
|
@@ -7912,8 +8266,8 @@ class UIText extends UIElement {
|
|
|
7912
8266
|
}
|
|
7913
8267
|
const textChunks = this._private_buildTextChunks();
|
|
7914
8268
|
const { lines, size } = calculateTextContentParameters(textChunks, this._private_maxLineWidthInternal);
|
|
7915
|
-
const paddingV = this.
|
|
7916
|
-
const paddingH = this.
|
|
8269
|
+
const paddingV = this._private_paddingInternal.top + this._private_paddingInternal.bottom;
|
|
8270
|
+
const paddingH = this._private_paddingInternal.left + this._private_paddingInternal.right;
|
|
7917
8271
|
const desiredHeight = size.height + paddingV;
|
|
7918
8272
|
const desiredWidth = size.width + paddingH;
|
|
7919
8273
|
// Two calculation passes are required to cover both cases -
|
|
@@ -7928,20 +8282,18 @@ class UIText extends UIElement {
|
|
|
7928
8282
|
this._private_canvas.height = desiredHeight;
|
|
7929
8283
|
this._private_canvas.width = desiredWidth;
|
|
7930
8284
|
}
|
|
7931
|
-
renderTextLines(this.
|
|
7932
|
-
|
|
7933
|
-
this._private_rebuildTexture();
|
|
7934
|
-
}
|
|
8285
|
+
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, lines, this._private_context);
|
|
8286
|
+
this._private_updateProperties(resolutionDirty);
|
|
7935
8287
|
this._private_resizeModeDirty = false;
|
|
7936
8288
|
this._private_maxLineWidthDirty = false;
|
|
7937
|
-
this.
|
|
8289
|
+
this._private_paddingInternal.setDirtyFalse();
|
|
7938
8290
|
this._private_setDimensionsDirtyFalse();
|
|
7939
8291
|
this._private_setContentDirtyFalse();
|
|
7940
8292
|
}
|
|
7941
8293
|
_private_tryToRenderTextBreakMode() {
|
|
7942
8294
|
if (!this._private_resizeModeDirty &&
|
|
7943
8295
|
!this._private_maxLineWidthDirty &&
|
|
7944
|
-
!this.
|
|
8296
|
+
!this._private_paddingInternal.dirty &&
|
|
7945
8297
|
!this._private_checkDimensionsDirty() &&
|
|
7946
8298
|
!this._private_checkContentDirty()) {
|
|
7947
8299
|
return;
|
|
@@ -7951,8 +8303,8 @@ class UIText extends UIElement {
|
|
|
7951
8303
|
// suggest the desired sizes to the solver, and then
|
|
7952
8304
|
// adjust our expectations based on the result obtained.
|
|
7953
8305
|
const { size: desiredTextSize } = calculateTextContentParameters(textChunks, this._private_maxLineWidthInternal);
|
|
7954
|
-
const paddingV = this.
|
|
7955
|
-
const paddingH = this.
|
|
8306
|
+
const paddingV = this._private_paddingInternal.top + this._private_paddingInternal.bottom;
|
|
8307
|
+
const paddingH = this._private_paddingInternal.left + this._private_paddingInternal.right;
|
|
7956
8308
|
this.height = desiredTextSize.height + paddingV;
|
|
7957
8309
|
this.width = desiredTextSize.width + paddingH; // Width should remain a priority, so it is set last.
|
|
7958
8310
|
const { lines: realTextLines, size: realTextSize } = calculateTextContentParameters(textChunks, Math.round(this.width) - paddingH);
|
|
@@ -7965,24 +8317,32 @@ class UIText extends UIElement {
|
|
|
7965
8317
|
this._private_canvas.width = safeWidth;
|
|
7966
8318
|
this._private_canvas.height = safeHeight;
|
|
7967
8319
|
}
|
|
7968
|
-
renderTextLines(this.
|
|
7969
|
-
|
|
7970
|
-
this._private_rebuildTexture();
|
|
7971
|
-
}
|
|
8320
|
+
renderTextLines(this._private_paddingInternal.top, this._private_paddingInternal.left, realTextLines, this._private_context);
|
|
8321
|
+
this._private_updateProperties(resolutionDirty);
|
|
7972
8322
|
this._private_resizeModeDirty = false;
|
|
7973
8323
|
this._private_maxLineWidthDirty = false;
|
|
7974
|
-
this.
|
|
8324
|
+
this._private_paddingInternal.setDirtyFalse();
|
|
7975
8325
|
this._private_setDimensionsDirtyFalse();
|
|
7976
8326
|
this._private_setContentDirtyFalse();
|
|
7977
8327
|
}
|
|
7978
|
-
|
|
7979
|
-
|
|
7980
|
-
|
|
7981
|
-
|
|
7982
|
-
|
|
7983
|
-
|
|
7984
|
-
|
|
7985
|
-
|
|
8328
|
+
_private_updateProperties(resolutionDirty) {
|
|
8329
|
+
let properties;
|
|
8330
|
+
if (this._private_colorInternal.dirty) {
|
|
8331
|
+
properties ?? (properties = {});
|
|
8332
|
+
properties["color"] = this._private_colorInternal;
|
|
8333
|
+
this._private_colorInternal.setDirtyFalse();
|
|
8334
|
+
}
|
|
8335
|
+
if (resolutionDirty) {
|
|
8336
|
+
this._private_texture.dispose();
|
|
8337
|
+
this._private_texture = new CanvasTexture(this._private_canvas);
|
|
8338
|
+
this._private_texture.colorSpace = SRGBColorSpace;
|
|
8339
|
+
this._private_texture.needsUpdate = true;
|
|
8340
|
+
properties ?? (properties = {});
|
|
8341
|
+
properties["texture"] = this._private_texture;
|
|
8342
|
+
}
|
|
8343
|
+
if (properties) {
|
|
8344
|
+
this.sceneWrapper.setProperties(this.planeHandler, properties);
|
|
8345
|
+
}
|
|
7986
8346
|
}
|
|
7987
8347
|
_private_buildTextChunks() {
|
|
7988
8348
|
if (this._private_textChunksDirty) {
|
|
@@ -8028,15 +8388,18 @@ class UIResizePolicyNone extends UIResizePolicy {
|
|
|
8028
8388
|
}
|
|
8029
8389
|
}
|
|
8030
8390
|
|
|
8391
|
+
const FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY = new UIResizePolicyNone();
|
|
8392
|
+
|
|
8031
8393
|
/** Layer that automatically handles browser window resizing and input events */
|
|
8032
8394
|
class UIFullscreenLayer extends UILayer {
|
|
8033
|
-
|
|
8034
|
-
|
|
8035
|
-
* @param mode Initial visibility and interactivity mode
|
|
8036
|
-
*/
|
|
8037
|
-
constructor(resizePolicy = new UIResizePolicyNone(), mode = UIMode.VISIBLE) {
|
|
8395
|
+
constructor(options) {
|
|
8396
|
+
const resizePolicy = options?.resizePolicy ?? FULLSCREEN_LAYER_DEFAULT_RESIZE_POLICY;
|
|
8038
8397
|
const scale = resizePolicy.calculateScale(window.innerWidth, window.innerHeight);
|
|
8039
|
-
super(
|
|
8398
|
+
super({
|
|
8399
|
+
width: window.innerWidth * scale,
|
|
8400
|
+
height: window.innerHeight * scale,
|
|
8401
|
+
...options,
|
|
8402
|
+
});
|
|
8040
8403
|
this._private_resizePolicyDirty = false;
|
|
8041
8404
|
this._private_onResize = () => {
|
|
8042
8405
|
const scale = this.resizePolicy.calculateScale(window.innerWidth, window.innerHeight);
|
|
@@ -8093,23 +8456,27 @@ class UIFullscreenLayer extends UILayer {
|
|
|
8093
8456
|
* Projects 3D world position to 2D layer coordinates
|
|
8094
8457
|
* @param position World position
|
|
8095
8458
|
* @param camera Three.js camera
|
|
8459
|
+
* @param result Reusable vector instance
|
|
8096
8460
|
* @returns Layer coordinates
|
|
8097
8461
|
*/
|
|
8098
|
-
projectWorldPosition(position, camera) {
|
|
8099
|
-
|
|
8100
|
-
|
|
8101
|
-
|
|
8102
|
-
return
|
|
8462
|
+
projectWorldPosition(position, camera, result = new Vector3()) {
|
|
8463
|
+
result.copy(position).project(camera);
|
|
8464
|
+
result.x = MathUtils.mapLinear(result.x, -1, 1, this.x, this.width);
|
|
8465
|
+
result.y = MathUtils.mapLinear(result.y, -1, 1, this.y, this.height);
|
|
8466
|
+
return result;
|
|
8103
8467
|
}
|
|
8104
8468
|
/**
|
|
8105
8469
|
* Projects 2D layer coordinates to 3D world position
|
|
8106
8470
|
* @param position Layer coordinates
|
|
8107
8471
|
* @param camera Three.js camera
|
|
8108
8472
|
* @param z Depth coordinate
|
|
8473
|
+
* @param result Reusable vector instance
|
|
8109
8474
|
* @returns World position
|
|
8110
8475
|
*/
|
|
8111
|
-
projectLayerPosition(position, camera, z = -1) {
|
|
8112
|
-
return
|
|
8476
|
+
projectLayerPosition(position, camera, z = -1, result = new Vector3()) {
|
|
8477
|
+
return result
|
|
8478
|
+
.set(MathUtils.mapLinear(position.x, this.x, this.width, -1, 1), MathUtils.mapLinear(position.y, this.y, this.height, -1, 1), z)
|
|
8479
|
+
.unproject(camera);
|
|
8113
8480
|
}
|
|
8114
8481
|
/**
|
|
8115
8482
|
* Builds ray from layer position through camera
|
|
@@ -8609,5 +8976,5 @@ class UIResizePolicyFixedWidth extends UIResizePolicy {
|
|
|
8609
8976
|
}
|
|
8610
8977
|
}
|
|
8611
8978
|
|
|
8612
|
-
export { UIAnchor, UIAnimatedImage, UIAreaCircle, UIAreaPolygon, UIAreaRectangle, UIAreaRoundedRectangle, UIAspectConstraint, UIColor, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalInterpolationConstraint, UIHorizontalProportionConstraint, UIImage, UIInputDummy, UIInputEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UINineSliceRegionMode, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunctionCircular, UIProgressMaskFunctionDirectional, UIRelation, UIResizePolicyCover, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFit, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITextResizeMode, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalInterpolationConstraint, UIVerticalProportionConstraint, UIWidthConstraint };
|
|
8979
|
+
export { UIAnchor, UIAnimatedImage, UIAnimatedImageLoopMode, UIAreaCircle, UIAreaPolygon, UIAreaRectangle, UIAreaRoundedRectangle, UIAspectConstraint, UIColor, UIConstraint2DBuilder, UICoverConstraintBuilder, UICustomConstraint, UIExpression, UIFitConstraintBuilder, UIFullscreenLayer, UIGraphics, UIHeightConstraint, UIHorizontalDistanceConstraint, UIHorizontalInterpolationConstraint, UIHorizontalProportionConstraint, UIImage, UIInputDummy, UIInputEvent, UIMicro, UIMicroAnchorMode, UIMode, UINineSlice, UINineSliceRegionMode, UIOrientation, UIPriority, UIProgress, UIProgressMaskFunctionCircular, UIProgressMaskFunctionDirectional, UIRelation, UIResizePolicyCover, UIResizePolicyCross, UIResizePolicyCrossInverted, UIResizePolicyFit, UIResizePolicyFixedHeight, UIResizePolicyFixedWidth, UIResizePolicyNone, UIScene, UISceneUpdateMode, UISingleParameterConstraint, UIText, UITextResizeMode, UITransparencyMode, UIVerticalDistanceConstraint, UIVerticalInterpolationConstraint, UIVerticalProportionConstraint, UIWidthConstraint };
|
|
8613
8980
|
//# sourceMappingURL=index.js.map
|