@perplexdotgg/bounce 1.0.0 → 1.0.1
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/src/world.ts
DELETED
|
@@ -1,1335 +0,0 @@
|
|
|
1
|
-
import { InputType, PartialRecursive, WithPool } from "monomorph";
|
|
2
|
-
import { CastRayResult, CollideBodiesModule, CollideBodiesSettings } from "./physics/narrowphase/CollideBodiesModule";
|
|
3
|
-
import {
|
|
4
|
-
ActiveEdgeMode,
|
|
5
|
-
BackFaceMode,
|
|
6
|
-
CollectFacesMode,
|
|
7
|
-
CollisionCollector,
|
|
8
|
-
CollisionResult,
|
|
9
|
-
CollisionSettings,
|
|
10
|
-
} from "./collision/collide/collide";
|
|
11
|
-
import { CollideShapesModule } from "./collision/CollideShapesModule";
|
|
12
|
-
import { CoefficientFunctionType, ContactConstraintModule } from "./physics/solver/ContactConstraintModule";
|
|
13
|
-
import { ContactManifoldModule } from "./physics/manifold/ContactManifoldModule";
|
|
14
|
-
import { GjkModule } from "./collision/gjk/GjkModule";
|
|
15
|
-
import { PenetrationDepthModule } from "./collision/gjk/PenetrationDepthModule";
|
|
16
|
-
import { SleepModule, SleepOptions } from "./physics/SleepModule";
|
|
17
|
-
import { transformTensor } from "./math/tensor";
|
|
18
|
-
import { Vec3 } from "./math/vec3";
|
|
19
|
-
import { Body, BodyType, updateBody, updateWorldBounds } from "./physics/Body";
|
|
20
|
-
import { Sphere } from "./shape/Sphere";
|
|
21
|
-
import { Box } from "./shape/Box";
|
|
22
|
-
import { Ray } from "./shape/Ray";
|
|
23
|
-
import { BasicTransform } from "./math/BasicTransform";
|
|
24
|
-
import { DynamicShape, KinematicShape, Shape, ShapeType, StaticShape } from "./shape/Shape";
|
|
25
|
-
import { BvhModule, BvhModuleOptions } from "./physics/broadphase/BvhModule";
|
|
26
|
-
import { ManifoldCacheOptions } from "./physics/manifold/ManifoldCache";
|
|
27
|
-
import { CompoundShape } from "./shape/CompoundShape";
|
|
28
|
-
import { TransformedShape } from "./shape/TransformedShape";
|
|
29
|
-
import { CastShapesModule } from "./collision/CastShapesModule";
|
|
30
|
-
import { HeightMapBuilder } from "./builders/HeightMapBuilder";
|
|
31
|
-
import { ConvexHullBuilder } from "./builders/ConvexHullBuilder";
|
|
32
|
-
import ConvexHull, { ConvexHullFace, ConvexHullPoint } from "./shape/ConvexHull";
|
|
33
|
-
import { Cylinder } from "./shape/Cylinder";
|
|
34
|
-
import { BuildTriangleMeshParams, TriangleMeshBuilder } from "./builders/TriangleMeshBuilder";
|
|
35
|
-
import { TriangleMesh } from "./shape/TriangleMesh";
|
|
36
|
-
import { ConstraintSolver } from "./constraints/ConstraintSolver";
|
|
37
|
-
import { CastCollector, createDefaultCastSettings, QueryPrecision, RayCastSettings } from "./collision/cast/cast";
|
|
38
|
-
import { AllFlag } from "./physics/CollisionFilter";
|
|
39
|
-
import { Isometry } from "./math/isometry";
|
|
40
|
-
import { Capsule } from "./shape/Capsule";
|
|
41
|
-
import { ContactManifold, createContactPairKey } from "./physics/manifold/ContactManifold";
|
|
42
|
-
import { EstimateCollisionResponseResult } from "./physics/solver/estimateCollisionResponse";
|
|
43
|
-
import { PointConstraint } from "./constraints/PointConstraint";
|
|
44
|
-
import { FixedConstraint } from "./constraints/FixedConstraint";
|
|
45
|
-
import { DistanceConstraint } from "./constraints/DistanceConstraint";
|
|
46
|
-
import { HingeConstraint } from "./constraints/HingeConstraint";
|
|
47
|
-
import { ConstraintPairEdge, ConstraintPairNode, ConstraintPairsModule } from "./physics/broadphase/ConstraintPairsModule";
|
|
48
|
-
import { Constraint } from "./constraints/types";
|
|
49
|
-
import { HeightMap } from "./shape/HeightMap";
|
|
50
|
-
import { TriangleMeshBvhNode as TriangleMeshBvhNode, TriangleMeshBvhTree } from "./physics/broadphase/TriangleMeshBvhTree";
|
|
51
|
-
import { Triangle } from "./shape/Triangle";
|
|
52
|
-
import { Plane } from "./shape/Plane";
|
|
53
|
-
import { NumberValue } from "./math/NumberValue";
|
|
54
|
-
import { BodyPairEdge, BodyPairNode } from "./physics/broadphase/BodyPairsModule";
|
|
55
|
-
import { BvhNode } from "./physics/broadphase/BvhTree";
|
|
56
|
-
|
|
57
|
-
const shapeCenterOfMassInWorldSpace = /*@__PURE__*/ Vec3.create() as Vec3;
|
|
58
|
-
|
|
59
|
-
interface WorldOptions {
|
|
60
|
-
gravity: InputType<Vec3>;
|
|
61
|
-
broadphaseOptions: PartialRecursive<BvhModuleOptions>;
|
|
62
|
-
isGravityEnabled: boolean;
|
|
63
|
-
restitution: number;
|
|
64
|
-
friction: number;
|
|
65
|
-
solveVelocityIterations: number;
|
|
66
|
-
solvePositionIterations: number;
|
|
67
|
-
linearDamping: number;
|
|
68
|
-
angularDamping: number;
|
|
69
|
-
frictionFunction: CoefficientFunctionType;
|
|
70
|
-
restitutionFunction: CoefficientFunctionType;
|
|
71
|
-
minVelocityForElasticContact: number;
|
|
72
|
-
baumgarte: number;
|
|
73
|
-
penetrationSlop: number;
|
|
74
|
-
maxPenetrationDistance: number;
|
|
75
|
-
speculativeContactDistance: number;
|
|
76
|
-
collisionTolerance: number;
|
|
77
|
-
maxLinearSpeed: number;
|
|
78
|
-
maxAngularSpeed: number;
|
|
79
|
-
isWarmStartingEnabled: boolean;
|
|
80
|
-
collideShapeSettings: CollisionSettings;
|
|
81
|
-
timeStepSizeSeconds: number;
|
|
82
|
-
maxTimeToSimulateSeconds: number;
|
|
83
|
-
sleepOptions?: PartialRecursive<SleepOptions>;
|
|
84
|
-
contactManifoldOptions?: PartialRecursive<ManifoldCacheOptions>;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* a container and API for a physics simulation
|
|
89
|
-
*/
|
|
90
|
-
export class World {
|
|
91
|
-
options: WorldOptions;
|
|
92
|
-
gravity: Vec3;
|
|
93
|
-
|
|
94
|
-
collideBodiesSettings: CollideBodiesSettings;
|
|
95
|
-
maxLinearSpeedSquared: number;
|
|
96
|
-
maxAngularSpeedSquared: number;
|
|
97
|
-
|
|
98
|
-
collideShapesModule: CollideShapesModule;
|
|
99
|
-
castShapesModule: CastShapesModule;
|
|
100
|
-
|
|
101
|
-
collideBodiesModule: CollideBodiesModule;
|
|
102
|
-
sleepModule: SleepModule;
|
|
103
|
-
|
|
104
|
-
heightMapBuilder: HeightMapBuilder;
|
|
105
|
-
convexHullBuilder: ConvexHullBuilder;
|
|
106
|
-
triangleMeshBuilder: TriangleMeshBuilder;
|
|
107
|
-
|
|
108
|
-
constraintSolver: ConstraintSolver;
|
|
109
|
-
|
|
110
|
-
dynamicBodyCopies: typeof Body.ReferenceList;
|
|
111
|
-
kinematicBodyCopies: typeof Body.ReferenceList;
|
|
112
|
-
staticBodyCopies: typeof Body.ReferenceList;
|
|
113
|
-
|
|
114
|
-
dynamicBodies: typeof Body.ReferenceList;
|
|
115
|
-
kinematicBodies: typeof Body.ReferenceList;
|
|
116
|
-
staticBodies: typeof Body.ReferenceList;
|
|
117
|
-
|
|
118
|
-
pools: {
|
|
119
|
-
// shapes
|
|
120
|
-
sphere: typeof Sphere.Pool;
|
|
121
|
-
box: typeof Box.Pool;
|
|
122
|
-
capsule: typeof Capsule.Pool;
|
|
123
|
-
cylinder: typeof Cylinder.Pool;
|
|
124
|
-
convexHullFace: typeof ConvexHullFace.Pool;
|
|
125
|
-
convexHullNumberValue: typeof NumberValue.Pool;
|
|
126
|
-
convexHullPlane: typeof Plane.Pool;
|
|
127
|
-
convexHullPoint: typeof ConvexHullPoint.Pool;
|
|
128
|
-
convexHullVec3: typeof Vec3.Pool;
|
|
129
|
-
convexHull: typeof ConvexHull.Pool;
|
|
130
|
-
transformedShape: typeof TransformedShape.Pool;
|
|
131
|
-
triangleMeshBvhNode: typeof TriangleMeshBvhNode.Pool;
|
|
132
|
-
triangleMeshVertexPosition: typeof Vec3.Pool;
|
|
133
|
-
triangleMeshFaceIndex: typeof Vec3.Pool;
|
|
134
|
-
triangleMeshTriangle: typeof Triangle.Pool;
|
|
135
|
-
triangleMeshBvhTree: typeof TriangleMeshBvhTree.Pool;
|
|
136
|
-
triangleMesh: typeof TriangleMesh.Pool;
|
|
137
|
-
compoundShape: typeof CompoundShape.Pool;
|
|
138
|
-
heightMap: typeof HeightMap.Pool;
|
|
139
|
-
sphereCopy: typeof Sphere.Pool;
|
|
140
|
-
boxCopy: typeof Box.Pool;
|
|
141
|
-
capsuleCopy: typeof Capsule.Pool;
|
|
142
|
-
cylinderCopy: typeof Cylinder.Pool;
|
|
143
|
-
convexHullCopy: typeof ConvexHull.Pool;
|
|
144
|
-
triangleMeshCopy: typeof TriangleMesh.Pool;
|
|
145
|
-
compoundShapeCopy: typeof CompoundShape.Pool;
|
|
146
|
-
heightMapCopy: typeof HeightMap.Pool;
|
|
147
|
-
|
|
148
|
-
// bvh
|
|
149
|
-
bvhNodes: typeof BvhNode.Pool;
|
|
150
|
-
|
|
151
|
-
constraintPairNode: typeof ConstraintPairNode.Pool;
|
|
152
|
-
constraintPairEdge: typeof ConstraintPairEdge.Pool;
|
|
153
|
-
|
|
154
|
-
// bodies
|
|
155
|
-
body: typeof Body.Pool;
|
|
156
|
-
bodyCopy: typeof Body.Pool;
|
|
157
|
-
|
|
158
|
-
// body pairs
|
|
159
|
-
bodyPairNode: typeof BodyPairNode.Pool;
|
|
160
|
-
bodyPairEdge: typeof BodyPairEdge.Pool;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
broadphase: BvhModule;
|
|
164
|
-
|
|
165
|
-
step: number;
|
|
166
|
-
lastAdvanceTimeCall: number | null;
|
|
167
|
-
advanceTimeAccumulatedSeconds: number;
|
|
168
|
-
maxTimeToSimulateSeconds: number;
|
|
169
|
-
|
|
170
|
-
previousTimeStepSizeSeconds: number;
|
|
171
|
-
|
|
172
|
-
constructor(options: PartialRecursive<WorldOptions> = {}) {
|
|
173
|
-
this.options = {
|
|
174
|
-
gravity: { x: 0, y: -9.80665, z: 0 },
|
|
175
|
-
broadphaseOptions: undefined,
|
|
176
|
-
isGravityEnabled: true,
|
|
177
|
-
restitution: 0,
|
|
178
|
-
friction: 0,
|
|
179
|
-
solveVelocityIterations: 6,
|
|
180
|
-
solvePositionIterations: 2,
|
|
181
|
-
linearDamping: 0.05,
|
|
182
|
-
angularDamping: 0.05,
|
|
183
|
-
frictionFunction: CoefficientFunctionType.max,
|
|
184
|
-
restitutionFunction: CoefficientFunctionType.max,
|
|
185
|
-
minVelocityForElasticContact: 2,
|
|
186
|
-
baumgarte: 0.2,
|
|
187
|
-
penetrationSlop: 0.02,
|
|
188
|
-
maxPenetrationDistance: 0.2,
|
|
189
|
-
speculativeContactDistance: 0.02,
|
|
190
|
-
collisionTolerance: 1e-4,
|
|
191
|
-
maxLinearSpeed: 30.0,
|
|
192
|
-
maxAngularSpeed: 30.0,
|
|
193
|
-
isWarmStartingEnabled: true,
|
|
194
|
-
collideShapeSettings: {
|
|
195
|
-
maxSeparation: 0.02,
|
|
196
|
-
collisionTolerance: 1e-4,
|
|
197
|
-
activeEdgeMode: ActiveEdgeMode.CollideOnlyWithActive,
|
|
198
|
-
collectFacesMode: CollectFacesMode.NoFaces,
|
|
199
|
-
penetrationTolerance: 1e-4,
|
|
200
|
-
activeEdgeMovementDirectionX: 0,
|
|
201
|
-
activeEdgeMovementDirectionY: 0,
|
|
202
|
-
activeEdgeMovementDirectionZ: 0,
|
|
203
|
-
backFaceMode: BackFaceMode.IgnoreBackFaces,
|
|
204
|
-
},
|
|
205
|
-
timeStepSizeSeconds: 1 / 60,
|
|
206
|
-
maxTimeToSimulateSeconds: 1,
|
|
207
|
-
sleepOptions: undefined,
|
|
208
|
-
contactManifoldOptions: undefined,
|
|
209
|
-
...options,
|
|
210
|
-
} as WorldOptions;
|
|
211
|
-
|
|
212
|
-
this.collideBodiesSettings = { speculativeContactDistance: this.options.speculativeContactDistance };
|
|
213
|
-
this.maxLinearSpeedSquared = this.options.maxLinearSpeed * this.options.maxLinearSpeed;
|
|
214
|
-
this.maxAngularSpeedSquared = this.options.maxAngularSpeed * this.options.maxAngularSpeed;
|
|
215
|
-
this.gravity = Vec3.create(this.options.gravity);
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
this.pools = {
|
|
219
|
-
// shapes
|
|
220
|
-
box: new Box.Pool(),
|
|
221
|
-
boxCopy: new Box.Pool(),
|
|
222
|
-
capsule: new Capsule.Pool(),
|
|
223
|
-
capsuleCopy: new Capsule.Pool(),
|
|
224
|
-
compoundShape: new CompoundShape.Pool(),
|
|
225
|
-
compoundShapeCopy: new CompoundShape.Pool(),
|
|
226
|
-
convexHullFace: new ConvexHullFace.Pool(),
|
|
227
|
-
convexHullNumberValue: new NumberValue.Pool(),
|
|
228
|
-
convexHullPlane: new Plane.Pool(),
|
|
229
|
-
convexHullPoint: new ConvexHullPoint.Pool(),
|
|
230
|
-
convexHullVec3: new Vec3.Pool(),
|
|
231
|
-
convexHull: new ConvexHull.Pool(),
|
|
232
|
-
convexHullCopy: new ConvexHull.Pool(),
|
|
233
|
-
cylinder: new Cylinder.Pool(),
|
|
234
|
-
cylinderCopy: new Cylinder.Pool(),
|
|
235
|
-
heightMap: new HeightMap.Pool(),
|
|
236
|
-
heightMapCopy: new HeightMap.Pool(),
|
|
237
|
-
sphere: new Sphere.Pool(),
|
|
238
|
-
sphereCopy: new Sphere.Pool(),
|
|
239
|
-
transformedShape: new TransformedShape.Pool(),
|
|
240
|
-
triangleMesh: new TriangleMesh.Pool(),
|
|
241
|
-
triangleMeshBvhNode: new TriangleMeshBvhNode.Pool(),
|
|
242
|
-
triangleMeshBvhTree: new TriangleMeshBvhTree.Pool(),
|
|
243
|
-
triangleMeshCopy: new TriangleMesh.Pool(),
|
|
244
|
-
triangleMeshFaceIndex: new Vec3.Pool(),
|
|
245
|
-
triangleMeshTriangle: new Triangle.Pool(),
|
|
246
|
-
triangleMeshVertexPosition: new Vec3.Pool(),
|
|
247
|
-
|
|
248
|
-
bvhNodes: new BvhNode.Pool(),
|
|
249
|
-
|
|
250
|
-
constraintPairNode: new ConstraintPairNode.Pool(),
|
|
251
|
-
constraintPairEdge: new ConstraintPairEdge.Pool(),
|
|
252
|
-
|
|
253
|
-
body: new Body.Pool(),
|
|
254
|
-
bodyCopy: new Body.Pool(),
|
|
255
|
-
|
|
256
|
-
bodyPairEdge: new BodyPairEdge.Pool(),
|
|
257
|
-
bodyPairNode: new BodyPairNode.Pool(),
|
|
258
|
-
};
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
this.broadphase = new BvhModule(this, (this.options.broadphaseOptions as BvhModuleOptions) || undefined);
|
|
263
|
-
const gjkModule = new GjkModule();
|
|
264
|
-
const penetrationDepthModule = new PenetrationDepthModule(gjkModule);
|
|
265
|
-
const collideShapesModule = new CollideShapesModule(penetrationDepthModule);
|
|
266
|
-
const castShapesModule = new CastShapesModule(penetrationDepthModule);
|
|
267
|
-
this.collideShapesModule = collideShapesModule;
|
|
268
|
-
this.castShapesModule = castShapesModule;
|
|
269
|
-
const contactManifoldModule = new ContactManifoldModule(this.options.contactManifoldOptions);
|
|
270
|
-
const contactConstraintModule = new ContactConstraintModule(this, contactManifoldModule);
|
|
271
|
-
const constraintPairs = new ConstraintPairsModule(this.pools.constraintPairNode, this.pools.constraintPairEdge);
|
|
272
|
-
const sleepModule = new SleepModule(this.broadphase.pairs, constraintPairs, this.options.sleepOptions);
|
|
273
|
-
this.collideBodiesModule = new CollideBodiesModule(
|
|
274
|
-
this,
|
|
275
|
-
collideShapesModule,
|
|
276
|
-
castShapesModule,
|
|
277
|
-
contactManifoldModule,
|
|
278
|
-
contactConstraintModule,
|
|
279
|
-
sleepModule
|
|
280
|
-
);
|
|
281
|
-
|
|
282
|
-
this.heightMapBuilder = new HeightMapBuilder();
|
|
283
|
-
this.convexHullBuilder = new ConvexHullBuilder();
|
|
284
|
-
this.triangleMeshBuilder = new TriangleMeshBuilder();
|
|
285
|
-
|
|
286
|
-
this.constraintSolver = new ConstraintSolver(this, constraintPairs);
|
|
287
|
-
|
|
288
|
-
this.sleepModule = sleepModule;
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
this.dynamicBodyCopies = new Body.ReferenceList(this.pools.bodyCopy);
|
|
292
|
-
this.kinematicBodyCopies = new Body.ReferenceList(this.pools.bodyCopy);
|
|
293
|
-
this.staticBodyCopies = new Body.ReferenceList(this.pools.bodyCopy);
|
|
294
|
-
|
|
295
|
-
this.dynamicBodies = new Body.ReferenceList(this.pools.body);
|
|
296
|
-
this.kinematicBodies = new Body.ReferenceList(this.pools.body);
|
|
297
|
-
this.staticBodies = new Body.ReferenceList(this.pools.body);
|
|
298
|
-
|
|
299
|
-
this.step = 0;
|
|
300
|
-
this.lastAdvanceTimeCall = null;
|
|
301
|
-
this.advanceTimeAccumulatedSeconds = 0;
|
|
302
|
-
this.maxTimeToSimulateSeconds = this.options.maxTimeToSimulateSeconds;
|
|
303
|
-
|
|
304
|
-
this.previousTimeStepSizeSeconds = this.options.timeStepSizeSeconds;
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
collideBodiesWithBroadphase(
|
|
309
|
-
timeStepSizeSeconds: number,
|
|
310
|
-
isWarmStartingEnabled: boolean,
|
|
311
|
-
minVelocityForElasticContact: number
|
|
312
|
-
) {
|
|
313
|
-
this.collideBodiesModule.contactManifoldModule.flipCache();
|
|
314
|
-
this.collideBodiesModule.contactConstraintModule.clearContactConstraints();
|
|
315
|
-
|
|
316
|
-
for (let pair of this.broadphase.iteratePairs()) {
|
|
317
|
-
this.collideBodiesModule.collideBodies(
|
|
318
|
-
pair.bodyA!,
|
|
319
|
-
pair.bodyB!,
|
|
320
|
-
this.options.collideShapeSettings,
|
|
321
|
-
this.collideBodiesSettings,
|
|
322
|
-
timeStepSizeSeconds,
|
|
323
|
-
isWarmStartingEnabled,
|
|
324
|
-
minVelocityForElasticContact
|
|
325
|
-
);
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
*iterateOverBodyPairsBruteForce() {
|
|
330
|
-
for (const bodyA of this.dynamicBodies) {
|
|
331
|
-
for (const bodyB of this.dynamicBodies) {
|
|
332
|
-
// skip self
|
|
333
|
-
if (bodyA === bodyB) {
|
|
334
|
-
continue;
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
// skip already checked pairs
|
|
338
|
-
if (bodyA.index > bodyB.index) {
|
|
339
|
-
continue;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
yield [bodyA, bodyB];
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
for (const bodyB of this.kinematicBodies) {
|
|
346
|
-
yield [bodyA, bodyB];
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
for (const bodyB of this.staticBodies) {
|
|
350
|
-
yield [bodyA, bodyB];
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
collideBodiesWithoutBroadphase(
|
|
356
|
-
timeStepSizeSeconds: number,
|
|
357
|
-
isWarmStartingEnabled: boolean,
|
|
358
|
-
minVelocityForElasticContact: number
|
|
359
|
-
) {
|
|
360
|
-
this.collideBodiesModule.contactManifoldModule.flipCache();
|
|
361
|
-
this.collideBodiesModule.contactConstraintModule.clearContactConstraints();
|
|
362
|
-
// this.collideBodiesModule.contactManifoldModule.bodiesInContact.clear(); // TODO
|
|
363
|
-
|
|
364
|
-
for (const bodyA of this.dynamicBodies) {
|
|
365
|
-
for (const bodyB of this.dynamicBodies) {
|
|
366
|
-
// skip self
|
|
367
|
-
if (bodyA === bodyB) {
|
|
368
|
-
continue;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
// skip already checked pairs
|
|
372
|
-
if (bodyA.index > bodyB.index) {
|
|
373
|
-
continue;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
// skip if bounds have no overlap
|
|
377
|
-
if (bodyA.computedBounds.intersectsAabb(bodyB.computedBounds) === false) {
|
|
378
|
-
continue;
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
this.collideBodiesModule.collideBodies(
|
|
382
|
-
bodyA,
|
|
383
|
-
bodyB,
|
|
384
|
-
this.options.collideShapeSettings,
|
|
385
|
-
this.collideBodiesSettings,
|
|
386
|
-
timeStepSizeSeconds,
|
|
387
|
-
isWarmStartingEnabled,
|
|
388
|
-
minVelocityForElasticContact
|
|
389
|
-
);
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
for (const bodyB of this.kinematicBodies) {
|
|
393
|
-
// skip if bounds have no overlap
|
|
394
|
-
if (bodyA.computedBounds.intersectsAabb(bodyB.computedBounds) === false) {
|
|
395
|
-
continue;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
this.collideBodiesModule.collideBodies(
|
|
399
|
-
bodyA,
|
|
400
|
-
bodyB,
|
|
401
|
-
this.options.collideShapeSettings,
|
|
402
|
-
this.collideBodiesSettings,
|
|
403
|
-
timeStepSizeSeconds,
|
|
404
|
-
isWarmStartingEnabled,
|
|
405
|
-
minVelocityForElasticContact
|
|
406
|
-
);
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
for (const bodyB of this.staticBodies) {
|
|
410
|
-
// skip if bounds have no overlap
|
|
411
|
-
if (bodyA.computedBounds.intersectsAabb(bodyB.computedBounds) === false) {
|
|
412
|
-
continue;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
this.collideBodiesModule.collideBodies(
|
|
416
|
-
bodyA,
|
|
417
|
-
bodyB,
|
|
418
|
-
this.options.collideShapeSettings,
|
|
419
|
-
this.collideBodiesSettings,
|
|
420
|
-
timeStepSizeSeconds,
|
|
421
|
-
isWarmStartingEnabled,
|
|
422
|
-
minVelocityForElasticContact
|
|
423
|
-
);
|
|
424
|
-
}
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* integrates the acceleration of all bodies
|
|
430
|
-
*/
|
|
431
|
-
applyAccelerationIntegration(
|
|
432
|
-
bodies: typeof Body.Pool | typeof Body.ReferenceList,
|
|
433
|
-
timeStepSizeSeconds: number,
|
|
434
|
-
gravity: Vec3,
|
|
435
|
-
isGravityEnabled: boolean,
|
|
436
|
-
linearDamping: number,
|
|
437
|
-
angularDamping: number,
|
|
438
|
-
maxLinearSpeed: number,
|
|
439
|
-
maxLinearSpeedSquared: number,
|
|
440
|
-
maxAngularSpeed: number,
|
|
441
|
-
maxAngularSpeedSquared: number
|
|
442
|
-
) {
|
|
443
|
-
for (const body of bodies) {
|
|
444
|
-
if (body.isSleeping) {
|
|
445
|
-
continue;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
body.applyAccelerationIntegration(
|
|
449
|
-
timeStepSizeSeconds,
|
|
450
|
-
gravity,
|
|
451
|
-
isGravityEnabled,
|
|
452
|
-
linearDamping,
|
|
453
|
-
angularDamping,
|
|
454
|
-
maxLinearSpeed,
|
|
455
|
-
maxLinearSpeedSquared,
|
|
456
|
-
maxAngularSpeed,
|
|
457
|
-
maxAngularSpeedSquared
|
|
458
|
-
);
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
/**
|
|
463
|
-
* integrates the linear velocity of all bodies
|
|
464
|
-
*/
|
|
465
|
-
applyVelocityIntegration(bodies: typeof Body.Pool | typeof Body.ReferenceList, timeStepSizeSeconds: number) {
|
|
466
|
-
for (const body of bodies) {
|
|
467
|
-
if (body.isSleeping) {
|
|
468
|
-
continue;
|
|
469
|
-
}
|
|
470
|
-
body.applyLinearVelocityIntegration(timeStepSizeSeconds);
|
|
471
|
-
body.applyAngularVelocityIntegration(timeStepSizeSeconds);
|
|
472
|
-
this.broadphase.markDynamicBodyAsDirty(body);
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
|
|
476
|
-
solveVelocityConstraintsInterleaved(
|
|
477
|
-
isWarmStartingEnabled: boolean,
|
|
478
|
-
solveVelocityIterations: number,
|
|
479
|
-
deltaTimeSeconds: number,
|
|
480
|
-
warmStartImpulseRatio: number
|
|
481
|
-
) {
|
|
482
|
-
// contact constraints have already been initialized
|
|
483
|
-
this.constraintSolver.initVelocityConstraints(deltaTimeSeconds);
|
|
484
|
-
|
|
485
|
-
if (isWarmStartingEnabled) {
|
|
486
|
-
this.constraintSolver.warmStartConstraints(deltaTimeSeconds, warmStartImpulseRatio);
|
|
487
|
-
this.collideBodiesModule.contactConstraintModule.warmStartConstraints();
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
for (let i = 0; i < solveVelocityIterations; i++) {
|
|
491
|
-
this.constraintSolver.solveVelocityConstraintsStep(deltaTimeSeconds);
|
|
492
|
-
this.collideBodiesModule.contactConstraintModule.solveVelocityConstraintsStep();
|
|
493
|
-
}
|
|
494
|
-
|
|
495
|
-
// this.collideBodiesModule.contactConstraintModule.logLambdas();
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
solvePositionConstraintsInterleaved(
|
|
499
|
-
solvePositionIterations: number,
|
|
500
|
-
penetrationSlop: number,
|
|
501
|
-
maxPenetrationDistance: number,
|
|
502
|
-
baumgarte: number,
|
|
503
|
-
deltaTimeSeconds: number
|
|
504
|
-
) {
|
|
505
|
-
for (let i = 0; i < solvePositionIterations; i++) {
|
|
506
|
-
this.constraintSolver.solvePositionConstraintsStep(deltaTimeSeconds);
|
|
507
|
-
this.collideBodiesModule.contactConstraintModule.solvePositionConstraintsStep(
|
|
508
|
-
penetrationSlop,
|
|
509
|
-
maxPenetrationDistance,
|
|
510
|
-
baumgarte
|
|
511
|
-
);
|
|
512
|
-
}
|
|
513
|
-
}
|
|
514
|
-
|
|
515
|
-
updateWorldInverseInertias(bodies: typeof Body.Pool | typeof Body.ReferenceList) {
|
|
516
|
-
// update world inverse inertias
|
|
517
|
-
for (const body of bodies) {
|
|
518
|
-
transformTensor(body.computedWorldInverseInertia, body.computedLocalInverseInertia, body.orientation);
|
|
519
|
-
}
|
|
520
|
-
}
|
|
521
|
-
|
|
522
|
-
updateCachedBodyData(bodies: typeof Body.Pool | typeof Body.ReferenceList) {
|
|
523
|
-
for (const body of bodies) {
|
|
524
|
-
shapeCenterOfMassInWorldSpace.copy(body.shape!.computedCenterOfMass);
|
|
525
|
-
shapeCenterOfMassInWorldSpace.transformByQuat(body.orientation);
|
|
526
|
-
body.position.subtractVectors(body.computedCenterOfMassPosition, shapeCenterOfMassInWorldSpace);
|
|
527
|
-
updateWorldBounds(body);
|
|
528
|
-
}
|
|
529
|
-
}
|
|
530
|
-
|
|
531
|
-
// updateBodyProperties() {
|
|
532
|
-
// for (const body of this.bodies()) {
|
|
533
|
-
// // updateBody(body);
|
|
534
|
-
// }
|
|
535
|
-
// }
|
|
536
|
-
|
|
537
|
-
clearForcesOnBodies() {
|
|
538
|
-
for (const body of this.dynamicBodies) {
|
|
539
|
-
body.clearForces();
|
|
540
|
-
}
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// stepping API
|
|
544
|
-
takeOneStep(timeStepSizeSeconds?: number) {
|
|
545
|
-
// console.log("before step", this.broadphase.dynamicTree.dirtyObjects.size);
|
|
546
|
-
// this.broadphase.updateDirtyBodies();
|
|
547
|
-
timeStepSizeSeconds = timeStepSizeSeconds ?? this.options.timeStepSizeSeconds;
|
|
548
|
-
const warmStartImpulseRatio = timeStepSizeSeconds / this.previousTimeStepSizeSeconds;
|
|
549
|
-
// this.updateCachedBodyData(this.dynamicBodies);
|
|
550
|
-
// this.updateCachedBodyData(this.staticBodies);
|
|
551
|
-
// this.broadphase.updateDirtyBodies();
|
|
552
|
-
this.applyAccelerationIntegration(
|
|
553
|
-
this.dynamicBodies,
|
|
554
|
-
timeStepSizeSeconds,
|
|
555
|
-
this.gravity,
|
|
556
|
-
this.options.isGravityEnabled,
|
|
557
|
-
this.options.linearDamping,
|
|
558
|
-
this.options.angularDamping,
|
|
559
|
-
this.options.maxLinearSpeed,
|
|
560
|
-
this.maxLinearSpeedSquared,
|
|
561
|
-
this.options.maxAngularSpeed,
|
|
562
|
-
this.maxAngularSpeedSquared
|
|
563
|
-
);
|
|
564
|
-
// this.collideBodiesWithoutBroadphase(
|
|
565
|
-
// timeStepSizeSeconds,
|
|
566
|
-
// this.options.isWarmStartingEnabled,
|
|
567
|
-
// this.options.minVelocityForElasticContact
|
|
568
|
-
// );
|
|
569
|
-
this.collideBodiesWithBroadphase(
|
|
570
|
-
timeStepSizeSeconds,
|
|
571
|
-
this.options.isWarmStartingEnabled,
|
|
572
|
-
this.options.minVelocityForElasticContact
|
|
573
|
-
);
|
|
574
|
-
this.solveVelocityConstraintsInterleaved(
|
|
575
|
-
this.options.isWarmStartingEnabled,
|
|
576
|
-
this.options.solveVelocityIterations,
|
|
577
|
-
timeStepSizeSeconds,
|
|
578
|
-
warmStartImpulseRatio
|
|
579
|
-
);
|
|
580
|
-
if (this.options.isWarmStartingEnabled) {
|
|
581
|
-
this.collideBodiesModule.contactConstraintModule.cacheLambdas();
|
|
582
|
-
}
|
|
583
|
-
this.applyVelocityIntegration(this.dynamicBodies, timeStepSizeSeconds);
|
|
584
|
-
this.solvePositionConstraintsInterleaved(
|
|
585
|
-
this.options.solvePositionIterations,
|
|
586
|
-
this.options.penetrationSlop,
|
|
587
|
-
this.options.maxPenetrationDistance,
|
|
588
|
-
this.options.baumgarte,
|
|
589
|
-
timeStepSizeSeconds
|
|
590
|
-
);
|
|
591
|
-
this.updateWorldInverseInertias(this.dynamicBodies);
|
|
592
|
-
this.sleepModule.updateBodySleepStates(this.dynamicBodies, timeStepSizeSeconds);
|
|
593
|
-
this.updateCachedBodyData(this.dynamicBodies);
|
|
594
|
-
this.updateCachedBodyData(this.kinematicBodies);
|
|
595
|
-
this.updateCachedBodyData(this.staticBodies);
|
|
596
|
-
this.clearForcesOnBodies();
|
|
597
|
-
// this.broadphase.updateDirtyBodies();
|
|
598
|
-
// console.log("after step", this.broadphase.dynamicTree.dirtyObjects.size);
|
|
599
|
-
this.step++;
|
|
600
|
-
this.previousTimeStepSizeSeconds = timeStepSizeSeconds;
|
|
601
|
-
}
|
|
602
|
-
|
|
603
|
-
advanceTime(timeStepSizeSeconds?: number, timeToSimulateSeconds?: number) {
|
|
604
|
-
// compute current time
|
|
605
|
-
const nowSeconds = performance.now() / 1000;
|
|
606
|
-
|
|
607
|
-
// compute time step size
|
|
608
|
-
if (!timeStepSizeSeconds) {
|
|
609
|
-
timeStepSizeSeconds = this.options.timeStepSizeSeconds;
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
// compute time to simulate. if first call, we use time step size to start it off
|
|
613
|
-
if (!timeToSimulateSeconds) {
|
|
614
|
-
if (!this.lastAdvanceTimeCall) {
|
|
615
|
-
timeToSimulateSeconds = timeStepSizeSeconds;
|
|
616
|
-
} else {
|
|
617
|
-
timeToSimulateSeconds = nowSeconds - this.lastAdvanceTimeCall;
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
timeToSimulateSeconds = Math.min(timeToSimulateSeconds, this.maxTimeToSimulateSeconds);
|
|
621
|
-
|
|
622
|
-
// take as many steps that fit into the time to simulate
|
|
623
|
-
this.advanceTimeAccumulatedSeconds += timeToSimulateSeconds;
|
|
624
|
-
while (this.advanceTimeAccumulatedSeconds >= timeStepSizeSeconds) {
|
|
625
|
-
this.takeOneStep(timeStepSizeSeconds);
|
|
626
|
-
this.advanceTimeAccumulatedSeconds -= timeStepSizeSeconds;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
// update last advance time call
|
|
630
|
-
this.lastAdvanceTimeCall = this.lastAdvanceTimeCall ?? nowSeconds;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
// shapes API
|
|
634
|
-
createSphere(options: InputType<Sphere>) {
|
|
635
|
-
const shape = Sphere.create(options, this.pools.sphere);
|
|
636
|
-
|
|
637
|
-
const shapeCopy = Sphere.create(options, this.pools.sphereCopy);
|
|
638
|
-
shapeCopy.copy(shape);
|
|
639
|
-
shape.copyForDiff = shapeCopy;
|
|
640
|
-
|
|
641
|
-
shape.world = this;
|
|
642
|
-
return shape;
|
|
643
|
-
}
|
|
644
|
-
|
|
645
|
-
createBox(options: InputType<Box>) {
|
|
646
|
-
const shape = Box.create(options, this.pools.box);
|
|
647
|
-
|
|
648
|
-
const shapeCopy = Box.create(options, this.pools.boxCopy);
|
|
649
|
-
shapeCopy.copy(shape);
|
|
650
|
-
shape.copyForDiff = shapeCopy;
|
|
651
|
-
|
|
652
|
-
shape.world = this;
|
|
653
|
-
return shape;
|
|
654
|
-
}
|
|
655
|
-
|
|
656
|
-
createCylinder(options: InputType<Cylinder>) {
|
|
657
|
-
const shape = Cylinder.create(options, this.pools.cylinder);
|
|
658
|
-
|
|
659
|
-
const shapeCopy = Cylinder.create(options, this.pools.cylinderCopy);
|
|
660
|
-
shapeCopy.copy(shape);
|
|
661
|
-
shape.copyForDiff = shapeCopy;
|
|
662
|
-
|
|
663
|
-
shape.world = this;
|
|
664
|
-
return shape;
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
createCapsule(options: InputType<Capsule>) {
|
|
668
|
-
const shape = Capsule.create(options, this.pools.capsule);
|
|
669
|
-
|
|
670
|
-
const shapeCopy = Capsule.create(options, this.pools.capsuleCopy);
|
|
671
|
-
shapeCopy.copy(shape);
|
|
672
|
-
shape.copyForDiff = shapeCopy;
|
|
673
|
-
|
|
674
|
-
shape.world = this;
|
|
675
|
-
return shape;
|
|
676
|
-
}
|
|
677
|
-
|
|
678
|
-
createTriangleMesh(params: BuildTriangleMeshParams) {
|
|
679
|
-
const shape = this.triangleMeshBuilder.build(
|
|
680
|
-
params,
|
|
681
|
-
this.pools.triangleMesh,
|
|
682
|
-
this.pools.triangleMeshBvhNode,
|
|
683
|
-
this.pools.triangleMeshBvhTree,
|
|
684
|
-
this.pools.triangleMeshVertexPosition,
|
|
685
|
-
this.pools.triangleMeshFaceIndex,
|
|
686
|
-
this.pools.triangleMeshTriangle,
|
|
687
|
-
);
|
|
688
|
-
|
|
689
|
-
const shapeCopy = TriangleMesh.create({
|
|
690
|
-
vertexPositions: { pool: this.pools.triangleMeshVertexPosition },
|
|
691
|
-
faceIndices: { pool: this.pools.triangleMeshFaceIndex },
|
|
692
|
-
triangles: { pool: this.pools.triangleMeshTriangle },
|
|
693
|
-
}, this.pools.triangleMeshCopy);
|
|
694
|
-
shapeCopy.copy(shape);
|
|
695
|
-
shape.copyForDiff = shapeCopy;
|
|
696
|
-
|
|
697
|
-
shape.world = this;
|
|
698
|
-
return shape;
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
createConvexHull(vertices: Float32Array, convexRadius: number = 0.02, hullTolerance: number = 1e-3) {
|
|
702
|
-
const shape = this.convexHullBuilder.buildFromPoints(
|
|
703
|
-
vertices,
|
|
704
|
-
convexRadius,
|
|
705
|
-
hullTolerance,
|
|
706
|
-
this.pools.convexHull,
|
|
707
|
-
this.pools.convexHullFace,
|
|
708
|
-
this.pools.convexHullNumberValue,
|
|
709
|
-
this.pools.convexHullPlane,
|
|
710
|
-
this.pools.convexHullPoint,
|
|
711
|
-
this.pools.convexHullVec3,
|
|
712
|
-
) as WithPool<ConvexHull>;
|
|
713
|
-
|
|
714
|
-
const shapeCopy = ConvexHull.create({
|
|
715
|
-
faces: { pool: this.pools.convexHullFace },
|
|
716
|
-
vertexIdx: { pool: this.pools.convexHullNumberValue },
|
|
717
|
-
planes: { pool: this.pools.convexHullPlane },
|
|
718
|
-
points: { pool: this.pools.convexHullPoint },
|
|
719
|
-
shapeNoConvexPoints: { pool: this.pools.convexHullVec3 },
|
|
720
|
-
}, this.pools.convexHullCopy);
|
|
721
|
-
shapeCopy.copy(shape);
|
|
722
|
-
shape.copyForDiff = shapeCopy;
|
|
723
|
-
|
|
724
|
-
shape.world = this;
|
|
725
|
-
return shape;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
createCompoundShape(
|
|
729
|
-
params: {
|
|
730
|
-
shape: Shape;
|
|
731
|
-
transform: InputType<BasicTransform>;
|
|
732
|
-
}[]
|
|
733
|
-
) {
|
|
734
|
-
|
|
735
|
-
const compoundShape = CompoundShape.create({ shapes: { pool: this.pools.transformedShape } }, this.pools.compoundShape);
|
|
736
|
-
|
|
737
|
-
compoundShape.world = this;
|
|
738
|
-
|
|
739
|
-
for (const param of params) {
|
|
740
|
-
const transformedShape = compoundShape.shapes.create(
|
|
741
|
-
{
|
|
742
|
-
transform: param.transform,
|
|
743
|
-
},
|
|
744
|
-
);
|
|
745
|
-
transformedShape.shape = param.shape;
|
|
746
|
-
}
|
|
747
|
-
|
|
748
|
-
compoundShape.update();
|
|
749
|
-
|
|
750
|
-
const compoundShapeCopy = CompoundShape.create({ shapes: { pool: this.pools.transformedShape } }, this.pools.compoundShapeCopy);
|
|
751
|
-
compoundShapeCopy.copy(compoundShape);
|
|
752
|
-
compoundShape.copyForDiff = compoundShapeCopy;
|
|
753
|
-
compoundShapeCopy.update();
|
|
754
|
-
|
|
755
|
-
return compoundShape;
|
|
756
|
-
}
|
|
757
|
-
|
|
758
|
-
/**
|
|
759
|
-
* Creates a height map shape from the given resolution, extents, and heights.
|
|
760
|
-
* @param resolution - The number of vertices in each dimension of the height map.
|
|
761
|
-
* @param extents - The width, height, and depth of the height map in meters.
|
|
762
|
-
* @param heights - A flat array of heights for each vertex in the height map. normalized to the range [0, 1]
|
|
763
|
-
*/
|
|
764
|
-
createHeightMap(
|
|
765
|
-
vertexCount: { width: number; depth: number },
|
|
766
|
-
extents: InputType<Vec3>,
|
|
767
|
-
heights: Float32Array | Float64Array | number[]
|
|
768
|
-
) {
|
|
769
|
-
const shape = this.heightMapBuilder.buildHeightMap(vertexCount, extents, heights, this.pools.heightMap);
|
|
770
|
-
|
|
771
|
-
// TODO: should we implement copyForDiff for heightmap?
|
|
772
|
-
// const shapeCopy = this.heightMapBuilder.buildHeightMap(subdivisionsCount, scale, positionOffset, heights);
|
|
773
|
-
// shapeCopy.copy(shape);
|
|
774
|
-
// shape.copyForDiff = shapeCopy;
|
|
775
|
-
|
|
776
|
-
shape.world = this;
|
|
777
|
-
return shape;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
*bodies() {
|
|
781
|
-
yield* this.dynamicBodies;
|
|
782
|
-
yield* this.kinematicBodies;
|
|
783
|
-
yield* this.staticBodies;
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
destroyShape(shape: Shape) {
|
|
787
|
-
for (const body of this.bodies()) {
|
|
788
|
-
if (body.shape === shape) {
|
|
789
|
-
body.destroy();
|
|
790
|
-
}
|
|
791
|
-
}
|
|
792
|
-
|
|
793
|
-
const shapeCopy = shape.copyForDiff;
|
|
794
|
-
if (shapeCopy) {
|
|
795
|
-
shapeCopy.destroy();
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
shape.destroy();
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
// bodies API
|
|
802
|
-
createStaticBody(options: InputType<Body> & { shape: StaticShape }): Body {
|
|
803
|
-
options = options ?? {};
|
|
804
|
-
options.type = BodyType.static;
|
|
805
|
-
const body = this.staticBodies.create(options);
|
|
806
|
-
|
|
807
|
-
const bodyCopy = this.staticBodyCopies.create(options);
|
|
808
|
-
bodyCopy.copy(body);
|
|
809
|
-
body.copyForDiff = bodyCopy;
|
|
810
|
-
|
|
811
|
-
body.world = this;
|
|
812
|
-
|
|
813
|
-
this.broadphase.addStaticBody(body);
|
|
814
|
-
return body;
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
createDynamicBody(options: InputType<Body> & { shape: DynamicShape }): Body {
|
|
818
|
-
options = options ?? {};
|
|
819
|
-
options.type = BodyType.dynamic;
|
|
820
|
-
const body = this.dynamicBodies.create(options);
|
|
821
|
-
|
|
822
|
-
const bodyCopy = this.dynamicBodyCopies.create(options);
|
|
823
|
-
bodyCopy.copy(body);
|
|
824
|
-
body.copyForDiff = bodyCopy;
|
|
825
|
-
|
|
826
|
-
body.world = this;
|
|
827
|
-
|
|
828
|
-
this.broadphase.addDynamicBody(body);
|
|
829
|
-
return body;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
createKinematicBody(options: InputType<Body> & { shape: KinematicShape }): Body {
|
|
833
|
-
options = options ?? {};
|
|
834
|
-
options.type = BodyType.kinematic;
|
|
835
|
-
const body = this.kinematicBodies.create(options);
|
|
836
|
-
|
|
837
|
-
const bodyCopy = this.kinematicBodyCopies.create(options);
|
|
838
|
-
bodyCopy.copy(body);
|
|
839
|
-
body.copyForDiff = bodyCopy;
|
|
840
|
-
|
|
841
|
-
body.world = this;
|
|
842
|
-
|
|
843
|
-
this.broadphase.addKinematicBody(body);
|
|
844
|
-
return body;
|
|
845
|
-
}
|
|
846
|
-
|
|
847
|
-
createBody(
|
|
848
|
-
options: InputType<Body> &
|
|
849
|
-
(
|
|
850
|
-
| { type: BodyType.dynamic; shape: DynamicShape }
|
|
851
|
-
| { type: BodyType.static; shape: StaticShape }
|
|
852
|
-
| { type: BodyType.kinematic; shape: KinematicShape }
|
|
853
|
-
)
|
|
854
|
-
) {
|
|
855
|
-
switch (options.type) {
|
|
856
|
-
case BodyType.dynamic: {
|
|
857
|
-
return this.createDynamicBody(options);
|
|
858
|
-
}
|
|
859
|
-
|
|
860
|
-
case BodyType.static: {
|
|
861
|
-
return this.createStaticBody(options);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
case BodyType.kinematic: {
|
|
865
|
-
return this.createKinematicBody(options);
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
default: {
|
|
869
|
-
throw new Error(`Unknown options: ${options}`);
|
|
870
|
-
}
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
destroyBody(body: Body) {
|
|
875
|
-
const bodyCopy = body.copyForDiff;
|
|
876
|
-
if (bodyCopy) {
|
|
877
|
-
bodyCopy.destroy();
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
switch (body.type) {
|
|
881
|
-
case BodyType.dynamic: {
|
|
882
|
-
this.broadphase.removeDynamicBody(body as WithPool<Body>);
|
|
883
|
-
break;
|
|
884
|
-
}
|
|
885
|
-
|
|
886
|
-
case BodyType.static: {
|
|
887
|
-
this.broadphase.removeStaticBody(body as WithPool<Body>);
|
|
888
|
-
break;
|
|
889
|
-
}
|
|
890
|
-
|
|
891
|
-
case BodyType.kinematic: {
|
|
892
|
-
this.broadphase.removeKinematicBody(body as WithPool<Body>);
|
|
893
|
-
break;
|
|
894
|
-
}
|
|
895
|
-
|
|
896
|
-
default: {
|
|
897
|
-
throw new Error("Unknown body type.");
|
|
898
|
-
}
|
|
899
|
-
}
|
|
900
|
-
|
|
901
|
-
this.constraintSolver.constraintPairs.destroyAllPairsOfOne(body);
|
|
902
|
-
|
|
903
|
-
body.node = null;
|
|
904
|
-
body.destroy();
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
// contacts API
|
|
908
|
-
didBodiesCollide(bodyA: Body, bodyB: Body) {
|
|
909
|
-
const cache = this.collideBodiesModule.contactManifoldModule.currentManifoldCache;
|
|
910
|
-
const key = createContactPairKey(bodyA, bodyB);
|
|
911
|
-
return cache.pairMap.has(key);
|
|
912
|
-
}
|
|
913
|
-
|
|
914
|
-
*iterateContactManifolds(bodyA?: Body, bodyB?: Body) {
|
|
915
|
-
const cache = this.collideBodiesModule.contactManifoldModule.currentManifoldCache;
|
|
916
|
-
|
|
917
|
-
if (!bodyA && !bodyB) {
|
|
918
|
-
for (const manifold of cache.manifolds.contactManifoldPool) {
|
|
919
|
-
yield manifold;
|
|
920
|
-
}
|
|
921
|
-
} else if (bodyA && !bodyB) {
|
|
922
|
-
for (const manifold of cache.manifolds.contactManifoldPool) {
|
|
923
|
-
if (manifold.containsBody(bodyA)) {
|
|
924
|
-
yield manifold;
|
|
925
|
-
}
|
|
926
|
-
}
|
|
927
|
-
} else if (!bodyA && bodyB) {
|
|
928
|
-
for (const manifold of cache.manifolds.contactManifoldPool) {
|
|
929
|
-
if (manifold.containsBody(bodyB)) {
|
|
930
|
-
yield manifold;
|
|
931
|
-
}
|
|
932
|
-
}
|
|
933
|
-
} else {
|
|
934
|
-
const key = createContactPairKey(bodyA!, bodyB!);
|
|
935
|
-
const pair = cache.pairMap.get(key);
|
|
936
|
-
if (!pair) {
|
|
937
|
-
return;
|
|
938
|
-
}
|
|
939
|
-
|
|
940
|
-
let manifold = pair.firstContactManifold;
|
|
941
|
-
while (manifold) {
|
|
942
|
-
yield manifold;
|
|
943
|
-
manifold = manifold.nextContactManifold as WithPool<ContactManifold> | null;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
}
|
|
947
|
-
|
|
948
|
-
// scene query API
|
|
949
|
-
intersectShape(
|
|
950
|
-
onHit: (result: CollisionResult) => boolean,
|
|
951
|
-
shape: Shape,
|
|
952
|
-
transform: BasicTransform,
|
|
953
|
-
settings?: ShapeIntersectSettings
|
|
954
|
-
) {
|
|
955
|
-
settings = settings || { precision: QueryPrecision.preciseWithContacts, returnClosestOnly: true };
|
|
956
|
-
isometry.fromRotationAndTranslation(transform.rotation, transform.position);
|
|
957
|
-
intersectShapeCollector.initialize(onHit);
|
|
958
|
-
this.collideBodiesModule.collideShape(
|
|
959
|
-
shape,
|
|
960
|
-
1.0,
|
|
961
|
-
isometry,
|
|
962
|
-
intersectShapeCollector,
|
|
963
|
-
collideShapeSettings,
|
|
964
|
-
zeroVector,
|
|
965
|
-
AllFlag
|
|
966
|
-
);
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
castRay(onHit: (result: CastRayResult) => boolean, ray: Ray, settings?: RayCastSettings) {
|
|
970
|
-
settings = settings || { precision: QueryPrecision.preciseWithContacts, returnClosestOnly: true };
|
|
971
|
-
this.collideBodiesModule.castRay(onHit, ray, settings, AllFlag, AllFlag);
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
castShape(
|
|
975
|
-
onHit: (result: CastShapeResult) => boolean,
|
|
976
|
-
shape: Shape,
|
|
977
|
-
transform: BasicTransform,
|
|
978
|
-
displacementOrEndPosition: Vec3,
|
|
979
|
-
settings?: ShapeCastSettings
|
|
980
|
-
) {
|
|
981
|
-
isometry.fromRotationAndTranslation(transform.rotation, transform.position);
|
|
982
|
-
settings = settings || {
|
|
983
|
-
precision: QueryPrecision.preciseWithContacts,
|
|
984
|
-
returnClosestOnly: false,
|
|
985
|
-
treatAsDisplacement: false,
|
|
986
|
-
};
|
|
987
|
-
if (settings.treatAsDisplacement) {
|
|
988
|
-
displacement.copy(displacementOrEndPosition);
|
|
989
|
-
} else {
|
|
990
|
-
displacement.zero();
|
|
991
|
-
displacement.subtractVectors(displacementOrEndPosition, transform.position);
|
|
992
|
-
}
|
|
993
|
-
castShapeCollector.initialize(onHit);
|
|
994
|
-
this.collideBodiesModule.castShape(
|
|
995
|
-
shape,
|
|
996
|
-
1.0,
|
|
997
|
-
isometry,
|
|
998
|
-
displacement,
|
|
999
|
-
castSettings,
|
|
1000
|
-
zeroVector,
|
|
1001
|
-
castShapeCollector,
|
|
1002
|
-
AllFlag
|
|
1003
|
-
);
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
estimateCollisionResponse(
|
|
1007
|
-
result: EstimateCollisionResponseResult,
|
|
1008
|
-
bodyA: Body,
|
|
1009
|
-
bodyB: Body,
|
|
1010
|
-
settings?: Partial<EstimateCollisionResponseSettings>
|
|
1011
|
-
) {
|
|
1012
|
-
const timeStepSizeSeconds = settings?.timeStepSizeSeconds ?? this.options.timeStepSizeSeconds;
|
|
1013
|
-
this.collideBodiesModule.estimateCollisionResponse(result, bodyA, bodyB, timeStepSizeSeconds);
|
|
1014
|
-
}
|
|
1015
|
-
|
|
1016
|
-
// serialization API
|
|
1017
|
-
toArray(array: number[] | Float32Array | Float64Array, startOffset = 0): number {
|
|
1018
|
-
// order needs to match fromArray!
|
|
1019
|
-
|
|
1020
|
-
// shapes
|
|
1021
|
-
startOffset = this.pools.boxCopy.toArray(array, startOffset);
|
|
1022
|
-
startOffset = this.pools.box.toArray(array, startOffset);
|
|
1023
|
-
|
|
1024
|
-
startOffset = this.pools.capsuleCopy.toArray(array, startOffset);
|
|
1025
|
-
startOffset = this.pools.capsule.toArray(array, startOffset);
|
|
1026
|
-
|
|
1027
|
-
startOffset = this.pools.cylinderCopy.toArray(array, startOffset);
|
|
1028
|
-
startOffset = this.pools.cylinder.toArray(array, startOffset);
|
|
1029
|
-
|
|
1030
|
-
startOffset = this.pools.sphereCopy.toArray(array, startOffset);
|
|
1031
|
-
startOffset = this.pools.sphere.toArray(array, startOffset);
|
|
1032
|
-
|
|
1033
|
-
startOffset = this.pools.convexHullFace.toArray(array, startOffset);
|
|
1034
|
-
startOffset = this.pools.convexHullNumberValue.toArray(array, startOffset);
|
|
1035
|
-
startOffset = this.pools.convexHullPlane.toArray(array, startOffset);
|
|
1036
|
-
startOffset = this.pools.convexHullPoint.toArray(array, startOffset);
|
|
1037
|
-
startOffset = this.pools.convexHullVec3.toArray(array, startOffset);
|
|
1038
|
-
startOffset = this.pools.convexHullCopy.toArray(array, startOffset);
|
|
1039
|
-
startOffset = this.pools.convexHull.toArray(array, startOffset);
|
|
1040
|
-
|
|
1041
|
-
startOffset = this.pools.triangleMeshBvhNode.toArray(array, startOffset);
|
|
1042
|
-
startOffset = this.pools.triangleMeshBvhTree.toArray(array, startOffset);
|
|
1043
|
-
startOffset = this.pools.triangleMeshVertexPosition.toArray(array, startOffset);
|
|
1044
|
-
startOffset = this.pools.triangleMeshFaceIndex.toArray(array, startOffset);
|
|
1045
|
-
startOffset = this.pools.triangleMeshTriangle.toArray(array, startOffset);
|
|
1046
|
-
startOffset = this.pools.triangleMeshCopy.toArray(array, startOffset);
|
|
1047
|
-
startOffset = this.pools.triangleMesh.toArray(array, startOffset);
|
|
1048
|
-
|
|
1049
|
-
startOffset = this.pools.heightMapCopy.toArray(array, startOffset);
|
|
1050
|
-
startOffset = this.pools.heightMap.toArray(array, startOffset);
|
|
1051
|
-
|
|
1052
|
-
startOffset = this.pools.transformedShape.toArray(array, startOffset);
|
|
1053
|
-
startOffset = this.pools.compoundShapeCopy.toArray(array, startOffset);
|
|
1054
|
-
startOffset = this.pools.compoundShape.toArray(array, startOffset);
|
|
1055
|
-
|
|
1056
|
-
// bodies
|
|
1057
|
-
startOffset = this.pools.bodyCopy.toArray(array, startOffset);
|
|
1058
|
-
startOffset = this.pools.body.toArray(array, startOffset);
|
|
1059
|
-
|
|
1060
|
-
// constraints
|
|
1061
|
-
startOffset = this.pools.constraintPairNode.toArray(array, startOffset);
|
|
1062
|
-
startOffset = this.pools.constraintPairEdge.toArray(array, startOffset);
|
|
1063
|
-
|
|
1064
|
-
startOffset = this.constraintSolver.distanceConstraints.toArray(array, startOffset);
|
|
1065
|
-
startOffset = this.constraintSolver.fixedConstraints.toArray(array, startOffset);
|
|
1066
|
-
startOffset = this.constraintSolver.hingeConstraints.toArray(array, startOffset);
|
|
1067
|
-
startOffset = this.constraintSolver.pointConstraints.toArray(array, startOffset);
|
|
1068
|
-
|
|
1069
|
-
// bvh
|
|
1070
|
-
startOffset = this.broadphase.toArray(array, startOffset);
|
|
1071
|
-
|
|
1072
|
-
// contact manifold cache
|
|
1073
|
-
startOffset = this.collideBodiesModule.contactManifoldModule.toArray(array, startOffset);
|
|
1074
|
-
|
|
1075
|
-
return startOffset;
|
|
1076
|
-
}
|
|
1077
|
-
|
|
1078
|
-
fromArray(array: number[] | Float32Array | Float64Array, startOffset = 0): number {
|
|
1079
|
-
startOffset = this.pools.boxCopy.fromArray(array, { copyForDiff: null! }, startOffset);
|
|
1080
|
-
startOffset = this.pools.box.fromArray(array, { copyForDiff: this.pools.boxCopy }, startOffset);
|
|
1081
|
-
|
|
1082
|
-
startOffset = this.pools.capsuleCopy.fromArray(array, { copyForDiff: null! }, startOffset);
|
|
1083
|
-
startOffset = this.pools.capsule.fromArray(array, { copyForDiff: this.pools.capsuleCopy }, startOffset);
|
|
1084
|
-
|
|
1085
|
-
startOffset = this.pools.cylinderCopy.fromArray(array, { copyForDiff: null! }, startOffset);
|
|
1086
|
-
startOffset = this.pools.cylinder.fromArray(array, { copyForDiff: this.pools.cylinderCopy }, startOffset);
|
|
1087
|
-
|
|
1088
|
-
startOffset = this.pools.sphereCopy.fromArray(array, { copyForDiff: null! }, startOffset);
|
|
1089
|
-
startOffset = this.pools.sphere.fromArray(array, { copyForDiff: this.pools.sphereCopy }, startOffset);
|
|
1090
|
-
|
|
1091
|
-
startOffset = this.pools.convexHullFace.fromArray(array, startOffset);
|
|
1092
|
-
startOffset = this.pools.convexHullNumberValue.fromArray(array, startOffset);
|
|
1093
|
-
startOffset = this.pools.convexHullPlane.fromArray(array, startOffset);
|
|
1094
|
-
startOffset = this.pools.convexHullPoint.fromArray(array, startOffset);
|
|
1095
|
-
startOffset = this.pools.convexHullVec3.fromArray(array, startOffset);
|
|
1096
|
-
startOffset = this.pools.convexHullCopy.fromArray(array, {
|
|
1097
|
-
copyForDiff: null!,
|
|
1098
|
-
faces: this.pools.convexHullFace,
|
|
1099
|
-
planes: this.pools.convexHullPlane,
|
|
1100
|
-
points: this.pools.convexHullPoint,
|
|
1101
|
-
shapeNoConvexPoints: this.pools.convexHullVec3,
|
|
1102
|
-
vertexIdx: this.pools.convexHullNumberValue,
|
|
1103
|
-
}, startOffset);
|
|
1104
|
-
startOffset = this.pools.convexHull.fromArray(array, {
|
|
1105
|
-
copyForDiff: this.pools.convexHullCopy,
|
|
1106
|
-
faces: this.pools.convexHullFace,
|
|
1107
|
-
planes: this.pools.convexHullPlane,
|
|
1108
|
-
points: this.pools.convexHullPoint,
|
|
1109
|
-
shapeNoConvexPoints: this.pools.convexHullVec3,
|
|
1110
|
-
vertexIdx: this.pools.convexHullNumberValue
|
|
1111
|
-
}, startOffset);
|
|
1112
|
-
|
|
1113
|
-
startOffset = this.pools.triangleMeshBvhNode.fromArray(array, {
|
|
1114
|
-
left: this.pools.triangleMeshBvhNode,
|
|
1115
|
-
right: this.pools.triangleMeshBvhNode,
|
|
1116
|
-
parent: this.pools.triangleMeshBvhNode,
|
|
1117
|
-
objects: this.pools.triangleMeshTriangle,
|
|
1118
|
-
}, startOffset);
|
|
1119
|
-
startOffset = this.pools.triangleMeshBvhTree.fromArray(array, {
|
|
1120
|
-
nodes: this.pools.triangleMeshBvhNode,
|
|
1121
|
-
}, startOffset);
|
|
1122
|
-
startOffset = this.pools.triangleMeshVertexPosition.fromArray(array, startOffset);
|
|
1123
|
-
startOffset = this.pools.triangleMeshFaceIndex.fromArray(array, startOffset);
|
|
1124
|
-
startOffset = this.pools.triangleMeshTriangle.fromArray(array, startOffset);
|
|
1125
|
-
startOffset = this.pools.triangleMeshCopy.fromArray(array, {
|
|
1126
|
-
copyForDiff: null!,
|
|
1127
|
-
bvh: this.pools.triangleMeshBvhTree,
|
|
1128
|
-
vertexPositions: this.pools.triangleMeshVertexPosition,
|
|
1129
|
-
faceIndices: this.pools.triangleMeshFaceIndex,
|
|
1130
|
-
triangles: this.pools.triangleMeshTriangle,
|
|
1131
|
-
}, startOffset);
|
|
1132
|
-
startOffset = this.pools.triangleMesh.fromArray(array, {
|
|
1133
|
-
copyForDiff: this.pools.triangleMeshCopy,
|
|
1134
|
-
bvh: this.pools.triangleMeshBvhTree,
|
|
1135
|
-
vertexPositions: this.pools.triangleMeshVertexPosition,
|
|
1136
|
-
faceIndices: this.pools.triangleMeshFaceIndex,
|
|
1137
|
-
triangles: this.pools.triangleMeshTriangle,
|
|
1138
|
-
}, startOffset);
|
|
1139
|
-
|
|
1140
|
-
startOffset = this.pools.heightMapCopy.fromArray(array, { copyForDiff: null! }, startOffset);
|
|
1141
|
-
startOffset = this.pools.heightMap.fromArray(array, { copyForDiff: this.pools.heightMapCopy }, startOffset);
|
|
1142
|
-
|
|
1143
|
-
startOffset = this.pools.transformedShape.fromArray(array, {
|
|
1144
|
-
shape0: this.pools.box,
|
|
1145
|
-
shape1: this.pools.capsule,
|
|
1146
|
-
shape3: this.pools.convexHull,
|
|
1147
|
-
shape4: this.pools.cylinder,
|
|
1148
|
-
shape6: this.pools.sphere,
|
|
1149
|
-
}, startOffset);
|
|
1150
|
-
startOffset = this.pools.compoundShapeCopy.fromArray(
|
|
1151
|
-
array,
|
|
1152
|
-
{
|
|
1153
|
-
copyForDiff: null!,
|
|
1154
|
-
shapes: this.pools.transformedShape,
|
|
1155
|
-
},
|
|
1156
|
-
startOffset,
|
|
1157
|
-
);
|
|
1158
|
-
startOffset = this.pools.compoundShape.fromArray(
|
|
1159
|
-
array,
|
|
1160
|
-
{
|
|
1161
|
-
copyForDiff: this.pools.compoundShapeCopy,
|
|
1162
|
-
shapes: this.pools.transformedShape,
|
|
1163
|
-
},
|
|
1164
|
-
startOffset,
|
|
1165
|
-
);
|
|
1166
|
-
|
|
1167
|
-
let startOffsetConstraintPairNode, startOffsetBody, startOffsetBodyCopy, startOffsetBodyPairNode;
|
|
1168
|
-
|
|
1169
|
-
startOffsetBodyCopy = startOffset;
|
|
1170
|
-
startOffset = this.pools.bodyCopy.fromArrayNoReferences(array, startOffset);
|
|
1171
|
-
startOffsetBody = startOffset;
|
|
1172
|
-
startOffset = this.pools.body.fromArrayNoReferences(array, startOffset);
|
|
1173
|
-
|
|
1174
|
-
startOffsetConstraintPairNode = startOffset;
|
|
1175
|
-
startOffset = this.pools.constraintPairNode.fromArrayNoReferences(array, startOffset);
|
|
1176
|
-
this.pools.constraintPairEdge.fromArrayNoReferences(array, startOffset);
|
|
1177
|
-
startOffset = this.pools.constraintPairEdge.fromArrayOnlyReferences(array, {
|
|
1178
|
-
node: this.pools.constraintPairNode,
|
|
1179
|
-
next: this.pools.constraintPairEdge,
|
|
1180
|
-
prev: this.pools.constraintPairEdge,
|
|
1181
|
-
}, startOffset);
|
|
1182
|
-
|
|
1183
|
-
startOffset = this.constraintSolver.distanceConstraints.fromArray(array, {
|
|
1184
|
-
bodyA: this.pools.body,
|
|
1185
|
-
bodyB: this.pools.body,
|
|
1186
|
-
constraintPairNode: this.pools.constraintPairNode,
|
|
1187
|
-
}, startOffset);
|
|
1188
|
-
startOffset = this.constraintSolver.fixedConstraints.fromArray(array, {
|
|
1189
|
-
bodyA: this.pools.body,
|
|
1190
|
-
bodyB: this.pools.body,
|
|
1191
|
-
constraintPairNode: this.pools.constraintPairNode,
|
|
1192
|
-
}, startOffset);
|
|
1193
|
-
startOffset = this.constraintSolver.hingeConstraints.fromArray(array, {
|
|
1194
|
-
bodyA: this.pools.body,
|
|
1195
|
-
bodyB: this.pools.body,
|
|
1196
|
-
constraintPairNode: this.pools.constraintPairNode,
|
|
1197
|
-
}, startOffset);
|
|
1198
|
-
startOffset = this.constraintSolver.pointConstraints.fromArray(array, {
|
|
1199
|
-
bodyA: this.pools.body,
|
|
1200
|
-
bodyB: this.pools.body,
|
|
1201
|
-
constraintPairNode: this.pools.constraintPairNode,
|
|
1202
|
-
}, startOffset);
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
startOffset = this.broadphase.fromArray(array, startOffset);
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
this.pools.constraintPairNode.fromArrayOnlyReferences(array, {
|
|
1209
|
-
bodyA: this.pools.body,
|
|
1210
|
-
bodyB: this.pools.body,
|
|
1211
|
-
edgeA: this.pools.constraintPairEdge,
|
|
1212
|
-
edgeB: this.pools.constraintPairEdge,
|
|
1213
|
-
constraintDistance: this.constraintSolver.distanceConstraints,
|
|
1214
|
-
constraintFixed: this.constraintSolver.fixedConstraints,
|
|
1215
|
-
constraintHinge: this.constraintSolver.hingeConstraints,
|
|
1216
|
-
constraintPoint: this.constraintSolver.pointConstraints,
|
|
1217
|
-
}, startOffsetConstraintPairNode);
|
|
1218
|
-
|
|
1219
|
-
this.pools.bodyCopy.fromArrayOnlyReferences(array, {
|
|
1220
|
-
copyForDiff: null!,
|
|
1221
|
-
firstPotentialConstraintPairEdge: this.pools.constraintPairEdge,
|
|
1222
|
-
node: this.pools.bvhNodes,
|
|
1223
|
-
firstPotentialPairEdge: this.pools.bodyPairEdge,
|
|
1224
|
-
['shape' + ShapeType.box as 'shape0']: this.pools.box,
|
|
1225
|
-
['shape' + ShapeType.capsule as 'shape1']: this.pools.capsule,
|
|
1226
|
-
['shape' + ShapeType.compoundShape as 'shape2']: this.pools.compoundShape,
|
|
1227
|
-
['shape' + ShapeType.convexHull as 'shape3']: this.pools.convexHull,
|
|
1228
|
-
['shape' + ShapeType.cylinder as 'shape4']: this.pools.cylinder,
|
|
1229
|
-
['shape' + ShapeType.heightMap as 'shape5']: this.pools.heightMap,
|
|
1230
|
-
['shape' + ShapeType.sphere as 'shape6']: this.pools.sphere,
|
|
1231
|
-
['shape' + ShapeType.triangleMesh as 'shape7']: this.pools.triangleMesh,
|
|
1232
|
-
}, startOffsetBodyCopy);
|
|
1233
|
-
|
|
1234
|
-
this.pools.body.fromArrayOnlyReferences(array, {
|
|
1235
|
-
copyForDiff: this.pools.bodyCopy,
|
|
1236
|
-
firstPotentialConstraintPairEdge: this.pools.constraintPairEdge,
|
|
1237
|
-
node: this.pools.bvhNodes,
|
|
1238
|
-
firstPotentialPairEdge: this.pools.bodyPairEdge,
|
|
1239
|
-
['shape' + ShapeType.box as 'shape0']: this.pools.box,
|
|
1240
|
-
['shape' + ShapeType.capsule as 'shape1']: this.pools.capsule,
|
|
1241
|
-
['shape' + ShapeType.compoundShape as 'shape2']: this.pools.compoundShape,
|
|
1242
|
-
['shape' + ShapeType.convexHull as 'shape3']: this.pools.convexHull,
|
|
1243
|
-
['shape' + ShapeType.cylinder as 'shape4']: this.pools.cylinder,
|
|
1244
|
-
['shape' + ShapeType.heightMap as 'shape5']: this.pools.heightMap,
|
|
1245
|
-
['shape' + ShapeType.sphere as 'shape6']: this.pools.sphere,
|
|
1246
|
-
['shape' + ShapeType.triangleMesh as 'shape7']: this.pools.triangleMesh,
|
|
1247
|
-
}, startOffsetBody);
|
|
1248
|
-
|
|
1249
|
-
startOffset = this.collideBodiesModule.contactManifoldModule.fromArray(array, {
|
|
1250
|
-
body: this.pools.body,
|
|
1251
|
-
}, startOffset);
|
|
1252
|
-
|
|
1253
|
-
return startOffset;
|
|
1254
|
-
}
|
|
1255
|
-
|
|
1256
|
-
// constraints
|
|
1257
|
-
createPointConstraint(params: InputType<PointConstraint>) {
|
|
1258
|
-
return this.constraintSolver.createPointConstraint(params);
|
|
1259
|
-
}
|
|
1260
|
-
|
|
1261
|
-
createFixedConstraint(params: InputType<FixedConstraint>) {
|
|
1262
|
-
return this.constraintSolver.createFixedConstraint(params);
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
createDistanceConstraint(params: InputType<DistanceConstraint>) {
|
|
1266
|
-
return this.constraintSolver.createDistanceConstraint(params);
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
createHingeConstraint(params: InputType<HingeConstraint>) {
|
|
1270
|
-
return this.constraintSolver.createHingeConstraint(params);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
destroyConstraint(constraint: Constraint) {
|
|
1274
|
-
this.constraintSolver.destroyConstraint(constraint);
|
|
1275
|
-
}
|
|
1276
|
-
}
|
|
1277
|
-
|
|
1278
|
-
const isometry = /*@__PURE__*/ Isometry.create();
|
|
1279
|
-
const collideShapeSettings: CollisionSettings = {
|
|
1280
|
-
activeEdgeMode: ActiveEdgeMode.CollideWithAll,
|
|
1281
|
-
activeEdgeMovementDirectionX: 0,
|
|
1282
|
-
activeEdgeMovementDirectionY: 0,
|
|
1283
|
-
activeEdgeMovementDirectionZ: 0,
|
|
1284
|
-
backFaceMode: BackFaceMode.IgnoreBackFaces,
|
|
1285
|
-
collectFacesMode: CollectFacesMode.NoFaces,
|
|
1286
|
-
collisionTolerance: 1e-4,
|
|
1287
|
-
maxSeparation: 0.02,
|
|
1288
|
-
penetrationTolerance: 1e-4,
|
|
1289
|
-
};
|
|
1290
|
-
const zeroVector = /*@__PURE__*/ Vec3.create();
|
|
1291
|
-
|
|
1292
|
-
interface ShapeIntersectSettings {
|
|
1293
|
-
precision?: QueryPrecision;
|
|
1294
|
-
returnClosestOnly?: boolean;
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
interface ShapeCastSettings {
|
|
1298
|
-
precision?: QueryPrecision;
|
|
1299
|
-
returnClosestOnly?: boolean;
|
|
1300
|
-
treatAsDisplacement?: boolean;
|
|
1301
|
-
}
|
|
1302
|
-
|
|
1303
|
-
interface EstimateCollisionResponseSettings {
|
|
1304
|
-
timeStepSizeSeconds: number;
|
|
1305
|
-
}
|
|
1306
|
-
|
|
1307
|
-
interface CastShapeResult {}
|
|
1308
|
-
|
|
1309
|
-
class IntersectShapeCollector extends CollisionCollector {
|
|
1310
|
-
onHit: ((result: CollisionResult) => boolean) | null = null;
|
|
1311
|
-
|
|
1312
|
-
initialize(onHit: (result: CollisionResult) => boolean) {
|
|
1313
|
-
this.onHit = onHit;
|
|
1314
|
-
}
|
|
1315
|
-
|
|
1316
|
-
addHit(result: CollisionResult): void {
|
|
1317
|
-
this.onHit?.(result);
|
|
1318
|
-
}
|
|
1319
|
-
}
|
|
1320
|
-
const intersectShapeCollector = /*@__PURE__*/ new IntersectShapeCollector();
|
|
1321
|
-
const displacement = /*@__PURE__*/ Vec3.create();
|
|
1322
|
-
const castSettings = /*@__PURE__*/ createDefaultCastSettings();
|
|
1323
|
-
|
|
1324
|
-
class CastShapeCollector extends CastCollector {
|
|
1325
|
-
onHit: ((result: CastShapeResult) => boolean) | null = null;
|
|
1326
|
-
|
|
1327
|
-
initialize(onHit: (result: CastShapeResult) => boolean) {
|
|
1328
|
-
this.onHit = onHit;
|
|
1329
|
-
}
|
|
1330
|
-
|
|
1331
|
-
addHit(result: CastShapeResult): void {
|
|
1332
|
-
this.onHit?.(result);
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
const castShapeCollector = /*@__PURE__*/ new CastShapeCollector();
|