@galacean/engine-physics-physx 0.0.0-experimental-backup.0 → 0.0.0-experimental-2.0-game

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.
@@ -0,0 +1,1966 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.PhysicsPhysX = {}), global.Galacean));
5
+ })(this, (function (exports, engine) { 'use strict';
6
+
7
+ function _instanceof(left, right) {
8
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
9
+ return !!right[Symbol.hasInstance](left);
10
+ } else return left instanceof right;
11
+ }
12
+
13
+ function _set_prototype_of(o, p) {
14
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
15
+ o.__proto__ = p;
16
+
17
+ return o;
18
+ };
19
+
20
+ return _set_prototype_of(o, p);
21
+ }
22
+
23
+ function _inherits(subClass, superClass) {
24
+ if (typeof superClass !== "function" && superClass !== null) {
25
+ throw new TypeError("Super expression must either be null or a function");
26
+ }
27
+
28
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
29
+
30
+ if (superClass) _set_prototype_of(subClass, superClass);
31
+ }
32
+
33
+ /**
34
+ * Flags which affect the behavior of Shapes.
35
+ */ var ShapeFlag = /*#__PURE__*/ function(ShapeFlag) {
36
+ /** The shape will partake in collision in the physical simulation. */ ShapeFlag[ShapeFlag["SIMULATION_SHAPE"] = 1] = "SIMULATION_SHAPE";
37
+ /** The shape will partake in scene queries (ray casts, overlap tests, sweeps, ...). */ ShapeFlag[ShapeFlag["SCENE_QUERY_SHAPE"] = 2] = "SCENE_QUERY_SHAPE";
38
+ /** The shape is a trigger which can send reports whenever other shapes enter/leave its volume. */ ShapeFlag[ShapeFlag["TRIGGER_SHAPE"] = 4] = "TRIGGER_SHAPE";
39
+ return ShapeFlag;
40
+ }({});
41
+ /**
42
+ * Abstract class for collider shapes.
43
+ */ var PhysXColliderShape = /*#__PURE__*/ function() {
44
+ function PhysXColliderShape(physXPhysics) {
45
+ /** @internal */ this._controllers = new engine.DisorderedArray();
46
+ /** @internal */ this._contractOffset = 0.02;
47
+ /** @internal */ this._worldScale = new engine.Vector3(1, 1, 1);
48
+ /** @internal */ this._position = new engine.Vector3();
49
+ /** @internal */ this._rotation = new engine.Vector3();
50
+ this._axis = null;
51
+ this._physXRotation = new engine.Quaternion();
52
+ this._shapeFlags = 2 | 1;
53
+ this._physXPhysics = physXPhysics;
54
+ }
55
+ var _proto = PhysXColliderShape.prototype;
56
+ /**
57
+ * {@inheritDoc IColliderShape.setRotation }
58
+ */ _proto.setRotation = function setRotation(value) {
59
+ var rotation = this._rotation.set(engine.MathUtil.degreeToRadian(value.x), engine.MathUtil.degreeToRadian(value.y), engine.MathUtil.degreeToRadian(value.z));
60
+ engine.Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, this._physXRotation);
61
+ this._axis && engine.Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
62
+ this._physXRotation.normalize();
63
+ this._setLocalPose();
64
+ };
65
+ /**
66
+ * {@inheritDoc IColliderShape.setPosition }
67
+ */ _proto.setPosition = function setPosition(value) {
68
+ if (value !== this._position) {
69
+ this._position.copyFrom(value);
70
+ }
71
+ var controllers = this._controllers;
72
+ for(var i = 0, n = controllers.length; i < n; i++){
73
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
74
+ }
75
+ this._setLocalPose();
76
+ };
77
+ /**
78
+ * {@inheritDoc IColliderShape.setWorldScale }
79
+ */ _proto.setWorldScale = function setWorldScale(scale) {
80
+ this._worldScale.set(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
81
+ this._setLocalPose();
82
+ var controllers = this._controllers;
83
+ for(var i = 0, n = controllers.length; i < n; i++){
84
+ controllers.get(i)._updateShapePosition(this._position, this._worldScale);
85
+ }
86
+ };
87
+ /**
88
+ * {@inheritDoc IColliderShape.setContactOffset }
89
+ * @default 0.02f * PxTolerancesScale::length
90
+ */ _proto.setContactOffset = function setContactOffset(offset) {
91
+ this._contractOffset = offset;
92
+ var controllers = this._controllers;
93
+ if (controllers.length) {
94
+ for(var i = 0, n = controllers.length; i < n; i++){
95
+ var _controllers_get__pxController;
96
+ (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setContactOffset(offset);
97
+ }
98
+ } else {
99
+ this._pxShape.setContactOffset(offset);
100
+ }
101
+ };
102
+ /**
103
+ * {@inheritDoc IColliderShape.setMaterial }
104
+ */ _proto.setMaterial = function setMaterial(value) {
105
+ this._pxMaterial = value._pxMaterial;
106
+ this._pxShape.setMaterial(this._pxMaterial);
107
+ };
108
+ /**
109
+ * {@inheritDoc IColliderShape.setIsTrigger }
110
+ */ _proto.setIsTrigger = function setIsTrigger(value) {
111
+ this._modifyFlag(1, !value);
112
+ this._modifyFlag(4, value);
113
+ this._setShapeFlags(this._shapeFlags);
114
+ };
115
+ /**
116
+ * {@inheritDoc IColliderShape.pointDistance }
117
+ */ _proto.pointDistance = function pointDistance(point) {
118
+ var info = this._pxGeometry.pointDistance(this._pxShape.getGlobalPose(), point);
119
+ var closestPoint = info.closestPoint;
120
+ var res = PhysXColliderShape._tempVector4;
121
+ res.set(closestPoint.x, closestPoint.y, closestPoint.z, info.distance);
122
+ return res;
123
+ };
124
+ /**
125
+ * {@inheritDoc IColliderShape.destroy }
126
+ */ _proto.destroy = function destroy() {
127
+ var _this__pxGeometry;
128
+ this._pxShape.release();
129
+ (_this__pxGeometry = this._pxGeometry) == null ? void 0 : _this__pxGeometry.delete();
130
+ };
131
+ /**
132
+ * @internal
133
+ */ _proto._setShapeFlags = function _setShapeFlags(flags) {
134
+ this._shapeFlags = flags;
135
+ var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
136
+ this._pxShape.setFlags(shapeFlags);
137
+ shapeFlags.delete();
138
+ };
139
+ _proto._setLocalPose = function _setLocalPose() {
140
+ var transform = PhysXColliderShape.transform;
141
+ engine.Vector3.multiply(this._position, this._worldScale, transform.translation);
142
+ transform.rotation = this._physXRotation;
143
+ this._pxShape.setLocalPose(transform);
144
+ };
145
+ _proto._initialize = function _initialize(material, id) {
146
+ this._id = id;
147
+ this._pxMaterial = material._pxMaterial;
148
+ var shapeFlags = new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags);
149
+ this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, shapeFlags);
150
+ shapeFlags.delete();
151
+ this._pxShape.setUUID(id);
152
+ };
153
+ _proto._modifyFlag = function _modifyFlag(flag, value) {
154
+ this._shapeFlags = value ? this._shapeFlags | flag : this._shapeFlags & ~flag;
155
+ };
156
+ return PhysXColliderShape;
157
+ }();
158
+ PhysXColliderShape.halfSqrt = 0.70710678118655;
159
+ PhysXColliderShape.transform = {
160
+ translation: new engine.Vector3(),
161
+ rotation: null
162
+ };
163
+ PhysXColliderShape._tempVector4 = new engine.Vector4();
164
+
165
+ /**
166
+ * Box collider shape in PhysX.
167
+ */ var PhysXBoxColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
168
+ _inherits(PhysXBoxColliderShape, PhysXColliderShape);
169
+ function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
170
+ var _this;
171
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, /** @internal */ _this._halfSize = new engine.Vector3();
172
+ var halfSize = _this._halfSize;
173
+ halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
174
+ _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(halfSize.x, halfSize.y, halfSize.z);
175
+ _this._initialize(material, uniqueID);
176
+ _this._setLocalPose();
177
+ return _this;
178
+ }
179
+ var _proto = PhysXBoxColliderShape.prototype;
180
+ /**
181
+ * {@inheritDoc IBoxColliderShape.setSize }
182
+ */ _proto.setSize = function setSize(value) {
183
+ var halfSize = this._halfSize;
184
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
185
+ halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
186
+ engine.Vector3.multiply(halfSize, this._worldScale, tempExtents);
187
+ this._pxGeometry.halfExtents = tempExtents;
188
+ this._pxShape.setGeometry(this._pxGeometry);
189
+ this._updateController(tempExtents);
190
+ };
191
+ /**
192
+ * {@inheritDoc IColliderShape.setRotation }
193
+ */ _proto.setRotation = function setRotation(value) {
194
+ PhysXColliderShape.prototype.setRotation.call(this, value);
195
+ if (this._controllers.length > 0) {
196
+ console.warn("Box character controller `rotation` is not supported in PhysX and will be ignored");
197
+ }
198
+ };
199
+ /**
200
+ * {@inheritDoc IColliderShape.setWorldScale }
201
+ */ _proto.setWorldScale = function setWorldScale(scale) {
202
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
203
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
204
+ engine.Vector3.multiply(this._halfSize, this._worldScale, tempExtents);
205
+ this._pxGeometry.halfExtents = tempExtents;
206
+ this._pxShape.setGeometry(this._pxGeometry);
207
+ this._updateController(tempExtents);
208
+ };
209
+ _proto._updateController = function _updateController(extents) {
210
+ var controllers = this._controllers;
211
+ for(var i = 0, n = controllers.length; i < n; i++){
212
+ var pxController = controllers.get(i)._pxController;
213
+ if (pxController) {
214
+ pxController.setHalfHeight(extents.y);
215
+ pxController.setHalfSideExtent(extents.x);
216
+ pxController.setHalfForwardExtent(extents.z);
217
+ }
218
+ }
219
+ };
220
+ return PhysXBoxColliderShape;
221
+ }(PhysXColliderShape);
222
+ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
223
+
224
+ /**
225
+ * Capsule collider shape in PhysX.
226
+ */ var PhysXCapsuleColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
227
+ _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
228
+ function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
229
+ var _this;
230
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this, /** @internal */ _this._upAxis = 1;
231
+ _this._radius = radius;
232
+ _this._halfHeight = height * 0.5;
233
+ _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
234
+ _this._physXRotation.copyFrom(_this._axis);
235
+ _this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(radius, _this._halfHeight);
236
+ _this._initialize(material, uniqueID);
237
+ _this._setLocalPose();
238
+ return _this;
239
+ }
240
+ var _proto = PhysXCapsuleColliderShape.prototype;
241
+ /**
242
+ * {@inheritDoc ICapsuleColliderShape.setRadius }
243
+ */ _proto.setRadius = function setRadius(value) {
244
+ this._radius = value;
245
+ var sizeScale = this._worldScale;
246
+ switch(this._upAxis){
247
+ case 0:
248
+ this._pxGeometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
249
+ break;
250
+ case 1:
251
+ this._pxGeometry.radius = this._radius * Math.max(sizeScale.x, sizeScale.z);
252
+ break;
253
+ case 2:
254
+ this._pxGeometry.radius = this._radius * Math.max(sizeScale.x, sizeScale.y);
255
+ break;
256
+ }
257
+ this._pxShape.setGeometry(this._pxGeometry);
258
+ var radius = this._pxGeometry.radius;
259
+ var controllers = this._controllers;
260
+ for(var i = 0, n = controllers.length; i < n; i++){
261
+ var _controllers_get__pxController;
262
+ (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setRadius(radius);
263
+ }
264
+ };
265
+ /**
266
+ * {@inheritDoc ICapsuleColliderShape.setHeight }
267
+ */ _proto.setHeight = function setHeight(value) {
268
+ this._halfHeight = value * 0.5;
269
+ var sizeScale = this._worldScale;
270
+ switch(this._upAxis){
271
+ case 0:
272
+ this._pxGeometry.halfHeight = this._halfHeight * sizeScale.x;
273
+ break;
274
+ case 1:
275
+ this._pxGeometry.halfHeight = this._halfHeight * sizeScale.y;
276
+ break;
277
+ case 2:
278
+ this._pxGeometry.halfHeight = this._halfHeight * sizeScale.z;
279
+ break;
280
+ }
281
+ this._pxShape.setGeometry(this._pxGeometry);
282
+ var height = this._pxGeometry.halfHeight * 2;
283
+ var controllers = this._controllers;
284
+ for(var i = 0, n = controllers.length; i < n; i++){
285
+ var _controllers_get__pxController;
286
+ (_controllers_get__pxController = controllers.get(i)._pxController) == null ? void 0 : _controllers_get__pxController.setHeight(height);
287
+ }
288
+ };
289
+ /**
290
+ * {@inheritDoc ICapsuleColliderShape.setRotation }
291
+ */ _proto.setRotation = function setRotation(value) {
292
+ PhysXColliderShape1.prototype.setRotation.call(this, value);
293
+ if (this._controllers.length > 0) {
294
+ console.warn("Capsule character controller `rotation` is not supported in PhysX and will be ignored");
295
+ }
296
+ };
297
+ /**
298
+ * {@inheritDoc ICapsuleColliderShape.setUpAxis }
299
+ */ _proto.setUpAxis = function setUpAxis(upAxis) {
300
+ var _this = this, rotation = _this._rotation, axis = _this._axis, physXRotation = _this._physXRotation;
301
+ this._upAxis = upAxis;
302
+ switch(this._upAxis){
303
+ case 0:
304
+ axis.set(0, 0, 0, 1);
305
+ break;
306
+ case 1:
307
+ axis.set(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
308
+ break;
309
+ case 2:
310
+ axis.set(0, PhysXColliderShape.halfSqrt, 0, PhysXColliderShape.halfSqrt);
311
+ break;
312
+ }
313
+ if (rotation) {
314
+ engine.Quaternion.rotationYawPitchRoll(rotation.y, rotation.x, rotation.z, physXRotation);
315
+ engine.Quaternion.multiply(physXRotation, axis, physXRotation);
316
+ } else {
317
+ physXRotation.copyFrom(axis);
318
+ }
319
+ this._setLocalPose();
320
+ if (this._controllers.length > 0) {
321
+ console.warn("Capsule character controller `upAxis` is not supported in PhysX and will be ignored");
322
+ }
323
+ };
324
+ /**
325
+ * {@inheritDoc IColliderShape.setWorldScale }
326
+ */ _proto.setWorldScale = function setWorldScale(scale) {
327
+ PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
328
+ var sizeScale = this._worldScale;
329
+ var geometry = this._pxGeometry;
330
+ switch(this._upAxis){
331
+ case 0:
332
+ geometry.radius = this._radius * Math.max(sizeScale.y, sizeScale.z);
333
+ geometry.halfHeight = this._halfHeight * sizeScale.x;
334
+ break;
335
+ case 1:
336
+ geometry.radius = this._radius * Math.max(sizeScale.x, sizeScale.z);
337
+ geometry.halfHeight = this._halfHeight * sizeScale.y;
338
+ break;
339
+ case 2:
340
+ geometry.radius = this._radius * Math.max(sizeScale.x, sizeScale.y);
341
+ geometry.halfHeight = this._halfHeight * sizeScale.z;
342
+ break;
343
+ }
344
+ this._pxShape.setGeometry(geometry);
345
+ var radius = geometry.radius;
346
+ var height = geometry.halfHeight * 2;
347
+ var controllers = this._controllers;
348
+ for(var i = 0, n = controllers.length; i < n; i++){
349
+ var pxController = controllers.get(i)._pxController;
350
+ if (pxController) {
351
+ pxController.setRadius(radius);
352
+ pxController.setHeight(height);
353
+ }
354
+ }
355
+ };
356
+ return PhysXCapsuleColliderShape;
357
+ }(PhysXColliderShape);
358
+ /**
359
+ * The up axis of the collider shape.
360
+ */ var ColliderShapeUpAxis = /*#__PURE__*/ function(ColliderShapeUpAxis) {
361
+ /** Up axis is X. */ ColliderShapeUpAxis[ColliderShapeUpAxis["X"] = 0] = "X";
362
+ /** Up axis is Y. */ ColliderShapeUpAxis[ColliderShapeUpAxis["Y"] = 1] = "Y";
363
+ /** Up axis is Z. */ ColliderShapeUpAxis[ColliderShapeUpAxis["Z"] = 2] = "Z";
364
+ return ColliderShapeUpAxis;
365
+ }({});
366
+
367
+ /**
368
+ * Base class for character controllers.
369
+ */ var PhysXCharacterController = /*#__PURE__*/ function() {
370
+ function PhysXCharacterController(physXPhysics) {
371
+ /** @internal */ this._scene = null;
372
+ this._shapeScaledPosition = new engine.Vector3();
373
+ this._worldPosition = null;
374
+ this._physXPhysics = physXPhysics;
375
+ }
376
+ var _proto = PhysXCharacterController.prototype;
377
+ /**
378
+ * {@inheritDoc ICharacterController.move }
379
+ */ _proto.move = function move(disp, minDist, elapsedTime) {
380
+ var _this__pxController;
381
+ var _this__pxController_move;
382
+ return (_this__pxController_move = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.move(disp, minDist, elapsedTime)) != null ? _this__pxController_move : 0;
383
+ };
384
+ /**
385
+ * {@inheritDoc ICharacterController.setWorldPosition }
386
+ */ _proto.setWorldPosition = function setWorldPosition(position) {
387
+ this._worldPosition = position;
388
+ this._updateNativePosition();
389
+ };
390
+ /**
391
+ * {@inheritDoc ICharacterController.getWorldPosition }
392
+ */ _proto.getWorldPosition = function getWorldPosition(position) {
393
+ if (this._pxController) {
394
+ position.copyFrom(this._pxController.getPosition());
395
+ position.subtract(this._shapeScaledPosition);
396
+ }
397
+ };
398
+ /**
399
+ * {@inheritDoc ICharacterController.setStepOffset }
400
+ */ _proto.setStepOffset = function setStepOffset(offset) {
401
+ var _this__pxController;
402
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setStepOffset(offset);
403
+ };
404
+ /**
405
+ * {@inheritDoc ICharacterController.setNonWalkableMode }
406
+ */ _proto.setNonWalkableMode = function setNonWalkableMode(flag) {
407
+ var _this__pxController;
408
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setNonWalkableMode(flag);
409
+ };
410
+ /**
411
+ * {@inheritDoc ICharacterController.setUpDirection }
412
+ */ _proto.setUpDirection = function setUpDirection(up) {
413
+ var _this__pxController;
414
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setUpDirection(up);
415
+ };
416
+ /**
417
+ * {@inheritDoc ICharacterController.setSlopeLimit }
418
+ */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
419
+ var _this__pxController;
420
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setSlopeLimit(Math.cos(slopeLimit * Math.PI / 180));
421
+ };
422
+ /**
423
+ * {@inheritDoc ICharacterController.addShape }
424
+ */ _proto.addShape = function addShape(shape) {
425
+ var _this__pxController, _this__scene;
426
+ // Add shape should sync latest position and world scale to pxController
427
+ this._updateShapePosition(shape._position, shape._worldScale);
428
+ // When CharacterController is disabled, set shape property need check pxController whether exist because of this._pxManager is null and won't create pxController
429
+ this._pxManager && this._createPXController(this._pxManager, shape);
430
+ this._shape = shape;
431
+ shape._controllers.add(this);
432
+ (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.setContactOffset(shape._contractOffset);
433
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
434
+ };
435
+ /**
436
+ * {@inheritDoc ICharacterController.removeShape }
437
+ */ _proto.removeShape = function removeShape(shape) {
438
+ var _this__scene;
439
+ this._destroyPXController();
440
+ this._shape = null;
441
+ shape._controllers.delete(this);
442
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
443
+ };
444
+ /**
445
+ * {@inheritDoc ICollider.setCollisionLayer }
446
+ */ _proto.setCollisionLayer = function setCollisionLayer(layer) {
447
+ var _this__pxController;
448
+ var actor = (_this__pxController = this._pxController) == null ? void 0 : _this__pxController.getActor();
449
+ if (actor) {
450
+ this._physXPhysics._physX.setGroup(actor, layer);
451
+ }
452
+ };
453
+ /**
454
+ * {@inheritDoc ICharacterController.destroy }
455
+ */ _proto.destroy = function destroy() {
456
+ this._destroyPXController();
457
+ };
458
+ /**
459
+ * @internal
460
+ */ _proto._createPXController = function _createPXController(pxManager, shape) {
461
+ var desc;
462
+ if (_instanceof(shape, PhysXBoxColliderShape)) {
463
+ desc = new this._physXPhysics._physX.PxBoxControllerDesc();
464
+ desc.halfHeight = shape._halfSize.y;
465
+ desc.halfSideExtent = shape._halfSize.x;
466
+ desc.halfForwardExtent = shape._halfSize.z;
467
+ if (shape._rotation.lengthSquared() > 0) {
468
+ console.warn("Box character controller `rotation` is not supported in PhysX and will be ignored");
469
+ }
470
+ } else if (_instanceof(shape, PhysXCapsuleColliderShape)) {
471
+ desc = new this._physXPhysics._physX.PxCapsuleControllerDesc();
472
+ desc.radius = shape._radius;
473
+ desc.height = shape._halfHeight * 2;
474
+ desc.climbingMode = 1; // constraint mode
475
+ if (shape._rotation.lengthSquared() > 0) {
476
+ console.warn("Capsule character controller `rotation` is not supported in PhysX and will be ignored");
477
+ }
478
+ if (shape._upAxis !== ColliderShapeUpAxis.Y) {
479
+ console.warn("Capsule character controller `upAxis` is not supported in PhysX and will be ignored");
480
+ }
481
+ } else {
482
+ throw "unsupported shape type";
483
+ }
484
+ desc.setMaterial(shape._pxMaterial);
485
+ this._pxController = pxManager._getControllerManager().createController(desc);
486
+ desc.delete();
487
+ this._pxController.setUUID(shape._id);
488
+ this._updateNativePosition();
489
+ };
490
+ /**
491
+ * @internal
492
+ */ _proto._destroyPXController = function _destroyPXController() {
493
+ if (this._pxController) {
494
+ this._pxController.release();
495
+ this._pxController = null;
496
+ }
497
+ };
498
+ /**
499
+ * @internal
500
+ */ _proto._updateShapePosition = function _updateShapePosition(shapePosition, worldScale) {
501
+ engine.Vector3.multiply(shapePosition, worldScale, this._shapeScaledPosition);
502
+ this._updateNativePosition();
503
+ };
504
+ _proto._updateNativePosition = function _updateNativePosition() {
505
+ var worldPosition = this._worldPosition;
506
+ if (this._pxController && worldPosition) {
507
+ engine.Vector3.add(worldPosition, this._shapeScaledPosition, PhysXCharacterController._tempVec);
508
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
509
+ }
510
+ };
511
+ return PhysXCharacterController;
512
+ }();
513
+ PhysXCharacterController._tempVec = new engine.Vector3();
514
+
515
+ /**
516
+ * Abstract class of physical collider.
517
+ */ var PhysXCollider = /*#__PURE__*/ function() {
518
+ function PhysXCollider(physXPhysics) {
519
+ /** @internal */ this._scene = null;
520
+ /** @internal */ this._shapes = new Array();
521
+ this._physXPhysics = physXPhysics;
522
+ }
523
+ var _proto = PhysXCollider.prototype;
524
+ /**
525
+ * {@inheritDoc ICollider.addShape }
526
+ */ _proto.addShape = function addShape(shape) {
527
+ var _this__scene;
528
+ this._pxActor.attachShape(shape._pxShape);
529
+ this._shapes.push(shape);
530
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._addColliderShape(shape._id);
531
+ };
532
+ /**
533
+ * {@inheritDoc ICollider.removeShape }
534
+ */ _proto.removeShape = function removeShape(shape) {
535
+ var _this__scene;
536
+ this._pxActor.detachShape(shape._pxShape, true);
537
+ var shapes = this._shapes;
538
+ shapes.splice(shapes.indexOf(shape), 1);
539
+ (_this__scene = this._scene) == null ? void 0 : _this__scene._removeColliderShape(shape._id);
540
+ };
541
+ /**
542
+ * {@inheritDoc ICollider.setWorldTransform }
543
+ */ _proto.setWorldTransform = function setWorldTransform(position, rotation) {
544
+ this._pxActor.setGlobalPose(this._transform(position, rotation), true);
545
+ };
546
+ /**
547
+ * {@inheritDoc ICollider.getWorldTransform }
548
+ */ _proto.getWorldTransform = function getWorldTransform(outPosition, outRotation) {
549
+ var transform = this._pxActor.getGlobalPose();
550
+ outPosition.set(transform.translation.x, transform.translation.y, transform.translation.z);
551
+ outRotation.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
552
+ };
553
+ /**
554
+ * {@inheritDoc ICollider.setCollisionLayer }
555
+ */ _proto.setCollisionLayer = function setCollisionLayer(layer) {
556
+ this._physXPhysics._physX.setGroup(this._pxActor, layer);
557
+ };
558
+ /**
559
+ * {@inheritDoc ICollider.destroy }
560
+ */ _proto.destroy = function destroy() {
561
+ this._pxActor.release();
562
+ };
563
+ /**
564
+ * @internal
565
+ */ _proto._transform = function _transform(pos, rot) {
566
+ var transform = PhysXCollider._tempTransform;
567
+ transform.translation = pos;
568
+ transform.rotation = rot.normalize();
569
+ return transform;
570
+ };
571
+ return PhysXCollider;
572
+ }();
573
+ PhysXCollider._tempTransform = {
574
+ translation: null,
575
+ rotation: null
576
+ };
577
+
578
+ /**
579
+ * A dynamic collider can act with self-defined movement or physical force
580
+ */ var PhysXDynamicCollider = /*#__PURE__*/ function(PhysXCollider) {
581
+ _inherits(PhysXDynamicCollider, PhysXCollider);
582
+ function PhysXDynamicCollider(physXPhysics, position, rotation) {
583
+ var _this;
584
+ _this = PhysXCollider.call(this, physXPhysics) || this;
585
+ var transform = _this._transform(position, rotation);
586
+ _this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
587
+ return _this;
588
+ }
589
+ var _proto = PhysXDynamicCollider.prototype;
590
+ /**
591
+ * {@inheritDoc IDynamicCollider.setLinearDamping }
592
+ */ _proto.setLinearDamping = function setLinearDamping(value) {
593
+ this._pxActor.setLinearDamping(value);
594
+ };
595
+ /**
596
+ * {@inheritDoc IDynamicCollider.setAngularDamping }
597
+ */ _proto.setAngularDamping = function setAngularDamping(value) {
598
+ this._pxActor.setAngularDamping(value);
599
+ };
600
+ /**
601
+ * {@inheritDoc IDynamicCollider.getLinearVelocity }
602
+ */ _proto.getLinearVelocity = function getLinearVelocity(out) {
603
+ var velocity = this._pxActor.getLinearVelocity();
604
+ return out.set(velocity.x, velocity.y, velocity.z);
605
+ };
606
+ /**
607
+ * {@inheritDoc IDynamicCollider.setLinearVelocity }
608
+ */ _proto.setLinearVelocity = function setLinearVelocity(value) {
609
+ this._pxActor.setLinearVelocity(value, true);
610
+ };
611
+ /**
612
+ * {@inheritDoc IDynamicCollider.getAngularVelocity }
613
+ */ _proto.getAngularVelocity = function getAngularVelocity(out) {
614
+ var velocity = this._pxActor.getAngularVelocity();
615
+ return out.set(engine.MathUtil.radianToDegree(velocity.x), engine.MathUtil.radianToDegree(velocity.y), engine.MathUtil.radianToDegree(velocity.z));
616
+ };
617
+ /**
618
+ * {@inheritDoc IDynamicCollider.setAngularVelocity }
619
+ */ _proto.setAngularVelocity = function setAngularVelocity(value) {
620
+ PhysXDynamicCollider._tempTranslation.set(engine.MathUtil.degreeToRadian(value.x), engine.MathUtil.degreeToRadian(value.y), engine.MathUtil.degreeToRadian(value.z));
621
+ this._pxActor.setAngularVelocity(PhysXDynamicCollider._tempTranslation, true);
622
+ };
623
+ /**
624
+ * {@inheritDoc IDynamicCollider.setMass }
625
+ */ _proto.setMass = function setMass(value) {
626
+ this._pxActor.setMass(value);
627
+ };
628
+ /**
629
+ * {@inheritDoc IDynamicCollider.getCenterOfMass }
630
+ */ _proto.getCenterOfMass = function getCenterOfMass(out) {
631
+ var translation = this._pxActor.getCMassLocalPose().translation;
632
+ return out.set(translation.x, translation.y, translation.z);
633
+ };
634
+ /**
635
+ * {@inheritDoc IDynamicCollider.setCenterOfMass }
636
+ */ _proto.setCenterOfMass = function setCenterOfMass(position) {
637
+ this._pxActor.setCMassLocalPose(position);
638
+ };
639
+ /**
640
+ * {@inheritDoc IDynamicCollider.setInertiaTensor }
641
+ */ _proto.setInertiaTensor = function setInertiaTensor(value) {
642
+ this._pxActor.setMassSpaceInertiaTensor(value);
643
+ };
644
+ /**
645
+ * {@inheritDoc IDynamicCollider.getInertiaTensor }
646
+ */ _proto.getInertiaTensor = function getInertiaTensor(out) {
647
+ var inertia = this._pxActor.getMassSpaceInertiaTensor();
648
+ return out.set(inertia.x, inertia.y, inertia.z);
649
+ };
650
+ /**
651
+ * {@inheritDoc IDynamicCollider.setMassAndUpdateInertia }
652
+ */ _proto.setMassAndUpdateInertia = function setMassAndUpdateInertia(mass) {
653
+ this._pxActor.setMassAndUpdateInertia(mass);
654
+ };
655
+ /**
656
+ * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
657
+ */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
658
+ this._pxActor.setMaxAngularVelocity(engine.MathUtil.degreeToRadian(value));
659
+ };
660
+ /**
661
+ * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
662
+ */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
663
+ this._pxActor.setMaxDepenetrationVelocity(value);
664
+ };
665
+ /**
666
+ * {@inheritDoc IDynamicCollider.setSleepThreshold }
667
+ * @default 1e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
668
+ */ _proto.setSleepThreshold = function setSleepThreshold(value) {
669
+ this._pxActor.setSleepThreshold(value);
670
+ };
671
+ /**
672
+ * {@inheritDoc IDynamicCollider.setSolverIterations }
673
+ */ _proto.setSolverIterations = function setSolverIterations(value) {
674
+ this._pxActor.setSolverIterationCounts(value, 1);
675
+ };
676
+ /**
677
+ * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
678
+ */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
679
+ var physX = this._physXPhysics._physX;
680
+ switch(value){
681
+ case 1:
682
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
683
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
684
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
685
+ break;
686
+ case 2:
687
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, true);
688
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
689
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
690
+ break;
691
+ case 3:
692
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
693
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
694
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
695
+ break;
696
+ case 0:
697
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
698
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
699
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
700
+ break;
701
+ }
702
+ };
703
+ /**
704
+ * {@inheritDoc IDynamicCollider.setUseGravity }
705
+ */ _proto.setUseGravity = function setUseGravity(value) {
706
+ this._pxActor.setActorFlag(this._physXPhysics._physX.PxActorFlag.eDISABLE_GRAVITY, !value);
707
+ };
708
+ /**
709
+ * {@inheritDoc IDynamicCollider.setIsKinematic }
710
+ */ _proto.setIsKinematic = function setIsKinematic(value) {
711
+ if (value) {
712
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
713
+ } else {
714
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
715
+ }
716
+ };
717
+ /**
718
+ * {@inheritDoc IDynamicCollider.setConstraints }
719
+ */ _proto.setConstraints = function setConstraints(flags) {
720
+ this._pxActor.setRigidDynamicLockFlags(flags);
721
+ };
722
+ /**
723
+ * {@inheritDoc IDynamicCollider.addForce }
724
+ */ _proto.addForce = function addForce(force) {
725
+ this._pxActor.addForce({
726
+ x: force.x,
727
+ y: force.y,
728
+ z: force.z
729
+ });
730
+ };
731
+ /**
732
+ * {@inheritDoc IDynamicCollider.addTorque }
733
+ */ _proto.addTorque = function addTorque(torque) {
734
+ this._pxActor.addTorque({
735
+ x: torque.x,
736
+ y: torque.y,
737
+ z: torque.z
738
+ });
739
+ };
740
+ /**
741
+ * {@inheritDoc IDynamicCollider.move }
742
+ */ _proto.move = function move(positionOrRotation, rotation) {
743
+ if (rotation) {
744
+ this._pxActor.setKinematicTarget(positionOrRotation, rotation);
745
+ return;
746
+ }
747
+ var tempTranslation = PhysXDynamicCollider._tempTranslation;
748
+ var tempRotation = PhysXDynamicCollider._tempRotation;
749
+ this.getWorldTransform(tempTranslation, tempRotation);
750
+ if (_instanceof(positionOrRotation, engine.Vector3)) {
751
+ this._pxActor.setKinematicTarget(positionOrRotation, tempRotation);
752
+ } else {
753
+ this._pxActor.setKinematicTarget(tempTranslation, positionOrRotation);
754
+ }
755
+ };
756
+ /**
757
+ * {@inheritDoc IDynamicCollider.sleep }
758
+ */ _proto.sleep = function sleep() {
759
+ return this._pxActor.putToSleep();
760
+ };
761
+ /**
762
+ * {@inheritDoc IDynamicCollider.isSleeping }
763
+ */ _proto.isSleeping = function isSleeping() {
764
+ return this._pxActor.isSleeping();
765
+ };
766
+ /**
767
+ * {@inheritDoc IDynamicCollider.wakeUp }
768
+ */ _proto.wakeUp = function wakeUp() {
769
+ return this._pxActor.wakeUp();
770
+ };
771
+ return PhysXDynamicCollider;
772
+ }(PhysXCollider);
773
+ PhysXDynamicCollider._tempTranslation = new engine.Vector3();
774
+ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
775
+
776
+ var PhysXPhysicsManager = function PhysXPhysicsManager() {
777
+ /** @internal */ this._eventMap = {};
778
+ };
779
+
780
+ /**
781
+ * Physics material describes how to handle colliding objects (friction, bounciness).
782
+ */ var PhysXPhysicsMaterial = /*#__PURE__*/ function() {
783
+ function PhysXPhysicsMaterial(physXPhysics, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
784
+ this._physXPhysics = physXPhysics;
785
+ var pxMaterial = physXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
786
+ pxMaterial.setFrictionCombineMode(frictionCombine);
787
+ pxMaterial.setRestitutionCombineMode(bounceCombine);
788
+ this._pxMaterial = pxMaterial;
789
+ }
790
+ var _proto = PhysXPhysicsMaterial.prototype;
791
+ /**
792
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
793
+ */ _proto.setBounciness = function setBounciness(value) {
794
+ this._pxMaterial.setRestitution(value);
795
+ };
796
+ /**
797
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
798
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
799
+ this._pxMaterial.setDynamicFriction(value);
800
+ };
801
+ /**
802
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
803
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
804
+ this._pxMaterial.setStaticFriction(value);
805
+ };
806
+ /**
807
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
808
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
809
+ this._pxMaterial.setRestitutionCombineMode(value);
810
+ };
811
+ /**
812
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
813
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
814
+ this._pxMaterial.setFrictionCombineMode(value);
815
+ };
816
+ /**
817
+ * {@inheritDoc IPhysicsMaterial.destroy }
818
+ */ _proto.destroy = function destroy() {
819
+ this._pxMaterial.release();
820
+ };
821
+ return PhysXPhysicsMaterial;
822
+ }();
823
+
824
+ function _defineProperties(target, props) {
825
+ for (var i = 0; i < props.length; i++) {
826
+ var descriptor = props[i];
827
+ descriptor.enumerable = descriptor.enumerable || false;
828
+ descriptor.configurable = true;
829
+
830
+ if ("value" in descriptor) descriptor.writable = true;
831
+
832
+ Object.defineProperty(target, descriptor.key, descriptor);
833
+ }
834
+ }
835
+ function _create_class(Constructor, protoProps, staticProps) {
836
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
837
+ if (staticProps) _defineProperties(Constructor, staticProps);
838
+
839
+ return Constructor;
840
+ }
841
+
842
+ /**
843
+ * A manager is a collection of colliders and constraints which can interact.
844
+ */ var PhysXPhysicsScene = /*#__PURE__*/ function() {
845
+ function PhysXPhysicsScene(physXPhysics, physicsManager) {
846
+ var _this = this;
847
+ /** @internal */ this._pxControllerManager = null;
848
+ // Cached geometry objects for reuse
849
+ this._boxGeometry = null;
850
+ this._sphereGeometry = null;
851
+ this._capsuleGeometry = null;
852
+ this._activeTriggers = new engine.DisorderedArray();
853
+ this._contactEvents = [];
854
+ this._contactEventCount = 0;
855
+ this._triggerEvents = [];
856
+ this._physicsEvents = {
857
+ contactEvents: [],
858
+ contactEventCount: 0,
859
+ triggerEvents: []
860
+ };
861
+ this._triggerEventPool = [];
862
+ this._physXPhysics = physXPhysics;
863
+ this._physXManager = physicsManager;
864
+ var physX = physXPhysics._physX;
865
+ this._pxRaycastHit = new physX.PxRaycastHit();
866
+ this._pxFilterData = new physX.PxQueryFilterData();
867
+ this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4 | 8);
868
+ var triggerCallback = {
869
+ onContactBegin: function(collision) {
870
+ _this._bufferContactEvent(collision, 0);
871
+ },
872
+ onContactEnd: function(collision) {
873
+ _this._bufferContactEvent(collision, 2);
874
+ },
875
+ onContactPersist: function(collision) {
876
+ _this._bufferContactEvent(collision, 1);
877
+ },
878
+ onTriggerBegin: function(index1, index2) {
879
+ var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
880
+ event.state = 0;
881
+ _this._activeTriggers.add(event);
882
+ },
883
+ onTriggerEnd: function(index1, index2) {
884
+ var event;
885
+ if (index1 < index2) {
886
+ var subMap = _this._physXManager._eventMap[index1];
887
+ event = subMap[index2];
888
+ subMap[index2] = undefined;
889
+ } else {
890
+ var subMap1 = _this._physXManager._eventMap[index2];
891
+ event = subMap1[index1];
892
+ subMap1[index1] = undefined;
893
+ }
894
+ event.state = 2;
895
+ }
896
+ };
897
+ var pxPhysics = physXPhysics._pxPhysics;
898
+ this._physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
899
+ var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, this._physXSimulationCallbackInstance);
900
+ this._pxScene = pxPhysics.createScene(sceneDesc);
901
+ sceneDesc.delete();
902
+ }
903
+ var _proto = PhysXPhysicsScene.prototype;
904
+ /**
905
+ * {@inheritDoc IPhysicsScene.setGravity }
906
+ */ _proto.setGravity = function setGravity(value) {
907
+ this._pxScene.setGravity(value);
908
+ };
909
+ /**
910
+ * {@inheritDoc IPhysicsScene.addCollider }
911
+ */ _proto.addCollider = function addCollider(collider) {
912
+ collider._scene = this;
913
+ this._pxScene.addActor(collider._pxActor, null);
914
+ var shapes = collider._shapes;
915
+ for(var i = 0, n = shapes.length; i < n; i++){
916
+ this._addColliderShape(shapes[i]._id);
917
+ }
918
+ };
919
+ /**
920
+ * {@inheritDoc IPhysicsScene.removeCollider }
921
+ */ _proto.removeCollider = function removeCollider(collider) {
922
+ collider._scene = null;
923
+ this._pxScene.removeActor(collider._pxActor, true);
924
+ var shapes = collider._shapes;
925
+ for(var i = 0, n = shapes.length; i < n; i++){
926
+ this._removeColliderShape(shapes[i]._id);
927
+ }
928
+ };
929
+ /**
930
+ * {@inheritDoc IPhysicsScene.addCharacterController }
931
+ */ _proto.addCharacterController = function addCharacterController(characterController) {
932
+ characterController._scene = this;
933
+ // Physx have no API to remove/readd cct into scene.
934
+ if (!characterController._pxController) {
935
+ var shape = characterController._shape;
936
+ if (shape) {
937
+ var lastPXManager = characterController._pxManager;
938
+ if (lastPXManager !== this) {
939
+ lastPXManager && characterController._destroyPXController();
940
+ characterController._createPXController(this, shape);
941
+ }
942
+ this._addColliderShape(shape._id);
943
+ }
944
+ }
945
+ characterController._pxManager = this;
946
+ };
947
+ /**
948
+ * {@inheritDoc IPhysicsScene.removeCharacterController }
949
+ */ _proto.removeCharacterController = function removeCharacterController(characterController) {
950
+ characterController._scene = null;
951
+ characterController._pxManager = null;
952
+ characterController._destroyPXController();
953
+ var shape = characterController._shape;
954
+ shape && this._removeColliderShape(shape._id);
955
+ };
956
+ /**
957
+ * {@inheritDoc IPhysicsScene.update }
958
+ */ _proto.update = function update(elapsedTime) {
959
+ this._contactEventCount = 0;
960
+ this._simulate(elapsedTime);
961
+ this._fetchResults();
962
+ };
963
+ /**
964
+ * {@inheritDoc IPhysicsScene.updateEvents }
965
+ */ _proto.updateEvents = function updateEvents() {
966
+ var physicsEvents = this._physicsEvents;
967
+ // Collect trigger events: snapshot state for dispatch, then advance
968
+ var _this = this, triggerEventPool = _this._triggerEventPool, activeTriggers = _this._activeTriggers, triggerEvents = _this._triggerEvents;
969
+ triggerEvents.length = 0;
970
+ activeTriggers.forEach(function(event, i) {
971
+ event.dispatchState = event.state;
972
+ triggerEvents.push(event);
973
+ if (event.state === 0) {
974
+ event.state = 1;
975
+ } else if (event.state === 2) {
976
+ activeTriggers.deleteByIndex(i);
977
+ triggerEventPool.push(event);
978
+ }
979
+ });
980
+ physicsEvents.contactEvents = this._contactEvents;
981
+ physicsEvents.contactEventCount = this._contactEventCount;
982
+ physicsEvents.triggerEvents = triggerEvents;
983
+ return physicsEvents;
984
+ };
985
+ /**
986
+ * {@inheritDoc IPhysicsScene.raycast }
987
+ */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
988
+ var _this = this, pxHitResult = _this._pxRaycastHit;
989
+ distance = Math.min(distance, 3.4e38); // float32 max value limit in physX raycast.
990
+ var raycastCallback = {
991
+ preFilter: function(filterData, index, actor) {
992
+ if (onRaycast(index)) {
993
+ return 2; // eBLOCK
994
+ } else {
995
+ return 0; // eNONE
996
+ }
997
+ },
998
+ postFilter: function(filterData, distance) {
999
+ if (distance <= 0) {
1000
+ return 0; // eNONE — skip initial overlap
1001
+ }
1002
+ return 2; // eBLOCK
1003
+ }
1004
+ };
1005
+ var pxRaycastCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback);
1006
+ var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, pxRaycastCallback);
1007
+ pxRaycastCallback.delete();
1008
+ if (result && hit != undefined) {
1009
+ var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
1010
+ var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
1011
+ position.set(pxPosition.x, pxPosition.y, pxPosition.z);
1012
+ normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
1013
+ hit(pxHitResult.getShape().getUUID(), pxHitResult.distance, position, normal);
1014
+ }
1015
+ return result;
1016
+ };
1017
+ /**
1018
+ * {@inheritDoc IPhysicsScene.boxCast }
1019
+ */ _proto.boxCast = function boxCast(center, orientation, halfExtents, direction, distance, onSweep, outHitResult) {
1020
+ if (!this._boxGeometry) {
1021
+ this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
1022
+ } else {
1023
+ this._boxGeometry.halfExtents = halfExtents;
1024
+ }
1025
+ var pose = PhysXPhysicsScene._tempPose;
1026
+ pose.translation.copyFrom(center);
1027
+ pose.rotation.copyFrom(orientation);
1028
+ return this._sweepSingle(this._boxGeometry, pose, direction, distance, onSweep, outHitResult);
1029
+ };
1030
+ /**
1031
+ * {@inheritDoc IPhysicsScene.sphereCast }
1032
+ */ _proto.sphereCast = function sphereCast(center, radius, direction, distance, onSweep, outHitResult) {
1033
+ if (!this._sphereGeometry) {
1034
+ this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
1035
+ } else {
1036
+ this._sphereGeometry.radius = radius;
1037
+ }
1038
+ var tempQuat = PhysXPhysicsScene._tempQuaternion;
1039
+ tempQuat.set(0, 0, 0, 1); // Identity quaternion
1040
+ var pose = {
1041
+ translation: center,
1042
+ rotation: tempQuat
1043
+ };
1044
+ return this._sweepSingle(this._sphereGeometry, pose, direction, distance, onSweep, outHitResult);
1045
+ };
1046
+ /**
1047
+ * {@inheritDoc IPhysicsScene.capsuleCast }
1048
+ */ _proto.capsuleCast = function capsuleCast(center, radius, height, orientation, direction, distance, onSweep, outHitResult) {
1049
+ if (!this._capsuleGeometry) {
1050
+ this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
1051
+ } else {
1052
+ this._capsuleGeometry.radius = radius;
1053
+ this._capsuleGeometry.halfHeight = height * 0.5;
1054
+ }
1055
+ var pose = PhysXPhysicsScene._tempPose;
1056
+ pose.translation.copyFrom(center);
1057
+ pose.rotation.copyFrom(orientation);
1058
+ return this._sweepSingle(this._capsuleGeometry, pose, direction, distance, onSweep, outHitResult);
1059
+ };
1060
+ /**
1061
+ * {@inheritDoc IPhysicsScene.overlapBoxAll }
1062
+ */ _proto.overlapBoxAll = function overlapBoxAll(center, orientation, halfExtents, onOverlap) {
1063
+ if (!this._boxGeometry) {
1064
+ this._boxGeometry = new this._physXPhysics._physX.PxBoxGeometry(halfExtents.x, halfExtents.y, halfExtents.z);
1065
+ } else {
1066
+ this._boxGeometry.halfExtents = halfExtents;
1067
+ }
1068
+ var pose = PhysXPhysicsScene._tempPose;
1069
+ pose.translation.copyFrom(center);
1070
+ pose.rotation.copyFrom(orientation);
1071
+ return this._overlapMultiple(this._boxGeometry, pose, onOverlap);
1072
+ };
1073
+ /**
1074
+ * {@inheritDoc IPhysicsScene.overlapSphereAll }
1075
+ */ _proto.overlapSphereAll = function overlapSphereAll(center, radius, onOverlap) {
1076
+ if (!this._sphereGeometry) {
1077
+ this._sphereGeometry = new this._physXPhysics._physX.PxSphereGeometry(radius);
1078
+ } else {
1079
+ this._sphereGeometry.radius = radius;
1080
+ }
1081
+ var tempQuat = PhysXPhysicsScene._tempQuaternion;
1082
+ tempQuat.set(0, 0, 0, 1);
1083
+ var pose = {
1084
+ translation: center,
1085
+ rotation: tempQuat
1086
+ };
1087
+ return this._overlapMultiple(this._sphereGeometry, pose, onOverlap);
1088
+ };
1089
+ /**
1090
+ * {@inheritDoc IPhysicsScene.overlapCapsuleAll }
1091
+ */ _proto.overlapCapsuleAll = function overlapCapsuleAll(center, radius, height, orientation, onOverlap) {
1092
+ if (!this._capsuleGeometry) {
1093
+ this._capsuleGeometry = new this._physXPhysics._physX.PxCapsuleGeometry(radius, height * 0.5);
1094
+ } else {
1095
+ this._capsuleGeometry.radius = radius;
1096
+ this._capsuleGeometry.halfHeight = height * 0.5;
1097
+ }
1098
+ var pose = PhysXPhysicsScene._tempPose;
1099
+ pose.translation.copyFrom(center);
1100
+ pose.rotation.copyFrom(orientation);
1101
+ return this._overlapMultiple(this._capsuleGeometry, pose, onOverlap);
1102
+ };
1103
+ /**
1104
+ * {@inheritDoc IPhysicsScene.gc }
1105
+ */ _proto.gc = function gc() {
1106
+ this._contactEvents.length = this._contactEventCount;
1107
+ };
1108
+ /**
1109
+ * {@inheritDoc IPhysicsScene.destroy }
1110
+ */ _proto.destroy = function destroy() {
1111
+ var _this__boxGeometry, _this__sphereGeometry, _this__capsuleGeometry, // Need to release the controller manager before release the scene.
1112
+ _this__pxControllerManager;
1113
+ (_this__boxGeometry = this._boxGeometry) == null ? void 0 : _this__boxGeometry.delete();
1114
+ (_this__sphereGeometry = this._sphereGeometry) == null ? void 0 : _this__sphereGeometry.delete();
1115
+ (_this__capsuleGeometry = this._capsuleGeometry) == null ? void 0 : _this__capsuleGeometry.delete();
1116
+ this._physXSimulationCallbackInstance.delete();
1117
+ this._pxRaycastHit.delete();
1118
+ this._pxFilterData.flags.delete();
1119
+ this._pxFilterData.delete();
1120
+ (_this__pxControllerManager = this._pxControllerManager) == null ? void 0 : _this__pxControllerManager.release();
1121
+ this._pxScene.release();
1122
+ };
1123
+ /**
1124
+ * @internal
1125
+ */ _proto._getControllerManager = function _getControllerManager() {
1126
+ var pxControllerManager = this._pxControllerManager;
1127
+ if (pxControllerManager === null) {
1128
+ this._pxControllerManager = pxControllerManager = this._pxScene.createControllerManager();
1129
+ }
1130
+ return pxControllerManager;
1131
+ };
1132
+ /**
1133
+ * @internal
1134
+ */ _proto._addColliderShape = function _addColliderShape(id) {
1135
+ this._physXManager._eventMap[id] = Object.create(null);
1136
+ };
1137
+ /**
1138
+ * @internal
1139
+ */ _proto._removeColliderShape = function _removeColliderShape(id) {
1140
+ var _this = this, triggerEventPool = _this._triggerEventPool, activeTriggers = _this._activeTriggers;
1141
+ var _this__physXManager = this._physXManager, eventMap = _this__physXManager._eventMap;
1142
+ activeTriggers.forEach(function(event, i) {
1143
+ if (event.index1 == id) {
1144
+ activeTriggers.deleteByIndex(i);
1145
+ triggerEventPool.push(event);
1146
+ } else if (event.index2 == id) {
1147
+ activeTriggers.deleteByIndex(i);
1148
+ triggerEventPool.push(event);
1149
+ // If the shape is big index, should clear from the small index shape subMap
1150
+ eventMap[event.index1][id] = undefined;
1151
+ }
1152
+ });
1153
+ delete eventMap[id];
1154
+ };
1155
+ _proto._sweepSingle = function _sweepSingle(geometry, pose, direction, distance, onSweep, outHitResult) {
1156
+ distance = Math.min(distance, 3.4e38); // float32 max value limit in physx sweep
1157
+ var sweepCallback = {
1158
+ preFilter: function(filterData, index, actor) {
1159
+ if (onSweep(index)) {
1160
+ return 2; // eBLOCK
1161
+ } else {
1162
+ return 0; // eNONE
1163
+ }
1164
+ },
1165
+ postFilter: function(filterData, distance) {
1166
+ if (distance <= 0) {
1167
+ return 0; // eNONE — skip initial overlap
1168
+ }
1169
+ return 2; // eBLOCK
1170
+ }
1171
+ };
1172
+ var pxSweepCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(sweepCallback);
1173
+ var pxSweepHit = new this._physXPhysics._physX.PxSweepHit();
1174
+ var result = this._pxScene.sweepSingle(geometry, pose, direction, distance, pxSweepHit, this._pxFilterData, pxSweepCallback);
1175
+ if (result && outHitResult != undefined) {
1176
+ var position = PhysXPhysicsScene._tempPosition, normal = PhysXPhysicsScene._tempNormal;
1177
+ var pxPosition = pxSweepHit.position, pxNormal = pxSweepHit.normal;
1178
+ position.set(pxPosition.x, pxPosition.y, pxPosition.z);
1179
+ normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
1180
+ outHitResult(pxSweepHit.getShape().getUUID(), pxSweepHit.distance, position, normal);
1181
+ }
1182
+ pxSweepCallback.delete();
1183
+ pxSweepHit.delete();
1184
+ return result;
1185
+ };
1186
+ _proto._overlapMultiple = function _overlapMultiple(geometry, pose, onOverlap) {
1187
+ var overlapCallback = {
1188
+ preFilter: function(filterData, index, actor) {
1189
+ return onOverlap(index) ? 2 : 0;
1190
+ }
1191
+ };
1192
+ var pxOverlapCallback = this._physXPhysics._physX.PxQueryFilterCallback.implement(overlapCallback);
1193
+ var maxHits = 256;
1194
+ var hits = this._pxScene.overlapMultiple(geometry, pose, maxHits, this._pxFilterData, pxOverlapCallback);
1195
+ var result = PhysXPhysicsScene._tempShapeIDs;
1196
+ result.length = 0;
1197
+ if (hits) {
1198
+ // PhysX overlapMultiple returns a collection with size() method
1199
+ for(var i = 0, n = hits.size(); i < n; i++){
1200
+ result.push(hits.get(i).getShape().getUUID());
1201
+ }
1202
+ }
1203
+ pxOverlapCallback.delete();
1204
+ hits == null ? void 0 : hits.delete();
1205
+ return result;
1206
+ };
1207
+ _proto._simulate = function _simulate(elapsedTime) {
1208
+ this._pxScene.simulate(elapsedTime, true);
1209
+ };
1210
+ _proto._fetchResults = function _fetchResults(block) {
1211
+ if (block === void 0) block = true;
1212
+ this._pxScene.fetchResults(block);
1213
+ };
1214
+ _proto._getTrigger = function _getTrigger(index1, index2) {
1215
+ var event;
1216
+ if (this._triggerEventPool.length) {
1217
+ event = this._triggerEventPool.pop();
1218
+ event.index1 = index1;
1219
+ event.index2 = index2;
1220
+ } else {
1221
+ event = new TriggerEvent(index1, index2);
1222
+ }
1223
+ this._physXManager._eventMap[index1][index2] = event;
1224
+ return event;
1225
+ };
1226
+ _proto._bufferContactEvent = function _bufferContactEvent(collision, state) {
1227
+ var _this__contactEvents, _index;
1228
+ var index = this._contactEventCount++;
1229
+ var event = (_this__contactEvents = this._contactEvents)[_index = index] || (_this__contactEvents[_index] = new ContactEvent());
1230
+ event.shape0Id = collision.shape0Id;
1231
+ event.shape1Id = collision.shape1Id;
1232
+ event.state = state;
1233
+ // Copy contact points from PhysX (the native data is only valid during fetchResults)
1234
+ var nativeContacts = collision.getContacts();
1235
+ var count = nativeContacts.size();
1236
+ var bufferedContacts = event._bufferedContacts;
1237
+ bufferedContacts.contactCount = count;
1238
+ for(var i = 0; i < count; i++){
1239
+ var _bufferedContacts_contacts, _i;
1240
+ var src = nativeContacts.get(i);
1241
+ var dst = (_bufferedContacts_contacts = bufferedContacts.contacts)[_i = i] || (_bufferedContacts_contacts[_i] = new BufferedContactPoint());
1242
+ dst.position.copyFrom(src.position);
1243
+ dst.normal.copyFrom(src.normal);
1244
+ dst.impulse.copyFrom(src.impulse);
1245
+ dst.separation = src.separation;
1246
+ }
1247
+ };
1248
+ return PhysXPhysicsScene;
1249
+ }();
1250
+ PhysXPhysicsScene._tempPosition = new engine.Vector3();
1251
+ PhysXPhysicsScene._tempQuaternion = new engine.Quaternion();
1252
+ PhysXPhysicsScene._tempNormal = new engine.Vector3();
1253
+ PhysXPhysicsScene._tempPose = {
1254
+ translation: new engine.Vector3(),
1255
+ rotation: new engine.Quaternion()
1256
+ };
1257
+ PhysXPhysicsScene._tempShapeIDs = [];
1258
+ /**
1259
+ * Trigger event to store interactive object ids and state.
1260
+ */ var TriggerEvent = function TriggerEvent(index1, index2) {
1261
+ this.index1 = index1;
1262
+ this.index2 = index2;
1263
+ };
1264
+ /**
1265
+ * Buffered contact point data, copied from PhysX during fetchResults.
1266
+ */ var BufferedContactPoint = function BufferedContactPoint() {
1267
+ this.position = new engine.Vector3();
1268
+ this.normal = new engine.Vector3();
1269
+ this.impulse = new engine.Vector3();
1270
+ this.separation = 0;
1271
+ };
1272
+ /**
1273
+ * Contact event buffered from PhysX fetchResults callback.
1274
+ * Implements ICollision so it can be passed directly to the core layer.
1275
+ */ var BufferedContacts = /*#__PURE__*/ function() {
1276
+ function BufferedContacts() {
1277
+ this.contactCount = 0;
1278
+ this.contacts = [];
1279
+ }
1280
+ var _proto = BufferedContacts.prototype;
1281
+ _proto.size = function size() {
1282
+ return this.contactCount;
1283
+ };
1284
+ _proto.get = function get(index) {
1285
+ return this.contacts[index];
1286
+ };
1287
+ return BufferedContacts;
1288
+ }();
1289
+ var ContactEvent = /*#__PURE__*/ function() {
1290
+ function ContactEvent() {
1291
+ /** @internal */ this._bufferedContacts = new BufferedContacts();
1292
+ }
1293
+ var _proto = ContactEvent.prototype;
1294
+ _proto.getContacts = function getContacts() {
1295
+ return this._bufferedContacts;
1296
+ };
1297
+ _create_class(ContactEvent, [
1298
+ {
1299
+ key: "contactCount",
1300
+ get: function get() {
1301
+ return this._bufferedContacts.contactCount;
1302
+ }
1303
+ }
1304
+ ]);
1305
+ return ContactEvent;
1306
+ }();
1307
+
1308
+ /**
1309
+ * A static collider component that will not move.
1310
+ * @remarks Mostly used for object which always stays at the same place and never moves around.
1311
+ */ var PhysXStaticCollider = /*#__PURE__*/ function(PhysXCollider) {
1312
+ _inherits(PhysXStaticCollider, PhysXCollider);
1313
+ function PhysXStaticCollider(physXPhysics, position, rotation) {
1314
+ var _this;
1315
+ _this = PhysXCollider.call(this, physXPhysics) || this;
1316
+ _this._pxActor = physXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
1317
+ return _this;
1318
+ }
1319
+ return PhysXStaticCollider;
1320
+ }(PhysXCollider);
1321
+
1322
+ /**
1323
+ * PhysX runtime mode.
1324
+ */ var PhysXRuntimeMode = /*#__PURE__*/ function(PhysXRuntimeMode) {
1325
+ /** Use WebAssembly SIMD mode first, then WebAssembly as fallback. */ PhysXRuntimeMode[PhysXRuntimeMode["Auto"] = 0] = "Auto";
1326
+ /** WebAssembly mode. */ PhysXRuntimeMode[PhysXRuntimeMode["WebAssembly"] = 1] = "WebAssembly";
1327
+ /** WebAssembly SIMD mode. */ PhysXRuntimeMode[PhysXRuntimeMode["WebAssemblySIMD"] = 2] = "WebAssemblySIMD";
1328
+ return PhysXRuntimeMode;
1329
+ }({});
1330
+
1331
+ /**
1332
+ * a base interface providing common functionality for PhysX joints
1333
+ */ var PhysXJoint = /*#__PURE__*/ function() {
1334
+ function PhysXJoint(physXPhysics) {
1335
+ this._rotation = new engine.Quaternion();
1336
+ this._breakForce = Number.MAX_VALUE;
1337
+ this._breakTorque = Number.MAX_VALUE;
1338
+ this._physXPhysics = physXPhysics;
1339
+ }
1340
+ var _proto = PhysXJoint.prototype;
1341
+ /**
1342
+ * {@inheritDoc IJoint.setConnectedCollider }
1343
+ */ _proto.setConnectedCollider = function setConnectedCollider(value) {
1344
+ var _this__collider;
1345
+ this._pxJoint.setActors(((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null, (value == null ? void 0 : value._pxActor) || null);
1346
+ };
1347
+ /**
1348
+ * {@inheritDoc IJoint.setConnectedAnchor }
1349
+ */ _proto.setAnchor = function setAnchor(value) {
1350
+ this._setLocalPose(0, value, PhysXJoint._defaultQuat);
1351
+ this._anchor = value;
1352
+ };
1353
+ /**
1354
+ * {@inheritDoc IJoint.setConnectedAnchor }
1355
+ */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1356
+ this._setLocalPose(1, value, this._rotation);
1357
+ this._connectedAnchor = value;
1358
+ };
1359
+ _proto.setRotation = function setRotation(value) {
1360
+ this._setLocalPose(1, this._connectedAnchor, value);
1361
+ this._rotation.copyFrom(value);
1362
+ };
1363
+ /**
1364
+ * {@inheritDoc IJoint.setMassScale }
1365
+ */ _proto.setMassScale = function setMassScale(value) {
1366
+ this._pxJoint.setInvMassScale0(1 / value);
1367
+ };
1368
+ /**
1369
+ * {@inheritDoc IJoint.setConnectedMassScale }
1370
+ */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
1371
+ this._pxJoint.setInvMassScale1(1 / value);
1372
+ };
1373
+ /**
1374
+ * {@inheritDoc IJoint.setInertiaScale }
1375
+ */ _proto.setInertiaScale = function setInertiaScale(value) {
1376
+ this._pxJoint.setInvInertiaScale0(value);
1377
+ };
1378
+ /**
1379
+ * {@inheritDoc IJoint.setConnectedInertiaScale }
1380
+ */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
1381
+ this._pxJoint.setInvInertiaScale1(value);
1382
+ };
1383
+ /**
1384
+ * {@inheritDoc IJoint.setBreakForce }
1385
+ */ _proto.setBreakForce = function setBreakForce(value) {
1386
+ this._breakForce = value;
1387
+ this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
1388
+ };
1389
+ /**
1390
+ * {@inheritDoc IJoint.setBreakTorque }
1391
+ */ _proto.setBreakTorque = function setBreakTorque(value) {
1392
+ this._breakTorque = value;
1393
+ this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
1394
+ };
1395
+ /**
1396
+ * {@inheritDoc IJoint.destroy }
1397
+ */ _proto.destroy = function destroy() {
1398
+ if (!this._pxJoint) return;
1399
+ this._pxJoint.release();
1400
+ this._collider = null;
1401
+ };
1402
+ /**
1403
+ * Set the joint local pose for an actor.
1404
+ * @param actor 0 for the first actor, 1 for the second actor.
1405
+ * @param position the local position for the actor this joint
1406
+ * @param rotation the local rotation for the actor this joint
1407
+ */ _proto._setLocalPose = function _setLocalPose(actor, position, rotation) {
1408
+ this._pxJoint.setLocalPose(actor, position, rotation);
1409
+ };
1410
+ return PhysXJoint;
1411
+ }();
1412
+ PhysXJoint._defaultVec = new engine.Vector3();
1413
+ PhysXJoint._defaultQuat = new engine.Quaternion();
1414
+
1415
+ /**
1416
+ * A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
1417
+ */ var PhysXFixedJoint = /*#__PURE__*/ function(PhysXJoint1) {
1418
+ _inherits(PhysXFixedJoint, PhysXJoint1);
1419
+ function PhysXFixedJoint(physXPhysics, collider) {
1420
+ var _this;
1421
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
1422
+ _this._collider = collider;
1423
+ _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1424
+ return _this;
1425
+ }
1426
+ return PhysXFixedJoint;
1427
+ }(PhysXJoint);
1428
+
1429
+ /**
1430
+ * A joint which behaves in a similar way to a hinge or axle.
1431
+ */ var PhysXHingeJoint = /*#__PURE__*/ function(PhysXJoint1) {
1432
+ _inherits(PhysXHingeJoint, PhysXJoint1);
1433
+ function PhysXHingeJoint(physXPhysics, collider) {
1434
+ var _this;
1435
+ _this = PhysXJoint1.call(this, physXPhysics) || this, _this._axisRotationQuaternion = new engine.Quaternion(), _this._connectedAxisRotationQuaternion = new engine.Quaternion();
1436
+ _this._collider = collider;
1437
+ _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1438
+ return _this;
1439
+ }
1440
+ var _proto = PhysXHingeJoint.prototype;
1441
+ _proto.setRotation = function setRotation(value) {
1442
+ var axis = this._axis;
1443
+ this._rotation.copyFrom(value);
1444
+ axis && this.setAxis(axis);
1445
+ };
1446
+ /**
1447
+ * {@inheritDoc IHingeJoint.setAxis }
1448
+ */ _proto.setAxis = function setAxis(value) {
1449
+ this._axis = value;
1450
+ var xAxis = PhysXHingeJoint._xAxis;
1451
+ var axisRotationQuaternion = this._axisRotationQuaternion;
1452
+ xAxis.set(1, 0, 0);
1453
+ var angle = Math.acos(engine.Vector3.dot(xAxis, value));
1454
+ engine.Vector3.cross(xAxis, value, xAxis);
1455
+ engine.Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
1456
+ this._setLocalPose(0, this._anchor, axisRotationQuaternion);
1457
+ var connectedAxisRotationQuaternion = this._connectedAxisRotationQuaternion;
1458
+ engine.Quaternion.multiply(this._rotation, axisRotationQuaternion, connectedAxisRotationQuaternion);
1459
+ this._setLocalPose(1, this._connectedAnchor, connectedAxisRotationQuaternion);
1460
+ };
1461
+ _proto.setAnchor = function setAnchor(value) {
1462
+ this._setLocalPose(0, value, this._axisRotationQuaternion);
1463
+ this._anchor = value;
1464
+ };
1465
+ /**
1466
+ * {@inheritDoc IJoint.setConnectedAnchor }
1467
+ */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
1468
+ this._setLocalPose(1, value, this._connectedAxisRotationQuaternion);
1469
+ this._connectedAnchor = value;
1470
+ };
1471
+ /**
1472
+ * {@inheritDoc IHingeJoint.getAngle }
1473
+ */ _proto.getAngle = function getAngle() {
1474
+ return engine.MathUtil.radianToDegree(this._pxJoint.getAngle());
1475
+ };
1476
+ /**
1477
+ * {@inheritDoc IHingeJoint.getVelocity }
1478
+ */ _proto.getVelocity = function getVelocity() {
1479
+ return this._pxJoint.getVelocity();
1480
+ };
1481
+ /**
1482
+ * {@inheritDoc IHingeJoint.setHardLimitCone }
1483
+ */ _proto.setHardLimit = function setHardLimit(lowerLimit, upperLimit, contactDist) {
1484
+ this._pxJoint.setHardLimit(engine.MathUtil.degreeToRadian(lowerLimit), engine.MathUtil.degreeToRadian(upperLimit), contactDist);
1485
+ };
1486
+ /**
1487
+ * {@inheritDoc IHingeJoint.setHardLimitCone }
1488
+ */ _proto.setSoftLimit = function setSoftLimit(lowerLimit, upperLimit, stiffness, damping) {
1489
+ this._pxJoint.setSoftLimit(engine.MathUtil.degreeToRadian(lowerLimit), engine.MathUtil.degreeToRadian(upperLimit), stiffness, damping);
1490
+ };
1491
+ /**
1492
+ * {@inheritDoc IHingeJoint.setDriveVelocity }
1493
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity, autowake) {
1494
+ if (autowake === void 0) autowake = true;
1495
+ this._pxJoint.setDriveVelocity(velocity, autowake);
1496
+ };
1497
+ /**
1498
+ * {@inheritDoc IHingeJoint.setDriveForceLimit }
1499
+ */ _proto.setDriveForceLimit = function setDriveForceLimit(limit) {
1500
+ this._pxJoint.setDriveForceLimit(limit);
1501
+ };
1502
+ /**
1503
+ * {@inheritDoc IHingeJoint.setDriveGearRatio }
1504
+ */ _proto.setDriveGearRatio = function setDriveGearRatio(ratio) {
1505
+ this._pxJoint.setDriveGearRatio(ratio);
1506
+ };
1507
+ /**
1508
+ * {@inheritDoc IHingeJoint.setHingeJointFlag }
1509
+ */ _proto.setHingeJointFlag = function setHingeJointFlag(flag, value) {
1510
+ this._pxJoint.setRevoluteJointFlag(flag, value);
1511
+ };
1512
+ return PhysXHingeJoint;
1513
+ }(PhysXJoint);
1514
+ PhysXHingeJoint._xAxis = new engine.Vector3(1, 0, 0);
1515
+
1516
+ /**
1517
+ * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
1518
+ */ var PhysXSpringJoint = /*#__PURE__*/ function(PhysXJoint1) {
1519
+ _inherits(PhysXSpringJoint, PhysXJoint1);
1520
+ function PhysXSpringJoint(physXPhysics, collider) {
1521
+ var _this;
1522
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
1523
+ _this._collider = collider;
1524
+ _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
1525
+ _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
1526
+ _this._pxJoint.setDistanceJointFlag(4, true); // enable min distance;
1527
+ _this._pxJoint.setDistanceJointFlag(8, true); // enable spring;
1528
+ return _this;
1529
+ }
1530
+ var _proto = PhysXSpringJoint.prototype;
1531
+ /**
1532
+ * {@inheritDoc ISpringJoint.setMinDistance }
1533
+ */ _proto.setMinDistance = function setMinDistance(distance) {
1534
+ this._pxJoint.setMinDistance(distance);
1535
+ };
1536
+ /**
1537
+ * {@inheritDoc ISpringJoint.setMaxDistance }
1538
+ */ _proto.setMaxDistance = function setMaxDistance(distance) {
1539
+ this._pxJoint.setMaxDistance(distance);
1540
+ };
1541
+ /**
1542
+ * {@inheritDoc ISpringJoint.setTolerance }
1543
+ */ _proto.setTolerance = function setTolerance(tolerance) {
1544
+ this._pxJoint.setTolerance(tolerance);
1545
+ };
1546
+ /**
1547
+ * {@inheritDoc ISpringJoint.setStiffness }
1548
+ */ _proto.setStiffness = function setStiffness(stiffness) {
1549
+ this._pxJoint.setStiffness(stiffness);
1550
+ };
1551
+ /**
1552
+ * {@inheritDoc ISpringJoint.setDamping }
1553
+ */ _proto.setDamping = function setDamping(damping) {
1554
+ this._pxJoint.setDamping(damping);
1555
+ };
1556
+ return PhysXSpringJoint;
1557
+ }(PhysXJoint);
1558
+
1559
+ function _assert_this_initialized(self) {
1560
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
1561
+
1562
+ return self;
1563
+ }
1564
+
1565
+ function _type_of(obj) {
1566
+ "@swc/helpers - typeof";
1567
+
1568
+ return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
1569
+ }
1570
+
1571
+ function _possible_constructor_return(self, call) {
1572
+ if (call && (_type_of(call) === "object" || typeof call === "function")) return call;
1573
+
1574
+ return _assert_this_initialized(self);
1575
+ }
1576
+
1577
+ /**
1578
+ * Mesh collider shape in PhysX.
1579
+ */ var PhysXMeshColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1580
+ _inherits(PhysXMeshColliderShape, PhysXColliderShape);
1581
+ function PhysXMeshColliderShape(physXPhysics, uniqueID, positions, indices, isConvex, material, cookingFlags) {
1582
+ var _this;
1583
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, _this._pxMesh = null;
1584
+ _this._isConvex = isConvex;
1585
+ if (!_this._cookMesh(positions, indices, cookingFlags)) {
1586
+ return _possible_constructor_return(_this);
1587
+ }
1588
+ var physX = physXPhysics._physX, physics = physXPhysics._pxPhysics;
1589
+ var _this__worldScale = _this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1590
+ var shapeFlags = ShapeFlag.SCENE_QUERY_SHAPE | ShapeFlag.SIMULATION_SHAPE;
1591
+ var meshFlag = isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1592
+ var createShapeFn = isConvex ? physX.createConvexMeshShape : physX.createTriMeshShape;
1593
+ _this._pxShape = createShapeFn(_this._pxMesh, scaleX, scaleY, scaleZ, meshFlag, shapeFlags, material._pxMaterial, physics);
1594
+ _this._id = uniqueID;
1595
+ _this._pxMaterial = material._pxMaterial;
1596
+ _this._pxShape.setUUID(uniqueID);
1597
+ _this._setLocalPose();
1598
+ return _this;
1599
+ }
1600
+ var _proto = PhysXMeshColliderShape.prototype;
1601
+ /**
1602
+ * {@inheritDoc IMeshColliderShape.setMeshData }
1603
+ */ _proto.setMeshData = function setMeshData(positions, indices, isConvex, cookingFlags) {
1604
+ var _this__pxMesh, _this__pxGeometry;
1605
+ (_this__pxMesh = this._pxMesh) == null ? void 0 : _this__pxMesh.release();
1606
+ (_this__pxGeometry = this._pxGeometry) == null ? void 0 : _this__pxGeometry.delete();
1607
+ this._pxMesh = null;
1608
+ this._pxGeometry = null;
1609
+ this._isConvex = isConvex;
1610
+ if (!this._cookMesh(positions, indices, cookingFlags)) {
1611
+ return false;
1612
+ }
1613
+ this._pxShape.setGeometry(this._pxGeometry);
1614
+ return true;
1615
+ };
1616
+ /**
1617
+ * {@inheritDoc IColliderShape.setWorldScale }
1618
+ */ _proto.setWorldScale = function setWorldScale(scale) {
1619
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
1620
+ this._updateGeometry();
1621
+ };
1622
+ /**
1623
+ * {@inheritDoc IColliderShape.destroy }
1624
+ */ _proto.destroy = function destroy() {
1625
+ var _this__pxMesh;
1626
+ (_this__pxMesh = this._pxMesh) == null ? void 0 : _this__pxMesh.release();
1627
+ PhysXColliderShape.prototype.destroy.call(this);
1628
+ };
1629
+ _proto._cookMesh = function _cookMesh(positions, indices, cookingFlags) {
1630
+ var _this__physXPhysics = this._physXPhysics, physX = _this__physXPhysics._physX, physics = _this__physXPhysics._pxPhysics, cooking = _this__physXPhysics._pxCooking, cookingParams = _this__physXPhysics._pxCookingParams;
1631
+ // Apply per-shape cooking flags
1632
+ var preprocessFlags = 0;
1633
+ if (cookingFlags & engine.MeshColliderShapeCookingFlag.VertexWelding) {
1634
+ preprocessFlags |= 1; // eWELD_VERTICES
1635
+ }
1636
+ if (!(cookingFlags & engine.MeshColliderShapeCookingFlag.Cleaning)) {
1637
+ preprocessFlags |= 2; // eDISABLE_CLEAN_MESH
1638
+ }
1639
+ physX.setCookingMeshPreprocessParams(cookingParams, preprocessFlags);
1640
+ cooking.setParams(cookingParams);
1641
+ var verticesPtr = this._allocatePositions(positions);
1642
+ if (this._isConvex) {
1643
+ this._pxMesh = cooking.createConvexMesh(verticesPtr, positions.length, physics);
1644
+ physX._free(verticesPtr);
1645
+ if (!this._pxMesh) {
1646
+ this._logConvexCookingError(physX);
1647
+ return false;
1648
+ }
1649
+ } else {
1650
+ if (!indices) {
1651
+ physX._free(verticesPtr);
1652
+ console.error("PhysXMeshColliderShape: Triangle mesh requires indices.");
1653
+ return false;
1654
+ }
1655
+ var isU32 = _instanceof(indices, Uint32Array);
1656
+ var indicesPtr = this._allocateIndices(indices, isU32);
1657
+ this._pxMesh = cooking.createTriMesh(verticesPtr, positions.length, indicesPtr, indices.length / 3, !isU32, physics);
1658
+ physX._free(verticesPtr);
1659
+ physX._free(indicesPtr);
1660
+ if (!this._pxMesh) {
1661
+ this._logTriMeshCookingError(physX);
1662
+ return false;
1663
+ }
1664
+ }
1665
+ var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1666
+ var meshFlag = this._isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1667
+ this._pxGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag);
1668
+ return true;
1669
+ };
1670
+ _proto._logConvexCookingError = function _logConvexCookingError(physX) {
1671
+ switch(physX.getLastConvexCookingResult()){
1672
+ case 1:
1673
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh. Could not find 4 vertices that do not form a zero-area triangle.");
1674
+ break;
1675
+ case 2:
1676
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh within the maximum polygons limit (256). Consider simplifying the mesh.");
1677
+ break;
1678
+ default:
1679
+ console.error("PhysXMeshColliderShape: Failed to create convex mesh. The input geometry may be invalid.");
1680
+ break;
1681
+ }
1682
+ };
1683
+ _proto._logTriMeshCookingError = function _logTriMeshCookingError(physX) {
1684
+ switch(physX.getLastTriMeshCookingResult()){
1685
+ case 1:
1686
+ console.error("PhysXMeshColliderShape: Failed to create triangle mesh. One of the triangles is too large. Consider tessellating large triangles.");
1687
+ break;
1688
+ default:
1689
+ console.error("PhysXMeshColliderShape: Failed to create triangle mesh. The input geometry may be invalid.");
1690
+ break;
1691
+ }
1692
+ };
1693
+ _proto._allocatePositions = function _allocatePositions(positions) {
1694
+ var physX = this._physXPhysics._physX;
1695
+ var length = positions.length;
1696
+ var ptr = physX._malloc(length * 3 * 4);
1697
+ var view = new Float32Array(physX.HEAPF32.buffer, ptr, length * 3);
1698
+ for(var i = 0, offset = 0; i < length; i++, offset += 3){
1699
+ positions[i].copyToArray(view, offset);
1700
+ }
1701
+ return ptr;
1702
+ };
1703
+ _proto._allocateIndices = function _allocateIndices(indices, isU32) {
1704
+ var physX = this._physXPhysics._physX;
1705
+ // Uint8Array and Uint16Array both write as Uint16 (PhysX minimum index size)
1706
+ var TypedArrayCtor = isU32 ? Uint32Array : Uint16Array;
1707
+ var heap = isU32 ? physX.HEAPU32 : physX.HEAPU16;
1708
+ var ptr = physX._malloc(indices.length * TypedArrayCtor.BYTES_PER_ELEMENT);
1709
+ new TypedArrayCtor(heap.buffer, ptr, indices.length).set(indices);
1710
+ return ptr;
1711
+ };
1712
+ _proto._updateGeometry = function _updateGeometry() {
1713
+ if (!this._pxMesh) return;
1714
+ var physX = this._physXPhysics._physX;
1715
+ var _this__worldScale = this._worldScale, scaleX = _this__worldScale.x, scaleY = _this__worldScale.y, scaleZ = _this__worldScale.z;
1716
+ var meshFlag = this._isConvex ? PhysXMeshColliderShape._tightBoundsFlag : 0;
1717
+ var newGeometry = this._isConvex ? physX.createConvexMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag) : physX.createTriMeshGeometry(this._pxMesh, scaleX, scaleY, scaleZ, meshFlag);
1718
+ this._pxGeometry.delete();
1719
+ this._pxGeometry = newGeometry;
1720
+ this._pxShape.setGeometry(this._pxGeometry);
1721
+ };
1722
+ return PhysXMeshColliderShape;
1723
+ }(PhysXColliderShape);
1724
+ PhysXMeshColliderShape._tightBoundsFlag = 1 // eTIGHT_BOUNDS = 1 (1<<0)
1725
+ ;
1726
+
1727
+ /**
1728
+ * Plane collider shape in PhysX.
1729
+ */ var PhysXPlaneColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
1730
+ _inherits(PhysXPlaneColliderShape, PhysXColliderShape1);
1731
+ function PhysXPlaneColliderShape(physXPhysics, uniqueID, material) {
1732
+ var _this;
1733
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this;
1734
+ _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
1735
+ _this._physXRotation.copyFrom(_this._axis);
1736
+ _this._pxGeometry = new physXPhysics._physX.PxPlaneGeometry();
1737
+ _this._initialize(material, uniqueID);
1738
+ _this._setLocalPose();
1739
+ return _this;
1740
+ }
1741
+ return PhysXPlaneColliderShape;
1742
+ }(PhysXColliderShape);
1743
+
1744
+ /**
1745
+ * Sphere collider shape in PhysX.
1746
+ */ var PhysXSphereColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1747
+ _inherits(PhysXSphereColliderShape, PhysXColliderShape);
1748
+ function PhysXSphereColliderShape(physXPhysics, uniqueID, radius, material) {
1749
+ var _this;
1750
+ _this = PhysXColliderShape.call(this, physXPhysics) || this, _this._maxScale = 1;
1751
+ _this._radius = radius;
1752
+ _this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(radius * _this._maxScale);
1753
+ _this._initialize(material, uniqueID);
1754
+ _this._setLocalPose();
1755
+ return _this;
1756
+ }
1757
+ var _proto = PhysXSphereColliderShape.prototype;
1758
+ /**
1759
+ * {@inheritDoc ISphereColliderShape.setRadius }
1760
+ */ _proto.setRadius = function setRadius(value) {
1761
+ this._radius = value;
1762
+ this._pxGeometry.radius = value * this._maxScale;
1763
+ this._pxShape.setGeometry(this._pxGeometry);
1764
+ };
1765
+ /**
1766
+ * {@inheritDoc IColliderShape.setWorldScale }
1767
+ */ _proto.setWorldScale = function setWorldScale(scale) {
1768
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
1769
+ this._maxScale = Math.max(Math.abs(scale.x), Math.abs(scale.y), Math.abs(scale.z));
1770
+ this._pxGeometry.radius = this._radius * this._maxScale;
1771
+ this._pxShape.setGeometry(this._pxGeometry);
1772
+ };
1773
+ return PhysXSphereColliderShape;
1774
+ }(PhysXColliderShape);
1775
+
1776
+ /**
1777
+ * PhysX object creation.
1778
+ */ var PhysXPhysics = /*#__PURE__*/ function() {
1779
+ function PhysXPhysics(runtimeMode, runtimeUrls) {
1780
+ if (runtimeMode === void 0) runtimeMode = PhysXRuntimeMode.Auto;
1781
+ this._initializeState = 0;
1782
+ this._runTimeMode = runtimeMode;
1783
+ var _runtimeUrls_wasmSIMDModeUrl;
1784
+ this._wasmSIMDModeUrl = (_runtimeUrls_wasmSIMDModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmSIMDModeUrl) != null ? _runtimeUrls_wasmSIMDModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*iHrYQKBrgTAAAAAAQ4AAAAgAehQnAQ/physx.release.simd.js";
1785
+ var _runtimeUrls_wasmModeUrl;
1786
+ this._wasmModeUrl = (_runtimeUrls_wasmModeUrl = runtimeUrls == null ? void 0 : runtimeUrls.wasmModeUrl) != null ? _runtimeUrls_wasmModeUrl : "https://mdn.alipayobjects.com/rms/afts/file/A*DFuvR6Mv5C0AAAAAQ4AAAAgAehQnAQ/physx.release.js";
1787
+ }
1788
+ var _proto = PhysXPhysics.prototype;
1789
+ /**
1790
+ * Initialize PhysXPhysics.
1791
+ * @param runtimeMode - Runtime mode
1792
+ * @returns Promise object
1793
+ */ _proto.initialize = function initialize() {
1794
+ var _this = this;
1795
+ if (this._initializeState === 2) {
1796
+ return Promise.resolve();
1797
+ } else if (this._initializeState === 1) {
1798
+ return this._initializePromise;
1799
+ }
1800
+ this._initializeState = 1;
1801
+ var runtimeMode = this._runTimeMode;
1802
+ var scriptPromise = new Promise(function(resolve, reject) {
1803
+ var script = document.createElement("script");
1804
+ document.body.appendChild(script);
1805
+ script.async = true;
1806
+ script.onload = resolve;
1807
+ script.onerror = reject;
1808
+ if (runtimeMode == PhysXRuntimeMode.Auto) {
1809
+ runtimeMode = engine.SystemInfo._detectSIMDSupported() ? PhysXRuntimeMode.WebAssemblySIMD : PhysXRuntimeMode.WebAssembly;
1810
+ }
1811
+ if (runtimeMode == PhysXRuntimeMode.WebAssemblySIMD) {
1812
+ script.src = _this._wasmSIMDModeUrl;
1813
+ } else {
1814
+ script.src = _this._wasmModeUrl;
1815
+ }
1816
+ });
1817
+ var initializePromise = new Promise(function(resolve, reject) {
1818
+ scriptPromise.then(function() {
1819
+ return window.PHYSX().then(function(PHYSX) {
1820
+ _this._runTimeMode = runtimeMode;
1821
+ _this._init(PHYSX);
1822
+ _this._initializeState = 2;
1823
+ _this._initializePromise = null;
1824
+ console.log("PhysX loaded.");
1825
+ resolve();
1826
+ }, reject);
1827
+ }, reject).catch(reject);
1828
+ });
1829
+ this._initializePromise = initializePromise;
1830
+ return initializePromise;
1831
+ };
1832
+ /**
1833
+ * Destroy PhysXPhysics.
1834
+ */ _proto.destroy = function destroy() {
1835
+ this._pxCooking.release();
1836
+ this._pxCookingParams.delete();
1837
+ this._physX.PxCloseExtensions();
1838
+ this._pxPhysics.release();
1839
+ this._pxFoundation.release();
1840
+ this._defaultErrorCallback.delete();
1841
+ this._allocator.delete();
1842
+ this._tolerancesScale.delete();
1843
+ };
1844
+ /**
1845
+ * {@inheritDoc IPhysics.createPhysicsManager }
1846
+ */ _proto.createPhysicsManager = function createPhysicsManager() {
1847
+ return new PhysXPhysicsManager();
1848
+ };
1849
+ /**
1850
+ * {@inheritDoc IPhysics.createPhysicsScene }
1851
+ */ _proto.createPhysicsScene = function createPhysicsScene(physicsManager) {
1852
+ var scene = new PhysXPhysicsScene(this, physicsManager);
1853
+ return scene;
1854
+ };
1855
+ /**
1856
+ * {@inheritDoc IPhysics.createStaticCollider }
1857
+ */ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
1858
+ return new PhysXStaticCollider(this, position, rotation);
1859
+ };
1860
+ /**
1861
+ * {@inheritDoc IPhysics.createDynamicCollider }
1862
+ */ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
1863
+ return new PhysXDynamicCollider(this, position, rotation);
1864
+ };
1865
+ /**
1866
+ * {@inheritDoc IPhysics.createCharacterController }
1867
+ */ _proto.createCharacterController = function createCharacterController() {
1868
+ return new PhysXCharacterController(this);
1869
+ };
1870
+ /**
1871
+ * {@inheritDoc IPhysics.createPhysicsMaterial }
1872
+ */ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1873
+ return new PhysXPhysicsMaterial(this, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1874
+ };
1875
+ /**
1876
+ * {@inheritDoc IPhysics.createBoxColliderShape }
1877
+ */ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1878
+ return new PhysXBoxColliderShape(this, uniqueID, size, material);
1879
+ };
1880
+ /**
1881
+ * {@inheritDoc IPhysics.createSphereColliderShape }
1882
+ */ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1883
+ return new PhysXSphereColliderShape(this, uniqueID, radius, material);
1884
+ };
1885
+ /**
1886
+ * {@inheritDoc IPhysics.createPlaneColliderShape }
1887
+ */ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1888
+ return new PhysXPlaneColliderShape(this, uniqueID, material);
1889
+ };
1890
+ /**
1891
+ * {@inheritDoc IPhysics.createCapsuleColliderShape }
1892
+ */ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1893
+ return new PhysXCapsuleColliderShape(this, uniqueID, radius, height, material);
1894
+ };
1895
+ /**
1896
+ * {@inheritDoc IPhysics.createMeshColliderShape }
1897
+ */ _proto.createMeshColliderShape = function createMeshColliderShape(uniqueID, positions, indices, isConvex, material, cookingFlags) {
1898
+ var shape = new PhysXMeshColliderShape(this, uniqueID, positions, indices, isConvex, material, cookingFlags);
1899
+ return shape._pxShape ? shape : null;
1900
+ };
1901
+ /**
1902
+ * {@inheritDoc IPhysics.createFixedJoint }
1903
+ */ _proto.createFixedJoint = function createFixedJoint(collider) {
1904
+ return new PhysXFixedJoint(this, collider);
1905
+ };
1906
+ /**
1907
+ * {@inheritDoc IPhysics.createHingeJoint }
1908
+ */ _proto.createHingeJoint = function createHingeJoint(collider) {
1909
+ return new PhysXHingeJoint(this, collider);
1910
+ };
1911
+ /**
1912
+ * {@inheritDoc IPhysics.createSpringJoint }
1913
+ */ _proto.createSpringJoint = function createSpringJoint(collider) {
1914
+ return new PhysXSpringJoint(this, collider);
1915
+ };
1916
+ /**
1917
+ * {@inheritDoc IPhysics.getColliderLayerCollision }
1918
+ */ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
1919
+ return this._physX.getGroupCollisionFlag(layer1, layer2);
1920
+ };
1921
+ /**
1922
+ * {@inheritDoc IPhysics.setColliderLayerCollision }
1923
+ */ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, isCollide) {
1924
+ this._physX.setGroupCollisionFlag(layer1, layer2, isCollide);
1925
+ };
1926
+ _proto._init = function _init(physX) {
1927
+ var version = physX.PX_PHYSICS_VERSION;
1928
+ var defaultErrorCallback = new physX.PxDefaultErrorCallback();
1929
+ var allocator = new physX.PxDefaultAllocator();
1930
+ var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
1931
+ var tolerancesScale = new physX.PxTolerancesScale();
1932
+ var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, tolerancesScale, false, null);
1933
+ physX.PxInitExtensions(pxPhysics, null);
1934
+ // Initialize cooking for mesh colliders
1935
+ var cookingParams = new physX.PxCookingParams(tolerancesScale);
1936
+ physX.setCookingMeshPreprocessParams(cookingParams, 1); // eWELD_VERTICES
1937
+ cookingParams.meshWeldTolerance = 0.001;
1938
+ // BVH34 midphase requires SSE2; SIMD WASM provides SSE2 via WASM SIMD
1939
+ if (this._runTimeMode === PhysXRuntimeMode.WebAssemblySIMD) {
1940
+ physX.setCookingMidphaseType(cookingParams, 1); // eBVH34
1941
+ }
1942
+ var pxCooking = physX.PxCreateCooking(version, pxFoundation, cookingParams);
1943
+ this._physX = physX;
1944
+ this._pxFoundation = pxFoundation;
1945
+ this._pxPhysics = pxPhysics;
1946
+ this._pxCooking = pxCooking;
1947
+ this._pxCookingParams = cookingParams;
1948
+ this._defaultErrorCallback = defaultErrorCallback;
1949
+ this._allocator = allocator;
1950
+ this._tolerancesScale = tolerancesScale;
1951
+ };
1952
+ return PhysXPhysics;
1953
+ }();
1954
+
1955
+ //@ts-ignore
1956
+ var version = "0.0.0-experimental-2.0-game";
1957
+ console.log("Galacean Engine Physics PhysX Version: " + version);
1958
+
1959
+ exports.PhysXPhysics = PhysXPhysics;
1960
+ exports.PhysXRuntimeMode = PhysXRuntimeMode;
1961
+ exports.version = version;
1962
+
1963
+ Object.defineProperty(exports, '__esModule', { value: true });
1964
+
1965
+ }));
1966
+ //# sourceMappingURL=browser.js.map