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