@series-inc/rundot-syncplay 5.23.0-beta.7 → 5.23.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/README.md +116 -15
- package/dist/browser.d.ts +87 -55
- package/dist/browser.js +47 -52
- package/dist/certification.d.ts +32 -3
- package/dist/certification.js +88 -3
- package/dist/cjs/browser.js +259 -87
- package/dist/cjs/certification.js +87 -2
- package/dist/cjs/collision.js +58 -0
- package/dist/cjs/creator.js +2 -1
- package/dist/cjs/engine-complete.js +213 -3
- package/dist/cjs/engine-parity-matrix.js +19 -4
- package/dist/cjs/index.js +199 -132
- package/dist/cjs/math.js +342 -15
- package/dist/cjs/movement3d.js +230 -1
- package/dist/cjs/node.js +5 -1
- package/dist/cjs/noise.js +58 -0
- package/dist/cjs/physics-cert.js +147 -6
- package/dist/cjs/physics2d.js +10 -4
- package/dist/cjs/physics3d-joints.js +637 -0
- package/dist/cjs/physics3d-shared.js +288 -0
- package/dist/cjs/physics3d-solver.js +1351 -0
- package/dist/cjs/physics3d-vehicle.js +467 -0
- package/dist/cjs/physics3d.js +1057 -223
- package/dist/cjs/random.js +49 -0
- package/dist/cjs/replay-bundle.js +127 -20
- package/dist/cjs/sample-scenes.js +3 -0
- package/dist/cjs/sdk-offline.js +6 -32
- package/dist/cjs/sdk-session.js +156 -0
- package/dist/cjs/session-build.js +42 -0
- package/dist/cjs/testing.js +107 -0
- package/dist/cli.js +40 -12
- package/dist/collision.d.ts +12 -0
- package/dist/collision.js +52 -0
- package/dist/creator.d.ts +1 -1
- package/dist/creator.js +1 -1
- package/dist/engine-complete.js +214 -4
- package/dist/engine-parity-matrix.js +19 -4
- package/dist/index.d.ts +94 -89
- package/dist/index.js +45 -56
- package/dist/math.d.ts +59 -6
- package/dist/math.js +342 -15
- package/dist/movement3d.d.ts +73 -0
- package/dist/movement3d.js +229 -1
- package/dist/node.d.ts +4 -0
- package/dist/node.js +2 -0
- package/dist/noise.d.ts +7 -0
- package/dist/noise.js +51 -0
- package/dist/physics-cert.d.ts +1 -1
- package/dist/physics-cert.js +147 -6
- package/dist/physics2d.js +10 -4
- package/dist/physics3d-joints.d.ts +94 -0
- package/dist/physics3d-joints.js +634 -0
- package/dist/physics3d-shared.d.ts +72 -0
- package/dist/physics3d-shared.js +257 -0
- package/dist/physics3d-solver.d.ts +197 -0
- package/dist/physics3d-solver.js +1346 -0
- package/dist/physics3d-vehicle.d.ts +84 -0
- package/dist/physics3d-vehicle.js +463 -0
- package/dist/physics3d.d.ts +108 -8
- package/dist/physics3d.js +1006 -177
- package/dist/random.d.ts +7 -0
- package/dist/random.js +49 -0
- package/dist/replay-bundle.d.ts +40 -1
- package/dist/replay-bundle.js +126 -20
- package/dist/sample-scenes.js +3 -0
- package/dist/sdk-offline.js +6 -32
- package/dist/sdk-session.d.ts +47 -0
- package/dist/sdk-session.js +153 -0
- package/dist/session-build.d.ts +21 -0
- package/dist/session-build.js +39 -0
- package/dist/testing.d.ts +52 -0
- package/dist/testing.js +45 -0
- package/dist/tools/vite-plugin.d.ts +8 -0
- package/dist/tools/vite-plugin.js +63 -9
- package/package.json +11 -3
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Leaf numeric kernel + vector/quaternion/matrix helpers for the deterministic
|
|
4
|
+
* rigid-body solver. This module imports nothing package-local so `physics3d`,
|
|
5
|
+
* `physics3d-solver`, and `physics3d-joints` can all depend on it in one
|
|
6
|
+
* direction with no ESM cycle.
|
|
7
|
+
*
|
|
8
|
+
* Determinism regime: plain IEEE doubles restricted to `+ - * /` plus integer
|
|
9
|
+
* rounding/abs/min/max/trunc (no transcendental library calls — the static
|
|
10
|
+
* checker bans the square-root/power/trig family). Square roots go through
|
|
11
|
+
* `deterministicSqrt` (quantized, for persisted distances) or `solverSqrt`
|
|
12
|
+
* (unquantized Newton, for solver-internal math — state is quantized only at the
|
|
13
|
+
* frame edge, never mid-solve).
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.quantizeDistance = quantizeDistance;
|
|
17
|
+
exports.quantizeAngle = quantizeAngle;
|
|
18
|
+
exports.deterministicSqrt = deterministicSqrt;
|
|
19
|
+
exports.solverSqrt = solverSqrt;
|
|
20
|
+
exports.vec3 = vec3;
|
|
21
|
+
exports.addVec3 = addVec3;
|
|
22
|
+
exports.subVec3 = subVec3;
|
|
23
|
+
exports.scaleVec3 = scaleVec3;
|
|
24
|
+
exports.dotVec3 = dotVec3;
|
|
25
|
+
exports.crossVec3 = crossVec3;
|
|
26
|
+
exports.lengthVec3 = lengthVec3;
|
|
27
|
+
exports.normalizeVec3 = normalizeVec3;
|
|
28
|
+
exports.quatToMat3 = quatToMat3;
|
|
29
|
+
exports.mulMat3Vec = mulMat3Vec;
|
|
30
|
+
exports.mulMat3TransposeVec = mulMat3TransposeVec;
|
|
31
|
+
exports.worldInvInertia = worldInvInertia;
|
|
32
|
+
exports.integrateQuat = integrateQuat;
|
|
33
|
+
exports.normalizeQuat = normalizeQuat;
|
|
34
|
+
exports.quatConjugate = quatConjugate;
|
|
35
|
+
exports.quatMultiply = quatMultiply;
|
|
36
|
+
exports.quaternionFromQuarterTurns = quaternionFromQuarterTurns;
|
|
37
|
+
exports.rotatePointByQuat = rotatePointByQuat;
|
|
38
|
+
exports.rotatePointByQuatInverse = rotatePointByQuatInverse;
|
|
39
|
+
exports.clampNumber = clampNumber;
|
|
40
|
+
exports.skewMat3 = skewMat3;
|
|
41
|
+
exports.mat3Multiply = mat3Multiply;
|
|
42
|
+
exports.mat3Sub = mat3Sub;
|
|
43
|
+
exports.mat3FromDiag = mat3FromDiag;
|
|
44
|
+
exports.invertMat3 = invertMat3;
|
|
45
|
+
function quantizeDistance(distance) {
|
|
46
|
+
// Pure integer rounding, not fixed-point string rounding — see physics2d
|
|
47
|
+
// quantizeDistance (cross-engine half-way divergence on checksummed state).
|
|
48
|
+
const quantized = Math.round(distance * 1e6) / 1e6;
|
|
49
|
+
return quantized === 0 ? 0 : quantized;
|
|
50
|
+
}
|
|
51
|
+
function quantizeAngle(value) {
|
|
52
|
+
const wrapped = value - Math.floor(value);
|
|
53
|
+
const quantizedAngle = Math.round(wrapped * 1e6) / 1e6;
|
|
54
|
+
return quantizedAngle === 0 ? 0 : quantizedAngle;
|
|
55
|
+
}
|
|
56
|
+
function deterministicSqrt(value) {
|
|
57
|
+
if (value <= 0) {
|
|
58
|
+
return 0;
|
|
59
|
+
}
|
|
60
|
+
let estimate = 1;
|
|
61
|
+
let magnitude = value;
|
|
62
|
+
while (magnitude >= 4) {
|
|
63
|
+
magnitude /= 4;
|
|
64
|
+
estimate *= 2;
|
|
65
|
+
}
|
|
66
|
+
if (magnitude > 1) {
|
|
67
|
+
estimate *= 2;
|
|
68
|
+
}
|
|
69
|
+
for (let iteration = 0; iteration < 8; iteration += 1) {
|
|
70
|
+
estimate = (estimate + value / estimate) / 2;
|
|
71
|
+
}
|
|
72
|
+
return quantizeDistance(estimate);
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Unquantized Newton square root for solver-internal math. Bit-for-bit identical
|
|
76
|
+
* to the seed/iteration schedule the validated spike used; every operation is
|
|
77
|
+
* exactly specified IEEE-754 arithmetic, so all certified V8 peers agree. State
|
|
78
|
+
* that reaches the canonical world is quantized separately at the frame edge.
|
|
79
|
+
*/
|
|
80
|
+
function solverSqrt(value) {
|
|
81
|
+
if (value <= 0) {
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
let estimate = 1;
|
|
85
|
+
let magnitude = value;
|
|
86
|
+
while (magnitude >= 4) {
|
|
87
|
+
magnitude /= 4;
|
|
88
|
+
estimate *= 2;
|
|
89
|
+
}
|
|
90
|
+
if (magnitude > 1) {
|
|
91
|
+
estimate *= 2;
|
|
92
|
+
}
|
|
93
|
+
for (let iteration = 0; iteration < 8; iteration += 1) {
|
|
94
|
+
estimate = (estimate + value / estimate) / 2;
|
|
95
|
+
}
|
|
96
|
+
return estimate;
|
|
97
|
+
}
|
|
98
|
+
function vec3(x, y, z) {
|
|
99
|
+
return { x, y, z };
|
|
100
|
+
}
|
|
101
|
+
function addVec3(a, b) {
|
|
102
|
+
return { x: a.x + b.x, y: a.y + b.y, z: a.z + b.z };
|
|
103
|
+
}
|
|
104
|
+
function subVec3(a, b) {
|
|
105
|
+
return { x: a.x - b.x, y: a.y - b.y, z: a.z - b.z };
|
|
106
|
+
}
|
|
107
|
+
function scaleVec3(a, s) {
|
|
108
|
+
return { x: a.x * s, y: a.y * s, z: a.z * s };
|
|
109
|
+
}
|
|
110
|
+
function dotVec3(a, b) {
|
|
111
|
+
return a.x * b.x + a.y * b.y + a.z * b.z;
|
|
112
|
+
}
|
|
113
|
+
function crossVec3(a, b) {
|
|
114
|
+
return {
|
|
115
|
+
x: a.y * b.z - a.z * b.y,
|
|
116
|
+
y: a.z * b.x - a.x * b.z,
|
|
117
|
+
z: a.x * b.y - a.y * b.x,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function lengthVec3(a) {
|
|
121
|
+
return solverSqrt(dotVec3(a, a));
|
|
122
|
+
}
|
|
123
|
+
function normalizeVec3(a) {
|
|
124
|
+
const length = lengthVec3(a);
|
|
125
|
+
return length === 0 ? { x: 0, y: 0, z: 0 } : scaleVec3(a, 1 / length);
|
|
126
|
+
}
|
|
127
|
+
function quatToMat3(q) {
|
|
128
|
+
const { x, y, z, w } = q;
|
|
129
|
+
return [
|
|
130
|
+
1 - 2 * (y * y + z * z), 2 * (x * y - w * z), 2 * (x * z + w * y),
|
|
131
|
+
2 * (x * y + w * z), 1 - 2 * (x * x + z * z), 2 * (y * z - w * x),
|
|
132
|
+
2 * (x * z - w * y), 2 * (y * z + w * x), 1 - 2 * (x * x + y * y),
|
|
133
|
+
];
|
|
134
|
+
}
|
|
135
|
+
function mulMat3Vec(m, a) {
|
|
136
|
+
return {
|
|
137
|
+
x: m[0] * a.x + m[1] * a.y + m[2] * a.z,
|
|
138
|
+
y: m[3] * a.x + m[4] * a.y + m[5] * a.z,
|
|
139
|
+
z: m[6] * a.x + m[7] * a.y + m[8] * a.z,
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function mulMat3TransposeVec(m, a) {
|
|
143
|
+
return {
|
|
144
|
+
x: m[0] * a.x + m[3] * a.y + m[6] * a.z,
|
|
145
|
+
y: m[1] * a.x + m[4] * a.y + m[7] * a.z,
|
|
146
|
+
z: m[2] * a.x + m[5] * a.y + m[8] * a.z,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/** World-space inverse inertia = R · diag(invI) · Rᵀ. */
|
|
150
|
+
function worldInvInertia(rot, invI) {
|
|
151
|
+
const invIArr = [invI.x, invI.y, invI.z];
|
|
152
|
+
const out = new Array(9).fill(0);
|
|
153
|
+
for (let row = 0; row < 3; row += 1) {
|
|
154
|
+
for (let col = 0; col < 3; col += 1) {
|
|
155
|
+
out[row * 3 + col] =
|
|
156
|
+
rot[row * 3 + 0] * invIArr[0] * rot[col * 3 + 0] +
|
|
157
|
+
rot[row * 3 + 1] * invIArr[1] * rot[col * 3 + 1] +
|
|
158
|
+
rot[row * 3 + 2] * invIArr[2] * rot[col * 3 + 2];
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Trig-free quaternion integration: q += ½·(ω⊗q)·dt, renormalized with
|
|
165
|
+
* `solverSqrt`. Returns a unit quaternion; degenerate inputs collapse to
|
|
166
|
+
* identity so no NaN reaches state.
|
|
167
|
+
*/
|
|
168
|
+
function integrateQuat(q, w, dt) {
|
|
169
|
+
const hx = w.x * 0.5 * dt;
|
|
170
|
+
const hy = w.y * 0.5 * dt;
|
|
171
|
+
const hz = w.z * 0.5 * dt;
|
|
172
|
+
const nx = q.x + (hx * q.w + hy * q.z - hz * q.y);
|
|
173
|
+
const ny = q.y + (hy * q.w + hz * q.x - hx * q.z);
|
|
174
|
+
const nz = q.z + (hz * q.w + hx * q.y - hy * q.x);
|
|
175
|
+
const nw = q.w + (-hx * q.x - hy * q.y - hz * q.z);
|
|
176
|
+
const length = solverSqrt(nx * nx + ny * ny + nz * nz + nw * nw);
|
|
177
|
+
if (length === 0) {
|
|
178
|
+
return { x: 0, y: 0, z: 0, w: 1 };
|
|
179
|
+
}
|
|
180
|
+
return { x: nx / length, y: ny / length, z: nz / length, w: nw / length };
|
|
181
|
+
}
|
|
182
|
+
function normalizeQuat(q) {
|
|
183
|
+
const length = solverSqrt(q.x * q.x + q.y * q.y + q.z * q.z + q.w * q.w);
|
|
184
|
+
if (length === 0) {
|
|
185
|
+
return { x: 0, y: 0, z: 0, w: 1 };
|
|
186
|
+
}
|
|
187
|
+
return { x: q.x / length, y: q.y / length, z: q.z / length, w: q.w / length };
|
|
188
|
+
}
|
|
189
|
+
function quatConjugate(q) {
|
|
190
|
+
return { x: -q.x, y: -q.y, z: -q.z, w: q.w };
|
|
191
|
+
}
|
|
192
|
+
function quatMultiply(a, b) {
|
|
193
|
+
return {
|
|
194
|
+
w: a.w * b.w - a.x * b.x - a.y * b.y - a.z * b.z,
|
|
195
|
+
x: a.w * b.x + a.x * b.w + a.y * b.z - a.z * b.y,
|
|
196
|
+
y: a.w * b.y - a.x * b.z + a.y * b.w + a.z * b.x,
|
|
197
|
+
z: a.w * b.z + a.x * b.y - a.y * b.x + a.z * b.w,
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const QUARTER_ROOT_HALF = solverSqrt(0.5);
|
|
201
|
+
function axisQuarterTurnQuat(axis, turns) {
|
|
202
|
+
const c = ((Math.trunc(turns) % 4) + 4) % 4;
|
|
203
|
+
// half-angle is turns·45°; sin/cos of {0,45,90,135}° are exactly {0/1, ±√½}.
|
|
204
|
+
const table = [
|
|
205
|
+
{ s: 0, w: 1 },
|
|
206
|
+
{ s: QUARTER_ROOT_HALF, w: QUARTER_ROOT_HALF },
|
|
207
|
+
{ s: 1, w: 0 },
|
|
208
|
+
{ s: QUARTER_ROOT_HALF, w: -QUARTER_ROOT_HALF },
|
|
209
|
+
];
|
|
210
|
+
const entry = table[c];
|
|
211
|
+
return {
|
|
212
|
+
x: axis === 0 ? entry.s : 0,
|
|
213
|
+
y: axis === 1 ? entry.s : 0,
|
|
214
|
+
z: axis === 2 ? entry.s : 0,
|
|
215
|
+
w: entry.w,
|
|
216
|
+
};
|
|
217
|
+
}
|
|
218
|
+
/** Compose integer quarter-turn rotations about x, then y, then z into a quaternion. */
|
|
219
|
+
function quaternionFromQuarterTurns(turns) {
|
|
220
|
+
const qx = axisQuarterTurnQuat(0, turns.x);
|
|
221
|
+
const qy = axisQuarterTurnQuat(1, turns.y);
|
|
222
|
+
const qz = axisQuarterTurnQuat(2, turns.z);
|
|
223
|
+
return quatMultiply(quatMultiply(qx, qy), qz);
|
|
224
|
+
}
|
|
225
|
+
/** Rotate a vector by a quaternion using only mul/add/cross (no transcendentals). */
|
|
226
|
+
function rotatePointByQuat(q, p) {
|
|
227
|
+
const u = { x: q.x, y: q.y, z: q.z };
|
|
228
|
+
const t = scaleVec3(crossVec3(u, p), 2);
|
|
229
|
+
return addVec3(addVec3(p, scaleVec3(t, q.w)), crossVec3(u, t));
|
|
230
|
+
}
|
|
231
|
+
/** Rotate a vector by the inverse (conjugate) of a quaternion. */
|
|
232
|
+
function rotatePointByQuatInverse(q, p) {
|
|
233
|
+
return rotatePointByQuat(quatConjugate(q), p);
|
|
234
|
+
}
|
|
235
|
+
function clampNumber(value, lo, hi) {
|
|
236
|
+
return value < lo ? lo : value > hi ? hi : value;
|
|
237
|
+
}
|
|
238
|
+
/** Skew-symmetric (cross-product) matrix of a vector. */
|
|
239
|
+
function skewMat3(v) {
|
|
240
|
+
return [
|
|
241
|
+
0, -v.z, v.y,
|
|
242
|
+
v.z, 0, -v.x,
|
|
243
|
+
-v.y, v.x, 0,
|
|
244
|
+
];
|
|
245
|
+
}
|
|
246
|
+
function mat3Multiply(a, b) {
|
|
247
|
+
const out = new Array(9).fill(0);
|
|
248
|
+
for (let row = 0; row < 3; row += 1) {
|
|
249
|
+
for (let col = 0; col < 3; col += 1) {
|
|
250
|
+
out[row * 3 + col] =
|
|
251
|
+
a[row * 3 + 0] * b[0 * 3 + col] +
|
|
252
|
+
a[row * 3 + 1] * b[1 * 3 + col] +
|
|
253
|
+
a[row * 3 + 2] * b[2 * 3 + col];
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
return out;
|
|
257
|
+
}
|
|
258
|
+
function mat3Sub(a, b) {
|
|
259
|
+
return a.map((value, index) => value - b[index]);
|
|
260
|
+
}
|
|
261
|
+
function mat3FromDiag(d) {
|
|
262
|
+
return [d.x, 0, 0, 0, d.y, 0, 0, 0, d.z];
|
|
263
|
+
}
|
|
264
|
+
/** Invert a 3x3 matrix; returns a zero matrix if singular (deterministic fallback). */
|
|
265
|
+
function invertMat3(m) {
|
|
266
|
+
const a = m[0];
|
|
267
|
+
const b = m[1];
|
|
268
|
+
const c = m[2];
|
|
269
|
+
const d = m[3];
|
|
270
|
+
const e = m[4];
|
|
271
|
+
const f = m[5];
|
|
272
|
+
const g = m[6];
|
|
273
|
+
const h = m[7];
|
|
274
|
+
const i = m[8];
|
|
275
|
+
const co0 = e * i - f * h;
|
|
276
|
+
const co1 = f * g - d * i;
|
|
277
|
+
const co2 = d * h - e * g;
|
|
278
|
+
const det = a * co0 + b * co1 + c * co2;
|
|
279
|
+
if (det === 0) {
|
|
280
|
+
return [0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
281
|
+
}
|
|
282
|
+
const inv = 1 / det;
|
|
283
|
+
return [
|
|
284
|
+
co0 * inv, (c * h - b * i) * inv, (b * f - c * e) * inv,
|
|
285
|
+
co1 * inv, (a * i - c * g) * inv, (c * d - a * f) * inv,
|
|
286
|
+
co2 * inv, (b * g - a * h) * inv, (a * e - b * d) * inv,
|
|
287
|
+
];
|
|
288
|
+
}
|