@perplexdotgg/bounce 1.3.1 → 1.4.0

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/build/bounce.js CHANGED
@@ -1959,6 +1959,7 @@ class Aabb extends createClass(aabbProps) {
1959
1959
  this.min.minVectors(boxA.min, boxB.min);
1960
1960
  this.max.maxVectors(boxA.max, boxB.max);
1961
1961
  this.computeCentroid(this.centroid);
1962
+ return this;
1962
1963
  }
1963
1964
  expand(value) {
1964
1965
  this.min.x -= value;
@@ -4027,7 +4028,6 @@ const CollisionFilter = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
4027
4028
  shouldPairCollide,
4028
4029
  toggleFlag
4029
4030
  }, Symbol.toStringTag, { value: "Module" }));
4030
- const expandedObjectBounds = /* @__PURE__ */ Aabb.create();
4031
4031
  const leftAabb = /* @__PURE__ */ Aabb.create();
4032
4032
  const rightAabb = /* @__PURE__ */ Aabb.create();
4033
4033
  const centroidBounds$1 = /* @__PURE__ */ Aabb.create();
@@ -4086,7 +4086,7 @@ class BvhTree {
4086
4086
  }
4087
4087
  updateDirtyObjects() {
4088
4088
  for (const object of this.dirtyObjects) {
4089
- if (this.update(object, false)) ;
4089
+ this.update(object, false);
4090
4090
  }
4091
4091
  this.dirtyObjects.clear();
4092
4092
  }
