@galfus/engine 0.0.0-stage → 0.31.1-alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +190 -2
- package/package.json +59 -4
- package/src/anchors/cache.ts +101 -0
- package/src/anchors/component.ts +123 -0
- package/src/anchors/hierarchy.ts +192 -0
- package/src/anchors/index.ts +8 -0
- package/src/anchors/solver.ts +247 -0
- package/src/anchors/strategy.ts +142 -0
- package/src/animation/blending.ts +163 -0
- package/src/animation/clip.ts +132 -0
- package/src/animation/coordinator.ts +568 -0
- package/src/animation/index.ts +7 -0
- package/src/animation/native-targets.ts +37 -0
- package/src/animation/player.ts +287 -0
- package/src/audio/index.ts +4 -0
- package/src/audio/manager.ts +371 -0
- package/src/collision/components.ts +211 -0
- package/src/collision/index.ts +16 -0
- package/src/collision/query2d.ts +167 -0
- package/src/collision/query3d.ts +170 -0
- package/src/ecs/component.ts +130 -0
- package/src/ecs/entity.ts +75 -0
- package/src/ecs/index.ts +9 -0
- package/src/ecs/intent.ts +162 -0
- package/src/ecs/metadata.ts +44 -0
- package/src/ecs/system.ts +224 -0
- package/src/ecs/world.ts +291 -0
- package/src/index.ts +19 -0
- package/src/interaction/focus.ts +327 -0
- package/src/interaction/index.ts +9 -0
- package/src/interaction/listener.ts +58 -0
- package/src/interaction/snapshot2d.ts +210 -0
- package/src/interaction/snapshot3d.ts +214 -0
- package/src/interaction/system.ts +544 -0
- package/src/interaction/types.ts +27 -0
- package/src/math/common.ts +67 -0
- package/src/math/index.ts +17 -0
- package/src/math/mat2d.ts +320 -0
- package/src/math/mat4.ts +576 -0
- package/src/math/quat.ts +438 -0
- package/src/math/vec2.ts +161 -0
- package/src/math/vec3.ts +242 -0
- package/src/math/vec4.ts +171 -0
- package/src/multiverse/coordinator.ts +540 -0
- package/src/multiverse/index.ts +13 -0
- package/src/multiverse/presentation-graph.ts +306 -0
- package/src/multiverse/presentation-links.ts +134 -0
- package/src/multiverse/realm.ts +49 -0
- package/src/platform/index.ts +2 -0
- package/src/platform/platform.ts +149 -0
- package/src/platform/window.ts +181 -0
- package/src/realm2d/components.ts +254 -0
- package/src/realm2d/index.ts +12 -0
- package/src/realm2d/presets/index.ts +36 -0
- package/src/realm2d/realm.ts +522 -0
- package/src/realm2d/sync.ts +284 -0
- package/src/realm2d/utils/index.ts +32 -0
- package/src/realm3d/components.ts +341 -0
- package/src/realm3d/geometry.ts +224 -0
- package/src/realm3d/index.ts +12 -0
- package/src/realm3d/presets/index.ts +67 -0
- package/src/realm3d/realm.ts +588 -0
- package/src/realm3d/resource-ids.ts +62 -0
- package/src/realm3d/skinning.ts +128 -0
- package/src/realm3d/sync.ts +442 -0
- package/src/realm3d/utils/index.ts +26 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/manager.ts +92 -0
- package/src/runtime.ts +588 -0
- package/src/spatial/dirty_registry.ts +217 -0
- package/src/spatial/flags.ts +14 -0
- package/src/spatial/index.ts +6 -0
- package/src/spatial/metrics.ts +124 -0
- package/src/text/editor.ts +224 -0
- package/src/text/encoding.ts +38 -0
- package/src/text/index.ts +13 -0
- package/src/text/input.ts +160 -0
- package/src/text/keyboard.ts +50 -0
- package/src/text/svg-decorations.ts +147 -0
- package/src/types.ts +85 -0
package/src/math/vec3.ts
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 3D vector operations.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { EPSILON, equalsApprox } from './common';
|
|
6
|
+
import type { ReadonlyMat4 } from './mat4';
|
|
7
|
+
import type { ReadonlyQuat } from './quat';
|
|
8
|
+
|
|
9
|
+
export type Vec3 = Float32Array & {
|
|
10
|
+
0: number;
|
|
11
|
+
1: number;
|
|
12
|
+
2: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ReadonlyVec3 = ArrayLike<number> & {
|
|
16
|
+
0: number;
|
|
17
|
+
1: number;
|
|
18
|
+
2: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export type WritableVec3 = Vec3 | [number, number, number];
|
|
22
|
+
|
|
23
|
+
export function create(): Vec3 {
|
|
24
|
+
return new Float32Array(3) as unknown as Vec3;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function fromValues(x: number, y: number, z: number): Vec3 {
|
|
28
|
+
const out = new Float32Array(3) as unknown as Vec3;
|
|
29
|
+
out[0] = x;
|
|
30
|
+
out[1] = y;
|
|
31
|
+
out[2] = z;
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function copy(out: Vec3, a: ReadonlyVec3): Vec3 {
|
|
36
|
+
out[0] = a[0];
|
|
37
|
+
out[1] = a[1];
|
|
38
|
+
out[2] = a[2];
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function set(out: Vec3, x: number, y: number, z: number): Vec3 {
|
|
43
|
+
out[0] = x;
|
|
44
|
+
out[1] = y;
|
|
45
|
+
out[2] = z;
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function add<T extends WritableVec3>(out: T, a: ReadonlyVec3, b: ReadonlyVec3): T {
|
|
50
|
+
out[0] = a[0] + b[0];
|
|
51
|
+
out[1] = a[1] + b[1];
|
|
52
|
+
out[2] = a[2] + b[2];
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Adds a scaled vector to another vector. */
|
|
57
|
+
export function scaleAndAdd<T extends WritableVec3>(
|
|
58
|
+
out: T,
|
|
59
|
+
a: ReadonlyVec3,
|
|
60
|
+
b: ReadonlyVec3,
|
|
61
|
+
scale: number
|
|
62
|
+
): T {
|
|
63
|
+
out[0] = a[0] + b[0] * scale;
|
|
64
|
+
out[1] = a[1] + b[1] * scale;
|
|
65
|
+
out[2] = a[2] + b[2] * scale;
|
|
66
|
+
return out;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export function subtract(out: Vec3, a: ReadonlyVec3, b: ReadonlyVec3): Vec3 {
|
|
70
|
+
out[0] = a[0] - b[0];
|
|
71
|
+
out[1] = a[1] - b[1];
|
|
72
|
+
out[2] = a[2] - b[2];
|
|
73
|
+
return out;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export function multiply(out: Vec3, a: ReadonlyVec3, b: ReadonlyVec3): Vec3 {
|
|
77
|
+
out[0] = a[0] * b[0];
|
|
78
|
+
out[1] = a[1] * b[1];
|
|
79
|
+
out[2] = a[2] * b[2];
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function scale<T extends WritableVec3>(out: T, a: ReadonlyVec3, b: number): T {
|
|
84
|
+
out[0] = a[0] * b;
|
|
85
|
+
out[1] = a[1] * b;
|
|
86
|
+
out[2] = a[2] * b;
|
|
87
|
+
return out;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function distance(a: ReadonlyVec3, b: ReadonlyVec3): number {
|
|
91
|
+
const x = b[0] - a[0];
|
|
92
|
+
const y = b[1] - a[1];
|
|
93
|
+
const z = b[2] - a[2];
|
|
94
|
+
return Math.hypot(x, y, z);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function length(a: ReadonlyVec3): number {
|
|
98
|
+
return Math.hypot(a[0], a[1], a[2]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function normalize<T extends WritableVec3>(out: T, a: ReadonlyVec3): T {
|
|
102
|
+
const x = a[0];
|
|
103
|
+
const y = a[1];
|
|
104
|
+
const z = a[2];
|
|
105
|
+
const len = Math.hypot(x, y, z);
|
|
106
|
+
out[0] = len === 0 ? 0 : x / len;
|
|
107
|
+
out[1] = len === 0 ? 0 : y / len;
|
|
108
|
+
out[2] = len === 0 ? 0 : z / len;
|
|
109
|
+
return out;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function dot(a: ReadonlyVec3, b: ReadonlyVec3): number {
|
|
113
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function cross(out: Vec3, a: ReadonlyVec3, b: ReadonlyVec3): Vec3 {
|
|
117
|
+
const ax = a[0];
|
|
118
|
+
const ay = a[1];
|
|
119
|
+
const az = a[2];
|
|
120
|
+
const bx = b[0];
|
|
121
|
+
const by = b[1];
|
|
122
|
+
const bz = b[2];
|
|
123
|
+
|
|
124
|
+
out[0] = ay * bz - az * by;
|
|
125
|
+
out[1] = az * bx - ax * bz;
|
|
126
|
+
out[2] = ax * by - ay * bx;
|
|
127
|
+
return out;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export function lerp(out: Vec3, a: ReadonlyVec3, b: ReadonlyVec3, t: number): Vec3 {
|
|
131
|
+
const ax = a[0];
|
|
132
|
+
const ay = a[1];
|
|
133
|
+
const az = a[2];
|
|
134
|
+
out[0] = ax + t * (b[0] - ax);
|
|
135
|
+
out[1] = ay + t * (b[1] - ay);
|
|
136
|
+
out[2] = az + t * (b[2] - az);
|
|
137
|
+
return out;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export function clamp(
|
|
141
|
+
out: Vec3,
|
|
142
|
+
a: ReadonlyVec3,
|
|
143
|
+
min: ReadonlyVec3 | number,
|
|
144
|
+
max: ReadonlyVec3 | number
|
|
145
|
+
): Vec3 {
|
|
146
|
+
const minX = typeof min === 'number' ? min : min[0];
|
|
147
|
+
const minY = typeof min === 'number' ? min : min[1];
|
|
148
|
+
const minZ = typeof min === 'number' ? min : min[2];
|
|
149
|
+
const maxX = typeof max === 'number' ? max : max[0];
|
|
150
|
+
const maxY = typeof max === 'number' ? max : max[1];
|
|
151
|
+
const maxZ = typeof max === 'number' ? max : max[2];
|
|
152
|
+
out[0] = Math.min(Math.max(a[0], minX), maxX);
|
|
153
|
+
out[1] = Math.min(Math.max(a[1], minY), maxY);
|
|
154
|
+
out[2] = Math.min(Math.max(a[2], minZ), maxZ);
|
|
155
|
+
return out;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export function transformQuat(out: Vec3, a: ReadonlyVec3, q: ReadonlyQuat): Vec3 {
|
|
159
|
+
const qx = q[0];
|
|
160
|
+
const qy = q[1];
|
|
161
|
+
const qz = q[2];
|
|
162
|
+
const qw = q[3];
|
|
163
|
+
const x = a[0];
|
|
164
|
+
const y = a[1];
|
|
165
|
+
const z = a[2];
|
|
166
|
+
|
|
167
|
+
let uvx = qy * z - qz * y;
|
|
168
|
+
let uvy = qz * x - qx * z;
|
|
169
|
+
let uvz = qx * y - qy * x;
|
|
170
|
+
|
|
171
|
+
let uuvx = qy * uvz - qz * uvy;
|
|
172
|
+
let uuvy = qz * uvx - qx * uvz;
|
|
173
|
+
let uuvz = qx * uvy - qy * uvx;
|
|
174
|
+
|
|
175
|
+
const w2 = qw * 2;
|
|
176
|
+
uvx *= w2;
|
|
177
|
+
uvy *= w2;
|
|
178
|
+
uvz *= w2;
|
|
179
|
+
|
|
180
|
+
uuvx *= 2;
|
|
181
|
+
uuvy *= 2;
|
|
182
|
+
uuvz *= 2;
|
|
183
|
+
|
|
184
|
+
out[0] = x + uvx + uuvx;
|
|
185
|
+
out[1] = y + uvy + uuvy;
|
|
186
|
+
out[2] = z + uvz + uuvz;
|
|
187
|
+
return out;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function transformMat4<T extends WritableVec3>(out: T, a: ReadonlyVec3, m: ReadonlyMat4): T {
|
|
191
|
+
const x = a[0];
|
|
192
|
+
const y = a[1];
|
|
193
|
+
const z = a[2];
|
|
194
|
+
let w = m[3] * x + m[7] * y + m[11] * z + m[15];
|
|
195
|
+
w = w || 1.0;
|
|
196
|
+
out[0] = (m[0] * x + m[4] * y + m[8] * z + m[12]) / w;
|
|
197
|
+
out[1] = (m[1] * x + m[5] * y + m[9] * z + m[13]) / w;
|
|
198
|
+
out[2] = (m[2] * x + m[6] * y + m[10] * z + m[14]) / w;
|
|
199
|
+
return out;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Transforms a direction by the linear part of a 4x4 matrix. */
|
|
203
|
+
export function transformDirectionMat4<T extends WritableVec3>(
|
|
204
|
+
out: T,
|
|
205
|
+
a: ReadonlyVec3,
|
|
206
|
+
m: ReadonlyMat4
|
|
207
|
+
): T {
|
|
208
|
+
const x = a[0],
|
|
209
|
+
y = a[1],
|
|
210
|
+
z = a[2];
|
|
211
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z;
|
|
212
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z;
|
|
213
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z;
|
|
214
|
+
return out;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Transforms a normal using the transpose of an already inverted affine matrix. */
|
|
218
|
+
export function transformNormalMat4<T extends WritableVec3>(
|
|
219
|
+
out: T,
|
|
220
|
+
a: ReadonlyVec3,
|
|
221
|
+
inverse: ReadonlyMat4
|
|
222
|
+
): T {
|
|
223
|
+
const x = a[0],
|
|
224
|
+
y = a[1],
|
|
225
|
+
z = a[2];
|
|
226
|
+
out[0] = inverse[0] * x + inverse[1] * y + inverse[2] * z;
|
|
227
|
+
out[1] = inverse[4] * x + inverse[5] * y + inverse[6] * z;
|
|
228
|
+
out[2] = inverse[8] * x + inverse[9] * y + inverse[10] * z;
|
|
229
|
+
return out;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
export function exactEquals(a: ReadonlyVec3, b: ReadonlyVec3): boolean {
|
|
233
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2];
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export function equals(a: ReadonlyVec3, b: ReadonlyVec3, epsilon: number = EPSILON): boolean {
|
|
237
|
+
return (
|
|
238
|
+
equalsApprox(a[0], b[0], epsilon) &&
|
|
239
|
+
equalsApprox(a[1], b[1], epsilon) &&
|
|
240
|
+
equalsApprox(a[2], b[2], epsilon)
|
|
241
|
+
);
|
|
242
|
+
}
|
package/src/math/vec4.ts
ADDED
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 4D vector operations.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { EPSILON, equalsApprox } from './common';
|
|
6
|
+
import type { ReadonlyMat4 } from './mat4';
|
|
7
|
+
|
|
8
|
+
export type Vec4 = Float32Array & {
|
|
9
|
+
0: number;
|
|
10
|
+
1: number;
|
|
11
|
+
2: number;
|
|
12
|
+
3: number;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export type ReadonlyVec4 = ArrayLike<number> & {
|
|
16
|
+
0: number;
|
|
17
|
+
1: number;
|
|
18
|
+
2: number;
|
|
19
|
+
3: number;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function create(): Vec4 {
|
|
23
|
+
return new Float32Array(4) as unknown as Vec4;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function fromValues(x: number, y: number, z: number, w: number): Vec4 {
|
|
27
|
+
const out = new Float32Array(4) as unknown as Vec4;
|
|
28
|
+
out[0] = x;
|
|
29
|
+
out[1] = y;
|
|
30
|
+
out[2] = z;
|
|
31
|
+
out[3] = w;
|
|
32
|
+
return out;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function copy(out: Vec4, a: ReadonlyVec4): Vec4 {
|
|
36
|
+
out[0] = a[0];
|
|
37
|
+
out[1] = a[1];
|
|
38
|
+
out[2] = a[2];
|
|
39
|
+
out[3] = a[3];
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function set(out: Vec4, x: number, y: number, z: number, w: number): Vec4 {
|
|
44
|
+
out[0] = x;
|
|
45
|
+
out[1] = y;
|
|
46
|
+
out[2] = z;
|
|
47
|
+
out[3] = w;
|
|
48
|
+
return out;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function add(out: Vec4, a: ReadonlyVec4, b: ReadonlyVec4): Vec4 {
|
|
52
|
+
out[0] = a[0] + b[0];
|
|
53
|
+
out[1] = a[1] + b[1];
|
|
54
|
+
out[2] = a[2] + b[2];
|
|
55
|
+
out[3] = a[3] + b[3];
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function subtract(out: Vec4, a: ReadonlyVec4, b: ReadonlyVec4): Vec4 {
|
|
60
|
+
out[0] = a[0] - b[0];
|
|
61
|
+
out[1] = a[1] - b[1];
|
|
62
|
+
out[2] = a[2] - b[2];
|
|
63
|
+
out[3] = a[3] - b[3];
|
|
64
|
+
return out;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export function multiply(out: Vec4, a: ReadonlyVec4, b: ReadonlyVec4): Vec4 {
|
|
68
|
+
out[0] = a[0] * b[0];
|
|
69
|
+
out[1] = a[1] * b[1];
|
|
70
|
+
out[2] = a[2] * b[2];
|
|
71
|
+
out[3] = a[3] * b[3];
|
|
72
|
+
return out;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function scale(out: Vec4, a: ReadonlyVec4, b: number): Vec4 {
|
|
76
|
+
out[0] = a[0] * b;
|
|
77
|
+
out[1] = a[1] * b;
|
|
78
|
+
out[2] = a[2] * b;
|
|
79
|
+
out[3] = a[3] * b;
|
|
80
|
+
return out;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function distance(a: ReadonlyVec4, b: ReadonlyVec4): number {
|
|
84
|
+
const x = b[0] - a[0];
|
|
85
|
+
const y = b[1] - a[1];
|
|
86
|
+
const z = b[2] - a[2];
|
|
87
|
+
const w = b[3] - a[3];
|
|
88
|
+
return Math.hypot(x, y, z, w);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function length(a: ReadonlyVec4): number {
|
|
92
|
+
return Math.hypot(a[0], a[1], a[2], a[3]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function normalize(out: Vec4, a: ReadonlyVec4): Vec4 {
|
|
96
|
+
const x = a[0];
|
|
97
|
+
const y = a[1];
|
|
98
|
+
const z = a[2];
|
|
99
|
+
const w = a[3];
|
|
100
|
+
let len = x * x + y * y + z * z + w * w;
|
|
101
|
+
if (len > 0) {
|
|
102
|
+
len = 1 / Math.sqrt(len);
|
|
103
|
+
}
|
|
104
|
+
out[0] = x * len;
|
|
105
|
+
out[1] = y * len;
|
|
106
|
+
out[2] = z * len;
|
|
107
|
+
out[3] = w * len;
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function dot(a: ReadonlyVec4, b: ReadonlyVec4): number {
|
|
112
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
export function lerp(out: Vec4, a: ReadonlyVec4, b: ReadonlyVec4, t: number): Vec4 {
|
|
116
|
+
const ax = a[0];
|
|
117
|
+
const ay = a[1];
|
|
118
|
+
const az = a[2];
|
|
119
|
+
const aw = a[3];
|
|
120
|
+
out[0] = ax + t * (b[0] - ax);
|
|
121
|
+
out[1] = ay + t * (b[1] - ay);
|
|
122
|
+
out[2] = az + t * (b[2] - az);
|
|
123
|
+
out[3] = aw + t * (b[3] - aw);
|
|
124
|
+
return out;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export function clamp(
|
|
128
|
+
out: Vec4,
|
|
129
|
+
a: ReadonlyVec4,
|
|
130
|
+
min: ReadonlyVec4 | number,
|
|
131
|
+
max: ReadonlyVec4 | number
|
|
132
|
+
): Vec4 {
|
|
133
|
+
const minX = typeof min === 'number' ? min : min[0];
|
|
134
|
+
const minY = typeof min === 'number' ? min : min[1];
|
|
135
|
+
const minZ = typeof min === 'number' ? min : min[2];
|
|
136
|
+
const minW = typeof min === 'number' ? min : min[3];
|
|
137
|
+
const maxX = typeof max === 'number' ? max : max[0];
|
|
138
|
+
const maxY = typeof max === 'number' ? max : max[1];
|
|
139
|
+
const maxZ = typeof max === 'number' ? max : max[2];
|
|
140
|
+
const maxW = typeof max === 'number' ? max : max[3];
|
|
141
|
+
out[0] = Math.min(Math.max(a[0], minX), maxX);
|
|
142
|
+
out[1] = Math.min(Math.max(a[1], minY), maxY);
|
|
143
|
+
out[2] = Math.min(Math.max(a[2], minZ), maxZ);
|
|
144
|
+
out[3] = Math.min(Math.max(a[3], minW), maxW);
|
|
145
|
+
return out;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export function transformMat4(out: Vec4, a: ReadonlyVec4, m: ReadonlyMat4): Vec4 {
|
|
149
|
+
const x = a[0];
|
|
150
|
+
const y = a[1];
|
|
151
|
+
const z = a[2];
|
|
152
|
+
const w = a[3];
|
|
153
|
+
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
|
|
154
|
+
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
|
|
155
|
+
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
|
|
156
|
+
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
|
|
157
|
+
return out;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
export function exactEquals(a: ReadonlyVec4, b: ReadonlyVec4): boolean {
|
|
161
|
+
return a[0] === b[0] && a[1] === b[1] && a[2] === b[2] && a[3] === b[3];
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export function equals(a: ReadonlyVec4, b: ReadonlyVec4, epsilon: number = EPSILON): boolean {
|
|
165
|
+
return (
|
|
166
|
+
equalsApprox(a[0], b[0], epsilon) &&
|
|
167
|
+
equalsApprox(a[1], b[1], epsilon) &&
|
|
168
|
+
equalsApprox(a[2], b[2], epsilon) &&
|
|
169
|
+
equalsApprox(a[3], b[3], epsilon)
|
|
170
|
+
);
|
|
171
|
+
}
|