@galacean/engine-physics-physx 1.6.7 → 1.6.8

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