@perplexdotgg/bounce 1.3.0 → 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
@@ -943,12 +943,16 @@ const quatProps = {
943
943
  class Quat extends createClass(quatProps) {
944
944
  constructor(data, index, pool) {
945
945
  if (Array.isArray(data)) {
946
- data = {
947
- x: data[0] ?? 0,
948
- y: data[1] ?? 0,
949
- z: data[2] ?? 0,
950
- w: data[3] ?? 1
951
- };
946
+ if (data.length && data.length < 4) {
947
+ tempQuat.setFromEulerRadians(data[0], data[1] ?? 0, data[2] ?? 0);
948
+ } else {
949
+ tempQuat.x = data[0] ?? 0;
950
+ tempQuat.y = data[1] ?? 0;
951
+ tempQuat.z = data[2] ?? 0;
952
+ tempQuat.w = data[3] ?? 1;
953
+ }
954
+ super(tempQuat, index, pool);
955
+ return;
952
956
  }
953
957
  super(data, index, pool);
954
958
  }
@@ -1151,6 +1155,7 @@ class Quat extends createClass(quatProps) {
1151
1155
  }
1152
1156
  const vector = /* @__PURE__ */ Vec3.create();
1153
1157
  const tempMat3 = /* @__PURE__ */ Mat3.create();
1158
+ const tempQuat = /* @__PURE__ */ Quat.create();
1154
1159
  const rotationMatrix$2 = /* @__PURE__ */ Mat3.create();
1155
1160
  const scaling = /* @__PURE__ */ Vec3.create();
1156
1161
  const conjugatedRotation = /* @__PURE__ */ Quat.create();
@@ -1954,6 +1959,7 @@ class Aabb extends createClass(aabbProps) {
1954
1959
  this.min.minVectors(boxA.min, boxB.min);
1955
1960
  this.max.maxVectors(boxA.max, boxB.max);
1956
1961
  this.computeCentroid(this.centroid);
1962
+ return this;
1957
1963
  }
1958
1964
  expand(value) {
1959
1965
  this.min.x -= value;
@@ -4022,7 +4028,6 @@ const CollisionFilter = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.def
4022
4028
  shouldPairCollide,
4023
4029
  toggleFlag
4024
4030
  }, Symbol.toStringTag, { value: "Module" }));
4025
- const expandedObjectBounds = /* @__PURE__ */ Aabb.create();
4026
4031
  const leftAabb = /* @__PURE__ */ Aabb.create();
4027
4032
  const rightAabb = /* @__PURE__ */ Aabb.create();
4028
4033
  const centroidBounds$1 = /* @__PURE__ */ Aabb.create();
@@ -4081,7 +4086,7 @@ class BvhTree {
4081
4086
  }
4082
4087
  updateDirtyObjects() {
4083
4088
  for (const object of this.dirtyObjects) {
4084
- if (this.update(object, false)) ;
4089
+ this.update(object, false);
4085
4090
  }
4086
4091
  this.dirtyObjects.clear();
4087
4092
  }
