@perplexdotgg/bounce 1.0.0 → 1.0.2
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.d.ts +39501 -0
- package/build/bounce.js +17166 -0
- package/package.json +1 -1
- package/src/builders/ConvexHullBuilder.ts +0 -437
- package/src/builders/ConvexHullBuilder2d.ts +0 -344
- package/src/builders/ConvexHullBuilder3d.ts +0 -1689
- package/src/builders/HeightMapBuilder.ts +0 -414
- package/src/builders/TriangleMeshBuilder.ts +0 -92
- package/src/collision/CastShapesModule.ts +0 -184
- package/src/collision/CollideShapesModule.ts +0 -152
- package/src/collision/HeightMapCaster.ts +0 -38
- package/src/collision/HeightMapCollider.ts +0 -33
- package/src/collision/TriangleCaster.ts +0 -249
- package/src/collision/TriangleCollider.ts +0 -308
- package/src/collision/TriangleCollider2.ts +0 -379
- package/src/collision/activeEdge.ts +0 -146
- package/src/collision/cast/cast.ts +0 -139
- package/src/collision/cast/castCompoundVsCompound.ts +0 -59
- package/src/collision/cast/castCompoundVsConvex.ts +0 -116
- package/src/collision/cast/castConvexVsCompound.ts +0 -123
- package/src/collision/cast/castConvexVsConvex.ts +0 -213
- package/src/collision/cast/castConvexVsHeightMap.ts +0 -73
- package/src/collision/cast/castConvexVsTriangleMesh.ts +0 -56
- package/src/collision/cast/castRayVsCompound.ts +0 -44
- package/src/collision/cast/castRayVsConvex.ts +0 -45
- package/src/collision/cast/castRayVsHeightMap.ts +0 -58
- package/src/collision/cast/castRayVsTriangleMesh.ts +0 -58
- package/src/collision/closestPoints/closestPoints.ts +0 -23
- package/src/collision/closestPoints/computeBarycentricCoordinates2d.ts +0 -32
- package/src/collision/closestPoints/computeBarycentricCoordinates3d.ts +0 -81
- package/src/collision/closestPoints/computeClosestPointOnLine.ts +0 -30
- package/src/collision/closestPoints/computeClosestPointOnTetrahedron.ts +0 -96
- package/src/collision/closestPoints/computeClosestPointOnTriangle.ts +0 -195
- package/src/collision/closestPoints/isOriginOutsideOfPlane.ts +0 -25
- package/src/collision/closestPoints/isOriginOutsideOfTrianglePlanes.ts +0 -72
- package/src/collision/collide/collide.ts +0 -146
- package/src/collision/collide/collideCompoundVsCompound.ts +0 -60
- package/src/collision/collide/collideCompoundVsConvex.ts +0 -59
- package/src/collision/collide/collideCompoundVsHeightMap.ts +0 -73
- package/src/collision/collide/collideCompoundVsTriangleMesh.ts +0 -56
- package/src/collision/collide/collideConvexVsCompound.ts +0 -57
- package/src/collision/collide/collideConvexVsConvex.ts +0 -225
- package/src/collision/collide/collideConvexVsConvexImp.ts +0 -236
- package/src/collision/collide/collideConvexVsHeightMap.ts +0 -53
- package/src/collision/collide/collideConvexVsTriangleMesh.ts +0 -58
- package/src/collision/collide/collideHeightMapVsCompound.ts +0 -69
- package/src/collision/collide/collideHeightMapVsConvex.ts +0 -53
- package/src/collision/collide/collideSphereVsSphere.ts +0 -81
- package/src/collision/collide/collideTriangleMeshVsCompound.ts +0 -58
- package/src/collision/collide/collideTriangleMeshVsConvex.ts +0 -58
- package/src/collision/epa/EpaConvexHullBuilder.ts +0 -397
- package/src/collision/epa/StaticArray.ts +0 -154
- package/src/collision/epa/TriangleFactory.ts +0 -32
- package/src/collision/epa/arrays.ts +0 -99
- package/src/collision/epa/binaryHeap.ts +0 -82
- package/src/collision/epa/structs.ts +0 -227
- package/src/collision/gjk/GjkModule.ts +0 -864
- package/src/collision/gjk/PenetrationDepthModule.ts +0 -493
- package/src/collision/gjk/SupportPoints.ts +0 -50
- package/src/collision/imp/MinkowskiDifference.ts +0 -36
- package/src/collision/imp/computeExploredDistanceLowerUpperBound.ts +0 -40
- package/src/collision/imp/finalizeImpResult.ts +0 -69
- package/src/collision/imp/findContactImp.ts +0 -196
- package/src/collision/imp/imp.ts +0 -28
- package/src/collision/imp/incrementalMinimumDistanceExploreDirection.ts +0 -207
- package/src/collision/mpr/findPortal.ts +0 -152
- package/src/collision/mpr/mpr.ts +0 -29
- package/src/collision/mpr/updatePortal.ts +0 -52
- package/src/constraints/BaseConstraint.ts +0 -50
- package/src/constraints/ConstraintOptions.ts +0 -22
- package/src/constraints/ConstraintSolver.ts +0 -119
- package/src/constraints/DistanceConstraint.ts +0 -229
- package/src/constraints/FixedConstraint.ts +0 -203
- package/src/constraints/HingeConstraint.ts +0 -460
- package/src/constraints/PointConstraint.ts +0 -108
- package/src/constraints/components/AngleComponent.ts +0 -226
- package/src/constraints/components/AxisComponent.ts +0 -263
- package/src/constraints/components/HingeComponent.ts +0 -215
- package/src/constraints/components/Motor.ts +0 -36
- package/src/constraints/components/PointConstraintComponent.ts +0 -179
- package/src/constraints/components/RotationEulerComponent.ts +0 -139
- package/src/constraints/components/Spring.ts +0 -30
- package/src/constraints/components/SpringComponent.ts +0 -71
- package/src/constraints/types.ts +0 -6
- package/src/helpers.ts +0 -147
- package/src/index.ts +0 -50
- package/src/math/BasicTransform.ts +0 -19
- package/src/math/NumberValue.ts +0 -13
- package/src/math/isometry.ts +0 -64
- package/src/math/mat3.ts +0 -529
- package/src/math/mat4.ts +0 -588
- package/src/math/quat.ts +0 -193
- package/src/math/scalar.ts +0 -81
- package/src/math/tensor.ts +0 -17
- package/src/math/vec3.ts +0 -589
- package/src/math/vec4.ts +0 -10
- package/src/physics/Body.ts +0 -581
- package/src/physics/CollisionFilter.ts +0 -52
- package/src/physics/SleepModule.ts +0 -163
- package/src/physics/broadphase/BodyPairsModule.ts +0 -363
- package/src/physics/broadphase/BvhModule.ts +0 -237
- package/src/physics/broadphase/BvhTree.ts +0 -803
- package/src/physics/broadphase/ConstraintPairsModule.ts +0 -385
- package/src/physics/broadphase/TriangleMeshBvhTree.ts +0 -379
- package/src/physics/manifold/ContactManifold.ts +0 -227
- package/src/physics/manifold/ContactManifoldModule.ts +0 -623
- package/src/physics/manifold/Face.ts +0 -119
- package/src/physics/manifold/ManifoldCache.ts +0 -116
- package/src/physics/manifold/clipping/clipPolyVsEdge.ts +0 -131
- package/src/physics/manifold/clipping/clipPolyVsPlane.ts +0 -73
- package/src/physics/manifold/clipping/clipPolyVsPoly.ts +0 -72
- package/src/physics/narrowphase/CollideBodiesModule.ts +0 -755
- package/src/physics/solver/ContactConstraintModule.ts +0 -659
- package/src/physics/solver/ManifoldConstraint.ts +0 -420
- package/src/physics/solver/estimateCollisionResponse.ts +0 -146
- package/src/shape/Aabb.ts +0 -400
- package/src/shape/Box.ts +0 -231
- package/src/shape/Capsule.ts +0 -332
- package/src/shape/CompoundShape.ts +0 -288
- package/src/shape/Convex.ts +0 -130
- package/src/shape/ConvexHull.ts +0 -423
- package/src/shape/Cylinder.ts +0 -313
- package/src/shape/HeightMap.ts +0 -511
- package/src/shape/Line.ts +0 -14
- package/src/shape/Plane.ts +0 -116
- package/src/shape/Ray.ts +0 -81
- package/src/shape/Segment.ts +0 -25
- package/src/shape/Shape.ts +0 -77
- package/src/shape/Sphere.ts +0 -181
- package/src/shape/TransformedShape.ts +0 -51
- package/src/shape/Triangle.ts +0 -122
- package/src/shape/TriangleMesh.ts +0 -186
- package/src/types.ts +0 -1
- package/src/world.ts +0 -1335
- package/tests/BodyPairsModule.test.ts +0 -71
- package/tests/BvhTree.test.ts +0 -406
- package/tests/test.md +0 -642
- package/tests/vec3.test.ts +0 -12
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Aabb } from "../../shape/Aabb";
|
|
3
|
-
import { HeightMap } from "../../shape/HeightMap";
|
|
4
|
-
import { ConvexShape } from "../../shape/Shape";
|
|
5
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
6
|
-
import { BackFaceMode, CollisionCollector, CollisionSettings } from "./collide";
|
|
7
|
-
import { HeightMapCollider } from "../HeightMapCollider";
|
|
8
|
-
import { Body } from "../../physics/Body";
|
|
9
|
-
import { Vec3 } from "../../math/vec3";
|
|
10
|
-
|
|
11
|
-
const isometryWorldToB = /*@__PURE__*/ Isometry.create();
|
|
12
|
-
const isometryAToB = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
const shapeABoundsInBSpace = /*@__PURE__*/ Aabb.create();
|
|
14
|
-
|
|
15
|
-
const heightMapCollider = /*@__PURE__*/ new HeightMapCollider();
|
|
16
|
-
|
|
17
|
-
export function collideConvexVsHeightMap(
|
|
18
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
19
|
-
collector: CollisionCollector,
|
|
20
|
-
shapeA: ConvexShape,
|
|
21
|
-
shapeB: HeightMap,
|
|
22
|
-
isometryA: Isometry,
|
|
23
|
-
isometryB: Isometry,
|
|
24
|
-
settings: CollisionSettings,
|
|
25
|
-
bodyA: Body | null,
|
|
26
|
-
bodyB: Body | null,
|
|
27
|
-
initialDirection?: Vec3,
|
|
28
|
-
subShapeIdA: number = 0,
|
|
29
|
-
subShapeIdB: number = 0
|
|
30
|
-
) {
|
|
31
|
-
// TODO: don't hardcode this option
|
|
32
|
-
settings.backFaceMode = BackFaceMode.CollideWithBackFaces;
|
|
33
|
-
|
|
34
|
-
heightMapCollider.triangleCollider.initialize(
|
|
35
|
-
penetrationDepthModule,
|
|
36
|
-
shapeA,
|
|
37
|
-
isometryA,
|
|
38
|
-
isometryB,
|
|
39
|
-
settings,
|
|
40
|
-
collector,
|
|
41
|
-
undefined,
|
|
42
|
-
bodyA,
|
|
43
|
-
bodyB
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
isometryWorldToB.matrix.invertMatrix(isometryB.matrix);
|
|
47
|
-
isometryAToB.matrix.multiplyMatrices(isometryWorldToB.matrix, isometryA.matrix);
|
|
48
|
-
shapeABoundsInBSpace.copy(shapeA.computedAabb);
|
|
49
|
-
shapeABoundsInBSpace.transform(isometryAToB);
|
|
50
|
-
shapeABoundsInBSpace.expand(settings.maxSeparation);
|
|
51
|
-
heightMapCollider.initialize(shapeABoundsInBSpace, bodyA, bodyB);
|
|
52
|
-
shapeB.walkHeightMap(heightMapCollider);
|
|
53
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Aabb } from "../../shape/Aabb";
|
|
3
|
-
import { ConvexShape } from "../../shape/Shape";
|
|
4
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
5
|
-
import { ActiveEdgeMode, BackFaceMode, CollectFacesMode, CollisionCollector, CollisionSettings } from "./collide";
|
|
6
|
-
import { TriangleMesh } from "../../shape/TriangleMesh";
|
|
7
|
-
import { Triangle } from "../../shape/Triangle";
|
|
8
|
-
import { TriangleCollider2 } from "../TriangleCollider2";
|
|
9
|
-
import { Body } from "../../physics/Body";
|
|
10
|
-
import { Vec3 } from "../../math/vec3";
|
|
11
|
-
|
|
12
|
-
const isometryWorldToB = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
const isometryAToB = /*@__PURE__*/ Isometry.create();
|
|
14
|
-
const shapeABoundsInBSpace = /*@__PURE__*/ Aabb.create();
|
|
15
|
-
const triangleCollider = /*@__PURE__*/ new TriangleCollider2();
|
|
16
|
-
|
|
17
|
-
function onHit(triangle: Triangle): boolean {
|
|
18
|
-
triangleCollider.collide(triangle, triangle.activeEdges, triangle.subShapeId, undefined, undefined, false);
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function collideConvexVsTriangleMesh(
|
|
23
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
24
|
-
collector: CollisionCollector,
|
|
25
|
-
shapeA: ConvexShape,
|
|
26
|
-
shapeB: TriangleMesh,
|
|
27
|
-
isometryA: Isometry,
|
|
28
|
-
isometryB: Isometry,
|
|
29
|
-
settings: CollisionSettings,
|
|
30
|
-
bodyA: Body | null,
|
|
31
|
-
bodyB: Body | null,
|
|
32
|
-
initialDirection?: Vec3,
|
|
33
|
-
subShapeIdA: number = 0,
|
|
34
|
-
subShapeIdB: number = 0
|
|
35
|
-
): void {
|
|
36
|
-
// TODO: don't hardcode this option
|
|
37
|
-
settings.backFaceMode = BackFaceMode.IgnoreBackFaces;
|
|
38
|
-
settings.collectFacesMode = CollectFacesMode.CollectFaces;
|
|
39
|
-
settings.activeEdgeMode = ActiveEdgeMode.CollideWithAll;
|
|
40
|
-
|
|
41
|
-
triangleCollider.initialize(
|
|
42
|
-
penetrationDepthModule,
|
|
43
|
-
shapeA,
|
|
44
|
-
isometryA,
|
|
45
|
-
isometryB,
|
|
46
|
-
settings,
|
|
47
|
-
collector,
|
|
48
|
-
subShapeIdA,
|
|
49
|
-
bodyA,
|
|
50
|
-
bodyB
|
|
51
|
-
);
|
|
52
|
-
isometryWorldToB.matrix.invertMatrix(isometryB.matrix);
|
|
53
|
-
isometryAToB.matrix.multiplyMatrices(isometryWorldToB.matrix, isometryA.matrix);
|
|
54
|
-
shapeABoundsInBSpace.copy(shapeA.computedAabb);
|
|
55
|
-
shapeABoundsInBSpace.transform(isometryAToB);
|
|
56
|
-
shapeABoundsInBSpace.expand(settings.maxSeparation);
|
|
57
|
-
shapeB.bvh!.intersectAabb(onHit, shapeABoundsInBSpace);
|
|
58
|
-
}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Vec3 } from "../../math/vec3";
|
|
3
|
-
import { Aabb } from "../../shape/Aabb";
|
|
4
|
-
import { CompoundShape } from "../../shape/CompoundShape";
|
|
5
|
-
import { HeightMap } from "../../shape/HeightMap";
|
|
6
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
7
|
-
import { BackFaceMode, CollisionCollector, CollisionSettings } from "./collide";
|
|
8
|
-
import { HeightMapCollider } from "../HeightMapCollider";
|
|
9
|
-
import { Body } from "../../physics/Body";
|
|
10
|
-
import { ConvexShape } from "../../shape/Shape";
|
|
11
|
-
|
|
12
|
-
const isometryWorldToA = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
const isometryBToA = /*@__PURE__*/ Isometry.create();
|
|
14
|
-
const shapeBBoundsInASpace = /*@__PURE__*/ Aabb.create();
|
|
15
|
-
|
|
16
|
-
const transformSubShapeToB = /*@__PURE__*/ Isometry.create();
|
|
17
|
-
const transformSubShapeToWorld = /*@__PURE__*/ Isometry.create();
|
|
18
|
-
|
|
19
|
-
const heightMapCollider = /*@__PURE__*/ new HeightMapCollider();
|
|
20
|
-
|
|
21
|
-
export function collideHeightMapVsCompound(
|
|
22
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
23
|
-
collector: CollisionCollector,
|
|
24
|
-
shapeA: HeightMap,
|
|
25
|
-
shapeB: CompoundShape,
|
|
26
|
-
isometryA: Isometry,
|
|
27
|
-
isometryB: Isometry,
|
|
28
|
-
settings: CollisionSettings,
|
|
29
|
-
bodyA: Body | null,
|
|
30
|
-
bodyB: Body | null,
|
|
31
|
-
initialDirection?: Vec3,
|
|
32
|
-
subShapeIdA: number = 0,
|
|
33
|
-
subShapeIdB: number = 0
|
|
34
|
-
) {
|
|
35
|
-
// TODO: don't hardcode this option
|
|
36
|
-
settings.backFaceMode = BackFaceMode.CollideWithBackFaces;
|
|
37
|
-
|
|
38
|
-
let index = 0;
|
|
39
|
-
for (const { shape, transform } of shapeB.shapes) {
|
|
40
|
-
const translation = transform.position;
|
|
41
|
-
const rotation = transform.rotation;
|
|
42
|
-
|
|
43
|
-
// set the isometries
|
|
44
|
-
transformSubShapeToB.fromRotationAndTranslation(rotation, translation);
|
|
45
|
-
transformSubShapeToWorld.matrix.multiplyMatrices(isometryB.matrix, transformSubShapeToB.matrix);
|
|
46
|
-
|
|
47
|
-
heightMapCollider.triangleCollider.initialize(
|
|
48
|
-
penetrationDepthModule,
|
|
49
|
-
shape as ConvexShape,
|
|
50
|
-
transformSubShapeToWorld,
|
|
51
|
-
isometryA,
|
|
52
|
-
settings,
|
|
53
|
-
collector,
|
|
54
|
-
index
|
|
55
|
-
);
|
|
56
|
-
|
|
57
|
-
isometryWorldToA.matrix.invertMatrix(isometryA.matrix);
|
|
58
|
-
|
|
59
|
-
isometryBToA.matrix.multiplyMatrices(transformSubShapeToWorld.matrix, isometryWorldToA.matrix);
|
|
60
|
-
|
|
61
|
-
shapeBBoundsInASpace.copy((shape as ConvexShape).computedAabb);
|
|
62
|
-
shapeBBoundsInASpace.transform(isometryBToA);
|
|
63
|
-
shapeBBoundsInASpace.expand(settings.maxSeparation);
|
|
64
|
-
heightMapCollider.initialize(shapeBBoundsInASpace, bodyB, bodyA);
|
|
65
|
-
shapeA.walkHeightMap(heightMapCollider);
|
|
66
|
-
|
|
67
|
-
index++;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Vec3 } from "../../math/vec3";
|
|
3
|
-
import { Aabb } from "../../shape/Aabb";
|
|
4
|
-
import { HeightMap } from "../../shape/HeightMap";
|
|
5
|
-
import { ConvexShape } from "../../shape/Shape";
|
|
6
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
7
|
-
import { BackFaceMode, CollisionCollector, CollisionSettings } from "./collide";
|
|
8
|
-
import { HeightMapCollider } from "../HeightMapCollider";
|
|
9
|
-
import { Body } from "../../physics/Body";
|
|
10
|
-
|
|
11
|
-
const isometryWorldToA = /*@__PURE__*/ Isometry.create();
|
|
12
|
-
const isometryBToA = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
const shapeBBoundsInASpace = /*@__PURE__*/ Aabb.create();
|
|
14
|
-
|
|
15
|
-
const heightMapCollider = /*@__PURE__*/ new HeightMapCollider();
|
|
16
|
-
|
|
17
|
-
export function collideHeightMapVsConvex(
|
|
18
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
19
|
-
collector: CollisionCollector,
|
|
20
|
-
shapeA: HeightMap,
|
|
21
|
-
shapeB: ConvexShape,
|
|
22
|
-
isometryA: Isometry,
|
|
23
|
-
isometryB: Isometry,
|
|
24
|
-
settings: CollisionSettings,
|
|
25
|
-
bodyA: Body | null,
|
|
26
|
-
bodyB: Body | null,
|
|
27
|
-
initialDirection?: Vec3,
|
|
28
|
-
subShapeIdA: number = 0,
|
|
29
|
-
subShapeIdB: number = 0
|
|
30
|
-
) {
|
|
31
|
-
// TODO: don't hardcode this option
|
|
32
|
-
settings.backFaceMode = BackFaceMode.CollideWithBackFaces;
|
|
33
|
-
|
|
34
|
-
heightMapCollider.triangleCollider.initialize(
|
|
35
|
-
penetrationDepthModule,
|
|
36
|
-
shapeB,
|
|
37
|
-
isometryB,
|
|
38
|
-
isometryA,
|
|
39
|
-
settings,
|
|
40
|
-
collector,
|
|
41
|
-
undefined,
|
|
42
|
-
bodyB,
|
|
43
|
-
bodyA
|
|
44
|
-
);
|
|
45
|
-
|
|
46
|
-
isometryWorldToA.matrix.invertMatrix(isometryA.matrix);
|
|
47
|
-
isometryBToA.matrix.multiplyMatrices(isometryWorldToA.matrix, isometryB.matrix);
|
|
48
|
-
shapeBBoundsInASpace.copy(shapeB.computedAabb);
|
|
49
|
-
shapeBBoundsInASpace.transform(isometryBToA);
|
|
50
|
-
shapeBBoundsInASpace.expand(settings.maxSeparation);
|
|
51
|
-
heightMapCollider.initialize(shapeBBoundsInASpace, bodyB, bodyA);
|
|
52
|
-
shapeA.walkHeightMap(heightMapCollider);
|
|
53
|
-
}
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { squared } from "../../math/scalar";
|
|
3
|
-
import { Vec3 } from "../../math/vec3";
|
|
4
|
-
import { Body } from "../../physics/Body";
|
|
5
|
-
import { Sphere } from "../../shape/Sphere";
|
|
6
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
7
|
-
import { CollisionCollector, CollisionResult, CollisionSettings } from "./collide";
|
|
8
|
-
|
|
9
|
-
const result = CollisionResult.create({
|
|
10
|
-
faceA: {
|
|
11
|
-
numVertices: 0,
|
|
12
|
-
buffer: { pool: new Vec3.Pool(32), maxLength: 32 },
|
|
13
|
-
},
|
|
14
|
-
faceB: {
|
|
15
|
-
numVertices: 0,
|
|
16
|
-
buffer: { pool: new Vec3.Pool(32), maxLength: 32 },
|
|
17
|
-
},
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
const positionA = /*@__PURE__*/ Vec3.create();
|
|
21
|
-
const positionB = /*@__PURE__*/ Vec3.create();
|
|
22
|
-
const ab = /*@__PURE__*/ Vec3.create();
|
|
23
|
-
|
|
24
|
-
// TODO: use settings
|
|
25
|
-
// TODO: use initialDirection
|
|
26
|
-
export function collideSphereVsSphere(
|
|
27
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
28
|
-
collector: CollisionCollector,
|
|
29
|
-
shapeA: Sphere,
|
|
30
|
-
shapeB: Sphere,
|
|
31
|
-
isometryA: Isometry,
|
|
32
|
-
isometryB: Isometry,
|
|
33
|
-
settings: CollisionSettings,
|
|
34
|
-
bodyA: Body | null,
|
|
35
|
-
bodyB: Body | null,
|
|
36
|
-
initialDirection?: Vec3,
|
|
37
|
-
subShapeIdA: number = 0,
|
|
38
|
-
subShapeIdB: number = 0
|
|
39
|
-
) {
|
|
40
|
-
result.reset();
|
|
41
|
-
// @ts-ignore
|
|
42
|
-
result.bodyA = bodyA;
|
|
43
|
-
// @ts-ignore
|
|
44
|
-
result.bodyB = bodyB;
|
|
45
|
-
|
|
46
|
-
// get positions
|
|
47
|
-
isometryA.matrix.getTranslation(positionA);
|
|
48
|
-
isometryB.matrix.getTranslation(positionB);
|
|
49
|
-
|
|
50
|
-
// get distance
|
|
51
|
-
ab.subtractVectors(positionB, positionA);
|
|
52
|
-
|
|
53
|
-
// exit if no contact
|
|
54
|
-
if (ab.squaredLength() > squared(shapeA.radius + shapeB.radius)) {
|
|
55
|
-
result.hasContact = false;
|
|
56
|
-
collector.addMiss();
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
// set results
|
|
61
|
-
result.hasContact = true;
|
|
62
|
-
// @ts-ignore
|
|
63
|
-
result.bodyA = bodyA;
|
|
64
|
-
// @ts-ignore
|
|
65
|
-
result.bodyB = bodyB;
|
|
66
|
-
result.subShapeIdA = subShapeIdA;
|
|
67
|
-
result.subShapeIdB = subShapeIdB;
|
|
68
|
-
result.normalA.normalizeVector(ab);
|
|
69
|
-
result.normalB.negateVector(result.normalA);
|
|
70
|
-
result.contactPointA.addScaledToVector(positionA, result.normalA, shapeA.radius);
|
|
71
|
-
result.contactPointB.addScaledToVector(positionB, result.normalB, shapeB.radius);
|
|
72
|
-
result.momentArmA.subtractVectors(result.contactPointA, positionA);
|
|
73
|
-
result.momentArmB.subtractVectors(result.contactPointB, positionB);
|
|
74
|
-
result.penetration = shapeA.radius + shapeB.radius - ab.length();
|
|
75
|
-
|
|
76
|
-
// normalize the normals
|
|
77
|
-
result.normalA.normalizeVector(result.normalA);
|
|
78
|
-
result.normalB.normalizeVector(result.normalB);
|
|
79
|
-
|
|
80
|
-
collector.addHit(result);
|
|
81
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Vec3 } from "../../math/vec3";
|
|
3
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
4
|
-
import { CollisionCollector, CollisionSettings } from "./collide";
|
|
5
|
-
import { CompoundShape } from "../../shape/CompoundShape";
|
|
6
|
-
import { TriangleMesh } from "../../shape/TriangleMesh";
|
|
7
|
-
import { collideTriangleMeshVsConvex } from "./collideTriangleMeshVsConvex";
|
|
8
|
-
import { Body } from "../../physics/Body";
|
|
9
|
-
import { ConvexShape } from "../..";
|
|
10
|
-
|
|
11
|
-
const transformSubShapeToB = /*@__PURE__*/ Isometry.create();
|
|
12
|
-
const transformSubShapeToWorld = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
|
|
14
|
-
// the results are in world space
|
|
15
|
-
export function collideTriangleMeshVsCompound(
|
|
16
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
17
|
-
collector: CollisionCollector,
|
|
18
|
-
shapeA: TriangleMesh,
|
|
19
|
-
shapeB: CompoundShape,
|
|
20
|
-
isometryA: Isometry,
|
|
21
|
-
isometryB: Isometry,
|
|
22
|
-
settings: CollisionSettings,
|
|
23
|
-
bodyA: Body | null,
|
|
24
|
-
bodyB: Body | null,
|
|
25
|
-
initialDirection?: Vec3,
|
|
26
|
-
subShapeIdA: number = 0,
|
|
27
|
-
subShapeIdB: number = 0
|
|
28
|
-
): void {
|
|
29
|
-
// throw new Error("Not implemented");
|
|
30
|
-
|
|
31
|
-
let index = 0;
|
|
32
|
-
for (const { shape, transform } of shapeB.shapes) {
|
|
33
|
-
const translation = transform.position;
|
|
34
|
-
const rotation = transform.rotation;
|
|
35
|
-
|
|
36
|
-
// set the isometries
|
|
37
|
-
transformSubShapeToB.fromRotationAndTranslation(rotation, translation);
|
|
38
|
-
transformSubShapeToWorld.matrix.multiplyMatrices(isometryB.matrix, transformSubShapeToB.matrix);
|
|
39
|
-
|
|
40
|
-
// collide the shapes. TODO: this should be convex vs convex for now, but may be expanded in the future
|
|
41
|
-
collideTriangleMeshVsConvex(
|
|
42
|
-
penetrationDepthModule,
|
|
43
|
-
collector,
|
|
44
|
-
shapeA,
|
|
45
|
-
shape as ConvexShape,
|
|
46
|
-
isometryA,
|
|
47
|
-
transformSubShapeToWorld,
|
|
48
|
-
settings,
|
|
49
|
-
bodyA,
|
|
50
|
-
bodyB,
|
|
51
|
-
initialDirection,
|
|
52
|
-
0,
|
|
53
|
-
index
|
|
54
|
-
);
|
|
55
|
-
|
|
56
|
-
index++;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { Isometry } from "../../math/isometry";
|
|
2
|
-
import { Aabb } from "../../shape/Aabb";
|
|
3
|
-
import { ConvexShape } from "../../shape/Shape";
|
|
4
|
-
import { PenetrationDepthModule } from "../gjk/PenetrationDepthModule";
|
|
5
|
-
import { ActiveEdgeMode, BackFaceMode, CollectFacesMode, CollisionCollector, CollisionSettings } from "./collide";
|
|
6
|
-
import { TriangleMesh } from "../../shape/TriangleMesh";
|
|
7
|
-
import { Triangle } from "../../shape/Triangle";
|
|
8
|
-
import { TriangleCollider2 } from "../TriangleCollider2";
|
|
9
|
-
import { Body } from "../../physics/Body";
|
|
10
|
-
import { Vec3 } from "../../math/vec3";
|
|
11
|
-
|
|
12
|
-
const isometryWorldToA = /*@__PURE__*/ Isometry.create();
|
|
13
|
-
const isometryBToA = /*@__PURE__*/ Isometry.create();
|
|
14
|
-
const shapeBBoundsInASpace = /*@__PURE__*/ Aabb.create();
|
|
15
|
-
const triangleCollider = /*@__PURE__*/ new TriangleCollider2();
|
|
16
|
-
|
|
17
|
-
function onHit(triangle: Triangle): boolean {
|
|
18
|
-
triangleCollider.collide(triangle, triangle.activeEdges, triangle.subShapeId, undefined, undefined, true);
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export function collideTriangleMeshVsConvex(
|
|
23
|
-
penetrationDepthModule: PenetrationDepthModule,
|
|
24
|
-
collector: CollisionCollector,
|
|
25
|
-
shapeA: TriangleMesh,
|
|
26
|
-
shapeB: ConvexShape,
|
|
27
|
-
isometryA: Isometry,
|
|
28
|
-
isometryB: Isometry,
|
|
29
|
-
settings: CollisionSettings,
|
|
30
|
-
bodyA: Body | null,
|
|
31
|
-
bodyB: Body | null,
|
|
32
|
-
initialDirection?: Vec3,
|
|
33
|
-
subShapeIdA: number = 0,
|
|
34
|
-
subShapeIdB: number = 0
|
|
35
|
-
): void {
|
|
36
|
-
// TODO: don't hardcode this option
|
|
37
|
-
settings.backFaceMode = BackFaceMode.IgnoreBackFaces;
|
|
38
|
-
settings.collectFacesMode = CollectFacesMode.CollectFaces;
|
|
39
|
-
settings.activeEdgeMode = ActiveEdgeMode.CollideWithAll;
|
|
40
|
-
|
|
41
|
-
triangleCollider.initialize(
|
|
42
|
-
penetrationDepthModule,
|
|
43
|
-
shapeB,
|
|
44
|
-
isometryB,
|
|
45
|
-
isometryA,
|
|
46
|
-
settings,
|
|
47
|
-
collector,
|
|
48
|
-
subShapeIdB,
|
|
49
|
-
bodyB,
|
|
50
|
-
bodyA
|
|
51
|
-
);
|
|
52
|
-
isometryWorldToA.matrix.invertMatrix(isometryA.matrix);
|
|
53
|
-
isometryBToA.matrix.multiplyMatrices(isometryWorldToA.matrix, isometryB.matrix);
|
|
54
|
-
shapeBBoundsInASpace.copy(shapeB.computedAabb);
|
|
55
|
-
shapeBBoundsInASpace.transform(isometryBToA);
|
|
56
|
-
shapeBBoundsInASpace.expand(settings.maxSeparation);
|
|
57
|
-
shapeA.bvh!.intersectAabb(onHit, shapeBBoundsInASpace);
|
|
58
|
-
}
|