@gg-web-engine/rapier3d 0.0.30 → 0.0.37
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.
|
@@ -33,7 +33,7 @@ export class Rapier3dTriggerComponent extends Rapier3dRigidBodyComponent {
|
|
|
33
33
|
else if (h2 === ((_b = this.nativeBody) === null || _b === void 0 ? void 0 : _b.handle)) {
|
|
34
34
|
otherBody = this.world.handleIdEntityMap.get(h1);
|
|
35
35
|
}
|
|
36
|
-
if (!otherBody
|
|
36
|
+
if (!otherBody)
|
|
37
37
|
return;
|
|
38
38
|
(started ? this.onEnter$ : this.onLeft$).next(otherBody);
|
|
39
39
|
});
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gg-web-engine/rapier3d",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
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",
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "
|
|
8
|
+
"test": "jest",
|
|
9
9
|
"prettier-format": "prettier --config ../core/.prettierrc 'src/**/*.ts' --write",
|
|
10
10
|
"prepublish": "rm -rf ./dist/ && tsc",
|
|
11
11
|
"build": "tsc"
|
|
@@ -26,18 +26,42 @@
|
|
|
26
26
|
"url": "https://github.com/AndyGura/gg-web-engine/issues"
|
|
27
27
|
},
|
|
28
28
|
"homepage": "https://github.com/AndyGura/gg-web-engine#readme",
|
|
29
|
-
"dependencies": {
|
|
30
|
-
},
|
|
31
29
|
"devDependencies": {
|
|
32
30
|
"@dimforge/rapier3d-compat": "0.0.0-c23a138-20231001",
|
|
33
|
-
"@gg-web-engine/core": "0.0.
|
|
31
|
+
"@gg-web-engine/core": "0.0.37",
|
|
32
|
+
"@types/jest": "^29.5.0",
|
|
33
|
+
"jest": "^29.5.0",
|
|
34
|
+
"jest-environment-jsdom": "^29.5.0",
|
|
34
35
|
"prettier": "^2.8.6",
|
|
35
36
|
"rxjs": "7.8.0",
|
|
37
|
+
"ts-jest": "^29.0.5",
|
|
36
38
|
"typescript": "~4.7.2"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
41
|
"@dimforge/rapier3d-compat": "0.0.0-c23a138-20231001",
|
|
40
|
-
"@gg-web-engine/core": "0.0.
|
|
42
|
+
"@gg-web-engine/core": "0.0.37",
|
|
41
43
|
"rxjs": "7.8.0"
|
|
44
|
+
},
|
|
45
|
+
"jest": {
|
|
46
|
+
"rootDir": ".",
|
|
47
|
+
"testRegex": "\\.spec\\.ts$",
|
|
48
|
+
"transform": {
|
|
49
|
+
"^.+\\.(t|j)s$": "ts-jest"
|
|
50
|
+
},
|
|
51
|
+
"moduleNameMapper": {
|
|
52
|
+
"@gg-web-engine/core": "<rootDir>/../core/src/index.ts"
|
|
53
|
+
},
|
|
54
|
+
"preset": "ts-jest/presets/default",
|
|
55
|
+
"collectCoverageFrom": [
|
|
56
|
+
"**/*.ts",
|
|
57
|
+
"!**/*.module.ts"
|
|
58
|
+
],
|
|
59
|
+
"coveragePathIgnorePatterns": [
|
|
60
|
+
"<rootDir>/node_modules/",
|
|
61
|
+
"<rootDir>/dist/",
|
|
62
|
+
"<rootDir>/test/"
|
|
63
|
+
],
|
|
64
|
+
"coverageDirectory": "./coverage",
|
|
65
|
+
"testEnvironment": "jsdom"
|
|
42
66
|
}
|
|
43
67
|
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import { Rapier3dFactory, Rapier3dWorldComponent } from '../../src';
|
|
2
|
+
import { Pnt3 } from '@gg-web-engine/core';
|
|
3
|
+
|
|
4
|
+
describe(`Rapier3dTriggerComponent`, () => {
|
|
5
|
+
|
|
6
|
+
let world: Rapier3dWorldComponent;
|
|
7
|
+
let factory: Rapier3dFactory;
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
if (world) {
|
|
10
|
+
world.dispose();
|
|
11
|
+
}
|
|
12
|
+
world = new Rapier3dWorldComponent();
|
|
13
|
+
factory = new Rapier3dFactory(world);
|
|
14
|
+
await world.init();
|
|
15
|
+
world.gravity = Pnt3.O;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(() => {
|
|
19
|
+
world.dispose();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it(`should detect object intersection`, async () => {
|
|
23
|
+
const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
24
|
+
trigger.addToWorld({ physicsWorld: world } as any);
|
|
25
|
+
const ball = factory.createRigidBody({
|
|
26
|
+
shape: { shape: 'SPHERE', radius: 1 },
|
|
27
|
+
body: { dynamic: true, mass: 1 },
|
|
28
|
+
}, { position: { x: 0, y: 0, z: 12 } });
|
|
29
|
+
ball.addToWorld({ physicsWorld: world } as any);
|
|
30
|
+
ball.linearVelocity = { x: 0, y: 0, z: -10 };
|
|
31
|
+
let enterRegistered = false;
|
|
32
|
+
let exitRegistered = false;
|
|
33
|
+
trigger.onEntityEntered.subscribe(((obj) => {
|
|
34
|
+
enterRegistered = obj === ball;
|
|
35
|
+
}));
|
|
36
|
+
trigger.onEntityLeft.subscribe(((obj) => {
|
|
37
|
+
exitRegistered = obj === ball;
|
|
38
|
+
}));
|
|
39
|
+
world.simulate(500);
|
|
40
|
+
trigger.checkOverlaps(); // trigger entity performs that on tick
|
|
41
|
+
expect(enterRegistered).toBe(false);
|
|
42
|
+
expect(exitRegistered).toBe(false);
|
|
43
|
+
|
|
44
|
+
world.simulate(500);
|
|
45
|
+
trigger.checkOverlaps();
|
|
46
|
+
expect(enterRegistered).toBe(true);
|
|
47
|
+
expect(exitRegistered).toBe(false);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it(`should detect end of object intersection`, async () => {
|
|
51
|
+
const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
52
|
+
trigger.addToWorld({ physicsWorld: world } as any);
|
|
53
|
+
const ball = factory.createRigidBody({
|
|
54
|
+
shape: { shape: 'SPHERE', radius: 1 },
|
|
55
|
+
body: { dynamic: true, mass: 1 },
|
|
56
|
+
}, { position: { x: 0, y: 0, z: 12 } });
|
|
57
|
+
ball.addToWorld({ physicsWorld: world } as any);
|
|
58
|
+
ball.linearVelocity = { x: 0, y: 0, z: -10 };
|
|
59
|
+
let exitRegistered = false;
|
|
60
|
+
trigger.onEntityLeft.subscribe(((obj) => {
|
|
61
|
+
exitRegistered = obj === ball;
|
|
62
|
+
}));
|
|
63
|
+
world.simulate(1000);
|
|
64
|
+
trigger.checkOverlaps();
|
|
65
|
+
expect(exitRegistered).toBe(false);
|
|
66
|
+
world.simulate(1000);
|
|
67
|
+
trigger.checkOverlaps();
|
|
68
|
+
expect(exitRegistered).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it(`should fire object intersection if spawned inside`, async () => {
|
|
72
|
+
const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
73
|
+
trigger.addToWorld({ physicsWorld: world } as any);
|
|
74
|
+
const ball = factory.createRigidBody({
|
|
75
|
+
shape: { shape: 'SPHERE', radius: 1 },
|
|
76
|
+
body: { dynamic: true, mass: 1 },
|
|
77
|
+
}, { position: { x: 0, y: 0, z: 0 } });
|
|
78
|
+
ball.addToWorld({ physicsWorld: world } as any);
|
|
79
|
+
let enterRegistered = false;
|
|
80
|
+
trigger.onEntityEntered.subscribe(((obj) => {
|
|
81
|
+
enterRegistered = obj === ball;
|
|
82
|
+
}));
|
|
83
|
+
world.simulate(1000);
|
|
84
|
+
trigger.checkOverlaps();
|
|
85
|
+
expect(enterRegistered).toBe(true);
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// TODO implement functionality below
|
|
89
|
+
// it(`should fire end of object intersection if trigger removed`, async () => {
|
|
90
|
+
// const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
91
|
+
// trigger.addToWorld({ physicsWorld: world } as any);
|
|
92
|
+
// const ball = factory.createRigidBody({
|
|
93
|
+
// shape: { shape: 'SPHERE', radius: 1 },
|
|
94
|
+
// body: { dynamic: true, mass: 1 },
|
|
95
|
+
// }, { position: { x: 0, y: 0, z: 0 } });
|
|
96
|
+
// ball.addToWorld({ physicsWorld: world } as any);
|
|
97
|
+
// let exitRegistered = false;
|
|
98
|
+
// trigger.onEntityLeft.subscribe(((obj) => {
|
|
99
|
+
// exitRegistered = obj === ball;
|
|
100
|
+
// }));
|
|
101
|
+
// world.simulate(1000);
|
|
102
|
+
// trigger.checkOverlaps();
|
|
103
|
+
// trigger.removeFromWorld({ physicsWorld: world } as any);
|
|
104
|
+
// expect(exitRegistered).toBe(true);
|
|
105
|
+
// });
|
|
106
|
+
//
|
|
107
|
+
// it(`should fire end of object intersection if object removed`, async () => {
|
|
108
|
+
// const trigger = factory.createTrigger({ shape: 'BOX', dimensions: { x: 10, y: 10, z: 10 } });
|
|
109
|
+
// trigger.addToWorld({ physicsWorld: world } as any);
|
|
110
|
+
// const ball = factory.createRigidBody({
|
|
111
|
+
// shape: { shape: 'SPHERE', radius: 1 },
|
|
112
|
+
// body: { dynamic: true, mass: 1 },
|
|
113
|
+
// }, { position: { x: 0, y: 0, z: 0 } });
|
|
114
|
+
// ball.addToWorld({ physicsWorld: world } as any);
|
|
115
|
+
// let exitRegistered = false;
|
|
116
|
+
// trigger.onEntityLeft.subscribe(((obj) => {
|
|
117
|
+
// exitRegistered = obj === ball;
|
|
118
|
+
// }));
|
|
119
|
+
// world.simulate(1000);
|
|
120
|
+
// trigger.checkOverlaps();
|
|
121
|
+
// ball.removeFromWorld({ physicsWorld: world } as any);
|
|
122
|
+
// expect(exitRegistered).toBe(true);
|
|
123
|
+
// });
|
|
124
|
+
});
|