@galacean/engine-physics-physx 0.9.20 → 1.0.0-alpha.7
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/README.md +2 -2
- package/dist/browser.js +222 -194
- package/dist/browser.min.js +1 -1
- package/dist/main.js +222 -194
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +282 -36489
- package/dist/module.js +221 -195
- package/dist/module.js.map +1 -1
- package/libs/.DS_Store +0 -0
- package/libs/physx.release.js +1 -1
- package/libs/physx.release.js.js +31 -30
- package/libs/physx.release.js.mem +0 -0
- package/libs/physx.release.wasm +0 -0
- package/package.json +8 -8
- package/types/PhysXCharacterController.d.ts +6 -0
- package/types/PhysXCollider.d.ts +3 -0
- package/types/PhysXDynamicCollider.d.ts +2 -1
- package/types/PhysXPhysics.d.ts +21 -17
- package/types/PhysXPhysicsManager.d.ts +5 -4
- package/types/PhysXPhysicsMaterial.d.ts +3 -1
- package/types/PhysXStaticCollider.d.ts +3 -7
- package/types/joint/PhysXFixedJoint.d.ts +3 -2
- package/types/joint/PhysXHingeJoint.d.ts +4 -3
- package/types/joint/PhysXJoint.d.ts +4 -1
- package/types/joint/PhysXSpringJoint.d.ts +2 -1
- package/types/shape/PhysXBoxColliderShape.d.ts +4 -8
- package/types/shape/PhysXCapsuleColliderShape.d.ts +2 -8
- package/types/shape/PhysXColliderShape.d.ts +5 -2
- package/types/shape/PhysXPlaneColliderShape.d.ts +2 -11
- package/types/shape/PhysXSphereColliderShape.d.ts +4 -9
- package/LICENSE +0 -21
package/dist/module.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Vector3, Quaternion } from '@galacean/engine';
|
|
1
|
+
import { Vector3, Quaternion, version } from '@galacean/engine';
|
|
2
2
|
|
|
3
3
|
function _instanceof(left, right) {
|
|
4
4
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
@@ -6,28 +6,6 @@ function _instanceof(left, right) {
|
|
|
6
6
|
} else return left instanceof right;
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
/******************************************************************************
|
|
10
|
-
Copyright (c) Microsoft Corporation.
|
|
11
|
-
|
|
12
|
-
Permission to use, copy, modify, and/or distribute this software for any
|
|
13
|
-
purpose with or without fee is hereby granted.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
|
16
|
-
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
17
|
-
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
|
18
|
-
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
|
19
|
-
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
|
20
|
-
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
|
21
|
-
PERFORMANCE OF THIS SOFTWARE.
|
|
22
|
-
***************************************************************************** */
|
|
23
|
-
|
|
24
|
-
function __decorate(decorators, target, key, desc) {
|
|
25
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
26
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
27
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
28
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
9
|
/**
|
|
32
10
|
* PhysX runtime mode.
|
|
33
11
|
*/ var PhysXRuntimeMode;
|
|
@@ -60,10 +38,11 @@ function _inherits(subClass, superClass) {
|
|
|
60
38
|
/**
|
|
61
39
|
* a base interface providing common functionality for PhysX joints
|
|
62
40
|
*/ var PhysXJoint = /*#__PURE__*/ function() {
|
|
63
|
-
function PhysXJoint() {
|
|
41
|
+
function PhysXJoint(physXPhysics) {
|
|
64
42
|
this._connectedAnchor = new Vector3();
|
|
65
43
|
this._breakForce = Number.MAX_VALUE;
|
|
66
44
|
this._breakTorque = Number.MAX_VALUE;
|
|
45
|
+
this._physXPhysics = physXPhysics;
|
|
67
46
|
}
|
|
68
47
|
var _proto = PhysXJoint.prototype;
|
|
69
48
|
/**
|
|
@@ -134,11 +113,11 @@ function _inherits(subClass, superClass) {
|
|
|
134
113
|
* A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
|
|
135
114
|
*/ var PhysXFixedJoint = /*#__PURE__*/ function(PhysXJoint1) {
|
|
136
115
|
_inherits(PhysXFixedJoint, PhysXJoint1);
|
|
137
|
-
function PhysXFixedJoint(collider) {
|
|
116
|
+
function PhysXFixedJoint(physXPhysics, collider) {
|
|
138
117
|
var _this;
|
|
139
|
-
_this = PhysXJoint1.call(this) || this;
|
|
118
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
140
119
|
_this._collider = collider;
|
|
141
|
-
_this._pxJoint =
|
|
120
|
+
_this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
142
121
|
return _this;
|
|
143
122
|
}
|
|
144
123
|
return PhysXFixedJoint;
|
|
@@ -148,14 +127,14 @@ function _inherits(subClass, superClass) {
|
|
|
148
127
|
* A joint which behaves in a similar way to a hinge or axle.
|
|
149
128
|
*/ var PhysXHingeJoint = /*#__PURE__*/ function(PhysXJoint1) {
|
|
150
129
|
_inherits(PhysXHingeJoint, PhysXJoint1);
|
|
151
|
-
function PhysXHingeJoint(collider) {
|
|
130
|
+
function PhysXHingeJoint(physXPhysics, collider) {
|
|
152
131
|
var _this;
|
|
153
|
-
_this = PhysXJoint1.call(this) || this;
|
|
132
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
154
133
|
_this._axisRotationQuaternion = new Quaternion();
|
|
155
134
|
_this._swingOffset = new Vector3();
|
|
156
135
|
_this._velocity = new Vector3();
|
|
157
136
|
_this._collider = collider;
|
|
158
|
-
_this._pxJoint =
|
|
137
|
+
_this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
159
138
|
return _this;
|
|
160
139
|
}
|
|
161
140
|
var _proto = PhysXHingeJoint.prototype;
|
|
@@ -226,12 +205,12 @@ function _inherits(subClass, superClass) {
|
|
|
226
205
|
* a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
|
|
227
206
|
*/ var PhysXSpringJoint = /*#__PURE__*/ function(PhysXJoint1) {
|
|
228
207
|
_inherits(PhysXSpringJoint, PhysXJoint1);
|
|
229
|
-
function PhysXSpringJoint(collider) {
|
|
208
|
+
function PhysXSpringJoint(physXPhysics, collider) {
|
|
230
209
|
var _this;
|
|
231
|
-
_this = PhysXJoint1.call(this) || this;
|
|
210
|
+
_this = PhysXJoint1.call(this, physXPhysics) || this;
|
|
232
211
|
_this._swingOffset = new Vector3();
|
|
233
212
|
_this._collider = collider;
|
|
234
|
-
_this._pxJoint =
|
|
213
|
+
_this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
|
|
235
214
|
_this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
|
|
236
215
|
_this._pxJoint.setDistanceJointFlag(4, true); // enable min distance;
|
|
237
216
|
_this._pxJoint.setDistanceJointFlag(8, true); // enable spring;
|
|
@@ -327,24 +306,25 @@ var ShapeFlag;
|
|
|
327
306
|
/**
|
|
328
307
|
* Abstract class for collider shapes.
|
|
329
308
|
*/ var PhysXColliderShape = /*#__PURE__*/ function() {
|
|
330
|
-
function PhysXColliderShape() {
|
|
309
|
+
function PhysXColliderShape(physXPhysics) {
|
|
331
310
|
/** @internal */ this._controllers = new DisorderedArray();
|
|
332
311
|
this._scale = new Vector3(1, 1, 1);
|
|
333
312
|
this._position = new Vector3();
|
|
334
313
|
this._rotation = null;
|
|
335
314
|
this._axis = null;
|
|
336
|
-
this.
|
|
315
|
+
this._physXRotation = new Quaternion();
|
|
337
316
|
this._shapeFlags = 2 | 1;
|
|
338
317
|
/** @internal */ this._pxMaterials = new Array(1);
|
|
318
|
+
this._physXPhysics = physXPhysics;
|
|
339
319
|
}
|
|
340
320
|
var _proto = PhysXColliderShape.prototype;
|
|
341
321
|
/**
|
|
342
322
|
* {@inheritDoc IColliderShape.setRotation }
|
|
343
323
|
*/ _proto.setRotation = function setRotation(value) {
|
|
344
324
|
this._rotation = value;
|
|
345
|
-
Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this.
|
|
346
|
-
this._axis && Quaternion.multiply(this.
|
|
347
|
-
this.
|
|
325
|
+
Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
|
|
326
|
+
this._axis && Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
|
|
327
|
+
this._physXRotation.normalize();
|
|
348
328
|
this._setLocalPose();
|
|
349
329
|
};
|
|
350
330
|
/**
|
|
@@ -353,7 +333,21 @@ var ShapeFlag;
|
|
|
353
333
|
if (value !== this._position) {
|
|
354
334
|
this._position.copyFrom(value);
|
|
355
335
|
}
|
|
336
|
+
var controllers = this._controllers;
|
|
337
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
338
|
+
controllers.get(i)._pxController.setLocalPosition(this._position, this._scale);
|
|
339
|
+
}
|
|
340
|
+
this._setLocalPose();
|
|
341
|
+
};
|
|
342
|
+
/**
|
|
343
|
+
* {@inheritDoc IColliderShape.setWorldScale }
|
|
344
|
+
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
345
|
+
this._scale.copyFrom(scale);
|
|
356
346
|
this._setLocalPose();
|
|
347
|
+
var controllers = this._controllers;
|
|
348
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
349
|
+
controllers.get(i)._setLocalPosition(this._position, this._scale);
|
|
350
|
+
}
|
|
357
351
|
};
|
|
358
352
|
/**
|
|
359
353
|
* {@inheritDoc IColliderShape.setContactOffset }
|
|
@@ -387,19 +381,19 @@ var ShapeFlag;
|
|
|
387
381
|
* @internal
|
|
388
382
|
*/ _proto._setShapeFlags = function _setShapeFlags(flags) {
|
|
389
383
|
this._shapeFlags = flags;
|
|
390
|
-
this._pxShape.setFlags(new
|
|
384
|
+
this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
|
|
391
385
|
};
|
|
392
386
|
_proto._setLocalPose = function _setLocalPose() {
|
|
393
387
|
var transform = PhysXColliderShape.transform;
|
|
394
388
|
Vector3.multiply(this._position, this._scale, transform.translation);
|
|
395
|
-
transform.rotation = this.
|
|
389
|
+
transform.rotation = this._physXRotation;
|
|
396
390
|
this._pxShape.setLocalPose(transform);
|
|
397
391
|
};
|
|
398
392
|
_proto._initialize = function _initialize(material, id) {
|
|
399
393
|
this._id = id;
|
|
400
394
|
this._pxMaterials[0] = material._pxMaterial;
|
|
401
|
-
this._pxShape =
|
|
402
|
-
this._pxShape.
|
|
395
|
+
this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
|
|
396
|
+
this._pxShape.setUUID(id);
|
|
403
397
|
};
|
|
404
398
|
_proto._modifyFlag = function _modifyFlag(flag, value) {
|
|
405
399
|
this._shapeFlags = value ? this._shapeFlags | flag : this._shapeFlags & ~flag;
|
|
@@ -420,12 +414,12 @@ var ShapeFlag;
|
|
|
420
414
|
* Box collider shape in PhysX.
|
|
421
415
|
*/ var PhysXBoxColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
|
|
422
416
|
_inherits(PhysXBoxColliderShape, PhysXColliderShape);
|
|
423
|
-
function PhysXBoxColliderShape(uniqueID, size, material) {
|
|
417
|
+
function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
|
|
424
418
|
var _this;
|
|
425
|
-
_this = PhysXColliderShape.call(this) || this;
|
|
419
|
+
_this = PhysXColliderShape.call(this, physXPhysics) || this;
|
|
426
420
|
/** @internal */ _this._halfSize = new Vector3();
|
|
427
421
|
_this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
|
|
428
|
-
_this._pxGeometry = new
|
|
422
|
+
_this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(_this._halfSize.x * _this._scale.x, _this._halfSize.y * _this._scale.y, _this._halfSize.z * _this._scale.z);
|
|
429
423
|
_this._initialize(material, uniqueID);
|
|
430
424
|
_this._setLocalPose();
|
|
431
425
|
return _this;
|
|
@@ -434,26 +428,31 @@ var ShapeFlag;
|
|
|
434
428
|
/**
|
|
435
429
|
* {@inheritDoc IBoxColliderShape.setSize }
|
|
436
430
|
*/ _proto.setSize = function setSize(value) {
|
|
431
|
+
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
437
432
|
this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
|
|
438
|
-
Vector3.multiply(this._halfSize, this._scale,
|
|
439
|
-
this._pxGeometry.halfExtents =
|
|
433
|
+
Vector3.multiply(this._halfSize, this._scale, tempExtents);
|
|
434
|
+
this._pxGeometry.halfExtents = tempExtents;
|
|
440
435
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
441
|
-
|
|
442
|
-
for(var i = 0, n = controllers.length; i < n; i++){
|
|
443
|
-
var pxController = controllers.get(i)._pxController;
|
|
444
|
-
pxController.setHalfHeight(this._halfSize.x);
|
|
445
|
-
pxController.setHalfSideExtent(this._halfSize.y);
|
|
446
|
-
pxController.setHalfForwardExtent(this._halfSize.z);
|
|
447
|
-
}
|
|
436
|
+
this._updateController(tempExtents);
|
|
448
437
|
};
|
|
449
438
|
/**
|
|
450
439
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
451
440
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
Vector3.multiply(this._halfSize, this._scale,
|
|
455
|
-
this._pxGeometry.halfExtents =
|
|
441
|
+
PhysXColliderShape.prototype.setWorldScale.call(this, scale);
|
|
442
|
+
var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
|
|
443
|
+
Vector3.multiply(this._halfSize, this._scale, tempExtents);
|
|
444
|
+
this._pxGeometry.halfExtents = tempExtents;
|
|
456
445
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
446
|
+
this._updateController(tempExtents);
|
|
447
|
+
};
|
|
448
|
+
_proto._updateController = function _updateController(extents) {
|
|
449
|
+
var controllers = this._controllers;
|
|
450
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
451
|
+
var pxController = controllers.get(i)._pxController;
|
|
452
|
+
pxController.setHalfHeight(extents.x);
|
|
453
|
+
pxController.setHalfSideExtent(extents.y);
|
|
454
|
+
pxController.setHalfForwardExtent(extents.z);
|
|
455
|
+
}
|
|
457
456
|
};
|
|
458
457
|
return PhysXBoxColliderShape;
|
|
459
458
|
}(PhysXColliderShape);
|
|
@@ -465,15 +464,15 @@ var ShapeFlag;
|
|
|
465
464
|
* Capsule collider shape in PhysX.
|
|
466
465
|
*/ var PhysXCapsuleColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
|
|
467
466
|
_inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
|
|
468
|
-
function PhysXCapsuleColliderShape(uniqueID, radius, height, material) {
|
|
467
|
+
function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
|
|
469
468
|
var _this;
|
|
470
|
-
_this = PhysXColliderShape1.call(this) || this;
|
|
469
|
+
_this = PhysXColliderShape1.call(this, physXPhysics) || this;
|
|
471
470
|
_this._upAxis = /** Up axis is Y. */ 1;
|
|
472
471
|
_this._radius = radius;
|
|
473
472
|
_this._halfHeight = height * 0.5;
|
|
474
473
|
_this._axis = new Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
475
|
-
_this.
|
|
476
|
-
_this._pxGeometry = new
|
|
474
|
+
_this._physXRotation.copyFrom(_this._axis);
|
|
475
|
+
_this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(_this._radius, _this._halfHeight);
|
|
477
476
|
_this._initialize(material, uniqueID);
|
|
478
477
|
_this._setLocalPose();
|
|
479
478
|
return _this;
|
|
@@ -495,9 +494,10 @@ var ShapeFlag;
|
|
|
495
494
|
break;
|
|
496
495
|
}
|
|
497
496
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
497
|
+
var radius = this._pxGeometry.radius;
|
|
498
498
|
var controllers = this._controllers;
|
|
499
499
|
for(var i = 0, n = controllers.length; i < n; i++){
|
|
500
|
-
controllers.get(i)._pxController.setRadius(
|
|
500
|
+
controllers.get(i)._pxController.setRadius(radius);
|
|
501
501
|
}
|
|
502
502
|
};
|
|
503
503
|
/**
|
|
@@ -516,15 +516,16 @@ var ShapeFlag;
|
|
|
516
516
|
break;
|
|
517
517
|
}
|
|
518
518
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
519
|
+
var height = this._pxGeometry.halfHeight * 2;
|
|
519
520
|
var controllers = this._controllers;
|
|
520
521
|
for(var i = 0, n = controllers.length; i < n; i++){
|
|
521
|
-
controllers.get(i)._pxController.setHeight(
|
|
522
|
+
controllers.get(i)._pxController.setHeight(height);
|
|
522
523
|
}
|
|
523
524
|
};
|
|
524
525
|
/**
|
|
525
526
|
* {@inheritDoc ICapsuleColliderShape.setUpAxis }
|
|
526
527
|
*/ _proto.setUpAxis = function setUpAxis(upAxis) {
|
|
527
|
-
var _this = this, rotation = _this._rotation, axis = _this._axis,
|
|
528
|
+
var _this = this, rotation = _this._rotation, axis = _this._axis, physXRotation = _this._physXRotation;
|
|
528
529
|
this._upAxis = upAxis;
|
|
529
530
|
switch(this._upAxis){
|
|
530
531
|
case 0:
|
|
@@ -538,33 +539,41 @@ var ShapeFlag;
|
|
|
538
539
|
break;
|
|
539
540
|
}
|
|
540
541
|
if (rotation) {
|
|
541
|
-
Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z,
|
|
542
|
-
Quaternion.multiply(
|
|
542
|
+
Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
|
|
543
|
+
Quaternion.multiply(physXRotation, axis, physXRotation);
|
|
543
544
|
} else {
|
|
544
|
-
|
|
545
|
+
physXRotation.copyFrom(axis);
|
|
545
546
|
}
|
|
546
547
|
this._setLocalPose();
|
|
547
548
|
};
|
|
548
549
|
/**
|
|
549
550
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
550
551
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
551
|
-
|
|
552
|
-
this.
|
|
552
|
+
PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
|
|
553
|
+
var geometry = this._pxGeometry;
|
|
553
554
|
switch(this._upAxis){
|
|
554
555
|
case 0:
|
|
555
|
-
|
|
556
|
-
|
|
556
|
+
geometry.radius = this._radius * Math.max(scale.y, scale.z);
|
|
557
|
+
geometry.halfHeight = this._halfHeight * scale.x;
|
|
557
558
|
break;
|
|
558
559
|
case 1:
|
|
559
|
-
|
|
560
|
-
|
|
560
|
+
geometry.radius = this._radius * Math.max(scale.x, scale.z);
|
|
561
|
+
geometry.halfHeight = this._halfHeight * scale.y;
|
|
561
562
|
break;
|
|
562
563
|
case 2:
|
|
563
|
-
|
|
564
|
-
|
|
564
|
+
geometry.radius = this._radius * Math.max(scale.x, scale.y);
|
|
565
|
+
geometry.halfHeight = this._halfHeight * scale.z;
|
|
565
566
|
break;
|
|
566
567
|
}
|
|
567
|
-
this._pxShape.setGeometry(
|
|
568
|
+
this._pxShape.setGeometry(geometry);
|
|
569
|
+
var radius = geometry.radius;
|
|
570
|
+
var height = geometry.halfHeight * 2;
|
|
571
|
+
var controllers = this._controllers;
|
|
572
|
+
for(var i = 0, n = controllers.length; i < n; i++){
|
|
573
|
+
var pxController = controllers.get(i)._pxController;
|
|
574
|
+
pxController.setRadius(radius);
|
|
575
|
+
pxController.setHeight(height);
|
|
576
|
+
}
|
|
568
577
|
};
|
|
569
578
|
return PhysXCapsuleColliderShape;
|
|
570
579
|
}(PhysXColliderShape);
|
|
@@ -580,7 +589,11 @@ var /**
|
|
|
580
589
|
/**
|
|
581
590
|
* Base class for character controllers.
|
|
582
591
|
*/ var PhysXCharacterController = /*#__PURE__*/ function() {
|
|
583
|
-
function PhysXCharacterController() {
|
|
592
|
+
function PhysXCharacterController(physXPhysics) {
|
|
593
|
+
this._scaledOffset = new Vector3();
|
|
594
|
+
this._position = null;
|
|
595
|
+
this._physXPhysics = physXPhysics;
|
|
596
|
+
}
|
|
584
597
|
var _proto = PhysXCharacterController.prototype;
|
|
585
598
|
/**
|
|
586
599
|
* {@inheritDoc ICharacterController.move }
|
|
@@ -590,12 +603,17 @@ var /**
|
|
|
590
603
|
/**
|
|
591
604
|
* {@inheritDoc ICharacterController.setWorldPosition }
|
|
592
605
|
*/ _proto.setWorldPosition = function setWorldPosition(position) {
|
|
593
|
-
this.
|
|
606
|
+
this._position = position;
|
|
607
|
+
if (this._pxController) {
|
|
608
|
+
Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
|
|
609
|
+
this._pxController.setPosition(PhysXCharacterController._tempVec);
|
|
610
|
+
}
|
|
594
611
|
};
|
|
595
612
|
/**
|
|
596
613
|
* {@inheritDoc ICharacterController.getWorldPosition }
|
|
597
614
|
*/ _proto.getWorldPosition = function getWorldPosition(position) {
|
|
598
615
|
position.copyFrom(this._pxController.getPosition());
|
|
616
|
+
position.subtract(this._scaledOffset);
|
|
599
617
|
};
|
|
600
618
|
/**
|
|
601
619
|
* {@inheritDoc ICharacterController.setStepOffset }
|
|
@@ -641,12 +659,12 @@ var /**
|
|
|
641
659
|
*/ _proto._createPXController = function _createPXController(pxManager, shape) {
|
|
642
660
|
var desc;
|
|
643
661
|
if (_instanceof(shape, PhysXBoxColliderShape)) {
|
|
644
|
-
desc = new
|
|
662
|
+
desc = new this._physXPhysics._physX.PxBoxControllerDesc();
|
|
645
663
|
desc.halfHeight = shape._halfSize.x;
|
|
646
664
|
desc.halfSideExtent = shape._halfSize.y;
|
|
647
665
|
desc.halfForwardExtent = shape._halfSize.z;
|
|
648
666
|
} else if (_instanceof(shape, PhysXCapsuleColliderShape)) {
|
|
649
|
-
desc = new
|
|
667
|
+
desc = new this._physXPhysics._physX.PxCapsuleControllerDesc();
|
|
650
668
|
desc.radius = shape._radius;
|
|
651
669
|
desc.height = shape._halfHeight * 2;
|
|
652
670
|
desc.climbingMode = 1; // constraint mode
|
|
@@ -655,7 +673,7 @@ var /**
|
|
|
655
673
|
}
|
|
656
674
|
desc.setMaterial(shape._pxMaterials[0]);
|
|
657
675
|
this._pxController = pxManager._getControllerManager().createController(desc);
|
|
658
|
-
this._pxController.
|
|
676
|
+
this._pxController.setUUID(shape._id);
|
|
659
677
|
};
|
|
660
678
|
/**
|
|
661
679
|
* @internal
|
|
@@ -665,13 +683,24 @@ var /**
|
|
|
665
683
|
this._pxController = null;
|
|
666
684
|
}
|
|
667
685
|
};
|
|
686
|
+
/**
|
|
687
|
+
* @internal
|
|
688
|
+
*/ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
|
|
689
|
+
Vector3.multiply(position, scale, this._scaledOffset);
|
|
690
|
+
this.setWorldPosition(this._position);
|
|
691
|
+
};
|
|
668
692
|
return PhysXCharacterController;
|
|
669
693
|
}();
|
|
694
|
+
(function() {
|
|
695
|
+
PhysXCharacterController._tempVec = new Vector3();
|
|
696
|
+
})();
|
|
670
697
|
|
|
671
698
|
/**
|
|
672
699
|
* Abstract class of physical collider.
|
|
673
700
|
*/ var PhysXCollider = /*#__PURE__*/ function() {
|
|
674
|
-
function PhysXCollider() {
|
|
701
|
+
function PhysXCollider(physXPhysics) {
|
|
702
|
+
this._physXPhysics = physXPhysics;
|
|
703
|
+
}
|
|
675
704
|
var _proto = PhysXCollider.prototype;
|
|
676
705
|
/**
|
|
677
706
|
* {@inheritDoc ICollider.addShape }
|
|
@@ -728,11 +757,11 @@ var CollisionDetectionMode;
|
|
|
728
757
|
* A dynamic collider can act with self-defined movement or physical force
|
|
729
758
|
*/ var PhysXDynamicCollider = /*#__PURE__*/ function(PhysXCollider) {
|
|
730
759
|
_inherits(PhysXDynamicCollider, PhysXCollider);
|
|
731
|
-
function PhysXDynamicCollider(position, rotation) {
|
|
760
|
+
function PhysXDynamicCollider(physXPhysics, position, rotation) {
|
|
732
761
|
var _this;
|
|
733
|
-
_this = PhysXCollider.call(this) || this;
|
|
762
|
+
_this = PhysXCollider.call(this, physXPhysics) || this;
|
|
734
763
|
var transform = _this._transform(position, rotation);
|
|
735
|
-
_this._pxActor =
|
|
764
|
+
_this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
|
|
736
765
|
return _this;
|
|
737
766
|
}
|
|
738
767
|
var _proto = PhysXDynamicCollider.prototype;
|
|
@@ -797,18 +826,19 @@ var CollisionDetectionMode;
|
|
|
797
826
|
*/ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
|
|
798
827
|
switch(value){
|
|
799
828
|
case 1:
|
|
800
|
-
this._pxActor.setRigidBodyFlag(
|
|
829
|
+
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
|
|
801
830
|
break;
|
|
802
831
|
case 2:
|
|
803
|
-
this._pxActor.setRigidBodyFlag(
|
|
832
|
+
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
|
|
804
833
|
break;
|
|
805
834
|
case 3:
|
|
806
|
-
this._pxActor.setRigidBodyFlag(
|
|
835
|
+
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
|
|
807
836
|
break;
|
|
808
837
|
case 0:
|
|
809
|
-
this.
|
|
810
|
-
this._pxActor.setRigidBodyFlag(
|
|
811
|
-
this._pxActor.setRigidBodyFlag(
|
|
838
|
+
var physX = this._physXPhysics._physX;
|
|
839
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
|
|
840
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
|
|
841
|
+
this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
|
|
812
842
|
break;
|
|
813
843
|
}
|
|
814
844
|
};
|
|
@@ -816,9 +846,9 @@ var CollisionDetectionMode;
|
|
|
816
846
|
* {@inheritDoc IDynamicCollider.setIsKinematic }
|
|
817
847
|
*/ _proto.setIsKinematic = function setIsKinematic(value) {
|
|
818
848
|
if (value) {
|
|
819
|
-
this._pxActor.setRigidBodyFlag(
|
|
849
|
+
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
|
|
820
850
|
} else {
|
|
821
|
-
this._pxActor.setRigidBodyFlag(
|
|
851
|
+
this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
|
|
822
852
|
}
|
|
823
853
|
};
|
|
824
854
|
/**
|
|
@@ -882,12 +912,17 @@ var CollisionDetectionMode;
|
|
|
882
912
|
/**
|
|
883
913
|
* A manager is a collection of colliders and constraints which can interact.
|
|
884
914
|
*/ var PhysXPhysicsManager = /*#__PURE__*/ function() {
|
|
885
|
-
function PhysXPhysicsManager(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
915
|
+
function PhysXPhysicsManager(physXPhysics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
886
916
|
var _this = this;
|
|
887
917
|
/** @internal */ this._pxControllerManager = null;
|
|
888
918
|
this._currentEvents = new DisorderedArray();
|
|
889
919
|
this._eventMap = {};
|
|
890
920
|
this._eventPool = [];
|
|
921
|
+
this._physXPhysics = physXPhysics;
|
|
922
|
+
var physX = physXPhysics._physX;
|
|
923
|
+
this._pxRaycastHit = new physX.PxRaycastHit();
|
|
924
|
+
this._pxFilterData = new physX.PxQueryFilterData();
|
|
925
|
+
this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4);
|
|
891
926
|
this._onContactEnter = onContactEnter;
|
|
892
927
|
this._onContactExit = onContactExit;
|
|
893
928
|
this._onContactStay = onContactStay;
|
|
@@ -895,31 +930,21 @@ var CollisionDetectionMode;
|
|
|
895
930
|
this._onTriggerExit = onTriggerExit;
|
|
896
931
|
this._onTriggerStay = onTriggerStay;
|
|
897
932
|
var triggerCallback = {
|
|
898
|
-
onContactBegin: function(
|
|
899
|
-
var index1 = obj1.getQueryFilterData().word0;
|
|
900
|
-
var index2 = obj2.getQueryFilterData().word0;
|
|
933
|
+
onContactBegin: function(index1, index2) {
|
|
901
934
|
_this._onContactEnter(index1, index2);
|
|
902
935
|
},
|
|
903
|
-
onContactEnd: function(
|
|
904
|
-
var index1 = obj1.getQueryFilterData().word0;
|
|
905
|
-
var index2 = obj2.getQueryFilterData().word0;
|
|
936
|
+
onContactEnd: function(index1, index2) {
|
|
906
937
|
_this._onContactExit(index1, index2);
|
|
907
938
|
},
|
|
908
|
-
onContactPersist: function(
|
|
909
|
-
var index1 = obj1.getQueryFilterData().word0;
|
|
910
|
-
var index2 = obj2.getQueryFilterData().word0;
|
|
939
|
+
onContactPersist: function(index1, index2) {
|
|
911
940
|
_this._onContactStay(index1, index2);
|
|
912
941
|
},
|
|
913
|
-
onTriggerBegin: function(
|
|
914
|
-
var index1 = obj1.getQueryFilterData().word0;
|
|
915
|
-
var index2 = obj2.getQueryFilterData().word0;
|
|
942
|
+
onTriggerBegin: function(index1, index2) {
|
|
916
943
|
var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
|
|
917
944
|
event.state = 0;
|
|
918
945
|
_this._currentEvents.add(event);
|
|
919
946
|
},
|
|
920
|
-
onTriggerEnd: function(
|
|
921
|
-
var index1 = obj1.getQueryFilterData().word0;
|
|
922
|
-
var index2 = obj2.getQueryFilterData().word0;
|
|
947
|
+
onTriggerEnd: function(index1, index2) {
|
|
923
948
|
var event;
|
|
924
949
|
if (index1 < index2) {
|
|
925
950
|
var subMap = _this._eventMap[index1];
|
|
@@ -933,9 +958,10 @@ var CollisionDetectionMode;
|
|
|
933
958
|
event.state = 2;
|
|
934
959
|
}
|
|
935
960
|
};
|
|
936
|
-
var
|
|
937
|
-
var
|
|
938
|
-
|
|
961
|
+
var pxPhysics = physXPhysics._pxPhysics;
|
|
962
|
+
var physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
|
|
963
|
+
var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, physXSimulationCallbackInstance);
|
|
964
|
+
this._pxScene = pxPhysics.createScene(sceneDesc);
|
|
939
965
|
}
|
|
940
966
|
var _proto = PhysXPhysicsManager.prototype;
|
|
941
967
|
/**
|
|
@@ -1003,11 +1029,10 @@ var CollisionDetectionMode;
|
|
|
1003
1029
|
/**
|
|
1004
1030
|
* {@inheritDoc IPhysicsManager.raycast }
|
|
1005
1031
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
1006
|
-
var pxHitResult =
|
|
1032
|
+
var _this = this, pxHitResult = _this._pxRaycastHit;
|
|
1007
1033
|
distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
|
|
1008
1034
|
var raycastCallback = {
|
|
1009
|
-
preFilter: function(filterData,
|
|
1010
|
-
var index = shape.getQueryFilterData().word0;
|
|
1035
|
+
preFilter: function(filterData, index, actor) {
|
|
1011
1036
|
if (onRaycast(index)) {
|
|
1012
1037
|
return 2; // eBLOCK
|
|
1013
1038
|
} else {
|
|
@@ -1016,13 +1041,13 @@ var CollisionDetectionMode;
|
|
|
1016
1041
|
},
|
|
1017
1042
|
postFilter: function(filterData, hit) {}
|
|
1018
1043
|
};
|
|
1019
|
-
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult,
|
|
1044
|
+
var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback));
|
|
1020
1045
|
if (result && hit != undefined) {
|
|
1021
1046
|
var position = PhysXPhysicsManager._tempPosition, normal = PhysXPhysicsManager._tempNormal;
|
|
1022
1047
|
var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
|
|
1023
1048
|
position.set(pxPosition.x, pxPosition.y, pxPosition.z);
|
|
1024
1049
|
normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
|
|
1025
|
-
hit(pxHitResult.getShape().
|
|
1050
|
+
hit(pxHitResult.getShape().getUUID(), pxHitResult.distance, position, normal);
|
|
1026
1051
|
}
|
|
1027
1052
|
return result;
|
|
1028
1053
|
};
|
|
@@ -1070,11 +1095,6 @@ var CollisionDetectionMode;
|
|
|
1070
1095
|
}
|
|
1071
1096
|
}
|
|
1072
1097
|
};
|
|
1073
|
-
PhysXPhysicsManager._init = function _init() {
|
|
1074
|
-
PhysXPhysicsManager._pxRaycastHit = new PhysXPhysics._physX.PxRaycastHit();
|
|
1075
|
-
PhysXPhysicsManager._pxFilterData = new PhysXPhysics._physX.PxQueryFilterData();
|
|
1076
|
-
PhysXPhysicsManager._pxFilterData.flags = new PhysXPhysics._physX.PxQueryFlags(1 | 2 | 4);
|
|
1077
|
-
};
|
|
1078
1098
|
return PhysXPhysicsManager;
|
|
1079
1099
|
}();
|
|
1080
1100
|
(function() {
|
|
@@ -1112,8 +1132,9 @@ var /**
|
|
|
1112
1132
|
/**
|
|
1113
1133
|
* Physics material describes how to handle colliding objects (friction, bounciness).
|
|
1114
1134
|
*/ var PhysXPhysicsMaterial = /*#__PURE__*/ function() {
|
|
1115
|
-
function PhysXPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
|
|
1116
|
-
|
|
1135
|
+
function PhysXPhysicsMaterial(physXPhysics, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
|
|
1136
|
+
this._physXPhysics = physXPhysics;
|
|
1137
|
+
var pxMaterial = physXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
|
|
1117
1138
|
pxMaterial.setFrictionCombineMode(frictionCombine);
|
|
1118
1139
|
pxMaterial.setRestitutionCombineMode(bounceCombine);
|
|
1119
1140
|
this._pxMaterial = pxMaterial;
|
|
@@ -1166,10 +1187,10 @@ var /**
|
|
|
1166
1187
|
* @remarks Mostly used for object which always stays at the same place and never moves around.
|
|
1167
1188
|
*/ var PhysXStaticCollider = /*#__PURE__*/ function(PhysXCollider) {
|
|
1168
1189
|
_inherits(PhysXStaticCollider, PhysXCollider);
|
|
1169
|
-
function PhysXStaticCollider(position, rotation) {
|
|
1190
|
+
function PhysXStaticCollider(physXPhysics, position, rotation) {
|
|
1170
1191
|
var _this;
|
|
1171
|
-
_this = PhysXCollider.call(this) || this;
|
|
1172
|
-
_this._pxActor =
|
|
1192
|
+
_this = PhysXCollider.call(this, physXPhysics) || this;
|
|
1193
|
+
_this._pxActor = physXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
|
|
1173
1194
|
return _this;
|
|
1174
1195
|
}
|
|
1175
1196
|
return PhysXStaticCollider;
|
|
@@ -1179,23 +1200,16 @@ var /**
|
|
|
1179
1200
|
* Plane collider shape in PhysX.
|
|
1180
1201
|
*/ var PhysXPlaneColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
|
|
1181
1202
|
_inherits(PhysXPlaneColliderShape, PhysXColliderShape1);
|
|
1182
|
-
function PhysXPlaneColliderShape(uniqueID, material) {
|
|
1203
|
+
function PhysXPlaneColliderShape(physXPhysics, uniqueID, material) {
|
|
1183
1204
|
var _this;
|
|
1184
|
-
_this = PhysXColliderShape1.call(this) || this;
|
|
1205
|
+
_this = PhysXColliderShape1.call(this, physXPhysics) || this;
|
|
1185
1206
|
_this._axis = new Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
|
|
1186
|
-
_this.
|
|
1187
|
-
_this._pxGeometry = new
|
|
1207
|
+
_this._physXRotation.copyFrom(_this._axis);
|
|
1208
|
+
_this._pxGeometry = new physXPhysics._physX.PxPlaneGeometry();
|
|
1188
1209
|
_this._initialize(material, uniqueID);
|
|
1189
1210
|
_this._setLocalPose();
|
|
1190
1211
|
return _this;
|
|
1191
1212
|
}
|
|
1192
|
-
var _proto = PhysXPlaneColliderShape.prototype;
|
|
1193
|
-
/**
|
|
1194
|
-
* {@inheritDoc IColliderShape.setWorldScale }
|
|
1195
|
-
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
1196
|
-
this._scale.copyFrom(scale);
|
|
1197
|
-
this._setLocalPose();
|
|
1198
|
-
};
|
|
1199
1213
|
return PhysXPlaneColliderShape;
|
|
1200
1214
|
}(PhysXColliderShape);
|
|
1201
1215
|
|
|
@@ -1203,12 +1217,12 @@ var /**
|
|
|
1203
1217
|
* Sphere collider shape in PhysX.
|
|
1204
1218
|
*/ var PhysXSphereColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
|
|
1205
1219
|
_inherits(PhysXSphereColliderShape, PhysXColliderShape);
|
|
1206
|
-
function PhysXSphereColliderShape(uniqueID, radius, material) {
|
|
1220
|
+
function PhysXSphereColliderShape(physXPhysics, uniqueID, radius, material) {
|
|
1207
1221
|
var _this;
|
|
1208
|
-
_this = PhysXColliderShape.call(this) || this;
|
|
1222
|
+
_this = PhysXColliderShape.call(this, physXPhysics) || this;
|
|
1209
1223
|
_this._maxScale = 1;
|
|
1210
1224
|
_this._radius = radius;
|
|
1211
|
-
_this._pxGeometry = new
|
|
1225
|
+
_this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(_this._radius * _this._maxScale);
|
|
1212
1226
|
_this._initialize(material, uniqueID);
|
|
1213
1227
|
_this._setLocalPose();
|
|
1214
1228
|
return _this;
|
|
@@ -1224,9 +1238,8 @@ var /**
|
|
|
1224
1238
|
/**
|
|
1225
1239
|
* {@inheritDoc IColliderShape.setWorldScale }
|
|
1226
1240
|
*/ _proto.setWorldScale = function setWorldScale(scale) {
|
|
1227
|
-
|
|
1228
|
-
this.
|
|
1229
|
-
this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
|
|
1241
|
+
PhysXColliderShape.prototype.setWorldScale.call(this, scale);
|
|
1242
|
+
this._maxScale = Math.max(scale.x, scale.y);
|
|
1230
1243
|
this._pxGeometry.radius = this._radius * this._maxScale;
|
|
1231
1244
|
this._pxShape.setGeometry(this._pxGeometry);
|
|
1232
1245
|
};
|
|
@@ -1234,21 +1247,26 @@ var /**
|
|
|
1234
1247
|
}(PhysXColliderShape);
|
|
1235
1248
|
|
|
1236
1249
|
/**
|
|
1237
|
-
*
|
|
1238
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
var
|
|
1245
|
-
function PhysXPhysics1() {}
|
|
1250
|
+
* PhysX object creation.
|
|
1251
|
+
*/ var PhysXPhysics = /*#__PURE__*/ function() {
|
|
1252
|
+
function PhysXPhysics(runtimeMode) {
|
|
1253
|
+
if (runtimeMode === void 0) runtimeMode = PhysXRuntimeMode.Auto;
|
|
1254
|
+
this._initializeState = 0;
|
|
1255
|
+
this._runTimeMode = runtimeMode;
|
|
1256
|
+
}
|
|
1257
|
+
var _proto = PhysXPhysics.prototype;
|
|
1246
1258
|
/**
|
|
1247
1259
|
* Initialize PhysXPhysics.
|
|
1248
1260
|
* @param runtimeMode - Runtime mode
|
|
1249
1261
|
* @returns Promise object
|
|
1250
|
-
*/
|
|
1251
|
-
|
|
1262
|
+
*/ _proto.initialize = function initialize() {
|
|
1263
|
+
var _this = this;
|
|
1264
|
+
if (this._initializeState === 2) {
|
|
1265
|
+
return Promise.resolve();
|
|
1266
|
+
} else if (this._initializeState === 1) {
|
|
1267
|
+
return this._initializePromise;
|
|
1268
|
+
}
|
|
1269
|
+
var runtimeMode = this._runTimeMode;
|
|
1252
1270
|
var scriptPromise = new Promise(function(resolve, reject) {
|
|
1253
1271
|
var script = document.createElement("script");
|
|
1254
1272
|
document.body.appendChild(script);
|
|
@@ -1272,107 +1290,115 @@ var PhysXPhysics = /*#__PURE__*/ function() {
|
|
|
1272
1290
|
}
|
|
1273
1291
|
}
|
|
1274
1292
|
if (runtimeMode == PhysXRuntimeMode.JavaScript) {
|
|
1275
|
-
script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/
|
|
1293
|
+
script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/" + version + "/libs/physx.release.js.js";
|
|
1276
1294
|
} else if (runtimeMode == PhysXRuntimeMode.WebAssembly) {
|
|
1277
|
-
script.src = "https://gw.alipayobjects.com/os/lib/
|
|
1295
|
+
script.src = "https://gw.alipayobjects.com/os/lib/galacean/engine-physics-physx/" + version + "/libs/physx.release.js";
|
|
1278
1296
|
}
|
|
1279
1297
|
});
|
|
1280
|
-
|
|
1298
|
+
var initializePromise = new Promise(function(resolve, reject) {
|
|
1281
1299
|
scriptPromise.then(function() {
|
|
1282
1300
|
return window.PHYSX().then(function(PHYSX) {
|
|
1283
|
-
|
|
1301
|
+
_this._init(PHYSX);
|
|
1302
|
+
_this._initializeState = 2;
|
|
1303
|
+
_this._initializePromise = null;
|
|
1284
1304
|
console.log("PhysX loaded.");
|
|
1285
1305
|
resolve();
|
|
1286
1306
|
}, reject);
|
|
1287
1307
|
}, reject).catch(reject);
|
|
1288
1308
|
});
|
|
1309
|
+
this._initializePromise = initializePromise;
|
|
1310
|
+
return initializePromise;
|
|
1289
1311
|
};
|
|
1290
1312
|
/**
|
|
1291
1313
|
* Destroy PhysXPhysics.
|
|
1292
|
-
*/
|
|
1293
|
-
this.
|
|
1314
|
+
*/ _proto.destroy = function destroy() {
|
|
1315
|
+
this._physX.PxCloseExtensions();
|
|
1294
1316
|
this._pxPhysics.release();
|
|
1317
|
+
this._pxFoundation.release();
|
|
1295
1318
|
this._physX = null;
|
|
1296
1319
|
this._pxFoundation = null;
|
|
1297
1320
|
this._pxPhysics = null;
|
|
1298
1321
|
};
|
|
1299
1322
|
/**
|
|
1300
1323
|
* {@inheritDoc IPhysics.createPhysicsManager }
|
|
1301
|
-
*/
|
|
1302
|
-
|
|
1324
|
+
*/ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
|
|
1325
|
+
var manager = new PhysXPhysicsManager(this, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
|
|
1326
|
+
return manager;
|
|
1303
1327
|
};
|
|
1304
1328
|
/**
|
|
1305
1329
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
1306
|
-
*/
|
|
1307
|
-
return new PhysXStaticCollider(position, rotation);
|
|
1330
|
+
*/ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
|
|
1331
|
+
return new PhysXStaticCollider(this, position, rotation);
|
|
1308
1332
|
};
|
|
1309
1333
|
/**
|
|
1310
1334
|
* {@inheritDoc IPhysics.createDynamicCollider }
|
|
1311
|
-
*/
|
|
1312
|
-
return new PhysXDynamicCollider(position, rotation);
|
|
1335
|
+
*/ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
|
|
1336
|
+
return new PhysXDynamicCollider(this, position, rotation);
|
|
1313
1337
|
};
|
|
1314
1338
|
/**
|
|
1315
1339
|
* {@inheritDoc IPhysics.createCharacterController }
|
|
1316
|
-
*/
|
|
1317
|
-
return new PhysXCharacterController();
|
|
1340
|
+
*/ _proto.createCharacterController = function createCharacterController() {
|
|
1341
|
+
return new PhysXCharacterController(this);
|
|
1318
1342
|
};
|
|
1319
1343
|
/**
|
|
1320
1344
|
* {@inheritDoc IPhysics.createPhysicsMaterial }
|
|
1321
|
-
*/
|
|
1322
|
-
return new PhysXPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
|
|
1345
|
+
*/ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
|
|
1346
|
+
return new PhysXPhysicsMaterial(this, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
|
|
1323
1347
|
};
|
|
1324
1348
|
/**
|
|
1325
1349
|
* {@inheritDoc IPhysics.createBoxColliderShape }
|
|
1326
|
-
*/
|
|
1327
|
-
return new PhysXBoxColliderShape(uniqueID, size, material);
|
|
1350
|
+
*/ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
|
|
1351
|
+
return new PhysXBoxColliderShape(this, uniqueID, size, material);
|
|
1328
1352
|
};
|
|
1329
1353
|
/**
|
|
1330
1354
|
* {@inheritDoc IPhysics.createSphereColliderShape }
|
|
1331
|
-
*/
|
|
1332
|
-
return new PhysXSphereColliderShape(uniqueID, radius, material);
|
|
1355
|
+
*/ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
|
|
1356
|
+
return new PhysXSphereColliderShape(this, uniqueID, radius, material);
|
|
1333
1357
|
};
|
|
1334
1358
|
/**
|
|
1335
1359
|
* {@inheritDoc IPhysics.createPlaneColliderShape }
|
|
1336
|
-
*/
|
|
1337
|
-
return new PhysXPlaneColliderShape(uniqueID, material);
|
|
1360
|
+
*/ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
|
|
1361
|
+
return new PhysXPlaneColliderShape(this, uniqueID, material);
|
|
1338
1362
|
};
|
|
1339
1363
|
/**
|
|
1340
1364
|
* {@inheritDoc IPhysics.createCapsuleColliderShape }
|
|
1341
|
-
*/
|
|
1342
|
-
return new PhysXCapsuleColliderShape(uniqueID, radius, height, material);
|
|
1365
|
+
*/ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
|
|
1366
|
+
return new PhysXCapsuleColliderShape(this, uniqueID, radius, height, material);
|
|
1343
1367
|
};
|
|
1344
1368
|
/**
|
|
1345
1369
|
* {@inheritDoc IPhysics.createFixedJoint }
|
|
1346
|
-
*/
|
|
1347
|
-
return new PhysXFixedJoint(collider);
|
|
1370
|
+
*/ _proto.createFixedJoint = function createFixedJoint(collider) {
|
|
1371
|
+
return new PhysXFixedJoint(this, collider);
|
|
1348
1372
|
};
|
|
1349
1373
|
/**
|
|
1350
1374
|
* {@inheritDoc IPhysics.createHingeJoint }
|
|
1351
|
-
*/
|
|
1352
|
-
return new PhysXHingeJoint(collider);
|
|
1375
|
+
*/ _proto.createHingeJoint = function createHingeJoint(collider) {
|
|
1376
|
+
return new PhysXHingeJoint(this, collider);
|
|
1353
1377
|
};
|
|
1354
1378
|
/**
|
|
1355
1379
|
* {@inheritDoc IPhysics.createSpringJoint }
|
|
1356
|
-
*/
|
|
1357
|
-
return new PhysXSpringJoint(collider);
|
|
1380
|
+
*/ _proto.createSpringJoint = function createSpringJoint(collider) {
|
|
1381
|
+
return new PhysXSpringJoint(this, collider);
|
|
1358
1382
|
};
|
|
1359
|
-
|
|
1383
|
+
_proto._init = function _init(physX) {
|
|
1360
1384
|
var version = physX.PX_PHYSICS_VERSION;
|
|
1361
1385
|
var defaultErrorCallback = new physX.PxDefaultErrorCallback();
|
|
1362
1386
|
var allocator = new physX.PxDefaultAllocator();
|
|
1363
1387
|
var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
|
|
1364
1388
|
var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, new physX.PxTolerancesScale(), false, null);
|
|
1365
1389
|
physX.PxInitExtensions(pxPhysics, null);
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
PhysXPhysicsManager._init();
|
|
1390
|
+
this._physX = physX;
|
|
1391
|
+
this._pxFoundation = pxFoundation;
|
|
1392
|
+
this._pxPhysics = pxPhysics;
|
|
1370
1393
|
};
|
|
1371
|
-
return
|
|
1394
|
+
return PhysXPhysics;
|
|
1372
1395
|
}();
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
]
|
|
1396
|
+
var InitializeState;
|
|
1397
|
+
(function(InitializeState) {
|
|
1398
|
+
InitializeState[InitializeState["Uninitialized"] = 0] = "Uninitialized";
|
|
1399
|
+
InitializeState[InitializeState["Initializing"] = 1] = "Initializing";
|
|
1400
|
+
InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
|
|
1401
|
+
})(InitializeState || (InitializeState = {}));
|
|
1376
1402
|
|
|
1377
1403
|
export { PhysXPhysics, PhysXRuntimeMode };
|
|
1378
1404
|
//# sourceMappingURL=module.js.map
|