@@ -4175,7 +4175,7 @@ class BvhTree {
4175
4175
  node.computedBounds.min.fromArray([Infinity, Infinity, Infinity]);
4176
4176
  node.computedBounds.max.fromArray([-Infinity, -Infinity, -Infinity]);
4177
4177
  for (const object of node.objects) {
4178
- node.computedBounds.unionAabb(object.computedBounds);
4178
+ node.computedBounds.unionAabb(object.computedExpandedBounds);
4179
4179
  }
4180
4180
  node.height = 0;
4181
4181
  } else {
@@ -4265,11 +4265,11 @@ class BvhTree {
4265
4265
  destroyBvhNode(node) {
4266
4266
  node.destroy();
4267
4267
  }
4268
- insert(object, shouldUpdateDirtyObjects = true) {
4269
- expandedObjectBounds.expandAabb(object.computedBounds, this.options.expansionMargin);
4268
+ insert(object) {
4269
+ object.computedExpandedBounds.expandAabb(object.computedBounds, this.options.expansionMargin);
4270
4270
  if (!this.root) {
4271
4271
  const root = this.createBvhNode();
4272
- root.computedBounds.copy(expandedObjectBounds);
4272
+ root.computedBounds.copy(object.computedExpandedBounds);
4273
4273
  root.objects.push(object);
4274
4274
  root.height = 0;
4275
4275
  this.root = root;
@@ -4288,7 +4288,7 @@ class BvhTree {
4288
4288
  }
4289
4289
  if (best.objects.length < this.options.maxObjectsPerLeaf || best.height >= this.options.maxDepth) {
4290
4290
  best.objects.push(object);
4291
- best.computedBounds.unionAabb(expandedObjectBounds);
4291
+ best.computedBounds.unionAabb(object.computedExpandedBounds);
4292
4292
  object.node = best;
4293
4293
  return this.refit(best);
4294
4294
  }
@@ -4297,15 +4297,15 @@ class BvhTree {
4297
4297
  best.objects.push(object);
4298
4298
  this.splitObjects(left, right, best);
4299
4299
  best.objects.length = 0;
4300
- left.computedBounds.copy(left.objects.getAtIndex(0).computedBounds);
4300
+ left.computedBounds.copy(left.objects.getAtIndex(0).computedExpandedBounds);
4301
4301
  for (let i = 1; i < left.objects.length; i++) {
4302
- left.computedBounds.unionAabb(left.objects.getAtIndex(i).computedBounds);
4302
+ left.computedBounds.unionAabb(left.objects.getAtIndex(i).computedExpandedBounds);
4303
4303
  }
4304
4304
  left.parent = best;
4305
4305
  left.height = 0;
4306
- right.computedBounds.copy(right.objects.getAtIndex(0).computedBounds);
4306
+ right.computedBounds.copy(right.objects.getAtIndex(0).computedExpandedBounds);
4307
4307
  for (let i = 1; i < right.objects.length; i++) {
4308
- right.computedBounds.unionAabb(right.objects.getAtIndex(i).computedBounds);
4308
+ right.computedBounds.unionAabb(right.objects.getAtIndex(i).computedExpandedBounds);
4309
4309
  }
4310
4310
  right.parent = best;
4311
4311
  right.height = 0;
@@ -4365,7 +4365,7 @@ class BvhTree {
4365
4365
  this.remove(object);
4366
4366
  return this.insert(object);
4367
4367
  }
4368
- intersectBody(onHit2, body2, shouldUpdateDirtyObjects = true) {
4368
+ intersectBody(onHit2, bodyToIntersect, shouldUpdateDirtyObjects = true) {
4369
4369
  if (!this.root) {
4370
4370
  return;
4371
4371
  }
@@ -4380,7 +4380,7 @@ class BvhTree {
4380
4380
  if (!node) {
4381
4381
  continue;
4382
4382
  }
4383
- if (!node.computedBounds.intersectsAabb(body2.computedBounds)) {
4383
+ if (!node.computedBounds.intersectsAabb(bodyToIntersect.computedBounds)) {
4384
4384
  continue;
4385
4385
  }
4386
4386
  if (!node.isLeaf()) {
@@ -4389,21 +4389,40 @@ class BvhTree {
4389
4389
  continue;
4390
4390
  }
4391
4391
  for (const otherBody of node.objects) {
4392
- if (body2 === otherBody) {
4392
+ if (bodyToIntersect === otherBody || !shouldPairCollide(bodyToIntersect.belongsToGroups, bodyToIntersect.collidesWithGroups, otherBody.belongsToGroups, otherBody.collidesWithGroups) || !bodyToIntersect.computedBounds.intersectsAabb(otherBody.computedBounds)) {
4393
4393
  continue;
4394
4394
  }
4395
- if (shouldPairCollide(
4396
- body2.belongsToGroups,
4397
- body2.collidesWithGroups,
4398
- otherBody.belongsToGroups,
4399
- otherBody.collidesWithGroups
4400
- ) === false) {
4401
- continue;
4395
+ if (onHit2(otherBody)) {
4396
+ return;
4402
4397
  }
4403
- if (!body2.computedBounds.intersectsAabb(otherBody.computedBounds)) {
4398
+ }
4399
+ }
4400
+ }
4401
+ intersectAabb(onHit2, bounds, shouldUpdateDirtyObjects = true) {
4402
+ if (!this.root) {
4403
+ return;
4404
+ }
4405
+ if (shouldUpdateDirtyObjects) {
4406
+ this.updateDirtyObjects();
4407
+ }
4408
+ const stack2 = this.intersectStack;
4409
+ stack2.length = 0;
4410
+ stack2.push(this.root);
4411
+ while (stack2.length > 0) {
4412
+ const node = stack2.pop();
4413
+ if (!node.computedBounds.intersectsAabb(bounds)) {
4414
+ continue;
4415
+ }
4416
+ if (!node.isLeaf()) {
4417
+ stack2.push(node.left);
4418
+ stack2.push(node.right);
4419
+ continue;
4420
+ }
4421
+ for (const object of node.objects) {
4422
+ if (!bounds.intersectsAabb(object.computedBounds)) {
4404
4423
  continue;
4405
4424
  }
4406
- if (onHit2(otherBody)) {
4425
+ if (onHit2(object)) {
4407
4426
  return;
4408
4427
  }
4409
4428
  }
@@ -4445,10 +4464,7 @@ class BvhTree {
4445
4464
  stack2.push(this.root);
4446
4465
  while (stack2.length > 0) {
4447
4466
  const node = stack2.pop();
4448
- if (!node) {
4449
- continue;
4450
- }
4451
- if (node.computedBounds.intersectsAabb(bounds) === false) {
4467
+ if (!node || !node.computedBounds.intersectsAabb(bounds)) {
4452
4468
  continue;
4453
4469
  }
4454
4470
  if (!node.isLeaf()) {
@@ -4457,10 +4473,7 @@ class BvhTree {
4457
4473
  continue;
4458
4474
  }
4459
4475
  for (const body2 of node.objects) {
4460
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4461
- continue;
4462
- }
4463
- if (!body2.computedBounds.intersectsAabb(bounds)) {
4476
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) || !body2.computedBounds.intersectsAabb(bounds)) {
4464
4477
  continue;
4465
4478
  }
4466
4479
  bodyVisitor.visit(body2);
@@ -4486,7 +4499,7 @@ class BvhTree {
4486
4499
  continue;
4487
4500
  }
4488
4501
  nodeBounds$1.copy(node.computedBounds);
4489
- if (ray2.intersectsAabb(nodeBounds$1) === false) {
4502
+ if (!ray2.intersectsAabb(nodeBounds$1)) {
4490
4503
  continue;
4491
4504
  }
4492
4505
  if (!node.isLeaf()) {
@@ -4495,11 +4508,11 @@ class BvhTree {
4495
4508
  continue;
4496
4509
  }
4497
4510
  for (const body2 of node.objects) {
4498
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4511
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups)) {
4499
4512
  continue;
4500
4513
  }
4501
4514
  bodyBounds$1.copy(body2.computedBounds);
4502
- if (ray2.intersectsAabb(bodyBounds$1) === false) {
4515
+ if (!ray2.intersectsAabb(bodyBounds$1)) {
4503
4516
  continue;
4504
4517
  }
4505
4518
  bodyVisitor.visit(body2);
@@ -4530,7 +4543,7 @@ class BvhTree {
4530
4543
  }
4531
4544
  nodeBounds$1.copy(node.computedBounds);
4532
4545
  nodeBounds$1.expandByVector(halfExtents$2);
4533
- if (ray$4.intersectsAabb(nodeBounds$1) === false) {
4546
+ if (!ray$4.intersectsAabb(nodeBounds$1)) {
4534
4547
  continue;
4535
4548
  }
4536
4549
  if (!node.isLeaf()) {
@@ -4539,12 +4552,12 @@ class BvhTree {
4539
4552
  continue;
4540
4553
  }
4541
4554
  for (const body2 of node.objects) {
4542
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4555
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups)) {
4543
4556
  continue;
4544
4557
  }
4545
4558
  bodyBounds$1.copy(body2.computedBounds);
4546
4559
  bodyBounds$1.expandByVector(halfExtents$2);
4547
- if (ray$4.intersectsAabb(bodyBounds$1) === false) {
4560
+ if (!ray$4.intersectsAabb(bodyBounds$1)) {
4548
4561
  continue;
4549
4562
  }
4550
4563
  bodyVisitor.visit(body2);
@@ -7991,6 +8004,7 @@ const bodyProps = {
7991
8004
  angularVelocity: Vec3,
7992
8005
  computedCenterOfMassPosition: ChildType(Vec3, void 0, true),
7993
8006
  computedBounds: ChildType(Aabb, void 0, true),
8007
+ computedExpandedBounds: ChildType(Aabb, void 0, true),
7994
8008
  previousPosition: ChildType(Vec3, void 0, true),
7995
8009
  previousOrientation: ChildType(Quat, void 0, true),
7996
8010
  isSleeping: BooleanType(false, true),
@@ -8042,6 +8056,9 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
8042
8056
  return this["shape" + this.shapeType];
8043
8057
  }
8044
8058
  set shape(newShape) {
8059
+ this.setShape(newShape);
8060
+ }
8061
+ setShape(newShape, updateBroadphase = true) {
8045
8062
  this["shape" + this.shapeType] = null;
8046
8063
  this["shape" + newShape.type] = newShape;
8047
8064
  this.shapeType = newShape.type;
@@ -8063,7 +8080,9 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
8063
8080
  newShape.computedVolume = hull.computedVolume;
8064
8081
  newShape.inertia.copy(hull.inertia);
8065
8082
  }
8066
- updateBody(this);
8083
+ if (updateBroadphase) {
8084
+ updateBody(this);
8085
+ }
8067
8086
  }
8068
8087
  // physics integration functions
8069
8088
  /**
@@ -8379,112 +8398,13 @@ function updateMassProperties(body2) {
8379
8398
  body2.shape.computeInverseInertiaTensor(body2.computedLocalInverseInertia, body2.mass);
8380
8399
  transformTensor(body2.computedWorldInverseInertia, body2.computedLocalInverseInertia, body2.orientation);
8381
8400
  }
8382
- function updateBody(body2) {
8401
+ function updateBody(body2, updateBroadphase = true) {
8383
8402
  updateMassProperties(body2);
8384
8403
  updateCenterOfMassPosition(body2);
8385
8404
  updateWorldBounds(body2);
8386
- }
8387
- var CollisionStatus = /* @__PURE__ */ ((CollisionStatus2) => {
8388
- CollisionStatus2[CollisionStatus2["NotColliding"] = 0] = "NotColliding";
8389
- CollisionStatus2[CollisionStatus2["Colliding"] = 1] = "Colliding";
8390
- CollisionStatus2[CollisionStatus2["Indeterminate"] = 2] = "Indeterminate";
8391
- return CollisionStatus2;
8392
- })(CollisionStatus || {});
8393
- const collisionResultProps = {
8394
- status: NumberType(
8395
- 2
8396
- /* Indeterminate */
8397
- ),
8398
- hasContact: BooleanType(false),
8399
- penetration: 0,
8400
- contactPointA: Vec3,
8401
- contactPointB: Vec3,
8402
- normalA: Vec3,
8403
- normalB: Vec3,
8404
- momentArmA: Vec3,
8405
- momentArmB: Vec3,
8406
- surfaceNormalA: Vec3,
8407
- surfaceNormalB: Vec3,
8408
- bodyA: LazyReferenceType((() => Body)),
8409
- bodyB: LazyReferenceType((() => Body)),
8410
- subShapeIdA: 0,
8411
- subShapeIdB: 0,
8412
- isBackFace: BooleanType(false),
8413
- faceA: Face,
8414
- faceB: Face
8415
- };
8416
- class CollisionResult extends createClass(collisionResultProps) {
8417
- /**
8418
- * swaps the A and B data
8419
- */
8420
- swap() {
8421
- this.contactPointA.swap(this.contactPointB);
8422
- this.normalA.swap(this.normalB);
8423
- this.momentArmA.swap(this.momentArmB);
8424
- this.surfaceNormalA.swap(this.surfaceNormalB);
8425
- const tempBody = this.bodyA;
8426
- this.bodyA = this.bodyB;
8427
- this.bodyB = tempBody;
8428
- const tempSubShapeId = this.subShapeIdA;
8429
- this.subShapeIdA = this.subShapeIdB;
8430
- this.subShapeIdB = tempSubShapeId;
8431
- const tempFace = this.faceA;
8432
- this.faceA = this.faceB;
8433
- this.faceB = tempFace;
8434
- }
8435
- }
8436
- const _CollisionCollector = class _CollisionCollector {
8437
- constructor() {
8438
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8439
- this.body2 = null;
8440
- }
8441
- getEarlyOutFraction() {
8442
- return _CollisionCollector.initialEarlyOutFraction;
8405
+ if (updateBroadphase) {
8406
+ body2.markBodyAsDirty();
8443
8407
  }
8444
- getPositiveEarlyOutFraction() {
8445
- return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
8446
- }
8447
- reset() {
8448
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8449
- this.body2 = null;
8450
- return this;
8451
- }
8452
- addHit(result2) {
8453
- }
8454
- addMiss() {
8455
- }
8456
- };
8457
- _CollisionCollector.initialEarlyOutFraction = Infinity;
8458
- _CollisionCollector.shouldEarlyOutFraction = -Infinity;
8459
- let CollisionCollector = _CollisionCollector;
8460
- var CollectFacesMode = /* @__PURE__ */ ((CollectFacesMode2) => {
8461
- CollectFacesMode2[CollectFacesMode2["CollectFaces"] = 0] = "CollectFaces";
8462
- CollectFacesMode2[CollectFacesMode2["NoFaces"] = 1] = "NoFaces";
8463
- return CollectFacesMode2;
8464
- })(CollectFacesMode || {});
8465
- var ActiveEdgeMode = /* @__PURE__ */ ((ActiveEdgeMode2) => {
8466
- ActiveEdgeMode2[ActiveEdgeMode2["CollideOnlyWithActive"] = 0] = "CollideOnlyWithActive";
8467
- ActiveEdgeMode2[ActiveEdgeMode2["CollideWithAll"] = 1] = "CollideWithAll";
8468
- return ActiveEdgeMode2;
8469
- })(ActiveEdgeMode || {});
8470
- var BackFaceMode = /* @__PURE__ */ ((BackFaceMode2) => {
8471
- BackFaceMode2[BackFaceMode2["IgnoreBackFaces"] = 0] = "IgnoreBackFaces";
8472
- BackFaceMode2[BackFaceMode2["CollideWithBackFaces"] = 1] = "CollideWithBackFaces";
8473
- return BackFaceMode2;
8474
- })(BackFaceMode || {});
8475
- function createDefaultCollisionSettings() {
8476
- return {
8477
- maxSeparation: 0,
8478
- collisionTolerance: 1e-4,
8479
- activeEdgeMode: 0,
8480
- collectFacesMode: 1,
8481
- penetrationTolerance: 1e-4,
8482
- activeEdgeMovementDirectionX: 0,
8483
- activeEdgeMovementDirectionY: 0,
8484
- activeEdgeMovementDirectionZ: 0,
8485
- backFaceMode: 0
8486
- /* IgnoreBackFaces */
8487
- };
8488
8408
  }
8489
8409
  const castResultProps = {
8490
8410
  status: NumberType(
@@ -8567,15 +8487,6 @@ var QueryPrecision = /* @__PURE__ */ ((QueryPrecision2) => {
8567
8487
  QueryPrecision2[QueryPrecision2["preciseWithContacts"] = 2] = "preciseWithContacts";
8568
8488
  return QueryPrecision2;
8569
8489
  })(QueryPrecision || {});
8570
- function createDefaultCastSettings() {
8571
- return {
8572
- ...createDefaultCollisionSettings(),
8573
- backFaceModeConvex: BackFaceMode.IgnoreBackFaces,
8574
- backFaceModeTriangles: BackFaceMode.IgnoreBackFaces,
8575
- useShrunkenShapeAndConvexRadius: false,
8576
- returnDeepestPoint: false
8577
- };
8578
- }
8579
8490
  const ab$4 = /* @__PURE__ */ Vec3.create();
8580
8491
  function computeBarycentricCoordinates2d(outBarycentric, a3, b3, squaredTolerance = 1e-10) {
8581
8492
  ab$4.subtractVectors(b3, a3);
@@ -9437,6 +9348,94 @@ class GjkModule {
9437
9348
  }
9438
9349
  }
9439
9350
  const v = /* @__PURE__ */ Vec3.create();
9351
+ var CollisionStatus = /* @__PURE__ */ ((CollisionStatus2) => {
9352
+ CollisionStatus2[CollisionStatus2["NotColliding"] = 0] = "NotColliding";
9353
+ CollisionStatus2[CollisionStatus2["Colliding"] = 1] = "Colliding";
9354
+ CollisionStatus2[CollisionStatus2["Indeterminate"] = 2] = "Indeterminate";
9355
+ return CollisionStatus2;
9356
+ })(CollisionStatus || {});
9357
+ const collisionResultProps = {
9358
+ status: NumberType(
9359
+ 2
9360
+ /* Indeterminate */
9361
+ ),
9362
+ hasContact: BooleanType(false),
9363
+ penetration: 0,
9364
+ contactPointA: Vec3,
9365
+ contactPointB: Vec3,
9366
+ normalA: Vec3,
9367
+ normalB: Vec3,
9368
+ momentArmA: Vec3,
9369
+ momentArmB: Vec3,
9370
+ surfaceNormalA: Vec3,
9371
+ surfaceNormalB: Vec3,
9372
+ bodyA: LazyReferenceType((() => Body)),
9373
+ bodyB: LazyReferenceType((() => Body)),
9374
+ subShapeIdA: 0,
9375
+ subShapeIdB: 0,
9376
+ isBackFace: BooleanType(false),
9377
+ faceA: Face,
9378
+ faceB: Face
9379
+ };
9380
+ class CollisionResult extends createClass(collisionResultProps) {
9381
+ /**
9382
+ * swaps the A and B data
9383
+ */
9384
+ swap() {
9385
+ this.contactPointA.swap(this.contactPointB);
9386
+ this.normalA.swap(this.normalB);
9387
+ this.momentArmA.swap(this.momentArmB);
9388
+ this.surfaceNormalA.swap(this.surfaceNormalB);
9389
+ const tempBody = this.bodyA;
9390
+ this.bodyA = this.bodyB;
9391
+ this.bodyB = tempBody;
9392
+ const tempSubShapeId = this.subShapeIdA;
9393
+ this.subShapeIdA = this.subShapeIdB;
9394
+ this.subShapeIdB = tempSubShapeId;
9395
+ const tempFace = this.faceA;
9396
+ this.faceA = this.faceB;
9397
+ this.faceB = tempFace;
9398
+ }
9399
+ }
9400
+ const _CollisionCollector = class _CollisionCollector {
9401
+ constructor() {
9402
+ this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
9403
+ this.body2 = null;
9404
+ }
9405
+ getEarlyOutFraction() {
9406
+ return _CollisionCollector.initialEarlyOutFraction;
9407
+ }
9408
+ getPositiveEarlyOutFraction() {
9409
+ return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
9410
+ }
9411
+ reset() {
9412
+ this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
9413
+ this.body2 = null;
9414
+ return this;
9415
+ }
9416
+ addHit(result2) {
9417
+ }
9418
+ addMiss() {
9419
+ }
9420
+ };
9421
+ _CollisionCollector.initialEarlyOutFraction = Infinity;
9422
+ _CollisionCollector.shouldEarlyOutFraction = -Infinity;
9423
+ let CollisionCollector = _CollisionCollector;
9424
+ var CollectFacesMode = /* @__PURE__ */ ((CollectFacesMode2) => {
9425
+ CollectFacesMode2[CollectFacesMode2["CollectFaces"] = 0] = "CollectFaces";
9426
+ CollectFacesMode2[CollectFacesMode2["NoFaces"] = 1] = "NoFaces";
9427
+ return CollectFacesMode2;
9428
+ })(CollectFacesMode || {});
9429
+ var ActiveEdgeMode = /* @__PURE__ */ ((ActiveEdgeMode2) => {
9430
+ ActiveEdgeMode2[ActiveEdgeMode2["CollideOnlyWithActive"] = 0] = "CollideOnlyWithActive";
9431
+ ActiveEdgeMode2[ActiveEdgeMode2["CollideWithAll"] = 1] = "CollideWithAll";
9432
+ return ActiveEdgeMode2;
9433
+ })(ActiveEdgeMode || {});
9434
+ var BackFaceMode = /* @__PURE__ */ ((BackFaceMode2) => {
9435
+ BackFaceMode2[BackFaceMode2["IgnoreBackFaces"] = 0] = "IgnoreBackFaces";
9436
+ BackFaceMode2[BackFaceMode2["CollideWithBackFaces"] = 1] = "CollideWithBackFaces";
9437
+ return BackFaceMode2;
9438
+ })(BackFaceMode || {});
9440
9439
  const edgeProps = {
9441
9440
  neighbourTriangle: LazyReferenceType((() => Triangle2)),
9442
9441
  neighbourEdge: 0,
@@ -11218,88 +11217,79 @@ function collideCompoundVsTriangleMesh(penetrationDepthModule2, collector2, shap
11218
11217
  function noOp() {
11219
11218
  return;
11220
11219
  }
11221
- const collideShapesFns = {
11222
- [ShapeType.sphere]: {
11223
- [ShapeType.box]: collideConvexVsConvex,
11224
- [ShapeType.capsule]: collideConvexVsConvex,
11225
- [ShapeType.convexHull]: collideConvexVsConvex,
11226
- [ShapeType.compoundShape]: collideConvexVsCompound,
11227
- [ShapeType.cylinder]: collideConvexVsConvex,
11228
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11229
- [ShapeType.sphere]: collideSphereVsSphere,
11230
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11231
- },
11232
- [ShapeType.box]: {
11233
- [ShapeType.box]: collideConvexVsConvex,
11234
- [ShapeType.capsule]: collideConvexVsConvex,
11235
- [ShapeType.compoundShape]: collideConvexVsCompound,
11236
- [ShapeType.convexHull]: collideConvexVsConvex,
11237
- [ShapeType.cylinder]: collideConvexVsConvex,
11238
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11239
- [ShapeType.sphere]: collideConvexVsConvex,
11240
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11241
- },
11242
- [ShapeType.convexHull]: {
11243
- [ShapeType.box]: collideConvexVsConvex,
11244
- [ShapeType.capsule]: collideConvexVsConvex,
11245
- [ShapeType.compoundShape]: collideConvexVsCompound,
11246
- [ShapeType.convexHull]: collideConvexVsConvex,
11247
- [ShapeType.cylinder]: collideConvexVsConvex,
11248
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11249
- [ShapeType.sphere]: collideConvexVsConvex,
11250
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11251
- },
11252
- [ShapeType.compoundShape]: {
11253
- [ShapeType.box]: collideCompoundVsConvex,
11254
- [ShapeType.capsule]: collideCompoundVsConvex,
11255
- [ShapeType.compoundShape]: collideCompoundVsCompound,
11256
- [ShapeType.convexHull]: collideCompoundVsConvex,
11257
- [ShapeType.cylinder]: collideCompoundVsConvex,
11258
- [ShapeType.heightMap]: collideCompoundVsHeightMap,
11259
- [ShapeType.sphere]: collideCompoundVsConvex,
11260
- [ShapeType.triangleMesh]: collideCompoundVsTriangleMesh
11261
- },
11262
- [ShapeType.cylinder]: {
11263
- [ShapeType.box]: collideConvexVsConvex,
11264
- [ShapeType.capsule]: collideConvexVsConvex,
11265
- [ShapeType.compoundShape]: collideConvexVsCompound,
11266
- [ShapeType.convexHull]: collideConvexVsConvex,
11267
- [ShapeType.cylinder]: collideConvexVsConvex,
11268
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11269
- [ShapeType.sphere]: collideConvexVsConvex,
11270
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11271
- },
11272
- [ShapeType.capsule]: {
11273
- [ShapeType.box]: collideConvexVsConvex,
11274
- [ShapeType.capsule]: collideConvexVsConvex,
11275
- [ShapeType.compoundShape]: collideConvexVsCompound,
11276
- [ShapeType.convexHull]: collideConvexVsConvex,
11277
- [ShapeType.cylinder]: collideConvexVsConvex,
11278
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11279
- [ShapeType.sphere]: collideConvexVsConvex,
11280
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11281
- },
11282
- [ShapeType.heightMap]: {
11283
- [ShapeType.box]: collideHeightMapVsConvex,
11284
- [ShapeType.capsule]: collideHeightMapVsConvex,
11285
- [ShapeType.compoundShape]: collideHeightMapVsCompound,
11286
- [ShapeType.convexHull]: collideHeightMapVsConvex,
11287
- [ShapeType.cylinder]: collideHeightMapVsConvex,
11288
- [ShapeType.heightMap]: noOp,
11289
- [ShapeType.sphere]: collideHeightMapVsConvex,
11290
- [ShapeType.triangleMesh]: noOp
11291
- },
11292
- [ShapeType.triangleMesh]: {
11293
- [ShapeType.box]: collideTriangleMeshVsConvex,
11294
- [ShapeType.capsule]: collideTriangleMeshVsConvex,
11295
- [ShapeType.compoundShape]: collideTriangleMeshVsCompound,
11296
- [ShapeType.convexHull]: collideTriangleMeshVsConvex,
11297
- [ShapeType.cylinder]: collideTriangleMeshVsConvex,
11298
- [ShapeType.heightMap]: noOp,
11299
- [ShapeType.sphere]: collideTriangleMeshVsConvex,
11300
- [ShapeType.triangleMesh]: noOp
11301
- }
11302
- };
11220
+ const collideShapesFns = [];
11221
+ collideShapesFns[ShapeType.box] = [];
11222
+ collideShapesFns[ShapeType.capsule] = [];
11223
+ collideShapesFns[ShapeType.compoundShape] = [];
11224
+ collideShapesFns[ShapeType.convexHull] = [];
11225
+ collideShapesFns[ShapeType.cylinder] = [];
11226
+ collideShapesFns[ShapeType.heightMap] = [];
11227
+ collideShapesFns[ShapeType.sphere] = [];
11228
+ collideShapesFns[ShapeType.triangleMesh] = [];
11229
+ collideShapesFns[ShapeType.box][ShapeType.box] = collideConvexVsConvex;
11230
+ collideShapesFns[ShapeType.box][ShapeType.capsule] = collideConvexVsConvex;
11231
+ collideShapesFns[ShapeType.box][ShapeType.compoundShape] = collideConvexVsCompound;
11232
+ collideShapesFns[ShapeType.box][ShapeType.convexHull] = collideConvexVsConvex;
11233
+ collideShapesFns[ShapeType.box][ShapeType.cylinder] = collideConvexVsConvex;
11234
+ collideShapesFns[ShapeType.box][ShapeType.heightMap] = collideConvexVsHeightMap;
11235
+ collideShapesFns[ShapeType.box][ShapeType.sphere] = collideConvexVsConvex;
11236
+ collideShapesFns[ShapeType.box][ShapeType.triangleMesh] = collideConvexVsTriangleMesh;
11237
+ collideShapesFns[ShapeType.capsule][ShapeType.box] = collideConvexVsConvex;
11238
+ collideShapesFns[ShapeType.capsule][ShapeType.capsule] = collideConvexVsConvex;
11239
+ collideShapesFns[ShapeType.capsule][ShapeType.compoundShape] = collideConvexVsCompound;
11240
+ collideShapesFns[ShapeType.capsule][ShapeType.convexHull] = collideConvexVsConvex;
11241
+ collideShapesFns[ShapeType.capsule][ShapeType.cylinder] = collideConvexVsConvex;
11242
+ collideShapesFns[ShapeType.capsule][ShapeType.heightMap] = collideConvexVsHeightMap;
11243
+ collideShapesFns[ShapeType.capsule][ShapeType.sphere] = collideConvexVsConvex;
11244
+ collideShapesFns[ShapeType.capsule][ShapeType.triangleMesh] = collideConvexVsTriangleMesh;
11245
+ collideShapesFns[ShapeType.compoundShape][ShapeType.box] = collideCompoundVsConvex;
11246
+ collideShapesFns[ShapeType.compoundShape][ShapeType.capsule] = collideCompoundVsConvex;
11247
+ collideShapesFns[ShapeType.compoundShape][ShapeType.compoundShape] = collideCompoundVsCompound;
11248
+ collideShapesFns[ShapeType.compoundShape][ShapeType.convexHull] = collideCompoundVsConvex;
11249
+ collideShapesFns[ShapeType.compoundShape][ShapeType.cylinder] = collideCompoundVsConvex;
11250
+ collideShapesFns[ShapeType.compoundShape][ShapeType.heightMap] = collideCompoundVsHeightMap;
11251
+ collideShapesFns[ShapeType.compoundShape][ShapeType.sphere] = collideCompoundVsConvex;
11252
+ collideShapesFns[ShapeType.compoundShape][ShapeType.triangleMesh] = collideCompoundVsTriangleMesh;
11253
+ collideShapesFns[ShapeType.convexHull][ShapeType.box] = collideConvexVsConvex;
11254
+ collideShapesFns[ShapeType.convexHull][ShapeType.capsule] = collideConvexVsConvex;
11255
+ collideShapesFns[ShapeType.convexHull][ShapeType.compoundShape] = collideConvexVsCompound;
11256
+ collideShapesFns[ShapeType.convexHull][ShapeType.convexHull] = collideConvexVsConvex;
11257
+ collideShapesFns[ShapeType.convexHull][ShapeType.cylinder] = collideConvexVsConvex;
11258
+ collideShapesFns[ShapeType.convexHull][ShapeType.heightMap] = collideConvexVsHeightMap;
11259
+ collideShapesFns[ShapeType.convexHull][ShapeType.sphere] = collideConvexVsConvex;
11260
+ collideShapesFns[ShapeType.convexHull][ShapeType.triangleMesh] = collideConvexVsTriangleMesh;
11261
+ collideShapesFns[ShapeType.cylinder][ShapeType.box] = collideConvexVsConvex;
11262
+ collideShapesFns[ShapeType.cylinder][ShapeType.capsule] = collideConvexVsConvex;
11263
+ collideShapesFns[ShapeType.cylinder][ShapeType.compoundShape] = collideConvexVsCompound;
11264
+ collideShapesFns[ShapeType.cylinder][ShapeType.convexHull] = collideConvexVsConvex;
11265
+ collideShapesFns[ShapeType.cylinder][ShapeType.cylinder] = collideConvexVsConvex;
11266
+ collideShapesFns[ShapeType.cylinder][ShapeType.heightMap] = collideConvexVsHeightMap;
11267
+ collideShapesFns[ShapeType.cylinder][ShapeType.sphere] = collideConvexVsConvex;
11268
+ collideShapesFns[ShapeType.cylinder][ShapeType.triangleMesh] = collideConvexVsTriangleMesh;
11269
+ collideShapesFns[ShapeType.heightMap][ShapeType.box] = collideHeightMapVsConvex;
11270
+ collideShapesFns[ShapeType.heightMap][ShapeType.capsule] = collideHeightMapVsConvex;
11271
+ collideShapesFns[ShapeType.heightMap][ShapeType.compoundShape] = collideHeightMapVsCompound;
11272
+ collideShapesFns[ShapeType.heightMap][ShapeType.convexHull] = collideHeightMapVsConvex;
11273
+ collideShapesFns[ShapeType.heightMap][ShapeType.cylinder] = collideHeightMapVsConvex;
11274
+ collideShapesFns[ShapeType.heightMap][ShapeType.heightMap] = noOp;
11275
+ collideShapesFns[ShapeType.heightMap][ShapeType.sphere] = collideHeightMapVsConvex;
11276
+ collideShapesFns[ShapeType.heightMap][ShapeType.triangleMesh] = noOp;
11277
+ collideShapesFns[ShapeType.sphere][ShapeType.box] = collideConvexVsConvex;
11278
+ collideShapesFns[ShapeType.sphere][ShapeType.capsule] = collideConvexVsConvex;
11279
+ collideShapesFns[ShapeType.sphere][ShapeType.compoundShape] = collideConvexVsCompound;
11280
+ collideShapesFns[ShapeType.sphere][ShapeType.convexHull] = collideConvexVsConvex;
11281
+ collideShapesFns[ShapeType.sphere][ShapeType.cylinder] = collideConvexVsConvex;
11282
+ collideShapesFns[ShapeType.sphere][ShapeType.heightMap] = collideConvexVsHeightMap;
11283
+ collideShapesFns[ShapeType.sphere][ShapeType.sphere] = collideSphereVsSphere;
11284
+ collideShapesFns[ShapeType.sphere][ShapeType.triangleMesh] = collideConvexVsTriangleMesh;
11285
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.box] = collideTriangleMeshVsConvex;
11286
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.capsule] = collideTriangleMeshVsConvex;
11287
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.compoundShape] = collideTriangleMeshVsCompound;
11288
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.convexHull] = collideTriangleMeshVsConvex;
11289
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.cylinder] = collideTriangleMeshVsConvex;
11290
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.heightMap] = noOp;
11291
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.sphere] = collideTriangleMeshVsConvex;
11292
+ collideShapesFns[ShapeType.triangleMesh][ShapeType.triangleMesh] = noOp;
11303
11293
  class CollideShapesModule {
11304
11294
  constructor(penetrationDepthModule2) {
11305
11295
  this.penetrationDepthModule = penetrationDepthModule2;
@@ -11309,11 +11299,9 @@ class CollideShapesModule {
11309
11299
  // the isometries must transform the shapes into world space
11310
11300
  // the results are in world space
11311
11301
  collideShapes(collector2, shapeA, isometryA2, shapeB2, isometryB2, settings, bodyA, bodyB, subShapeIdA = 0, subShapeIdB = 0) {
11312
- const keyA = shapeA.type;
11313
- const keyB = shapeB2.type;
11314
- const collisionFunction = collideShapesFns[keyA][keyB];
11302
+ const collisionFunction = collideShapesFns[shapeA.type][shapeB2.type];
11315
11303
  if (!collisionFunction) {
11316
- throw new Error(`no collision function found for shapes with type ${keyA} and ${keyB}`);
11304
+ throw new Error(`no collision function found for shapes with type ${shapeA.type} and ${shapeB2.type}`);
11317
11305
  }
11318
11306
  return collisionFunction(
11319
11307
  this.penetrationDepthModule,
@@ -11628,7 +11616,7 @@ class CollideBodiesModule {
11628
11616
  }
11629
11617
  isometryA.matrix.postTranslatedMatrix(inCenterOfMassTransform.matrix, offset);
11630
11618
  boundsA$1.copy(inShape.computedAabb);
11631
- boundsA$1.expand(inCollideShapeSettings ? inCollideShapeSettings.maxSeparation : 0);
11619
+ boundsA$1.expand(inCollideShapeSettings?.maxSeparation ?? 0);
11632
11620
  boundsA$1.transform(inCenterOfMassTransform);
11633
11621
  collideShapeVisitor.initialize(
11634
11622
  isometryA,
@@ -11735,7 +11723,7 @@ class CastRayBodyVisitor {
11735
11723
  }
11736
11724
  visit(body2) {
11737
11725
  isometryB.fromRotationAndTranslation(body2.orientation, body2.computedCenterOfMassPosition);
11738
- this.castModule.castRay(this.collector, this.ray, body2.shape, isometryB, 1, zeroVector$1, this.settings, body2);
11726
+ this.castModule.castRay(this.collector, this.ray, body2.shape, isometryB, 1, zeroVector$1, body2);
11739
11727
  }
11740
11728
  }
11741
11729
  const castRayVisitor = /* @__PURE__ */ new CastRayBodyVisitor();
@@ -12615,19 +12603,9 @@ class BvhModule {
12615
12603
  for (const node of this.pairs.iteratePairs()) {
12616
12604
  const bodyA = node.bodyA;
12617
12605
  const bodyB = node.bodyB;
12618
- if (bodyA.type === BodyType.static && bodyB.type === BodyType.static) {
12606
+ if (bodyA.type !== BodyType.dynamic && bodyB.type !== BodyType.dynamic || bodyB.type === BodyType.static && bodyA.isSleeping) {
12619
12607
  continue;
12620
12608
  }
12621
- if (bodyA.type === BodyType.static && bodyB.type === BodyType.dynamic) {
12622
- if (bodyB.isSleeping) {
12623
- continue;
12624
- }
12625
- }
12626
- if (bodyA.type === BodyType.dynamic && bodyB.type === BodyType.static) {
12627
- if (bodyA.isSleeping) {
12628
- continue;
12629
- }
12630
- }
12631
12609
  yield node;
12632
12610
  }
12633
12611
  }
@@ -13069,7 +13047,7 @@ function castConvexVsTriangleMesh(penetrationDepthModule2, ioCollector, inShapeA
13069
13047
  isometryWorldToB$2.matrix.multiply3x3(transformedDisplacement, displacement2);
13070
13048
  inShapeB.bvh.castAabb(onHit$2, boundsA, transformedDisplacement);
13071
13049
  }
13072
- function castRayVsConvex(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13050
+ function castRayVsConvex(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13073
13051
  const convexB2 = inShapeB.computeSupportShape(SupportMode.IncludeConvexRadius, 1);
13074
13052
  raycast.fraction = ioCollector.getEarlyOutFraction();
13075
13053
  worldToB.matrix.invertMatrix(isometryB2.matrix);
@@ -13095,7 +13073,7 @@ const result$2 = /* @__PURE__ */ CastResult.create();
13095
13073
  const raycast = { fraction: 0 };
13096
13074
  const transformedRay$2 = /* @__PURE__ */ Ray.create();
13097
13075
  const worldToB = /* @__PURE__ */ Isometry.create();
13098
- function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13076
+ function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13099
13077
  for (const shapeObj of inShapeB.shapes) {
13100
13078
  const shape = shapeObj.shape;
13101
13079
  const transform2 = shapeObj.transform;
@@ -13109,7 +13087,6 @@ function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB
13109
13087
  transformSubShapeBToWorld,
13110
13088
  inScaleB,
13111
13089
  offset2,
13112
- inSettings,
13113
13090
  bodyB
13114
13091
  );
13115
13092
  }
@@ -13136,7 +13113,7 @@ function onHit$1(triangle2) {
13136
13113
  collector$1.addHit(result$1);
13137
13114
  return false;
13138
13115
  }
13139
- function castRayVsTriangleMesh(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13116
+ function castRayVsTriangleMesh(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13140
13117
  ioCollector.reset();
13141
13118
  isometryWorldToB$1.matrix.invertMatrix(isometryB2.matrix);
13142
13119
  transformedRay$1.copy(inRay).transform(isometryWorldToB$1);
@@ -13169,7 +13146,7 @@ function onHit(triangle2) {
13169
13146
  collector.addHit(result);
13170
13147
  return false;
13171
13148
  }
13172
- function castRayVsHeightMap(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13149
+ function castRayVsHeightMap(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13173
13150
  ioCollector.reset();
13174
13151
  isometryWorldToB.matrix.invertMatrix(isometryB2.matrix);
13175
13152
  transformedRay.copy(inRay).transform(isometryWorldToB);
@@ -13182,100 +13159,76 @@ const result = /* @__PURE__ */ CastResult.create();
13182
13159
  const raycasterResult = { fraction: 1, hit: false };
13183
13160
  const isometryWorldToB = /* @__PURE__ */ Isometry.create();
13184
13161
  const transformedRay = /* @__PURE__ */ Ray.create();
13185
- const castShapesFns = {
13186
- [ShapeType.sphere]: {
13187
- [ShapeType.box]: castConvexVsConvex,
13188
- [ShapeType.capsule]: castConvexVsConvex,
13189
- [ShapeType.compoundShape]: castConvexVsCompound,
13190
- [ShapeType.convexHull]: castConvexVsConvex,
13191
- [ShapeType.cylinder]: castConvexVsConvex,
13192
- [ShapeType.heightMap]: castConvexVsHeightMap,
13193
- [ShapeType.sphere]: castConvexVsConvex,
13194
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13195
- },
13196
- [ShapeType.box]: {
13197
- [ShapeType.box]: castConvexVsConvex,
13198
- [ShapeType.capsule]: castConvexVsConvex,
13199
- [ShapeType.compoundShape]: castConvexVsCompound,
13200
- [ShapeType.convexHull]: castConvexVsConvex,
13201
- [ShapeType.cylinder]: castConvexVsConvex,
13202
- [ShapeType.heightMap]: castConvexVsHeightMap,
13203
- [ShapeType.sphere]: castConvexVsConvex,
13204
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13205
- },
13206
- [ShapeType.capsule]: {
13207
- [ShapeType.box]: castConvexVsConvex,
13208
- [ShapeType.capsule]: castConvexVsConvex,
13209
- [ShapeType.compoundShape]: castConvexVsCompound,
13210
- [ShapeType.convexHull]: castConvexVsConvex,
13211
- [ShapeType.cylinder]: castConvexVsConvex,
13212
- [ShapeType.heightMap]: castConvexVsHeightMap,
13213
- [ShapeType.sphere]: castConvexVsConvex,
13214
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13215
- },
13216
- [ShapeType.cylinder]: {
13217
- [ShapeType.box]: castConvexVsConvex,
13218
- [ShapeType.capsule]: castConvexVsConvex,
13219
- [ShapeType.compoundShape]: castConvexVsCompound,
13220
- [ShapeType.convexHull]: castConvexVsConvex,
13221
- [ShapeType.cylinder]: castConvexVsConvex,
13222
- [ShapeType.heightMap]: castConvexVsHeightMap,
13223
- [ShapeType.sphere]: castConvexVsConvex,
13224
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13225
- },
13226
- [ShapeType.compoundShape]: {
13227
- [ShapeType.box]: castCompoundVsConvex,
13228
- [ShapeType.capsule]: castCompoundVsConvex,
13229
- // [ShapeType.compoundShape]: castCompoundVsCompound,
13230
- [ShapeType.convexHull]: castCompoundVsConvex,
13231
- [ShapeType.cylinder]: castCompoundVsConvex,
13232
- // [ShapeType.heightMap]: castCompoundVsHeightMap,
13233
- [ShapeType.sphere]: castCompoundVsConvex
13234
- // [ShapeType.triangleMesh]: castCompoundVsTriangleMesh,
13235
- }
13236
- // [ShapeType.heightMap]: {
13237
- // [ShapeType.box]: castHeightMapVsConvex,
13238
- // [ShapeType.capsule]: castHeightMapVsConvex,
13239
- // [ShapeType.compoundShape]: castHeightMapVsCompound,
13240
- // [ShapeType.convexHull]: castHeightMapVsConvex,
13241
- // [ShapeType.cylinder]: castHeightMapVsConvex,
13242
- // [ShapeType.heightMap]: castHeightMapVsHeightMap,
13243
- // [ShapeType.sphere]: castHeightMapVsConvex,
13244
- // [ShapeType.triangleMesh]: castHeightMapVsTriangleMesh,
13245
- // },
13246
- // [ShapeType.triangleMesh]: {
13247
- // [ShapeType.box]: castTriangleMeshVsConvex,
13248
- // [ShapeType.capsule]: castTriangleMeshVsConvex,
13249
- // [ShapeType.compoundShape]: castTriangleMeshVsCompound,
13250
- // [ShapeType.convexHull]: castTriangleMeshVsConvex,
13251
- // [ShapeType.cylinder]: castTriangleMeshVsConvex,
13252
- // [ShapeType.heightMap]: castTriangleMeshVsHeightMap,
13253
- // [ShapeType.sphere]: castTriangleMeshVsConvex,
13254
- // [ShapeType.triangleMesh]: castTriangleMeshVsTriangleMesh,
13255
- // },
13256
- // [ShapeType.triangle]: {
13257
- // [ShapeType.box]: castTriangleVsConvex,
13258
- // [ShapeType.sphere]: castTriangleVsConvex,
13259
- // },
13260
- };
13261
- const raycastFns = {
13262
- [ShapeType.sphere]: castRayVsConvex,
13263
- [ShapeType.box]: castRayVsConvex,
13264
- [ShapeType.capsule]: castRayVsConvex,
13265
- [ShapeType.cylinder]: castRayVsConvex,
13266
- [ShapeType.compoundShape]: castRayVsCompound,
13267
- // castRayVsCompound,
13268
- [ShapeType.convexHull]: castRayVsConvex,
13269
- [ShapeType.heightMap]: castRayVsHeightMap,
13270
- // castRayVsHeightMap,
13271
- [ShapeType.triangleMesh]: castRayVsTriangleMesh
13272
- // castRayVsTriangleMesh,
13273
- };
13162
+ const castShapesFns = [];
13163
+ castShapesFns[ShapeType.box] = [];
13164
+ castShapesFns[ShapeType.capsule] = [];
13165
+ castShapesFns[ShapeType.compoundShape] = [];
13166
+ castShapesFns[ShapeType.convexHull] = [];
13167
+ castShapesFns[ShapeType.cylinder] = [];
13168
+ castShapesFns[ShapeType.heightMap] = [];
13169
+ castShapesFns[ShapeType.sphere] = [];
13170
+ castShapesFns[ShapeType.triangleMesh] = [];
13171
+ castShapesFns[ShapeType.box][ShapeType.box] = castConvexVsConvex;
13172
+ castShapesFns[ShapeType.box][ShapeType.capsule] = castConvexVsConvex;
13173
+ castShapesFns[ShapeType.box][ShapeType.compoundShape] = castConvexVsCompound;
13174
+ castShapesFns[ShapeType.box][ShapeType.convexHull] = castConvexVsConvex;
13175
+ castShapesFns[ShapeType.box][ShapeType.cylinder] = castConvexVsConvex;
13176
+ castShapesFns[ShapeType.box][ShapeType.heightMap] = castConvexVsHeightMap;
13177
+ castShapesFns[ShapeType.box][ShapeType.sphere] = castConvexVsConvex;
13178
+ castShapesFns[ShapeType.box][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13179
+ castShapesFns[ShapeType.capsule][ShapeType.box] = castConvexVsConvex;
13180
+ castShapesFns[ShapeType.capsule][ShapeType.capsule] = castConvexVsConvex;
13181
+ castShapesFns[ShapeType.capsule][ShapeType.compoundShape] = castConvexVsCompound;
13182
+ castShapesFns[ShapeType.capsule][ShapeType.convexHull] = castConvexVsConvex;
13183
+ castShapesFns[ShapeType.capsule][ShapeType.cylinder] = castConvexVsConvex;
13184
+ castShapesFns[ShapeType.capsule][ShapeType.heightMap] = castConvexVsHeightMap;
13185
+ castShapesFns[ShapeType.capsule][ShapeType.sphere] = castConvexVsConvex;
13186
+ castShapesFns[ShapeType.capsule][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13187
+ castShapesFns[ShapeType.compoundShape][ShapeType.box] = castCompoundVsConvex;
13188
+ castShapesFns[ShapeType.compoundShape][ShapeType.capsule] = castCompoundVsConvex;
13189
+ castShapesFns[ShapeType.compoundShape][ShapeType.convexHull] = castCompoundVsConvex;
13190
+ castShapesFns[ShapeType.compoundShape][ShapeType.cylinder] = castCompoundVsConvex;
13191
+ castShapesFns[ShapeType.compoundShape][ShapeType.heightMap] = castConvexVsHeightMap;
13192
+ castShapesFns[ShapeType.compoundShape][ShapeType.sphere] = castCompoundVsConvex;
13193
+ castShapesFns[ShapeType.compoundShape][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13194
+ castShapesFns[ShapeType.convexHull][ShapeType.box] = castConvexVsConvex;
13195
+ castShapesFns[ShapeType.convexHull][ShapeType.capsule] = castConvexVsConvex;
13196
+ castShapesFns[ShapeType.convexHull][ShapeType.compoundShape] = castConvexVsCompound;
13197
+ castShapesFns[ShapeType.convexHull][ShapeType.convexHull] = castConvexVsConvex;
13198
+ castShapesFns[ShapeType.convexHull][ShapeType.cylinder] = castConvexVsConvex;
13199
+ castShapesFns[ShapeType.convexHull][ShapeType.heightMap] = castConvexVsHeightMap;
13200
+ castShapesFns[ShapeType.convexHull][ShapeType.sphere] = castConvexVsConvex;
13201
+ castShapesFns[ShapeType.convexHull][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13202
+ castShapesFns[ShapeType.cylinder][ShapeType.box] = castConvexVsConvex;
13203
+ castShapesFns[ShapeType.cylinder][ShapeType.capsule] = castConvexVsConvex;
13204
+ castShapesFns[ShapeType.cylinder][ShapeType.compoundShape] = castConvexVsCompound;
13205
+ castShapesFns[ShapeType.cylinder][ShapeType.convexHull] = castConvexVsConvex;
13206
+ castShapesFns[ShapeType.cylinder][ShapeType.cylinder] = castConvexVsConvex;
13207
+ castShapesFns[ShapeType.cylinder][ShapeType.heightMap] = castConvexVsHeightMap;
13208
+ castShapesFns[ShapeType.cylinder][ShapeType.sphere] = castConvexVsConvex;
13209
+ castShapesFns[ShapeType.cylinder][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13210
+ castShapesFns[ShapeType.sphere][ShapeType.box] = castConvexVsConvex;
13211
+ castShapesFns[ShapeType.sphere][ShapeType.capsule] = castConvexVsConvex;
13212
+ castShapesFns[ShapeType.sphere][ShapeType.compoundShape] = castConvexVsCompound;
13213
+ castShapesFns[ShapeType.sphere][ShapeType.convexHull] = castConvexVsConvex;
13214
+ castShapesFns[ShapeType.sphere][ShapeType.cylinder] = castConvexVsConvex;
13215
+ castShapesFns[ShapeType.sphere][ShapeType.heightMap] = castConvexVsHeightMap;
13216
+ castShapesFns[ShapeType.sphere][ShapeType.sphere] = castConvexVsConvex;
13217
+ castShapesFns[ShapeType.sphere][ShapeType.triangleMesh] = castConvexVsTriangleMesh;
13218
+ const raycastFns = [];
13219
+ raycastFns[ShapeType.box] = castRayVsConvex;
13220
+ raycastFns[ShapeType.capsule] = castRayVsConvex;
13221
+ raycastFns[ShapeType.compoundShape] = castRayVsCompound;
13222
+ raycastFns[ShapeType.convexHull] = castRayVsConvex;
13223
+ raycastFns[ShapeType.cylinder] = castRayVsConvex;
13224
+ raycastFns[ShapeType.heightMap] = castRayVsHeightMap;
13225
+ raycastFns[ShapeType.sphere] = castRayVsConvex;
13226
+ raycastFns[ShapeType.triangleMesh] = castRayVsTriangleMesh;
13274
13227
  class CastShapesModule {
13275
13228
  constructor(penetrationDepthModule2) {
13276
13229
  this.penetrationDepthModule = penetrationDepthModule2;
13277
13230
  }
13278
- castRay(collector2, ray2, shapeB2, isometryB2, scaleB, offset2, settings, bodyB = null) {
13231
+ castRay(collector2, ray2, shapeB2, isometryB2, scaleB, offset2, bodyB = null) {
13279
13232
  const fn = raycastFns[shapeB2.type];
13280
13233
  if (!fn) {
13281
13234
  return;
@@ -13289,7 +13242,6 @@ class CastShapesModule {
13289
13242
  isometryB2,
13290
13243
  scaleB,
13291
13244
  offset2,
13292
- settings,
13293
13245
  bodyB
13294
13246
  );
13295
13247
  }
@@ -13298,11 +13250,9 @@ class CastShapesModule {
13298
13250
  // the isometries must transform the shapes into world space
13299
13251
  // the results are in world space
13300
13252
  castShapes(collector2, shapeA, isometryA2, scaleA, shapeB2, isometryB2, scaleB, displacement2, offset2, settings, bodyA = null, bodyB = null) {
13301
- const keyA = shapeA.type;
13302
- const keyB = shapeB2.type;
13303
- const castFunction = castShapesFns[keyA][keyB];
13253
+ const castFunction = castShapesFns[shapeA.type][shapeB2.type];
13304
13254
  if (!castFunction) {
13305
- throw new Error(`no cast function found for shapes with type ${keyA} and ${keyB}`);
13255
+ throw new Error(`no cast function found for shapes with type ${shapeA.type} and ${shapeB2.type}`);
13306
13256
  }
13307
13257
  return castFunction(
13308
13258
  this.penetrationDepthModule,
@@ -15458,11 +15408,6 @@ class World {
15458
15408
  updateWorldBounds(body2);
15459
15409
  }
15460
15410
  }
15461
- // updateBodyProperties() {
15462
- // for (const body of this.bodies()) {
15463
- // // updateBody(body);
15464
- // }
15465
- // }
15466
15411
  clearForcesOnBodies() {
15467
15412
  for (const body2 of this.dynamicBodies) {
15468
15413
  body2.clearForces();
@@ -15666,10 +15611,13 @@ class World {
15666
15611
  options.type = BodyType.static;
15667
15612
  options.world = this;
15668
15613
  const body2 = this.staticBodies.create(options);
15614
+ const originalShape = options.shape;
15615
+ options.shape = null;
15669
15616
  const bodyCopy = this.staticBodyCopies.create(options);
15670
15617
  bodyCopy.copy(body2);
15671
15618
  body2.copyForDiff = bodyCopy;
15672
- this.broadphase.addStaticBody(body2);
15619
+ bodyCopy.setShape(body2.shape, false);
15620
+ options.shape = originalShape;
15673
15621
  return body2;
15674
15622
  }
15675
15623
  createDynamicBody(options) {
@@ -15677,10 +15625,13 @@ class World {
15677
15625
  options.type = BodyType.dynamic;
15678
15626
  options.world = this;
15679
15627
  const body2 = this.dynamicBodies.create(options);
15628
+ const originalShape = options.shape;
15629
+ options.shape = null;
15680
15630
  const bodyCopy = this.dynamicBodyCopies.create(options);
15681
15631
  bodyCopy.copy(body2);
15682
15632
  body2.copyForDiff = bodyCopy;
15683
- this.broadphase.addDynamicBody(body2);
15633
+ bodyCopy.setShape(body2.shape, false);
15634
+ options.shape = originalShape;
15684
15635
  return body2;
15685
15636
  }
15686
15637
  createKinematicBody(options) {
@@ -15688,10 +15639,13 @@ class World {
15688
15639
  options.type = BodyType.kinematic;
15689
15640
  options.world = this;
15690
15641
  const body2 = this.kinematicBodies.create(options);
15642
+ const originalShape = options.shape;
15643
+ options.shape = null;
15691
15644
  const bodyCopy = this.kinematicBodyCopies.create(options);
15692
15645
  bodyCopy.copy(body2);
15693
15646
  body2.copyForDiff = bodyCopy;
15694
- this.broadphase.addKinematicBody(body2);
15647
+ bodyCopy.setShape(body2.shape, false);
15648
+ options.shape = originalShape;
15695
15649
  return body2;
15696
15650
  }
15697
15651
  createBody(options) {
@@ -15775,6 +15729,10 @@ class World {
15775
15729
  }
15776
15730
  // scene query API
15777
15731
  intersectShape(onHit2, shape, transform2, settings) {
15732
+ if (!(transform2 instanceof BasicTransform)) {
15733
+ tempBasicTransform.reset(transform2);
15734
+ transform2 = tempBasicTransform;
15735
+ }
15778
15736
  isometry.fromRotationAndTranslation(transform2.rotation, transform2.position);
15779
15737
  intersectShapeCollector.initialize(onHit2);
15780
15738
  this.collideBodiesModule.collideShape(
@@ -15784,7 +15742,7 @@ class World {
15784
15742
  intersectShapeCollector,
15785
15743
  collideShapeSettings,
15786
15744
  zeroVector,
15787
- AllFlag
15745
+ settings?.collisionMask ?? AllFlag
15788
15746
  );
15789
15747
  }
15790
15748
  castRay(onHit2, ray2, settings) {
@@ -15793,12 +15751,8 @@ class World {
15793
15751
  }
15794
15752
  castShape(onHit2, shape, transform2, displacementOrEndPosition, settings) {
15795
15753
  isometry.fromRotationAndTranslation(transform2.rotation, transform2.position);
15796
- settings = settings || {
15797
- precision: QueryPrecision.preciseWithContacts,
15798
- returnClosestOnly: false,
15799
- treatAsDisplacement: false
15800
- };
15801
- if (settings.treatAsDisplacement) {
15754
+ settings = settings || {};
15755
+ if (settings?.treatAsDisplacement ?? false) {
15802
15756
  displacement.copy(displacementOrEndPosition);
15803
15757
  } else {
15804
15758
  displacement.zero();
@@ -16063,7 +16017,21 @@ class IntersectShapeCollector extends CollisionCollector {
16063
16017
  }
16064
16018
  const intersectShapeCollector = /* @__PURE__ */ new IntersectShapeCollector();
16065
16019
  const displacement = /* @__PURE__ */ Vec3.create();
16066
- const castSettings = /* @__PURE__ */ createDefaultCastSettings();
16020
+ const castSettings = {
16021
+ maxSeparation: 0,
16022
+ collisionTolerance: 1e-4,
16023
+ activeEdgeMode: ActiveEdgeMode.CollideOnlyWithActive,
16024
+ collectFacesMode: CollectFacesMode.NoFaces,
16025
+ penetrationTolerance: 1e-4,
16026
+ activeEdgeMovementDirectionX: 0,
16027
+ activeEdgeMovementDirectionY: 0,
16028
+ activeEdgeMovementDirectionZ: 0,
16029
+ backFaceMode: BackFaceMode.IgnoreBackFaces,
16030
+ backFaceModeConvex: BackFaceMode.IgnoreBackFaces,
16031
+ backFaceModeTriangles: BackFaceMode.IgnoreBackFaces,
16032
+ useShrunkenShapeAndConvexRadius: false,
16033
+ returnDeepestPoint: false
16034
+ };
16067
16035
  class CastShapeCollector extends CastCollector {
16068
16036
  constructor() {
16069
16037
  super(...arguments);
@@ -16077,6 +16045,7 @@ class CastShapeCollector extends CastCollector {
16077
16045
  }
16078
16046
  }
16079
16047
  const castShapeCollector = /* @__PURE__ */ new CastShapeCollector();
16048
+ const tempBasicTransform = /* @__PURE__ */ BasicTransform.create();
16080
16049
  export {
16081
16050
  Aabb,
16082
16051
  ActiveEdgeMode,