@flighthq/physics3d 0.4.0-next.1694.598ef6f
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/dist/contacts.d.ts +4 -0
- package/dist/contacts.d.ts.map +1 -0
- package/dist/contacts.js +55 -0
- package/dist/contacts.js.map +1 -0
- package/dist/contract.d.ts +17 -0
- package/dist/contract.d.ts.map +1 -0
- package/dist/contract.js +17 -0
- package/dist/contract.js.map +1 -0
- package/dist/enablePhysics3DGuards.d.ts +4 -0
- package/dist/enablePhysics3DGuards.d.ts.map +1 -0
- package/dist/enablePhysics3DGuards.js +68 -0
- package/dist/enablePhysics3DGuards.js.map +1 -0
- package/dist/explainPhysics3DJoints.d.ts +3 -0
- package/dist/explainPhysics3DJoints.d.ts.map +1 -0
- package/dist/explainPhysics3DJoints.js +32 -0
- package/dist/explainPhysics3DJoints.js.map +1 -0
- package/dist/explainPhysics3DStep.d.ts +3 -0
- package/dist/explainPhysics3DStep.d.ts.map +1 -0
- package/dist/explainPhysics3DStep.js +48 -0
- package/dist/explainPhysics3DStep.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/integrate.d.ts +6 -0
- package/dist/integrate.d.ts.map +1 -0
- package/dist/integrate.js +154 -0
- package/dist/integrate.js.map +1 -0
- package/dist/islands.d.ts +5 -0
- package/dist/islands.d.ts.map +1 -0
- package/dist/islands.js +316 -0
- package/dist/islands.js.map +1 -0
- package/dist/jointCollisionSuppression.d.ts +4 -0
- package/dist/jointCollisionSuppression.d.ts.map +1 -0
- package/dist/jointCollisionSuppression.js +40 -0
- package/dist/jointCollisionSuppression.js.map +1 -0
- package/dist/jointFactories.d.ts +8 -0
- package/dist/jointFactories.d.ts.map +1 -0
- package/dist/jointFactories.js +126 -0
- package/dist/jointFactories.js.map +1 -0
- package/dist/jointMath.d.ts +17 -0
- package/dist/jointMath.d.ts.map +1 -0
- package/dist/jointMath.js +361 -0
- package/dist/jointMath.js.map +1 -0
- package/dist/jointRegistry.d.ts +8 -0
- package/dist/jointRegistry.d.ts.map +1 -0
- package/dist/jointRegistry.js +144 -0
- package/dist/jointRegistry.js.map +1 -0
- package/dist/jointRows.d.ts +32 -0
- package/dist/jointRows.d.ts.map +1 -0
- package/dist/jointRows.js +308 -0
- package/dist/jointRows.js.map +1 -0
- package/dist/joints.d.ts +14 -0
- package/dist/joints.d.ts.map +1 -0
- package/dist/joints.js +758 -0
- package/dist/joints.js.map +1 -0
- package/dist/massProperties.d.ts +8 -0
- package/dist/massProperties.d.ts.map +1 -0
- package/dist/massProperties.js +169 -0
- package/dist/massProperties.js.map +1 -0
- package/dist/ownership.d.ts +5 -0
- package/dist/ownership.d.ts.map +1 -0
- package/dist/ownership.js +16 -0
- package/dist/ownership.js.map +1 -0
- package/dist/registerBuiltInPhysics3DJointSolvers.d.ts +3 -0
- package/dist/registerBuiltInPhysics3DJointSolvers.d.ts.map +1 -0
- package/dist/registerBuiltInPhysics3DJointSolvers.js +14 -0
- package/dist/registerBuiltInPhysics3DJointSolvers.js.map +1 -0
- package/dist/solver.d.ts +8 -0
- package/dist/solver.d.ts.map +1 -0
- package/dist/solver.js +383 -0
- package/dist/solver.js.map +1 -0
- package/dist/step.d.ts +5 -0
- package/dist/step.d.ts.map +1 -0
- package/dist/step.js +250 -0
- package/dist/step.js.map +1 -0
- package/dist/stepValidation.d.ts +12 -0
- package/dist/stepValidation.d.ts.map +1 -0
- package/dist/stepValidation.js +201 -0
- package/dist/stepValidation.js.map +1 -0
- package/dist/symmetricTensor.d.ts +11 -0
- package/dist/symmetricTensor.d.ts.map +1 -0
- package/dist/symmetricTensor.js +150 -0
- package/dist/symmetricTensor.js.map +1 -0
- package/dist/world.d.ts +19 -0
- package/dist/world.d.ts.map +1 -0
- package/dist/world.js +370 -0
- package/dist/world.js.map +1 -0
- package/package.json +49 -0
- package/src/contacts.test.ts +64 -0
- package/src/enablePhysics3DGuards.test.ts +105 -0
- package/src/explainPhysics3DJoints.test.ts +101 -0
- package/src/explainPhysics3DStep.test.ts +123 -0
- package/src/integrate.test.ts +249 -0
- package/src/islands.test.ts +357 -0
- package/src/jointCollisionSuppression.test.ts +94 -0
- package/src/jointFactories.test.ts +195 -0
- package/src/jointMath.test.ts +643 -0
- package/src/jointRegistry.test.ts +229 -0
- package/src/jointRows.test.ts +484 -0
- package/src/joints.test.ts +677 -0
- package/src/massProperties.test.ts +305 -0
- package/src/ownership.test.ts +36 -0
- package/src/registerBuiltInPhysics3DJointSolvers.test.ts +48 -0
- package/src/solver.test.ts +481 -0
- package/src/step.test.ts +390 -0
- package/src/stepValidation.test.ts +244 -0
- package/src/symmetricTensor.test.ts +166 -0
- package/src/world.test.ts +512 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Symmetric 3x3 tensor arithmetic, in the six-component form the solver stores inertia in.
|
|
2
|
+
//
|
|
3
|
+
// Package-internal: these are how the mass and constraint code reads a tensor, not part of the
|
|
4
|
+
// physics3d API. They take and return loose numbers rather than a matrix type because an inertia tensor
|
|
5
|
+
// lives as six flat fields on `RigidBody3D` — `@flighthq/geometry`'s `Matrix3` is an `Entity` wrapping a
|
|
6
|
+
// `Float32Array`, which is both an indirection in a hot loop and a precision step down from what a
|
|
7
|
+
// solver's accumulators need.
|
|
8
|
+
//
|
|
9
|
+
// Every function here writes into a caller-provided `out` array of six numbers, ordered
|
|
10
|
+
// `[xx, yy, zz, xy, xz, yz]`, and is safe when `out` also supplies the input.
|
|
11
|
+
// Component offsets into the six-number form. Named so a caller indexes by meaning rather than by a
|
|
12
|
+
// number whose order it has to remember.
|
|
13
|
+
export const TENSOR_XX = 0;
|
|
14
|
+
export const TENSOR_YY = 1;
|
|
15
|
+
export const TENSOR_ZZ = 2;
|
|
16
|
+
export const TENSOR_XY = 3;
|
|
17
|
+
export const TENSOR_XZ = 4;
|
|
18
|
+
export const TENSOR_YZ = 5;
|
|
19
|
+
// Applies a symmetric tensor to a vector, writing `tensor * v` into `out`. The workhorse: every
|
|
20
|
+
// constraint row multiplies an angular term by an inverse inertia tensor.
|
|
21
|
+
export function applySymmetricTensor(tensor, vX, vY, vZ, out) {
|
|
22
|
+
const xx = tensor[TENSOR_XX];
|
|
23
|
+
const yy = tensor[TENSOR_YY];
|
|
24
|
+
const zz = tensor[TENSOR_ZZ];
|
|
25
|
+
const xy = tensor[TENSOR_XY];
|
|
26
|
+
const xz = tensor[TENSOR_XZ];
|
|
27
|
+
const yz = tensor[TENSOR_YZ];
|
|
28
|
+
out[0] = xx * vX + xy * vY + xz * vZ;
|
|
29
|
+
out[1] = xy * vX + yy * vY + yz * vZ;
|
|
30
|
+
out[2] = xz * vX + yz * vY + zz * vZ;
|
|
31
|
+
}
|
|
32
|
+
// Inverts a symmetric tensor, writing the result into `out`. Returns false and writes a zero tensor
|
|
33
|
+
// when the tensor is singular — which is the ordinary case, not an error: a static body, a
|
|
34
|
+
// fixed-rotation body, and a zero-mass body all carry a singular inertia, and a zero inverse is exactly
|
|
35
|
+
// what makes "infinite inertia" fall out of the same arithmetic as any other body with no branch.
|
|
36
|
+
//
|
|
37
|
+
// The determinant is compared against a scale-relative epsilon rather than an absolute one, because an
|
|
38
|
+
// inertia tensor's magnitude tracks mass times length squared and a fixed epsilon would call a small
|
|
39
|
+
// but perfectly invertible body singular.
|
|
40
|
+
export function inverseSymmetricTensor(tensor, out) {
|
|
41
|
+
const xx = tensor[TENSOR_XX];
|
|
42
|
+
const yy = tensor[TENSOR_YY];
|
|
43
|
+
const zz = tensor[TENSOR_ZZ];
|
|
44
|
+
const xy = tensor[TENSOR_XY];
|
|
45
|
+
const xz = tensor[TENSOR_XZ];
|
|
46
|
+
const yz = tensor[TENSOR_YZ];
|
|
47
|
+
// Cofactors of the symmetric matrix; only six are distinct.
|
|
48
|
+
const cofactorXX = yy * zz - yz * yz;
|
|
49
|
+
const cofactorXY = xz * yz - xy * zz;
|
|
50
|
+
const cofactorXZ = xy * yz - xz * yy;
|
|
51
|
+
const determinant = xx * cofactorXX + xy * cofactorXY + xz * cofactorXZ;
|
|
52
|
+
const scale = Math.abs(xx) + Math.abs(yy) + Math.abs(zz);
|
|
53
|
+
if (!Number.isFinite(determinant) || Math.abs(determinant) <= SINGULAR_EPSILON * scale * scale * scale) {
|
|
54
|
+
out[TENSOR_XX] = 0;
|
|
55
|
+
out[TENSOR_YY] = 0;
|
|
56
|
+
out[TENSOR_ZZ] = 0;
|
|
57
|
+
out[TENSOR_XY] = 0;
|
|
58
|
+
out[TENSOR_XZ] = 0;
|
|
59
|
+
out[TENSOR_YZ] = 0;
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
const inverseDeterminant = 1 / determinant;
|
|
63
|
+
out[TENSOR_XX] = cofactorXX * inverseDeterminant;
|
|
64
|
+
out[TENSOR_YY] = (xx * zz - xz * xz) * inverseDeterminant;
|
|
65
|
+
out[TENSOR_ZZ] = (xx * yy - xy * xy) * inverseDeterminant;
|
|
66
|
+
out[TENSOR_XY] = cofactorXY * inverseDeterminant;
|
|
67
|
+
out[TENSOR_XZ] = cofactorXZ * inverseDeterminant;
|
|
68
|
+
out[TENSOR_YZ] = (xy * xz - xx * yz) * inverseDeterminant;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
// Rotates a symmetric tensor into world space by a unit quaternion, writing `R * tensor * transpose(R)`
|
|
72
|
+
// into `out`. The result is symmetric by construction, so only six components are produced.
|
|
73
|
+
//
|
|
74
|
+
// The rotation matrix is built once and applied as two multiplies rather than composing the similarity
|
|
75
|
+
// transform in closed quaternion form: the closed form is longer, no faster, and far harder to check
|
|
76
|
+
// against a reference implementation.
|
|
77
|
+
export function rotateSymmetricTensor(tensor, quaternionX, quaternionY, quaternionZ, quaternionW, out) {
|
|
78
|
+
const x2 = quaternionX + quaternionX;
|
|
79
|
+
const y2 = quaternionY + quaternionY;
|
|
80
|
+
const z2 = quaternionZ + quaternionZ;
|
|
81
|
+
const xx2 = quaternionX * x2;
|
|
82
|
+
const yy2 = quaternionY * y2;
|
|
83
|
+
const zz2 = quaternionZ * z2;
|
|
84
|
+
const xy2 = quaternionX * y2;
|
|
85
|
+
const xz2 = quaternionX * z2;
|
|
86
|
+
const yz2 = quaternionY * z2;
|
|
87
|
+
const wx2 = quaternionW * x2;
|
|
88
|
+
const wy2 = quaternionW * y2;
|
|
89
|
+
const wz2 = quaternionW * z2;
|
|
90
|
+
// Column-major rotation basis: r0 is the image of the local x axis, and so on.
|
|
91
|
+
const r00 = 1 - yy2 - zz2;
|
|
92
|
+
const r10 = xy2 + wz2;
|
|
93
|
+
const r20 = xz2 - wy2;
|
|
94
|
+
const r01 = xy2 - wz2;
|
|
95
|
+
const r11 = 1 - xx2 - zz2;
|
|
96
|
+
const r21 = yz2 + wx2;
|
|
97
|
+
const r02 = xz2 + wy2;
|
|
98
|
+
const r12 = yz2 - wx2;
|
|
99
|
+
const r22 = 1 - xx2 - yy2;
|
|
100
|
+
const xx = tensor[TENSOR_XX];
|
|
101
|
+
const yy = tensor[TENSOR_YY];
|
|
102
|
+
const zz = tensor[TENSOR_ZZ];
|
|
103
|
+
const xy = tensor[TENSOR_XY];
|
|
104
|
+
const xz = tensor[TENSOR_XZ];
|
|
105
|
+
const yz = tensor[TENSOR_YZ];
|
|
106
|
+
// m = tensor * transpose(R). Since `transpose(R)[k][j]` is `R[j][k]`, each entry pairs a row of the
|
|
107
|
+
// tensor with a ROW of R — pairing it with a column instead silently computes `R * tensor * R`, which
|
|
108
|
+
// agrees with the right answer for every symmetric rotation and disagrees for a quarter turn.
|
|
109
|
+
const m00 = xx * r00 + xy * r01 + xz * r02;
|
|
110
|
+
const m01 = xx * r10 + xy * r11 + xz * r12;
|
|
111
|
+
const m02 = xx * r20 + xy * r21 + xz * r22;
|
|
112
|
+
const m10 = xy * r00 + yy * r01 + yz * r02;
|
|
113
|
+
const m11 = xy * r10 + yy * r11 + yz * r12;
|
|
114
|
+
const m12 = xy * r20 + yy * r21 + yz * r22;
|
|
115
|
+
const m20 = xz * r00 + yz * r01 + zz * r02;
|
|
116
|
+
const m21 = xz * r10 + yz * r11 + zz * r12;
|
|
117
|
+
const m22 = xz * r20 + yz * r21 + zz * r22;
|
|
118
|
+
out[TENSOR_XX] = r00 * m00 + r01 * m10 + r02 * m20;
|
|
119
|
+
out[TENSOR_YY] = r10 * m01 + r11 * m11 + r12 * m21;
|
|
120
|
+
out[TENSOR_ZZ] = r20 * m02 + r21 * m12 + r22 * m22;
|
|
121
|
+
out[TENSOR_XY] = r00 * m01 + r01 * m11 + r02 * m21;
|
|
122
|
+
out[TENSOR_XZ] = r00 * m02 + r01 * m12 + r02 * m22;
|
|
123
|
+
out[TENSOR_YZ] = r10 * m02 + r11 * m12 + r12 * m22;
|
|
124
|
+
}
|
|
125
|
+
// Shifts a symmetric tensor from an axis through the centre of mass to a parallel axis offset by
|
|
126
|
+
// (`dX`,`dY`,`dZ`), writing the result into `out` — the parallel-axis theorem,
|
|
127
|
+
// `I + mass * (dot(d,d) * identity - outer(d,d))`.
|
|
128
|
+
//
|
|
129
|
+
// This is what lets primitives combine without an eigenvalue solve: each contributes its own tensor
|
|
130
|
+
// about its own centre, and every one of them is shifted to the assembly's centre and summed. Note the
|
|
131
|
+
// direction — this moves AWAY from the centre of mass. Passing a negated offset does not move back,
|
|
132
|
+
// because the correction is quadratic in the offset and therefore even.
|
|
133
|
+
export function translateSymmetricTensor(tensor, mass, dX, dY, dZ, out) {
|
|
134
|
+
const xx = tensor[TENSOR_XX];
|
|
135
|
+
const yy = tensor[TENSOR_YY];
|
|
136
|
+
const zz = tensor[TENSOR_ZZ];
|
|
137
|
+
const xy = tensor[TENSOR_XY];
|
|
138
|
+
const xz = tensor[TENSOR_XZ];
|
|
139
|
+
const yz = tensor[TENSOR_YZ];
|
|
140
|
+
out[TENSOR_XX] = xx + mass * (dY * dY + dZ * dZ);
|
|
141
|
+
out[TENSOR_YY] = yy + mass * (dX * dX + dZ * dZ);
|
|
142
|
+
out[TENSOR_ZZ] = zz + mass * (dX * dX + dY * dY);
|
|
143
|
+
out[TENSOR_XY] = xy - mass * dX * dY;
|
|
144
|
+
out[TENSOR_XZ] = xz - mass * dX * dZ;
|
|
145
|
+
out[TENSOR_YZ] = yz - mass * dY * dZ;
|
|
146
|
+
}
|
|
147
|
+
// Relative tolerance for calling a tensor singular. Cubed against the tensor's trace scale in
|
|
148
|
+
// `inverseSymmetricTensor`, since a 3x3 determinant carries three factors of the matrix's magnitude.
|
|
149
|
+
const SINGULAR_EPSILON = 1e-12;
|
|
150
|
+
//# sourceMappingURL=symmetricTensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"symmetricTensor.js","sourceRoot":"","sources":["../src/symmetricTensor.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAC3F,EAAE;AACF,+FAA+F;AAC/F,wGAAwG;AACxG,yGAAyG;AACzG,mGAAmG;AACnG,8BAA8B;AAC9B,EAAE;AACF,wFAAwF;AACxF,8EAA8E;AAE9E,oGAAoG;AACpG,yCAAyC;AACzC,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAC3B,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,CAAC;AAE3B,gGAAgG;AAChG,0EAA0E;AAC1E,MAAM,UAAU,oBAAoB,CAClC,MAAmC,EACnC,EAAU,EACV,EAAU,EACV,EAAU,EACV,GAAa;IAEb,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,C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,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAC7B,MAAM,EAAE,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC;IAE7B,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,CAAC;IACjD,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IACrC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;IACrC,GAAG,CAAC,SAAS,CAAC,GAAG,EAAE,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,CAAC;AACvC,CAAC;AAED,8FAA8F;AAC9F,qGAAqG;AACrG,MAAM,gBAAgB,GAAG,KAAK,CAAC"}
|
package/dist/world.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Physics3DBodyType, Physics3DSequentialImpulseConfig, Physics3DSolverConfig, Physics3DWorld, RigidBody3D } from '@flighthq/types/contract';
|
|
2
|
+
export declare function addPhysics3DBody(world: Physics3DWorld, body: RigidBody3D): number;
|
|
3
|
+
export declare function applyPhysics3DForce(body: RigidBody3D, x: number, y: number, z: number): void;
|
|
4
|
+
export declare function applyPhysics3DForceAtPoint(body: RigidBody3D, x: number, y: number, z: number, pointX: number, pointY: number, pointZ: number): void;
|
|
5
|
+
export declare function applyPhysics3DLinearImpulse(body: RigidBody3D, x: number, y: number, z: number): void;
|
|
6
|
+
export declare function applyPhysics3DTorque(body: RigidBody3D, x: number, y: number, z: number): void;
|
|
7
|
+
export declare function createPhysics3DSequentialImpulseConfig(): Physics3DSequentialImpulseConfig;
|
|
8
|
+
export declare function createPhysics3DSolverConfig(): Physics3DSolverConfig;
|
|
9
|
+
export declare function createPhysics3DWorld(): Physics3DWorld;
|
|
10
|
+
export declare function createRigidBody3D(type?: Physics3DBodyType): RigidBody3D;
|
|
11
|
+
export declare function findPhysics3DBody(world: Readonly<Physics3DWorld>, index: number): RigidBody3D | null;
|
|
12
|
+
export declare function removePhysics3DBody(world: Physics3DWorld, body: RigidBody3D): boolean;
|
|
13
|
+
export declare function setPhysics3DBodyFixedRotation(body: RigidBody3D, fixedRotation: boolean): void;
|
|
14
|
+
export declare function setPhysics3DBodyTransform(body: RigidBody3D, x: number, y: number, z: number, orientationX: number, orientationY: number, orientationZ: number, orientationW: number): void;
|
|
15
|
+
export declare function setPhysics3DBodyType(body: RigidBody3D, type: Physics3DBodyType): void;
|
|
16
|
+
export declare function wakePhysics3DBody(body: RigidBody3D): void;
|
|
17
|
+
export declare function writeRigidBody3DWorldCenter(body: Readonly<RigidBody3D>, out: number[]): void;
|
|
18
|
+
export declare const Physics3DWorldVersion = 1;
|
|
19
|
+
//# sourceMappingURL=world.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.d.ts","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,gCAAgC,EAChC,qBAAqB,EACrB,cAAc,EACd,WAAW,EACZ,MAAM,0BAA0B,CAAC;AAoBlC,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,WAAW,GAAG,MAAM,CASjF;AAID,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC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AI,CAyBN;AAOD,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,iBAAiB,GAAG,IAAI,CAoBrF;AAID,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI,CAIzD;AAID,wBAAgB,2BAA2B,CAAC,IAAI,EAAE,QAAQ,CAAC,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI,CAwB5F;AAID,eAAO,MAAM,qBAAqB,IAAI,CAAC"}
|
package/dist/world.js
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
import { refreshRigidBody3DWorldInertia } from './integrate';
|
|
2
|
+
import { rebuildPhysics3DJointCollisionSuppressions } from './jointCollisionSuppression';
|
|
3
|
+
import { createPhysics3DMassData, setRigidBody3DMassData } from './massProperties';
|
|
4
|
+
import { physics3DJointOwners } from './ownership';
|
|
5
|
+
// World and body lifecycle: allocation, membership, and the mutations that have to run through a
|
|
6
|
+
// function because something derived follows from them.
|
|
7
|
+
//
|
|
8
|
+
// A bare field assignment is the API wherever nothing follows from it — writing `body.linearDamping`
|
|
9
|
+
// is complete on its own. The setters here exist only where they are not: changing a body's type
|
|
10
|
+
// changes its inverse mass, teleporting it invalidates its world-space inertia, and both would leave a
|
|
11
|
+
// world quietly inconsistent if left to assignment.
|
|
12
|
+
// Adds an already-created body to the world and assigns its persistent index. Returns the index.
|
|
13
|
+
//
|
|
14
|
+
// The index comes from the world's monotonic counter rather than the body array's length, so removing
|
|
15
|
+
// a body never lets a later one inherit its identity — which is what stops a stale contact or joint
|
|
16
|
+
// from being revived against a different body that happened to take its slot.
|
|
17
|
+
export function addPhysics3DBody(world, body) {
|
|
18
|
+
if (world.bodyByIndex.has(body.index) && world.bodyByIndex.get(body.index) === body)
|
|
19
|
+
return body.index;
|
|
20
|
+
body.index = world.nextBodyIndex;
|
|
21
|
+
world.nextBodyIndex += 1;
|
|
22
|
+
world.bodies.push(body);
|
|
23
|
+
world.bodyByIndex.set(body.index, body);
|
|
24
|
+
refreshRigidBody3DWorldInertia(body);
|
|
25
|
+
return body.index;
|
|
26
|
+
}
|
|
27
|
+
// Accumulates a force at the body's centre of mass, to be consumed by the next step. Ignored for a
|
|
28
|
+
// body that cannot respond to one.
|
|
29
|
+
export function applyPhysics3DForce(body, x, y, z) {
|
|
30
|
+
if (body.type !== 'dynamic')
|
|
31
|
+
return;
|
|
32
|
+
wakePhysics3DBody(body);
|
|
33
|
+
body.forceX += x;
|
|
34
|
+
body.forceY += y;
|
|
35
|
+
body.forceZ += z;
|
|
36
|
+
}
|
|
37
|
+
// Accumulates a force at a world-space point, which produces both a force at the centre of mass and the
|
|
38
|
+
// torque of its lever arm. This is the difference between pushing a crate and spinning it.
|
|
39
|
+
export function applyPhysics3DForceAtPoint(body, x, y, z, pointX, pointY, pointZ) {
|
|
40
|
+
if (body.type !== 'dynamic')
|
|
41
|
+
return;
|
|
42
|
+
wakePhysics3DBody(body);
|
|
43
|
+
body.forceX += x;
|
|
44
|
+
body.forceY += y;
|
|
45
|
+
body.forceZ += z;
|
|
46
|
+
writeRigidBody3DWorldCenter(body, scratchCenter);
|
|
47
|
+
const rX = pointX - scratchCenter[0];
|
|
48
|
+
const rY = pointY - scratchCenter[1];
|
|
49
|
+
const rZ = pointZ - scratchCenter[2];
|
|
50
|
+
body.torqueX += rY * z - rZ * y;
|
|
51
|
+
body.torqueY += rZ * x - rX * z;
|
|
52
|
+
body.torqueZ += rX * y - rY * x;
|
|
53
|
+
}
|
|
54
|
+
// Applies an instantaneous change in momentum at the centre of mass, bypassing the force accumulator.
|
|
55
|
+
// An impulse is what a jump or a hit is: a velocity change now, not a force integrated over the step.
|
|
56
|
+
export function applyPhysics3DLinearImpulse(body, x, y, z) {
|
|
57
|
+
if (body.type !== 'dynamic' || body.inverseMass === 0)
|
|
58
|
+
return;
|
|
59
|
+
wakePhysics3DBody(body);
|
|
60
|
+
body.velocityX += x * body.inverseMass;
|
|
61
|
+
body.velocityY += y * body.inverseMass;
|
|
62
|
+
body.velocityZ += z * body.inverseMass;
|
|
63
|
+
}
|
|
64
|
+
// Accumulates a torque about the centre of mass, to be consumed by the next step.
|
|
65
|
+
export function applyPhysics3DTorque(body, x, y, z) {
|
|
66
|
+
if (body.type !== 'dynamic')
|
|
67
|
+
return;
|
|
68
|
+
wakePhysics3DBody(body);
|
|
69
|
+
body.torqueX += x;
|
|
70
|
+
body.torqueY += y;
|
|
71
|
+
body.torqueZ += z;
|
|
72
|
+
}
|
|
73
|
+
// The default sequential-impulse tuning. Eight velocity iterations and three position iterations are
|
|
74
|
+
// the values a Box2D-lineage solver converges acceptably at for ordinary scenes; a scene of tall stacks
|
|
75
|
+
// wants more of the first, and one with deep initial overlap more of the second.
|
|
76
|
+
export function createPhysics3DSequentialImpulseConfig() {
|
|
77
|
+
return {
|
|
78
|
+
velocityIterations: 8,
|
|
79
|
+
positionIterations: 3,
|
|
80
|
+
penetrationSlop: 0.005,
|
|
81
|
+
positionCorrection: 0.2,
|
|
82
|
+
restitutionThreshold: 1,
|
|
83
|
+
warmStarting: true,
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
// The default solver tuning. `substeps` is 1, which reproduces a single discrete step per call.
|
|
87
|
+
export function createPhysics3DSolverConfig() {
|
|
88
|
+
return {
|
|
89
|
+
allowSleeping: true,
|
|
90
|
+
sleepLinearThreshold: 0.01,
|
|
91
|
+
sleepAngularThreshold: 0.02,
|
|
92
|
+
timeToSleep: 0.5,
|
|
93
|
+
substeps: 1,
|
|
94
|
+
continuousCollision: false,
|
|
95
|
+
maxCcdSubsteps: 4,
|
|
96
|
+
sequentialImpulse: createPhysics3DSequentialImpulseConfig(),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// Allocates an empty world under earth gravity along -Y.
|
|
100
|
+
//
|
|
101
|
+
// The world owns no broadphase index, unlike `Physics2DWorld`. That is not an omission to be filled by
|
|
102
|
+
// a physics-specific seam: `SpatialIndexBackend2D` is the swap point and its 3D counterpart does not
|
|
103
|
+
// exist yet, so contacts are supplied by the caller until it does.
|
|
104
|
+
export function createPhysics3DWorld() {
|
|
105
|
+
return {
|
|
106
|
+
version: Physics3DWorldVersion,
|
|
107
|
+
bodies: [],
|
|
108
|
+
bodyByIndex: new Map(),
|
|
109
|
+
contacts: [],
|
|
110
|
+
joints: [],
|
|
111
|
+
jointSolvers: new Map(),
|
|
112
|
+
jointCollisionSuppressions: new Map(),
|
|
113
|
+
events: { began: [], ended: [] },
|
|
114
|
+
contactHooks: { preSolve: null, postSolve: null },
|
|
115
|
+
solver: { constraints: [], constraintByPair: new Map() },
|
|
116
|
+
config: createPhysics3DSolverConfig(),
|
|
117
|
+
islandParents: new Map(),
|
|
118
|
+
islandSleepTimers: new Map(),
|
|
119
|
+
solveIslandByRoot: new Map(),
|
|
120
|
+
solveIslandRoots: [],
|
|
121
|
+
solveIslandBodyStarts: [],
|
|
122
|
+
solveIslandBodyCounts: [],
|
|
123
|
+
solveIslandContactStarts: [],
|
|
124
|
+
solveIslandContactCounts: [],
|
|
125
|
+
solveIslandJointStarts: [],
|
|
126
|
+
solveIslandJointCounts: [],
|
|
127
|
+
solveIslandBodyIndices: [],
|
|
128
|
+
solveIslandContactIndices: [],
|
|
129
|
+
solveIslandJointIndices: [],
|
|
130
|
+
solveIslandCursors: [],
|
|
131
|
+
gravityX: 0,
|
|
132
|
+
gravityY: -9.80665,
|
|
133
|
+
gravityZ: 0,
|
|
134
|
+
previousTimestep: 0,
|
|
135
|
+
nextBodyIndex: 0,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
// Allocates a body at rest at the origin, with no mass. It is not in any world until added, and it will
|
|
139
|
+
// not move until given mass: a dynamic body with zero mass carries a zero inverse mass, which is the
|
|
140
|
+
// same immovable sentinel a static body carries.
|
|
141
|
+
export function createRigidBody3D(type = 'dynamic') {
|
|
142
|
+
return {
|
|
143
|
+
index: -1,
|
|
144
|
+
type,
|
|
145
|
+
x: 0,
|
|
146
|
+
y: 0,
|
|
147
|
+
z: 0,
|
|
148
|
+
orientationX: 0,
|
|
149
|
+
orientationY: 0,
|
|
150
|
+
orientationZ: 0,
|
|
151
|
+
orientationW: 1,
|
|
152
|
+
velocityX: 0,
|
|
153
|
+
velocityY: 0,
|
|
154
|
+
velocityZ: 0,
|
|
155
|
+
angularVelocityX: 0,
|
|
156
|
+
angularVelocityY: 0,
|
|
157
|
+
angularVelocityZ: 0,
|
|
158
|
+
forceX: 0,
|
|
159
|
+
forceY: 0,
|
|
160
|
+
forceZ: 0,
|
|
161
|
+
torqueX: 0,
|
|
162
|
+
torqueY: 0,
|
|
163
|
+
torqueZ: 0,
|
|
164
|
+
mass: 0,
|
|
165
|
+
inverseMass: 0,
|
|
166
|
+
inertiaXX: 0,
|
|
167
|
+
inertiaYY: 0,
|
|
168
|
+
inertiaZZ: 0,
|
|
169
|
+
inertiaXY: 0,
|
|
170
|
+
inertiaXZ: 0,
|
|
171
|
+
inertiaYZ: 0,
|
|
172
|
+
inverseInertiaXX: 0,
|
|
173
|
+
inverseInertiaYY: 0,
|
|
174
|
+
inverseInertiaZZ: 0,
|
|
175
|
+
inverseInertiaXY: 0,
|
|
176
|
+
inverseInertiaXZ: 0,
|
|
177
|
+
inverseInertiaYZ: 0,
|
|
178
|
+
inverseInertiaWorldXX: 0,
|
|
179
|
+
inverseInertiaWorldYY: 0,
|
|
180
|
+
inverseInertiaWorldZZ: 0,
|
|
181
|
+
inverseInertiaWorldXY: 0,
|
|
182
|
+
inverseInertiaWorldXZ: 0,
|
|
183
|
+
inverseInertiaWorldYZ: 0,
|
|
184
|
+
centerX: 0,
|
|
185
|
+
centerY: 0,
|
|
186
|
+
centerZ: 0,
|
|
187
|
+
linearDamping: 0,
|
|
188
|
+
angularDamping: 0,
|
|
189
|
+
gravityScale: 1,
|
|
190
|
+
fixedRotation: false,
|
|
191
|
+
bullet: false,
|
|
192
|
+
sleeping: false,
|
|
193
|
+
sleepEnabled: true,
|
|
194
|
+
sleepTimer: 0,
|
|
195
|
+
material: { density: 1, friction: 0.2, restitution: 0 },
|
|
196
|
+
filter: { categoryBits: 1, maskBits: 0xffff, groupIndex: 0 },
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
// Looks a body up by its persistent index, or null when no body in this world carries it. The
|
|
200
|
+
// expected-failure sentinel: a caller holding an index across a removal gets null, not a throw.
|
|
201
|
+
export function findPhysics3DBody(world, index) {
|
|
202
|
+
return world.bodyByIndex.get(index) ?? null;
|
|
203
|
+
}
|
|
204
|
+
// Removes a body and every contact and joint that referenced it. Returns false when the body is not in
|
|
205
|
+
// this world.
|
|
206
|
+
//
|
|
207
|
+
// Constraints go with it because a contact naming a removed body would resolve to null inside a solver
|
|
208
|
+
// loop, and the alternative — a null check per constraint per iteration — pays on every step for a case
|
|
209
|
+
// that only arises at removal.
|
|
210
|
+
//
|
|
211
|
+
// A joint dropped here leaves by the SAME two exits `removePhysics3DJoint` uses: its ownership entry is
|
|
212
|
+
// released, and the suppression index is rebuilt. Splicing it out of the array alone leaves a joint that
|
|
213
|
+
// no world holds but that every world still refuses to accept, and leaves the pair it connected suppressed
|
|
214
|
+
// against a joint that no longer exists — a contact that silently never reports.
|
|
215
|
+
export function removePhysics3DBody(world, body) {
|
|
216
|
+
const at = world.bodies.indexOf(body);
|
|
217
|
+
if (at < 0)
|
|
218
|
+
return false;
|
|
219
|
+
world.bodies.splice(at, 1);
|
|
220
|
+
world.bodyByIndex.delete(body.index);
|
|
221
|
+
const index = body.index;
|
|
222
|
+
for (let i = world.contacts.length - 1; i >= 0; i--) {
|
|
223
|
+
const contact = world.contacts[i];
|
|
224
|
+
if (contact.bodyA === index || contact.bodyB === index)
|
|
225
|
+
world.contacts.splice(i, 1);
|
|
226
|
+
}
|
|
227
|
+
let removedJoint = false;
|
|
228
|
+
for (let i = world.joints.length - 1; i >= 0; i--) {
|
|
229
|
+
const joint = world.joints[i];
|
|
230
|
+
if (joint.bodyA !== index && joint.bodyB !== index)
|
|
231
|
+
continue;
|
|
232
|
+
world.joints.splice(i, 1);
|
|
233
|
+
physics3DJointOwners.delete(joint);
|
|
234
|
+
removedJoint = true;
|
|
235
|
+
}
|
|
236
|
+
if (removedJoint)
|
|
237
|
+
rebuildPhysics3DJointCollisionSuppressions(world);
|
|
238
|
+
world.solver.constraintByPair.clear();
|
|
239
|
+
return true;
|
|
240
|
+
}
|
|
241
|
+
// Opts a dynamic body into or out of rotating at all, rebuilding its inverse inertia.
|
|
242
|
+
//
|
|
243
|
+
// A fixed-rotation body keeps its translational mass and exposes a zero inverse inertia tensor to every
|
|
244
|
+
// contact and joint equation — the same sentinel a static body uses, applied to rotation alone. Its
|
|
245
|
+
// angular velocity is cleared, because leaving one behind would let a body that cannot be rotated by
|
|
246
|
+
// anything keep spinning forever from whatever it had before.
|
|
247
|
+
export function setPhysics3DBodyFixedRotation(body, fixedRotation) {
|
|
248
|
+
if (body.fixedRotation === fixedRotation)
|
|
249
|
+
return;
|
|
250
|
+
body.fixedRotation = fixedRotation;
|
|
251
|
+
if (fixedRotation) {
|
|
252
|
+
body.angularVelocityX = 0;
|
|
253
|
+
body.angularVelocityY = 0;
|
|
254
|
+
body.angularVelocityZ = 0;
|
|
255
|
+
}
|
|
256
|
+
refreshRigidBody3DMass(body);
|
|
257
|
+
}
|
|
258
|
+
// Teleports a body, refreshing the world-space inertia its new orientation implies.
|
|
259
|
+
//
|
|
260
|
+
// The quaternion is normalized on the way in rather than trusted: a caller composing one from euler
|
|
261
|
+
// angles or interpolating between two will hand over something fractionally off the unit sphere, and
|
|
262
|
+
// every rotation downstream would inherit the error.
|
|
263
|
+
export function setPhysics3DBodyTransform(body, x, y, z, orientationX, orientationY, orientationZ, orientationW) {
|
|
264
|
+
body.x = x;
|
|
265
|
+
body.y = y;
|
|
266
|
+
body.z = z;
|
|
267
|
+
const lengthSquared = orientationX * orientationX +
|
|
268
|
+
orientationY * orientationY +
|
|
269
|
+
orientationZ * orientationZ +
|
|
270
|
+
orientationW * orientationW;
|
|
271
|
+
if (lengthSquared > 0) {
|
|
272
|
+
const scale = 1 / Math.sqrt(lengthSquared);
|
|
273
|
+
body.orientationX = orientationX * scale;
|
|
274
|
+
body.orientationY = orientationY * scale;
|
|
275
|
+
body.orientationZ = orientationZ * scale;
|
|
276
|
+
body.orientationW = orientationW * scale;
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
body.orientationX = 0;
|
|
280
|
+
body.orientationY = 0;
|
|
281
|
+
body.orientationZ = 0;
|
|
282
|
+
body.orientationW = 1;
|
|
283
|
+
}
|
|
284
|
+
wakePhysics3DBody(body);
|
|
285
|
+
refreshRigidBody3DWorldInertia(body);
|
|
286
|
+
}
|
|
287
|
+
// Changes how a body participates, rebuilding the mass properties that follow from it.
|
|
288
|
+
//
|
|
289
|
+
// Leaving a body's velocity behind when it becomes static would strand motion nothing can consume, so
|
|
290
|
+
// the velocities are cleared; becoming dynamic keeps them, since a body that was being pushed as
|
|
291
|
+
// kinematic is plausibly still moving.
|
|
292
|
+
export function setPhysics3DBodyType(body, type) {
|
|
293
|
+
if (body.type === type)
|
|
294
|
+
return;
|
|
295
|
+
body.type = type;
|
|
296
|
+
if (type === 'static') {
|
|
297
|
+
body.velocityX = 0;
|
|
298
|
+
body.velocityY = 0;
|
|
299
|
+
body.velocityZ = 0;
|
|
300
|
+
body.angularVelocityX = 0;
|
|
301
|
+
body.angularVelocityY = 0;
|
|
302
|
+
body.angularVelocityZ = 0;
|
|
303
|
+
body.sleeping = false;
|
|
304
|
+
}
|
|
305
|
+
body.forceX = 0;
|
|
306
|
+
body.forceY = 0;
|
|
307
|
+
body.forceZ = 0;
|
|
308
|
+
body.torqueX = 0;
|
|
309
|
+
body.torqueY = 0;
|
|
310
|
+
body.torqueZ = 0;
|
|
311
|
+
refreshRigidBody3DMass(body);
|
|
312
|
+
refreshRigidBody3DWorldInertia(body);
|
|
313
|
+
}
|
|
314
|
+
// Wakes a body and resets its stillness timer. A no-op for a static body, which is neither awake nor
|
|
315
|
+
// asleep.
|
|
316
|
+
export function wakePhysics3DBody(body) {
|
|
317
|
+
if (body.type === 'static')
|
|
318
|
+
return;
|
|
319
|
+
body.sleeping = false;
|
|
320
|
+
body.sleepTimer = 0;
|
|
321
|
+
}
|
|
322
|
+
// Writes the body's centre of mass in WORLD space into `out`, rotating the local centre by the body's
|
|
323
|
+
// orientation and adding its position. The lever arm for every force and contact starts here.
|
|
324
|
+
export function writeRigidBody3DWorldCenter(body, out) {
|
|
325
|
+
const cX = body.centerX;
|
|
326
|
+
const cY = body.centerY;
|
|
327
|
+
const cZ = body.centerZ;
|
|
328
|
+
if (cX === 0 && cY === 0 && cZ === 0) {
|
|
329
|
+
out[0] = body.x;
|
|
330
|
+
out[1] = body.y;
|
|
331
|
+
out[2] = body.z;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
// Rotate by the quaternion as `v + 2 * cross(q.xyz, cross(q.xyz, v) + q.w * v)`.
|
|
335
|
+
const qX = body.orientationX;
|
|
336
|
+
const qY = body.orientationY;
|
|
337
|
+
const qZ = body.orientationZ;
|
|
338
|
+
const qW = body.orientationW;
|
|
339
|
+
const tX = qY * cZ - qZ * cY + qW * cX;
|
|
340
|
+
const tY = qZ * cX - qX * cZ + qW * cY;
|
|
341
|
+
const tZ = qX * cY - qY * cX + qW * cZ;
|
|
342
|
+
out[0] = body.x + cX + 2 * (qY * tZ - qZ * tY);
|
|
343
|
+
out[1] = body.y + cY + 2 * (qZ * tX - qX * tZ);
|
|
344
|
+
out[2] = body.z + cZ + 2 * (qX * tY - qY * tX);
|
|
345
|
+
}
|
|
346
|
+
// The serializable-shape version of `Physics3DWorld`. Bumped when a field a format layer would have
|
|
347
|
+
// written changes meaning, so a reconstructed world can be recognized as older and upgraded.
|
|
348
|
+
export const Physics3DWorldVersion = 1;
|
|
349
|
+
// Recomputes the inverse mass and local inverse inertia after something that changes a body's
|
|
350
|
+
// ELIGIBILITY to move rather than its geometry — a type change, a fixed-rotation change.
|
|
351
|
+
//
|
|
352
|
+
// It reads the forward mass and inertia the body already carries, which is exactly why those are
|
|
353
|
+
// stored: the inverse is zero for every body this is called on the way out of, so it holds nothing to
|
|
354
|
+
// recover them from.
|
|
355
|
+
function refreshRigidBody3DMass(body) {
|
|
356
|
+
scratchMassData.mass = body.mass;
|
|
357
|
+
scratchMassData.centerX = body.centerX;
|
|
358
|
+
scratchMassData.centerY = body.centerY;
|
|
359
|
+
scratchMassData.centerZ = body.centerZ;
|
|
360
|
+
scratchMassData.inertiaXX = body.inertiaXX;
|
|
361
|
+
scratchMassData.inertiaYY = body.inertiaYY;
|
|
362
|
+
scratchMassData.inertiaZZ = body.inertiaZZ;
|
|
363
|
+
scratchMassData.inertiaXY = body.inertiaXY;
|
|
364
|
+
scratchMassData.inertiaXZ = body.inertiaXZ;
|
|
365
|
+
scratchMassData.inertiaYZ = body.inertiaYZ;
|
|
366
|
+
setRigidBody3DMassData(body, scratchMassData);
|
|
367
|
+
}
|
|
368
|
+
const scratchCenter = [0, 0, 0];
|
|
369
|
+
const scratchMassData = createPhysics3DMassData();
|
|
370
|
+
//# sourceMappingURL=world.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"world.js","sourceRoot":"","sources":["../src/world.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,8BAA8B,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,0CAA0C,EAAE,MAAM,6BAA6B,CAAC;AACzF,OAAO,EAAE,uBAAuB,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,iGAAiG;AACjG,wDAAwD;AACxD,EAAE;AACF,qGAAqG;AACrG,iGAAiG;AACjG,uGAAuG;AACvG,oDAAoD;AAEpD,iGAAiG;AACjG,EAAE;AACF,sGAAsG;AACtG,oGAAoG;AACpG,8EAA8E;AAC9E,MAAM,UAAU,gBAAgB,CAAC,KAAqB,EAAE,IAAiB;IACvE,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C;IAE3C,sBAAsB,CAAC,IAAI,EAAE,eAAe,CAAC,CAAC;AAChD,CAAC;AAED,MAAM,aAAa,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;AAChC,MAAM,eAAe,GAAG,uBAAuB,EAAE,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@flighthq/physics3d",
|
|
3
|
+
"version": "0.4.0-next.1694.598ef6f",
|
|
4
|
+
"author": "Joshua Granick and other contributors",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/flighthq/flight.git",
|
|
9
|
+
"directory": "packages/physics3d"
|
|
10
|
+
},
|
|
11
|
+
"type": "module",
|
|
12
|
+
"main": "dist/index.js",
|
|
13
|
+
"types": "dist/index.d.ts",
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
},
|
|
19
|
+
"./contract": {
|
|
20
|
+
"types": "./dist/contract.d.ts",
|
|
21
|
+
"default": "./dist/contract.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"src/**/*.test.ts",
|
|
27
|
+
"!dist/**/*.test.js",
|
|
28
|
+
"!dist/**/*.test.d.ts",
|
|
29
|
+
"!dist/**/*.test.js.map",
|
|
30
|
+
"!dist/**/*.test.d.ts.map"
|
|
31
|
+
],
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsc -b",
|
|
34
|
+
"clean": "tsc -b --clean",
|
|
35
|
+
"test": "vitest run --config vitest.config.ts",
|
|
36
|
+
"test:watch": "vitest --watch --config vitest.config.ts",
|
|
37
|
+
"prepack": "npm run clean && npm run clean:dist && npm run build",
|
|
38
|
+
"clean:dist": "tsx ../../scripts/clean-package-dist.ts"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@flighthq/log": "0.4.0-next.1694.598ef6f",
|
|
42
|
+
"@flighthq/types": "0.4.0-next.1694.598ef6f"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "^5.3.0"
|
|
46
|
+
},
|
|
47
|
+
"description": "3D rigid-body dynamics — quaternion integration over inertia tensors and a deterministic sequential-impulse solver, with explicit stepping and no hidden per-frame allocation",
|
|
48
|
+
"sideEffects": false
|
|
49
|
+
}
|