laymur 0.9.0 → 0.10.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/dist/index.js +317 -51
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/miscellaneous/UIColor.d.ts +107 -11
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Vector4, PlaneGeometry, Color, Scene, OrthographicCamera, ShaderMaterial, Mesh, Texture, Vector2, Vector3, Matrix2, Matrix3, Matrix4, MathUtils, Quaternion, CanvasTexture, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, InstancedBufferGeometry, InstancedBufferAttribute } from 'three';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Mathematical expression builder for constraint equations in the UI layout system.
|
|
@@ -1815,6 +1815,14 @@ function resolvePriority(priority) {
|
|
|
1815
1815
|
return priority ?? UIPriority.P0;
|
|
1816
1816
|
}
|
|
1817
1817
|
|
|
1818
|
+
/**
|
|
1819
|
+
* Converts sRGB component to linear color space.
|
|
1820
|
+
* @param c - sRGB component value (0-1)
|
|
1821
|
+
* @returns Linear component value (0-1)
|
|
1822
|
+
*/
|
|
1823
|
+
function sRGBToLinear(c) {
|
|
1824
|
+
return c <= 0.04045 ? c / 12.92 : Math.pow((c + 0.055) / 1.055, 2.4);
|
|
1825
|
+
}
|
|
1818
1826
|
const COLORS = {
|
|
1819
1827
|
black: 0x000000,
|
|
1820
1828
|
white: 0xffffff,
|
|
@@ -1874,6 +1882,11 @@ class UIColor extends i {
|
|
|
1874
1882
|
this._private_gInternal = 1;
|
|
1875
1883
|
this._private_bInternal = 1;
|
|
1876
1884
|
this._private_aInternal = 1;
|
|
1885
|
+
this._private_hInternal = 0;
|
|
1886
|
+
this._private_sInternal = 0;
|
|
1887
|
+
this._private_lInternal = 1;
|
|
1888
|
+
this._private_rgbDirty = false;
|
|
1889
|
+
this._private_hslDirty = false;
|
|
1877
1890
|
if (args.length >= 3 && typeof args[0] === "number") {
|
|
1878
1891
|
const [r, g, b, a = 1] = args;
|
|
1879
1892
|
this._private_rInternal = r;
|
|
@@ -1884,44 +1897,220 @@ class UIColor extends i {
|
|
|
1884
1897
|
else if (args.length >= 1) {
|
|
1885
1898
|
const [first, a = 1] = args;
|
|
1886
1899
|
if (typeof first === "string") {
|
|
1887
|
-
this.
|
|
1900
|
+
this.setColorName(first, a);
|
|
1888
1901
|
}
|
|
1889
1902
|
else {
|
|
1890
1903
|
this.setHexRGB(first, a);
|
|
1891
1904
|
}
|
|
1892
1905
|
}
|
|
1893
1906
|
}
|
|
1907
|
+
/** Creates black color (0x000000). */
|
|
1908
|
+
static get black() {
|
|
1909
|
+
return new UIColor("black");
|
|
1910
|
+
}
|
|
1911
|
+
/** Creates white color (0xFFFFFF). */
|
|
1912
|
+
static get white() {
|
|
1913
|
+
return new UIColor("white");
|
|
1914
|
+
}
|
|
1915
|
+
/** Creates red color (0xFF0000). */
|
|
1916
|
+
static get red() {
|
|
1917
|
+
return new UIColor("red");
|
|
1918
|
+
}
|
|
1919
|
+
/** Creates green color (0x008000). */
|
|
1920
|
+
static get green() {
|
|
1921
|
+
return new UIColor("green");
|
|
1922
|
+
}
|
|
1923
|
+
/** Creates blue color (0x0000FF). */
|
|
1924
|
+
static get blue() {
|
|
1925
|
+
return new UIColor("blue");
|
|
1926
|
+
}
|
|
1927
|
+
/** Creates yellow color (0xFFFF00). */
|
|
1928
|
+
static get yellow() {
|
|
1929
|
+
return new UIColor("yellow");
|
|
1930
|
+
}
|
|
1931
|
+
/** Creates cyan color (0x00FFFF). */
|
|
1932
|
+
static get cyan() {
|
|
1933
|
+
return new UIColor("cyan");
|
|
1934
|
+
}
|
|
1935
|
+
/** Creates magenta color (0xFF00FF). */
|
|
1936
|
+
static get magenta() {
|
|
1937
|
+
return new UIColor("magenta");
|
|
1938
|
+
}
|
|
1939
|
+
/** Creates gray color (0x808080). */
|
|
1940
|
+
static get gray() {
|
|
1941
|
+
return new UIColor("gray");
|
|
1942
|
+
}
|
|
1943
|
+
/** Creates grey color (0x808080). */
|
|
1944
|
+
static get grey() {
|
|
1945
|
+
return new UIColor("grey");
|
|
1946
|
+
}
|
|
1947
|
+
/** Creates silver color (0xC0C0C0). */
|
|
1948
|
+
static get silver() {
|
|
1949
|
+
return new UIColor("silver");
|
|
1950
|
+
}
|
|
1951
|
+
/** Creates maroon color (0x800000). */
|
|
1952
|
+
static get maroon() {
|
|
1953
|
+
return new UIColor("maroon");
|
|
1954
|
+
}
|
|
1955
|
+
/** Creates olive color (0x808000). */
|
|
1956
|
+
static get olive() {
|
|
1957
|
+
return new UIColor("olive");
|
|
1958
|
+
}
|
|
1959
|
+
/** Creates lime color (0x00FF00). */
|
|
1960
|
+
static get lime() {
|
|
1961
|
+
return new UIColor("lime");
|
|
1962
|
+
}
|
|
1963
|
+
/** Creates aqua color (0x00FFFF). */
|
|
1964
|
+
static get aqua() {
|
|
1965
|
+
return new UIColor("aqua");
|
|
1966
|
+
}
|
|
1967
|
+
/** Creates teal color (0x008080). */
|
|
1968
|
+
static get teal() {
|
|
1969
|
+
return new UIColor("teal");
|
|
1970
|
+
}
|
|
1971
|
+
/** Creates navy color (0x000080). */
|
|
1972
|
+
static get navy() {
|
|
1973
|
+
return new UIColor("navy");
|
|
1974
|
+
}
|
|
1975
|
+
/** Creates fuchsia color (0xFF00FF). */
|
|
1976
|
+
static get fuchsia() {
|
|
1977
|
+
return new UIColor("fuchsia");
|
|
1978
|
+
}
|
|
1979
|
+
/** Creates purple color (0x800080). */
|
|
1980
|
+
static get purple() {
|
|
1981
|
+
return new UIColor("purple");
|
|
1982
|
+
}
|
|
1983
|
+
/** Creates orange color (0xFFA500). */
|
|
1984
|
+
static get orange() {
|
|
1985
|
+
return new UIColor("orange");
|
|
1986
|
+
}
|
|
1987
|
+
/** Creates pink color (0xFFC0CB). */
|
|
1988
|
+
static get pink() {
|
|
1989
|
+
return new UIColor("pink");
|
|
1990
|
+
}
|
|
1991
|
+
/** Creates brown color (0xA52A2A). */
|
|
1992
|
+
static get brown() {
|
|
1993
|
+
return new UIColor("brown");
|
|
1994
|
+
}
|
|
1995
|
+
/** Creates gold color (0xFFD700). */
|
|
1996
|
+
static get gold() {
|
|
1997
|
+
return new UIColor("gold");
|
|
1998
|
+
}
|
|
1999
|
+
/** Creates violet color (0xEE82EE). */
|
|
2000
|
+
static get violet() {
|
|
2001
|
+
return new UIColor("violet");
|
|
2002
|
+
}
|
|
2003
|
+
/** Creates indigo color (0x4B0082). */
|
|
2004
|
+
static get indigo() {
|
|
2005
|
+
return new UIColor("indigo");
|
|
2006
|
+
}
|
|
2007
|
+
/** Creates coral color (0xFF7F50). */
|
|
2008
|
+
static get coral() {
|
|
2009
|
+
return new UIColor("coral");
|
|
2010
|
+
}
|
|
2011
|
+
/** Creates salmon color (0xFA8072). */
|
|
2012
|
+
static get salmon() {
|
|
2013
|
+
return new UIColor("salmon");
|
|
2014
|
+
}
|
|
2015
|
+
/** Creates khaki color (0xF0E68C). */
|
|
2016
|
+
static get khaki() {
|
|
2017
|
+
return new UIColor("khaki");
|
|
2018
|
+
}
|
|
2019
|
+
/** Creates plum color (0xDDA0DD). */
|
|
2020
|
+
static get plum() {
|
|
2021
|
+
return new UIColor("plum");
|
|
2022
|
+
}
|
|
2023
|
+
/** Creates orchid color (0xDA70D6). */
|
|
2024
|
+
static get orchid() {
|
|
2025
|
+
return new UIColor("orchid");
|
|
2026
|
+
}
|
|
2027
|
+
/** Creates tan color (0xD2B48C). */
|
|
2028
|
+
static get tan() {
|
|
2029
|
+
return new UIColor("tan");
|
|
2030
|
+
}
|
|
2031
|
+
/** Creates beige color (0xF5F5DC). */
|
|
2032
|
+
static get beige() {
|
|
2033
|
+
return new UIColor("beige");
|
|
2034
|
+
}
|
|
2035
|
+
/** Creates mint color (0x98FB98). */
|
|
2036
|
+
static get mint() {
|
|
2037
|
+
return new UIColor("mint");
|
|
2038
|
+
}
|
|
2039
|
+
/** Creates lavender color (0xE6E6FA). */
|
|
2040
|
+
static get lavender() {
|
|
2041
|
+
return new UIColor("lavender");
|
|
2042
|
+
}
|
|
2043
|
+
/** Creates crimson color (0xDC143C). */
|
|
2044
|
+
static get crimson() {
|
|
2045
|
+
return new UIColor("crimson");
|
|
2046
|
+
}
|
|
2047
|
+
/** Creates azure color (0xF0FFFF). */
|
|
2048
|
+
static get azure() {
|
|
2049
|
+
return new UIColor("azure");
|
|
2050
|
+
}
|
|
2051
|
+
/** Creates ivory color (0xFFFFF0). */
|
|
2052
|
+
static get ivory() {
|
|
2053
|
+
return new UIColor("ivory");
|
|
2054
|
+
}
|
|
2055
|
+
/** Creates snow color (0xFFFAFA). */
|
|
2056
|
+
static get snow() {
|
|
2057
|
+
return new UIColor("snow");
|
|
2058
|
+
}
|
|
1894
2059
|
/** Red component (0-1). */
|
|
1895
2060
|
get r() {
|
|
2061
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1896
2062
|
return this._private_rInternal;
|
|
1897
2063
|
}
|
|
1898
2064
|
/** Green component (0-1). */
|
|
1899
2065
|
get g() {
|
|
2066
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1900
2067
|
return this._private_gInternal;
|
|
1901
2068
|
}
|
|
1902
2069
|
/** Blue component (0-1). */
|
|
1903
2070
|
get b() {
|
|
2071
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1904
2072
|
return this._private_bInternal;
|
|
1905
2073
|
}
|
|
1906
2074
|
/** Alpha component (0-1). */
|
|
1907
2075
|
get a() {
|
|
1908
2076
|
return this._private_aInternal;
|
|
1909
2077
|
}
|
|
2078
|
+
/** Hue component (0-360). */
|
|
2079
|
+
get hue() {
|
|
2080
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2081
|
+
return this._private_hInternal;
|
|
2082
|
+
}
|
|
2083
|
+
/** Saturation component (0-1). */
|
|
2084
|
+
get saturation() {
|
|
2085
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2086
|
+
return this._private_sInternal;
|
|
2087
|
+
}
|
|
2088
|
+
/** Lightness component (0-1). */
|
|
2089
|
+
get lightness() {
|
|
2090
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2091
|
+
return this._private_lInternal;
|
|
2092
|
+
}
|
|
1910
2093
|
set r(value) {
|
|
2094
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1911
2095
|
if (value !== this._private_rInternal) {
|
|
1912
2096
|
this._private_rInternal = value;
|
|
2097
|
+
this._private_hslDirty = true;
|
|
1913
2098
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1914
2099
|
}
|
|
1915
2100
|
}
|
|
1916
2101
|
set g(value) {
|
|
2102
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1917
2103
|
if (value !== this._private_gInternal) {
|
|
1918
2104
|
this._private_gInternal = value;
|
|
2105
|
+
this._private_hslDirty = true;
|
|
1919
2106
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1920
2107
|
}
|
|
1921
2108
|
}
|
|
1922
2109
|
set b(value) {
|
|
2110
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1923
2111
|
if (value !== this._private_bInternal) {
|
|
1924
2112
|
this._private_bInternal = value;
|
|
2113
|
+
this._private_hslDirty = true;
|
|
1925
2114
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1926
2115
|
}
|
|
1927
2116
|
}
|
|
@@ -1931,6 +2120,30 @@ class UIColor extends i {
|
|
|
1931
2120
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1932
2121
|
}
|
|
1933
2122
|
}
|
|
2123
|
+
set hue(value) {
|
|
2124
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2125
|
+
if (value !== this._private_hInternal) {
|
|
2126
|
+
this._private_hInternal = value;
|
|
2127
|
+
this._private_rgbDirty = true;
|
|
2128
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
set saturation(value) {
|
|
2132
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2133
|
+
if (value !== this._private_sInternal) {
|
|
2134
|
+
this._private_sInternal = value;
|
|
2135
|
+
this._private_rgbDirty = true;
|
|
2136
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2137
|
+
}
|
|
2138
|
+
}
|
|
2139
|
+
set lightness(value) {
|
|
2140
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2141
|
+
if (value !== this._private_lInternal) {
|
|
2142
|
+
this._private_lInternal = value;
|
|
2143
|
+
this._private_rgbDirty = true;
|
|
2144
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2145
|
+
}
|
|
2146
|
+
}
|
|
1934
2147
|
/**
|
|
1935
2148
|
* Sets all color components.
|
|
1936
2149
|
*
|
|
@@ -1941,6 +2154,7 @@ class UIColor extends i {
|
|
|
1941
2154
|
* @returns This instance
|
|
1942
2155
|
*/
|
|
1943
2156
|
set(r, g, b, a = this._private_aInternal) {
|
|
2157
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1944
2158
|
if (r !== this._private_rInternal ||
|
|
1945
2159
|
g !== this._private_gInternal ||
|
|
1946
2160
|
b !== this._private_bInternal ||
|
|
@@ -1949,6 +2163,7 @@ class UIColor extends i {
|
|
|
1949
2163
|
this._private_gInternal = g;
|
|
1950
2164
|
this._private_bInternal = b;
|
|
1951
2165
|
this._private_aInternal = a;
|
|
2166
|
+
this._private_hslDirty = true;
|
|
1952
2167
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1953
2168
|
}
|
|
1954
2169
|
return this;
|
|
@@ -1957,6 +2172,7 @@ class UIColor extends i {
|
|
|
1957
2172
|
* Returns 32-bit hex RGBA value (alpha in MSB).
|
|
1958
2173
|
*/
|
|
1959
2174
|
getHexRGBA() {
|
|
2175
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1960
2176
|
return ((Math.round(this._private_rInternal * 255) << 24) |
|
|
1961
2177
|
(Math.round(this._private_gInternal * 255) << 16) |
|
|
1962
2178
|
(Math.round(this._private_bInternal * 255) << 8) |
|
|
@@ -1966,37 +2182,11 @@ class UIColor extends i {
|
|
|
1966
2182
|
* Returns 24-bit hex RGB value.
|
|
1967
2183
|
*/
|
|
1968
2184
|
getHexRGB() {
|
|
2185
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1969
2186
|
return ((Math.round(this._private_rInternal * 255) << 16) |
|
|
1970
2187
|
(Math.round(this._private_gInternal * 255) << 8) |
|
|
1971
2188
|
Math.round(this._private_bInternal * 255));
|
|
1972
2189
|
}
|
|
1973
|
-
/**
|
|
1974
|
-
* Converts to HSL format.
|
|
1975
|
-
*
|
|
1976
|
-
* @returns Object with h (0-360), s (0-1), l (0-1)
|
|
1977
|
-
*/
|
|
1978
|
-
getHSL() {
|
|
1979
|
-
const { _private_rInternal: r, _private_gInternal: g, _private_bInternal: b } = this;
|
|
1980
|
-
const max = Math.max(r, g, b);
|
|
1981
|
-
const min = Math.min(r, g, b);
|
|
1982
|
-
const d = max - min;
|
|
1983
|
-
const l = (max + min) / 2;
|
|
1984
|
-
let h = 0;
|
|
1985
|
-
if (d !== 0) {
|
|
1986
|
-
if (max === r) {
|
|
1987
|
-
h = (g - b) / d + (g < b ? 6 : 0);
|
|
1988
|
-
}
|
|
1989
|
-
else if (max === g) {
|
|
1990
|
-
h = (b - r) / d + 2;
|
|
1991
|
-
}
|
|
1992
|
-
else {
|
|
1993
|
-
h = (r - g) / d + 4;
|
|
1994
|
-
}
|
|
1995
|
-
h *= 60;
|
|
1996
|
-
}
|
|
1997
|
-
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
1998
|
-
return { h, s, l };
|
|
1999
|
-
}
|
|
2000
2190
|
/**
|
|
2001
2191
|
* Sets color from 32-bit hex RGBA value.
|
|
2002
2192
|
*
|
|
@@ -2004,6 +2194,7 @@ class UIColor extends i {
|
|
|
2004
2194
|
* @returns This instance
|
|
2005
2195
|
*/
|
|
2006
2196
|
setHexRGBA(hex) {
|
|
2197
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2007
2198
|
const r = ((hex >> 16) & 0xff) / 255;
|
|
2008
2199
|
const g = ((hex >> 8) & 0xff) / 255;
|
|
2009
2200
|
const b = (hex & 0xff) / 255;
|
|
@@ -2016,6 +2207,7 @@ class UIColor extends i {
|
|
|
2016
2207
|
this._private_gInternal = g;
|
|
2017
2208
|
this._private_bInternal = b;
|
|
2018
2209
|
this._private_aInternal = a;
|
|
2210
|
+
this._private_hslDirty = true;
|
|
2019
2211
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2020
2212
|
}
|
|
2021
2213
|
return this;
|
|
@@ -2028,6 +2220,7 @@ class UIColor extends i {
|
|
|
2028
2220
|
* @returns This instance
|
|
2029
2221
|
*/
|
|
2030
2222
|
setHexRGB(hex, a = this._private_aInternal) {
|
|
2223
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2031
2224
|
const r = ((hex >> 16) & 0xff) / 255;
|
|
2032
2225
|
const g = ((hex >> 8) & 0xff) / 255;
|
|
2033
2226
|
const b = (hex & 0xff) / 255;
|
|
@@ -2039,6 +2232,7 @@ class UIColor extends i {
|
|
|
2039
2232
|
this._private_gInternal = g;
|
|
2040
2233
|
this._private_bInternal = b;
|
|
2041
2234
|
this._private_aInternal = a;
|
|
2235
|
+
this._private_hslDirty = true;
|
|
2042
2236
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2043
2237
|
}
|
|
2044
2238
|
return this;
|
|
@@ -2053,22 +2247,19 @@ class UIColor extends i {
|
|
|
2053
2247
|
* @returns This instance
|
|
2054
2248
|
*/
|
|
2055
2249
|
setHSL(h, s, l, a = this._private_aInternal) {
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
|
|
2062
|
-
|
|
2063
|
-
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
2069
|
-
: [c, 0, x];
|
|
2070
|
-
const m = l - c / 2;
|
|
2071
|
-
return this.set(r + m, g + m, b + m, a);
|
|
2250
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2251
|
+
if (h !== this._private_hInternal ||
|
|
2252
|
+
s !== this._private_sInternal ||
|
|
2253
|
+
l !== this._private_lInternal ||
|
|
2254
|
+
a !== this._private_aInternal) {
|
|
2255
|
+
this._private_hInternal = h;
|
|
2256
|
+
this._private_sInternal = s;
|
|
2257
|
+
this._private_lInternal = l;
|
|
2258
|
+
this._private_aInternal = a;
|
|
2259
|
+
this._private_rgbDirty = true;
|
|
2260
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2261
|
+
}
|
|
2262
|
+
return this;
|
|
2072
2263
|
}
|
|
2073
2264
|
/**
|
|
2074
2265
|
* Sets color from predefined name.
|
|
@@ -2078,7 +2269,7 @@ class UIColor extends i {
|
|
|
2078
2269
|
* @returns This instance
|
|
2079
2270
|
* @throws Error if color name is unknown
|
|
2080
2271
|
*/
|
|
2081
|
-
|
|
2272
|
+
setColorName(colorName, a = this._private_aInternal) {
|
|
2082
2273
|
const normalizedName = colorName.toLowerCase().trim();
|
|
2083
2274
|
const hex = COLORS[normalizedName];
|
|
2084
2275
|
if (hex === undefined) {
|
|
@@ -2090,11 +2281,26 @@ class UIColor extends i {
|
|
|
2090
2281
|
* Returns CSS rgba() string.
|
|
2091
2282
|
*/
|
|
2092
2283
|
toCSSColor() {
|
|
2284
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2093
2285
|
const r = Math.round(this._private_rInternal * 255);
|
|
2094
2286
|
const g = Math.round(this._private_gInternal * 255);
|
|
2095
2287
|
const b = Math.round(this._private_bInternal * 255);
|
|
2096
2288
|
return `rgba(${r}, ${g}, ${b}, ${this._private_aInternal})`;
|
|
2097
2289
|
}
|
|
2290
|
+
/**
|
|
2291
|
+
* Converts color to linear color space for GLSL.
|
|
2292
|
+
*
|
|
2293
|
+
* @param result - Vector4 to store the result
|
|
2294
|
+
* @returns Vector4 with linear RGB (0-1) and alpha
|
|
2295
|
+
*/
|
|
2296
|
+
toGLSLColor(result = new Vector4()) {
|
|
2297
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2298
|
+
result.x = sRGBToLinear(this._private_rInternal);
|
|
2299
|
+
result.y = sRGBToLinear(this._private_gInternal);
|
|
2300
|
+
result.z = sRGBToLinear(this._private_bInternal);
|
|
2301
|
+
result.w = this._private_aInternal;
|
|
2302
|
+
return result;
|
|
2303
|
+
}
|
|
2098
2304
|
/**
|
|
2099
2305
|
* Copies values from another color.
|
|
2100
2306
|
*
|
|
@@ -2103,6 +2309,8 @@ class UIColor extends i {
|
|
|
2103
2309
|
*/
|
|
2104
2310
|
copy(color) {
|
|
2105
2311
|
if (color instanceof UIColor) {
|
|
2312
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2313
|
+
color._private_ensureRGBUpdatedFromHSL();
|
|
2106
2314
|
if (this._private_rInternal !== color._private_rInternal ||
|
|
2107
2315
|
this._private_gInternal !== color._private_gInternal ||
|
|
2108
2316
|
this._private_bInternal !== color._private_bInternal ||
|
|
@@ -2111,10 +2319,12 @@ class UIColor extends i {
|
|
|
2111
2319
|
this._private_gInternal = color._private_gInternal;
|
|
2112
2320
|
this._private_bInternal = color._private_bInternal;
|
|
2113
2321
|
this._private_aInternal = color._private_aInternal;
|
|
2322
|
+
this._private_hslDirty = true;
|
|
2114
2323
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2115
2324
|
}
|
|
2116
2325
|
}
|
|
2117
2326
|
else {
|
|
2327
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2118
2328
|
if (this._private_rInternal !== color.r ||
|
|
2119
2329
|
this._private_gInternal !== color.g ||
|
|
2120
2330
|
this._private_bInternal !== color.b ||
|
|
@@ -2123,6 +2333,7 @@ class UIColor extends i {
|
|
|
2123
2333
|
this._private_gInternal = color.g;
|
|
2124
2334
|
this._private_bInternal = color.b;
|
|
2125
2335
|
this._private_aInternal = 1;
|
|
2336
|
+
this._private_hslDirty = true;
|
|
2126
2337
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2127
2338
|
}
|
|
2128
2339
|
}
|
|
@@ -2132,8 +2343,66 @@ class UIColor extends i {
|
|
|
2132
2343
|
* Creates a copy of this color.
|
|
2133
2344
|
*/
|
|
2134
2345
|
clone() {
|
|
2346
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2135
2347
|
return new UIColor(this._private_rInternal, this._private_gInternal, this._private_bInternal, this._private_aInternal);
|
|
2136
2348
|
}
|
|
2349
|
+
/**
|
|
2350
|
+
* Updates RGB values from HSL if needed.
|
|
2351
|
+
*/
|
|
2352
|
+
_private_ensureRGBUpdatedFromHSL() {
|
|
2353
|
+
if (this._private_rgbDirty) {
|
|
2354
|
+
const { _private_hInternal: h, _private_sInternal: s, _private_lInternal: l } = this;
|
|
2355
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2356
|
+
const hp = h / 60;
|
|
2357
|
+
const x = c * (1 - Math.abs((hp % 2) - 1));
|
|
2358
|
+
let [r, g, b] = hp < 1
|
|
2359
|
+
? [c, x, 0]
|
|
2360
|
+
: hp < 2
|
|
2361
|
+
? [x, c, 0]
|
|
2362
|
+
: hp < 3
|
|
2363
|
+
? [0, c, x]
|
|
2364
|
+
: hp < 4
|
|
2365
|
+
? [0, x, c]
|
|
2366
|
+
: hp < 5
|
|
2367
|
+
? [x, 0, c]
|
|
2368
|
+
: [c, 0, x];
|
|
2369
|
+
const m = l - c / 2;
|
|
2370
|
+
this._private_rInternal = r + m;
|
|
2371
|
+
this._private_gInternal = g + m;
|
|
2372
|
+
this._private_bInternal = b + m;
|
|
2373
|
+
this._private_rgbDirty = false;
|
|
2374
|
+
}
|
|
2375
|
+
}
|
|
2376
|
+
/**
|
|
2377
|
+
* Updates HSL values from RGB if needed.
|
|
2378
|
+
*/
|
|
2379
|
+
_private_ensureHSLUpdatedFromRGB() {
|
|
2380
|
+
if (this._private_hslDirty) {
|
|
2381
|
+
const { _private_rInternal: r, _private_gInternal: g, _private_bInternal: b } = this;
|
|
2382
|
+
const max = Math.max(r, g, b);
|
|
2383
|
+
const min = Math.min(r, g, b);
|
|
2384
|
+
const d = max - min;
|
|
2385
|
+
const l = (max + min) / 2;
|
|
2386
|
+
let h = 0;
|
|
2387
|
+
if (d !== 0) {
|
|
2388
|
+
if (max === r) {
|
|
2389
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
2390
|
+
}
|
|
2391
|
+
else if (max === g) {
|
|
2392
|
+
h = (b - r) / d + 2;
|
|
2393
|
+
}
|
|
2394
|
+
else {
|
|
2395
|
+
h = (r - g) / d + 4;
|
|
2396
|
+
}
|
|
2397
|
+
h *= 60;
|
|
2398
|
+
}
|
|
2399
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
2400
|
+
this._private_hInternal = h;
|
|
2401
|
+
this._private_sInternal = s;
|
|
2402
|
+
this._private_lInternal = l;
|
|
2403
|
+
this._private_hslDirty = false;
|
|
2404
|
+
}
|
|
2405
|
+
}
|
|
2137
2406
|
}
|
|
2138
2407
|
|
|
2139
2408
|
/**
|
|
@@ -2169,7 +2438,6 @@ var fragmentShader = "in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <co
|
|
|
2169
2438
|
var vertexShader = "out vec2 io_UV;\n#include <common>\n\nvoid main() {\n #include <begin_vertex>\n io_UV = uv;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n}\n";
|
|
2170
2439
|
|
|
2171
2440
|
const DEFAULT_ALPHA_TEST = 0.25;
|
|
2172
|
-
const COLOR = new Color();
|
|
2173
2441
|
const UNIFROM_TYPE_MAP = new Map([
|
|
2174
2442
|
[UIColor, "vec4"],
|
|
2175
2443
|
[Color, "vec3"],
|
|
@@ -2217,7 +2485,7 @@ class UISceneWrapper {
|
|
|
2217
2485
|
...Object.fromEntries(entries.map(([k, v]) => [
|
|
2218
2486
|
k,
|
|
2219
2487
|
{
|
|
2220
|
-
value: v instanceof UIColor ?
|
|
2488
|
+
value: v instanceof UIColor ? v.toGLSLColor() : v,
|
|
2221
2489
|
},
|
|
2222
2490
|
])),
|
|
2223
2491
|
},
|
|
@@ -2259,9 +2527,7 @@ class UISceneWrapper {
|
|
|
2259
2527
|
throw new Error(`Uniform ${uniform} not found in material`);
|
|
2260
2528
|
}
|
|
2261
2529
|
if (value instanceof UIColor) {
|
|
2262
|
-
|
|
2263
|
-
linear.convertSRGBToLinear();
|
|
2264
|
-
descriptor.material.uniforms[uniform].value.set(linear.r, linear.g, linear.b, value.a);
|
|
2530
|
+
value.toGLSLColor(descriptor.material.uniforms[uniform].value);
|
|
2265
2531
|
}
|
|
2266
2532
|
else {
|
|
2267
2533
|
descriptor.material.uniforms[uniform].value = value;
|