laymur 0.9.0 → 0.10.1
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 +362 -55
- 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 +131 -16
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Color, PlaneGeometry, Scene, OrthographicCamera, ShaderMaterial,
|
|
1
|
+
import { Color, Vector4, PlaneGeometry, 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;
|
|
@@ -1881,47 +1894,229 @@ class UIColor extends i {
|
|
|
1881
1894
|
this._private_bInternal = b;
|
|
1882
1895
|
this._private_aInternal = a;
|
|
1883
1896
|
}
|
|
1884
|
-
else
|
|
1885
|
-
const [
|
|
1886
|
-
if (typeof
|
|
1887
|
-
this.
|
|
1897
|
+
else {
|
|
1898
|
+
const [firstArgument, a = 1] = args;
|
|
1899
|
+
if (typeof firstArgument === "string") {
|
|
1900
|
+
this.setColorName(firstArgument, a);
|
|
1901
|
+
}
|
|
1902
|
+
else if (firstArgument instanceof Color) {
|
|
1903
|
+
this._private_rInternal = firstArgument.r;
|
|
1904
|
+
this._private_gInternal = firstArgument.g;
|
|
1905
|
+
this._private_bInternal = firstArgument.b;
|
|
1906
|
+
this._private_aInternal = a;
|
|
1888
1907
|
}
|
|
1889
1908
|
else {
|
|
1890
|
-
this.setHexRGB(
|
|
1909
|
+
this.setHexRGB(firstArgument, a);
|
|
1891
1910
|
}
|
|
1892
1911
|
}
|
|
1893
1912
|
}
|
|
1913
|
+
/** Creates black color (0x000000). */
|
|
1914
|
+
static get black() {
|
|
1915
|
+
return new UIColor("black");
|
|
1916
|
+
}
|
|
1917
|
+
/** Creates white color (0xFFFFFF). */
|
|
1918
|
+
static get white() {
|
|
1919
|
+
return new UIColor("white");
|
|
1920
|
+
}
|
|
1921
|
+
/** Creates red color (0xFF0000). */
|
|
1922
|
+
static get red() {
|
|
1923
|
+
return new UIColor("red");
|
|
1924
|
+
}
|
|
1925
|
+
/** Creates green color (0x008000). */
|
|
1926
|
+
static get green() {
|
|
1927
|
+
return new UIColor("green");
|
|
1928
|
+
}
|
|
1929
|
+
/** Creates blue color (0x0000FF). */
|
|
1930
|
+
static get blue() {
|
|
1931
|
+
return new UIColor("blue");
|
|
1932
|
+
}
|
|
1933
|
+
/** Creates yellow color (0xFFFF00). */
|
|
1934
|
+
static get yellow() {
|
|
1935
|
+
return new UIColor("yellow");
|
|
1936
|
+
}
|
|
1937
|
+
/** Creates cyan color (0x00FFFF). */
|
|
1938
|
+
static get cyan() {
|
|
1939
|
+
return new UIColor("cyan");
|
|
1940
|
+
}
|
|
1941
|
+
/** Creates magenta color (0xFF00FF). */
|
|
1942
|
+
static get magenta() {
|
|
1943
|
+
return new UIColor("magenta");
|
|
1944
|
+
}
|
|
1945
|
+
/** Creates gray color (0x808080). */
|
|
1946
|
+
static get gray() {
|
|
1947
|
+
return new UIColor("gray");
|
|
1948
|
+
}
|
|
1949
|
+
/** Creates grey color (0x808080). */
|
|
1950
|
+
static get grey() {
|
|
1951
|
+
return new UIColor("grey");
|
|
1952
|
+
}
|
|
1953
|
+
/** Creates silver color (0xC0C0C0). */
|
|
1954
|
+
static get silver() {
|
|
1955
|
+
return new UIColor("silver");
|
|
1956
|
+
}
|
|
1957
|
+
/** Creates maroon color (0x800000). */
|
|
1958
|
+
static get maroon() {
|
|
1959
|
+
return new UIColor("maroon");
|
|
1960
|
+
}
|
|
1961
|
+
/** Creates olive color (0x808000). */
|
|
1962
|
+
static get olive() {
|
|
1963
|
+
return new UIColor("olive");
|
|
1964
|
+
}
|
|
1965
|
+
/** Creates lime color (0x00FF00). */
|
|
1966
|
+
static get lime() {
|
|
1967
|
+
return new UIColor("lime");
|
|
1968
|
+
}
|
|
1969
|
+
/** Creates aqua color (0x00FFFF). */
|
|
1970
|
+
static get aqua() {
|
|
1971
|
+
return new UIColor("aqua");
|
|
1972
|
+
}
|
|
1973
|
+
/** Creates teal color (0x008080). */
|
|
1974
|
+
static get teal() {
|
|
1975
|
+
return new UIColor("teal");
|
|
1976
|
+
}
|
|
1977
|
+
/** Creates navy color (0x000080). */
|
|
1978
|
+
static get navy() {
|
|
1979
|
+
return new UIColor("navy");
|
|
1980
|
+
}
|
|
1981
|
+
/** Creates fuchsia color (0xFF00FF). */
|
|
1982
|
+
static get fuchsia() {
|
|
1983
|
+
return new UIColor("fuchsia");
|
|
1984
|
+
}
|
|
1985
|
+
/** Creates purple color (0x800080). */
|
|
1986
|
+
static get purple() {
|
|
1987
|
+
return new UIColor("purple");
|
|
1988
|
+
}
|
|
1989
|
+
/** Creates orange color (0xFFA500). */
|
|
1990
|
+
static get orange() {
|
|
1991
|
+
return new UIColor("orange");
|
|
1992
|
+
}
|
|
1993
|
+
/** Creates pink color (0xFFC0CB). */
|
|
1994
|
+
static get pink() {
|
|
1995
|
+
return new UIColor("pink");
|
|
1996
|
+
}
|
|
1997
|
+
/** Creates brown color (0xA52A2A). */
|
|
1998
|
+
static get brown() {
|
|
1999
|
+
return new UIColor("brown");
|
|
2000
|
+
}
|
|
2001
|
+
/** Creates gold color (0xFFD700). */
|
|
2002
|
+
static get gold() {
|
|
2003
|
+
return new UIColor("gold");
|
|
2004
|
+
}
|
|
2005
|
+
/** Creates violet color (0xEE82EE). */
|
|
2006
|
+
static get violet() {
|
|
2007
|
+
return new UIColor("violet");
|
|
2008
|
+
}
|
|
2009
|
+
/** Creates indigo color (0x4B0082). */
|
|
2010
|
+
static get indigo() {
|
|
2011
|
+
return new UIColor("indigo");
|
|
2012
|
+
}
|
|
2013
|
+
/** Creates coral color (0xFF7F50). */
|
|
2014
|
+
static get coral() {
|
|
2015
|
+
return new UIColor("coral");
|
|
2016
|
+
}
|
|
2017
|
+
/** Creates salmon color (0xFA8072). */
|
|
2018
|
+
static get salmon() {
|
|
2019
|
+
return new UIColor("salmon");
|
|
2020
|
+
}
|
|
2021
|
+
/** Creates khaki color (0xF0E68C). */
|
|
2022
|
+
static get khaki() {
|
|
2023
|
+
return new UIColor("khaki");
|
|
2024
|
+
}
|
|
2025
|
+
/** Creates plum color (0xDDA0DD). */
|
|
2026
|
+
static get plum() {
|
|
2027
|
+
return new UIColor("plum");
|
|
2028
|
+
}
|
|
2029
|
+
/** Creates orchid color (0xDA70D6). */
|
|
2030
|
+
static get orchid() {
|
|
2031
|
+
return new UIColor("orchid");
|
|
2032
|
+
}
|
|
2033
|
+
/** Creates tan color (0xD2B48C). */
|
|
2034
|
+
static get tan() {
|
|
2035
|
+
return new UIColor("tan");
|
|
2036
|
+
}
|
|
2037
|
+
/** Creates beige color (0xF5F5DC). */
|
|
2038
|
+
static get beige() {
|
|
2039
|
+
return new UIColor("beige");
|
|
2040
|
+
}
|
|
2041
|
+
/** Creates mint color (0x98FB98). */
|
|
2042
|
+
static get mint() {
|
|
2043
|
+
return new UIColor("mint");
|
|
2044
|
+
}
|
|
2045
|
+
/** Creates lavender color (0xE6E6FA). */
|
|
2046
|
+
static get lavender() {
|
|
2047
|
+
return new UIColor("lavender");
|
|
2048
|
+
}
|
|
2049
|
+
/** Creates crimson color (0xDC143C). */
|
|
2050
|
+
static get crimson() {
|
|
2051
|
+
return new UIColor("crimson");
|
|
2052
|
+
}
|
|
2053
|
+
/** Creates azure color (0xF0FFFF). */
|
|
2054
|
+
static get azure() {
|
|
2055
|
+
return new UIColor("azure");
|
|
2056
|
+
}
|
|
2057
|
+
/** Creates ivory color (0xFFFFF0). */
|
|
2058
|
+
static get ivory() {
|
|
2059
|
+
return new UIColor("ivory");
|
|
2060
|
+
}
|
|
2061
|
+
/** Creates snow color (0xFFFAFA). */
|
|
2062
|
+
static get snow() {
|
|
2063
|
+
return new UIColor("snow");
|
|
2064
|
+
}
|
|
1894
2065
|
/** Red component (0-1). */
|
|
1895
2066
|
get r() {
|
|
2067
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1896
2068
|
return this._private_rInternal;
|
|
1897
2069
|
}
|
|
1898
2070
|
/** Green component (0-1). */
|
|
1899
2071
|
get g() {
|
|
2072
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1900
2073
|
return this._private_gInternal;
|
|
1901
2074
|
}
|
|
1902
2075
|
/** Blue component (0-1). */
|
|
1903
2076
|
get b() {
|
|
2077
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1904
2078
|
return this._private_bInternal;
|
|
1905
2079
|
}
|
|
1906
2080
|
/** Alpha component (0-1). */
|
|
1907
2081
|
get a() {
|
|
1908
2082
|
return this._private_aInternal;
|
|
1909
2083
|
}
|
|
2084
|
+
/** Hue component (0-360). */
|
|
2085
|
+
get hue() {
|
|
2086
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2087
|
+
return this._private_hInternal;
|
|
2088
|
+
}
|
|
2089
|
+
/** Saturation component (0-1). */
|
|
2090
|
+
get saturation() {
|
|
2091
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2092
|
+
return this._private_sInternal;
|
|
2093
|
+
}
|
|
2094
|
+
/** Lightness component (0-1). */
|
|
2095
|
+
get lightness() {
|
|
2096
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2097
|
+
return this._private_lInternal;
|
|
2098
|
+
}
|
|
1910
2099
|
set r(value) {
|
|
2100
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1911
2101
|
if (value !== this._private_rInternal) {
|
|
1912
2102
|
this._private_rInternal = value;
|
|
2103
|
+
this._private_hslDirty = true;
|
|
1913
2104
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1914
2105
|
}
|
|
1915
2106
|
}
|
|
1916
2107
|
set g(value) {
|
|
2108
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1917
2109
|
if (value !== this._private_gInternal) {
|
|
1918
2110
|
this._private_gInternal = value;
|
|
2111
|
+
this._private_hslDirty = true;
|
|
1919
2112
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1920
2113
|
}
|
|
1921
2114
|
}
|
|
1922
2115
|
set b(value) {
|
|
2116
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1923
2117
|
if (value !== this._private_bInternal) {
|
|
1924
2118
|
this._private_bInternal = value;
|
|
2119
|
+
this._private_hslDirty = true;
|
|
1925
2120
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1926
2121
|
}
|
|
1927
2122
|
}
|
|
@@ -1931,6 +2126,30 @@ class UIColor extends i {
|
|
|
1931
2126
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1932
2127
|
}
|
|
1933
2128
|
}
|
|
2129
|
+
set hue(value) {
|
|
2130
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2131
|
+
if (value !== this._private_hInternal) {
|
|
2132
|
+
this._private_hInternal = value;
|
|
2133
|
+
this._private_rgbDirty = true;
|
|
2134
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2135
|
+
}
|
|
2136
|
+
}
|
|
2137
|
+
set saturation(value) {
|
|
2138
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2139
|
+
if (value !== this._private_sInternal) {
|
|
2140
|
+
this._private_sInternal = value;
|
|
2141
|
+
this._private_rgbDirty = true;
|
|
2142
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2143
|
+
}
|
|
2144
|
+
}
|
|
2145
|
+
set lightness(value) {
|
|
2146
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2147
|
+
if (value !== this._private_lInternal) {
|
|
2148
|
+
this._private_lInternal = value;
|
|
2149
|
+
this._private_rgbDirty = true;
|
|
2150
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2151
|
+
}
|
|
2152
|
+
}
|
|
1934
2153
|
/**
|
|
1935
2154
|
* Sets all color components.
|
|
1936
2155
|
*
|
|
@@ -1941,6 +2160,7 @@ class UIColor extends i {
|
|
|
1941
2160
|
* @returns This instance
|
|
1942
2161
|
*/
|
|
1943
2162
|
set(r, g, b, a = this._private_aInternal) {
|
|
2163
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1944
2164
|
if (r !== this._private_rInternal ||
|
|
1945
2165
|
g !== this._private_gInternal ||
|
|
1946
2166
|
b !== this._private_bInternal ||
|
|
@@ -1949,6 +2169,7 @@ class UIColor extends i {
|
|
|
1949
2169
|
this._private_gInternal = g;
|
|
1950
2170
|
this._private_bInternal = b;
|
|
1951
2171
|
this._private_aInternal = a;
|
|
2172
|
+
this._private_hslDirty = true;
|
|
1952
2173
|
this.emit(UIColorEvent.CHANGE, this);
|
|
1953
2174
|
}
|
|
1954
2175
|
return this;
|
|
@@ -1957,6 +2178,7 @@ class UIColor extends i {
|
|
|
1957
2178
|
* Returns 32-bit hex RGBA value (alpha in MSB).
|
|
1958
2179
|
*/
|
|
1959
2180
|
getHexRGBA() {
|
|
2181
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1960
2182
|
return ((Math.round(this._private_rInternal * 255) << 24) |
|
|
1961
2183
|
(Math.round(this._private_gInternal * 255) << 16) |
|
|
1962
2184
|
(Math.round(this._private_bInternal * 255) << 8) |
|
|
@@ -1966,37 +2188,11 @@ class UIColor extends i {
|
|
|
1966
2188
|
* Returns 24-bit hex RGB value.
|
|
1967
2189
|
*/
|
|
1968
2190
|
getHexRGB() {
|
|
2191
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
1969
2192
|
return ((Math.round(this._private_rInternal * 255) << 16) |
|
|
1970
2193
|
(Math.round(this._private_gInternal * 255) << 8) |
|
|
1971
2194
|
Math.round(this._private_bInternal * 255));
|
|
1972
2195
|
}
|
|
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
2196
|
/**
|
|
2001
2197
|
* Sets color from 32-bit hex RGBA value.
|
|
2002
2198
|
*
|
|
@@ -2004,6 +2200,7 @@ class UIColor extends i {
|
|
|
2004
2200
|
* @returns This instance
|
|
2005
2201
|
*/
|
|
2006
2202
|
setHexRGBA(hex) {
|
|
2203
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2007
2204
|
const r = ((hex >> 16) & 0xff) / 255;
|
|
2008
2205
|
const g = ((hex >> 8) & 0xff) / 255;
|
|
2009
2206
|
const b = (hex & 0xff) / 255;
|
|
@@ -2016,6 +2213,7 @@ class UIColor extends i {
|
|
|
2016
2213
|
this._private_gInternal = g;
|
|
2017
2214
|
this._private_bInternal = b;
|
|
2018
2215
|
this._private_aInternal = a;
|
|
2216
|
+
this._private_hslDirty = true;
|
|
2019
2217
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2020
2218
|
}
|
|
2021
2219
|
return this;
|
|
@@ -2028,6 +2226,7 @@ class UIColor extends i {
|
|
|
2028
2226
|
* @returns This instance
|
|
2029
2227
|
*/
|
|
2030
2228
|
setHexRGB(hex, a = this._private_aInternal) {
|
|
2229
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2031
2230
|
const r = ((hex >> 16) & 0xff) / 255;
|
|
2032
2231
|
const g = ((hex >> 8) & 0xff) / 255;
|
|
2033
2232
|
const b = (hex & 0xff) / 255;
|
|
@@ -2039,6 +2238,7 @@ class UIColor extends i {
|
|
|
2039
2238
|
this._private_gInternal = g;
|
|
2040
2239
|
this._private_bInternal = b;
|
|
2041
2240
|
this._private_aInternal = a;
|
|
2241
|
+
this._private_hslDirty = true;
|
|
2042
2242
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2043
2243
|
}
|
|
2044
2244
|
return this;
|
|
@@ -2053,22 +2253,19 @@ class UIColor extends i {
|
|
|
2053
2253
|
* @returns This instance
|
|
2054
2254
|
*/
|
|
2055
2255
|
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);
|
|
2256
|
+
this._private_ensureHSLUpdatedFromRGB();
|
|
2257
|
+
if (h !== this._private_hInternal ||
|
|
2258
|
+
s !== this._private_sInternal ||
|
|
2259
|
+
l !== this._private_lInternal ||
|
|
2260
|
+
a !== this._private_aInternal) {
|
|
2261
|
+
this._private_hInternal = h;
|
|
2262
|
+
this._private_sInternal = s;
|
|
2263
|
+
this._private_lInternal = l;
|
|
2264
|
+
this._private_aInternal = a;
|
|
2265
|
+
this._private_rgbDirty = true;
|
|
2266
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2267
|
+
}
|
|
2268
|
+
return this;
|
|
2072
2269
|
}
|
|
2073
2270
|
/**
|
|
2074
2271
|
* Sets color from predefined name.
|
|
@@ -2078,7 +2275,7 @@ class UIColor extends i {
|
|
|
2078
2275
|
* @returns This instance
|
|
2079
2276
|
* @throws Error if color name is unknown
|
|
2080
2277
|
*/
|
|
2081
|
-
|
|
2278
|
+
setColorName(colorName, a = this._private_aInternal) {
|
|
2082
2279
|
const normalizedName = colorName.toLowerCase().trim();
|
|
2083
2280
|
const hex = COLORS[normalizedName];
|
|
2084
2281
|
if (hex === undefined) {
|
|
@@ -2086,15 +2283,65 @@ class UIColor extends i {
|
|
|
2086
2283
|
}
|
|
2087
2284
|
return this.setHexRGB(hex, a);
|
|
2088
2285
|
}
|
|
2286
|
+
/**
|
|
2287
|
+
* Sets color from Three.js Color object.
|
|
2288
|
+
*
|
|
2289
|
+
* @param threeColor - Three.js Color object
|
|
2290
|
+
* @param a - Alpha (0-1)
|
|
2291
|
+
* @returns This instance
|
|
2292
|
+
*/
|
|
2293
|
+
setThreeColor(threeColor, a = this._private_aInternal) {
|
|
2294
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2295
|
+
if (threeColor.r !== this._private_rInternal ||
|
|
2296
|
+
threeColor.g !== this._private_gInternal ||
|
|
2297
|
+
threeColor.b !== this._private_bInternal ||
|
|
2298
|
+
a !== this._private_aInternal) {
|
|
2299
|
+
this._private_rInternal = threeColor.r;
|
|
2300
|
+
this._private_gInternal = threeColor.g;
|
|
2301
|
+
this._private_bInternal = threeColor.b;
|
|
2302
|
+
this._private_aInternal = a;
|
|
2303
|
+
this._private_hslDirty = true;
|
|
2304
|
+
this.emit(UIColorEvent.CHANGE, this);
|
|
2305
|
+
}
|
|
2306
|
+
return this;
|
|
2307
|
+
}
|
|
2089
2308
|
/**
|
|
2090
2309
|
* Returns CSS rgba() string.
|
|
2091
2310
|
*/
|
|
2092
2311
|
toCSSColor() {
|
|
2312
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2093
2313
|
const r = Math.round(this._private_rInternal * 255);
|
|
2094
2314
|
const g = Math.round(this._private_gInternal * 255);
|
|
2095
2315
|
const b = Math.round(this._private_bInternal * 255);
|
|
2096
2316
|
return `rgba(${r}, ${g}, ${b}, ${this._private_aInternal})`;
|
|
2097
2317
|
}
|
|
2318
|
+
/**
|
|
2319
|
+
* Converts color to linear color space for GLSL.
|
|
2320
|
+
*
|
|
2321
|
+
* @param result - Vector4 to store the result
|
|
2322
|
+
* @returns Vector4 with linear RGB (0-1) and alpha
|
|
2323
|
+
*/
|
|
2324
|
+
toGLSLColor(result = new Vector4()) {
|
|
2325
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2326
|
+
result.x = sRGBToLinear(this._private_rInternal);
|
|
2327
|
+
result.y = sRGBToLinear(this._private_gInternal);
|
|
2328
|
+
result.z = sRGBToLinear(this._private_bInternal);
|
|
2329
|
+
result.w = this._private_aInternal;
|
|
2330
|
+
return result;
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* Converts color to Three.js Color object (without alpha).
|
|
2334
|
+
*
|
|
2335
|
+
* @param result - Color object to store the result
|
|
2336
|
+
* @returns Color with RGB values
|
|
2337
|
+
*/
|
|
2338
|
+
toThreeColor(result = new Color()) {
|
|
2339
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2340
|
+
result.r = this._private_rInternal;
|
|
2341
|
+
result.g = this._private_gInternal;
|
|
2342
|
+
result.b = this._private_bInternal;
|
|
2343
|
+
return result;
|
|
2344
|
+
}
|
|
2098
2345
|
/**
|
|
2099
2346
|
* Copies values from another color.
|
|
2100
2347
|
*
|
|
@@ -2103,6 +2350,8 @@ class UIColor extends i {
|
|
|
2103
2350
|
*/
|
|
2104
2351
|
copy(color) {
|
|
2105
2352
|
if (color instanceof UIColor) {
|
|
2353
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2354
|
+
color._private_ensureRGBUpdatedFromHSL();
|
|
2106
2355
|
if (this._private_rInternal !== color._private_rInternal ||
|
|
2107
2356
|
this._private_gInternal !== color._private_gInternal ||
|
|
2108
2357
|
this._private_bInternal !== color._private_bInternal ||
|
|
@@ -2111,10 +2360,12 @@ class UIColor extends i {
|
|
|
2111
2360
|
this._private_gInternal = color._private_gInternal;
|
|
2112
2361
|
this._private_bInternal = color._private_bInternal;
|
|
2113
2362
|
this._private_aInternal = color._private_aInternal;
|
|
2363
|
+
this._private_hslDirty = true;
|
|
2114
2364
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2115
2365
|
}
|
|
2116
2366
|
}
|
|
2117
2367
|
else {
|
|
2368
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2118
2369
|
if (this._private_rInternal !== color.r ||
|
|
2119
2370
|
this._private_gInternal !== color.g ||
|
|
2120
2371
|
this._private_bInternal !== color.b ||
|
|
@@ -2123,6 +2374,7 @@ class UIColor extends i {
|
|
|
2123
2374
|
this._private_gInternal = color.g;
|
|
2124
2375
|
this._private_bInternal = color.b;
|
|
2125
2376
|
this._private_aInternal = 1;
|
|
2377
|
+
this._private_hslDirty = true;
|
|
2126
2378
|
this.emit(UIColorEvent.CHANGE, this);
|
|
2127
2379
|
}
|
|
2128
2380
|
}
|
|
@@ -2132,8 +2384,66 @@ class UIColor extends i {
|
|
|
2132
2384
|
* Creates a copy of this color.
|
|
2133
2385
|
*/
|
|
2134
2386
|
clone() {
|
|
2387
|
+
this._private_ensureRGBUpdatedFromHSL();
|
|
2135
2388
|
return new UIColor(this._private_rInternal, this._private_gInternal, this._private_bInternal, this._private_aInternal);
|
|
2136
2389
|
}
|
|
2390
|
+
/**
|
|
2391
|
+
* Updates RGB values from HSL if needed.
|
|
2392
|
+
*/
|
|
2393
|
+
_private_ensureRGBUpdatedFromHSL() {
|
|
2394
|
+
if (this._private_rgbDirty) {
|
|
2395
|
+
const { _private_hInternal: h, _private_sInternal: s, _private_lInternal: l } = this;
|
|
2396
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
2397
|
+
const hp = h / 60;
|
|
2398
|
+
const x = c * (1 - Math.abs((hp % 2) - 1));
|
|
2399
|
+
let [r, g, b] = hp < 1
|
|
2400
|
+
? [c, x, 0]
|
|
2401
|
+
: hp < 2
|
|
2402
|
+
? [x, c, 0]
|
|
2403
|
+
: hp < 3
|
|
2404
|
+
? [0, c, x]
|
|
2405
|
+
: hp < 4
|
|
2406
|
+
? [0, x, c]
|
|
2407
|
+
: hp < 5
|
|
2408
|
+
? [x, 0, c]
|
|
2409
|
+
: [c, 0, x];
|
|
2410
|
+
const m = l - c / 2;
|
|
2411
|
+
this._private_rInternal = r + m;
|
|
2412
|
+
this._private_gInternal = g + m;
|
|
2413
|
+
this._private_bInternal = b + m;
|
|
2414
|
+
this._private_rgbDirty = false;
|
|
2415
|
+
}
|
|
2416
|
+
}
|
|
2417
|
+
/**
|
|
2418
|
+
* Updates HSL values from RGB if needed.
|
|
2419
|
+
*/
|
|
2420
|
+
_private_ensureHSLUpdatedFromRGB() {
|
|
2421
|
+
if (this._private_hslDirty) {
|
|
2422
|
+
const { _private_rInternal: r, _private_gInternal: g, _private_bInternal: b } = this;
|
|
2423
|
+
const max = Math.max(r, g, b);
|
|
2424
|
+
const min = Math.min(r, g, b);
|
|
2425
|
+
const d = max - min;
|
|
2426
|
+
const l = (max + min) / 2;
|
|
2427
|
+
let h = 0;
|
|
2428
|
+
if (d !== 0) {
|
|
2429
|
+
if (max === r) {
|
|
2430
|
+
h = (g - b) / d + (g < b ? 6 : 0);
|
|
2431
|
+
}
|
|
2432
|
+
else if (max === g) {
|
|
2433
|
+
h = (b - r) / d + 2;
|
|
2434
|
+
}
|
|
2435
|
+
else {
|
|
2436
|
+
h = (r - g) / d + 4;
|
|
2437
|
+
}
|
|
2438
|
+
h *= 60;
|
|
2439
|
+
}
|
|
2440
|
+
const s = d === 0 ? 0 : d / (1 - Math.abs(2 * l - 1));
|
|
2441
|
+
this._private_hInternal = h;
|
|
2442
|
+
this._private_sInternal = s;
|
|
2443
|
+
this._private_lInternal = l;
|
|
2444
|
+
this._private_hslDirty = false;
|
|
2445
|
+
}
|
|
2446
|
+
}
|
|
2137
2447
|
}
|
|
2138
2448
|
|
|
2139
2449
|
/**
|
|
@@ -2169,7 +2479,6 @@ var fragmentShader = "in vec2 io_UV;\n\nuniform float alphaTest;\n\n#include <co
|
|
|
2169
2479
|
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
2480
|
|
|
2171
2481
|
const DEFAULT_ALPHA_TEST = 0.25;
|
|
2172
|
-
const COLOR = new Color();
|
|
2173
2482
|
const UNIFROM_TYPE_MAP = new Map([
|
|
2174
2483
|
[UIColor, "vec4"],
|
|
2175
2484
|
[Color, "vec3"],
|
|
@@ -2217,7 +2526,7 @@ class UISceneWrapper {
|
|
|
2217
2526
|
...Object.fromEntries(entries.map(([k, v]) => [
|
|
2218
2527
|
k,
|
|
2219
2528
|
{
|
|
2220
|
-
value: v instanceof UIColor ?
|
|
2529
|
+
value: v instanceof UIColor ? v.toGLSLColor() : v,
|
|
2221
2530
|
},
|
|
2222
2531
|
])),
|
|
2223
2532
|
},
|
|
@@ -2259,9 +2568,7 @@ class UISceneWrapper {
|
|
|
2259
2568
|
throw new Error(`Uniform ${uniform} not found in material`);
|
|
2260
2569
|
}
|
|
2261
2570
|
if (value instanceof UIColor) {
|
|
2262
|
-
|
|
2263
|
-
linear.convertSRGBToLinear();
|
|
2264
|
-
descriptor.material.uniforms[uniform].value.set(linear.r, linear.g, linear.b, value.a);
|
|
2571
|
+
value.toGLSLColor(descriptor.material.uniforms[uniform].value);
|
|
2265
2572
|
}
|
|
2266
2573
|
else {
|
|
2267
2574
|
descriptor.material.uniforms[uniform].value = value;
|