@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
|
@@ -0,0 +1,320 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 2x3 affine transformation matrix for 2D graphics.
|
|
3
|
+
*
|
|
4
|
+
* Stored as a 6-element Float32Array: [a, b, c, d, tx, ty]
|
|
5
|
+
* Corresponding to the matrix:
|
|
6
|
+
* | a c tx |
|
|
7
|
+
* | b d ty |
|
|
8
|
+
* | 0 0 1 |
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { EPSILON, equalsApprox } from './common';
|
|
12
|
+
import type { ReadonlyVec2, Vec2 } from './vec2';
|
|
13
|
+
|
|
14
|
+
export type Mat2d = Float32Array & {
|
|
15
|
+
0: number;
|
|
16
|
+
1: number;
|
|
17
|
+
2: number;
|
|
18
|
+
3: number;
|
|
19
|
+
4: number;
|
|
20
|
+
5: number;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export type ReadonlyMat2d = ArrayLike<number> & {
|
|
24
|
+
0: number;
|
|
25
|
+
1: number;
|
|
26
|
+
2: number;
|
|
27
|
+
3: number;
|
|
28
|
+
4: number;
|
|
29
|
+
5: number;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export function create(): Mat2d {
|
|
33
|
+
const out = new Float32Array(6) as unknown as Mat2d;
|
|
34
|
+
out[0] = 1;
|
|
35
|
+
out[3] = 1;
|
|
36
|
+
return out;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function identity(out: Mat2d): Mat2d {
|
|
40
|
+
out[0] = 1;
|
|
41
|
+
out[1] = 0;
|
|
42
|
+
out[2] = 0;
|
|
43
|
+
out[3] = 1;
|
|
44
|
+
out[4] = 0;
|
|
45
|
+
out[5] = 0;
|
|
46
|
+
return out;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function copy(out: Mat2d, a: ReadonlyMat2d): Mat2d {
|
|
50
|
+
out[0] = a[0];
|
|
51
|
+
out[1] = a[1];
|
|
52
|
+
out[2] = a[2];
|
|
53
|
+
out[3] = a[3];
|
|
54
|
+
out[4] = a[4];
|
|
55
|
+
out[5] = a[5];
|
|
56
|
+
return out;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export function fromValues(
|
|
60
|
+
a: number,
|
|
61
|
+
b: number,
|
|
62
|
+
c: number,
|
|
63
|
+
d: number,
|
|
64
|
+
tx: number,
|
|
65
|
+
ty: number
|
|
66
|
+
): Mat2d {
|
|
67
|
+
const out = new Float32Array(6) as unknown as Mat2d;
|
|
68
|
+
out[0] = a;
|
|
69
|
+
out[1] = b;
|
|
70
|
+
out[2] = c;
|
|
71
|
+
out[3] = d;
|
|
72
|
+
out[4] = tx;
|
|
73
|
+
out[5] = ty;
|
|
74
|
+
return out;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export function multiply(out: Mat2d, a: ReadonlyMat2d, b: ReadonlyMat2d): Mat2d {
|
|
78
|
+
const a0 = a[0];
|
|
79
|
+
const a1 = a[1];
|
|
80
|
+
const a2 = a[2];
|
|
81
|
+
const a3 = a[3];
|
|
82
|
+
const a4 = a[4];
|
|
83
|
+
const a5 = a[5];
|
|
84
|
+
|
|
85
|
+
const b0 = b[0];
|
|
86
|
+
const b1 = b[1];
|
|
87
|
+
const b2 = b[2];
|
|
88
|
+
const b3 = b[3];
|
|
89
|
+
const b4 = b[4];
|
|
90
|
+
const b5 = b[5];
|
|
91
|
+
|
|
92
|
+
out[0] = a0 * b0 + a2 * b1;
|
|
93
|
+
out[1] = a1 * b0 + a3 * b1;
|
|
94
|
+
out[2] = a0 * b2 + a2 * b3;
|
|
95
|
+
out[3] = a1 * b2 + a3 * b3;
|
|
96
|
+
out[4] = a0 * b4 + a2 * b5 + a4;
|
|
97
|
+
out[5] = a1 * b4 + a3 * b5 + a5;
|
|
98
|
+
return out;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function fromTranslation(out: Mat2d, v: ReadonlyVec2): Mat2d {
|
|
102
|
+
out[0] = 1;
|
|
103
|
+
out[1] = 0;
|
|
104
|
+
out[2] = 0;
|
|
105
|
+
out[3] = 1;
|
|
106
|
+
out[4] = v[0];
|
|
107
|
+
out[5] = v[1];
|
|
108
|
+
return out;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function fromRotation(out: Mat2d, rad: number): Mat2d {
|
|
112
|
+
const s = Math.sin(rad);
|
|
113
|
+
const c = Math.cos(rad);
|
|
114
|
+
out[0] = c;
|
|
115
|
+
out[1] = s;
|
|
116
|
+
out[2] = -s;
|
|
117
|
+
out[3] = c;
|
|
118
|
+
out[4] = 0;
|
|
119
|
+
out[5] = 0;
|
|
120
|
+
return out;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export function fromScaling(out: Mat2d, v: ReadonlyVec2): Mat2d {
|
|
124
|
+
out[0] = v[0];
|
|
125
|
+
out[1] = 0;
|
|
126
|
+
out[2] = 0;
|
|
127
|
+
out[3] = v[1];
|
|
128
|
+
out[4] = 0;
|
|
129
|
+
out[5] = 0;
|
|
130
|
+
return out;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export function fromRotationTranslationScale(
|
|
134
|
+
out: Mat2d,
|
|
135
|
+
translation: ReadonlyVec2,
|
|
136
|
+
rotationRad: number,
|
|
137
|
+
scale: ReadonlyVec2
|
|
138
|
+
): Mat2d {
|
|
139
|
+
const s = Math.sin(rotationRad);
|
|
140
|
+
const c = Math.cos(rotationRad);
|
|
141
|
+
const sx = scale[0];
|
|
142
|
+
const sy = scale[1];
|
|
143
|
+
|
|
144
|
+
out[0] = c * sx;
|
|
145
|
+
out[1] = s * sx;
|
|
146
|
+
out[2] = -s * sy;
|
|
147
|
+
out[3] = c * sy;
|
|
148
|
+
out[4] = translation[0];
|
|
149
|
+
out[5] = translation[1];
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
export function translate(out: Mat2d, a: ReadonlyMat2d, v: ReadonlyVec2): Mat2d {
|
|
154
|
+
const a0 = a[0];
|
|
155
|
+
const a1 = a[1];
|
|
156
|
+
const a2 = a[2];
|
|
157
|
+
const a3 = a[3];
|
|
158
|
+
const a4 = a[4];
|
|
159
|
+
const a5 = a[5];
|
|
160
|
+
const vx = v[0];
|
|
161
|
+
const vy = v[1];
|
|
162
|
+
|
|
163
|
+
out[0] = a0;
|
|
164
|
+
out[1] = a1;
|
|
165
|
+
out[2] = a2;
|
|
166
|
+
out[3] = a3;
|
|
167
|
+
out[4] = a0 * vx + a2 * vy + a4;
|
|
168
|
+
out[5] = a1 * vx + a3 * vy + a5;
|
|
169
|
+
return out;
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
export function rotate(out: Mat2d, a: ReadonlyMat2d, rad: number): Mat2d {
|
|
173
|
+
const a0 = a[0];
|
|
174
|
+
const a1 = a[1];
|
|
175
|
+
const a2 = a[2];
|
|
176
|
+
const a3 = a[3];
|
|
177
|
+
const a4 = a[4];
|
|
178
|
+
const a5 = a[5];
|
|
179
|
+
const s = Math.sin(rad);
|
|
180
|
+
const c = Math.cos(rad);
|
|
181
|
+
|
|
182
|
+
out[0] = a0 * c + a2 * s;
|
|
183
|
+
out[1] = a1 * c + a3 * s;
|
|
184
|
+
out[2] = a0 * -s + a2 * c;
|
|
185
|
+
out[3] = a1 * -s + a3 * c;
|
|
186
|
+
out[4] = a4;
|
|
187
|
+
out[5] = a5;
|
|
188
|
+
return out;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
export function scale(out: Mat2d, a: ReadonlyMat2d, v: ReadonlyVec2): Mat2d {
|
|
192
|
+
const a0 = a[0];
|
|
193
|
+
const a1 = a[1];
|
|
194
|
+
const a2 = a[2];
|
|
195
|
+
const a3 = a[3];
|
|
196
|
+
const a4 = a[4];
|
|
197
|
+
const a5 = a[5];
|
|
198
|
+
const vx = v[0];
|
|
199
|
+
const vy = v[1];
|
|
200
|
+
|
|
201
|
+
out[0] = a0 * vx;
|
|
202
|
+
out[1] = a1 * vx;
|
|
203
|
+
out[2] = a2 * vy;
|
|
204
|
+
out[3] = a3 * vy;
|
|
205
|
+
out[4] = a4;
|
|
206
|
+
out[5] = a5;
|
|
207
|
+
return out;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function invert(out: Mat2d, a: ReadonlyMat2d): Mat2d | null {
|
|
211
|
+
const aa = a[0];
|
|
212
|
+
const ab = a[1];
|
|
213
|
+
const ac = a[2];
|
|
214
|
+
const ad = a[3];
|
|
215
|
+
const atx = a[4];
|
|
216
|
+
const aty = a[5];
|
|
217
|
+
|
|
218
|
+
let det = aa * ad - ab * ac;
|
|
219
|
+
if (!det) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
det = 1.0 / det;
|
|
223
|
+
|
|
224
|
+
out[0] = ad * det;
|
|
225
|
+
out[1] = -ab * det;
|
|
226
|
+
out[2] = -ac * det;
|
|
227
|
+
out[3] = aa * det;
|
|
228
|
+
out[4] = (ac * aty - ad * atx) * det;
|
|
229
|
+
out[5] = (ab * atx - aa * aty) * det;
|
|
230
|
+
return out;
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export function determinant(a: ReadonlyMat2d): number {
|
|
234
|
+
return a[0] * a[3] - a[1] * a[2];
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
/** Extracts the signed scales used when decomposing an affine transform. */
|
|
238
|
+
export function getScaling(out: Vec2, mat: ReadonlyMat2d): Vec2 {
|
|
239
|
+
out[0] = Math.hypot(mat[0], mat[1]);
|
|
240
|
+
out[1] = Math.hypot(mat[2], mat[3]) * (determinant(mat) < 0 ? -1 : 1);
|
|
241
|
+
return out;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/** Extracts the rotation used when decomposing an affine transform. */
|
|
245
|
+
export function getRotation(mat: ReadonlyMat2d): number {
|
|
246
|
+
return Math.atan2(mat[1], mat[0]);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export function equals(a: ReadonlyMat2d, b: ReadonlyMat2d, epsilon: number = EPSILON): boolean {
|
|
250
|
+
return (
|
|
251
|
+
equalsApprox(a[0], b[0], epsilon) &&
|
|
252
|
+
equalsApprox(a[1], b[1], epsilon) &&
|
|
253
|
+
equalsApprox(a[2], b[2], epsilon) &&
|
|
254
|
+
equalsApprox(a[3], b[3], epsilon) &&
|
|
255
|
+
equalsApprox(a[4], b[4], epsilon) &&
|
|
256
|
+
equalsApprox(a[5], b[5], epsilon)
|
|
257
|
+
);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Copies the 2D translation components from `from` into `out`.
|
|
262
|
+
*/
|
|
263
|
+
export function copyPosition(out: Mat2d, from: ReadonlyMat2d): Mat2d {
|
|
264
|
+
out[4] = from[4];
|
|
265
|
+
out[5] = from[5];
|
|
266
|
+
return out;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Sets the 2D translation components in `out`.
|
|
271
|
+
*/
|
|
272
|
+
export function setTranslation(out: Mat2d, xOrVec: number | ReadonlyVec2, y?: number): Mat2d {
|
|
273
|
+
if (typeof xOrVec === 'number') {
|
|
274
|
+
out[4] = xOrVec;
|
|
275
|
+
out[5] = y ?? 0;
|
|
276
|
+
} else {
|
|
277
|
+
out[4] = xOrVec[0];
|
|
278
|
+
out[5] = xOrVec[1];
|
|
279
|
+
}
|
|
280
|
+
return out;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Extracts the 2D translation vector from `mat` into `out`.
|
|
285
|
+
*/
|
|
286
|
+
export function getTranslation(out: Vec2, mat: ReadonlyMat2d): Vec2 {
|
|
287
|
+
out[0] = mat[4];
|
|
288
|
+
out[1] = mat[5];
|
|
289
|
+
return out;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/**
|
|
293
|
+
* Performs a component-wise linear interpolation between two 2D affine transformation matrices.
|
|
294
|
+
*/
|
|
295
|
+
export function lerp(out: Mat2d, a: ReadonlyMat2d, b: ReadonlyMat2d, t: number): Mat2d {
|
|
296
|
+
out[0] = a[0] + t * (b[0] - a[0]);
|
|
297
|
+
out[1] = a[1] + t * (b[1] - a[1]);
|
|
298
|
+
out[2] = a[2] + t * (b[2] - a[2]);
|
|
299
|
+
out[3] = a[3] + t * (b[3] - a[3]);
|
|
300
|
+
out[4] = a[4] + t * (b[4] - a[4]);
|
|
301
|
+
out[5] = a[5] + t * (b[5] - a[5]);
|
|
302
|
+
return out;
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* Clamps each component of a 2D affine transformation matrix between min and max.
|
|
307
|
+
*/
|
|
308
|
+
export function clamp(
|
|
309
|
+
out: Mat2d,
|
|
310
|
+
a: ReadonlyMat2d,
|
|
311
|
+
min: ReadonlyMat2d | number,
|
|
312
|
+
max: ReadonlyMat2d | number
|
|
313
|
+
): Mat2d {
|
|
314
|
+
for (let i = 0; i < 6; i++) {
|
|
315
|
+
const minVal = typeof min === 'number' ? min : min[i]!;
|
|
316
|
+
const maxVal = typeof max === 'number' ? max : max[i]!;
|
|
317
|
+
out[i] = Math.min(Math.max(a[i]!, minVal), maxVal);
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|