@gg-web-engine/ammo 0.0.24 → 0.0.28

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.
@@ -1,7 +1,7 @@
1
- import { Gg3dWorld, IEntity, IRigidBody3dComponent, IVisualScene3dComponent, Point3, Point4 } from '@gg-web-engine/core';
1
+ import { Gg3dWorld, IEntity, IVisualScene3dComponent, Point3, Point4 } from '@gg-web-engine/core';
2
2
  import { AmmoWorldComponent } from './ammo-world.component';
3
3
  import Ammo from 'ammojs-typed';
4
- export declare abstract class AmmoBodyComponent<T extends Ammo.btCollisionObject> implements IRigidBody3dComponent<AmmoWorldComponent> {
4
+ export declare abstract class AmmoBodyComponent<T extends Ammo.btCollisionObject> {
5
5
  protected readonly world: AmmoWorldComponent;
6
6
  protected _nativeBody: T;
7
7
  protected static nativeBodyReverseMap: Map<number, AmmoBodyComponent<any>>;
@@ -19,5 +19,4 @@ export declare abstract class AmmoBodyComponent<T extends Ammo.btCollisionObject
19
19
  abstract addToWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
20
20
  abstract removeFromWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
21
21
  dispose(): void;
22
- abstract resetMotion(): void;
23
22
  }
@@ -1,16 +1,16 @@
1
- import { RaycastVehicle3dEntity, IRaycastVehicleComponent, Point3, Point4, SuspensionOptions, WheelOptions, Gg3dWorld, IVisualScene3dComponent } from '@gg-web-engine/core';
1
+ import { Gg3dWorld, IRaycastVehicleComponent, IVisualScene3dComponent, Point3, Point4, RaycastVehicle3dEntity, WheelOptions, SuspensionOptions } from '@gg-web-engine/core';
2
2
  import Ammo from 'ammojs-typed';
3
3
  import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
4
4
  import { AmmoWorldComponent } from './ammo-world.component';
5
5
  export declare class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent implements IRaycastVehicleComponent<AmmoWorldComponent> {
6
6
  protected readonly world: AmmoWorldComponent;
7
- chassisBody: Ammo.btRigidBody;
7
+ chassisBody: AmmoRigidBodyComponent;
8
8
  readonly nativeVehicle: Ammo.btRaycastVehicle;
9
9
  readonly vehicleTuning: Ammo.btVehicleTuning;
10
10
  protected readonly wheelDirectionCS0: Ammo.btVector3;
11
11
  protected readonly wheelAxleCS: Ammo.btVector3;
12
12
  entity: RaycastVehicle3dEntity | null;
13
- constructor(world: AmmoWorldComponent, chassisBody: Ammo.btRigidBody);
13
+ constructor(world: AmmoWorldComponent, chassisBody: AmmoRigidBodyComponent);
14
14
  get wheelSpeed(): number;
15
15
  addToWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
16
16
  addWheel(options: WheelOptions, suspensionOptions: SuspensionOptions): void;
@@ -1,14 +1,14 @@
1
1
  import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
2
2
  export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
3
3
  constructor(world, chassisBody) {
4
- super(world, chassisBody);
4
+ super(world, chassisBody.nativeBody);
5
5
  this.world = world;
6
6
  this.chassisBody = chassisBody;
7
7
  this.vehicleTuning = new this.ammo.btVehicleTuning();
8
8
  this.wheelDirectionCS0 = new this.ammo.btVector3(0, 0, -1);
9
9
  this.wheelAxleCS = new this.ammo.btVector3(1, 0, 0);
10
10
  this.entity = null;
11
- this.nativeVehicle = new this.ammo.btRaycastVehicle(this.vehicleTuning, this.chassisBody, new this.ammo.btDefaultVehicleRaycaster(world.dynamicAmmoWorld));
11
+ this.nativeVehicle = new this.ammo.btRaycastVehicle(this.vehicleTuning, this.chassisBody.nativeBody, new this.ammo.btDefaultVehicleRaycaster(world.dynamicAmmoWorld));
12
12
  this.nativeVehicle.setCoordinateSystem(0, 2, 1);
13
13
  }
14
14
  get wheelSpeed() {
@@ -21,12 +21,12 @@ export class AmmoRaycastVehicleComponent extends AmmoRigidBodyComponent {
21
21
  throw new Error('Ammo raycast vehicle cannot be shared between different worlds');
22
22
  }
23
23
  // TODO parked cars can be deactivated until we start handling them. Needs explicit activation call
24
- this.chassisBody.setActivationState(4); // btCollisionObject::DISABLE_DEACTIVATION
25
- (_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.addRigidBody(this.chassisBody);
24
+ this.chassisBody.nativeBody.setActivationState(4); // btCollisionObject::DISABLE_DEACTIVATION
25
+ (_a = this.world.dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.addRigidBody(this.chassisBody.nativeBody);
26
26
  this.world.dynamicAmmoWorld.addAction(this.nativeVehicle);
27
27
  }
28
28
  addWheel(options, suspensionOptions) {
29
- const wheelInfo = this.nativeVehicle.addWheel(new this.ammo.btVector3(options.position.x, options.position.y, options.position.z * 2), this.wheelDirectionCS0, this.wheelAxleCS, suspensionOptions.restLength, options.tyre_radius, this.vehicleTuning, options.isFront);
29
+ const wheelInfo = this.nativeVehicle.addWheel(new this.ammo.btVector3(options.position.x, options.position.y, options.position.z), this.wheelDirectionCS0, this.wheelAxleCS, suspensionOptions.restLength, options.tyreRadius, this.vehicleTuning, options.isFront);
30
30
  wheelInfo.set_m_suspensionStiffness(suspensionOptions.stiffness);
31
31
  wheelInfo.set_m_wheelsDampingRelaxation(suspensionOptions.damping);
32
32
  wheelInfo.set_m_wheelsDampingCompression(suspensionOptions.compression);
@@ -1,11 +1,15 @@
1
1
  import { AmmoWorldComponent } from './ammo-world.component';
2
2
  import Ammo from 'ammojs-typed';
3
3
  import { AmmoBodyComponent } from './ammo-body.component';
4
- import { Entity3d, Gg3dWorld, IVisualScene3dComponent } from '@gg-web-engine/core';
5
- export declare class AmmoRigidBodyComponent extends AmmoBodyComponent<Ammo.btRigidBody> {
4
+ import { Entity3d, Gg3dWorld, IRigidBody3dComponent, IVisualScene3dComponent, Point3 } from '@gg-web-engine/core';
5
+ export declare class AmmoRigidBodyComponent extends AmmoBodyComponent<Ammo.btRigidBody> implements IRigidBody3dComponent<AmmoWorldComponent> {
6
6
  protected readonly world: AmmoWorldComponent;
7
7
  protected _nativeBody: Ammo.btRigidBody;
8
8
  entity: Entity3d | null;
9
+ get linearVelocity(): Point3;
10
+ set linearVelocity(value: Point3);
11
+ get angularVelocity(): Point3;
12
+ set angularVelocity(value: Point3);
9
13
  constructor(world: AmmoWorldComponent, _nativeBody: Ammo.btRigidBody);
10
14
  clone(): AmmoRigidBodyComponent;
11
15
  addToWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
@@ -6,6 +6,20 @@ export class AmmoRigidBodyComponent extends AmmoBodyComponent {
6
6
  this._nativeBody = _nativeBody;
7
7
  this.entity = null;
8
8
  }
9
+ get linearVelocity() {
10
+ const v = this.nativeBody.getLinearVelocity();
11
+ return { x: v.x(), y: v.y(), z: v.z() };
12
+ }
13
+ set linearVelocity(value) {
14
+ this.nativeBody.setLinearVelocity(new this.ammo.btVector3(value.x, value.y, value.z));
15
+ }
16
+ get angularVelocity() {
17
+ const v = this.nativeBody.getAngularVelocity();
18
+ return { x: v.x(), y: v.y(), z: v.z() };
19
+ }
20
+ set angularVelocity(value) {
21
+ this.nativeBody.setAngularVelocity(new this.ammo.btVector3(value.x, value.y, value.z));
22
+ }
9
23
  clone() {
10
24
  return this.world.factory.createRigidBodyFromShape(this._nativeBody.getCollisionShape(), {
11
25
  dynamic: !this._nativeBody.isStaticObject(),
@@ -3,12 +3,13 @@ import { AmmoWorldComponent } from './ammo-world.component';
3
3
  import { Observable, Subject } from 'rxjs';
4
4
  import Ammo from 'ammojs-typed';
5
5
  import { AmmoBodyComponent } from './ammo-body.component';
6
+ import { AmmoRigidBodyComponent } from './ammo-rigid-body.component';
6
7
  export declare class AmmoTriggerComponent extends AmmoBodyComponent<Ammo.btPairCachingGhostObject> implements ITrigger3dComponent<AmmoWorldComponent> {
7
8
  protected readonly world: AmmoWorldComponent;
8
9
  protected _nativeBody: Ammo.btPairCachingGhostObject;
9
10
  entity: IEntity | null;
10
- get onEntityEntered(): Observable<AmmoBodyComponent<any>>;
11
- get onEntityLeft(): Observable<AmmoBodyComponent<any> | null>;
11
+ get onEntityEntered(): Observable<AmmoRigidBodyComponent>;
12
+ get onEntityLeft(): Observable<AmmoRigidBodyComponent | null>;
12
13
  constructor(world: AmmoWorldComponent, _nativeBody: Ammo.btPairCachingGhostObject);
13
14
  protected readonly onEnter$: Subject<number>;
14
15
  protected readonly onLeft$: Subject<number>;
@@ -18,5 +19,4 @@ export declare class AmmoTriggerComponent extends AmmoBodyComponent<Ammo.btPairC
18
19
  addToWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
19
20
  removeFromWorld(world: Gg3dWorld<IVisualScene3dComponent, AmmoWorldComponent>): void;
20
21
  dispose(): void;
21
- resetMotion(): void;
22
22
  }
@@ -65,5 +65,4 @@ export class AmmoTriggerComponent extends AmmoBodyComponent {
65
65
  this.onEnter$.complete();
66
66
  this.onLeft$.complete();
67
67
  }
68
- resetMotion() { }
69
68
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/ammo",
3
- "version": "0.0.24",
3
+ "version": "0.0.28",
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,14 +34,14 @@
34
34
  "dependencies": {
35
35
  },
36
36
  "devDependencies": {
37
- "@gg-web-engine/core": "0.0.24",
37
+ "@gg-web-engine/core": "0.0.28",
38
38
  "ammojs-typed": "1.0.6",
39
39
  "mini-signals": "2.0.0",
40
40
  "prettier": "^2.8.6",
41
41
  "typescript": "~4.7.2"
42
42
  },
43
43
  "peerDependencies": {
44
- "@gg-web-engine/core": "0.0.24",
44
+ "@gg-web-engine/core": "0.0.28",
45
45
  "ammojs-typed": "1.0.6",
46
46
  "mini-signals": "2.0.0"
47
47
  }