@gg-web-engine/rapier3d 0.0.76 → 0.0.78
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.
|
@@ -101,6 +101,7 @@ export class Rapier3dRigidBodyComponent {
|
|
|
101
101
|
friction: this._colliderOptions.friction,
|
|
102
102
|
restitution: this._colliderOptions.restitution,
|
|
103
103
|
ccd: this._bodyDescr.ccdEnabled,
|
|
104
|
+
canSleep: this._bodyDescr.canSleep,
|
|
104
105
|
ownCollisionGroups: this.ownCollisionGroups,
|
|
105
106
|
interactWithCollisionGroups: this.interactWithCollisionGroups,
|
|
106
107
|
};
|
|
@@ -186,6 +187,7 @@ export class Rapier3dRigidBodyComponent {
|
|
|
186
187
|
// just a constructor-only `setCcdEnabled` call - carry it over explicitly so `clone()` doesn't
|
|
187
188
|
// silently drop CCD off the copy.
|
|
188
189
|
bd.setCcdEnabled(this._bodyDescr.ccdEnabled);
|
|
190
|
+
bd.setCanSleep(this._bodyDescr.canSleep);
|
|
189
191
|
// TODO more fields here?
|
|
190
192
|
return [colliderDescr, this.shape, bd, this._colliderOptions];
|
|
191
193
|
}
|
|
@@ -326,7 +328,7 @@ export class Rapier3dRigidBodyComponent {
|
|
|
326
328
|
}
|
|
327
329
|
sleep() {
|
|
328
330
|
var _a;
|
|
329
|
-
if (this._bodyDescr.status === RigidBodyType.Fixed) {
|
|
331
|
+
if (this._bodyDescr.status === RigidBodyType.Fixed || !this._bodyDescr.canSleep) {
|
|
330
332
|
return;
|
|
331
333
|
}
|
|
332
334
|
(_a = this._nativeBody) === null || _a === void 0 ? void 0 : _a.sleep();
|
|
@@ -30,7 +30,7 @@ export class Rapier3dFactory {
|
|
|
30
30
|
// ordinary rigid-body-vs-rigid-body contact needs it here too, since neither side had it before).
|
|
31
31
|
const colliderDescr = this.createColliderDescr(descriptor.shape);
|
|
32
32
|
colliderDescr.forEach(c => c.setActiveEvents(ActiveEvents.COLLISION_EVENTS));
|
|
33
|
-
return new Rapier3dRigidBodyComponent(this.world, colliderDescr, descriptor.shape, this.createRigidBodyDescr(descriptor.body, transform, colliderDescr), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: [this.world.mainCollisionGroup], interactWithCollisionGroups: [this.world.mainCollisionGroup], ccd: false }, descriptor.body));
|
|
33
|
+
return new Rapier3dRigidBodyComponent(this.world, colliderDescr, descriptor.shape, this.createRigidBodyDescr(descriptor.body, transform, colliderDescr), Object.assign({ friction: 0.5, restitution: 0.1, ownCollisionGroups: [this.world.mainCollisionGroup], interactWithCollisionGroups: [this.world.mainCollisionGroup], ccd: false, canSleep: true }, descriptor.body));
|
|
34
34
|
}
|
|
35
35
|
createTrigger(descriptor, transform) {
|
|
36
36
|
const colliderDescr = this.createColliderDescr(descriptor);
|
|
@@ -167,6 +167,7 @@ export class Rapier3dFactory {
|
|
|
167
167
|
// or kinematic body is never the one doing the moving-too-fast-to-detect part of that, so CCD
|
|
168
168
|
// is meaningless for either (see `BodyOptions.ccd`'s own doc).
|
|
169
169
|
bodyDesc.setCcdEnabled(!!options.ccd);
|
|
170
|
+
bodyDesc.setCanSleep(options.canSleep !== false);
|
|
170
171
|
}
|
|
171
172
|
return bodyDesc.setTranslation(pos.x, pos.y, pos.z).setRotation(new Quaternion(rot.x, rot.y, rot.z, rot.w));
|
|
172
173
|
}
|
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.78",
|
|
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",
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"homepage": "https://github.com/AndyGura/gg-web-engine#readme",
|
|
29
29
|
"devDependencies": {
|
|
30
30
|
"@dimforge/rapier3d-compat": "0.21.0",
|
|
31
|
-
"@gg-web-engine/core": "0.0.
|
|
31
|
+
"@gg-web-engine/core": "0.0.78",
|
|
32
32
|
"@types/jest": "^30.0.0",
|
|
33
33
|
"@types/node": "^26.4.0",
|
|
34
34
|
"jest": "^30.5.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
},
|
|
41
41
|
"peerDependencies": {
|
|
42
42
|
"@dimforge/rapier3d-compat": "0.21.0",
|
|
43
|
-
"@gg-web-engine/core": "0.0.
|
|
43
|
+
"@gg-web-engine/core": "0.0.78",
|
|
44
44
|
"rxjs": "7.8.2"
|
|
45
45
|
},
|
|
46
46
|
"jest": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SuspensionOptions, WheelOptions } from '@gg-web-engine/core';
|
|
2
2
|
import { Rapier3dFactory, Rapier3dRaycastVehicleComponent, Rapier3dRigidBodyComponent, Rapier3dWorldComponent } from '../../src';
|
|
3
3
|
|
|
4
|
-
// Shared suspension/wheel setup mirroring examples/
|
|
4
|
+
// Shared suspension/wheel setup mirroring examples/3d/raycast-vehicle - see that example
|
|
5
5
|
// for the full car setup.
|
|
6
6
|
const suspension: SuspensionOptions = {
|
|
7
7
|
compression: 4.4,
|
|
@@ -72,4 +72,34 @@ describe('Rapier3dRigidBodyComponent sleep API', () => {
|
|
|
72
72
|
floor.wakeUp();
|
|
73
73
|
expect(floor.isSleeping).toBe(false);
|
|
74
74
|
});
|
|
75
|
+
|
|
76
|
+
describe('canSleep', () => {
|
|
77
|
+
const restFor = (seconds: number) => {
|
|
78
|
+
for (let i = 0; i < seconds * 60; i++) {
|
|
79
|
+
world.simulate(1000 / 60);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
it('lets a resting dynamic body fall asleep by default', () => {
|
|
84
|
+
const body = factory.createRigidBody({ shape: { shape: 'SPHERE', radius: 1 }, body: { bodyType: 'dynamic', mass: 1 } }, { position: { x: 0, y: 0, z: 0 } });
|
|
85
|
+
body.addToWorld({ physicsWorld: world } as any);
|
|
86
|
+
|
|
87
|
+
restFor(5);
|
|
88
|
+
expect(body.bodyOptions.canSleep).toBe(true);
|
|
89
|
+
expect(body.isSleeping).toBe(true);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('keeps a canSleep: false body awake while resting, and sleep() is a no-op on it', () => {
|
|
93
|
+
const body = factory.createRigidBody({ shape: { shape: 'SPHERE', radius: 1 }, body: { bodyType: 'dynamic', mass: 1, canSleep: false } }, { position: { x: 0, y: 0, z: 0 } });
|
|
94
|
+
body.addToWorld({ physicsWorld: world } as any);
|
|
95
|
+
|
|
96
|
+
restFor(5);
|
|
97
|
+
expect(body.isSleeping).toBe(false);
|
|
98
|
+
|
|
99
|
+
body.sleep();
|
|
100
|
+
expect(body.isSleeping).toBe(false);
|
|
101
|
+
expect(body.bodyOptions.canSleep).toBe(false);
|
|
102
|
+
expect(body.clone().bodyOptions.canSleep).toBe(false);
|
|
103
|
+
});
|
|
104
|
+
});
|
|
75
105
|
});
|