@aethervtt/shard-core 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/dist/ecs/commands.d.ts +35 -0
  4. package/dist/ecs/commands.js +96 -0
  5. package/dist/ecs/entity.d.ts +11 -0
  6. package/dist/ecs/entity.js +12 -0
  7. package/dist/ecs/events.d.ts +34 -0
  8. package/dist/ecs/events.js +65 -0
  9. package/dist/ecs/hierarchy.d.ts +7 -0
  10. package/dist/ecs/hierarchy.js +29 -0
  11. package/dist/ecs/index.d.ts +8 -0
  12. package/dist/ecs/index.js +38 -0
  13. package/dist/ecs/observers.d.ts +40 -0
  14. package/dist/ecs/observers.js +27 -0
  15. package/dist/ecs/query.d.ts +44 -0
  16. package/dist/ecs/query.js +67 -0
  17. package/dist/ecs/table.d.ts +91 -0
  18. package/dist/ecs/table.js +286 -0
  19. package/dist/ecs/world.d.ts +127 -0
  20. package/dist/ecs/world.js +513 -0
  21. package/dist/error.d.ts +26 -0
  22. package/dist/error.js +29 -0
  23. package/dist/index.d.ts +6 -0
  24. package/dist/index.js +9 -0
  25. package/dist/json.d.ts +15 -0
  26. package/dist/json.js +22 -0
  27. package/dist/math/aabb.d.ts +13 -0
  28. package/dist/math/aabb.js +78 -0
  29. package/dist/math/affine.d.ts +28 -0
  30. package/dist/math/affine.js +159 -0
  31. package/dist/math/affine64.d.ts +11 -0
  32. package/dist/math/affine64.js +58 -0
  33. package/dist/math/frustum.d.ts +11 -0
  34. package/dist/math/frustum.js +59 -0
  35. package/dist/math/hash.d.ts +14 -0
  36. package/dist/math/hash.js +38 -0
  37. package/dist/math/index.d.ts +14 -0
  38. package/dist/math/index.js +33 -0
  39. package/dist/math/mat3.d.ts +6 -0
  40. package/dist/math/mat3.js +37 -0
  41. package/dist/math/mat4.d.ts +23 -0
  42. package/dist/math/mat4.js +224 -0
  43. package/dist/math/quat.d.ts +22 -0
  44. package/dist/math/quat.js +233 -0
  45. package/dist/math/ray.d.ts +10 -0
  46. package/dist/math/ray.js +54 -0
  47. package/dist/math/rng.d.ts +41 -0
  48. package/dist/math/rng.js +102 -0
  49. package/dist/math/types.d.ts +8 -0
  50. package/dist/math/types.js +4 -0
  51. package/dist/math/vec2.d.ts +11 -0
  52. package/dist/math/vec2.js +52 -0
  53. package/dist/math/vec3.d.ts +23 -0
  54. package/dist/math/vec3.js +135 -0
  55. package/dist/math/vec4.d.ts +8 -0
  56. package/dist/math/vec4.js +47 -0
  57. package/dist/scheduler/index.d.ts +3 -0
  58. package/dist/scheduler/index.js +39 -0
  59. package/dist/scheduler/profiler.d.ts +19 -0
  60. package/dist/scheduler/profiler.js +44 -0
  61. package/dist/scheduler/schedule.d.ts +52 -0
  62. package/dist/scheduler/schedule.js +235 -0
  63. package/dist/scheduler/system.d.ts +74 -0
  64. package/dist/scheduler/system.js +106 -0
  65. package/dist/schema/color.d.ts +7 -0
  66. package/dist/schema/color.js +34 -0
  67. package/dist/schema/component.d.ts +71 -0
  68. package/dist/schema/component.js +120 -0
  69. package/dist/schema/field.d.ts +145 -0
  70. package/dist/schema/field.js +591 -0
  71. package/dist/schema/index.d.ts +6 -0
  72. package/dist/schema/index.js +40 -0
  73. package/dist/schema/names.d.ts +27 -0
  74. package/dist/schema/names.js +39 -0
  75. package/dist/schema/registry.d.ts +38 -0
  76. package/dist/schema/registry.js +58 -0
  77. package/dist/schema/resource.d.ts +48 -0
  78. package/dist/schema/resource.js +79 -0
  79. package/dist/test-env.d.ts +31 -0
  80. package/dist/test-env.js +37 -0
  81. package/package.json +38 -0