@@ -4170,7 +4175,7 @@ class BvhTree {
4170
4175
  node.computedBounds.min.fromArray([Infinity, Infinity, Infinity]);
4171
4176
  node.computedBounds.max.fromArray([-Infinity, -Infinity, -Infinity]);
4172
4177
  for (const object of node.objects) {
4173
- node.computedBounds.unionAabb(object.computedBounds);
4178
+ node.computedBounds.unionAabb(object.computedExpandedBounds);
4174
4179
  }
4175
4180
  node.height = 0;
4176
4181
  } else {
@@ -4260,11 +4265,11 @@ class BvhTree {
4260
4265
  destroyBvhNode(node) {
4261
4266
  node.destroy();
4262
4267
  }
4263
- insert(object, shouldUpdateDirtyObjects = true) {
4264
- expandedObjectBounds.expandAabb(object.computedBounds, this.options.expansionMargin);
4268
+ insert(object) {
4269
+ object.computedExpandedBounds.expandAabb(object.computedBounds, this.options.expansionMargin);
4265
4270
  if (!this.root) {
4266
4271
  const root = this.createBvhNode();
4267
- root.computedBounds.copy(expandedObjectBounds);
4272
+ root.computedBounds.copy(object.computedExpandedBounds);
4268
4273
  root.objects.push(object);
4269
4274
  root.height = 0;
4270
4275
  this.root = root;
@@ -4283,7 +4288,7 @@ class BvhTree {
4283
4288
  }
4284
4289
  if (best.objects.length < this.options.maxObjectsPerLeaf || best.height >= this.options.maxDepth) {
4285
4290
  best.objects.push(object);
4286
- best.computedBounds.unionAabb(expandedObjectBounds);
4291
+ best.computedBounds.unionAabb(object.computedExpandedBounds);
4287
4292
  object.node = best;
4288
4293
  return this.refit(best);
4289
4294
  }
@@ -4292,15 +4297,15 @@ class BvhTree {
4292
4297
  best.objects.push(object);
4293
4298
  this.splitObjects(left, right, best);
4294
4299
  best.objects.length = 0;
4295
- left.computedBounds.copy(left.objects.getAtIndex(0).computedBounds);
4300
+ left.computedBounds.copy(left.objects.getAtIndex(0).computedExpandedBounds);
4296
4301
  for (let i = 1; i < left.objects.length; i++) {
4297
- left.computedBounds.unionAabb(left.objects.getAtIndex(i).computedBounds);
4302
+ left.computedBounds.unionAabb(left.objects.getAtIndex(i).computedExpandedBounds);
4298
4303
  }
4299
4304
  left.parent = best;
4300
4305
  left.height = 0;
4301
- right.computedBounds.copy(right.objects.getAtIndex(0).computedBounds);
4306
+ right.computedBounds.copy(right.objects.getAtIndex(0).computedExpandedBounds);
4302
4307
  for (let i = 1; i < right.objects.length; i++) {
4303
- right.computedBounds.unionAabb(right.objects.getAtIndex(i).computedBounds);
4308
+ right.computedBounds.unionAabb(right.objects.getAtIndex(i).computedExpandedBounds);
4304
4309
  }
4305
4310
  right.parent = best;
4306
4311
  right.height = 0;
@@ -4360,7 +4365,7 @@ class BvhTree {
4360
4365
  this.remove(object);
4361
4366
  return this.insert(object);
4362
4367
  }
4363
- intersectBody(onHit2, body2, shouldUpdateDirtyObjects = true) {
4368
+ intersectBody(onHit2, bodyToIntersect, shouldUpdateDirtyObjects = true) {
4364
4369
  if (!this.root) {
4365
4370
  return;
4366
4371
  }
@@ -4375,7 +4380,7 @@ class BvhTree {
4375
4380
  if (!node) {
4376
4381
  continue;
4377
4382
  }
4378
- if (!node.computedBounds.intersectsAabb(body2.computedBounds)) {
4383
+ if (!node.computedBounds.intersectsAabb(bodyToIntersect.computedBounds)) {
4379
4384
  continue;
4380
4385
  }
4381
4386
  if (!node.isLeaf()) {
@@ -4384,21 +4389,40 @@ class BvhTree {
4384
4389
  continue;
4385
4390
  }
4386
4391
  for (const otherBody of node.objects) {
4387
- if (body2 === otherBody) {
4392
+ if (bodyToIntersect === otherBody || !shouldPairCollide(bodyToIntersect.belongsToGroups, bodyToIntersect.collidesWithGroups, otherBody.belongsToGroups, otherBody.collidesWithGroups) || !bodyToIntersect.computedBounds.intersectsAabb(otherBody.computedBounds)) {
4388
4393
  continue;
4389
4394
  }
4390
- if (shouldPairCollide(
4391
- body2.belongsToGroups,
4392
- body2.collidesWithGroups,
4393
- otherBody.belongsToGroups,
4394
- otherBody.collidesWithGroups
4395
- ) === false) {
4396
- continue;
4395
+ if (onHit2(otherBody)) {
4396
+ return;
4397
4397
  }
4398
- 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)) {
4399
4423
  continue;
4400
4424
  }
4401
- if (onHit2(otherBody)) {
4425
+ if (onHit2(object)) {
4402
4426
  return;
4403
4427
  }
4404
4428
  }
@@ -4440,10 +4464,7 @@ class BvhTree {
4440
4464
  stack2.push(this.root);
4441
4465
  while (stack2.length > 0) {
4442
4466
  const node = stack2.pop();
4443
- if (!node) {
4444
- continue;
4445
- }
4446
- if (node.computedBounds.intersectsAabb(bounds) === false) {
4467
+ if (!node || !node.computedBounds.intersectsAabb(bounds)) {
4447
4468
  continue;
4448
4469
  }
4449
4470
  if (!node.isLeaf()) {
@@ -4452,10 +4473,7 @@ class BvhTree {
4452
4473
  continue;
4453
4474
  }
4454
4475
  for (const body2 of node.objects) {
4455
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4456
- continue;
4457
- }
4458
- if (!body2.computedBounds.intersectsAabb(bounds)) {
4476
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) || !body2.computedBounds.intersectsAabb(bounds)) {
4459
4477
  continue;
4460
4478
  }
4461
4479
  bodyVisitor.visit(body2);
@@ -4481,7 +4499,7 @@ class BvhTree {
4481
4499
  continue;
4482
4500
  }
4483
4501
  nodeBounds$1.copy(node.computedBounds);
4484
- if (ray2.intersectsAabb(nodeBounds$1) === false) {
4502
+ if (!ray2.intersectsAabb(nodeBounds$1)) {
4485
4503
  continue;
4486
4504
  }
4487
4505
  if (!node.isLeaf()) {
@@ -4490,11 +4508,11 @@ class BvhTree {
4490
4508
  continue;
4491
4509
  }
4492
4510
  for (const body2 of node.objects) {
4493
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4511
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups)) {
4494
4512
  continue;
4495
4513
  }
4496
4514
  bodyBounds$1.copy(body2.computedBounds);
4497
- if (ray2.intersectsAabb(bodyBounds$1) === false) {
4515
+ if (!ray2.intersectsAabb(bodyBounds$1)) {
4498
4516
  continue;
4499
4517
  }
4500
4518
  bodyVisitor.visit(body2);
@@ -4525,7 +4543,7 @@ class BvhTree {
4525
4543
  }
4526
4544
  nodeBounds$1.copy(node.computedBounds);
4527
4545
  nodeBounds$1.expandByVector(halfExtents$2);
4528
- if (ray$4.intersectsAabb(nodeBounds$1) === false) {
4546
+ if (!ray$4.intersectsAabb(nodeBounds$1)) {
4529
4547
  continue;
4530
4548
  }
4531
4549
  if (!node.isLeaf()) {
@@ -4534,12 +4552,12 @@ class BvhTree {
4534
4552
  continue;
4535
4553
  }
4536
4554
  for (const body2 of node.objects) {
4537
- if (shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups) === false) {
4555
+ if (!shouldPairCollide(body2.belongsToGroups, body2.collidesWithGroups, belongsToGroups, collidesWithGroups)) {
4538
4556
  continue;
4539
4557
  }
4540
4558
  bodyBounds$1.copy(body2.computedBounds);
4541
4559
  bodyBounds$1.expandByVector(halfExtents$2);
4542
- if (ray$4.intersectsAabb(bodyBounds$1) === false) {
4560
+ if (!ray$4.intersectsAabb(bodyBounds$1)) {
4543
4561
  continue;
4544
4562
  }
4545
4563
  bodyVisitor.visit(body2);
@@ -7986,6 +8004,7 @@ const bodyProps = {
7986
8004
  angularVelocity: Vec3,
7987
8005
  computedCenterOfMassPosition: ChildType(Vec3, void 0, true),
7988
8006
  computedBounds: ChildType(Aabb, void 0, true),
8007
+ computedExpandedBounds: ChildType(Aabb, void 0, true),
7989
8008
  previousPosition: ChildType(Vec3, void 0, true),
7990
8009
  previousOrientation: ChildType(Quat, void 0, true),
7991
8010
  isSleeping: BooleanType(false, true),
@@ -8037,6 +8056,9 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
8037
8056
  return this["shape" + this.shapeType];
8038
8057
  }
8039
8058
  set shape(newShape) {
8059
+ this.setShape(newShape);
8060
+ }
8061
+ setShape(newShape, updateBroadphase = true) {
8040
8062
  this["shape" + this.shapeType] = null;
8041
8063
  this["shape" + newShape.type] = newShape;
8042
8064
  this.shapeType = newShape.type;
@@ -8058,7 +8080,9 @@ class Body extends createClass(bodyProps, { afterConstructorCode }) {
8058
8080
  newShape.computedVolume = hull.computedVolume;
8059
8081
  newShape.inertia.copy(hull.inertia);
8060
8082
  }
8061
- updateBody(this);
8083
+ if (updateBroadphase) {
8084
+ updateBody(this);
8085
+ }
8062
8086
  }
8063
8087
  // physics integration functions
8064
8088
  /**
@@ -8374,113 +8398,14 @@ function updateMassProperties(body2) {
8374
8398
  body2.shape.computeInverseInertiaTensor(body2.computedLocalInverseInertia, body2.mass);
8375
8399
  transformTensor(body2.computedWorldInverseInertia, body2.computedLocalInverseInertia, body2.orientation);
8376
8400
  }
8377
- function updateBody(body2) {
8401
+ function updateBody(body2, updateBroadphase = true) {
8378
8402
  updateMassProperties(body2);
8379
8403
  updateCenterOfMassPosition(body2);
8380
8404
  updateWorldBounds(body2);
8381
- }
8382
- var CollisionStatus = /* @__PURE__ */ ((CollisionStatus2) => {
8383
- CollisionStatus2[CollisionStatus2["NotColliding"] = 0] = "NotColliding";
8384
- CollisionStatus2[CollisionStatus2["Colliding"] = 1] = "Colliding";
8385
- CollisionStatus2[CollisionStatus2["Indeterminate"] = 2] = "Indeterminate";
8386
- return CollisionStatus2;
8387
- })(CollisionStatus || {});
8388
- const collisionResultProps = {
8389
- status: NumberType(
8390
- 2
8391
- /* Indeterminate */
8392
- ),
8393
- hasContact: BooleanType(false),
8394
- penetration: 0,
8395
- contactPointA: Vec3,
8396
- contactPointB: Vec3,
8397
- normalA: Vec3,
8398
- normalB: Vec3,
8399
- momentArmA: Vec3,
8400
- momentArmB: Vec3,
8401
- surfaceNormalA: Vec3,
8402
- surfaceNormalB: Vec3,
8403
- bodyA: LazyReferenceType((() => Body)),
8404
- bodyB: LazyReferenceType((() => Body)),
8405
- subShapeIdA: 0,
8406
- subShapeIdB: 0,
8407
- isBackFace: BooleanType(false),
8408
- faceA: Face,
8409
- faceB: Face
8410
- };
8411
- class CollisionResult extends createClass(collisionResultProps) {
8412
- /**
8413
- * swaps the A and B data
8414
- */
8415
- swap() {
8416
- this.contactPointA.swap(this.contactPointB);
8417
- this.normalA.swap(this.normalB);
8418
- this.momentArmA.swap(this.momentArmB);
8419
- this.surfaceNormalA.swap(this.surfaceNormalB);
8420
- const tempBody = this.bodyA;
8421
- this.bodyA = this.bodyB;
8422
- this.bodyB = tempBody;
8423
- const tempSubShapeId = this.subShapeIdA;
8424
- this.subShapeIdA = this.subShapeIdB;
8425
- this.subShapeIdB = tempSubShapeId;
8426
- const tempFace = this.faceA;
8427
- this.faceA = this.faceB;
8428
- this.faceB = tempFace;
8405
+ if (updateBroadphase) {
8406
+ body2.markBodyAsDirty();
8429
8407
  }
8430
8408
  }
8431
- const _CollisionCollector = class _CollisionCollector {
8432
- constructor() {
8433
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8434
- this.body2 = null;
8435
- }
8436
- getEarlyOutFraction() {
8437
- return _CollisionCollector.initialEarlyOutFraction;
8438
- }
8439
- getPositiveEarlyOutFraction() {
8440
- return Math.max(Number.MIN_VALUE, this.earlyOutFraction);
8441
- }
8442
- reset() {
8443
- this.earlyOutFraction = _CollisionCollector.initialEarlyOutFraction;
8444
- this.body2 = null;
8445
- return this;
8446
- }
8447
- addHit(result2) {
8448
- }
8449
- addMiss() {
8450
- }
8451
- };
8452
- _CollisionCollector.initialEarlyOutFraction = Infinity;
8453
- _CollisionCollector.shouldEarlyOutFraction = -Infinity;
8454
- let CollisionCollector = _CollisionCollector;
8455
- var CollectFacesMode = /* @__PURE__ */ ((CollectFacesMode2) => {
8456
- CollectFacesMode2[CollectFacesMode2["CollectFaces"] = 0] = "CollectFaces";
8457
- CollectFacesMode2[CollectFacesMode2["NoFaces"] = 1] = "NoFaces";
8458
- return CollectFacesMode2;
8459
- })(CollectFacesMode || {});
8460
- var ActiveEdgeMode = /* @__PURE__ */ ((ActiveEdgeMode2) => {
8461
- ActiveEdgeMode2[ActiveEdgeMode2["CollideOnlyWithActive"] = 0] = "CollideOnlyWithActive";
8462
- ActiveEdgeMode2[ActiveEdgeMode2["CollideWithAll"] = 1] = "CollideWithAll";
8463
- return ActiveEdgeMode2;
8464
- })(ActiveEdgeMode || {});
8465
- var BackFaceMode = /* @__PURE__ */ ((BackFaceMode2) => {
8466
- BackFaceMode2[BackFaceMode2["IgnoreBackFaces"] = 0] = "IgnoreBackFaces";
8467
- BackFaceMode2[BackFaceMode2["CollideWithBackFaces"] = 1] = "CollideWithBackFaces";
8468
- return BackFaceMode2;
8469
- })(BackFaceMode || {});
8470
- function createDefaultCollisionSettings() {
8471
- return {
8472
- maxSeparation: 0,
8473
- collisionTolerance: 1e-4,
8474
- activeEdgeMode: 0,
8475
- collectFacesMode: 1,
8476
- penetrationTolerance: 1e-4,
8477
- activeEdgeMovementDirectionX: 0,
8478
- activeEdgeMovementDirectionY: 0,
8479
- activeEdgeMovementDirectionZ: 0,
8480
- backFaceMode: 0
8481
- /* IgnoreBackFaces */
8482
- };
8483
- }
8484
8409
  const castResultProps = {
8485
8410
  status: NumberType(
8486
8411
  2
@@ -8562,15 +8487,6 @@ var QueryPrecision = /* @__PURE__ */ ((QueryPrecision2) => {
8562
8487
  QueryPrecision2[QueryPrecision2["preciseWithContacts"] = 2] = "preciseWithContacts";
8563
8488
  return QueryPrecision2;
8564
8489
  })(QueryPrecision || {});
8565
- function createDefaultCastSettings() {
8566
- return {
8567
- ...createDefaultCollisionSettings(),
8568
- backFaceModeConvex: BackFaceMode.IgnoreBackFaces,
8569
- backFaceModeTriangles: BackFaceMode.IgnoreBackFaces,
8570
- useShrunkenShapeAndConvexRadius: false,
8571
- returnDeepestPoint: false
8572
- };
8573
- }
8574
8490
  const ab$4 = /* @__PURE__ */ Vec3.create();
8575
8491
  function computeBarycentricCoordinates2d(outBarycentric, a3, b3, squaredTolerance = 1e-10) {
8576
8492
  ab$4.subtractVectors(b3, a3);
@@ -9432,6 +9348,94 @@ class GjkModule {
9432
9348
  }
9433
9349
  }
9434
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 || {});
9435
9439
  const edgeProps = {
9436
9440
  neighbourTriangle: LazyReferenceType((() => Triangle2)),
9437
9441
  neighbourEdge: 0,
@@ -11213,88 +11217,79 @@ function collideCompoundVsTriangleMesh(penetrationDepthModule2, collector2, shap
11213
11217
  function noOp() {
11214
11218
  return;
11215
11219
  }
11216
- const collideShapesFns = {
11217
- [ShapeType.sphere]: {
11218
- [ShapeType.box]: collideConvexVsConvex,
11219
- [ShapeType.capsule]: collideConvexVsConvex,
11220
- [ShapeType.convexHull]: collideConvexVsConvex,
11221
- [ShapeType.compoundShape]: collideConvexVsCompound,
11222
- [ShapeType.cylinder]: collideConvexVsConvex,
11223
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11224
- [ShapeType.sphere]: collideSphereVsSphere,
11225
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11226
- },
11227
- [ShapeType.box]: {
11228
- [ShapeType.box]: collideConvexVsConvex,
11229
- [ShapeType.capsule]: collideConvexVsConvex,
11230
- [ShapeType.compoundShape]: collideConvexVsCompound,
11231
- [ShapeType.convexHull]: collideConvexVsConvex,
11232
- [ShapeType.cylinder]: collideConvexVsConvex,
11233
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11234
- [ShapeType.sphere]: collideConvexVsConvex,
11235
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11236
- },
11237
- [ShapeType.convexHull]: {
11238
- [ShapeType.box]: collideConvexVsConvex,
11239
- [ShapeType.capsule]: collideConvexVsConvex,
11240
- [ShapeType.compoundShape]: collideConvexVsCompound,
11241
- [ShapeType.convexHull]: collideConvexVsConvex,
11242
- [ShapeType.cylinder]: collideConvexVsConvex,
11243
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11244
- [ShapeType.sphere]: collideConvexVsConvex,
11245
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11246
- },
11247
- [ShapeType.compoundShape]: {
11248
- [ShapeType.box]: collideCompoundVsConvex,
11249
- [ShapeType.capsule]: collideCompoundVsConvex,
11250
- [ShapeType.compoundShape]: collideCompoundVsCompound,
11251
- [ShapeType.convexHull]: collideCompoundVsConvex,
11252
- [ShapeType.cylinder]: collideCompoundVsConvex,
11253
- [ShapeType.heightMap]: collideCompoundVsHeightMap,
11254
- [ShapeType.sphere]: collideCompoundVsConvex,
11255
- [ShapeType.triangleMesh]: collideCompoundVsTriangleMesh
11256
- },
11257
- [ShapeType.cylinder]: {
11258
- [ShapeType.box]: collideConvexVsConvex,
11259
- [ShapeType.capsule]: collideConvexVsConvex,
11260
- [ShapeType.compoundShape]: collideConvexVsCompound,
11261
- [ShapeType.convexHull]: collideConvexVsConvex,
11262
- [ShapeType.cylinder]: collideConvexVsConvex,
11263
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11264
- [ShapeType.sphere]: collideConvexVsConvex,
11265
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11266
- },
11267
- [ShapeType.capsule]: {
11268
- [ShapeType.box]: collideConvexVsConvex,
11269
- [ShapeType.capsule]: collideConvexVsConvex,
11270
- [ShapeType.compoundShape]: collideConvexVsCompound,
11271
- [ShapeType.convexHull]: collideConvexVsConvex,
11272
- [ShapeType.cylinder]: collideConvexVsConvex,
11273
- [ShapeType.heightMap]: collideConvexVsHeightMap,
11274
- [ShapeType.sphere]: collideConvexVsConvex,
11275
- [ShapeType.triangleMesh]: collideConvexVsTriangleMesh
11276
- },
11277
- [ShapeType.heightMap]: {
11278
- [ShapeType.box]: collideHeightMapVsConvex,
11279
- [ShapeType.capsule]: collideHeightMapVsConvex,
11280
- [ShapeType.compoundShape]: collideHeightMapVsCompound,
11281
- [ShapeType.convexHull]: collideHeightMapVsConvex,
11282
- [ShapeType.cylinder]: collideHeightMapVsConvex,
11283
- [ShapeType.heightMap]: noOp,
11284
- [ShapeType.sphere]: collideHeightMapVsConvex,
11285
- [ShapeType.triangleMesh]: noOp
11286
- },
11287
- [ShapeType.triangleMesh]: {
11288
- [ShapeType.box]: collideTriangleMeshVsConvex,
11289
- [ShapeType.capsule]: collideTriangleMeshVsConvex,
11290
- [ShapeType.compoundShape]: collideTriangleMeshVsCompound,
11291
- [ShapeType.convexHull]: collideTriangleMeshVsConvex,
11292
- [ShapeType.cylinder]: collideTriangleMeshVsConvex,
11293
- [ShapeType.heightMap]: noOp,
11294
- [ShapeType.sphere]: collideTriangleMeshVsConvex,
11295
- [ShapeType.triangleMesh]: noOp
11296
- }
11297
- };
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;
11298
11293
  class CollideShapesModule {
11299
11294
  constructor(penetrationDepthModule2) {
11300
11295
  this.penetrationDepthModule = penetrationDepthModule2;
@@ -11304,11 +11299,9 @@ class CollideShapesModule {
11304
11299
  // the isometries must transform the shapes into world space
11305
11300
  // the results are in world space
11306
11301
  collideShapes(collector2, shapeA, isometryA2, shapeB2, isometryB2, settings, bodyA, bodyB, subShapeIdA = 0, subShapeIdB = 0) {
11307
- const keyA = shapeA.type;
11308
- const keyB = shapeB2.type;
11309
- const collisionFunction = collideShapesFns[keyA][keyB];
11302
+ const collisionFunction = collideShapesFns[shapeA.type][shapeB2.type];
11310
11303
  if (!collisionFunction) {
11311
- 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}`);
11312
11305
  }
11313
11306
  return collisionFunction(
11314
11307
  this.penetrationDepthModule,
@@ -11623,7 +11616,7 @@ class CollideBodiesModule {
11623
11616
  }
11624
11617
  isometryA.matrix.postTranslatedMatrix(inCenterOfMassTransform.matrix, offset);
11625
11618
  boundsA$1.copy(inShape.computedAabb);
11626
- boundsA$1.expand(inCollideShapeSettings ? inCollideShapeSettings.maxSeparation : 0);
11619
+ boundsA$1.expand(inCollideShapeSettings?.maxSeparation ?? 0);
11627
11620
  boundsA$1.transform(inCenterOfMassTransform);
11628
11621
  collideShapeVisitor.initialize(
11629
11622
  isometryA,
@@ -11730,7 +11723,7 @@ class CastRayBodyVisitor {
11730
11723
  }
11731
11724
  visit(body2) {
11732
11725
  isometryB.fromRotationAndTranslation(body2.orientation, body2.computedCenterOfMassPosition);
11733
- 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);
11734
11727
  }
11735
11728
  }
11736
11729
  const castRayVisitor = /* @__PURE__ */ new CastRayBodyVisitor();
@@ -12610,19 +12603,9 @@ class BvhModule {
12610
12603
  for (const node of this.pairs.iteratePairs()) {
12611
12604
  const bodyA = node.bodyA;
12612
12605
  const bodyB = node.bodyB;
12613
- 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) {
12614
12607
  continue;
12615
12608
  }
12616
- if (bodyA.type === BodyType.static && bodyB.type === BodyType.dynamic) {
12617
- if (bodyB.isSleeping) {
12618
- continue;
12619
- }
12620
- }
12621
- if (bodyA.type === BodyType.dynamic && bodyB.type === BodyType.static) {
12622
- if (bodyA.isSleeping) {
12623
- continue;
12624
- }
12625
- }
12626
12609
  yield node;
12627
12610
  }
12628
12611
  }
@@ -13064,7 +13047,7 @@ function castConvexVsTriangleMesh(penetrationDepthModule2, ioCollector, inShapeA
13064
13047
  isometryWorldToB$2.matrix.multiply3x3(transformedDisplacement, displacement2);
13065
13048
  inShapeB.bvh.castAabb(onHit$2, boundsA, transformedDisplacement);
13066
13049
  }
13067
- function castRayVsConvex(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13050
+ function castRayVsConvex(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13068
13051
  const convexB2 = inShapeB.computeSupportShape(SupportMode.IncludeConvexRadius, 1);
13069
13052
  raycast.fraction = ioCollector.getEarlyOutFraction();
13070
13053
  worldToB.matrix.invertMatrix(isometryB2.matrix);
@@ -13090,7 +13073,7 @@ const result$2 = /* @__PURE__ */ CastResult.create();
13090
13073
  const raycast = { fraction: 0 };
13091
13074
  const transformedRay$2 = /* @__PURE__ */ Ray.create();
13092
13075
  const worldToB = /* @__PURE__ */ Isometry.create();
13093
- function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13076
+ function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13094
13077
  for (const shapeObj of inShapeB.shapes) {
13095
13078
  const shape = shapeObj.shape;
13096
13079
  const transform2 = shapeObj.transform;
@@ -13104,7 +13087,6 @@ function castRayVsCompound(penetrationDepthModule2, ioCollector, inRay, inShapeB
13104
13087
  transformSubShapeBToWorld,
13105
13088
  inScaleB,
13106
13089
  offset2,
13107
- inSettings,
13108
13090
  bodyB
13109
13091
  );
13110
13092
  }
@@ -13131,7 +13113,7 @@ function onHit$1(triangle2) {
13131
13113
  collector$1.addHit(result$1);
13132
13114
  return false;
13133
13115
  }
13134
- function castRayVsTriangleMesh(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13116
+ function castRayVsTriangleMesh(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13135
13117
  ioCollector.reset();
13136
13118
  isometryWorldToB$1.matrix.invertMatrix(isometryB2.matrix);
13137
13119
  transformedRay$1.copy(inRay).transform(isometryWorldToB$1);
@@ -13164,7 +13146,7 @@ function onHit(triangle2) {
13164
13146
  collector.addHit(result);
13165
13147
  return false;
13166
13148
  }
13167
- function castRayVsHeightMap(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, inSettings, bodyB = null) {
13149
+ function castRayVsHeightMap(penetrationDepthModule2, ioCollector, inRay, inShapeB, isometryB2, inScaleB, offset2, bodyB = null) {
13168
13150
  ioCollector.reset();
13169
13151
  isometryWorldToB.matrix.invertMatrix(isometryB2.matrix);
13170
13152
  transformedRay.copy(inRay).transform(isometryWorldToB);
@@ -13177,100 +13159,76 @@ const result = /* @__PURE__ */ CastResult.create();
13177
13159
  const raycasterResult = { fraction: 1, hit: false };
13178
13160
  const isometryWorldToB = /* @__PURE__ */ Isometry.create();
13179
13161
  const transformedRay = /* @__PURE__ */ Ray.create();
13180
- const castShapesFns = {
13181
- [ShapeType.sphere]: {
13182
- [ShapeType.box]: castConvexVsConvex,
13183
- [ShapeType.capsule]: castConvexVsConvex,
13184
- [ShapeType.compoundShape]: castConvexVsCompound,
13185
- [ShapeType.convexHull]: castConvexVsConvex,
13186
- [ShapeType.cylinder]: castConvexVsConvex,
13187
- [ShapeType.heightMap]: castConvexVsHeightMap,
13188
- [ShapeType.sphere]: castConvexVsConvex,
13189
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13190
- },
13191
- [ShapeType.box]: {
13192
- [ShapeType.box]: castConvexVsConvex,
13193
- [ShapeType.capsule]: castConvexVsConvex,
13194
- [ShapeType.compoundShape]: castConvexVsCompound,
13195
- [ShapeType.convexHull]: castConvexVsConvex,
13196
- [ShapeType.cylinder]: castConvexVsConvex,
13197
- [ShapeType.heightMap]: castConvexVsHeightMap,
13198
- [ShapeType.sphere]: castConvexVsConvex,
13199
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13200
- },
13201
- [ShapeType.capsule]: {
13202
- [ShapeType.box]: castConvexVsConvex,
13203
- [ShapeType.capsule]: castConvexVsConvex,
13204
- [ShapeType.compoundShape]: castConvexVsCompound,
13205
- [ShapeType.convexHull]: castConvexVsConvex,
13206
- [ShapeType.cylinder]: castConvexVsConvex,
13207
- [ShapeType.heightMap]: castConvexVsHeightMap,
13208
- [ShapeType.sphere]: castConvexVsConvex,
13209
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13210
- },
13211
- [ShapeType.cylinder]: {
13212
- [ShapeType.box]: castConvexVsConvex,
13213
- [ShapeType.capsule]: castConvexVsConvex,
13214
- [ShapeType.compoundShape]: castConvexVsCompound,
13215
- [ShapeType.convexHull]: castConvexVsConvex,
13216
- [ShapeType.cylinder]: castConvexVsConvex,
13217
- [ShapeType.heightMap]: castConvexVsHeightMap,
13218
- [ShapeType.sphere]: castConvexVsConvex,
13219
- [ShapeType.triangleMesh]: castConvexVsTriangleMesh
13220
- },
13221
- [ShapeType.compoundShape]: {
13222
- [ShapeType.box]: castCompoundVsConvex,
13223
- [ShapeType.capsule]: castCompoundVsConvex,
13224
- // [ShapeType.compoundShape]: castCompoundVsCompound,
13225
- [ShapeType.convexHull]: castCompoundVsConvex,
13226
- [ShapeType.cylinder]: castCompoundVsConvex,
13227
- // [ShapeType.heightMap]: castCompoundVsHeightMap,
13228
- [ShapeType.sphere]: castCompoundVsConvex
13229
- // [ShapeType.triangleMesh]: castCompoundVsTriangleMesh,
13230
- }
13231
- // [ShapeType.heightMap]: {
13232
- // [ShapeType.box]: castHeightMapVsConvex,
13233
- // [ShapeType.capsule]: castHeightMapVsConvex,
13234
- // [ShapeType.compoundShape]: castHeightMapVsCompound,
13235
- // [ShapeType.convexHull]: castHeightMapVsConvex,
13236
- // [ShapeType.cylinder]: castHeightMapVsConvex,
13237
- // [ShapeType.heightMap]: castHeightMapVsHeightMap,
13238
- // [ShapeType.sphere]: castHeightMapVsConvex,
13239
- // [ShapeType.triangleMesh]: castHeightMapVsTriangleMesh,
13240
- // },
13241
- // [ShapeType.triangleMesh]: {
13242
- // [ShapeType.box]: castTriangleMeshVsConvex,
13243
- // [ShapeType.capsule]: castTriangleMeshVsConvex,
13244
- // [ShapeType.compoundShape]: castTriangleMeshVsCompound,
13245
- // [ShapeType.convexHull]: castTriangleMeshVsConvex,
13246
- // [ShapeType.cylinder]: castTriangleMeshVsConvex,
13247
- // [ShapeType.heightMap]: castTriangleMeshVsHeightMap,
13248
- // [ShapeType.sphere]: castTriangleMeshVsConvex,
13249
- // [ShapeType.triangleMesh]: castTriangleMeshVsTriangleMesh,
13250
- // },
13251
- // [ShapeType.triangle]: {
13252
- // [ShapeType.box]: castTriangleVsConvex,
13253
- // [ShapeType.sphere]: castTriangleVsConvex,
13254
- // },
13255
- };
13256
- const raycastFns = {
13257
- [ShapeType.sphere]: castRayVsConvex,
13258
- [ShapeType.box]: castRayVsConvex,
13259
- [ShapeType.capsule]: castRayVsConvex,
13260
- [ShapeType.cylinder]: castRayVsConvex,
13261
- [ShapeType.compoundShape]: castRayVsCompound,
13262
- // castRayVsCompound,
13263
- [ShapeType.convexHull]: castRayVsConvex,
13264
- [ShapeType.heightMap]: castRayVsHeightMap,
13265
- // castRayVsHeightMap,
13266
- [ShapeType.triangleMesh]: castRayVsTriangleMesh
13267
- // castRayVsTriangleMesh,
13268
- };
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;
13269
13227
  class CastShapesModule {
13270
13228
  constructor(penetrationDepthModule2) {
13271
13229
  this.penetrationDepthModule = penetrationDepthModule2;
13272
13230
  }
13273
- castRay(collector2, ray2, shapeB2, isometryB2, scaleB, offset2, settings, bodyB = null) {
13231
+ castRay(collector2, ray2, shapeB2, isometryB2, scaleB, offset2, bodyB = null) {
13274
13232
  const fn = raycastFns[shapeB2.type];
13275
13233
  if (!fn) {
13276
13234
  return;
@@ -13284,7 +13242,6 @@ class CastShapesModule {
13284
13242
  isometryB2,
13285
13243
  scaleB,
13286
13244
  offset2,
13287
- settings,
13288
13245
  bodyB
13289
13246
  );
13290
13247
  }
@@ -13293,11 +13250,9 @@ class CastShapesModule {
13293
13250
  // the isometries must transform the shapes into world space
13294
13251
  // the results are in world space
13295
13252
  castShapes(collector2, shapeA, isometryA2, scaleA, shapeB2, isometryB2, scaleB, displacement2, offset2, settings, bodyA = null, bodyB = null) {
13296
- const keyA = shapeA.type;
13297
- const keyB = shapeB2.type;
13298
- const castFunction = castShapesFns[keyA][keyB];
13253
+ const castFunction = castShapesFns[shapeA.type][shapeB2.type];
13299
13254
  if (!castFunction) {
13300
- 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}`);
13301
13256
  }
13302
13257
  return castFunction(
13303
13258
  this.penetrationDepthModule,
@@ -15453,11 +15408,6 @@ class World {
15453
15408
  updateWorldBounds(body2);
15454
15409
  }
15455
15410
  }
15456
- // updateBodyProperties() {
15457
- // for (const body of this.bodies()) {
15458
- // // updateBody(body);
15459
- // }
15460
- // }
15461
15411
  clearForcesOnBodies() {
15462
15412
  for (const body2 of this.dynamicBodies) {
15463
15413
  body2.clearForces();
@@ -15661,11 +15611,13 @@ class World {
15661
15611
  options.type = BodyType.static;
15662
15612
  options.world = this;
15663
15613
  const body2 = this.staticBodies.create(options);
15614
+ const originalShape = options.shape;
15615
+ options.shape = null;
15664
15616
  const bodyCopy = this.staticBodyCopies.create(options);
15665
15617
  bodyCopy.copy(body2);
15666
15618
  body2.copyForDiff = bodyCopy;
15667
- body2.world = this;
15668
- this.broadphase.addStaticBody(body2);
15619
+ bodyCopy.setShape(body2.shape, false);
15620
+ options.shape = originalShape;
15669
15621
  return body2;
15670
15622
  }
15671
15623
  createDynamicBody(options) {
@@ -15673,10 +15625,13 @@ class World {
15673
15625
  options.type = BodyType.dynamic;
15674
15626
  options.world = this;
15675
15627
  const body2 = this.dynamicBodies.create(options);
15628
+ const originalShape = options.shape;
15629
+ options.shape = null;
15676
15630
  const bodyCopy = this.dynamicBodyCopies.create(options);
15677
15631
  bodyCopy.copy(body2);
15678
15632
  body2.copyForDiff = bodyCopy;
15679
- this.broadphase.addDynamicBody(body2);
15633
+ bodyCopy.setShape(body2.shape, false);
15634
+ options.shape = originalShape;
15680
15635
  return body2;
15681
15636
  }
15682
15637
  createKinematicBody(options) {
@@ -15684,10 +15639,13 @@ class World {
15684
15639
  options.type = BodyType.kinematic;
15685
15640
  options.world = this;
15686
15641
  const body2 = this.kinematicBodies.create(options);
15642
+ const originalShape = options.shape;
15643
+ options.shape = null;
15687
15644
  const bodyCopy = this.kinematicBodyCopies.create(options);
15688
15645
  bodyCopy.copy(body2);
15689
15646
  body2.copyForDiff = bodyCopy;
15690
- this.broadphase.addKinematicBody(body2);
15647
+ bodyCopy.setShape(body2.shape, false);
15648
+ options.shape = originalShape;
15691
15649
  return body2;
15692
15650
  }
15693
15651
  createBody(options) {
@@ -15771,6 +15729,10 @@ class World {
15771
15729
  }
15772
15730
  // scene query API
15773
15731
  intersectShape(onHit2, shape, transform2, settings) {
15732
+ if (!(transform2 instanceof BasicTransform)) {
15733
+ tempBasicTransform.reset(transform2);
15734
+ transform2 = tempBasicTransform;
15735
+ }
15774
15736
  isometry.fromRotationAndTranslation(transform2.rotation, transform2.position);
15775
15737
  intersectShapeCollector.initialize(onHit2);
15776
15738
  this.collideBodiesModule.collideShape(
@@ -15780,7 +15742,7 @@ class World {
15780
15742
  intersectShapeCollector,
15781
15743
  collideShapeSettings,
15782
15744
  zeroVector,
15783
- AllFlag
15745
+ settings?.collisionMask ?? AllFlag
15784
15746
  );
15785
15747
  }
15786
15748
  castRay(onHit2, ray2, settings) {
@@ -15789,12 +15751,8 @@ class World {
15789
15751
  }
15790
15752
  castShape(onHit2, shape, transform2, displacementOrEndPosition, settings) {
15791
15753
  isometry.fromRotationAndTranslation(transform2.rotation, transform2.position);
15792
- settings = settings || {
15793
- precision: QueryPrecision.preciseWithContacts,
15794
- returnClosestOnly: false,
15795
- treatAsDisplacement: false
15796
- };
15797
- if (settings.treatAsDisplacement) {
15754
+ settings = settings || {};
15755
+ if (settings?.treatAsDisplacement ?? false) {
15798
15756
  displacement.copy(displacementOrEndPosition);
15799
15757
  } else {
15800
15758
  displacement.zero();
@@ -16059,7 +16017,21 @@ class IntersectShapeCollector extends CollisionCollector {
16059
16017
  }
16060
16018
  const intersectShapeCollector = /* @__PURE__ */ new IntersectShapeCollector();
16061
16019
  const displacement = /* @__PURE__ */ Vec3.create();
16062
- 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
+ };
16063
16035
  class CastShapeCollector extends CastCollector {
16064
16036
  constructor() {
16065
16037
  super(...arguments);
@@ -16073,6 +16045,7 @@ class CastShapeCollector extends CastCollector {
16073
16045
  }
16074
16046
  }
16075
16047
  const castShapeCollector = /* @__PURE__ */ new CastShapeCollector();
16048
+ const tempBasicTransform = /* @__PURE__ */ BasicTransform.create();
16076
16049
  export {
16077
16050
  Aabb,
16078
16051
  ActiveEdgeMode,