@gg-web-engine/rapier3d 0.0.73 → 0.0.74
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.
|
@@ -86,5 +86,8 @@ export declare class Rapier3dRigidBodyComponent implements IRigidBody3dComponent
|
|
|
86
86
|
addToWorld(world: Rapier3dGgWorld): void;
|
|
87
87
|
removeFromWorld(world: Rapier3dGgWorld, dispose?: boolean): void;
|
|
88
88
|
resetMotion(): void;
|
|
89
|
+
get isSleeping(): boolean;
|
|
90
|
+
wakeUp(): void;
|
|
91
|
+
sleep(): void;
|
|
89
92
|
dispose(): void;
|
|
90
93
|
}
|
|
@@ -199,7 +199,7 @@ export class Rapier3dRigidBodyComponent {
|
|
|
199
199
|
this.debugBodySettings = new DebugBody3DSettings(this._bodyDescr.status == RigidBodyType.Fixed
|
|
200
200
|
? { type: 'RIGID_STATIC' }
|
|
201
201
|
: this._bodyDescr.status == RigidBodyType.Dynamic
|
|
202
|
-
? { type: 'RIGID_DYNAMIC', sleeping: () =>
|
|
202
|
+
? { type: 'RIGID_DYNAMIC', sleeping: () => this.isSleeping }
|
|
203
203
|
: { type: 'RIGID_KINEMATIC' }, this.shape);
|
|
204
204
|
this._nativeBody = null;
|
|
205
205
|
this._nativeBodyColliders = null;
|
|
@@ -313,6 +313,24 @@ export class Rapier3dRigidBodyComponent {
|
|
|
313
313
|
this._nativeBody.setAngvel(new Vector3(0, 0, 0), false);
|
|
314
314
|
this._nativeBody.setLinvel(new Vector3(0, 0, 0), false);
|
|
315
315
|
}
|
|
316
|
+
get isSleeping() {
|
|
317
|
+
var _a;
|
|
318
|
+
return this._bodyDescr.status !== RigidBodyType.Fixed && !!((_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.isSleeping());
|
|
319
|
+
}
|
|
320
|
+
wakeUp() {
|
|
321
|
+
var _a;
|
|
322
|
+
if (this._bodyDescr.status === RigidBodyType.Fixed) {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
(_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.wakeUp();
|
|
326
|
+
}
|
|
327
|
+
sleep() {
|
|
328
|
+
var _a;
|
|
329
|
+
if (this._bodyDescr.status === RigidBodyType.Fixed) {
|
|
330
|
+
return;
|
|
331
|
+
}
|
|
332
|
+
(_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.sleep();
|
|
333
|
+
}
|
|
316
334
|
dispose() {
|
|
317
335
|
if (this.nativeBody) {
|
|
318
336
|
this.removeFromWorld({ physicsWorld: this.world }, true);
|
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.74",
|
|
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,8 +27,8 @@
|
|
|
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.
|
|
30
|
+
"@dimforge/rapier3d-compat": "0.21.0",
|
|
31
|
+
"@gg-web-engine/core": "0.0.74",
|
|
32
32
|
"@types/jest": "^30.0.0",
|
|
33
33
|
"@types/node": "^26.4.0",
|
|
34
34
|
"jest": "^30.5.0",
|
|
@@ -39,8 +39,8 @@
|
|
|
39
39
|
"typescript": "~6.0.3"
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
|
-
"@dimforge/rapier3d-compat": "0.
|
|
43
|
-
"@gg-web-engine/core": "0.0.
|
|
42
|
+
"@dimforge/rapier3d-compat": "0.21.0",
|
|
43
|
+
"@gg-web-engine/core": "0.0.74",
|
|
44
44
|
"rxjs": "7.8.2"
|
|
45
45
|
},
|
|
46
46
|
"jest": {
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Pnt3 } from '@gg-web-engine/core';
|
|
2
|
+
import { Rapier3dFactory, Rapier3dWorldComponent } from '../../src';
|
|
3
|
+
|
|
4
|
+
describe('Rapier3dRigidBodyComponent sleep API', () => {
|
|
5
|
+
let world: Rapier3dWorldComponent;
|
|
6
|
+
let factory: Rapier3dFactory;
|
|
7
|
+
|
|
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('reports a fresh dynamic body as not sleeping', () => {
|
|
23
|
+
const body = factory.createRigidBody(
|
|
24
|
+
{ shape: { shape: 'SPHERE', radius: 1 }, body: { bodyType: 'dynamic', mass: 1 } },
|
|
25
|
+
{ position: { x: 0, y: 0, z: 0 } },
|
|
26
|
+
);
|
|
27
|
+
body.addToWorld({ physicsWorld: world } as any);
|
|
28
|
+
|
|
29
|
+
expect(body.isSleeping).toBe(false);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it('sleep() forces isSleeping true, wakeUp() flips it back', () => {
|
|
33
|
+
const body = factory.createRigidBody(
|
|
34
|
+
{ shape: { shape: 'SPHERE', radius: 1 }, body: { bodyType: 'dynamic', mass: 1 } },
|
|
35
|
+
{ position: { x: 0, y: 0, z: 0 } },
|
|
36
|
+
);
|
|
37
|
+
body.addToWorld({ physicsWorld: world } as any);
|
|
38
|
+
|
|
39
|
+
body.sleep();
|
|
40
|
+
expect(body.isSleeping).toBe(true);
|
|
41
|
+
|
|
42
|
+
body.wakeUp();
|
|
43
|
+
expect(body.isSleeping).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('a position write on a sleeping body wakes it back up', () => {
|
|
47
|
+
const body = factory.createRigidBody(
|
|
48
|
+
{ shape: { shape: 'SPHERE', radius: 1 }, body: { bodyType: 'dynamic', mass: 1 } },
|
|
49
|
+
{ position: { x: 0, y: 0, z: 0 } },
|
|
50
|
+
);
|
|
51
|
+
body.addToWorld({ physicsWorld: world } as any);
|
|
52
|
+
|
|
53
|
+
body.sleep();
|
|
54
|
+
expect(body.isSleeping).toBe(true);
|
|
55
|
+
|
|
56
|
+
body.position = { x: 1, y: 2, z: 3 };
|
|
57
|
+
expect(body.isSleeping).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('a static body always reports not sleeping, and sleep()/wakeUp() are no-ops', () => {
|
|
61
|
+
const floor = factory.createRigidBody(
|
|
62
|
+
{ shape: { shape: 'BOX', dimensions: { x: 10, y: 10, z: 1 } }, body: { bodyType: 'static' } },
|
|
63
|
+
{ position: { x: 0, y: 0, z: 0 } },
|
|
64
|
+
);
|
|
65
|
+
floor.addToWorld({ physicsWorld: world } as any);
|
|
66
|
+
|
|
67
|
+
expect(floor.isSleeping).toBe(false);
|
|
68
|
+
|
|
69
|
+
floor.sleep();
|
|
70
|
+
expect(floor.isSleeping).toBe(false);
|
|
71
|
+
|
|
72
|
+
floor.wakeUp();
|
|
73
|
+
expect(floor.isSleeping).toBe(false);
|
|
74
|
+
});
|
|
75
|
+
});
|