@gg-web-engine/ammo 0.0.48 → 0.0.56

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.
@@ -17,21 +17,28 @@ export class AmmoFactory {
17
17
  return new AmmoRaycastVehicleComponent(this.world, chassis);
18
18
  }
19
19
  createShape(descriptor) {
20
+ let shape;
20
21
  switch (descriptor.shape) {
21
22
  case 'PLANE':
22
- return new Ammo.btStaticPlaneShape(new Ammo.btVector3(0, 0, 1), 0);
23
+ shape = new Ammo.btStaticPlaneShape(new Ammo.btVector3(0, 0, 1), 0);
24
+ break;
23
25
  case 'BOX':
24
- return new Ammo.btBoxShape(new Ammo.btVector3(descriptor.dimensions.x / 2, descriptor.dimensions.y / 2, descriptor.dimensions.z / 2));
26
+ shape = new Ammo.btBoxShape(new Ammo.btVector3(descriptor.dimensions.x / 2, descriptor.dimensions.y / 2, descriptor.dimensions.z / 2));
27
+ break;
25
28
  case 'CAPSULE':
26
- return new Ammo.btCapsuleShapeZ(descriptor.radius, descriptor.centersDistance);
29
+ shape = new Ammo.btCapsuleShapeZ(descriptor.radius, descriptor.centersDistance);
30
+ break;
27
31
  case 'CYLINDER':
28
- return new Ammo.btCylinderShapeZ(new Ammo.btVector3(descriptor.radius, descriptor.radius, descriptor.height / 2));
32
+ shape = new Ammo.btCylinderShapeZ(new Ammo.btVector3(descriptor.radius, descriptor.radius, descriptor.height / 2));
33
+ break;
29
34
  case 'CONE':
30
- return new Ammo.btConeShapeZ(descriptor.radius, descriptor.height);
35
+ shape = new Ammo.btConeShapeZ(descriptor.radius, descriptor.height);
36
+ break;
31
37
  case 'SPHERE':
32
- return new Ammo.btSphereShape(descriptor.radius);
38
+ shape = new Ammo.btSphereShape(descriptor.radius);
39
+ break;
33
40
  case 'COMPOUND':
34
- const compoundShape = new Ammo.btCompoundShape();
41
+ let cs = new Ammo.btCompoundShape();
35
42
  for (const item of descriptor.children) {
36
43
  const subShape = this.createShape(item.shape);
37
44
  if (!subShape) {
@@ -42,19 +49,21 @@ export class AmmoFactory {
42
49
  const rot = item.rotation || Qtrn.O;
43
50
  subShapeTransform.setOrigin(new Ammo.btVector3(pos.x, pos.y, pos.z));
44
51
  subShapeTransform.setRotation(new Ammo.btQuaternion(rot.x, rot.y, rot.z, rot.w));
45
- compoundShape.addChildShape(subShapeTransform, subShape);
52
+ cs.addChildShape(subShapeTransform, subShape);
46
53
  }
47
- return compoundShape;
54
+ shape = cs;
55
+ break;
48
56
  case 'CONVEX_HULL':
49
- const shape = new Ammo.btConvexHullShape();
57
+ const s = new Ammo.btConvexHullShape();
50
58
  const tmpVector = new Ammo.btVector3();
51
59
  for (const v of descriptor.vertices) {
52
60
  tmpVector.setValue(v.x, v.y, v.z);
53
- shape.addPoint(tmpVector);
61
+ s.addPoint(tmpVector);
54
62
  }
55
63
  Ammo.destroy(tmpVector);
56
- shape.recalcLocalAabb();
57
- return shape;
64
+ s.recalcLocalAabb();
65
+ shape = s;
66
+ break;
58
67
  case 'MESH':
59
68
  const mesh = new Ammo.btTriangleMesh(true, true);
60
69
  const tmpVectors = [
@@ -71,9 +80,15 @@ export class AmmoFactory {
71
80
  tmpVectors.forEach(v => {
72
81
  Ammo.destroy(v);
73
82
  });
74
- return new Ammo.btBvhTriangleMeshShape(mesh, false, true);
83
+ shape = new Ammo.btBvhTriangleMeshShape(mesh, false, true);
84
+ break;
85
+ default:
86
+ throw new Error(`Shape "${descriptor.shape}" not implemented for Ammo.js`);
75
87
  }
76
- throw new Error(`Shape "${descriptor.shape}" not implemented for Ammo.js`);
88
+ if (descriptor.collisionMargin) {
89
+ shape.setMargin(descriptor.collisionMargin);
90
+ }
91
+ return shape;
77
92
  }
78
93
  createRigidBodyFromShape(nativeShape, shapeDescr, options, transform) {
79
94
  if (options.dynamic === false) {
@@ -18,6 +18,8 @@ export declare class AmmoWorldComponent implements IPhysicsWorld3dComponent<Ammo
18
18
  private _gravity;
19
19
  get gravity(): Point3;
20
20
  set gravity(value: Point3);
21
+ maxSubSteps?: number;
22
+ fixedTimeStep?: number;
21
23
  get dynamicAmmoWorld(): Ammo.btDiscreteDynamicsWorld | undefined;
22
24
  private collisionConfiguration;
23
25
  private dispatcher;
@@ -46,6 +46,8 @@ export class AmmoWorldComponent {
46
46
  this.children = [];
47
47
  this._loader = null;
48
48
  this._gravity = { x: 0, y: 0, z: -9.82 };
49
+ this.maxSubSteps = 100;
50
+ this.fixedTimeStep = 0.01;
49
51
  this.lockedCollisionGroups = [];
50
52
  this.added$.subscribe(c => this.children.push(c));
51
53
  this.removed$.subscribe(c => this.children.splice(this.children.indexOf(c), 1));
@@ -71,7 +73,7 @@ export class AmmoWorldComponent {
71
73
  }
72
74
  simulate(delta) {
73
75
  var _a;
74
- (_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(delta / 1000, 100, 0.01);
76
+ (_a = this._dynamicAmmoWorld) === null || _a === void 0 ? void 0 : _a.stepSimulation(delta / 1000, this.maxSubSteps || undefined, this.fixedTimeStep || undefined);
75
77
  this.afterTick$.next();
76
78
  }
77
79
  registerCollisionGroup() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gg-web-engine/ammo",
3
- "version": "0.0.48",
3
+ "version": "0.0.56",
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.48",
37
+ "@gg-web-engine/core": "0.0.56",
38
38
  "@types/jest": "^29.5.12",
39
39
  "jest": "^29.7.0",
40
40
  "jest-environment-jsdom": "^29.7.0",
@@ -45,7 +45,7 @@
45
45
  "typescript": "~5.5.4"
46
46
  },
47
47
  "peerDependencies": {
48
- "@gg-web-engine/core": "0.0.48",
48
+ "@gg-web-engine/core": "0.0.56",
49
49
  "mini-signals": "2.0.0",
50
50
  "rxjs": "7.8.1"
51
51
  },