@gg-web-engine/rapier3d 0.0.59 → 0.0.61
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.
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Body3DOptions, CollisionGroup, DebugBody3DSettings, Entity3d, IRigidBody3dComponent, Point3, Point4, Shape3DDescriptor } from '@gg-web-engine/core';
|
|
2
|
-
import { Collider, ColliderDesc, RigidBody, RigidBodyDesc } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { Collider, ColliderDesc, InteractionGroups, RigidBody, RigidBodyDesc } from '@dimforge/rapier3d-compat';
|
|
3
3
|
import { Rapier3dWorldComponent } from './rapier-3d-world.component';
|
|
4
4
|
import { Rapier3dGgWorld, Rapier3dPhysicsTypeDocRepo } from '../types';
|
|
5
|
-
import { InteractionGroups } from '@dimforge/rapier3d-compat/geometry/interaction_groups';
|
|
6
5
|
export declare class Rapier3dRigidBodyComponent implements IRigidBody3dComponent<Rapier3dPhysicsTypeDocRepo> {
|
|
7
6
|
protected readonly world: Rapier3dWorldComponent;
|
|
8
7
|
protected _colliderDescr: ColliderDesc[];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BitMask, DebugBody3DSettings, Pnt3, Qtrn, } from '@gg-web-engine/core';
|
|
2
|
-
import { ColliderDesc, Quaternion, RigidBodyDesc, Vector3 } from '@dimforge/rapier3d-compat';
|
|
2
|
+
import { ColliderDesc, Quaternion, RigidBodyDesc, Vector3, } from '@dimforge/rapier3d-compat';
|
|
3
3
|
export class Rapier3dRigidBodyComponent {
|
|
4
4
|
get position() {
|
|
5
5
|
return Pnt3.clone(this.nativeBody ? this.nativeBody.translation() : this._bodyDescr.translation);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gg-web-engine/rapier3d",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.61",
|
|
4
4
|
"description": "An attempt to create open source game engine for browser",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,20 +27,21 @@
|
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/AndyGura/gg-web-engine#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@dimforge/rapier3d-compat": "0.
|
|
31
|
-
"@gg-web-engine/core": "0.0.
|
|
32
|
-
"@types/jest": "^
|
|
33
|
-
"
|
|
34
|
-
"jest
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
30
|
+
"@dimforge/rapier3d-compat": "0.20.0",
|
|
31
|
+
"@gg-web-engine/core": "0.0.61",
|
|
32
|
+
"@types/jest": "^30.0.0",
|
|
33
|
+
"@types/node": "^26.4.0",
|
|
34
|
+
"jest": "^30.5.0",
|
|
35
|
+
"jest-environment-jsdom": "^30.5.0",
|
|
36
|
+
"prettier": "^3.9.6",
|
|
37
|
+
"rxjs": "7.8.2",
|
|
38
|
+
"ts-jest": "^29.4.12",
|
|
39
|
+
"typescript": "~6.0.3"
|
|
39
40
|
},
|
|
40
41
|
"peerDependencies": {
|
|
41
|
-
"@dimforge/rapier3d-compat": "0.
|
|
42
|
-
"@gg-web-engine/core": "0.0.
|
|
43
|
-
"rxjs": "7.8.
|
|
42
|
+
"@dimforge/rapier3d-compat": "0.20.0",
|
|
43
|
+
"@gg-web-engine/core": "0.0.61",
|
|
44
|
+
"rxjs": "7.8.2"
|
|
44
45
|
},
|
|
45
46
|
"jest": {
|
|
46
47
|
"rootDir": ".",
|
|
@@ -51,6 +52,9 @@
|
|
|
51
52
|
"moduleNameMapper": {
|
|
52
53
|
"@gg-web-engine/core": "<rootDir>/../core/src/index.ts"
|
|
53
54
|
},
|
|
55
|
+
"setupFiles": [
|
|
56
|
+
"<rootDir>/test/jest-polyfills.ts"
|
|
57
|
+
],
|
|
54
58
|
"preset": "ts-jest/presets/default",
|
|
55
59
|
"collectCoverageFrom": [
|
|
56
60
|
"**/*.ts",
|
|
@@ -19,6 +19,23 @@ describe(`Rapier3dTriggerComponent`, () => {
|
|
|
19
19
|
world.dispose();
|
|
20
20
|
});
|
|
21
21
|
|
|
22
|
+
// Rapier's world.step() runs narrow-phase collision detection against the positions from the
|
|
23
|
+
// *start* of the step, then integrates velocities into new positions at the end of it - so a
|
|
24
|
+
// collision/intersection that happens partway through one particular step is only reflected in
|
|
25
|
+
// the EventQueue on the *following* step. With one huge step (e.g. simulate(500) covering half
|
|
26
|
+
// a second of motion in a single leap) that shows up as a whole step's worth of lag, wrongly
|
|
27
|
+
// looking like a missed event. Advancing in many small steps (as a real per-frame game loop
|
|
28
|
+
// would) keeps that lag well under the assertion's resolution. Also, EventQueue was constructed
|
|
29
|
+
// with autoDrain=true (see Rapier3dWorldComponent.init), which clears any undrained events right
|
|
30
|
+
// before the *next* world.step() - so checkOverlaps() (which drains it) must be called after
|
|
31
|
+
// every single simulate() call, not just once at the end of a batch, or interior events are lost.
|
|
32
|
+
const advance = (totalMs: number, onStep: () => void, stepMs = 10) => {
|
|
33
|
+
for (let elapsed = 0; elapsed < totalMs; elapsed += stepMs) {
|
|
34
|
+
world.simulate(stepMs);
|
|
35
|
+
onStep();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
|
|
22
39
|
it(`should detect object intersection`, async () => {
|
|
23
40
|
const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
24
41
|
trigger.addToWorld({ physicsWorld: world } as any);
|
|
@@ -36,13 +53,11 @@ describe(`Rapier3dTriggerComponent`, () => {
|
|
|
36
53
|
trigger.onEntityLeft.subscribe(((obj) => {
|
|
37
54
|
exitRegistered = obj === ball;
|
|
38
55
|
}));
|
|
39
|
-
|
|
40
|
-
trigger.checkOverlaps(); // trigger entity performs that on tick
|
|
56
|
+
advance(500, () => trigger.checkOverlaps()); // trigger entity performs that on tick
|
|
41
57
|
expect(enterRegistered).toBe(false);
|
|
42
58
|
expect(exitRegistered).toBe(false);
|
|
43
59
|
|
|
44
|
-
|
|
45
|
-
trigger.checkOverlaps();
|
|
60
|
+
advance(500, () => trigger.checkOverlaps());
|
|
46
61
|
expect(enterRegistered).toBe(true);
|
|
47
62
|
expect(exitRegistered).toBe(false);
|
|
48
63
|
});
|
|
@@ -60,11 +75,9 @@ describe(`Rapier3dTriggerComponent`, () => {
|
|
|
60
75
|
trigger.onEntityLeft.subscribe(((obj) => {
|
|
61
76
|
exitRegistered = obj === ball;
|
|
62
77
|
}));
|
|
63
|
-
|
|
64
|
-
trigger.checkOverlaps();
|
|
78
|
+
advance(1000, () => trigger.checkOverlaps());
|
|
65
79
|
expect(exitRegistered).toBe(false);
|
|
66
|
-
|
|
67
|
-
trigger.checkOverlaps();
|
|
80
|
+
advance(1000, () => trigger.checkOverlaps());
|
|
68
81
|
expect(exitRegistered).toBe(true);
|
|
69
82
|
});
|
|
70
83
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// jest-environment-jsdom (jest 30 / jsdom 27) no longer exposes TextEncoder/TextDecoder as
|
|
2
|
+
// globals inside the jsdom sandbox, but @dimforge/rapier3d-compat's wasm-bindgen glue
|
|
3
|
+
// (rapier_wasm3d.js) references `TextDecoder`/`TextEncoder` at module top-level (outside of any
|
|
4
|
+
// function), so importing it fails at require-time before any test code runs. Polyfill them from
|
|
5
|
+
// Node's own `util` module, which does provide them, before the wasm glue module is imported.
|
|
6
|
+
import { TextDecoder, TextEncoder } from 'util';
|
|
7
|
+
|
|
8
|
+
if (typeof (globalThis as any).TextDecoder === 'undefined') {
|
|
9
|
+
(globalThis as any).TextDecoder = TextDecoder;
|
|
10
|
+
}
|
|
11
|
+
if (typeof (globalThis as any).TextEncoder === 'undefined') {
|
|
12
|
+
(globalThis as any).TextEncoder = TextEncoder;
|
|
13
|
+
}
|