@gg-web-engine/ammo 0.0.38 → 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.js +3 -1
- package/dist/components/ammo-rigid-body.component.d.ts +4 -2
- package/dist/components/ammo-rigid-body.component.js +14 -5
- 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 +8 -10
- package/dist/components/ammo-world.component.js +6 -43
- package/package.json +3 -3
- 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();
|
|
@@ -46,11 +46,13 @@ export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
|
|
|
46
46
|
this.chassisBody.nativeBody.setActivationState(4); // btCollisionObject::DISABLE_DEACTIVATION
|
|
47
47
|
this.chassisBody.addToWorld(world);
|
|
48
48
|
this.world.dynamicAmmoWorld.addAction(this.nativeVehicle);
|
|
49
|
+
this.world.added$.next(this);
|
|
49
50
|
}
|
|
50
51
|
removeFromWorld(world) {
|
|
51
52
|
this.addedToWorld = false;
|
|
52
53
|
this.chassisBody.removeFromWorld(world);
|
|
53
54
|
this.world.dynamicAmmoWorld.removeAction(this.nativeVehicle);
|
|
55
|
+
this.world.removed$.next(this);
|
|
54
56
|
}
|
|
55
57
|
addWheel(options, suspensionOptions) {
|
|
56
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);
|
|
@@ -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;
|
|
@@ -2,10 +2,11 @@ import Ammo from '../ammo.js/ammo';
|
|
|
2
2
|
import { AmmoBodyComponent } from './ammo-body.component';
|
|
3
3
|
import { first } from 'rxjs';
|
|
4
4
|
export class AmmoRigidBodyComponent 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
|
}
|
|
11
12
|
get linearVelocity() {
|
|
@@ -22,8 +23,16 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
22
23
|
set angularVelocity(value) {
|
|
23
24
|
this.nativeBody.setAngularVelocity(new Ammo.btVector3(value.x, value.y, value.z));
|
|
24
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
|
+
}
|
|
25
34
|
clone() {
|
|
26
|
-
return this.world.factory.createRigidBodyFromShape(this._nativeBody.getCollisionShape(), {
|
|
35
|
+
return this.world.factory.createRigidBodyFromShape(this._nativeBody.getCollisionShape(), this.shape, {
|
|
27
36
|
dynamic: !this._nativeBody.isStaticOrKinematicObject(),
|
|
28
37
|
mass: this._nativeBody.getMass(),
|
|
29
38
|
friction: this._nativeBody.getFriction(),
|
|
@@ -35,13 +44,13 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
|
|
|
35
44
|
}
|
|
36
45
|
addToWorld(world) {
|
|
37
46
|
var _a;
|
|
38
|
-
super.addToWorld(world);
|
|
39
47
|
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.addRigidBody(this.nativeBody, this._ownCGsMask, this._interactWithCGsMask);
|
|
48
|
+
super.addToWorld(world);
|
|
40
49
|
}
|
|
41
50
|
removeFromWorld(world) {
|
|
42
51
|
var _a;
|
|
43
|
-
super.removeFromWorld(world);
|
|
44
52
|
(_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.removeRigidBody(this.nativeBody);
|
|
53
|
+
super.removeFromWorld(world);
|
|
45
54
|
}
|
|
46
55
|
refreshCG() {
|
|
47
56
|
var _a, _b;
|
|
@@ -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,24 +1,23 @@
|
|
|
1
|
-
import { CollisionGroup,
|
|
1
|
+
import { CollisionGroup, IPhysicsWorld3dComponent, Point3 } from '@gg-web-engine/core';
|
|
2
2
|
import { Subject } from 'rxjs';
|
|
3
3
|
import Ammo from '../ammo.js/ammo';
|
|
4
4
|
import { AmmoFactory } from '../ammo-factory';
|
|
5
5
|
import { AmmoLoader } from '../ammo-loader';
|
|
6
6
|
import { AmmoPhysicsTypeDocRepo } from '../types';
|
|
7
|
+
import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
|
|
8
|
+
import { AmmoTriggerComponent } from './ammo-trigger.component';
|
|
7
9
|
export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<AmmoPhysicsTypeDocRepo> {
|
|
8
10
|
private _factory;
|
|
9
11
|
get factory(): AmmoFactory;
|
|
10
|
-
afterTick$: Subject<void>;
|
|
12
|
+
readonly afterTick$: Subject<void>;
|
|
13
|
+
readonly added$: Subject<AmmoRigidBodyComponent | AmmoTriggerComponent>;
|
|
14
|
+
readonly removed$: Subject<AmmoRigidBodyComponent | AmmoTriggerComponent>;
|
|
15
|
+
readonly children: (AmmoRigidBodyComponent | AmmoTriggerComponent)[];
|
|
11
16
|
private _loader;
|
|
12
17
|
get loader(): AmmoLoader;
|
|
13
18
|
private _gravity;
|
|
14
19
|
get gravity(): Point3;
|
|
15
20
|
set gravity(value: Point3);
|
|
16
|
-
private _timeScale;
|
|
17
|
-
get timeScale(): number;
|
|
18
|
-
set timeScale(value: number);
|
|
19
|
-
private _debugger;
|
|
20
|
-
private _debugDrawer;
|
|
21
|
-
get physicsDebugViewActive(): boolean;
|
|
22
21
|
get dynamicAmmoWorld(): Ammo.btDiscreteDynamicsWorld | undefined;
|
|
23
22
|
private collisionConfiguration;
|
|
24
23
|
private dispatcher;
|
|
@@ -27,12 +26,11 @@ export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<Ammo
|
|
|
27
26
|
private solver;
|
|
28
27
|
private gravityVector;
|
|
29
28
|
protected _dynamicAmmoWorld: Ammo.btDiscreteDynamicsWorld | undefined;
|
|
29
|
+
constructor();
|
|
30
30
|
init(): Promise<void>;
|
|
31
31
|
simulate(delta: number): void;
|
|
32
32
|
protected lockedCollisionGroups: number[];
|
|
33
33
|
registerCollisionGroup(): CollisionGroup;
|
|
34
34
|
deregisterCollisionGroup(group: CollisionGroup): void;
|
|
35
|
-
startDebugger(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>, drawer: IDebugPhysicsDrawer<Point3, Point4>): void;
|
|
36
|
-
stopDebugger(world: Gg3dWorld<VisualTypeDocRepo3D, AmmoPhysicsTypeDocRepo>): void;
|
|
37
35
|
dispose(): void;
|
|
38
36
|
}
|
|
@@ -11,17 +11,18 @@ import { Subject } from 'rxjs';
|
|
|
11
11
|
import Ammo from '../ammo.js/ammo';
|
|
12
12
|
import { AmmoFactory } from '../ammo-factory';
|
|
13
13
|
import { AmmoLoader } from '../ammo-loader';
|
|
14
|
-
import { AmmoDebugger, AmmoDebugMode } from '../ammo-debugger';
|
|
15
14
|
export class AmmoWorldComponent {
|
|
16
15
|
constructor() {
|
|
17
16
|
this._factory = null;
|
|
18
17
|
this.afterTick$ = new Subject();
|
|
18
|
+
this.added$ = new Subject();
|
|
19
|
+
this.removed$ = new Subject();
|
|
20
|
+
this.children = [];
|
|
19
21
|
this._loader = null;
|
|
20
22
|
this._gravity = { x: 0, y: 0, z: -9.82 };
|
|
21
|
-
this._timeScale = 1;
|
|
22
|
-
this._debugger = null;
|
|
23
|
-
this._debugDrawer = null;
|
|
24
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));
|
|
25
26
|
}
|
|
26
27
|
get factory() {
|
|
27
28
|
if (!this._factory) {
|
|
@@ -46,15 +47,6 @@ export class AmmoWorldComponent {
|
|
|
46
47
|
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setGravity(this.gravityVector);
|
|
47
48
|
}
|
|
48
49
|
}
|
|
49
|
-
get timeScale() {
|
|
50
|
-
return this._timeScale;
|
|
51
|
-
}
|
|
52
|
-
set timeScale(value) {
|
|
53
|
-
this._timeScale = value;
|
|
54
|
-
}
|
|
55
|
-
get physicsDebugViewActive() {
|
|
56
|
-
return !!this._debugger;
|
|
57
|
-
}
|
|
58
50
|
get dynamicAmmoWorld() {
|
|
59
51
|
return this._dynamicAmmoWorld;
|
|
60
52
|
}
|
|
@@ -79,11 +71,8 @@ export class AmmoWorldComponent {
|
|
|
79
71
|
}
|
|
80
72
|
simulate(delta) {
|
|
81
73
|
var _a;
|
|
82
|
-
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(
|
|
74
|
+
(_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(delta / 1000, 100, 0.01);
|
|
83
75
|
this.afterTick$.next();
|
|
84
|
-
if (this._debugger) {
|
|
85
|
-
this._debugger.update();
|
|
86
|
-
}
|
|
87
76
|
}
|
|
88
77
|
registerCollisionGroup() {
|
|
89
78
|
for (let i = 0; i < 16; i++) {
|
|
@@ -97,29 +86,6 @@ export class AmmoWorldComponent {
|
|
|
97
86
|
deregisterCollisionGroup(group) {
|
|
98
87
|
this.lockedCollisionGroups = this.lockedCollisionGroups.filter(x => x !== group);
|
|
99
88
|
}
|
|
100
|
-
startDebugger(world, drawer) {
|
|
101
|
-
var _a;
|
|
102
|
-
if (!this._debugger) {
|
|
103
|
-
this._debugger = new AmmoDebugger(this, drawer);
|
|
104
|
-
(_a = this.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setDebugDrawer(this._debugger.ammoInstance);
|
|
105
|
-
}
|
|
106
|
-
this._debugger.setDebugMode(AmmoDebugMode.DrawWireframe);
|
|
107
|
-
this._debugDrawer = drawer;
|
|
108
|
-
this._debugDrawer.addToWorld(world);
|
|
109
|
-
}
|
|
110
|
-
stopDebugger(world) {
|
|
111
|
-
var _a;
|
|
112
|
-
if (this._debugger) {
|
|
113
|
-
(_a = this.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.setDebugDrawer(null);
|
|
114
|
-
Ammo.destroy(this._debugger.ammoInstance);
|
|
115
|
-
this._debugger = null;
|
|
116
|
-
}
|
|
117
|
-
if (this._debugDrawer) {
|
|
118
|
-
this._debugDrawer.removeFromWorld(world);
|
|
119
|
-
this._debugDrawer.dispose();
|
|
120
|
-
this._debugDrawer = null;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
89
|
dispose() {
|
|
124
90
|
this.afterTick$.complete();
|
|
125
91
|
Ammo.destroy(this._dynamicAmmoWorld);
|
|
@@ -127,9 +93,6 @@ export class AmmoWorldComponent {
|
|
|
127
93
|
Ammo.destroy(this.broadphase);
|
|
128
94
|
Ammo.destroy(this.dispatcher);
|
|
129
95
|
Ammo.destroy(this.collisionConfiguration);
|
|
130
|
-
if (this._debugger) {
|
|
131
|
-
Ammo.destroy(this._debugger.ammoInstance);
|
|
132
|
-
}
|
|
133
96
|
this._dynamicAmmoWorld = this.solver = this.broadphase = this.dispatcher = this.collisionConfiguration = undefined;
|
|
134
97
|
}
|
|
135
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,7 +34,7 @@
|
|
|
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",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"typescript": "~4.7.2"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@gg-web-engine/core": "0.0.
|
|
48
|
+
"@gg-web-engine/core": "0.0.39",
|
|
49
49
|
"mini-signals": "2.0.0",
|
|
50
50
|
"rxjs": "7.8.1"
|
|
51
51
|
},
|
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
|
-
}
|