@aura3d/math 4.3.7 → 4.6.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/SphericalHarmonics3.d.ts +6 -3
- package/dist/SphericalHarmonics3.d.ts.map +1 -1
- package/dist/SphericalHarmonics3.js +8 -5
- package/dist/SphericalHarmonics3.js.map +1 -1
- package/dist/three/Box3.d.ts +106 -0
- package/dist/three/Box3.d.ts.map +1 -0
- package/dist/three/Box3.js +348 -0
- package/dist/three/Box3.js.map +1 -0
- package/dist/three/Color.d.ts +127 -0
- package/dist/three/Color.d.ts.map +1 -0
- package/dist/three/Color.js +501 -0
- package/dist/three/Color.js.map +1 -0
- package/dist/three/Euler.d.ts +50 -0
- package/dist/three/Euler.d.ts.map +1 -0
- package/dist/three/Euler.js +210 -0
- package/dist/three/Euler.js.map +1 -0
- package/dist/three/Frustum.d.ts +59 -0
- package/dist/three/Frustum.d.ts.map +1 -0
- package/dist/three/Frustum.js +135 -0
- package/dist/three/Frustum.js.map +1 -0
- package/dist/three/Matrix3.d.ts +56 -0
- package/dist/three/Matrix3.d.ts.map +1 -0
- package/dist/three/Matrix3.js +248 -0
- package/dist/three/Matrix3.js.map +1 -0
- package/dist/three/Matrix4.d.ts +79 -0
- package/dist/three/Matrix4.d.ts.map +1 -0
- package/dist/three/Matrix4.js +708 -0
- package/dist/three/Matrix4.js.map +1 -0
- package/dist/three/Plane.d.ts +65 -0
- package/dist/three/Plane.d.ts.map +1 -0
- package/dist/three/Plane.js +135 -0
- package/dist/three/Plane.js.map +1 -0
- package/dist/three/Quaternion.d.ts +91 -0
- package/dist/three/Quaternion.d.ts.map +1 -0
- package/dist/three/Quaternion.js +444 -0
- package/dist/three/Quaternion.js.map +1 -0
- package/dist/three/Ray.d.ts +56 -0
- package/dist/three/Ray.d.ts.map +1 -0
- package/dist/three/Ray.js +340 -0
- package/dist/three/Ray.js.map +1 -0
- package/dist/three/Sphere.d.ts +58 -0
- package/dist/three/Sphere.d.ts.map +1 -0
- package/dist/three/Sphere.js +166 -0
- package/dist/three/Sphere.js.map +1 -0
- package/dist/three/Triangle.d.ts +58 -0
- package/dist/three/Triangle.d.ts.map +1 -0
- package/dist/three/Triangle.js +229 -0
- package/dist/three/Triangle.js.map +1 -0
- package/dist/three/Vector2.d.ts +88 -0
- package/dist/three/Vector2.d.ts.map +1 -0
- package/dist/three/Vector2.js +283 -0
- package/dist/three/Vector2.js.map +1 -0
- package/dist/three/Vector3.d.ts +137 -0
- package/dist/three/Vector3.d.ts.map +1 -0
- package/dist/three/Vector3.js +458 -0
- package/dist/three/Vector3.js.map +1 -0
- package/dist/three/Vector4.d.ts +100 -0
- package/dist/three/Vector4.d.ts.map +1 -0
- package/dist/three/Vector4.js +443 -0
- package/dist/three/Vector4.js.map +1 -0
- package/dist/three/index.d.ts +29 -0
- package/dist/three/index.d.ts.map +1 -0
- package/dist/three/index.js +29 -0
- package/dist/three/index.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import { Color as ImmutableColor } from "../Color.js";
|
|
2
|
+
import { Matrix3 } from "./Matrix3.js";
|
|
3
|
+
export declare const NoColorSpace = "";
|
|
4
|
+
export declare const SRGBColorSpace = "srgb";
|
|
5
|
+
export declare const LinearSRGBColorSpace = "srgb-linear";
|
|
6
|
+
export declare const LinearTransfer = "linear";
|
|
7
|
+
export declare const SRGBTransfer = "srgb";
|
|
8
|
+
export interface HSL {
|
|
9
|
+
h: number;
|
|
10
|
+
s: number;
|
|
11
|
+
l: number;
|
|
12
|
+
}
|
|
13
|
+
export interface RGB {
|
|
14
|
+
r: number;
|
|
15
|
+
g: number;
|
|
16
|
+
b: number;
|
|
17
|
+
}
|
|
18
|
+
/** Anything with `r`, `g`, `b` channels, including the immutable `@aura3d/math` Color. */
|
|
19
|
+
export interface ColorLike {
|
|
20
|
+
readonly r: number;
|
|
21
|
+
readonly g: number;
|
|
22
|
+
readonly b: number;
|
|
23
|
+
}
|
|
24
|
+
interface ColorSpaceDefinition {
|
|
25
|
+
primaries: readonly number[];
|
|
26
|
+
whitePoint?: readonly number[];
|
|
27
|
+
transfer: string;
|
|
28
|
+
toXYZ: Matrix3;
|
|
29
|
+
fromXYZ: Matrix3;
|
|
30
|
+
luminanceCoefficients: readonly number[];
|
|
31
|
+
workingColorSpaceConfig?: {
|
|
32
|
+
unpackColorSpace: string;
|
|
33
|
+
};
|
|
34
|
+
outputColorSpaceConfig?: {
|
|
35
|
+
drawingBufferColorSpace: string;
|
|
36
|
+
toneMappingMode?: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export declare function SRGBToLinear(c: number): number;
|
|
40
|
+
export declare function LinearToSRGB(c: number): number;
|
|
41
|
+
/**
|
|
42
|
+
* three r185 `ColorManagement`: sRGB and linear-sRGB spaces, the linear-sRGB
|
|
43
|
+
* working space, and the same `convert` / `workingToColorSpace` /
|
|
44
|
+
* `colorSpaceToWorking` helpers. Additional spaces can be added with `define`.
|
|
45
|
+
*/
|
|
46
|
+
export declare const ColorManagement: {
|
|
47
|
+
enabled: boolean;
|
|
48
|
+
workingColorSpace: string;
|
|
49
|
+
spaces: Record<string, ColorSpaceDefinition>;
|
|
50
|
+
convert<T extends Color>(color: T, sourceColorSpace: string, targetColorSpace: string): T;
|
|
51
|
+
workingToColorSpace<T extends Color>(color: T, targetColorSpace: string): T;
|
|
52
|
+
colorSpaceToWorking<T extends Color>(color: T, sourceColorSpace: string): T;
|
|
53
|
+
getPrimaries(colorSpace: string): readonly number[];
|
|
54
|
+
getTransfer(colorSpace: string): string;
|
|
55
|
+
getToneMappingMode(colorSpace: string): string;
|
|
56
|
+
getLuminanceCoefficients<T extends {
|
|
57
|
+
fromArray(array: ArrayLike<number>): T;
|
|
58
|
+
}>(target: T, colorSpace?: string): T;
|
|
59
|
+
define(colorSpaces: Record<string, ColorSpaceDefinition>): void;
|
|
60
|
+
};
|
|
61
|
+
export declare const COLOR_KEYWORDS: Readonly<Record<string, number>>;
|
|
62
|
+
/**
|
|
63
|
+
* Mutable three.js-compatible RGB color in the linear-sRGB working space.
|
|
64
|
+
* Every modifier mutates `this` and returns `this`, exactly like three r185
|
|
65
|
+
* `Color`. `fromImmutable` / `toImmutable` cross into the immutable,
|
|
66
|
+
* linear-space `@aura3d/math` Color (alpha is 1 on the way out and ignored on the way in).
|
|
67
|
+
*/
|
|
68
|
+
export declare class Color {
|
|
69
|
+
static NAMES: Readonly<Record<string, number>>;
|
|
70
|
+
readonly isColor: true;
|
|
71
|
+
r: number;
|
|
72
|
+
g: number;
|
|
73
|
+
b: number;
|
|
74
|
+
constructor(r?: ColorLike | number | string, g?: number, b?: number);
|
|
75
|
+
/** Copy the linear channels of an immutable `@aura3d/math` Color (alpha is dropped). */
|
|
76
|
+
fromImmutable(c: ColorLike): this;
|
|
77
|
+
/** Snapshot as an immutable `@aura3d/math` Color with alpha 1 (throws on non-finite channels, like that class). */
|
|
78
|
+
toImmutable(alpha?: number): ImmutableColor;
|
|
79
|
+
set(r: ColorLike | number | string, g?: number, b?: number): this;
|
|
80
|
+
setScalar(scalar: number): this;
|
|
81
|
+
setHex(hex: number, colorSpace?: string): this;
|
|
82
|
+
setRGB(r: number, g: number, b: number, colorSpace?: string): this;
|
|
83
|
+
setHSL(h: number, s: number, l: number, colorSpace?: string): this;
|
|
84
|
+
setStyle(style: string, colorSpace?: string): this;
|
|
85
|
+
setColorName(style: string, colorSpace?: string): this;
|
|
86
|
+
clone(): this;
|
|
87
|
+
copy(color: ColorLike): this;
|
|
88
|
+
copySRGBToLinear(color: ColorLike): this;
|
|
89
|
+
copyLinearToSRGB(color: ColorLike): this;
|
|
90
|
+
convertSRGBToLinear(): this;
|
|
91
|
+
convertLinearToSRGB(): this;
|
|
92
|
+
getHex(colorSpace?: string): number;
|
|
93
|
+
getHexString(colorSpace?: string): string;
|
|
94
|
+
getHSL(target: HSL, colorSpace?: string): HSL;
|
|
95
|
+
getRGB(target: RGB, colorSpace?: string): RGB;
|
|
96
|
+
getStyle(colorSpace?: string): string;
|
|
97
|
+
offsetHSL(h: number, s: number, l: number): this;
|
|
98
|
+
add(color: ColorLike): this;
|
|
99
|
+
addColors(color1: ColorLike, color2: ColorLike): this;
|
|
100
|
+
addScalar(s: number): this;
|
|
101
|
+
sub(color: ColorLike): this;
|
|
102
|
+
multiply(color: ColorLike): this;
|
|
103
|
+
multiplyScalar(s: number): this;
|
|
104
|
+
lerp(color: ColorLike, alpha: number): this;
|
|
105
|
+
lerpColors(color1: ColorLike, color2: ColorLike, alpha: number): this;
|
|
106
|
+
lerpHSL(color: Color, alpha: number): this;
|
|
107
|
+
setFromVector3(v: {
|
|
108
|
+
readonly x: number;
|
|
109
|
+
readonly y: number;
|
|
110
|
+
readonly z: number;
|
|
111
|
+
}): this;
|
|
112
|
+
applyMatrix3(m: {
|
|
113
|
+
readonly elements: ArrayLike<number>;
|
|
114
|
+
}): this;
|
|
115
|
+
equals(c: ColorLike): boolean;
|
|
116
|
+
fromArray(array: ArrayLike<number>, offset?: number): this;
|
|
117
|
+
toArray(array?: number[], offset?: number): number[];
|
|
118
|
+
fromBufferAttribute(attribute: {
|
|
119
|
+
getX(index: number): number;
|
|
120
|
+
getY(index: number): number;
|
|
121
|
+
getZ(index: number): number;
|
|
122
|
+
}, index: number): this;
|
|
123
|
+
toJSON(): number;
|
|
124
|
+
[Symbol.iterator](): Generator<number, void, undefined>;
|
|
125
|
+
}
|
|
126
|
+
export {};
|
|
127
|
+
//# sourceMappingURL=Color.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Color.d.ts","sourceRoot":"","sources":["../../../../../packages/math/src/three/Color.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,IAAI,cAAc,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,eAAO,MAAM,YAAY,KAAK,CAAC;AAC/B,eAAO,MAAM,cAAc,SAAS,CAAC;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E,SAAS,CAAC;CAKzD"}
|
|
@@ -0,0 +1,501 @@
|
|
|
1
|
+
import { clamp, euclideanModulo, lerp } from "../MathUtils.js";
|
|
2
|
+
import { Color as ImmutableColor } from "../Color.js";
|
|
3
|
+
import { Matrix3 } from "./Matrix3.js";
|
|
4
|
+
export const NoColorSpace = "";
|
|
5
|
+
export const SRGBColorSpace = "srgb";
|
|
6
|
+
export const LinearSRGBColorSpace = "srgb-linear";
|
|
7
|
+
export const LinearTransfer = "linear";
|
|
8
|
+
export const SRGBTransfer = "srgb";
|
|
9
|
+
export function SRGBToLinear(c) {
|
|
10
|
+
return c < 0.04045 ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
|
|
11
|
+
}
|
|
12
|
+
export function LinearToSRGB(c) {
|
|
13
|
+
return c < 0.0031308 ? c * 12.92 : 1.055 * Math.pow(c, 0.41666) - 0.055;
|
|
14
|
+
}
|
|
15
|
+
const LINEAR_REC709_TO_XYZ = new Matrix3().set(0.4123908, 0.3575843, 0.1804808, 0.2126390, 0.7151687, 0.0721923, 0.0193308, 0.1191948, 0.9505322);
|
|
16
|
+
const XYZ_TO_LINEAR_REC709 = new Matrix3().set(3.2409699, -1.5373832, -0.4986108, -0.9692436, 1.8759675, 0.0415551, 0.0556301, -0.2039770, 1.0569715);
|
|
17
|
+
const REC709_PRIMARIES = [0.640, 0.330, 0.300, 0.600, 0.150, 0.060];
|
|
18
|
+
const REC709_LUMINANCE_COEFFICIENTS = [0.2126, 0.7152, 0.0722];
|
|
19
|
+
const D65 = [0.3127, 0.3290];
|
|
20
|
+
/**
|
|
21
|
+
* three r185 `ColorManagement`: sRGB and linear-sRGB spaces, the linear-sRGB
|
|
22
|
+
* working space, and the same `convert` / `workingToColorSpace` /
|
|
23
|
+
* `colorSpaceToWorking` helpers. Additional spaces can be added with `define`.
|
|
24
|
+
*/
|
|
25
|
+
export const ColorManagement = {
|
|
26
|
+
enabled: true,
|
|
27
|
+
workingColorSpace: LinearSRGBColorSpace,
|
|
28
|
+
spaces: {},
|
|
29
|
+
convert(color, sourceColorSpace, targetColorSpace) {
|
|
30
|
+
if (this.enabled === false || sourceColorSpace === targetColorSpace || !sourceColorSpace || !targetColorSpace) {
|
|
31
|
+
return color;
|
|
32
|
+
}
|
|
33
|
+
const source = this.spaces[sourceColorSpace];
|
|
34
|
+
const target = this.spaces[targetColorSpace];
|
|
35
|
+
if (source.transfer === SRGBTransfer) {
|
|
36
|
+
color.r = SRGBToLinear(color.r);
|
|
37
|
+
color.g = SRGBToLinear(color.g);
|
|
38
|
+
color.b = SRGBToLinear(color.b);
|
|
39
|
+
}
|
|
40
|
+
if (source.primaries !== target.primaries) {
|
|
41
|
+
color.applyMatrix3(source.toXYZ);
|
|
42
|
+
color.applyMatrix3(target.fromXYZ);
|
|
43
|
+
}
|
|
44
|
+
if (target.transfer === SRGBTransfer) {
|
|
45
|
+
color.r = LinearToSRGB(color.r);
|
|
46
|
+
color.g = LinearToSRGB(color.g);
|
|
47
|
+
color.b = LinearToSRGB(color.b);
|
|
48
|
+
}
|
|
49
|
+
return color;
|
|
50
|
+
},
|
|
51
|
+
workingToColorSpace(color, targetColorSpace) {
|
|
52
|
+
return this.convert(color, this.workingColorSpace, targetColorSpace);
|
|
53
|
+
},
|
|
54
|
+
colorSpaceToWorking(color, sourceColorSpace) {
|
|
55
|
+
return this.convert(color, sourceColorSpace, this.workingColorSpace);
|
|
56
|
+
},
|
|
57
|
+
getPrimaries(colorSpace) {
|
|
58
|
+
return this.spaces[colorSpace].primaries;
|
|
59
|
+
},
|
|
60
|
+
getTransfer(colorSpace) {
|
|
61
|
+
if (colorSpace === NoColorSpace)
|
|
62
|
+
return LinearTransfer;
|
|
63
|
+
return this.spaces[colorSpace].transfer;
|
|
64
|
+
},
|
|
65
|
+
getToneMappingMode(colorSpace) {
|
|
66
|
+
return this.spaces[colorSpace].outputColorSpaceConfig?.toneMappingMode || "standard";
|
|
67
|
+
},
|
|
68
|
+
getLuminanceCoefficients(target, colorSpace) {
|
|
69
|
+
return target.fromArray(this.spaces[colorSpace ?? this.workingColorSpace].luminanceCoefficients);
|
|
70
|
+
},
|
|
71
|
+
define(colorSpaces) {
|
|
72
|
+
Object.assign(this.spaces, colorSpaces);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
ColorManagement.define({
|
|
76
|
+
[LinearSRGBColorSpace]: {
|
|
77
|
+
primaries: REC709_PRIMARIES,
|
|
78
|
+
whitePoint: D65,
|
|
79
|
+
transfer: LinearTransfer,
|
|
80
|
+
toXYZ: LINEAR_REC709_TO_XYZ,
|
|
81
|
+
fromXYZ: XYZ_TO_LINEAR_REC709,
|
|
82
|
+
luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
|
|
83
|
+
workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
|
|
84
|
+
outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
|
|
85
|
+
},
|
|
86
|
+
[SRGBColorSpace]: {
|
|
87
|
+
primaries: REC709_PRIMARIES,
|
|
88
|
+
whitePoint: D65,
|
|
89
|
+
transfer: SRGBTransfer,
|
|
90
|
+
toXYZ: LINEAR_REC709_TO_XYZ,
|
|
91
|
+
fromXYZ: XYZ_TO_LINEAR_REC709,
|
|
92
|
+
luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
|
|
93
|
+
outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
export const COLOR_KEYWORDS = {
|
|
97
|
+
aliceblue: 0xF0F8FF, antiquewhite: 0xFAEBD7, aqua: 0x00FFFF, aquamarine: 0x7FFFD4, azure: 0xF0FFFF,
|
|
98
|
+
beige: 0xF5F5DC, bisque: 0xFFE4C4, black: 0x000000, blanchedalmond: 0xFFEBCD, blue: 0x0000FF, blueviolet: 0x8A2BE2,
|
|
99
|
+
brown: 0xA52A2A, burlywood: 0xDEB887, cadetblue: 0x5F9EA0, chartreuse: 0x7FFF00, chocolate: 0xD2691E,
|
|
100
|
+
coral: 0xFF7F50, cornflowerblue: 0x6495ED, cornsilk: 0xFFF8DC, crimson: 0xDC143C, cyan: 0x00FFFF,
|
|
101
|
+
darkblue: 0x00008B, darkcyan: 0x008B8B, darkgoldenrod: 0xB8860B, darkgray: 0xA9A9A9, darkgreen: 0x006400,
|
|
102
|
+
darkgrey: 0xA9A9A9, darkkhaki: 0xBDB76B, darkmagenta: 0x8B008B, darkolivegreen: 0x556B2F, darkorange: 0xFF8C00,
|
|
103
|
+
darkorchid: 0x9932CC, darkred: 0x8B0000, darksalmon: 0xE9967A, darkseagreen: 0x8FBC8F, darkslateblue: 0x483D8B,
|
|
104
|
+
darkslategray: 0x2F4F4F, darkslategrey: 0x2F4F4F, darkturquoise: 0x00CED1, darkviolet: 0x9400D3,
|
|
105
|
+
deeppink: 0xFF1493, deepskyblue: 0x00BFFF, dimgray: 0x696969, dimgrey: 0x696969, dodgerblue: 0x1E90FF,
|
|
106
|
+
firebrick: 0xB22222, floralwhite: 0xFFFAF0, forestgreen: 0x228B22, fuchsia: 0xFF00FF, gainsboro: 0xDCDCDC,
|
|
107
|
+
ghostwhite: 0xF8F8FF, gold: 0xFFD700, goldenrod: 0xDAA520, gray: 0x808080, green: 0x008000, greenyellow: 0xADFF2F,
|
|
108
|
+
grey: 0x808080, honeydew: 0xF0FFF0, hotpink: 0xFF69B4, indianred: 0xCD5C5C, indigo: 0x4B0082, ivory: 0xFFFFF0,
|
|
109
|
+
khaki: 0xF0E68C, lavender: 0xE6E6FA, lavenderblush: 0xFFF0F5, lawngreen: 0x7CFC00, lemonchiffon: 0xFFFACD,
|
|
110
|
+
lightblue: 0xADD8E6, lightcoral: 0xF08080, lightcyan: 0xE0FFFF, lightgoldenrodyellow: 0xFAFAD2,
|
|
111
|
+
lightgray: 0xD3D3D3, lightgreen: 0x90EE90, lightgrey: 0xD3D3D3, lightpink: 0xFFB6C1, lightsalmon: 0xFFA07A,
|
|
112
|
+
lightseagreen: 0x20B2AA, lightskyblue: 0x87CEFA, lightslategray: 0x778899, lightslategrey: 0x778899,
|
|
113
|
+
lightsteelblue: 0xB0C4DE, lightyellow: 0xFFFFE0, lime: 0x00FF00, limegreen: 0x32CD32, linen: 0xFAF0E6,
|
|
114
|
+
magenta: 0xFF00FF, maroon: 0x800000, mediumaquamarine: 0x66CDAA, mediumblue: 0x0000CD, mediumorchid: 0xBA55D3,
|
|
115
|
+
mediumpurple: 0x9370DB, mediumseagreen: 0x3CB371, mediumslateblue: 0x7B68EE, mediumspringgreen: 0x00FA9A,
|
|
116
|
+
mediumturquoise: 0x48D1CC, mediumvioletred: 0xC71585, midnightblue: 0x191970, mintcream: 0xF5FFFA,
|
|
117
|
+
mistyrose: 0xFFE4E1, moccasin: 0xFFE4B5, navajowhite: 0xFFDEAD, navy: 0x000080, oldlace: 0xFDF5E6, olive: 0x808000,
|
|
118
|
+
olivedrab: 0x6B8E23, orange: 0xFFA500, orangered: 0xFF4500, orchid: 0xDA70D6, palegoldenrod: 0xEEE8AA,
|
|
119
|
+
palegreen: 0x98FB98, paleturquoise: 0xAFEEEE, palevioletred: 0xDB7093, papayawhip: 0xFFEFD5, peachpuff: 0xFFDAB9,
|
|
120
|
+
peru: 0xCD853F, pink: 0xFFC0CB, plum: 0xDDA0DD, powderblue: 0xB0E0E6, purple: 0x800080, rebeccapurple: 0x663399,
|
|
121
|
+
red: 0xFF0000, rosybrown: 0xBC8F8F, royalblue: 0x4169E1, saddlebrown: 0x8B4513, salmon: 0xFA8072,
|
|
122
|
+
sandybrown: 0xF4A460, seagreen: 0x2E8B57, seashell: 0xFFF5EE, sienna: 0xA0522D, silver: 0xC0C0C0,
|
|
123
|
+
skyblue: 0x87CEEB, slateblue: 0x6A5ACD, slategray: 0x708090, slategrey: 0x708090, snow: 0xFFFAFA,
|
|
124
|
+
springgreen: 0x00FF7F, steelblue: 0x4682B4, tan: 0xD2B48C, teal: 0x008080, thistle: 0xD8BFD8, tomato: 0xFF6347,
|
|
125
|
+
turquoise: 0x40E0D0, violet: 0xEE82EE, wheat: 0xF5DEB3, white: 0xFFFFFF, whitesmoke: 0xF5F5F5, yellow: 0xFFFF00,
|
|
126
|
+
yellowgreen: 0x9ACD32,
|
|
127
|
+
};
|
|
128
|
+
const _hslA = { h: 0, s: 0, l: 0 };
|
|
129
|
+
const _hslB = { h: 0, s: 0, l: 0 };
|
|
130
|
+
function hue2rgb(p, q, t) {
|
|
131
|
+
if (t < 0)
|
|
132
|
+
t += 1;
|
|
133
|
+
if (t > 1)
|
|
134
|
+
t -= 1;
|
|
135
|
+
if (t < 1 / 6)
|
|
136
|
+
return p + (q - p) * 6 * t;
|
|
137
|
+
if (t < 1 / 2)
|
|
138
|
+
return q;
|
|
139
|
+
if (t < 2 / 3)
|
|
140
|
+
return p + (q - p) * 6 * (2 / 3 - t);
|
|
141
|
+
return p;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Mutable three.js-compatible RGB color in the linear-sRGB working space.
|
|
145
|
+
* Every modifier mutates `this` and returns `this`, exactly like three r185
|
|
146
|
+
* `Color`. `fromImmutable` / `toImmutable` cross into the immutable,
|
|
147
|
+
* linear-space `@aura3d/math` Color (alpha is 1 on the way out and ignored on the way in).
|
|
148
|
+
*/
|
|
149
|
+
export class Color {
|
|
150
|
+
static NAMES = COLOR_KEYWORDS;
|
|
151
|
+
r = 1;
|
|
152
|
+
g = 1;
|
|
153
|
+
b = 1;
|
|
154
|
+
constructor(r, g, b) {
|
|
155
|
+
this.set(r, g, b);
|
|
156
|
+
}
|
|
157
|
+
/** Copy the linear channels of an immutable `@aura3d/math` Color (alpha is dropped). */
|
|
158
|
+
fromImmutable(c) {
|
|
159
|
+
this.r = c.r;
|
|
160
|
+
this.g = c.g;
|
|
161
|
+
this.b = c.b;
|
|
162
|
+
return this;
|
|
163
|
+
}
|
|
164
|
+
/** Snapshot as an immutable `@aura3d/math` Color with alpha 1 (throws on non-finite channels, like that class). */
|
|
165
|
+
toImmutable(alpha = 1) {
|
|
166
|
+
return new ImmutableColor(this.r, this.g, this.b, alpha);
|
|
167
|
+
}
|
|
168
|
+
set(r, g, b) {
|
|
169
|
+
if (g === undefined && b === undefined) {
|
|
170
|
+
// r is THREE.Color, hex or string
|
|
171
|
+
const value = r;
|
|
172
|
+
if (value && typeof value === "object") {
|
|
173
|
+
this.copy(value);
|
|
174
|
+
}
|
|
175
|
+
else if (typeof value === "number") {
|
|
176
|
+
this.setHex(value);
|
|
177
|
+
}
|
|
178
|
+
else if (typeof value === "string") {
|
|
179
|
+
this.setStyle(value);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
this.setRGB(r, g, b);
|
|
184
|
+
}
|
|
185
|
+
return this;
|
|
186
|
+
}
|
|
187
|
+
setScalar(scalar) {
|
|
188
|
+
this.r = scalar;
|
|
189
|
+
this.g = scalar;
|
|
190
|
+
this.b = scalar;
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
setHex(hex, colorSpace = SRGBColorSpace) {
|
|
194
|
+
hex = Math.floor(hex);
|
|
195
|
+
this.r = ((hex >> 16) & 255) / 255;
|
|
196
|
+
this.g = ((hex >> 8) & 255) / 255;
|
|
197
|
+
this.b = (hex & 255) / 255;
|
|
198
|
+
ColorManagement.colorSpaceToWorking(this, colorSpace);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
setRGB(r, g, b, colorSpace = ColorManagement.workingColorSpace) {
|
|
202
|
+
this.r = r;
|
|
203
|
+
this.g = g;
|
|
204
|
+
this.b = b;
|
|
205
|
+
ColorManagement.colorSpaceToWorking(this, colorSpace);
|
|
206
|
+
return this;
|
|
207
|
+
}
|
|
208
|
+
setHSL(h, s, l, colorSpace = ColorManagement.workingColorSpace) {
|
|
209
|
+
// h,s,l ranges are in 0.0 - 1.0
|
|
210
|
+
h = euclideanModulo(h, 1);
|
|
211
|
+
s = clamp(s, 0, 1);
|
|
212
|
+
l = clamp(l, 0, 1);
|
|
213
|
+
if (s === 0) {
|
|
214
|
+
this.r = this.g = this.b = l;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
const p = l <= 0.5 ? l * (1 + s) : l + s - l * s;
|
|
218
|
+
const q = 2 * l - p;
|
|
219
|
+
this.r = hue2rgb(q, p, h + 1 / 3);
|
|
220
|
+
this.g = hue2rgb(q, p, h);
|
|
221
|
+
this.b = hue2rgb(q, p, h - 1 / 3);
|
|
222
|
+
}
|
|
223
|
+
ColorManagement.colorSpaceToWorking(this, colorSpace);
|
|
224
|
+
return this;
|
|
225
|
+
}
|
|
226
|
+
setStyle(style, colorSpace = SRGBColorSpace) {
|
|
227
|
+
function handleAlpha(string) {
|
|
228
|
+
if (string === undefined)
|
|
229
|
+
return;
|
|
230
|
+
if (parseFloat(string) < 1) {
|
|
231
|
+
console.warn(`THREE.Color: Alpha component of ${style} will be ignored.`);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let m;
|
|
235
|
+
if ((m = /^(\w+)\(([^)]*)\)/.exec(style))) {
|
|
236
|
+
// rgb / hsl
|
|
237
|
+
let color;
|
|
238
|
+
const name = m[1];
|
|
239
|
+
const components = m[2];
|
|
240
|
+
switch (name) {
|
|
241
|
+
case "rgb":
|
|
242
|
+
case "rgba":
|
|
243
|
+
if ((color = /^\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
|
|
244
|
+
// rgb(255,0,0) rgba(255,0,0,0.5)
|
|
245
|
+
handleAlpha(color[4]);
|
|
246
|
+
return this.setRGB(Math.min(255, parseInt(color[1], 10)) / 255, Math.min(255, parseInt(color[2], 10)) / 255, Math.min(255, parseInt(color[3], 10)) / 255, colorSpace);
|
|
247
|
+
}
|
|
248
|
+
if ((color = /^\s*(\d+)%\s*,\s*(\d+)%\s*,\s*(\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
|
|
249
|
+
// rgb(100%,0%,0%) rgba(100%,0%,0%,0.5)
|
|
250
|
+
handleAlpha(color[4]);
|
|
251
|
+
return this.setRGB(Math.min(100, parseInt(color[1], 10)) / 100, Math.min(100, parseInt(color[2], 10)) / 100, Math.min(100, parseInt(color[3], 10)) / 100, colorSpace);
|
|
252
|
+
}
|
|
253
|
+
break;
|
|
254
|
+
case "hsl":
|
|
255
|
+
case "hsla":
|
|
256
|
+
if ((color = /^\s*(\d*\.?\d+)\s*,\s*(\d*\.?\d+)%\s*,\s*(\d*\.?\d+)%\s*(?:,\s*(\d*\.?\d+)\s*)?$/.exec(components))) {
|
|
257
|
+
// hsl(120,50%,50%) hsla(120,50%,50%,0.5)
|
|
258
|
+
handleAlpha(color[4]);
|
|
259
|
+
return this.setHSL(parseFloat(color[1]) / 360, parseFloat(color[2]) / 100, parseFloat(color[3]) / 100, colorSpace);
|
|
260
|
+
}
|
|
261
|
+
break;
|
|
262
|
+
default:
|
|
263
|
+
console.warn(`THREE.Color: Unknown color model ${style}`);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
else if ((m = /^#([A-Fa-f\d]+)$/.exec(style))) {
|
|
267
|
+
// hex color
|
|
268
|
+
const hex = m[1];
|
|
269
|
+
const size = hex.length;
|
|
270
|
+
if (size === 3) {
|
|
271
|
+
// #ff0
|
|
272
|
+
return this.setRGB(parseInt(hex.charAt(0), 16) / 15, parseInt(hex.charAt(1), 16) / 15, parseInt(hex.charAt(2), 16) / 15, colorSpace);
|
|
273
|
+
}
|
|
274
|
+
else if (size === 6) {
|
|
275
|
+
// #ff0000
|
|
276
|
+
return this.setHex(parseInt(hex, 16), colorSpace);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
console.warn(`THREE.Color: Invalid hex color ${style}`);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
else if (style && style.length > 0) {
|
|
283
|
+
return this.setColorName(style, colorSpace);
|
|
284
|
+
}
|
|
285
|
+
return this;
|
|
286
|
+
}
|
|
287
|
+
setColorName(style, colorSpace = SRGBColorSpace) {
|
|
288
|
+
// color keywords
|
|
289
|
+
const hex = COLOR_KEYWORDS[style.toLowerCase()];
|
|
290
|
+
if (hex !== undefined) {
|
|
291
|
+
// red
|
|
292
|
+
this.setHex(hex, colorSpace);
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
// unknown color
|
|
296
|
+
console.warn(`THREE.Color: Unknown color ${style}`);
|
|
297
|
+
}
|
|
298
|
+
return this;
|
|
299
|
+
}
|
|
300
|
+
clone() {
|
|
301
|
+
return new this.constructor(this.r, this.g, this.b);
|
|
302
|
+
}
|
|
303
|
+
copy(color) {
|
|
304
|
+
this.r = color.r;
|
|
305
|
+
this.g = color.g;
|
|
306
|
+
this.b = color.b;
|
|
307
|
+
return this;
|
|
308
|
+
}
|
|
309
|
+
copySRGBToLinear(color) {
|
|
310
|
+
this.r = SRGBToLinear(color.r);
|
|
311
|
+
this.g = SRGBToLinear(color.g);
|
|
312
|
+
this.b = SRGBToLinear(color.b);
|
|
313
|
+
return this;
|
|
314
|
+
}
|
|
315
|
+
copyLinearToSRGB(color) {
|
|
316
|
+
this.r = LinearToSRGB(color.r);
|
|
317
|
+
this.g = LinearToSRGB(color.g);
|
|
318
|
+
this.b = LinearToSRGB(color.b);
|
|
319
|
+
return this;
|
|
320
|
+
}
|
|
321
|
+
convertSRGBToLinear() {
|
|
322
|
+
this.copySRGBToLinear(this);
|
|
323
|
+
return this;
|
|
324
|
+
}
|
|
325
|
+
convertLinearToSRGB() {
|
|
326
|
+
this.copyLinearToSRGB(this);
|
|
327
|
+
return this;
|
|
328
|
+
}
|
|
329
|
+
getHex(colorSpace = SRGBColorSpace) {
|
|
330
|
+
ColorManagement.workingToColorSpace(_color.copy(this), colorSpace);
|
|
331
|
+
return (Math.round(clamp(_color.r * 255, 0, 255)) * 65536 +
|
|
332
|
+
Math.round(clamp(_color.g * 255, 0, 255)) * 256 +
|
|
333
|
+
Math.round(clamp(_color.b * 255, 0, 255)));
|
|
334
|
+
}
|
|
335
|
+
getHexString(colorSpace = SRGBColorSpace) {
|
|
336
|
+
return `000000${this.getHex(colorSpace).toString(16)}`.slice(-6);
|
|
337
|
+
}
|
|
338
|
+
getHSL(target, colorSpace = ColorManagement.workingColorSpace) {
|
|
339
|
+
// h,s,l ranges are in 0.0 - 1.0
|
|
340
|
+
ColorManagement.workingToColorSpace(_color.copy(this), colorSpace);
|
|
341
|
+
const r = _color.r;
|
|
342
|
+
const g = _color.g;
|
|
343
|
+
const b = _color.b;
|
|
344
|
+
const max = Math.max(r, g, b);
|
|
345
|
+
const min = Math.min(r, g, b);
|
|
346
|
+
let hue = Number.NaN; // three leaves `hue` undefined when no channel matches max (NaN input); undefined / 6 is NaN
|
|
347
|
+
let saturation;
|
|
348
|
+
const lightness = (min + max) / 2.0;
|
|
349
|
+
if (min === max) {
|
|
350
|
+
hue = 0;
|
|
351
|
+
saturation = 0;
|
|
352
|
+
}
|
|
353
|
+
else {
|
|
354
|
+
const delta = max - min;
|
|
355
|
+
saturation = lightness <= 0.5 ? delta / (max + min) : delta / (2 - max - min);
|
|
356
|
+
switch (max) {
|
|
357
|
+
case r:
|
|
358
|
+
hue = (g - b) / delta + (g < b ? 6 : 0);
|
|
359
|
+
break;
|
|
360
|
+
case g:
|
|
361
|
+
hue = (b - r) / delta + 2;
|
|
362
|
+
break;
|
|
363
|
+
case b:
|
|
364
|
+
hue = (r - g) / delta + 4;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
hue /= 6;
|
|
368
|
+
}
|
|
369
|
+
target.h = hue;
|
|
370
|
+
target.s = saturation;
|
|
371
|
+
target.l = lightness;
|
|
372
|
+
return target;
|
|
373
|
+
}
|
|
374
|
+
getRGB(target, colorSpace = ColorManagement.workingColorSpace) {
|
|
375
|
+
ColorManagement.workingToColorSpace(_color.copy(this), colorSpace);
|
|
376
|
+
target.r = _color.r;
|
|
377
|
+
target.g = _color.g;
|
|
378
|
+
target.b = _color.b;
|
|
379
|
+
return target;
|
|
380
|
+
}
|
|
381
|
+
getStyle(colorSpace = SRGBColorSpace) {
|
|
382
|
+
ColorManagement.workingToColorSpace(_color.copy(this), colorSpace);
|
|
383
|
+
const r = _color.r;
|
|
384
|
+
const g = _color.g;
|
|
385
|
+
const b = _color.b;
|
|
386
|
+
if (colorSpace !== SRGBColorSpace) {
|
|
387
|
+
// Requires CSS Color Module Level 4 (https://www.w3.org/TR/css-color-4/).
|
|
388
|
+
return `color(${colorSpace} ${r.toFixed(3)} ${g.toFixed(3)} ${b.toFixed(3)})`;
|
|
389
|
+
}
|
|
390
|
+
return `rgb(${Math.round(r * 255)},${Math.round(g * 255)},${Math.round(b * 255)})`;
|
|
391
|
+
}
|
|
392
|
+
offsetHSL(h, s, l) {
|
|
393
|
+
this.getHSL(_hslA);
|
|
394
|
+
return this.setHSL(_hslA.h + h, _hslA.s + s, _hslA.l + l);
|
|
395
|
+
}
|
|
396
|
+
add(color) {
|
|
397
|
+
this.r += color.r;
|
|
398
|
+
this.g += color.g;
|
|
399
|
+
this.b += color.b;
|
|
400
|
+
return this;
|
|
401
|
+
}
|
|
402
|
+
addColors(color1, color2) {
|
|
403
|
+
this.r = color1.r + color2.r;
|
|
404
|
+
this.g = color1.g + color2.g;
|
|
405
|
+
this.b = color1.b + color2.b;
|
|
406
|
+
return this;
|
|
407
|
+
}
|
|
408
|
+
addScalar(s) {
|
|
409
|
+
this.r += s;
|
|
410
|
+
this.g += s;
|
|
411
|
+
this.b += s;
|
|
412
|
+
return this;
|
|
413
|
+
}
|
|
414
|
+
sub(color) {
|
|
415
|
+
this.r = Math.max(0, this.r - color.r);
|
|
416
|
+
this.g = Math.max(0, this.g - color.g);
|
|
417
|
+
this.b = Math.max(0, this.b - color.b);
|
|
418
|
+
return this;
|
|
419
|
+
}
|
|
420
|
+
multiply(color) {
|
|
421
|
+
this.r *= color.r;
|
|
422
|
+
this.g *= color.g;
|
|
423
|
+
this.b *= color.b;
|
|
424
|
+
return this;
|
|
425
|
+
}
|
|
426
|
+
multiplyScalar(s) {
|
|
427
|
+
this.r *= s;
|
|
428
|
+
this.g *= s;
|
|
429
|
+
this.b *= s;
|
|
430
|
+
return this;
|
|
431
|
+
}
|
|
432
|
+
lerp(color, alpha) {
|
|
433
|
+
this.r += (color.r - this.r) * alpha;
|
|
434
|
+
this.g += (color.g - this.g) * alpha;
|
|
435
|
+
this.b += (color.b - this.b) * alpha;
|
|
436
|
+
return this;
|
|
437
|
+
}
|
|
438
|
+
lerpColors(color1, color2, alpha) {
|
|
439
|
+
this.r = color1.r + (color2.r - color1.r) * alpha;
|
|
440
|
+
this.g = color1.g + (color2.g - color1.g) * alpha;
|
|
441
|
+
this.b = color1.b + (color2.b - color1.b) * alpha;
|
|
442
|
+
return this;
|
|
443
|
+
}
|
|
444
|
+
lerpHSL(color, alpha) {
|
|
445
|
+
this.getHSL(_hslA);
|
|
446
|
+
color.getHSL(_hslB);
|
|
447
|
+
const h = lerp(_hslA.h, _hslB.h, alpha);
|
|
448
|
+
const s = lerp(_hslA.s, _hslB.s, alpha);
|
|
449
|
+
const l = lerp(_hslA.l, _hslB.l, alpha);
|
|
450
|
+
this.setHSL(h, s, l);
|
|
451
|
+
return this;
|
|
452
|
+
}
|
|
453
|
+
setFromVector3(v) {
|
|
454
|
+
this.r = v.x;
|
|
455
|
+
this.g = v.y;
|
|
456
|
+
this.b = v.z;
|
|
457
|
+
return this;
|
|
458
|
+
}
|
|
459
|
+
applyMatrix3(m) {
|
|
460
|
+
const r = this.r;
|
|
461
|
+
const g = this.g;
|
|
462
|
+
const b = this.b;
|
|
463
|
+
const e = m.elements;
|
|
464
|
+
this.r = e[0] * r + e[3] * g + e[6] * b;
|
|
465
|
+
this.g = e[1] * r + e[4] * g + e[7] * b;
|
|
466
|
+
this.b = e[2] * r + e[5] * g + e[8] * b;
|
|
467
|
+
return this;
|
|
468
|
+
}
|
|
469
|
+
equals(c) {
|
|
470
|
+
return c.r === this.r && c.g === this.g && c.b === this.b;
|
|
471
|
+
}
|
|
472
|
+
fromArray(array, offset = 0) {
|
|
473
|
+
this.r = array[offset];
|
|
474
|
+
this.g = array[offset + 1];
|
|
475
|
+
this.b = array[offset + 2];
|
|
476
|
+
return this;
|
|
477
|
+
}
|
|
478
|
+
toArray(array = [], offset = 0) {
|
|
479
|
+
array[offset] = this.r;
|
|
480
|
+
array[offset + 1] = this.g;
|
|
481
|
+
array[offset + 2] = this.b;
|
|
482
|
+
return array;
|
|
483
|
+
}
|
|
484
|
+
fromBufferAttribute(attribute, index) {
|
|
485
|
+
this.r = attribute.getX(index);
|
|
486
|
+
this.g = attribute.getY(index);
|
|
487
|
+
this.b = attribute.getZ(index);
|
|
488
|
+
return this;
|
|
489
|
+
}
|
|
490
|
+
toJSON() {
|
|
491
|
+
return this.getHex();
|
|
492
|
+
}
|
|
493
|
+
*[Symbol.iterator]() {
|
|
494
|
+
yield this.r;
|
|
495
|
+
yield this.g;
|
|
496
|
+
yield this.b;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
Color.prototype.isColor = true;
|
|
500
|
+
const _color = new Color();
|
|
501
|
+
//# sourceMappingURL=Color.js.map
|