@@ -0,0 +1,78 @@
1
+ const create = () => empty(new Float32Array(6));
2
+ function empty(out) {
3
+ out[0] = out[1] = out[2] = Infinity;
4
+ out[3] = out[4] = out[5] = -Infinity;
5
+ return out;
6
+ }
7
+ function set(out, min, max) {
8
+ out[0] = min[0];
9
+ out[1] = min[1];
10
+ out[2] = min[2];
11
+ out[3] = max[0];
12
+ out[4] = max[1];
13
+ out[5] = max[2];
14
+ return out;
15
+ }
16
+ function fromPoints(out, positions, stride = 3) {
17
+ empty(out);
18
+ for (let i = 0; i + 2 < positions.length; i += stride) {
19
+ const x = positions[i];
20
+ const y = positions[i + 1];
21
+ const z = positions[i + 2];
22
+ if (x < out[0]) out[0] = x;
23
+ if (y < out[1]) out[1] = y;
24
+ if (z < out[2]) out[2] = z;
25
+ if (x > out[3]) out[3] = x;
26
+ if (y > out[4]) out[4] = y;
27
+ if (z > out[5]) out[5] = z;
28
+ }
29
+ return out;
30
+ }
31
+ function transformAffineAt(out, box, m, mo) {
32
+ const minX = box[0];
33
+ const minY = box[1];
34
+ const minZ = box[2];
35
+ const maxX = box[3];
36
+ const maxY = box[4];
37
+ const maxZ = box[5];
38
+ for (let r = 0; r < 3; r++) {
39
+ let lo = m[mo + r * 4 + 3];
40
+ let hi = lo;
41
+ const ex = m[mo + r * 4];
42
+ const ey = m[mo + r * 4 + 1];
43
+ const ez = m[mo + r * 4 + 2];
44
+ const ax = ex * minX;
45
+ const bx = ex * maxX;
46
+ const ay = ey * minY;
47
+ const by = ey * maxY;
48
+ const az = ez * minZ;
49
+ const bz = ez * maxZ;
50
+ lo += Math.min(ax, bx) + Math.min(ay, by) + Math.min(az, bz);
51
+ hi += Math.max(ax, bx) + Math.max(ay, by) + Math.max(az, bz);
52
+ out[r] = lo;
53
+ out[r + 3] = hi;
54
+ }
55
+ return out;
56
+ }
57
+ function center(out, box) {
58
+ out[0] = (box[0] + box[3]) / 2;
59
+ out[1] = (box[1] + box[4]) / 2;
60
+ out[2] = (box[2] + box[5]) / 2;
61
+ return out;
62
+ }
63
+ function intersects(a, b) {
64
+ return a[0] <= b[3] && a[3] >= b[0] && a[1] <= b[4] && a[4] >= b[1] && a[2] <= b[5] && a[5] >= b[2];
65
+ }
66
+ function containsPoint(box, p) {
67
+ return p[0] >= box[0] && p[0] <= box[3] && p[1] >= box[1] && p[1] <= box[4] && p[2] >= box[2] && p[2] <= box[5];
68
+ }
69
+ export {
70
+ center,
71
+ containsPoint,
72
+ create,
73
+ empty,
74
+ fromPoints,
75
+ intersects,
76
+ set,
77
+ transformAffineAt
78
+ };
@@ -0,0 +1,28 @@
1
+ import type { Readable, Writable } from './types.js';
2
+ /**
3
+ * Affine transforms stored as the top three rows of a 4x4 matrix, row by row (12 floats):
4
+ * `[m00 m01 m02 tx, m10 m11 m12 ty, m20 m21 m22 tz]`. The implied fourth row is `0 0 0 1`.
5
+ * In WGSL this is `array<vec4f, 3>`, and a point transforms with three dot products.
6
+ *
7
+ * `*At` variants read and write at offsets, for strided ECS columns.
8
+ */
9
+ export declare const create: () => Float32Array;
10
+ export declare function identityAt<T extends Writable>(out: T, o: number): T;
11
+ export declare const identity: <T extends Writable>(out: T) => T;
12
+ export declare function copyAt<T extends Writable>(out: T, o: number, a: Readable, ao: number): T;
13
+ /** Translation · rotation · scale, from values at offsets (t: vec3, q: quat, s: vec3). */
14
+ export declare function fromTRSAt<T extends Writable>(out: T, o: number, t: Readable, to: number, q: Readable, qo: number, s: Readable, so: number): T;
15
+ export declare const fromTRS: <T extends Writable>(out: T, t: Readable, q: Readable, s: Readable) => T;
16
+ /** out = a · b, at offsets. `out` may alias `b` but not `a`. */
17
+ export declare function multiplyAt<T extends Writable>(out: T, o: number, a: Readable, ao: number, b: Readable, bo: number): T;
18
+ export declare const multiply: <T extends Writable>(out: T, a: Readable, b: Readable) => T;
19
+ /** Inverse of an affine transform. Returns null for singular transforms. */
20
+ export declare function invert<T extends Writable>(out: T, a: Readable): T | null;
21
+ export declare function transformPointAt<T extends Writable>(out: T, a: Readable, ao: number, p: Readable): T;
22
+ export declare const transformPoint: <T extends Writable>(out: T, a: Readable, p: Readable) => T;
23
+ export declare function getTranslationAt<T extends Writable>(out: T, a: Readable, ao: number): T;
24
+ /** Expands to a column-major mat4. */
25
+ export declare function toMat4At<T extends Writable>(out: T, a: Readable, ao: number): T;
26
+ export declare const toMat4: <T extends Writable>(out: T, a: Readable) => T;
27
+ /** Takes the top three rows of a column-major mat4 (drops any projective part). */
28
+ export declare function fromMat4<T extends Writable>(out: T, m: Readable): T;
@@ -0,0 +1,159 @@
1
+ const create = () => identity(new Float32Array(12));
2
+ function identityAt(out, o) {
3
+ for (let i = 0; i < 12; i++) out[o + i] = 0;
4
+ out[o] = 1;
5
+ out[o + 5] = 1;
6
+ out[o + 10] = 1;
7
+ return out;
8
+ }
9
+ const identity = (out) => identityAt(out, 0);
10
+ function copyAt(out, o, a, ao) {
11
+ for (let i = 0; i < 12; i++) out[o + i] = a[ao + i];
12
+ return out;
13
+ }
14
+ function fromTRSAt(out, o, t, to, q, qo, s, so) {
15
+ const x = q[qo];
16
+ const y = q[qo + 1];
17
+ const z = q[qo + 2];
18
+ const w = q[qo + 3];
19
+ const sx = s[so];
20
+ const sy = s[so + 1];
21
+ const sz = s[so + 2];
22
+ const xx = x * x;
23
+ const yy = y * y;
24
+ const zz = z * z;
25
+ const xy = x * y;
26
+ const xz = x * z;
27
+ const yz = y * z;
28
+ const wx = w * x;
29
+ const wy = w * y;
30
+ const wz = w * z;
31
+ out[o] = (1 - 2 * (yy + zz)) * sx;
32
+ out[o + 1] = 2 * (xy - wz) * sy;
33
+ out[o + 2] = 2 * (xz + wy) * sz;
34
+ out[o + 3] = t[to];
35
+ out[o + 4] = 2 * (xy + wz) * sx;
36
+ out[o + 5] = (1 - 2 * (xx + zz)) * sy;
37
+ out[o + 6] = 2 * (yz - wx) * sz;
38
+ out[o + 7] = t[to + 1];
39
+ out[o + 8] = 2 * (xz - wy) * sx;
40
+ out[o + 9] = 2 * (yz + wx) * sy;
41
+ out[o + 10] = (1 - 2 * (xx + yy)) * sz;
42
+ out[o + 11] = t[to + 2];
43
+ return out;
44
+ }
45
+ const fromTRS = (out, t, q, s) => fromTRSAt(out, 0, t, 0, q, 0, s, 0);
46
+ function multiplyAt(out, o, a, ao, b, bo) {
47
+ const b00 = b[bo];
48
+ const b01 = b[bo + 1];
49
+ const b02 = b[bo + 2];
50
+ const b03 = b[bo + 3];
51
+ const b10 = b[bo + 4];
52
+ const b11 = b[bo + 5];
53
+ const b12 = b[bo + 6];
54
+ const b13 = b[bo + 7];
55
+ const b20 = b[bo + 8];
56
+ const b21 = b[bo + 9];
57
+ const b22 = b[bo + 10];
58
+ const b23 = b[bo + 11];
59
+ for (let r = 0; r < 3; r++) {
60
+ const a0 = a[ao + r * 4];
61
+ const a1 = a[ao + r * 4 + 1];
62
+ const a2 = a[ao + r * 4 + 2];
63
+ const a3 = a[ao + r * 4 + 3];
64
+ out[o + r * 4] = a0 * b00 + a1 * b10 + a2 * b20;
65
+ out[o + r * 4 + 1] = a0 * b01 + a1 * b11 + a2 * b21;
66
+ out[o + r * 4 + 2] = a0 * b02 + a1 * b12 + a2 * b22;
67
+ out[o + r * 4 + 3] = a0 * b03 + a1 * b13 + a2 * b23 + a3;
68
+ }
69
+ return out;
70
+ }
71
+ const multiply = (out, a, b) => multiplyAt(out, 0, a, 0, b, 0);
72
+ function invert(out, a) {
73
+ const a00 = a[0];
74
+ const a01 = a[1];
75
+ const a02 = a[2];
76
+ const a10 = a[4];
77
+ const a11 = a[5];
78
+ const a12 = a[6];
79
+ const a20 = a[8];
80
+ const a21 = a[9];
81
+ const a22 = a[10];
82
+ const tx = a[3];
83
+ const ty = a[7];
84
+ const tz = a[11];
85
+ const c00 = a11 * a22 - a12 * a21;
86
+ const c01 = a02 * a21 - a01 * a22;
87
+ const c02 = a01 * a12 - a02 * a11;
88
+ const det = a00 * c00 + a10 * c01 + a20 * c02;
89
+ if (!det) return null;
90
+ const inv = 1 / det;
91
+ const i00 = c00 * inv;
92
+ const i01 = c01 * inv;
93
+ const i02 = c02 * inv;
94
+ const i10 = (a12 * a20 - a10 * a22) * inv;
95
+ const i11 = (a00 * a22 - a02 * a20) * inv;
96
+ const i12 = (a02 * a10 - a00 * a12) * inv;
97
+ const i20 = (a10 * a21 - a11 * a20) * inv;
98
+ const i21 = (a01 * a20 - a00 * a21) * inv;
99
+ const i22 = (a00 * a11 - a01 * a10) * inv;
100
+ out[0] = i00;
101
+ out[1] = i01;
102
+ out[2] = i02;
103
+ out[3] = -(i00 * tx + i01 * ty + i02 * tz);
104
+ out[4] = i10;
105
+ out[5] = i11;
106
+ out[6] = i12;
107
+ out[7] = -(i10 * tx + i11 * ty + i12 * tz);
108
+ out[8] = i20;
109
+ out[9] = i21;
110
+ out[10] = i22;
111
+ out[11] = -(i20 * tx + i21 * ty + i22 * tz);
112
+ return out;
113
+ }
114
+ function transformPointAt(out, a, ao, p) {
115
+ const x = p[0];
116
+ const y = p[1];
117
+ const z = p[2];
118
+ out[0] = a[ao] * x + a[ao + 1] * y + a[ao + 2] * z + a[ao + 3];
119
+ out[1] = a[ao + 4] * x + a[ao + 5] * y + a[ao + 6] * z + a[ao + 7];
120
+ out[2] = a[ao + 8] * x + a[ao + 9] * y + a[ao + 10] * z + a[ao + 11];
121
+ return out;
122
+ }
123
+ const transformPoint = (out, a, p) => transformPointAt(out, a, 0, p);
124
+ function getTranslationAt(out, a, ao) {
125
+ out[0] = a[ao + 3];
126
+ out[1] = a[ao + 7];
127
+ out[2] = a[ao + 11];
128
+ return out;
129
+ }
130
+ function toMat4At(out, a, ao) {
131
+ for (let r = 0; r < 3; r++) for (let c = 0; c < 4; c++) out[c * 4 + r] = a[ao + r * 4 + c];
132
+ out[3] = 0;
133
+ out[7] = 0;
134
+ out[11] = 0;
135
+ out[15] = 1;
136
+ return out;
137
+ }
138
+ const toMat4 = (out, a) => toMat4At(out, a, 0);
139
+ function fromMat4(out, m) {
140
+ for (let r = 0; r < 3; r++) for (let c = 0; c < 4; c++) out[r * 4 + c] = m[c * 4 + r];
141
+ return out;
142
+ }
143
+ export {
144
+ copyAt,
145
+ create,
146
+ fromMat4,
147
+ fromTRS,
148
+ fromTRSAt,
149
+ getTranslationAt,
150
+ identity,
151
+ identityAt,
152
+ invert,
153
+ multiply,
154
+ multiplyAt,
155
+ toMat4,
156
+ toMat4At,
157
+ transformPoint,
158
+ transformPointAt
159
+ };
@@ -0,0 +1,11 @@
1
+ import type { Readable, Writable } from './types.js';
2
+ /**
3
+ * The `affine` functions on `Float64Array`, for the few places that need positions beyond f32
4
+ * precision (large-world grids, spec 0040). Same layout: the top three rows of a 4x4, row by row.
5
+ */
6
+ export { copyAt, fromMat4, fromTRS, fromTRSAt, getTranslationAt, identity, identityAt, invert, multiply, multiplyAt, toMat4, toMat4At, transformPoint, transformPointAt, } from './affine.js';
7
+ export declare const create: () => Float64Array;
8
+ /** out = a · translation(x, y, z). `out` may alias `a`. */
9
+ export declare function translateAt<T extends Writable>(out: T, o: number, a: Readable, ao: number, x: number, y: number, z: number): T;
10
+ /** Rotates and scales a direction (no translation). */
11
+ export declare function transformVectorAt<T extends Writable>(out: T, a: Readable, ao: number, v: Readable): T;
@@ -0,0 +1,58 @@
1
+ import { identity } from "./affine.js";
2
+ import {
3
+ copyAt,
4
+ fromMat4,
5
+ fromTRS,
6
+ fromTRSAt,
7
+ getTranslationAt,
8
+ identity as identity2,
9
+ identityAt,
10
+ invert,
11
+ multiply,
12
+ multiplyAt,
13
+ toMat4,
14
+ toMat4At,
15
+ transformPoint,
16
+ transformPointAt
17
+ } from "./affine.js";
18
+ const create = () => identity(new Float64Array(12));
19
+ function translateAt(out, o, a, ao, x, y, z) {
20
+ for (let r = 0; r < 3; r++) {
21
+ const a0 = a[ao + r * 4];
22
+ const a1 = a[ao + r * 4 + 1];
23
+ const a2 = a[ao + r * 4 + 2];
24
+ out[o + r * 4] = a0;
25
+ out[o + r * 4 + 1] = a1;
26
+ out[o + r * 4 + 2] = a2;
27
+ out[o + r * 4 + 3] = a0 * x + a1 * y + a2 * z + a[ao + r * 4 + 3];
28
+ }
29
+ return out;
30
+ }
31
+ function transformVectorAt(out, a, ao, v) {
32
+ const x = v[0];
33
+ const y = v[1];
34
+ const z = v[2];
35
+ out[0] = a[ao] * x + a[ao + 1] * y + a[ao + 2] * z;
36
+ out[1] = a[ao + 4] * x + a[ao + 5] * y + a[ao + 6] * z;
37
+ out[2] = a[ao + 8] * x + a[ao + 9] * y + a[ao + 10] * z;
38
+ return out;
39
+ }
40
+ export {
41
+ copyAt,
42
+ create,
43
+ fromMat4,
44
+ fromTRS,
45
+ fromTRSAt,
46
+ getTranslationAt,
47
+ identity2 as identity,
48
+ identityAt,
49
+ invert,
50
+ multiply,
51
+ multiplyAt,
52
+ toMat4,
53
+ toMat4At,
54
+ transformPoint,
55
+ transformPointAt,
56
+ transformVectorAt,
57
+ translateAt
58
+ };
@@ -0,0 +1,11 @@
1
+ import type { Readable, Writable } from './types.js';
2
+ /**
3
+ * Six planes as 24 floats `(nx, ny, nz, d)`, inside where `n · p + d >= 0`. Order: left, right,
4
+ * bottom, top, near, far. Works for standard and reversed-Z projections; a degenerate plane (the
5
+ * infinite far plane) always passes.
6
+ */
7
+ export declare const create: () => Float32Array;
8
+ export declare function fromViewProjection<T extends Writable>(out: T, m: Readable): T;
9
+ /** True if the box is at least partly inside (conservative: may keep boxes near corners). */
10
+ export declare function intersectsAabbAt(f: Readable, box: Readable, bo: number): boolean;
11
+ export declare const intersectsAabb: (f: Readable, box: Readable) => boolean;
@@ -0,0 +1,59 @@
1
+ const create = () => new Float32Array(24);
2
+ function fromViewProjection(out, m) {
3
+ for (let p = 0; p < 6; p++) {
4
+ const axis = p >> 1;
5
+ const sign = p & 1 ? -1 : 1;
6
+ let a;
7
+ let b;
8
+ let c;
9
+ let d;
10
+ if (axis < 2) {
11
+ a = m[3] + sign * m[axis];
12
+ b = m[7] + sign * m[4 + axis];
13
+ c = m[11] + sign * m[8 + axis];
14
+ d = m[15] + sign * m[12 + axis];
15
+ } else if (sign > 0) {
16
+ a = m[2];
17
+ b = m[6];
18
+ c = m[10];
19
+ d = m[14];
20
+ } else {
21
+ a = m[3] - m[2];
22
+ b = m[7] - m[6];
23
+ c = m[11] - m[10];
24
+ d = m[15] - m[14];
25
+ }
26
+ const len = Math.sqrt(a * a + b * b + c * c);
27
+ if (len < 1e-12) {
28
+ out[p * 4] = 0;
29
+ out[p * 4 + 1] = 0;
30
+ out[p * 4 + 2] = 0;
31
+ out[p * 4 + 3] = 1;
32
+ } else {
33
+ out[p * 4] = a / len;
34
+ out[p * 4 + 1] = b / len;
35
+ out[p * 4 + 2] = c / len;
36
+ out[p * 4 + 3] = d / len;
37
+ }
38
+ }
39
+ return out;
40
+ }
41
+ function intersectsAabbAt(f, box, bo) {
42
+ for (let p = 0; p < 24; p += 4) {
43
+ const nx = f[p];
44
+ const ny = f[p + 1];
45
+ const nz = f[p + 2];
46
+ const x = nx >= 0 ? box[bo + 3] : box[bo];
47
+ const y = ny >= 0 ? box[bo + 4] : box[bo + 1];
48
+ const z = nz >= 0 ? box[bo + 5] : box[bo + 2];
49
+ if (nx * x + ny * y + nz * z + f[p + 3] < 0) return false;
50
+ }
51
+ return true;
52
+ }
53
+ const intersectsAabb = (f, box) => intersectsAabbAt(f, box, 0);
54
+ export {
55
+ create,
56
+ fromViewProjection,
57
+ intersectsAabb,
58
+ intersectsAabbAt
59
+ };
@@ -0,0 +1,14 @@
1
+ /**
2
+ * A child seed from a seed and a label: how `Rng.fork`, noise sources, and generators derive seeds.
3
+ * Numeric labels hash as four bytes, so the noise kernel and WGSL compute the same value.
4
+ */
5
+ export declare function hashSeed(seed: number, label: string | number): number;
6
+ /** lowbias32 (Chris Wellons): a well-mixed 32-bit finalizer. */
7
+ export declare function mix32(h: number): number;
8
+ /** Primes the noise kernel multiplies lattice coordinates by before mixing. */
9
+ export declare const LATTICE_PRIMES: readonly [501125321, 1136930381, 1720413743, 1066037191];
10
+ /**
11
+ * The noise kernel's lattice hash of an integer cell under a seed, as an unsigned 32-bit number:
12
+ * the same value a noise source hashes for that cell. Generators use it for per-cell decisions.
13
+ */
14
+ export declare function hash32(seed: number, x: number, y?: number, z?: number, w?: number): number;
@@ -0,0 +1,38 @@
1
+ function fnv(h, unit) {
2
+ return Math.imul(h ^ unit, 16777619);
3
+ }
4
+ function hashLabel(label) {
5
+ let h = 2166136261;
6
+ if (typeof label === "string") {
7
+ for (let i = 0; i < label.length; i++) h = fnv(h, label.charCodeAt(i));
8
+ } else {
9
+ h = fnv(h, label & 255);
10
+ h = fnv(h, label >>> 8 & 255);
11
+ h = fnv(h, label >>> 16 & 255);
12
+ h = fnv(h, label >>> 24);
13
+ }
14
+ return h;
15
+ }
16
+ function hashSeed(seed, label) {
17
+ const h = hashLabel(label);
18
+ return (Math.imul((seed ^ h) >>> 0, 2654435761) ^ fnv(h, 35)) >>> 0;
19
+ }
20
+ function mix32(h) {
21
+ h ^= h >>> 16;
22
+ h = Math.imul(h, 2146121005);
23
+ h ^= h >>> 15;
24
+ h = Math.imul(h, 2221713035);
25
+ return (h ^ h >>> 16) >>> 0;
26
+ }
27
+ const LATTICE_PRIMES = [501125321, 1136930381, 1720413743, 1066037191];
28
+ function hash32(seed, x, y = 0, z = 0, w = 0) {
29
+ return mix32(
30
+ seed ^ Math.imul(x, LATTICE_PRIMES[0]) ^ Math.imul(y, LATTICE_PRIMES[1]) ^ Math.imul(z, LATTICE_PRIMES[2]) ^ Math.imul(w, LATTICE_PRIMES[3])
31
+ );
32
+ }
33
+ export {
34
+ LATTICE_PRIMES,
35
+ hash32,
36
+ hashSeed,
37
+ mix32
38
+ };
@@ -0,0 +1,14 @@
1
+ export * as aabb from './aabb.js';
2
+ export * as affine from './affine.js';
3
+ export * as affine64 from './affine64.js';
4
+ export * as frustum from './frustum.js';
5
+ export { hash32, hashSeed, LATTICE_PRIMES, mix32 } from './hash.js';
6
+ export * as mat3 from './mat3.js';
7
+ export * as mat4 from './mat4.js';
8
+ export * as quat from './quat.js';
9
+ export * as ray from './ray.js';
10
+ export { Rng } from './rng.js';
11
+ export { EPSILON, type Readable, type Writable } from './types.js';
12
+ export * as vec2 from './vec2.js';
13
+ export * as vec3 from './vec3.js';
14
+ export * as vec4 from './vec4.js';
@@ -0,0 +1,33 @@
1
+ import * as aabb from "./aabb.js";
2
+ import * as affine from "./affine.js";
3
+ import * as affine64 from "./affine64.js";
4
+ import * as frustum from "./frustum.js";
5
+ import { hash32, hashSeed, LATTICE_PRIMES, mix32 } from "./hash.js";
6
+ import * as mat3 from "./mat3.js";
7
+ import * as mat4 from "./mat4.js";
8
+ import * as quat from "./quat.js";
9
+ import * as ray from "./ray.js";
10
+ import { Rng } from "./rng.js";
11
+ import { EPSILON } from "./types.js";
12
+ import * as vec2 from "./vec2.js";
13
+ import * as vec3 from "./vec3.js";
14
+ import * as vec4 from "./vec4.js";
15
+ export {
16
+ EPSILON,
17
+ LATTICE_PRIMES,
18
+ Rng,
19
+ aabb,
20
+ affine,
21
+ affine64,
22
+ frustum,
23
+ hash32,
24
+ hashSeed,
25
+ mat3,
26
+ mat4,
27
+ mix32,
28
+ quat,
29
+ ray,
30
+ vec2,
31
+ vec3,
32
+ vec4
33
+ };
@@ -0,0 +1,6 @@
1
+ import type { Readable, Writable } from './types.js';
2
+ /** Column-major 3x3: element (row r, column c) at index c * 3 + r. */
3
+ export declare const create: () => Float32Array;
4
+ export declare function identity<T extends Writable>(out: T): T;
5
+ /** Inverse transpose of an affine transform's 3x3 part: transforms normals correctly under scale. */
6
+ export declare function normalFromAffineAt<T extends Writable>(out: T, a: Readable, ao: number): T | null;
@@ -0,0 +1,37 @@
1
+ const create = () => identity(new Float32Array(9));
2
+ function identity(out) {
3
+ for (let i = 0; i < 9; i++) out[i] = i % 4 === 0 ? 1 : 0;
4
+ return out;
5
+ }
6
+ function normalFromAffineAt(out, a, ao) {
7
+ const a00 = a[ao];
8
+ const a01 = a[ao + 1];
9
+ const a02 = a[ao + 2];
10
+ const a10 = a[ao + 4];
11
+ const a11 = a[ao + 5];
12
+ const a12 = a[ao + 6];
13
+ const a20 = a[ao + 8];
14
+ const a21 = a[ao + 9];
15
+ const a22 = a[ao + 10];
16
+ const c00 = a11 * a22 - a12 * a21;
17
+ const c01 = a12 * a20 - a10 * a22;
18
+ const c02 = a10 * a21 - a11 * a20;
19
+ const det = a00 * c00 + a01 * c01 + a02 * c02;
20
+ if (!det) return null;
21
+ const inv = 1 / det;
22
+ out[0] = c00 * inv;
23
+ out[1] = (a02 * a21 - a01 * a22) * inv;
24
+ out[2] = (a01 * a12 - a02 * a11) * inv;
25
+ out[3] = c01 * inv;
26
+ out[4] = (a00 * a22 - a02 * a20) * inv;
27
+ out[5] = (a02 * a10 - a00 * a12) * inv;
28
+ out[6] = c02 * inv;
29
+ out[7] = (a01 * a20 - a00 * a21) * inv;
30
+ out[8] = (a00 * a11 - a01 * a10) * inv;
31
+ return out;
32
+ }
33
+ export {
34
+ create,
35
+ identity,
36
+ normalFromAffineAt
37
+ };
@@ -0,0 +1,23 @@
1
+ import type { Readable, Writable } from './types.js';
2
+ /** Column-major 4x4: element (row r, column c) is at index c * 4 + r. */
3
+ export declare const create: () => Float32Array;
4
+ export declare function identity<T extends Writable>(out: T): T;
5
+ export declare function copy<T extends Writable>(out: T, a: Readable): T;
6
+ /** out = a · b */
7
+ export declare function multiply<T extends Writable>(out: T, a: Readable, b: Readable): T;
8
+ export declare function transpose<T extends Writable>(out: T, a: Readable): T;
9
+ /** General inverse. Returns null (and leaves `out` untouched) for singular matrices. */
10
+ export declare function invert<T extends Writable>(out: T, a: Readable): T | null;
11
+ /** Translation · rotation · scale. */
12
+ export declare function fromTRS<T extends Writable>(out: T, t: Readable, q: Readable, s: Readable): T;
13
+ export declare function getTranslation<T extends Writable>(out: T, m: Readable): T;
14
+ /** Perspective projection with WebGPU 0..1 depth (near → 0, far → 1). */
15
+ export declare function perspective<T extends Writable>(out: T, fovY: number, aspect: number, near: number, far: number): T;
16
+ /** Reversed-Z perspective with an infinite far plane: near → 1, infinity → 0. */
17
+ export declare function perspectiveReversedZ<T extends Writable>(out: T, fovY: number, aspect: number, near: number): T;
18
+ /** Orthographic projection with WebGPU 0..1 depth (near → 0, far → 1). */
19
+ export declare function orthographic<T extends Writable>(out: T, left: number, right: number, bottom: number, top: number, near: number, far: number): T;
20
+ /** Reversed-Z orthographic: near → 1, far → 0. */
21
+ export declare function orthographicReversedZ<T extends Writable>(out: T, left: number, right: number, bottom: number, top: number, near: number, far: number): T;
22
+ /** View matrix for a camera at `eye` looking at `target`. */
23
+ export declare function lookAt<T extends Writable>(out: T, eye: Readable, target: Readable, up: Readable): T;