@gg-web-engine/ammo 0.0.37 → 0.0.38
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/components/ammo-raycast-vehicle.component.d.ts +1 -0
- package/dist/components/ammo-raycast-vehicle.component.js +6 -0
- package/dist/components/ammo-rigid-body.component.js +28 -4
- package/dist/components/ammo-world.component.d.ts +2 -0
- package/dist/components/ammo-world.component.js +4 -0
- package/package.json +6 -4
|
@@ -41,12 +41,14 @@ export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
|
|
|
41
41
|
if (world.physicsWorld != this.world) {
|
|
42
42
|
throw new Error('Ammo raycast vehicle cannot be shared between different worlds');
|
|
43
43
|
}
|
|
44
|
+
this.addedToWorld = true;
|
|
44
45
|
// TODO parked cars can be deactivated until we start handling them. Needs explicit activation call
|
|
45
46
|
this.chassisBody.nativeBody.setActivationState(4); // btCollisionObject::DISABLE_DEACTIVATION
|
|
46
47
|
this.chassisBody.addToWorld(world);
|
|
47
48
|
this.world.dynamicAmmoWorld.addAction(this.nativeVehicle);
|
|
48
49
|
}
|
|
49
50
|
removeFromWorld(world) {
|
|
51
|
+
this.addedToWorld = false;
|
|
50
52
|
this.chassisBody.removeFromWorld(world);
|
|
51
53
|
this.world.dynamicAmmoWorld.removeAction(this.nativeVehicle);
|
|
52
54
|
}
|
|
@@ -95,4 +97,8 @@ export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
|
|
|
95
97
|
clone() {
|
|
96
98
|
return new AmmoRaycastVehicleComponent(this.world, this.chassisBody.clone());
|
|
97
99
|
}
|
|
100
|
+
resetMotion() {
|
|
101
|
+
this.resetSuspension();
|
|
102
|
+
super.resetMotion();
|
|
103
|
+
}
|
|
98
104
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Ammo from '../ammo.js/ammo';
|
|
2
2
|
import { AmmoBodyComponent } from './ammo-body.component';
|
|
3
|
+
import { first } from 'rxjs';
|
|
3
4
|
export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
4
5
|
constructor(world, _nativeBody) {
|
|
5
6
|
super(world, _nativeBody);
|
|
@@ -49,10 +50,33 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
49
50
|
}
|
|
50
51
|
resetMotion() {
|
|
51
52
|
const emptyVector = new Ammo.btVector3();
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (!this.addedToWorld) {
|
|
54
|
+
this.nativeBody.clearForces();
|
|
55
|
+
this.nativeBody.setLinearVelocity(emptyVector);
|
|
56
|
+
this.nativeBody.setAngularVelocity(emptyVector);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
// when resetting object motion state in ammo.js while it's added to the simulation,
|
|
60
|
+
// on the next tick it randomly gets broken (linear velocity vector has NaN components and then position too)
|
|
61
|
+
// By removing and adding the object to the world it happens less often
|
|
62
|
+
const ammoWorld = this.world;
|
|
63
|
+
this.removeFromWorld({ physicsWorld: ammoWorld });
|
|
64
|
+
const position = this.position;
|
|
65
|
+
const rotation = this.rotation;
|
|
66
|
+
this.nativeBody.clearForces();
|
|
67
|
+
this.nativeBody.setLinearVelocity(emptyVector);
|
|
68
|
+
this.nativeBody.setAngularVelocity(emptyVector);
|
|
69
|
+
this.world.afterTick$.pipe(first()).subscribe(() => {
|
|
70
|
+
this.addToWorld({ physicsWorld: ammoWorld });
|
|
71
|
+
const newLinVel = this.linearVelocity;
|
|
72
|
+
if (isNaN(newLinVel.x) || isNaN(newLinVel.y) || isNaN(newLinVel.z)) {
|
|
73
|
+
console.warn('resetMotion caused ammo body to have broken velocity. Fixing');
|
|
74
|
+
this.position = position;
|
|
75
|
+
this.rotation = rotation;
|
|
76
|
+
this.resetMotion();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
56
80
|
Ammo.destroy(emptyVector);
|
|
57
81
|
}
|
|
58
82
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CollisionGroup, Gg3dWorld, IDebugPhysicsDrawer, IPhysicsWorld3dComponent, Point3, Point4, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
2
3
|
import Ammo from '../ammo.js/ammo';
|
|
3
4
|
import { AmmoFactory } from '../ammo-factory';
|
|
4
5
|
import { AmmoLoader } from '../ammo-loader';
|
|
@@ -6,6 +7,7 @@ import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
|
6
7
|
export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<AmmoPhysicsTypeDocRepo> {
|
|
7
8
|
private _factory;
|
|
8
9
|
get factory(): AmmoFactory;
|
|
10
|
+
afterTick$: Subject<void>;
|
|
9
11
|
private _loader;
|
|
10
12
|
get loader(): AmmoLoader;
|
|
11
13
|
private _gravity;
|
|
@@ -7,6 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
+
import { Subject } from 'rxjs';
|
|
10
11
|
import Ammo from '../ammo.js/ammo';
|
|
11
12
|
import { AmmoFactory } from '../ammo-factory';
|
|
12
13
|
import { AmmoLoader } from '../ammo-loader';
|
|
@@ -14,6 +15,7 @@ import { AmmoDebugger, AmmoDebugMode } from '../ammo-debugger';
|
|
|
14
15
|
export class AmmoWorldComponent {
|
|
15
16
|
constructor() {
|
|
16
17
|
this._factory = null;
|
|
18
|
+
this.afterTick$ = new Subject();
|
|
17
19
|
this._loader = null;
|
|
18
20
|
this._gravity = { x: 0, y: 0, z: -9.82 };
|
|
19
21
|
this._timeScale = 1;
|
|
@@ -78,6 +80,7 @@ export class AmmoWorldComponent {
|
|
|
78
80
|
simulate(delta) {
|
|
79
81
|
var _a;
|
|
80
82
|
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation((this._timeScale * delta) / 1000, 100, this._timeScale * 0.01);
|
|
83
|
+
this.afterTick$.next();
|
|
81
84
|
if (this._debugger) {
|
|
82
85
|
this._debugger.update();
|
|
83
86
|
}
|
|
@@ -118,6 +121,7 @@ export class AmmoWorldComponent {
|
|
|
118
121
|
}
|
|
119
122
|
}
|
|
120
123
|
dispose() {
|
|
124
|
+
this.afterTick$.complete();
|
|
121
125
|
Ammo.destroy(this._dynamicAmmoWorld);
|
|
122
126
|
Ammo.destroy(this.solver);
|
|
123
127
|
Ammo.destroy(this.broadphase);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gg-web-engine/ammo",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.38",
|
|
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",
|
|
@@ -34,18 +34,20 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
|
-
"@gg-web-engine/core": "0.0.
|
|
37
|
+
"@gg-web-engine/core": "0.0.38",
|
|
38
38
|
"@types/jest": "^29.5.0",
|
|
39
39
|
"jest": "^29.5.0",
|
|
40
40
|
"jest-environment-jsdom": "^29.5.0",
|
|
41
41
|
"mini-signals": "2.0.0",
|
|
42
42
|
"prettier": "^2.8.6",
|
|
43
|
+
"rxjs": "7.8.1",
|
|
43
44
|
"ts-jest": "^29.0.5",
|
|
44
45
|
"typescript": "~4.7.2"
|
|
45
46
|
},
|
|
46
47
|
"peerDependencies": {
|
|
47
|
-
"@gg-web-engine/core": "0.0.
|
|
48
|
-
"mini-signals": "2.0.0"
|
|
48
|
+
"@gg-web-engine/core": "0.0.38",
|
|
49
|
+
"mini-signals": "2.0.0",
|
|
50
|
+
"rxjs": "7.8.1"
|
|
49
51
|
},
|
|
50
52
|
"jest": {
|
|
51
53
|
"rootDir": ".",
|