@holoscript/std 2.1.0 → 6.0.3
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/CHANGELOG.md +7 -0
- package/LICENSE +21 -0
- package/README.md +197 -0
- package/dist/__tests__/EconomicPrimitives.test.d.ts +2 -0
- package/dist/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
- package/dist/__tests__/EconomicTraits.test.d.ts +2 -0
- package/dist/__tests__/EconomicTraits.test.d.ts.map +1 -0
- package/dist/__tests__/SimulationLabPrimitives.test.d.ts +2 -0
- package/dist/__tests__/SimulationLabPrimitives.test.d.ts.map +1 -0
- package/dist/__tests__/collections.test.d.ts +2 -0
- package/dist/__tests__/collections.test.d.ts.map +1 -0
- package/dist/__tests__/events.test.d.ts +2 -0
- package/dist/__tests__/events.test.d.ts.map +1 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.d.ts.map +1 -0
- package/dist/__tests__/materials.test.d.ts +2 -0
- package/dist/__tests__/materials.test.d.ts.map +1 -0
- package/dist/__tests__/math.test.d.ts +2 -0
- package/dist/__tests__/math.test.d.ts.map +1 -0
- package/dist/__tests__/physics.test.d.ts +2 -0
- package/dist/__tests__/physics.test.d.ts.map +1 -0
- package/dist/__tests__/spatial.test.d.ts +2 -0
- package/dist/__tests__/spatial.test.d.ts.map +1 -0
- package/dist/__tests__/standard-library-fundamentals.test.d.ts +2 -0
- package/dist/__tests__/standard-library-fundamentals.test.d.ts.map +1 -0
- package/dist/__tests__/string-and-time-utilities.test.d.ts +2 -0
- package/dist/__tests__/string-and-time-utilities.test.d.ts.map +1 -0
- package/dist/__tests__/string-decoupled.test.d.ts +2 -0
- package/dist/__tests__/string-decoupled.test.d.ts.map +1 -0
- package/dist/__tests__/string.test.d.ts +2 -0
- package/dist/__tests__/string.test.d.ts.map +1 -0
- package/dist/__tests__/time.test.d.ts +2 -0
- package/dist/__tests__/time.test.d.ts.map +1 -0
- package/dist/chunk-7HVUYGPS.js +679 -0
- package/dist/chunk-7HVUYGPS.js.map +1 -0
- package/dist/chunk-P4O3WNG2.js +287 -0
- package/dist/chunk-P4O3WNG2.js.map +1 -0
- package/dist/chunk-PFX2JM4X.js +683 -0
- package/dist/chunk-PFX2JM4X.js.map +1 -0
- package/dist/chunk-W2Q3LUCM.js +348 -0
- package/dist/chunk-W2Q3LUCM.js.map +1 -0
- package/dist/chunk-WS6W35YC.js +443 -0
- package/dist/chunk-WS6W35YC.js.map +1 -0
- package/dist/chunk-ZXVZAQCZ.js +470 -0
- package/dist/chunk-ZXVZAQCZ.js.map +1 -0
- package/dist/collections.cjs +715 -0
- package/dist/collections.cjs.map +1 -0
- package/dist/collections.d.ts.map +1 -1
- package/dist/collections.js +16 -719
- package/dist/collections.js.map +1 -1
- package/dist/events.d.ts +32 -0
- package/dist/events.d.ts.map +1 -0
- package/dist/index.cjs +4101 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +21 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1270 -157
- package/dist/index.js.map +1 -1
- package/dist/materials.d.ts +50 -0
- package/dist/materials.d.ts.map +1 -0
- package/dist/math.cjs +591 -0
- package/dist/math.cjs.map +1 -0
- package/dist/math.d.ts.map +1 -1
- package/dist/math.js +51 -537
- package/dist/math.js.map +1 -1
- package/dist/physics.d.ts +59 -0
- package/dist/physics.d.ts.map +1 -0
- package/dist/spatial.d.ts +82 -0
- package/dist/spatial.d.ts.map +1 -0
- package/dist/string.basic.test.d.ts +5 -0
- package/dist/string.basic.test.d.ts.map +1 -0
- package/dist/string.cjs +422 -0
- package/dist/string.cjs.map +1 -0
- package/dist/string.d.ts +5 -1
- package/dist/string.d.ts.map +1 -1
- package/dist/string.js +106 -442
- package/dist/string.js.map +1 -1
- package/dist/string.test.d.ts +5 -0
- package/dist/string.test.d.ts.map +1 -0
- package/dist/time.cjs +512 -0
- package/dist/time.cjs.map +1 -0
- package/dist/time.d.ts.map +1 -1
- package/dist/time.js +41 -528
- package/dist/time.js.map +1 -1
- package/dist/traits/ARTraits.d.ts +14 -0
- package/dist/traits/ARTraits.d.ts.map +1 -0
- package/dist/traits/EconomicPrimitives.cjs +335 -0
- package/dist/traits/EconomicPrimitives.cjs.map +1 -0
- package/dist/traits/EconomicPrimitives.d.ts +345 -0
- package/dist/traits/EconomicPrimitives.d.ts.map +1 -0
- package/dist/traits/EconomicPrimitives.js +55 -0
- package/dist/traits/EconomicPrimitives.js.map +1 -0
- package/dist/traits/EconomicTraits.cjs +471 -0
- package/dist/traits/EconomicTraits.cjs.map +1 -0
- package/dist/traits/EconomicTraits.d.ts +71 -0
- package/dist/traits/EconomicTraits.d.ts.map +1 -0
- package/dist/traits/EconomicTraits.js +17 -0
- package/dist/traits/EconomicTraits.js.map +1 -0
- package/dist/traits/IoTTraits.d.ts +14 -0
- package/dist/traits/IoTTraits.d.ts.map +1 -0
- package/dist/traits/SimulationLabPrimitives.d.ts +187 -0
- package/dist/traits/SimulationLabPrimitives.d.ts.map +1 -0
- package/dist/traits/SimulationLabTraits.d.ts +42 -0
- package/dist/traits/SimulationLabTraits.d.ts.map +1 -0
- package/dist/traits/VRRTraits.d.ts +150 -0
- package/dist/traits/VRRTraits.d.ts.map +1 -0
- package/dist/traits/__tests__/ARTraits.test.d.ts +2 -0
- package/dist/traits/__tests__/ARTraits.test.d.ts.map +1 -0
- package/dist/traits/__tests__/EconomicPrimitives.test.d.ts +2 -0
- package/dist/traits/__tests__/EconomicPrimitives.test.d.ts.map +1 -0
- package/dist/traits/__tests__/EconomicTraits.test.d.ts +2 -0
- package/dist/traits/__tests__/EconomicTraits.test.d.ts.map +1 -0
- package/dist/types.d.ts +9 -0
- package/dist/types.d.ts.map +1 -1
- package/error-utf8.log +6 -0
- package/error.log +0 -0
- package/package.json +42 -19
- package/src/__tests__/EconomicPrimitives.test.ts +690 -0
- package/src/__tests__/EconomicTraits.test.ts +425 -0
- package/src/__tests__/SimulationLabPrimitives.test.ts +415 -0
- package/src/__tests__/collections.test.ts +182 -0
- package/src/__tests__/events.test.ts +135 -0
- package/src/__tests__/index.test.ts +14 -0
- package/src/__tests__/materials.test.ts +84 -0
- package/src/__tests__/math.test.ts +246 -0
- package/src/__tests__/physics.test.ts +83 -0
- package/src/__tests__/spatial.test.ts +333 -0
- package/src/__tests__/standard-library-fundamentals.test.ts +1301 -0
- package/src/__tests__/string-and-time-utilities.test.ts +1070 -0
- package/src/__tests__/string-decoupled.test.ts +14 -0
- package/src/__tests__/string.test.ts +164 -0
- package/src/__tests__/time.test.ts +110 -0
- package/src/collections.ts +8 -2
- package/src/events.ts +88 -0
- package/src/index.ts +161 -11
- package/src/materials.ts +109 -0
- package/src/math.ts +30 -14
- package/src/physics.ts +141 -0
- package/src/spatial.ts +320 -0
- package/src/string.basic.test.ts +14 -0
- package/src/string.test.ts +335 -0
- package/src/string.ts +45 -13
- package/src/time.ts +10 -11
- package/src/traits/ARTraits.ts +103 -0
- package/src/traits/EconomicPrimitives.ts +755 -0
- package/src/traits/EconomicTraits.ts +552 -0
- package/src/traits/IoTTraits.ts +102 -0
- package/src/traits/SimulationLabPrimitives.ts +650 -0
- package/src/traits/SimulationLabTraits.ts +191 -0
- package/src/traits/VRRTraits.ts +326 -0
- package/src/traits/__tests__/ARTraits.test.ts +14 -0
- package/src/traits/__tests__/EconomicPrimitives.test.ts +14 -0
- package/src/traits/__tests__/EconomicTraits.test.ts +14 -0
- package/src/types.ts +47 -12
- package/std_error.log +5 -0
- package/tsup.config.ts +17 -0
- package/vitest.config.ts +10 -0
- package/dist/types.js +0 -198
- package/dist/types.js.map +0 -1
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
// src/types.ts
|
|
2
|
+
function vec2(x = 0, y = 0) {
|
|
3
|
+
return { x, y };
|
|
4
|
+
}
|
|
5
|
+
function vec3(x = 0, y = 0, z = 0) {
|
|
6
|
+
return { x, y, z };
|
|
7
|
+
}
|
|
8
|
+
function vec4(x = 0, y = 0, z = 0, w = 0) {
|
|
9
|
+
return { x, y, z, w };
|
|
10
|
+
}
|
|
11
|
+
function quat(x = 0, y = 0, z = 0, w = 1) {
|
|
12
|
+
return { x, y, z, w };
|
|
13
|
+
}
|
|
14
|
+
function transform(position = vec3(), rotation = quat(), scale = vec3(1, 1, 1)) {
|
|
15
|
+
return { position, rotation, scale };
|
|
16
|
+
}
|
|
17
|
+
function rgb(r, g, b) {
|
|
18
|
+
return { r, g, b };
|
|
19
|
+
}
|
|
20
|
+
function rgba(r, g, b, a = 1) {
|
|
21
|
+
return { r, g, b, a };
|
|
22
|
+
}
|
|
23
|
+
function hsl(h, s, l) {
|
|
24
|
+
return { h, s, l };
|
|
25
|
+
}
|
|
26
|
+
function aabb(min = vec3(), max = vec3()) {
|
|
27
|
+
return { min, max };
|
|
28
|
+
}
|
|
29
|
+
function ray(origin, direction) {
|
|
30
|
+
return { origin, direction };
|
|
31
|
+
}
|
|
32
|
+
function vec3ToArray(v) {
|
|
33
|
+
return [v.x, v.y, v.z];
|
|
34
|
+
}
|
|
35
|
+
function arrayToVec3(arr) {
|
|
36
|
+
return { x: arr[0] || 0, y: arr[1] || 0, z: arr[2] || 0 };
|
|
37
|
+
}
|
|
38
|
+
function quatToArray(q) {
|
|
39
|
+
return [q.x, q.y, q.z, q.w];
|
|
40
|
+
}
|
|
41
|
+
function arrayToQuat(arr) {
|
|
42
|
+
return { x: arr[0] || 0, y: arr[1] || 0, z: arr[2] || 0, w: arr[3] ?? 1 };
|
|
43
|
+
}
|
|
44
|
+
function parseColor(color) {
|
|
45
|
+
if (typeof color === "string") {
|
|
46
|
+
if (color.startsWith("#")) {
|
|
47
|
+
const hex = color.slice(1);
|
|
48
|
+
if (hex.length === 3) {
|
|
49
|
+
return {
|
|
50
|
+
r: parseInt(hex[0] + hex[0], 16) / 255,
|
|
51
|
+
g: parseInt(hex[1] + hex[1], 16) / 255,
|
|
52
|
+
b: parseInt(hex[2] + hex[2], 16) / 255,
|
|
53
|
+
a: 1
|
|
54
|
+
};
|
|
55
|
+
} else if (hex.length === 6) {
|
|
56
|
+
return {
|
|
57
|
+
r: parseInt(hex.slice(0, 2), 16) / 255,
|
|
58
|
+
g: parseInt(hex.slice(2, 4), 16) / 255,
|
|
59
|
+
b: parseInt(hex.slice(4, 6), 16) / 255,
|
|
60
|
+
a: 1
|
|
61
|
+
};
|
|
62
|
+
} else if (hex.length === 8) {
|
|
63
|
+
return {
|
|
64
|
+
r: parseInt(hex.slice(0, 2), 16) / 255,
|
|
65
|
+
g: parseInt(hex.slice(2, 4), 16) / 255,
|
|
66
|
+
b: parseInt(hex.slice(4, 6), 16) / 255,
|
|
67
|
+
a: parseInt(hex.slice(6, 8), 16) / 255
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const namedColors = {
|
|
72
|
+
white: { r: 1, g: 1, b: 1, a: 1 },
|
|
73
|
+
black: { r: 0, g: 0, b: 0, a: 1 },
|
|
74
|
+
red: { r: 1, g: 0, b: 0, a: 1 },
|
|
75
|
+
green: { r: 0, g: 1, b: 0, a: 1 },
|
|
76
|
+
blue: { r: 0, g: 0, b: 1, a: 1 },
|
|
77
|
+
yellow: { r: 1, g: 1, b: 0, a: 1 },
|
|
78
|
+
cyan: { r: 0, g: 1, b: 1, a: 1 },
|
|
79
|
+
magenta: { r: 1, g: 0, b: 1, a: 1 }
|
|
80
|
+
};
|
|
81
|
+
return namedColors[color.toLowerCase()] || { r: 1, g: 1, b: 1, a: 1 };
|
|
82
|
+
}
|
|
83
|
+
if (typeof color === "number") {
|
|
84
|
+
return {
|
|
85
|
+
r: (color >> 16 & 255) / 255,
|
|
86
|
+
g: (color >> 8 & 255) / 255,
|
|
87
|
+
b: (color & 255) / 255,
|
|
88
|
+
a: 1
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
if ("h" in color) {
|
|
92
|
+
const { h, s, l } = color;
|
|
93
|
+
const c = (1 - Math.abs(2 * l - 1)) * s;
|
|
94
|
+
const x = c * (1 - Math.abs(h / 60 % 2 - 1));
|
|
95
|
+
const m = l - c / 2;
|
|
96
|
+
let r = 0, g = 0, b = 0;
|
|
97
|
+
if (h < 60) {
|
|
98
|
+
r = c;
|
|
99
|
+
g = x;
|
|
100
|
+
} else if (h < 120) {
|
|
101
|
+
r = x;
|
|
102
|
+
g = c;
|
|
103
|
+
} else if (h < 180) {
|
|
104
|
+
g = c;
|
|
105
|
+
b = x;
|
|
106
|
+
} else if (h < 240) {
|
|
107
|
+
g = x;
|
|
108
|
+
b = c;
|
|
109
|
+
} else if (h < 300) {
|
|
110
|
+
r = x;
|
|
111
|
+
b = c;
|
|
112
|
+
} else {
|
|
113
|
+
r = c;
|
|
114
|
+
b = x;
|
|
115
|
+
}
|
|
116
|
+
return { r: r + m, g: g + m, b: b + m, a: 1 };
|
|
117
|
+
}
|
|
118
|
+
if ("a" in color) {
|
|
119
|
+
return color;
|
|
120
|
+
}
|
|
121
|
+
return { ...color, a: 1 };
|
|
122
|
+
}
|
|
123
|
+
function colorToHex(color) {
|
|
124
|
+
const r = Math.round(color.r * 255).toString(16).padStart(2, "0");
|
|
125
|
+
const g = Math.round(color.g * 255).toString(16).padStart(2, "0");
|
|
126
|
+
const b = Math.round(color.b * 255).toString(16).padStart(2, "0");
|
|
127
|
+
return `#${r}${g}${b}`;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// src/math.ts
|
|
131
|
+
var PI = Math.PI;
|
|
132
|
+
var TAU = Math.PI * 2;
|
|
133
|
+
var HALF_PI = Math.PI / 2;
|
|
134
|
+
var DEG_TO_RAD = Math.PI / 180;
|
|
135
|
+
var RAD_TO_DEG = 180 / Math.PI;
|
|
136
|
+
var EPSILON = 1e-6;
|
|
137
|
+
function clamp(value, min, max) {
|
|
138
|
+
return Math.max(min, Math.min(max, value));
|
|
139
|
+
}
|
|
140
|
+
function lerp(a, b, t) {
|
|
141
|
+
return a + (b - a) * t;
|
|
142
|
+
}
|
|
143
|
+
function inverseLerp(a, b, value) {
|
|
144
|
+
return (value - a) / (b - a);
|
|
145
|
+
}
|
|
146
|
+
function remap(value, inMin, inMax, outMin, outMax) {
|
|
147
|
+
return lerp(outMin, outMax, inverseLerp(inMin, inMax, value));
|
|
148
|
+
}
|
|
149
|
+
function smoothstep(edge0, edge1, x) {
|
|
150
|
+
const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
|
|
151
|
+
return t * t * (3 - 2 * t);
|
|
152
|
+
}
|
|
153
|
+
function smootherstep(edge0, edge1, x) {
|
|
154
|
+
const t = clamp((x - edge0) / (edge1 - edge0), 0, 1);
|
|
155
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
156
|
+
}
|
|
157
|
+
function degToRad(degrees) {
|
|
158
|
+
return degrees * DEG_TO_RAD;
|
|
159
|
+
}
|
|
160
|
+
function radToDeg(radians) {
|
|
161
|
+
return radians * RAD_TO_DEG;
|
|
162
|
+
}
|
|
163
|
+
function mod(n, m) {
|
|
164
|
+
return (n % m + m) % m;
|
|
165
|
+
}
|
|
166
|
+
function fract(x) {
|
|
167
|
+
return x - Math.floor(x);
|
|
168
|
+
}
|
|
169
|
+
function sign(x) {
|
|
170
|
+
return x > 0 ? 1 : x < 0 ? -1 : 0;
|
|
171
|
+
}
|
|
172
|
+
function step(edge, x) {
|
|
173
|
+
return x < edge ? 0 : 1;
|
|
174
|
+
}
|
|
175
|
+
var vec2Math = {
|
|
176
|
+
add: (a, b) => ({ x: a.x + b.x, y: a.y + b.y }),
|
|
177
|
+
sub: (a, b) => ({ x: a.x - b.x, y: a.y - b.y }),
|
|
178
|
+
mul: (a, s) => ({ x: a.x * s, y: a.y * s }),
|
|
179
|
+
div: (a, s) => ({ x: a.x / s, y: a.y / s }),
|
|
180
|
+
dot: (a, b) => a.x * b.x + a.y * b.y,
|
|
181
|
+
length: (v) => Math.sqrt(v.x * v.x + v.y * v.y),
|
|
182
|
+
lengthSq: (v) => v.x * v.x + v.y * v.y,
|
|
183
|
+
normalize: (v) => {
|
|
184
|
+
const len = vec2Math.length(v);
|
|
185
|
+
return len > 0 ? vec2Math.div(v, len) : { x: 0, y: 0 };
|
|
186
|
+
},
|
|
187
|
+
distance: (a, b) => vec2Math.length(vec2Math.sub(a, b)),
|
|
188
|
+
lerp: (a, b, t) => ({
|
|
189
|
+
x: lerp(a.x, b.x, t),
|
|
190
|
+
y: lerp(a.y, b.y, t)
|
|
191
|
+
}),
|
|
192
|
+
rotate: (v, angle) => {
|
|
193
|
+
const c = Math.cos(angle);
|
|
194
|
+
const s = Math.sin(angle);
|
|
195
|
+
return { x: v.x * c - v.y * s, y: v.x * s + v.y * c };
|
|
196
|
+
},
|
|
197
|
+
angle: (v) => Math.atan2(v.y, v.x),
|
|
198
|
+
angleBetween: (a, b) => {
|
|
199
|
+
return Math.acos(clamp(vec2Math.dot(vec2Math.normalize(a), vec2Math.normalize(b)), -1, 1));
|
|
200
|
+
}
|
|
201
|
+
};
|
|
202
|
+
var vec3Math = {
|
|
203
|
+
zero: () => vec3(0, 0, 0),
|
|
204
|
+
one: () => vec3(1, 1, 1),
|
|
205
|
+
up: () => vec3(0, 1, 0),
|
|
206
|
+
down: () => vec3(0, -1, 0),
|
|
207
|
+
forward: () => vec3(0, 0, -1),
|
|
208
|
+
back: () => vec3(0, 0, 1),
|
|
209
|
+
left: () => vec3(-1, 0, 0),
|
|
210
|
+
right: () => vec3(1, 0, 0),
|
|
211
|
+
add: (a, b) => ({ x: a.x + b.x, y: a.y + b.y, z: a.z + b.z }),
|
|
212
|
+
sub: (a, b) => ({ x: a.x - b.x, y: a.y - b.y, z: a.z - b.z }),
|
|
213
|
+
mul: (a, s) => ({ x: a.x * s, y: a.y * s, z: a.z * s }),
|
|
214
|
+
div: (a, s) => ({ x: a.x / s, y: a.y / s, z: a.z / s }),
|
|
215
|
+
mulVec: (a, b) => ({ x: a.x * b.x, y: a.y * b.y, z: a.z * b.z }),
|
|
216
|
+
dot: (a, b) => a.x * b.x + a.y * b.y + a.z * b.z,
|
|
217
|
+
cross: (a, b) => ({
|
|
218
|
+
x: a.y * b.z - a.z * b.y,
|
|
219
|
+
y: a.z * b.x - a.x * b.z,
|
|
220
|
+
z: a.x * b.y - a.y * b.x
|
|
221
|
+
}),
|
|
222
|
+
length: (v) => Math.sqrt(v.x * v.x + v.y * v.y + v.z * v.z),
|
|
223
|
+
lengthSq: (v) => v.x * v.x + v.y * v.y + v.z * v.z,
|
|
224
|
+
normalize: (v) => {
|
|
225
|
+
const len = vec3Math.length(v);
|
|
226
|
+
return len > EPSILON ? vec3Math.div(v, len) : vec3(0, 0, 0);
|
|
227
|
+
},
|
|
228
|
+
distance: (a, b) => vec3Math.length(vec3Math.sub(a, b)),
|
|
229
|
+
distanceSq: (a, b) => vec3Math.lengthSq(vec3Math.sub(a, b)),
|
|
230
|
+
lerp: (a, b, t) => ({
|
|
231
|
+
x: lerp(a.x, b.x, t),
|
|
232
|
+
y: lerp(a.y, b.y, t),
|
|
233
|
+
z: lerp(a.z, b.z, t)
|
|
234
|
+
}),
|
|
235
|
+
slerp: (a, b, t) => {
|
|
236
|
+
const dot = clamp(vec3Math.dot(a, b), -1, 1);
|
|
237
|
+
const theta = Math.acos(dot) * t;
|
|
238
|
+
const relative = vec3Math.normalize(vec3Math.sub(b, vec3Math.mul(a, dot)));
|
|
239
|
+
return vec3Math.add(vec3Math.mul(a, Math.cos(theta)), vec3Math.mul(relative, Math.sin(theta)));
|
|
240
|
+
},
|
|
241
|
+
negate: (v) => ({ x: -v.x, y: -v.y, z: -v.z }),
|
|
242
|
+
abs: (v) => ({ x: Math.abs(v.x), y: Math.abs(v.y), z: Math.abs(v.z) }),
|
|
243
|
+
min: (a, b) => ({
|
|
244
|
+
x: Math.min(a.x, b.x),
|
|
245
|
+
y: Math.min(a.y, b.y),
|
|
246
|
+
z: Math.min(a.z, b.z)
|
|
247
|
+
}),
|
|
248
|
+
max: (a, b) => ({
|
|
249
|
+
x: Math.max(a.x, b.x),
|
|
250
|
+
y: Math.max(a.y, b.y),
|
|
251
|
+
z: Math.max(a.z, b.z)
|
|
252
|
+
}),
|
|
253
|
+
clamp: (v, min, max) => ({
|
|
254
|
+
x: clamp(v.x, min.x, max.x),
|
|
255
|
+
y: clamp(v.y, min.y, max.y),
|
|
256
|
+
z: clamp(v.z, min.z, max.z)
|
|
257
|
+
}),
|
|
258
|
+
floor: (v) => ({
|
|
259
|
+
x: Math.floor(v.x),
|
|
260
|
+
y: Math.floor(v.y),
|
|
261
|
+
z: Math.floor(v.z)
|
|
262
|
+
}),
|
|
263
|
+
ceil: (v) => ({
|
|
264
|
+
x: Math.ceil(v.x),
|
|
265
|
+
y: Math.ceil(v.y),
|
|
266
|
+
z: Math.ceil(v.z)
|
|
267
|
+
}),
|
|
268
|
+
round: (v) => ({
|
|
269
|
+
x: Math.round(v.x),
|
|
270
|
+
y: Math.round(v.y),
|
|
271
|
+
z: Math.round(v.z)
|
|
272
|
+
}),
|
|
273
|
+
reflect: (v, normal) => {
|
|
274
|
+
const dot = vec3Math.dot(v, normal);
|
|
275
|
+
return vec3Math.sub(v, vec3Math.mul(normal, 2 * dot));
|
|
276
|
+
},
|
|
277
|
+
project: (v, onto) => {
|
|
278
|
+
const dot = vec3Math.dot(v, onto);
|
|
279
|
+
const lenSq = vec3Math.lengthSq(onto);
|
|
280
|
+
return vec3Math.mul(onto, dot / lenSq);
|
|
281
|
+
},
|
|
282
|
+
angle: (a, b) => {
|
|
283
|
+
const dot = vec3Math.dot(vec3Math.normalize(a), vec3Math.normalize(b));
|
|
284
|
+
return Math.acos(clamp(dot, -1, 1));
|
|
285
|
+
},
|
|
286
|
+
equals: (a, b, epsilon = EPSILON) => {
|
|
287
|
+
return Math.abs(a.x - b.x) < epsilon && Math.abs(a.y - b.y) < epsilon && Math.abs(a.z - b.z) < epsilon;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
var quatMath = {
|
|
291
|
+
identity: () => quat(0, 0, 0, 1),
|
|
292
|
+
fromAxisAngle: (axis, angle) => {
|
|
293
|
+
const halfAngle = angle / 2;
|
|
294
|
+
const s = Math.sin(halfAngle);
|
|
295
|
+
const normalized = vec3Math.normalize(axis);
|
|
296
|
+
return {
|
|
297
|
+
x: normalized.x * s,
|
|
298
|
+
y: normalized.y * s,
|
|
299
|
+
z: normalized.z * s,
|
|
300
|
+
w: Math.cos(halfAngle)
|
|
301
|
+
};
|
|
302
|
+
},
|
|
303
|
+
fromEuler: (euler) => {
|
|
304
|
+
const { x, y, z } = euler;
|
|
305
|
+
const c1 = Math.cos(degToRad(x) / 2);
|
|
306
|
+
const c2 = Math.cos(degToRad(y) / 2);
|
|
307
|
+
const c3 = Math.cos(degToRad(z) / 2);
|
|
308
|
+
const s1 = Math.sin(degToRad(x) / 2);
|
|
309
|
+
const s2 = Math.sin(degToRad(y) / 2);
|
|
310
|
+
const s3 = Math.sin(degToRad(z) / 2);
|
|
311
|
+
return {
|
|
312
|
+
x: s1 * c2 * c3 + c1 * s2 * s3,
|
|
313
|
+
y: c1 * s2 * c3 - s1 * c2 * s3,
|
|
314
|
+
z: c1 * c2 * s3 + s1 * s2 * c3,
|
|
315
|
+
w: c1 * c2 * c3 - s1 * s2 * s3
|
|
316
|
+
};
|
|
317
|
+
},
|
|
318
|
+
toEuler: (q) => {
|
|
319
|
+
const sinr_cosp = 2 * (q.w * q.x + q.y * q.z);
|
|
320
|
+
const cosr_cosp = 1 - 2 * (q.x * q.x + q.y * q.y);
|
|
321
|
+
const x = Math.atan2(sinr_cosp, cosr_cosp);
|
|
322
|
+
const sinp = 2 * (q.w * q.y - q.z * q.x);
|
|
323
|
+
let y;
|
|
324
|
+
if (Math.abs(sinp) >= 1) {
|
|
325
|
+
y = Math.PI / 2 * Math.sign(sinp);
|
|
326
|
+
} else {
|
|
327
|
+
y = Math.asin(sinp);
|
|
328
|
+
}
|
|
329
|
+
const siny_cosp = 2 * (q.w * q.z + q.x * q.y);
|
|
330
|
+
const cosy_cosp = 1 - 2 * (q.y * q.y + q.z * q.z);
|
|
331
|
+
const z = Math.atan2(siny_cosp, cosy_cosp);
|
|
332
|
+
return {
|
|
333
|
+
x: radToDeg(x),
|
|
334
|
+
y: radToDeg(y),
|
|
335
|
+
z: radToDeg(z)
|
|
336
|
+
};
|
|
337
|
+
},
|
|
338
|
+
multiply: (a, b) => ({
|
|
339
|
+
x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
|
|
340
|
+
y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
|
|
341
|
+
z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
|
|
342
|
+
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z
|
|
343
|
+
}),
|
|
344
|
+
conjugate: (q) => ({ x: -q.x, y: -q.y, z: -q.z, w: q.w }),
|
|
345
|
+
inverse: (q) => {
|
|
346
|
+
const lenSq = q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w;
|
|
347
|
+
return {
|
|
348
|
+
x: -q.x / lenSq,
|
|
349
|
+
y: -q.y / lenSq,
|
|
350
|
+
z: -q.z / lenSq,
|
|
351
|
+
w: q.w / lenSq
|
|
352
|
+
};
|
|
353
|
+
},
|
|
354
|
+
normalize: (q) => {
|
|
355
|
+
const len = Math.sqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
|
|
356
|
+
return { x: q.x / len, y: q.y / len, z: q.z / len, w: q.w / len };
|
|
357
|
+
},
|
|
358
|
+
dot: (a, b) => a.x * b.x + a.y * b.y + a.z * b.z + a.w * b.w,
|
|
359
|
+
slerp: (a, b, t) => {
|
|
360
|
+
let dot = quatMath.dot(a, b);
|
|
361
|
+
let bAdjusted = b;
|
|
362
|
+
if (dot < 0) {
|
|
363
|
+
bAdjusted = { x: -b.x, y: -b.y, z: -b.z, w: -b.w };
|
|
364
|
+
dot = -dot;
|
|
365
|
+
}
|
|
366
|
+
if (dot > 0.9995) {
|
|
367
|
+
return quatMath.normalize({
|
|
368
|
+
x: lerp(a.x, bAdjusted.x, t),
|
|
369
|
+
y: lerp(a.y, bAdjusted.y, t),
|
|
370
|
+
z: lerp(a.z, bAdjusted.z, t),
|
|
371
|
+
w: lerp(a.w, bAdjusted.w, t)
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
const theta0 = Math.acos(dot);
|
|
375
|
+
const theta = theta0 * t;
|
|
376
|
+
const sinTheta = Math.sin(theta);
|
|
377
|
+
const sinTheta0 = Math.sin(theta0);
|
|
378
|
+
const s0 = Math.cos(theta) - dot * sinTheta / sinTheta0;
|
|
379
|
+
const s1 = sinTheta / sinTheta0;
|
|
380
|
+
return {
|
|
381
|
+
x: a.x * s0 + bAdjusted.x * s1,
|
|
382
|
+
y: a.y * s0 + bAdjusted.y * s1,
|
|
383
|
+
z: a.z * s0 + bAdjusted.z * s1,
|
|
384
|
+
w: a.w * s0 + bAdjusted.w * s1
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
rotateVec3: (q, v) => {
|
|
388
|
+
const qv = { x: q.x, y: q.y, z: q.z };
|
|
389
|
+
const uv = vec3Math.cross(qv, v);
|
|
390
|
+
const uuv = vec3Math.cross(qv, uv);
|
|
391
|
+
return vec3Math.add(v, vec3Math.add(vec3Math.mul(uv, 2 * q.w), vec3Math.mul(uuv, 2)));
|
|
392
|
+
},
|
|
393
|
+
lookAt: (forward, up = vec3(0, 1, 0)) => {
|
|
394
|
+
const f = vec3Math.normalize(forward);
|
|
395
|
+
const r = vec3Math.normalize(vec3Math.cross(up, f));
|
|
396
|
+
const u = vec3Math.cross(f, r);
|
|
397
|
+
const trace = r.x + u.y + f.z;
|
|
398
|
+
let q;
|
|
399
|
+
if (trace > 0) {
|
|
400
|
+
const s = 0.5 / Math.sqrt(trace + 1);
|
|
401
|
+
q = {
|
|
402
|
+
w: 0.25 / s,
|
|
403
|
+
x: (u.z - f.y) * s,
|
|
404
|
+
y: (f.x - r.z) * s,
|
|
405
|
+
z: (r.y - u.x) * s
|
|
406
|
+
};
|
|
407
|
+
} else if (r.x > u.y && r.x > f.z) {
|
|
408
|
+
const s = 2 * Math.sqrt(1 + r.x - u.y - f.z);
|
|
409
|
+
q = {
|
|
410
|
+
w: (u.z - f.y) / s,
|
|
411
|
+
x: 0.25 * s,
|
|
412
|
+
y: (u.x + r.y) / s,
|
|
413
|
+
z: (f.x + r.z) / s
|
|
414
|
+
};
|
|
415
|
+
} else if (u.y > f.z) {
|
|
416
|
+
const s = 2 * Math.sqrt(1 + u.y - r.x - f.z);
|
|
417
|
+
q = {
|
|
418
|
+
w: (f.x - r.z) / s,
|
|
419
|
+
x: (u.x + r.y) / s,
|
|
420
|
+
y: 0.25 * s,
|
|
421
|
+
z: (f.y + u.z) / s
|
|
422
|
+
};
|
|
423
|
+
} else {
|
|
424
|
+
const s = 2 * Math.sqrt(1 + f.z - r.x - u.y);
|
|
425
|
+
q = {
|
|
426
|
+
w: (r.y - u.x) / s,
|
|
427
|
+
x: (f.x + r.z) / s,
|
|
428
|
+
y: (f.y + u.z) / s,
|
|
429
|
+
z: 0.25 * s
|
|
430
|
+
};
|
|
431
|
+
}
|
|
432
|
+
return quatMath.normalize(q);
|
|
433
|
+
}
|
|
434
|
+
};
|
|
435
|
+
var aabbMath = {
|
|
436
|
+
contains: (aabb2, point) => {
|
|
437
|
+
return point.x >= aabb2.min.x && point.x <= aabb2.max.x && point.y >= aabb2.min.y && point.y <= aabb2.max.y && point.z >= aabb2.min.z && point.z <= aabb2.max.z;
|
|
438
|
+
},
|
|
439
|
+
intersects: (a, b) => {
|
|
440
|
+
return a.min.x <= b.max.x && a.max.x >= b.min.x && a.min.y <= b.max.y && a.max.y >= b.min.y && a.min.z <= b.max.z && a.max.z >= b.min.z;
|
|
441
|
+
},
|
|
442
|
+
center: (aabb2) => vec3Math.mul(vec3Math.add(aabb2.min, aabb2.max), 0.5),
|
|
443
|
+
size: (aabb2) => vec3Math.sub(aabb2.max, aabb2.min),
|
|
444
|
+
expand: (aabb2, point) => ({
|
|
445
|
+
min: vec3Math.min(aabb2.min, point),
|
|
446
|
+
max: vec3Math.max(aabb2.max, point)
|
|
447
|
+
}),
|
|
448
|
+
merge: (a, b) => ({
|
|
449
|
+
min: vec3Math.min(a.min, b.min),
|
|
450
|
+
max: vec3Math.max(a.max, b.max)
|
|
451
|
+
})
|
|
452
|
+
};
|
|
453
|
+
var perm = new Uint8Array(512);
|
|
454
|
+
for (let i = 0; i < 256; i++) perm[i] = perm[i + 256] = i;
|
|
455
|
+
for (let i = 255; i > 0; i--) {
|
|
456
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
457
|
+
[perm[i], perm[j]] = [perm[j], perm[i]];
|
|
458
|
+
perm[i + 256] = perm[i];
|
|
459
|
+
}
|
|
460
|
+
function fade(t) {
|
|
461
|
+
return t * t * t * (t * (t * 6 - 15) + 10);
|
|
462
|
+
}
|
|
463
|
+
function grad(hash, x, y, z) {
|
|
464
|
+
const h = hash & 15;
|
|
465
|
+
const u = h < 8 ? x : y;
|
|
466
|
+
const v = h < 4 ? y : h === 12 || h === 14 ? x : z;
|
|
467
|
+
return ((h & 1) === 0 ? u : -u) + ((h & 2) === 0 ? v : -v);
|
|
468
|
+
}
|
|
469
|
+
var noise = {
|
|
470
|
+
/**
|
|
471
|
+
* 3D Perlin noise (-1 to 1)
|
|
472
|
+
*/
|
|
473
|
+
perlin3d: (x, y, z) => {
|
|
474
|
+
const X = Math.floor(x) & 255;
|
|
475
|
+
const Y = Math.floor(y) & 255;
|
|
476
|
+
const Z = Math.floor(z) & 255;
|
|
477
|
+
x -= Math.floor(x);
|
|
478
|
+
y -= Math.floor(y);
|
|
479
|
+
z -= Math.floor(z);
|
|
480
|
+
const u = fade(x);
|
|
481
|
+
const v = fade(y);
|
|
482
|
+
const w = fade(z);
|
|
483
|
+
const A = perm[X] + Y;
|
|
484
|
+
const AA = perm[A] + Z;
|
|
485
|
+
const AB = perm[A + 1] + Z;
|
|
486
|
+
const B = perm[X + 1] + Y;
|
|
487
|
+
const BA = perm[B] + Z;
|
|
488
|
+
const BB = perm[B + 1] + Z;
|
|
489
|
+
return lerp(
|
|
490
|
+
lerp(
|
|
491
|
+
lerp(grad(perm[AA], x, y, z), grad(perm[BA], x - 1, y, z), u),
|
|
492
|
+
lerp(grad(perm[AB], x, y - 1, z), grad(perm[BB], x - 1, y - 1, z), u),
|
|
493
|
+
v
|
|
494
|
+
),
|
|
495
|
+
lerp(
|
|
496
|
+
lerp(grad(perm[AA + 1], x, y, z - 1), grad(perm[BA + 1], x - 1, y, z - 1), u),
|
|
497
|
+
lerp(grad(perm[AB + 1], x, y - 1, z - 1), grad(perm[BB + 1], x - 1, y - 1, z - 1), u),
|
|
498
|
+
v
|
|
499
|
+
),
|
|
500
|
+
w
|
|
501
|
+
);
|
|
502
|
+
},
|
|
503
|
+
/**
|
|
504
|
+
* 2D Perlin noise (-1 to 1)
|
|
505
|
+
*/
|
|
506
|
+
perlin2d: (x, y) => {
|
|
507
|
+
return noise.perlin3d(x, y, 0);
|
|
508
|
+
},
|
|
509
|
+
/**
|
|
510
|
+
* Fractal Brownian Motion (fBm)
|
|
511
|
+
*/
|
|
512
|
+
fbm: (x, y, z, octaves = 6, lacunarity = 2, gain = 0.5) => {
|
|
513
|
+
let value = 0;
|
|
514
|
+
let amplitude = 1;
|
|
515
|
+
let frequency = 1;
|
|
516
|
+
let maxValue = 0;
|
|
517
|
+
for (let i = 0; i < octaves; i++) {
|
|
518
|
+
value += amplitude * noise.perlin3d(x * frequency, y * frequency, z * frequency);
|
|
519
|
+
maxValue += amplitude;
|
|
520
|
+
amplitude *= gain;
|
|
521
|
+
frequency *= lacunarity;
|
|
522
|
+
}
|
|
523
|
+
return value / maxValue;
|
|
524
|
+
},
|
|
525
|
+
/**
|
|
526
|
+
* Simplex-like noise (approximation using perlin)
|
|
527
|
+
*/
|
|
528
|
+
simplex: (x, y) => {
|
|
529
|
+
return noise.perlin2d(x * 1.2, y * 1.2);
|
|
530
|
+
},
|
|
531
|
+
/**
|
|
532
|
+
* Worley/Cellular noise
|
|
533
|
+
*/
|
|
534
|
+
worley: (x, y, z) => {
|
|
535
|
+
const xi = Math.floor(x);
|
|
536
|
+
const yi = Math.floor(y);
|
|
537
|
+
const zi = Math.floor(z);
|
|
538
|
+
let minDist = Infinity;
|
|
539
|
+
for (let i = -1; i <= 1; i++) {
|
|
540
|
+
for (let j = -1; j <= 1; j++) {
|
|
541
|
+
for (let k = -1; k <= 1; k++) {
|
|
542
|
+
const cellX = xi + i;
|
|
543
|
+
const cellY = yi + j;
|
|
544
|
+
const cellZ = zi + k;
|
|
545
|
+
const hash = perm[perm[perm[cellX & 255] + cellY & 255] + cellZ & 255];
|
|
546
|
+
const px = cellX + hash / 255;
|
|
547
|
+
const py = cellY + hash * 7 % 255 / 255;
|
|
548
|
+
const pz = cellZ + hash * 13 % 255 / 255;
|
|
549
|
+
const dist = (x - px) * (x - px) + (y - py) * (y - py) + (z - pz) * (z - pz);
|
|
550
|
+
minDist = Math.min(minDist, dist);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
return Math.sqrt(minDist);
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
var random = {
|
|
558
|
+
/**
|
|
559
|
+
* Random float between 0 and 1
|
|
560
|
+
*/
|
|
561
|
+
float: () => Math.random(),
|
|
562
|
+
/**
|
|
563
|
+
* Random float in range [min, max)
|
|
564
|
+
*/
|
|
565
|
+
range: (min, max) => min + Math.random() * (max - min),
|
|
566
|
+
/**
|
|
567
|
+
* Random integer in range [min, max]
|
|
568
|
+
*/
|
|
569
|
+
int: (min, max) => Math.floor(min + Math.random() * (max - min + 1)),
|
|
570
|
+
/**
|
|
571
|
+
* Random boolean with probability
|
|
572
|
+
*/
|
|
573
|
+
bool: (probability = 0.5) => Math.random() < probability,
|
|
574
|
+
/**
|
|
575
|
+
* Random element from array
|
|
576
|
+
*/
|
|
577
|
+
pick: (array) => array[Math.floor(Math.random() * array.length)],
|
|
578
|
+
/**
|
|
579
|
+
* Shuffle array (Fisher-Yates)
|
|
580
|
+
*/
|
|
581
|
+
shuffle: (array) => {
|
|
582
|
+
const result = [...array];
|
|
583
|
+
for (let i = result.length - 1; i > 0; i--) {
|
|
584
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
585
|
+
[result[i], result[j]] = [result[j], result[i]];
|
|
586
|
+
}
|
|
587
|
+
return result;
|
|
588
|
+
},
|
|
589
|
+
/**
|
|
590
|
+
* Random Vec3 in unit sphere
|
|
591
|
+
*/
|
|
592
|
+
insideUnitSphere: () => {
|
|
593
|
+
const theta = Math.random() * TAU;
|
|
594
|
+
const phi = Math.acos(2 * Math.random() - 1);
|
|
595
|
+
const r = Math.cbrt(Math.random());
|
|
596
|
+
return {
|
|
597
|
+
x: r * Math.sin(phi) * Math.cos(theta),
|
|
598
|
+
y: r * Math.sin(phi) * Math.sin(theta),
|
|
599
|
+
z: r * Math.cos(phi)
|
|
600
|
+
};
|
|
601
|
+
},
|
|
602
|
+
/**
|
|
603
|
+
* Random Vec3 on unit sphere surface
|
|
604
|
+
*/
|
|
605
|
+
onUnitSphere: () => {
|
|
606
|
+
const theta = Math.random() * TAU;
|
|
607
|
+
const phi = Math.acos(2 * Math.random() - 1);
|
|
608
|
+
return {
|
|
609
|
+
x: Math.sin(phi) * Math.cos(theta),
|
|
610
|
+
y: Math.sin(phi) * Math.sin(theta),
|
|
611
|
+
z: Math.cos(phi)
|
|
612
|
+
};
|
|
613
|
+
},
|
|
614
|
+
/**
|
|
615
|
+
* Random Vec2 in unit circle
|
|
616
|
+
*/
|
|
617
|
+
insideUnitCircle: () => {
|
|
618
|
+
const theta = Math.random() * TAU;
|
|
619
|
+
const r = Math.sqrt(Math.random());
|
|
620
|
+
return {
|
|
621
|
+
x: r * Math.cos(theta),
|
|
622
|
+
y: r * Math.sin(theta)
|
|
623
|
+
};
|
|
624
|
+
},
|
|
625
|
+
/**
|
|
626
|
+
* Seeded random number generator
|
|
627
|
+
*/
|
|
628
|
+
seeded: (seed) => {
|
|
629
|
+
let s = seed;
|
|
630
|
+
return () => {
|
|
631
|
+
s = s * 1103515245 + 12345 & 2147483647;
|
|
632
|
+
return s / 2147483647;
|
|
633
|
+
};
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
|
|
637
|
+
export {
|
|
638
|
+
vec2,
|
|
639
|
+
vec3,
|
|
640
|
+
vec4,
|
|
641
|
+
quat,
|
|
642
|
+
transform,
|
|
643
|
+
rgb,
|
|
644
|
+
rgba,
|
|
645
|
+
hsl,
|
|
646
|
+
aabb,
|
|
647
|
+
ray,
|
|
648
|
+
vec3ToArray,
|
|
649
|
+
arrayToVec3,
|
|
650
|
+
quatToArray,
|
|
651
|
+
arrayToQuat,
|
|
652
|
+
parseColor,
|
|
653
|
+
colorToHex,
|
|
654
|
+
PI,
|
|
655
|
+
TAU,
|
|
656
|
+
HALF_PI,
|
|
657
|
+
DEG_TO_RAD,
|
|
658
|
+
RAD_TO_DEG,
|
|
659
|
+
EPSILON,
|
|
660
|
+
clamp,
|
|
661
|
+
lerp,
|
|
662
|
+
inverseLerp,
|
|
663
|
+
remap,
|
|
664
|
+
smoothstep,
|
|
665
|
+
smootherstep,
|
|
666
|
+
degToRad,
|
|
667
|
+
radToDeg,
|
|
668
|
+
mod,
|
|
669
|
+
fract,
|
|
670
|
+
sign,
|
|
671
|
+
step,
|
|
672
|
+
vec2Math,
|
|
673
|
+
vec3Math,
|
|
674
|
+
quatMath,
|
|
675
|
+
aabbMath,
|
|
676
|
+
noise,
|
|
677
|
+
random
|
|
678
|
+
};
|
|
679
|
+
//# sourceMappingURL=chunk-7HVUYGPS.js.map
|