@gg-web-engine/ammo 0.0.37 → 0.0.39
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/ammo-factory.d.ts +2 -2
- package/dist/ammo-factory.js +9 -9
- package/dist/components/ammo-body.component.d.ts +3 -2
- package/dist/components/ammo-body.component.js +5 -2
- package/dist/components/ammo-raycast-vehicle.component.d.ts +1 -0
- package/dist/components/ammo-raycast-vehicle.component.js +9 -1
- package/dist/components/ammo-rigid-body.component.d.ts +4 -2
- package/dist/components/ammo-rigid-body.component.js +42 -9
- package/dist/components/ammo-trigger.component.d.ts +4 -2
- package/dist/components/ammo-trigger.component.js +8 -4
- package/dist/components/ammo-world.component.d.ts +9 -9
- package/dist/components/ammo-world.component.js +10 -43
- package/package.json +6 -4
- package/dist/ammo-debugger.d.ts +0 -38
- package/dist/ammo-debugger.js +0 -77
package/dist/ammo-factory.d.ts
CHANGED
|
@@ -18,11 +18,11 @@ export declare class AmmoFactory implements IPhysicsBody3dComponentFactory<AmmoP
|
|
|
18
18
|
}): AmmoTriggerComponent;
|
|
19
19
|
createRaycastVehicle(chassis: AmmoRigidBodyComponent): AmmoRaycastVehicleComponent;
|
|
20
20
|
protected createShape(descriptor: Shape3DDescriptor): Ammo.btCollisionShape;
|
|
21
|
-
createRigidBodyFromShape(
|
|
21
|
+
createRigidBodyFromShape(nativeShape: Ammo.btCollisionShape, shapeDescr: Shape3DDescriptor, options: Partial<Body3DOptions>, transform?: {
|
|
22
22
|
position?: Point3;
|
|
23
23
|
rotation?: Point4;
|
|
24
24
|
}): AmmoRigidBodyComponent;
|
|
25
|
-
createTriggerFromShape(
|
|
25
|
+
createTriggerFromShape(nativeShape: Ammo.btCollisionShape, shapeDescr: Shape3DDescriptor, transform?: {
|
|
26
26
|
position?: Point3;
|
|
27
27
|
rotation?: Point4;
|
|
28
28
|
}): AmmoTriggerComponent;
|
package/dist/ammo-factory.js
CHANGED
|
@@ -8,10 +8,10 @@ export class AmmoFactory {
|
|
|
8
8
|
this.world = world;
|
|
9
9
|
}
|
|
10
10
|
createRigidBody(descriptor, transform) {
|
|
11
|
-
return this.createRigidBodyFromShape(this.createShape(descriptor.shape), descriptor.body, transform);
|
|
11
|
+
return this.createRigidBodyFromShape(this.createShape(descriptor.shape), descriptor.shape, descriptor.body, transform);
|
|
12
12
|
}
|
|
13
13
|
createTrigger(descriptor, transform) {
|
|
14
|
-
return this.createTriggerFromShape(this.createShape(descriptor), transform);
|
|
14
|
+
return this.createTriggerFromShape(this.createShape(descriptor), descriptor, transform);
|
|
15
15
|
}
|
|
16
16
|
createRaycastVehicle(chassis) {
|
|
17
17
|
return new AmmoRaycastVehicleComponent(this.world, chassis);
|
|
@@ -75,7 +75,7 @@ export class AmmoFactory {
|
|
|
75
75
|
}
|
|
76
76
|
throw new Error(`Shape "${descriptor.shape}" not implemented for Ammo.js`);
|
|
77
77
|
}
|
|
78
|
-
createRigidBodyFromShape(
|
|
78
|
+
createRigidBodyFromShape(nativeShape, shapeDescr, options, transform) {
|
|
79
79
|
if (options.dynamic === false) {
|
|
80
80
|
options.mass = 0;
|
|
81
81
|
}
|
|
@@ -86,8 +86,8 @@ export class AmmoFactory {
|
|
|
86
86
|
ammoTransform.setRotation(new Ammo.btQuaternion(rot.x, rot.y, rot.z, rot.w));
|
|
87
87
|
const motionState = new Ammo.btDefaultMotionState(ammoTransform);
|
|
88
88
|
const localInertia = new Ammo.btVector3(0, 0, 0);
|
|
89
|
-
|
|
90
|
-
const environmentBodyCI = new Ammo.btRigidBodyConstructionInfo(options.mass || 0, motionState,
|
|
89
|
+
nativeShape.calculateLocalInertia(options.mass || 0, localInertia);
|
|
90
|
+
const environmentBodyCI = new Ammo.btRigidBodyConstructionInfo(options.mass || 0, motionState, nativeShape, localInertia);
|
|
91
91
|
if (options.friction) {
|
|
92
92
|
environmentBodyCI.set_m_friction(options.friction);
|
|
93
93
|
environmentBodyCI.set_m_rollingFriction(options.friction);
|
|
@@ -95,7 +95,7 @@ export class AmmoFactory {
|
|
|
95
95
|
if (options.restitution) {
|
|
96
96
|
environmentBodyCI.set_m_restitution(options.restitution);
|
|
97
97
|
}
|
|
98
|
-
const comp = new AmmoRigidBodyComponent(this.world, new Ammo.btRigidBody(environmentBodyCI));
|
|
98
|
+
const comp = new AmmoRigidBodyComponent(this.world, new Ammo.btRigidBody(environmentBodyCI), shapeDescr);
|
|
99
99
|
if (options.ownCollisionGroups && options.ownCollisionGroups !== 'all') {
|
|
100
100
|
comp.ownCollisionGroups = options.ownCollisionGroups;
|
|
101
101
|
}
|
|
@@ -104,10 +104,10 @@ export class AmmoFactory {
|
|
|
104
104
|
}
|
|
105
105
|
return comp;
|
|
106
106
|
}
|
|
107
|
-
createTriggerFromShape(
|
|
107
|
+
createTriggerFromShape(nativeShape, shapeDescr, transform) {
|
|
108
108
|
var _a, _b, _c, _d, _e, _f, _g;
|
|
109
109
|
const ghostObject = new Ammo.btPairCachingGhostObject();
|
|
110
|
-
ghostObject.setCollisionShape(
|
|
110
|
+
ghostObject.setCollisionShape(nativeShape);
|
|
111
111
|
ghostObject.setCollisionFlags(ghostObject.getCollisionFlags() | 4); // 4 is a CF_NO_CONTACT_RESPONSE collision flag
|
|
112
112
|
ghostObject
|
|
113
113
|
.getWorldTransform()
|
|
@@ -115,6 +115,6 @@ export class AmmoFactory {
|
|
|
115
115
|
ghostObject
|
|
116
116
|
.getWorldTransform()
|
|
117
117
|
.setRotation(new Ammo.btQuaternion(((_d = transform === null || transform === void 0 ? void 0 : transform.rotation) === null || _d === void 0 ? void 0 : _d.x) || 0, ((_e = transform === null || transform === void 0 ? void 0 : transform.rotation) === null || _e === void 0 ? void 0 : _e.y) || 0, ((_f = transform === null || transform === void 0 ? void 0 : transform.rotation) === null || _f === void 0 ? void 0 : _f.z) || 0, ((_g = transform === null || transform === void 0 ? void 0 : transform.rotation) === null || _g === void 0 ? void 0 : _g.w) || 1));
|
|
118
|
-
return new AmmoTriggerComponent(this.world, ghostObject);
|
|
118
|
+
return new AmmoTriggerComponent(this.world, ghostObject, shapeDescr);
|
|
119
119
|
}
|
|
120
120
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { CollisionGroup, Gg3dWorld, IEntity, Point3, Point4, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
1
|
+
import { CollisionGroup, Gg3dWorld, IEntity, Point3, Point4, Shape3DDescriptor, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
2
2
|
import { AmmoWorldComponent } from './ammo-world.component';
|
|
3
3
|
import Ammo from '../ammo.js/ammo';
|
|
4
4
|
import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
5
5
|
export declare abstract class AmmoBodyComponent<T extends Ammo.btCollisionObject> {
|
|
6
6
|
protected readonly world: AmmoWorldComponent;
|
|
7
7
|
protected _nativeBody: T;
|
|
8
|
+
readonly shape: Shape3DDescriptor;
|
|
8
9
|
protected static nativeBodyReverseMap: Map<number, AmmoBodyComponent<any>>;
|
|
9
10
|
get position(): Point3;
|
|
10
11
|
set position(value: Point3);
|
|
@@ -22,7 +23,7 @@ export declare abstract class AmmoBodyComponent<T extends Ammo.btCollisionObject
|
|
|
22
23
|
set interactWithCollisionGroups(value: CollisionGroup[] | 'all');
|
|
23
24
|
get ownCollisionGroups(): CollisionGroup[];
|
|
24
25
|
set ownCollisionGroups(value: CollisionGroup[] | 'all');
|
|
25
|
-
protected constructor(world: AmmoWorldComponent, _nativeBody: T);
|
|
26
|
+
protected constructor(world: AmmoWorldComponent, _nativeBody: T, shape: Shape3DDescriptor);
|
|
26
27
|
abstract clone(): AmmoBodyComponent<T>;
|
|
27
28
|
addToWorld(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
28
29
|
removeFromWorld(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { BitMask } from '@gg-web-engine/core';
|
|
1
|
+
import { BitMask, } from '@gg-web-engine/core';
|
|
2
2
|
import Ammo from '../ammo.js/ammo';
|
|
3
3
|
export class AmmoBodyComponent {
|
|
4
|
-
constructor(world, _nativeBody) {
|
|
4
|
+
constructor(world, _nativeBody, shape) {
|
|
5
5
|
this.world = world;
|
|
6
6
|
this._nativeBody = _nativeBody;
|
|
7
|
+
this.shape = shape;
|
|
7
8
|
this.name = '';
|
|
8
9
|
this.addedToWorld = false;
|
|
9
10
|
this._interactWithCGsMask = BitMask.full(16);
|
|
@@ -80,12 +81,14 @@ export class AmmoBodyComponent {
|
|
|
80
81
|
throw new Error('Ammo bodies cannot be shared between different worlds');
|
|
81
82
|
}
|
|
82
83
|
this.addedToWorld = true;
|
|
84
|
+
this.world.added$.next(this);
|
|
83
85
|
}
|
|
84
86
|
removeFromWorld(world) {
|
|
85
87
|
if (world.physicsWorld != this.world) {
|
|
86
88
|
throw new Error('Ammo bodies cannot be shared between different worlds');
|
|
87
89
|
}
|
|
88
90
|
this.addedToWorld = false;
|
|
91
|
+
this.world.removed$.next(this);
|
|
89
92
|
}
|
|
90
93
|
dispose() {
|
|
91
94
|
try {
|
|
@@ -3,7 +3,7 @@ import Ammo from '../ammo.js/ammo';
|
|
|
3
3
|
import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
|
|
4
4
|
export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
|
|
5
5
|
constructor(world, chassisBody) {
|
|
6
|
-
super(world, chassisBody.nativeBody);
|
|
6
|
+
super(world, chassisBody.nativeBody, chassisBody.shape);
|
|
7
7
|
this.world = world;
|
|
8
8
|
this.chassisBody = chassisBody;
|
|
9
9
|
this.vehicleTuning = new Ammo.btVehicleTuning();
|
|
@@ -41,14 +41,18 @@ 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);
|
|
49
|
+
this.world.added$.next(this);
|
|
48
50
|
}
|
|
49
51
|
removeFromWorld(world) {
|
|
52
|
+
this.addedToWorld = false;
|
|
50
53
|
this.chassisBody.removeFromWorld(world);
|
|
51
54
|
this.world.dynamicAmmoWorld.removeAction(this.nativeVehicle);
|
|
55
|
+
this.world.removed$.next(this);
|
|
52
56
|
}
|
|
53
57
|
addWheel(options, suspensionOptions) {
|
|
54
58
|
const wheelInfo = this.nativeVehicle.addWheel(new Ammo.btVector3(options.position.x, options.position.y, options.position.z), this.wheelDirectionCS0, this.wheelAxleCS, suspensionOptions.restLength, options.tyreRadius, this.vehicleTuning, options.isFront);
|
|
@@ -95,4 +99,8 @@ export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
|
|
|
95
99
|
clone() {
|
|
96
100
|
return new AmmoRaycastVehicleComponent(this.world, this.chassisBody.clone());
|
|
97
101
|
}
|
|
102
|
+
resetMotion() {
|
|
103
|
+
this.resetSuspension();
|
|
104
|
+
super.resetMotion();
|
|
105
|
+
}
|
|
98
106
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { AmmoWorldComponent } from './ammo-world.component';
|
|
2
2
|
import Ammo from '../ammo.js/ammo';
|
|
3
3
|
import { AmmoBodyComponent } from './ammo-body.component';
|
|
4
|
-
import { Entity3d, Gg3dWorld, IRigidBody3dComponent, Point3, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
4
|
+
import { DebugBody3DSettings, Entity3d, Gg3dWorld, IRigidBody3dComponent, Point3, Shape3DDescriptor, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
5
5
|
import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
6
6
|
export declare class AmmoRigidBodyComponent extends AmmoBodyComponent<Ammo.btRigidBody> implements IRigidBody3dComponent<AmmoPhysicsTypeDocRepo> {
|
|
7
7
|
protected readonly world: AmmoWorldComponent;
|
|
8
8
|
protected _nativeBody: Ammo.btRigidBody;
|
|
9
|
+
readonly shape: Shape3DDescriptor;
|
|
9
10
|
entity: Entity3d | null;
|
|
10
11
|
get linearVelocity(): Point3;
|
|
11
12
|
set linearVelocity(value: Point3);
|
|
12
13
|
get angularVelocity(): Point3;
|
|
13
14
|
set angularVelocity(value: Point3);
|
|
14
|
-
|
|
15
|
+
get debugBodySettings(): DebugBody3DSettings;
|
|
16
|
+
constructor(world: AmmoWorldComponent, _nativeBody: Ammo.btRigidBody, shape: Shape3DDescriptor);
|
|
15
17
|
clone(): AmmoRigidBodyComponent;
|
|
16
18
|
addToWorld(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
17
19
|
removeFromWorld(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
@@ -1,10 +1,12 @@
|
|
|
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
|
-
constructor(world, _nativeBody) {
|
|
5
|
-
super(world, _nativeBody);
|
|
5
|
+
constructor(world, _nativeBody, shape) {
|
|
6
|
+
super(world, _nativeBody, shape);
|
|
6
7
|
this.world = world;
|
|
7
8
|
this._nativeBody = _nativeBody;
|
|
9
|
+
this.shape = shape;
|
|
8
10
|
this.entity = null;
|
|
9
11
|
}
|
|
10
12
|
get linearVelocity() {
|
|
@@ -21,8 +23,16 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
21
23
|
set angularVelocity(value) {
|
|
22
24
|
this.nativeBody.setAngularVelocity(new Ammo.btVector3(value.x, value.y, value.z));
|
|
23
25
|
}
|
|
26
|
+
get debugBodySettings() {
|
|
27
|
+
if (this._nativeBody.isStaticOrKinematicObject()) {
|
|
28
|
+
return { shape: this.shape, type: 'RIGID_STATIC' };
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return { shape: this.shape, type: 'RIGID_DYNAMIC', sleeping: !this._nativeBody.isActive() };
|
|
32
|
+
}
|
|
33
|
+
}
|
|
24
34
|
clone() {
|
|
25
|
-
return this.world.factory.createRigidBodyFromShape(this._nativeBody.getCollisionShape(), {
|
|
35
|
+
return this.world.factory.createRigidBodyFromShape(this._nativeBody.getCollisionShape(), this.shape, {
|
|
26
36
|
dynamic: !this._nativeBody.isStaticOrKinematicObject(),
|
|
27
37
|
mass: this._nativeBody.getMass(),
|
|
28
38
|
friction: this._nativeBody.getFriction(),
|
|
@@ -34,13 +44,13 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
34
44
|
}
|
|
35
45
|
addToWorld(world) {
|
|
36
46
|
var _a;
|
|
37
|
-
super.addToWorld(world);
|
|
38
47
|
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.addRigidBody(this.nativeBody, this._ownCGsMask, this._interactWithCGsMask);
|
|
48
|
+
super.addToWorld(world);
|
|
39
49
|
}
|
|
40
50
|
removeFromWorld(world) {
|
|
41
51
|
var _a;
|
|
42
|
-
super.removeFromWorld(world);
|
|
43
52
|
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.removeRigidBody(this.nativeBody);
|
|
53
|
+
super.removeFromWorld(world);
|
|
44
54
|
}
|
|
45
55
|
refreshCG() {
|
|
46
56
|
var _a, _b;
|
|
@@ -49,10 +59,33 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
49
59
|
}
|
|
50
60
|
resetMotion() {
|
|
51
61
|
const emptyVector = new Ammo.btVector3();
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
62
|
+
if (!this.addedToWorld) {
|
|
63
|
+
this.nativeBody.clearForces();
|
|
64
|
+
this.nativeBody.setLinearVelocity(emptyVector);
|
|
65
|
+
this.nativeBody.setAngularVelocity(emptyVector);
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// when resetting object motion state in ammo.js while it's added to the simulation,
|
|
69
|
+
// on the next tick it randomly gets broken (linear velocity vector has NaN components and then position too)
|
|
70
|
+
// By removing and adding the object to the world it happens less often
|
|
71
|
+
const ammoWorld = this.world;
|
|
72
|
+
this.removeFromWorld({ physicsWorld: ammoWorld });
|
|
73
|
+
const position = this.position;
|
|
74
|
+
const rotation = this.rotation;
|
|
75
|
+
this.nativeBody.clearForces();
|
|
76
|
+
this.nativeBody.setLinearVelocity(emptyVector);
|
|
77
|
+
this.nativeBody.setAngularVelocity(emptyVector);
|
|
78
|
+
this.world.afterTick$.pipe(first()).subscribe(() => {
|
|
79
|
+
this.addToWorld({ physicsWorld: ammoWorld });
|
|
80
|
+
const newLinVel = this.linearVelocity;
|
|
81
|
+
if (isNaN(newLinVel.x) || isNaN(newLinVel.y) || isNaN(newLinVel.z)) {
|
|
82
|
+
console.warn('resetMotion caused ammo body to have broken velocity. Fixing');
|
|
83
|
+
this.position = position;
|
|
84
|
+
this.rotation = rotation;
|
|
85
|
+
this.resetMotion();
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
56
89
|
Ammo.destroy(emptyVector);
|
|
57
90
|
}
|
|
58
91
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Gg3dWorld, IEntity, ITrigger3dComponent, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
1
|
+
import { DebugBody3DSettings, Gg3dWorld, IEntity, ITrigger3dComponent, Shape3DDescriptor, VisualTypeDocRepo3D } from '@gg-web-engine/core';
|
|
2
2
|
import { AmmoWorldComponent } from './ammo-world.component';
|
|
3
3
|
import { Observable, Subject } from 'rxjs';
|
|
4
4
|
import Ammo from '../ammo.js/ammo';
|
|
@@ -8,10 +8,12 @@ import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
|
8
8
|
export declare class AmmoTriggerComponent extends AmmoBodyComponent<Ammo.btPairCachingGhostObject> implements ITrigger3dComponent<AmmoPhysicsTypeDocRepo> {
|
|
9
9
|
protected readonly world: AmmoWorldComponent;
|
|
10
10
|
protected _nativeBody: Ammo.btPairCachingGhostObject;
|
|
11
|
+
readonly shape: Shape3DDescriptor;
|
|
11
12
|
entity: IEntity | null;
|
|
13
|
+
get debugBodySettings(): DebugBody3DSettings;
|
|
12
14
|
get onEntityEntered(): Observable<AmmoRigidBodyComponent>;
|
|
13
15
|
get onEntityLeft(): Observable<AmmoRigidBodyComponent | null>;
|
|
14
|
-
constructor(world: AmmoWorldComponent, _nativeBody: Ammo.btPairCachingGhostObject);
|
|
16
|
+
constructor(world: AmmoWorldComponent, _nativeBody: Ammo.btPairCachingGhostObject, shape: Shape3DDescriptor);
|
|
15
17
|
protected readonly onEnter$: Subject<number>;
|
|
16
18
|
protected readonly onLeft$: Subject<number>;
|
|
17
19
|
protected readonly overlaps: Set<Ammo.btCollisionObject>;
|
|
@@ -2,15 +2,19 @@ import { filter, map, Subject } from 'rxjs';
|
|
|
2
2
|
import Ammo from '../ammo.js/ammo';
|
|
3
3
|
import { AmmoBodyComponent } from './ammo-body.component';
|
|
4
4
|
export class AmmoTriggerComponent extends AmmoBodyComponent {
|
|
5
|
-
constructor(world, _nativeBody) {
|
|
6
|
-
super(world, _nativeBody);
|
|
5
|
+
constructor(world, _nativeBody, shape) {
|
|
6
|
+
super(world, _nativeBody, shape);
|
|
7
7
|
this.world = world;
|
|
8
8
|
this._nativeBody = _nativeBody;
|
|
9
|
+
this.shape = shape;
|
|
9
10
|
this.entity = null;
|
|
10
11
|
this.onEnter$ = new Subject();
|
|
11
12
|
this.onLeft$ = new Subject();
|
|
12
13
|
this.overlaps = new Set();
|
|
13
14
|
}
|
|
15
|
+
get debugBodySettings() {
|
|
16
|
+
return { shape: this.shape, type: 'TRIGGER' };
|
|
17
|
+
}
|
|
14
18
|
get onEntityEntered() {
|
|
15
19
|
return this.onEnter$.pipe(map(b => AmmoBodyComponent.nativeBodyReverseMap.get(b)), filter(x => !!x));
|
|
16
20
|
}
|
|
@@ -35,7 +39,7 @@ export class AmmoTriggerComponent extends AmmoBodyComponent {
|
|
|
35
39
|
}
|
|
36
40
|
}
|
|
37
41
|
clone() {
|
|
38
|
-
return this.world.factory.createTriggerFromShape(this._nativeBody.getCollisionShape(), {
|
|
42
|
+
return this.world.factory.createTriggerFromShape(this._nativeBody.getCollisionShape(), this.shape, {
|
|
39
43
|
position: this.position,
|
|
40
44
|
rotation: this.rotation,
|
|
41
45
|
});
|
|
@@ -48,12 +52,12 @@ export class AmmoTriggerComponent extends AmmoBodyComponent {
|
|
|
48
52
|
}
|
|
49
53
|
removeFromWorld(world) {
|
|
50
54
|
var _a;
|
|
51
|
-
super.removeFromWorld(world);
|
|
52
55
|
for (const body of this.overlaps) {
|
|
53
56
|
this.onLeft$.next(Ammo.getPointer(body));
|
|
54
57
|
}
|
|
55
58
|
this.overlaps.clear();
|
|
56
59
|
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.removeCollisionObject(this.nativeBody);
|
|
60
|
+
super.removeFromWorld(world);
|
|
57
61
|
}
|
|
58
62
|
refreshCG() {
|
|
59
63
|
var _a, _b;
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import { CollisionGroup,
|
|
1
|
+
import { CollisionGroup, IPhysicsWorld3dComponent, Point3 } 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';
|
|
5
6
|
import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
7
|
+
import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
|
|
8
|
+
import { AmmoTriggerComponent } from './ammo-trigger.component';
|
|
6
9
|
export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<AmmoPhysicsTypeDocRepo> {
|
|
7
10
|
private _factory;
|
|
8
11
|
get factory(): AmmoFactory;
|
|
12
|
+
readonly afterTick$: Subject<void>;
|
|
13
|
+
readonly added$: Subject<AmmoRigidBodyComponent | AmmoTriggerComponent>;
|
|
14
|
+
readonly removed$: Subject<AmmoRigidBodyComponent | AmmoTriggerComponent>;
|
|
15
|
+
readonly children: (AmmoRigidBodyComponent | AmmoTriggerComponent)[];
|
|
9
16
|
private _loader;
|
|
10
17
|
get loader(): AmmoLoader;
|
|
11
18
|
private _gravity;
|
|
12
19
|
get gravity(): Point3;
|
|
13
20
|
set gravity(value: Point3);
|
|
14
|
-
private _timeScale;
|
|
15
|
-
get timeScale(): number;
|
|
16
|
-
set timeScale(value: number);
|
|
17
|
-
private _debugger;
|
|
18
|
-
private _debugDrawer;
|
|
19
|
-
get physicsDebugViewActive(): boolean;
|
|
20
21
|
get dynamicAmmoWorld(): Ammo.btDiscreteDynamicsWorld | undefined;
|
|
21
22
|
private collisionConfiguration;
|
|
22
23
|
private dispatcher;
|
|
@@ -25,12 +26,11 @@ export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<Ammo
|
|
|
25
26
|
private solver;
|
|
26
27
|
private gravityVector;
|
|
27
28
|
protected _dynamicAmmoWorld: Ammo.btDiscreteDynamicsWorld | undefined;
|
|
29
|
+
constructor();
|
|
28
30
|
init(): Promise<void>;
|
|
29
31
|
simulate(delta: number): void;
|
|
30
32
|
protected lockedCollisionGroups: number[];
|
|
31
33
|
registerCollisionGroup(): CollisionGroup;
|
|
32
34
|
deregisterCollisionGroup(group: CollisionGroup): void;
|
|
33
|
-
startDebugger(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>, drawer: IDebugPhysicsDrawer<Point3, Point4>): void;
|
|
34
|
-
stopDebugger(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
35
35
|
dispose(): void;
|
|
36
36
|
}
|
|
@@ -7,19 +7,22 @@ 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';
|
|
13
|
-
import { AmmoDebugger, AmmoDebugMode } from '../ammo-debugger';
|
|
14
14
|
export class AmmoWorldComponent {
|
|
15
15
|
constructor() {
|
|
16
16
|
this._factory = null;
|
|
17
|
+
this.afterTick$ = new Subject();
|
|
18
|
+
this.added$ = new Subject();
|
|
19
|
+
this.removed$ = new Subject();
|
|
20
|
+
this.children = [];
|
|
17
21
|
this._loader = null;
|
|
18
22
|
this._gravity = { x: 0, y: 0, z: -9.82 };
|
|
19
|
-
this._timeScale = 1;
|
|
20
|
-
this._debugger = null;
|
|
21
|
-
this._debugDrawer = null;
|
|
22
23
|
this.lockedCollisionGroups = [];
|
|
24
|
+
this.added$.subscribe(c => this.children.push(c));
|
|
25
|
+
this.removed$.subscribe(c => this.children.splice(this.children.indexOf(c), 1));
|
|
23
26
|
}
|
|
24
27
|
get factory() {
|
|
25
28
|
if (!this._factory) {
|
|
@@ -44,15 +47,6 @@ export class AmmoWorldComponent {
|
|
|
44
47
|
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setGravity(this.gravityVector);
|
|
45
48
|
}
|
|
46
49
|
}
|
|
47
|
-
get timeScale() {
|
|
48
|
-
return this._timeScale;
|
|
49
|
-
}
|
|
50
|
-
set timeScale(value) {
|
|
51
|
-
this._timeScale = value;
|
|
52
|
-
}
|
|
53
|
-
get physicsDebugViewActive() {
|
|
54
|
-
return !!this._debugger;
|
|
55
|
-
}
|
|
56
50
|
get dynamicAmmoWorld() {
|
|
57
51
|
return this._dynamicAmmoWorld;
|
|
58
52
|
}
|
|
@@ -77,10 +71,8 @@ export class AmmoWorldComponent {
|
|
|
77
71
|
}
|
|
78
72
|
simulate(delta) {
|
|
79
73
|
var _a;
|
|
80
|
-
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(
|
|
81
|
-
|
|
82
|
-
this._debugger.update();
|
|
83
|
-
}
|
|
74
|
+
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(delta / 1000, 100, 0.01);
|
|
75
|
+
this.afterTick$.next();
|
|
84
76
|
}
|
|
85
77
|
registerCollisionGroup() {
|
|
86
78
|
for (let i = 0; i < 16; i++) {
|
|
@@ -94,38 +86,13 @@ export class AmmoWorldComponent {
|
|
|
94
86
|
deregisterCollisionGroup(group) {
|
|
95
87
|
this.lockedCollisionGroups = this.lockedCollisionGroups.filter(x => x !== group);
|
|
96
88
|
}
|
|
97
|
-
startDebugger(world, drawer) {
|
|
98
|
-
var _a;
|
|
99
|
-
if (!this._debugger) {
|
|
100
|
-
this._debugger = new AmmoDebugger(this, drawer);
|
|
101
|
-
(_a = this.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setDebugDrawer(this._debugger.ammoInstance);
|
|
102
|
-
}
|
|
103
|
-
this._debugger.setDebugMode(AmmoDebugMode.DrawWireframe);
|
|
104
|
-
this._debugDrawer = drawer;
|
|
105
|
-
this._debugDrawer.addToWorld(world);
|
|
106
|
-
}
|
|
107
|
-
stopDebugger(world) {
|
|
108
|
-
var _a;
|
|
109
|
-
if (this._debugger) {
|
|
110
|
-
(_a = this.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setDebugDrawer(null);
|
|
111
|
-
Ammo.destroy(this._debugger.ammoInstance);
|
|
112
|
-
this._debugger = null;
|
|
113
|
-
}
|
|
114
|
-
if (this._debugDrawer) {
|
|
115
|
-
this._debugDrawer.removeFromWorld(world);
|
|
116
|
-
this._debugDrawer.dispose();
|
|
117
|
-
this._debugDrawer = null;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
89
|
dispose() {
|
|
90
|
+
this.afterTick$.complete();
|
|
121
91
|
Ammo.destroy(this._dynamicAmmoWorld);
|
|
122
92
|
Ammo.destroy(this.solver);
|
|
123
93
|
Ammo.destroy(this.broadphase);
|
|
124
94
|
Ammo.destroy(this.dispatcher);
|
|
125
95
|
Ammo.destroy(this.collisionConfiguration);
|
|
126
|
-
if (this._debugger) {
|
|
127
|
-
Ammo.destroy(this._debugger.ammoInstance);
|
|
128
|
-
}
|
|
129
96
|
this._dynamicAmmoWorld = this.solver = this.broadphase = this.dispatcher = this.collisionConfiguration = undefined;
|
|
130
97
|
}
|
|
131
98
|
}
|
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.39",
|
|
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.39",
|
|
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.39",
|
|
49
|
+
"mini-signals": "2.0.0",
|
|
50
|
+
"rxjs": "7.8.1"
|
|
49
51
|
},
|
|
50
52
|
"jest": {
|
|
51
53
|
"rootDir": ".",
|
package/dist/ammo-debugger.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import Ammo from './ammo.js/ammo';
|
|
2
|
-
import { IDebugPhysicsDrawer, Point3, Point4 } from '@gg-web-engine/core';
|
|
3
|
-
import { AmmoWorldComponent } from './components/ammo-world.component';
|
|
4
|
-
export declare const DebugBufferSize: number;
|
|
5
|
-
export declare enum AmmoDebugMode {
|
|
6
|
-
NoDebug = 0,
|
|
7
|
-
DrawWireframe = 1,
|
|
8
|
-
DrawAabb = 2,
|
|
9
|
-
DrawFeaturesText = 4,
|
|
10
|
-
DrawContactPoints = 8,
|
|
11
|
-
NoDeactivation = 16,
|
|
12
|
-
NoHelpText = 32,
|
|
13
|
-
DrawText = 64,
|
|
14
|
-
ProfileTimings = 128,
|
|
15
|
-
EnableSatComparison = 256,
|
|
16
|
-
DisableBulletLCP = 512,
|
|
17
|
-
EnableCCD = 1024,
|
|
18
|
-
DrawConstraints = 2048,
|
|
19
|
-
DrawConstraintLimits = 4096,
|
|
20
|
-
FastWireframe = 8192,
|
|
21
|
-
DrawNormals = 16384,
|
|
22
|
-
MAX_DEBUG_DRAW_MODE = 4294967295
|
|
23
|
-
}
|
|
24
|
-
export declare class AmmoDebugger implements Ammo.btIDebugDraw {
|
|
25
|
-
protected readonly world: AmmoWorldComponent;
|
|
26
|
-
private readonly drawer;
|
|
27
|
-
protected debugMode: AmmoDebugMode;
|
|
28
|
-
constructor(world: AmmoWorldComponent, drawer: IDebugPhysicsDrawer<Point3, Point4>);
|
|
29
|
-
readonly ammoInstance: Ammo.btIDebugDraw;
|
|
30
|
-
draw3dText(location: Ammo.btVector3, textString: string): void;
|
|
31
|
-
drawContactPoint(pointOnB: Ammo.btVector3, normalOnB: Ammo.btVector3, distance: number, lifeTime: number, color: Ammo.btVector3): void;
|
|
32
|
-
drawLine(from: Ammo.btVector3, to: Ammo.btVector3, color: Ammo.btVector3): void;
|
|
33
|
-
getDebugMode(): number;
|
|
34
|
-
update(): void;
|
|
35
|
-
setDebugFlags(flags: AmmoDebugMode[]): void;
|
|
36
|
-
setDebugMode(debugMode: number): void;
|
|
37
|
-
reportErrorWarning(warningString: string): void;
|
|
38
|
-
}
|
package/dist/ammo-debugger.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import Ammo from './ammo.js/ammo';
|
|
2
|
-
export const DebugBufferSize = 3 * 1000000;
|
|
3
|
-
export var AmmoDebugMode;
|
|
4
|
-
(function (AmmoDebugMode) {
|
|
5
|
-
AmmoDebugMode[AmmoDebugMode["NoDebug"] = 0] = "NoDebug";
|
|
6
|
-
AmmoDebugMode[AmmoDebugMode["DrawWireframe"] = 1] = "DrawWireframe";
|
|
7
|
-
AmmoDebugMode[AmmoDebugMode["DrawAabb"] = 2] = "DrawAabb";
|
|
8
|
-
AmmoDebugMode[AmmoDebugMode["DrawFeaturesText"] = 4] = "DrawFeaturesText";
|
|
9
|
-
AmmoDebugMode[AmmoDebugMode["DrawContactPoints"] = 8] = "DrawContactPoints";
|
|
10
|
-
AmmoDebugMode[AmmoDebugMode["NoDeactivation"] = 16] = "NoDeactivation";
|
|
11
|
-
AmmoDebugMode[AmmoDebugMode["NoHelpText"] = 32] = "NoHelpText";
|
|
12
|
-
AmmoDebugMode[AmmoDebugMode["DrawText"] = 64] = "DrawText";
|
|
13
|
-
AmmoDebugMode[AmmoDebugMode["ProfileTimings"] = 128] = "ProfileTimings";
|
|
14
|
-
AmmoDebugMode[AmmoDebugMode["EnableSatComparison"] = 256] = "EnableSatComparison";
|
|
15
|
-
AmmoDebugMode[AmmoDebugMode["DisableBulletLCP"] = 512] = "DisableBulletLCP";
|
|
16
|
-
AmmoDebugMode[AmmoDebugMode["EnableCCD"] = 1024] = "EnableCCD";
|
|
17
|
-
AmmoDebugMode[AmmoDebugMode["DrawConstraints"] = 2048] = "DrawConstraints";
|
|
18
|
-
AmmoDebugMode[AmmoDebugMode["DrawConstraintLimits"] = 4096] = "DrawConstraintLimits";
|
|
19
|
-
AmmoDebugMode[AmmoDebugMode["FastWireframe"] = 8192] = "FastWireframe";
|
|
20
|
-
AmmoDebugMode[AmmoDebugMode["DrawNormals"] = 16384] = "DrawNormals";
|
|
21
|
-
AmmoDebugMode[AmmoDebugMode["MAX_DEBUG_DRAW_MODE"] = 4294967295] = "MAX_DEBUG_DRAW_MODE";
|
|
22
|
-
})(AmmoDebugMode || (AmmoDebugMode = {}));
|
|
23
|
-
const deserializeVector = function (vec) {
|
|
24
|
-
if (!isNaN(+vec)) {
|
|
25
|
-
const heap = Ammo.HEAPF32;
|
|
26
|
-
return {
|
|
27
|
-
x: heap[+vec / 4],
|
|
28
|
-
y: heap[(+vec + 4) / 4],
|
|
29
|
-
z: heap[(+vec + 8) / 4],
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
return { x: vec.x(), y: vec.y(), z: vec.z() };
|
|
33
|
-
};
|
|
34
|
-
export class AmmoDebugger {
|
|
35
|
-
constructor(world, drawer) {
|
|
36
|
-
this.world = world;
|
|
37
|
-
this.drawer = drawer;
|
|
38
|
-
this.debugMode = AmmoDebugMode.DrawWireframe;
|
|
39
|
-
this.ammoInstance = new Ammo.DebugDrawer();
|
|
40
|
-
this.ammoInstance.drawLine = this.drawLine.bind(this);
|
|
41
|
-
this.ammoInstance.drawContactPoint = this.drawContactPoint.bind(this);
|
|
42
|
-
this.ammoInstance.reportErrorWarning = this.reportErrorWarning.bind(this);
|
|
43
|
-
this.ammoInstance.draw3dText = this.draw3dText.bind(this);
|
|
44
|
-
this.ammoInstance.setDebugMode = this.setDebugMode.bind(this);
|
|
45
|
-
this.ammoInstance.getDebugMode = this.getDebugMode.bind(this);
|
|
46
|
-
}
|
|
47
|
-
draw3dText(location, textString) {
|
|
48
|
-
console.log('DRAWER DEBUG', 'draw3dtext');
|
|
49
|
-
}
|
|
50
|
-
drawContactPoint(pointOnB, normalOnB, distance, lifeTime, color) {
|
|
51
|
-
this.drawer.drawContactPoint(deserializeVector(pointOnB), deserializeVector(normalOnB), deserializeVector(color));
|
|
52
|
-
}
|
|
53
|
-
drawLine(from, to, color) {
|
|
54
|
-
this.drawer.drawLine(deserializeVector(from), deserializeVector(to), deserializeVector(color));
|
|
55
|
-
}
|
|
56
|
-
getDebugMode() {
|
|
57
|
-
return this.debugMode;
|
|
58
|
-
}
|
|
59
|
-
update() {
|
|
60
|
-
var _a;
|
|
61
|
-
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.debugDrawWorld();
|
|
62
|
-
this.drawer.update();
|
|
63
|
-
}
|
|
64
|
-
setDebugFlags(flags) {
|
|
65
|
-
let res = 0;
|
|
66
|
-
for (const flag of flags) {
|
|
67
|
-
res = res | flag;
|
|
68
|
-
}
|
|
69
|
-
this.setDebugMode(res);
|
|
70
|
-
}
|
|
71
|
-
setDebugMode(debugMode) {
|
|
72
|
-
this.debugMode = debugMode;
|
|
73
|
-
}
|
|
74
|
-
reportErrorWarning(warningString) {
|
|
75
|
-
console.log('DRAWER DEBUG', 'reportErrorWarning', warningString);
|
|
76
|
-
}
|
|
77
|
-
}
|