@galacean/engine-physics-physx 1.0.0-alpha.6 → 1.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -1,1360 +1,1409 @@
1
1
  (function (global, factory) {
2
- typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
- typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
- (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global["@galacean/enginePhysicsPhysx"] = {}, global["@galacean/engine"]));
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@galacean/engine')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', '@galacean/engine'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.Galacean = global.Galacean || {}, global.Galacean.PhysicsPhysX = {}), global.Galacean));
5
5
  })(this, (function (exports, engine) { 'use strict';
6
6
 
7
- function _instanceof(left, right) {
8
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
9
- return !!right[Symbol.hasInstance](left);
10
- } else {
11
- return left instanceof right;
7
+ function _instanceof(left, right) {
8
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
9
+ return !!right[Symbol.hasInstance](left);
10
+ } else return left instanceof right;
12
11
  }
13
- }
14
12
 
15
- /**
16
- * PhysX runtime mode.
17
- */ exports.PhysXRuntimeMode = void 0;
18
- (function(PhysXRuntimeMode) {
19
- PhysXRuntimeMode[PhysXRuntimeMode[/** Use webAssembly mode first, if WebAssembly mode is not supported, roll back to JavaScript mode. */ "Auto"] = 0] = "Auto";
20
- PhysXRuntimeMode[PhysXRuntimeMode[/** WebAssembly mode. */ "WebAssembly"] = 1] = "WebAssembly";
21
- PhysXRuntimeMode[PhysXRuntimeMode[/** JavaScript mode. */ "JavaScript"] = 2] = "JavaScript";
22
- })(exports.PhysXRuntimeMode || (exports.PhysXRuntimeMode = {}));
13
+ /**
14
+ * PhysX runtime mode.
15
+ */ exports.PhysXRuntimeMode = void 0;
16
+ (function(PhysXRuntimeMode) {
17
+ PhysXRuntimeMode[PhysXRuntimeMode[/** Use webAssembly mode first, if WebAssembly mode is not supported, roll back to JavaScript mode. */ "Auto"] = 0] = "Auto";
18
+ PhysXRuntimeMode[PhysXRuntimeMode[/** WebAssembly mode. */ "WebAssembly"] = 1] = "WebAssembly";
19
+ PhysXRuntimeMode[PhysXRuntimeMode[/** JavaScript mode. */ "JavaScript"] = 2] = "JavaScript";
20
+ })(exports.PhysXRuntimeMode || (exports.PhysXRuntimeMode = {}));
23
21
 
24
- function setPrototypeOf(o, p) {
25
- setPrototypeOf = Object.setPrototypeOf || function setPrototypeOf(o, p) {
26
- o.__proto__ = p;
27
- return o;
28
- };
29
-
30
- return setPrototypeOf(o, p);
31
- }
22
+ function _set_prototype_of(o, p) {
23
+ _set_prototype_of = Object.setPrototypeOf || function setPrototypeOf(o, p) {
24
+ o.__proto__ = p;
32
25
 
33
- function _setPrototypeOf(o, p) {
34
- return setPrototypeOf(o, p);
35
- }
26
+ return o;
27
+ };
36
28
 
37
- function _inherits(subClass, superClass) {
38
- if (typeof superClass !== "function" && superClass !== null) {
39
- throw new TypeError("Super expression must either be null or a function");
29
+ return _set_prototype_of(o, p);
40
30
  }
41
31
 
42
- subClass.prototype = Object.create(superClass && superClass.prototype, {
43
- constructor: {
44
- value: subClass,
45
- writable: true,
46
- configurable: true
47
- }
48
- });
49
- if (superClass) _setPrototypeOf(subClass, superClass);
50
- }
32
+ function _inherits(subClass, superClass) {
33
+ if (typeof superClass !== "function" && superClass !== null) {
34
+ throw new TypeError("Super expression must either be null or a function");
35
+ }
36
+
37
+ subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } });
51
38
 
52
- /**
53
- * a base interface providing common functionality for PhysX joints
54
- */ var PhysXJoint = /*#__PURE__*/ function() {
55
- function PhysXJoint(physXPhysics) {
56
- this._connectedAnchor = new engine.Vector3();
57
- this._breakForce = Number.MAX_VALUE;
58
- this._breakTorque = Number.MAX_VALUE;
59
- this._physXPhysics = physXPhysics;
60
- }
61
- var _proto = PhysXJoint.prototype;
62
- /**
63
- * {@inheritDoc IJoint.setConnectedCollider }
64
- */ _proto.setConnectedCollider = function setConnectedCollider(value) {
65
- var _this__collider;
66
- this._pxJoint.setActors((value == null ? void 0 : value._pxActor) || null, ((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null);
67
- };
68
- /**
69
- * {@inheritDoc IJoint.setConnectedAnchor }
70
- */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
71
- this._connectedAnchor.copyFrom(value);
72
- this._setLocalPose(0, value, PhysXJoint._defaultQuat);
73
- };
74
- /**
75
- * {@inheritDoc IJoint.setConnectedMassScale }
76
- */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
77
- this._pxJoint.setInvMassScale0(1 / value);
78
- };
79
- /**
80
- * {@inheritDoc IJoint.setConnectedInertiaScale }
81
- */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
82
- this._pxJoint.setInvInertiaScale0(1 / value);
83
- };
84
- /**
85
- * {@inheritDoc IJoint.setMassScale }
86
- */ _proto.setMassScale = function setMassScale(value) {
87
- this._pxJoint.setInvMassScale1(1 / value);
88
- };
89
- /**
90
- * {@inheritDoc IJoint.setInertiaScale }
91
- */ _proto.setInertiaScale = function setInertiaScale(value) {
92
- this._pxJoint.setInvInertiaScale1(1 / value);
93
- };
94
- /**
95
- * {@inheritDoc IJoint.setBreakForce }
96
- */ _proto.setBreakForce = function setBreakForce(value) {
97
- this._breakForce = value;
98
- this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
99
- };
100
- /**
101
- * {@inheritDoc IJoint.setBreakTorque }
102
- */ _proto.setBreakTorque = function setBreakTorque(value) {
103
- this._breakTorque = value;
104
- this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
105
- };
106
- /**
107
- * Set the joint local pose for an actor.
108
- * @param actor 0 for the first actor, 1 for the second actor.
109
- * @param position the local position for the actor this joint
110
- * @param rotation the local rotation for the actor this joint
111
- */ _proto._setLocalPose = function _setLocalPose(actor, position, rotation) {
112
- this._pxJoint.setLocalPose(actor, position, rotation);
113
- };
114
- return PhysXJoint;
115
- }();
116
- PhysXJoint._xAxis = new engine.Vector3(1, 0, 0);
117
- PhysXJoint._defaultVec = new engine.Vector3();
118
- PhysXJoint._defaultQuat = new engine.Quaternion();
39
+ if (superClass) _set_prototype_of(subClass, superClass);
40
+ }
41
+
42
+ /**
43
+ * a base interface providing common functionality for PhysX joints
44
+ */ var PhysXJoint = /*#__PURE__*/ function() {
45
+ function PhysXJoint(physXPhysics) {
46
+ this._connectedAnchor = new engine.Vector3();
47
+ this._breakForce = Number.MAX_VALUE;
48
+ this._breakTorque = Number.MAX_VALUE;
49
+ this._physXPhysics = physXPhysics;
50
+ }
51
+ var _proto = PhysXJoint.prototype;
52
+ /**
53
+ * {@inheritDoc IJoint.setConnectedCollider }
54
+ */ _proto.setConnectedCollider = function setConnectedCollider(value) {
55
+ var _this__collider;
56
+ this._pxJoint.setActors((value == null ? void 0 : value._pxActor) || null, ((_this__collider = this._collider) == null ? void 0 : _this__collider._pxActor) || null);
57
+ };
58
+ /**
59
+ * {@inheritDoc IJoint.setConnectedAnchor }
60
+ */ _proto.setConnectedAnchor = function setConnectedAnchor(value) {
61
+ this._connectedAnchor.copyFrom(value);
62
+ this._setLocalPose(0, value, PhysXJoint._defaultQuat);
63
+ };
64
+ /**
65
+ * {@inheritDoc IJoint.setConnectedMassScale }
66
+ */ _proto.setConnectedMassScale = function setConnectedMassScale(value) {
67
+ this._pxJoint.setInvMassScale0(1 / value);
68
+ };
69
+ /**
70
+ * {@inheritDoc IJoint.setConnectedInertiaScale }
71
+ */ _proto.setConnectedInertiaScale = function setConnectedInertiaScale(value) {
72
+ this._pxJoint.setInvInertiaScale0(1 / value);
73
+ };
74
+ /**
75
+ * {@inheritDoc IJoint.setMassScale }
76
+ */ _proto.setMassScale = function setMassScale(value) {
77
+ this._pxJoint.setInvMassScale1(1 / value);
78
+ };
79
+ /**
80
+ * {@inheritDoc IJoint.setInertiaScale }
81
+ */ _proto.setInertiaScale = function setInertiaScale(value) {
82
+ this._pxJoint.setInvInertiaScale1(1 / value);
83
+ };
84
+ /**
85
+ * {@inheritDoc IJoint.setBreakForce }
86
+ */ _proto.setBreakForce = function setBreakForce(value) {
87
+ this._breakForce = value;
88
+ this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
89
+ };
90
+ /**
91
+ * {@inheritDoc IJoint.setBreakTorque }
92
+ */ _proto.setBreakTorque = function setBreakTorque(value) {
93
+ this._breakTorque = value;
94
+ this._pxJoint.setBreakForce(this._breakForce, this._breakTorque);
95
+ };
96
+ /**
97
+ * Set the joint local pose for an actor.
98
+ * @param actor 0 for the first actor, 1 for the second actor.
99
+ * @param position the local position for the actor this joint
100
+ * @param rotation the local rotation for the actor this joint
101
+ */ _proto._setLocalPose = function _setLocalPose(actor, position, rotation) {
102
+ this._pxJoint.setLocalPose(actor, position, rotation);
103
+ };
104
+ return PhysXJoint;
105
+ }();
106
+ (function() {
107
+ PhysXJoint._xAxis = new engine.Vector3(1, 0, 0);
108
+ })();
109
+ (function() {
110
+ PhysXJoint._defaultVec = new engine.Vector3();
111
+ })();
112
+ (function() {
113
+ PhysXJoint._defaultQuat = new engine.Quaternion();
114
+ })();
119
115
 
120
- /**
121
- * A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
122
- */ var PhysXFixedJoint = /*#__PURE__*/ function(PhysXJoint1) {
123
- _inherits(PhysXFixedJoint, PhysXJoint1);
124
- function PhysXFixedJoint(physXPhysics, collider) {
125
- var _this;
126
- _this = PhysXJoint1.call(this, physXPhysics) || this;
127
- _this._collider = collider;
128
- _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
129
- return _this;
130
- }
131
- return PhysXFixedJoint;
132
- }(PhysXJoint);
116
+ /**
117
+ * A fixed joint permits no relative movement between two colliders. ie the bodies are glued together.
118
+ */ var PhysXFixedJoint = /*#__PURE__*/ function(PhysXJoint1) {
119
+ _inherits(PhysXFixedJoint, PhysXJoint1);
120
+ function PhysXFixedJoint(physXPhysics, collider) {
121
+ var _this;
122
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
123
+ _this._collider = collider;
124
+ _this._pxJoint = physXPhysics._pxPhysics.createFixedJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
125
+ return _this;
126
+ }
127
+ return PhysXFixedJoint;
128
+ }(PhysXJoint);
133
129
 
134
- /**
135
- * A joint which behaves in a similar way to a hinge or axle.
136
- */ var PhysXHingeJoint = /*#__PURE__*/ function(PhysXJoint1) {
137
- _inherits(PhysXHingeJoint, PhysXJoint1);
138
- function PhysXHingeJoint(physXPhysics, collider) {
139
- var _this;
140
- _this = PhysXJoint1.call(this, physXPhysics) || this;
141
- _this._axisRotationQuaternion = new engine.Quaternion();
142
- _this._swingOffset = new engine.Vector3();
143
- _this._velocity = new engine.Vector3();
144
- _this._collider = collider;
145
- _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
146
- return _this;
147
- }
148
- var _proto = PhysXHingeJoint.prototype;
149
- /**
150
- * {@inheritDoc IHingeJoint.setAxis }
151
- */ _proto.setAxis = function setAxis(value) {
152
- var xAxis = PhysXJoint._xAxis;
153
- var axisRotationQuaternion = this._axisRotationQuaternion;
154
- xAxis.set(1, 0, 0);
155
- value.normalize();
156
- var angle = Math.acos(engine.Vector3.dot(xAxis, value));
157
- engine.Vector3.cross(xAxis, value, xAxis);
158
- engine.Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
159
- this._setLocalPose(0, this._swingOffset, axisRotationQuaternion);
160
- };
161
- /**
162
- * {@inheritDoc IHingeJoint.setSwingOffset }
163
- */ _proto.setSwingOffset = function setSwingOffset(value) {
164
- this._swingOffset.copyFrom(value);
165
- this._setLocalPose(1, this._swingOffset, this._axisRotationQuaternion);
166
- };
167
- /**
168
- * {@inheritDoc IHingeJoint.getAngle }
169
- */ _proto.getAngle = function getAngle() {
170
- return this._pxJoint.getAngle();
171
- };
172
- /**
173
- * {@inheritDoc IHingeJoint.getVelocity }
174
- */ _proto.getVelocity = function getVelocity() {
175
- var velocity = this._velocity;
176
- velocity.copyFrom(this._pxJoint.getVelocity());
177
- return velocity;
178
- };
179
- /**
180
- * {@inheritDoc IHingeJoint.setHardLimitCone }
181
- */ _proto.setHardLimit = function setHardLimit(lowerLimit, upperLimit, contactDist) {
182
- this._pxJoint.setHardLimit(lowerLimit, upperLimit, contactDist);
183
- };
184
- /**
185
- * {@inheritDoc IHingeJoint.setHardLimitCone }
186
- */ _proto.setSoftLimit = function setSoftLimit(lowerLimit, upperLimit, stiffness, damping) {
187
- this._pxJoint.setSoftLimit(lowerLimit, upperLimit, stiffness, damping);
188
- };
189
- /**
190
- * {@inheritDoc IHingeJoint.setDriveVelocity }
191
- */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
192
- this._pxJoint.setDriveVelocity(velocity);
193
- };
194
- /**
195
- * {@inheritDoc IHingeJoint.setDriveForceLimit }
196
- */ _proto.setDriveForceLimit = function setDriveForceLimit(limit) {
197
- this._pxJoint.setDriveForceLimit(limit);
198
- };
199
- /**
200
- * {@inheritDoc IHingeJoint.setDriveGearRatio }
201
- */ _proto.setDriveGearRatio = function setDriveGearRatio(ratio) {
202
- this._pxJoint.setDriveGearRatio(ratio);
203
- };
204
- /**
205
- * {@inheritDoc IHingeJoint.setHingeJointFlag }
206
- */ _proto.setHingeJointFlag = function setHingeJointFlag(flag, value) {
207
- this._pxJoint.setRevoluteJointFlag(flag, value);
208
- };
209
- return PhysXHingeJoint;
210
- }(PhysXJoint);
130
+ /**
131
+ * A joint which behaves in a similar way to a hinge or axle.
132
+ */ var PhysXHingeJoint = /*#__PURE__*/ function(PhysXJoint1) {
133
+ _inherits(PhysXHingeJoint, PhysXJoint1);
134
+ function PhysXHingeJoint(physXPhysics, collider) {
135
+ var _this;
136
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
137
+ _this._axisRotationQuaternion = new engine.Quaternion();
138
+ _this._swingOffset = new engine.Vector3();
139
+ _this._velocity = new engine.Vector3();
140
+ _this._collider = collider;
141
+ _this._pxJoint = physXPhysics._pxPhysics.createRevoluteJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
142
+ return _this;
143
+ }
144
+ var _proto = PhysXHingeJoint.prototype;
145
+ /**
146
+ * {@inheritDoc IHingeJoint.setAxis }
147
+ */ _proto.setAxis = function setAxis(value) {
148
+ var xAxis = PhysXJoint._xAxis;
149
+ var axisRotationQuaternion = this._axisRotationQuaternion;
150
+ xAxis.set(1, 0, 0);
151
+ value.normalize();
152
+ var angle = Math.acos(engine.Vector3.dot(xAxis, value));
153
+ engine.Vector3.cross(xAxis, value, xAxis);
154
+ engine.Quaternion.rotationAxisAngle(xAxis, angle, axisRotationQuaternion);
155
+ this._setLocalPose(0, this._swingOffset, axisRotationQuaternion);
156
+ };
157
+ /**
158
+ * {@inheritDoc IHingeJoint.setSwingOffset }
159
+ */ _proto.setSwingOffset = function setSwingOffset(value) {
160
+ this._swingOffset.copyFrom(value);
161
+ this._setLocalPose(1, this._swingOffset, this._axisRotationQuaternion);
162
+ };
163
+ /**
164
+ * {@inheritDoc IHingeJoint.getAngle }
165
+ */ _proto.getAngle = function getAngle() {
166
+ return this._pxJoint.getAngle();
167
+ };
168
+ /**
169
+ * {@inheritDoc IHingeJoint.getVelocity }
170
+ */ _proto.getVelocity = function getVelocity() {
171
+ var velocity = this._velocity;
172
+ velocity.copyFrom(this._pxJoint.getVelocity());
173
+ return velocity;
174
+ };
175
+ /**
176
+ * {@inheritDoc IHingeJoint.setHardLimitCone }
177
+ */ _proto.setHardLimit = function setHardLimit(lowerLimit, upperLimit, contactDist) {
178
+ this._pxJoint.setHardLimit(lowerLimit, upperLimit, contactDist);
179
+ };
180
+ /**
181
+ * {@inheritDoc IHingeJoint.setHardLimitCone }
182
+ */ _proto.setSoftLimit = function setSoftLimit(lowerLimit, upperLimit, stiffness, damping) {
183
+ this._pxJoint.setSoftLimit(lowerLimit, upperLimit, stiffness, damping);
184
+ };
185
+ /**
186
+ * {@inheritDoc IHingeJoint.setDriveVelocity }
187
+ */ _proto.setDriveVelocity = function setDriveVelocity(velocity) {
188
+ this._pxJoint.setDriveVelocity(velocity);
189
+ };
190
+ /**
191
+ * {@inheritDoc IHingeJoint.setDriveForceLimit }
192
+ */ _proto.setDriveForceLimit = function setDriveForceLimit(limit) {
193
+ this._pxJoint.setDriveForceLimit(limit);
194
+ };
195
+ /**
196
+ * {@inheritDoc IHingeJoint.setDriveGearRatio }
197
+ */ _proto.setDriveGearRatio = function setDriveGearRatio(ratio) {
198
+ this._pxJoint.setDriveGearRatio(ratio);
199
+ };
200
+ /**
201
+ * {@inheritDoc IHingeJoint.setHingeJointFlag }
202
+ */ _proto.setHingeJointFlag = function setHingeJointFlag(flag, value) {
203
+ this._pxJoint.setRevoluteJointFlag(flag, value);
204
+ };
205
+ return PhysXHingeJoint;
206
+ }(PhysXJoint);
211
207
 
212
- /**
213
- * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
214
- */ var PhysXSpringJoint = /*#__PURE__*/ function(PhysXJoint1) {
215
- _inherits(PhysXSpringJoint, PhysXJoint1);
216
- function PhysXSpringJoint(physXPhysics, collider) {
217
- var _this;
218
- _this = PhysXJoint1.call(this, physXPhysics) || this;
219
- _this._swingOffset = new engine.Vector3();
220
- _this._collider = collider;
221
- _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
222
- _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
223
- _this._pxJoint.setDistanceJointFlag(4, true); // enable min distance;
224
- _this._pxJoint.setDistanceJointFlag(8, true); // enable spring;
225
- return _this;
226
- }
227
- var _proto = PhysXSpringJoint.prototype;
228
- /**
229
- * {@inheritDoc ISpringJoint.setSwingOffset }
230
- */ _proto.setSwingOffset = function setSwingOffset(value) {
231
- this._swingOffset.copyFrom(value);
232
- this._setLocalPose(1, value, PhysXJoint._defaultQuat);
233
- };
234
- /**
235
- * {@inheritDoc ISpringJoint.setMinDistance }
236
- */ _proto.setMinDistance = function setMinDistance(distance) {
237
- this._pxJoint.setMinDistance(distance);
238
- };
239
- /**
240
- * {@inheritDoc ISpringJoint.setMaxDistance }
241
- */ _proto.setMaxDistance = function setMaxDistance(distance) {
242
- this._pxJoint.setMaxDistance(distance);
243
- };
244
- /**
245
- * {@inheritDoc ISpringJoint.setTolerance }
246
- */ _proto.setTolerance = function setTolerance(tolerance) {
247
- this._pxJoint.setTolerance(tolerance);
248
- };
249
- /**
250
- * {@inheritDoc ISpringJoint.setStiffness }
251
- */ _proto.setStiffness = function setStiffness(stiffness) {
252
- this._pxJoint.setStiffness(stiffness);
253
- };
254
- /**
255
- * {@inheritDoc ISpringJoint.setDamping }
256
- */ _proto.setDamping = function setDamping(damping) {
257
- this._pxJoint.setDamping(damping);
258
- };
259
- return PhysXSpringJoint;
260
- }(PhysXJoint);
208
+ /**
209
+ * a joint that maintains an upper or lower bound (or both) on the distance between two points on different objects
210
+ */ var PhysXSpringJoint = /*#__PURE__*/ function(PhysXJoint1) {
211
+ _inherits(PhysXSpringJoint, PhysXJoint1);
212
+ function PhysXSpringJoint(physXPhysics, collider) {
213
+ var _this;
214
+ _this = PhysXJoint1.call(this, physXPhysics) || this;
215
+ _this._swingOffset = new engine.Vector3();
216
+ _this._collider = collider;
217
+ _this._pxJoint = physXPhysics._pxPhysics.createDistanceJoint(null, PhysXJoint._defaultVec, PhysXJoint._defaultQuat, collider._pxActor, PhysXJoint._defaultVec, PhysXJoint._defaultQuat);
218
+ _this._pxJoint.setDistanceJointFlag(2, true); // enable max distance;
219
+ _this._pxJoint.setDistanceJointFlag(4, true); // enable min distance;
220
+ _this._pxJoint.setDistanceJointFlag(8, true); // enable spring;
221
+ return _this;
222
+ }
223
+ var _proto = PhysXSpringJoint.prototype;
224
+ /**
225
+ * {@inheritDoc ISpringJoint.setSwingOffset }
226
+ */ _proto.setSwingOffset = function setSwingOffset(value) {
227
+ this._swingOffset.copyFrom(value);
228
+ this._setLocalPose(1, value, PhysXJoint._defaultQuat);
229
+ };
230
+ /**
231
+ * {@inheritDoc ISpringJoint.setMinDistance }
232
+ */ _proto.setMinDistance = function setMinDistance(distance) {
233
+ this._pxJoint.setMinDistance(distance);
234
+ };
235
+ /**
236
+ * {@inheritDoc ISpringJoint.setMaxDistance }
237
+ */ _proto.setMaxDistance = function setMaxDistance(distance) {
238
+ this._pxJoint.setMaxDistance(distance);
239
+ };
240
+ /**
241
+ * {@inheritDoc ISpringJoint.setTolerance }
242
+ */ _proto.setTolerance = function setTolerance(tolerance) {
243
+ this._pxJoint.setTolerance(tolerance);
244
+ };
245
+ /**
246
+ * {@inheritDoc ISpringJoint.setStiffness }
247
+ */ _proto.setStiffness = function setStiffness(stiffness) {
248
+ this._pxJoint.setStiffness(stiffness);
249
+ };
250
+ /**
251
+ * {@inheritDoc ISpringJoint.setDamping }
252
+ */ _proto.setDamping = function setDamping(damping) {
253
+ this._pxJoint.setDamping(damping);
254
+ };
255
+ return PhysXSpringJoint;
256
+ }(PhysXJoint);
261
257
 
262
- /**
263
- * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
264
- */ var DisorderedArray = /*#__PURE__*/ function() {
265
- function DisorderedArray(count) {
266
- if (count === void 0) count = 0;
267
- this.length = 0;
268
- this._elements = new Array(count);
269
- }
270
- var _proto = DisorderedArray.prototype;
271
- _proto.add = function add(element) {
272
- if (this.length === this._elements.length) this._elements.push(element);
273
- else this._elements[this.length] = element;
274
- this.length++;
275
- };
276
- _proto.delete = function _delete(element) {
277
- //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
278
- var index = this._elements.indexOf(element);
279
- this.deleteByIndex(index);
280
- };
281
- _proto.get = function get(index) {
282
- if (index >= this.length) {
283
- throw "Index is out of range.";
284
- }
285
- return this._elements[index];
286
- };
287
- /**
288
- *
289
- * @param index
290
- * @returns The replaced item is used to reset its index.
291
- */ _proto.deleteByIndex = function deleteByIndex(index) {
292
- var elements = this._elements;
293
- var end = null;
294
- var lastIndex = this.length - 1;
295
- if (index !== lastIndex) {
296
- end = elements[lastIndex];
297
- elements[index] = end;
298
- }
299
- this.length--;
300
- return end;
301
- };
302
- _proto.garbageCollection = function garbageCollection() {
303
- this._elements.length = this.length;
304
- };
305
- return DisorderedArray;
306
- }();
258
+ /**
259
+ * High-performance unordered array, delete uses exchange method to improve performance, internal capacity only increases.
260
+ */ var DisorderedArray = /*#__PURE__*/ function() {
261
+ function DisorderedArray(count) {
262
+ if (count === void 0) count = 0;
263
+ this.length = 0;
264
+ this._elements = new Array(count);
265
+ }
266
+ var _proto = DisorderedArray.prototype;
267
+ _proto.add = function add(element) {
268
+ if (this.length === this._elements.length) this._elements.push(element);
269
+ else this._elements[this.length] = element;
270
+ this.length++;
271
+ };
272
+ _proto.delete = function _delete(element) {
273
+ //TODO: It can be optimized for custom binary search and other algorithms, currently this._elements>=this.length wastes performance.
274
+ var index = this._elements.indexOf(element);
275
+ this.deleteByIndex(index);
276
+ };
277
+ _proto.get = function get(index) {
278
+ if (index >= this.length) {
279
+ throw "Index is out of range.";
280
+ }
281
+ return this._elements[index];
282
+ };
283
+ /**
284
+ *
285
+ * @param index
286
+ * @returns The replaced item is used to reset its index.
287
+ */ _proto.deleteByIndex = function deleteByIndex(index) {
288
+ var elements = this._elements;
289
+ var end = null;
290
+ var lastIndex = this.length - 1;
291
+ if (index !== lastIndex) {
292
+ end = elements[lastIndex];
293
+ elements[index] = end;
294
+ }
295
+ this.length--;
296
+ return end;
297
+ };
298
+ _proto.garbageCollection = function garbageCollection() {
299
+ this._elements.length = this.length;
300
+ };
301
+ return DisorderedArray;
302
+ }();
307
303
 
308
- var ShapeFlag;
309
- (function(ShapeFlag) {
310
- ShapeFlag[ShapeFlag[/** The shape will partake in collision in the physical simulation. */ "SIMULATION_SHAPE"] = 1] = "SIMULATION_SHAPE";
311
- ShapeFlag[ShapeFlag[/** The shape will partake in scene queries (ray casts, overlap tests, sweeps, ...). */ "SCENE_QUERY_SHAPE"] = 2] = "SCENE_QUERY_SHAPE";
312
- ShapeFlag[ShapeFlag[/** The shape is a trigger which can send reports whenever other shapes enter/leave its volume. */ "TRIGGER_SHAPE"] = 4] = "TRIGGER_SHAPE";
313
- })(ShapeFlag || (ShapeFlag = {}));
314
- /**
315
- * Abstract class for collider shapes.
316
- */ var PhysXColliderShape = /*#__PURE__*/ function() {
317
- function PhysXColliderShape(physXPhysics) {
318
- /** @internal */ this._controllers = new DisorderedArray();
319
- this._scale = new engine.Vector3(1, 1, 1);
320
- this._position = new engine.Vector3();
321
- this._rotation = null;
322
- this._axis = null;
323
- this._physXRotation = new engine.Quaternion();
324
- this._shapeFlags = 2 | 1;
325
- /** @internal */ this._pxMaterials = new Array(1);
326
- this._physXPhysics = physXPhysics;
327
- }
328
- var _proto = PhysXColliderShape.prototype;
329
- /**
330
- * {@inheritDoc IColliderShape.setRotation }
331
- */ _proto.setRotation = function setRotation(value) {
332
- this._rotation = value;
333
- engine.Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
334
- this._axis && engine.Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
335
- this._physXRotation.normalize();
336
- this._setLocalPose();
337
- };
338
- /**
339
- * {@inheritDoc IColliderShape.setPosition }
340
- */ _proto.setPosition = function setPosition(value) {
341
- if (value !== this._position) {
342
- this._position.copyFrom(value);
343
- }
344
- this._setLocalPose();
345
- };
346
- /**
347
- * {@inheritDoc IColliderShape.setContactOffset }
348
- * @default 0.02f * PxTolerancesScale::length
349
- */ _proto.setContactOffset = function setContactOffset(offset) {
350
- this._pxShape.setContactOffset(offset);
351
- var controllers = this._controllers;
352
- for(var i = 0, n = controllers.length; i < n; i++){
353
- controllers.get(i)._pxController.setContactOffset(offset);
354
- }
355
- };
356
- /**
357
- * {@inheritDoc IColliderShape.setMaterial }
358
- */ _proto.setMaterial = function setMaterial(value) {
359
- this._pxMaterials[0] = value._pxMaterial;
360
- this._pxShape.setMaterials(this._pxMaterials);
361
- };
362
- /**
363
- * {@inheritDoc IColliderShape.setIsTrigger }
364
- */ _proto.setIsTrigger = function setIsTrigger(value) {
365
- this._modifyFlag(1, !value);
366
- this._modifyFlag(4, value);
367
- this._setShapeFlags(this._shapeFlags);
368
- };
369
- /**
370
- * {@inheritDoc IColliderShape.destroy }
371
- */ _proto.destroy = function destroy() {
372
- this._pxShape.release();
373
- };
374
- /**
375
- * @internal
376
- */ _proto._setShapeFlags = function _setShapeFlags(flags) {
377
- this._shapeFlags = flags;
378
- this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
379
- };
380
- _proto._setLocalPose = function _setLocalPose() {
381
- var transform = PhysXColliderShape.transform;
382
- engine.Vector3.multiply(this._position, this._scale, transform.translation);
383
- transform.rotation = this._physXRotation;
384
- this._pxShape.setLocalPose(transform);
385
- };
386
- _proto._initialize = function _initialize(material, id) {
387
- this._id = id;
388
- this._pxMaterials[0] = material._pxMaterial;
389
- this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
390
- this._pxShape.setUUID(id);
391
- };
392
- _proto._modifyFlag = function _modifyFlag(flag, value) {
393
- this._shapeFlags = value ? this._shapeFlags | flag : this._shapeFlags & ~flag;
394
- };
395
- return PhysXColliderShape;
396
- }();
397
- PhysXColliderShape.halfSqrt = 0.70710678118655;
398
- PhysXColliderShape.transform = {
399
- translation: new engine.Vector3(),
400
- rotation: null
401
- };
304
+ var ShapeFlag;
305
+ (function(ShapeFlag) {
306
+ ShapeFlag[ShapeFlag[/** The shape will partake in collision in the physical simulation. */ "SIMULATION_SHAPE"] = 1] = "SIMULATION_SHAPE";
307
+ ShapeFlag[ShapeFlag[/** The shape will partake in scene queries (ray casts, overlap tests, sweeps, ...). */ "SCENE_QUERY_SHAPE"] = 2] = "SCENE_QUERY_SHAPE";
308
+ ShapeFlag[ShapeFlag[/** The shape is a trigger which can send reports whenever other shapes enter/leave its volume. */ "TRIGGER_SHAPE"] = 4] = "TRIGGER_SHAPE";
309
+ })(ShapeFlag || (ShapeFlag = {}));
310
+ /**
311
+ * Abstract class for collider shapes.
312
+ */ var PhysXColliderShape = /*#__PURE__*/ function() {
313
+ function PhysXColliderShape(physXPhysics) {
314
+ /** @internal */ this._controllers = new DisorderedArray();
315
+ this._scale = new engine.Vector3(1, 1, 1);
316
+ this._position = new engine.Vector3();
317
+ this._rotation = null;
318
+ this._axis = null;
319
+ this._physXRotation = new engine.Quaternion();
320
+ this._shapeFlags = 2 | 1;
321
+ /** @internal */ this._pxMaterials = new Array(1);
322
+ this._physXPhysics = physXPhysics;
323
+ }
324
+ var _proto = PhysXColliderShape.prototype;
325
+ /**
326
+ * {@inheritDoc IColliderShape.setRotation }
327
+ */ _proto.setRotation = function setRotation(value) {
328
+ this._rotation = value;
329
+ engine.Quaternion.rotationYawPitchRoll(value.x, value.y, value.z, this._physXRotation);
330
+ this._axis && engine.Quaternion.multiply(this._physXRotation, this._axis, this._physXRotation);
331
+ this._physXRotation.normalize();
332
+ this._setLocalPose();
333
+ };
334
+ /**
335
+ * {@inheritDoc IColliderShape.setPosition }
336
+ */ _proto.setPosition = function setPosition(value) {
337
+ if (value !== this._position) {
338
+ this._position.copyFrom(value);
339
+ }
340
+ var controllers = this._controllers;
341
+ for(var i = 0, n = controllers.length; i < n; i++){
342
+ controllers.get(i)._pxController.setLocalPosition(this._position, this._scale);
343
+ }
344
+ this._setLocalPose();
345
+ };
346
+ /**
347
+ * {@inheritDoc IColliderShape.setWorldScale }
348
+ */ _proto.setWorldScale = function setWorldScale(scale) {
349
+ this._scale.copyFrom(scale);
350
+ this._setLocalPose();
351
+ var controllers = this._controllers;
352
+ for(var i = 0, n = controllers.length; i < n; i++){
353
+ controllers.get(i)._setLocalPosition(this._position, this._scale);
354
+ }
355
+ };
356
+ /**
357
+ * {@inheritDoc IColliderShape.setContactOffset }
358
+ * @default 0.02f * PxTolerancesScale::length
359
+ */ _proto.setContactOffset = function setContactOffset(offset) {
360
+ this._pxShape.setContactOffset(offset);
361
+ var controllers = this._controllers;
362
+ for(var i = 0, n = controllers.length; i < n; i++){
363
+ controllers.get(i)._pxController.setContactOffset(offset);
364
+ }
365
+ };
366
+ /**
367
+ * {@inheritDoc IColliderShape.setMaterial }
368
+ */ _proto.setMaterial = function setMaterial(value) {
369
+ this._pxMaterials[0] = value._pxMaterial;
370
+ this._pxShape.setMaterials(this._pxMaterials);
371
+ };
372
+ /**
373
+ * {@inheritDoc IColliderShape.setIsTrigger }
374
+ */ _proto.setIsTrigger = function setIsTrigger(value) {
375
+ this._modifyFlag(1, !value);
376
+ this._modifyFlag(4, value);
377
+ this._setShapeFlags(this._shapeFlags);
378
+ };
379
+ /**
380
+ * {@inheritDoc IColliderShape.destroy }
381
+ */ _proto.destroy = function destroy() {
382
+ this._pxShape.release();
383
+ };
384
+ /**
385
+ * @internal
386
+ */ _proto._setShapeFlags = function _setShapeFlags(flags) {
387
+ this._shapeFlags = flags;
388
+ this._pxShape.setFlags(new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
389
+ };
390
+ _proto._setLocalPose = function _setLocalPose() {
391
+ var transform = PhysXColliderShape.transform;
392
+ engine.Vector3.multiply(this._position, this._scale, transform.translation);
393
+ transform.rotation = this._physXRotation;
394
+ this._pxShape.setLocalPose(transform);
395
+ };
396
+ _proto._initialize = function _initialize(material, id) {
397
+ this._id = id;
398
+ this._pxMaterials[0] = material._pxMaterial;
399
+ this._pxShape = this._physXPhysics._pxPhysics.createShape(this._pxGeometry, material._pxMaterial, true, new this._physXPhysics._physX.PxShapeFlags(this._shapeFlags));
400
+ this._pxShape.setUUID(id);
401
+ };
402
+ _proto._modifyFlag = function _modifyFlag(flag, value) {
403
+ this._shapeFlags = value ? this._shapeFlags | flag : this._shapeFlags & ~flag;
404
+ };
405
+ return PhysXColliderShape;
406
+ }();
407
+ (function() {
408
+ PhysXColliderShape.halfSqrt = 0.70710678118655;
409
+ })();
410
+ (function() {
411
+ PhysXColliderShape.transform = {
412
+ translation: new engine.Vector3(),
413
+ rotation: null
414
+ };
415
+ })();
402
416
 
403
- /**
404
- * Box collider shape in PhysX.
405
- */ var PhysXBoxColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
406
- _inherits(PhysXBoxColliderShape, PhysXColliderShape);
407
- function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
408
- var _this;
409
- _this = PhysXColliderShape.call(this, physXPhysics) || this;
410
- /** @internal */ _this._halfSize = new engine.Vector3();
411
- _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
412
- _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(_this._halfSize.x * _this._scale.x, _this._halfSize.y * _this._scale.y, _this._halfSize.z * _this._scale.z);
413
- _this._initialize(material, uniqueID);
414
- _this._setLocalPose();
415
- return _this;
416
- }
417
- var _proto = PhysXBoxColliderShape.prototype;
418
- /**
419
- * {@inheritDoc IBoxColliderShape.setSize }
420
- */ _proto.setSize = function setSize(value) {
421
- this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
422
- engine.Vector3.multiply(this._halfSize, this._scale, PhysXBoxColliderShape._tempHalfExtents);
423
- this._pxGeometry.halfExtents = PhysXBoxColliderShape._tempHalfExtents;
424
- this._pxShape.setGeometry(this._pxGeometry);
425
- var controllers = this._controllers;
426
- for(var i = 0, n = controllers.length; i < n; i++){
427
- var pxController = controllers.get(i)._pxController;
428
- pxController.setHalfHeight(this._halfSize.x);
429
- pxController.setHalfSideExtent(this._halfSize.y);
430
- pxController.setHalfForwardExtent(this._halfSize.z);
431
- }
432
- };
433
- /**
434
- * {@inheritDoc IColliderShape.setWorldScale }
435
- */ _proto.setWorldScale = function setWorldScale(scale) {
436
- this._scale.copyFrom(scale);
437
- this._setLocalPose();
438
- engine.Vector3.multiply(this._halfSize, this._scale, PhysXBoxColliderShape._tempHalfExtents);
439
- this._pxGeometry.halfExtents = PhysXBoxColliderShape._tempHalfExtents;
440
- this._pxShape.setGeometry(this._pxGeometry);
441
- };
442
- return PhysXBoxColliderShape;
443
- }(PhysXColliderShape);
444
- PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
417
+ /**
418
+ * Box collider shape in PhysX.
419
+ */ var PhysXBoxColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
420
+ _inherits(PhysXBoxColliderShape, PhysXColliderShape);
421
+ function PhysXBoxColliderShape(physXPhysics, uniqueID, size, material) {
422
+ var _this;
423
+ _this = PhysXColliderShape.call(this, physXPhysics) || this;
424
+ /** @internal */ _this._halfSize = new engine.Vector3();
425
+ _this._halfSize.set(size.x * 0.5, size.y * 0.5, size.z * 0.5);
426
+ _this._pxGeometry = new physXPhysics._physX.PxBoxGeometry(_this._halfSize.x * _this._scale.x, _this._halfSize.y * _this._scale.y, _this._halfSize.z * _this._scale.z);
427
+ _this._initialize(material, uniqueID);
428
+ _this._setLocalPose();
429
+ return _this;
430
+ }
431
+ var _proto = PhysXBoxColliderShape.prototype;
432
+ /**
433
+ * {@inheritDoc IBoxColliderShape.setSize }
434
+ */ _proto.setSize = function setSize(value) {
435
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
436
+ this._halfSize.set(value.x * 0.5, value.y * 0.5, value.z * 0.5);
437
+ engine.Vector3.multiply(this._halfSize, this._scale, tempExtents);
438
+ this._pxGeometry.halfExtents = tempExtents;
439
+ this._pxShape.setGeometry(this._pxGeometry);
440
+ this._updateController(tempExtents);
441
+ };
442
+ /**
443
+ * {@inheritDoc IColliderShape.setWorldScale }
444
+ */ _proto.setWorldScale = function setWorldScale(scale) {
445
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
446
+ var tempExtents = PhysXBoxColliderShape._tempHalfExtents;
447
+ engine.Vector3.multiply(this._halfSize, this._scale, tempExtents);
448
+ this._pxGeometry.halfExtents = tempExtents;
449
+ this._pxShape.setGeometry(this._pxGeometry);
450
+ this._updateController(tempExtents);
451
+ };
452
+ _proto._updateController = function _updateController(extents) {
453
+ var controllers = this._controllers;
454
+ for(var i = 0, n = controllers.length; i < n; i++){
455
+ var pxController = controllers.get(i)._pxController;
456
+ pxController.setHalfHeight(extents.x);
457
+ pxController.setHalfSideExtent(extents.y);
458
+ pxController.setHalfForwardExtent(extents.z);
459
+ }
460
+ };
461
+ return PhysXBoxColliderShape;
462
+ }(PhysXColliderShape);
463
+ (function() {
464
+ PhysXBoxColliderShape._tempHalfExtents = new engine.Vector3();
465
+ })();
445
466
 
446
- /**
447
- * Capsule collider shape in PhysX.
448
- */ var PhysXCapsuleColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
449
- _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
450
- function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
451
- var _this;
452
- _this = PhysXColliderShape1.call(this, physXPhysics) || this;
453
- _this._upAxis = /** Up axis is Y. */ 1;
454
- _this._radius = radius;
455
- _this._halfHeight = height * 0.5;
456
- _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
457
- _this._physXRotation.copyFrom(_this._axis);
458
- _this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(_this._radius, _this._halfHeight);
459
- _this._initialize(material, uniqueID);
460
- _this._setLocalPose();
461
- return _this;
462
- }
463
- var _proto = PhysXCapsuleColliderShape.prototype;
464
- /**
465
- * {@inheritDoc ICapsuleColliderShape.setRadius }
466
- */ _proto.setRadius = function setRadius(value) {
467
- this._radius = value;
468
- switch(this._upAxis){
469
- case /** Up axis is X. */ 0:
470
- this._pxGeometry.radius = this._radius * Math.max(this._scale.y, this._scale.z);
471
- break;
472
- case 1:
473
- this._pxGeometry.radius = this._radius * Math.max(this._scale.x, this._scale.z);
474
- break;
475
- case /** Up axis is Z. */ 2:
476
- this._pxGeometry.radius = this._radius * Math.max(this._scale.x, this._scale.y);
477
- break;
478
- }
479
- this._pxShape.setGeometry(this._pxGeometry);
480
- var controllers = this._controllers;
481
- for(var i = 0, n = controllers.length; i < n; i++){
482
- controllers.get(i)._pxController.setRadius(value);
483
- }
484
- };
485
- /**
486
- * {@inheritDoc ICapsuleColliderShape.setHeight }
487
- */ _proto.setHeight = function setHeight(value) {
488
- this._halfHeight = value * 0.5;
489
- switch(this._upAxis){
490
- case 0:
491
- this._pxGeometry.halfHeight = this._halfHeight * this._scale.x;
492
- break;
493
- case 1:
494
- this._pxGeometry.halfHeight = this._halfHeight * this._scale.y;
495
- break;
496
- case 2:
497
- this._pxGeometry.halfHeight = this._halfHeight * this._scale.z;
498
- break;
499
- }
500
- this._pxShape.setGeometry(this._pxGeometry);
501
- var controllers = this._controllers;
502
- for(var i = 0, n = controllers.length; i < n; i++){
503
- controllers.get(i)._pxController.setHeight(value);
504
- }
505
- };
506
- /**
507
- * {@inheritDoc ICapsuleColliderShape.setUpAxis }
508
- */ _proto.setUpAxis = function setUpAxis(upAxis) {
509
- var _this = this, rotation = _this._rotation, axis = _this._axis, physXRotation = _this._physXRotation;
510
- this._upAxis = upAxis;
511
- switch(this._upAxis){
512
- case 0:
513
- axis.set(0, 0, 0, 1);
514
- break;
515
- case 1:
516
- axis.set(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
517
- break;
518
- case 2:
519
- axis.set(0, PhysXColliderShape.halfSqrt, 0, PhysXColliderShape.halfSqrt);
520
- break;
521
- }
522
- if (rotation) {
523
- engine.Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
524
- engine.Quaternion.multiply(physXRotation, axis, physXRotation);
525
- } else {
526
- physXRotation.copyFrom(axis);
527
- }
528
- this._setLocalPose();
529
- };
530
- /**
531
- * {@inheritDoc IColliderShape.setWorldScale }
532
- */ _proto.setWorldScale = function setWorldScale(scale) {
533
- this._scale.copyFrom(scale);
534
- this._setLocalPose();
535
- switch(this._upAxis){
536
- case 0:
537
- this._pxGeometry.radius = this._radius * Math.max(scale.y, scale.z);
538
- this._pxGeometry.halfHeight = this._halfHeight * scale.x;
539
- break;
540
- case 1:
541
- this._pxGeometry.radius = this._radius * Math.max(scale.x, scale.z);
542
- this._pxGeometry.halfHeight = this._halfHeight * scale.y;
543
- break;
544
- case 2:
545
- this._pxGeometry.radius = this._radius * Math.max(scale.x, scale.y);
546
- this._pxGeometry.halfHeight = this._halfHeight * scale.z;
547
- break;
548
- }
549
- this._pxShape.setGeometry(this._pxGeometry);
550
- };
551
- return PhysXCapsuleColliderShape;
552
- }(PhysXColliderShape);
553
- var /**
554
- * The up axis of the collider shape.
555
- */ ColliderShapeUpAxis;
556
- (function(ColliderShapeUpAxis) {
557
- ColliderShapeUpAxis[ColliderShapeUpAxis["X"] = 0] = "X";
558
- ColliderShapeUpAxis[ColliderShapeUpAxis["Y"] = 1] = "Y";
559
- ColliderShapeUpAxis[ColliderShapeUpAxis["Z"] = 2] = "Z";
560
- })(ColliderShapeUpAxis || (ColliderShapeUpAxis = {}));
467
+ /**
468
+ * Capsule collider shape in PhysX.
469
+ */ var PhysXCapsuleColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
470
+ _inherits(PhysXCapsuleColliderShape, PhysXColliderShape1);
471
+ function PhysXCapsuleColliderShape(physXPhysics, uniqueID, radius, height, material) {
472
+ var _this;
473
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this;
474
+ _this._upAxis = /** Up axis is Y. */ 1;
475
+ _this._radius = radius;
476
+ _this._halfHeight = height * 0.5;
477
+ _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
478
+ _this._physXRotation.copyFrom(_this._axis);
479
+ _this._pxGeometry = new physXPhysics._physX.PxCapsuleGeometry(_this._radius, _this._halfHeight);
480
+ _this._initialize(material, uniqueID);
481
+ _this._setLocalPose();
482
+ return _this;
483
+ }
484
+ var _proto = PhysXCapsuleColliderShape.prototype;
485
+ /**
486
+ * {@inheritDoc ICapsuleColliderShape.setRadius }
487
+ */ _proto.setRadius = function setRadius(value) {
488
+ this._radius = value;
489
+ switch(this._upAxis){
490
+ case /** Up axis is X. */ 0:
491
+ this._pxGeometry.radius = this._radius * Math.max(this._scale.y, this._scale.z);
492
+ break;
493
+ case 1:
494
+ this._pxGeometry.radius = this._radius * Math.max(this._scale.x, this._scale.z);
495
+ break;
496
+ case /** Up axis is Z. */ 2:
497
+ this._pxGeometry.radius = this._radius * Math.max(this._scale.x, this._scale.y);
498
+ break;
499
+ }
500
+ this._pxShape.setGeometry(this._pxGeometry);
501
+ var radius = this._pxGeometry.radius;
502
+ var controllers = this._controllers;
503
+ for(var i = 0, n = controllers.length; i < n; i++){
504
+ controllers.get(i)._pxController.setRadius(radius);
505
+ }
506
+ };
507
+ /**
508
+ * {@inheritDoc ICapsuleColliderShape.setHeight }
509
+ */ _proto.setHeight = function setHeight(value) {
510
+ this._halfHeight = value * 0.5;
511
+ switch(this._upAxis){
512
+ case 0:
513
+ this._pxGeometry.halfHeight = this._halfHeight * this._scale.x;
514
+ break;
515
+ case 1:
516
+ this._pxGeometry.halfHeight = this._halfHeight * this._scale.y;
517
+ break;
518
+ case 2:
519
+ this._pxGeometry.halfHeight = this._halfHeight * this._scale.z;
520
+ break;
521
+ }
522
+ this._pxShape.setGeometry(this._pxGeometry);
523
+ var height = this._pxGeometry.halfHeight * 2;
524
+ var controllers = this._controllers;
525
+ for(var i = 0, n = controllers.length; i < n; i++){
526
+ controllers.get(i)._pxController.setHeight(height);
527
+ }
528
+ };
529
+ /**
530
+ * {@inheritDoc ICapsuleColliderShape.setUpAxis }
531
+ */ _proto.setUpAxis = function setUpAxis(upAxis) {
532
+ var _this = this, rotation = _this._rotation, axis = _this._axis, physXRotation = _this._physXRotation;
533
+ this._upAxis = upAxis;
534
+ switch(this._upAxis){
535
+ case 0:
536
+ axis.set(0, 0, 0, 1);
537
+ break;
538
+ case 1:
539
+ axis.set(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
540
+ break;
541
+ case 2:
542
+ axis.set(0, PhysXColliderShape.halfSqrt, 0, PhysXColliderShape.halfSqrt);
543
+ break;
544
+ }
545
+ if (rotation) {
546
+ engine.Quaternion.rotationYawPitchRoll(rotation.x, rotation.y, rotation.z, physXRotation);
547
+ engine.Quaternion.multiply(physXRotation, axis, physXRotation);
548
+ } else {
549
+ physXRotation.copyFrom(axis);
550
+ }
551
+ this._setLocalPose();
552
+ };
553
+ /**
554
+ * {@inheritDoc IColliderShape.setWorldScale }
555
+ */ _proto.setWorldScale = function setWorldScale(scale) {
556
+ PhysXColliderShape1.prototype.setWorldScale.call(this, scale);
557
+ var geometry = this._pxGeometry;
558
+ switch(this._upAxis){
559
+ case 0:
560
+ geometry.radius = this._radius * Math.max(scale.y, scale.z);
561
+ geometry.halfHeight = this._halfHeight * scale.x;
562
+ break;
563
+ case 1:
564
+ geometry.radius = this._radius * Math.max(scale.x, scale.z);
565
+ geometry.halfHeight = this._halfHeight * scale.y;
566
+ break;
567
+ case 2:
568
+ geometry.radius = this._radius * Math.max(scale.x, scale.y);
569
+ geometry.halfHeight = this._halfHeight * scale.z;
570
+ break;
571
+ }
572
+ this._pxShape.setGeometry(geometry);
573
+ var radius = geometry.radius;
574
+ var height = geometry.halfHeight * 2;
575
+ var controllers = this._controllers;
576
+ for(var i = 0, n = controllers.length; i < n; i++){
577
+ var pxController = controllers.get(i)._pxController;
578
+ pxController.setRadius(radius);
579
+ pxController.setHeight(height);
580
+ }
581
+ };
582
+ return PhysXCapsuleColliderShape;
583
+ }(PhysXColliderShape);
584
+ var /**
585
+ * The up axis of the collider shape.
586
+ */ ColliderShapeUpAxis;
587
+ (function(ColliderShapeUpAxis) {
588
+ ColliderShapeUpAxis[ColliderShapeUpAxis["X"] = 0] = "X";
589
+ ColliderShapeUpAxis[ColliderShapeUpAxis["Y"] = 1] = "Y";
590
+ ColliderShapeUpAxis[ColliderShapeUpAxis["Z"] = 2] = "Z";
591
+ })(ColliderShapeUpAxis || (ColliderShapeUpAxis = {}));
561
592
 
562
- /**
563
- * Base class for character controllers.
564
- */ var PhysXCharacterController = /*#__PURE__*/ function() {
565
- function PhysXCharacterController(physXPhysics) {
566
- this._physXPhysics = physXPhysics;
567
- }
568
- var _proto = PhysXCharacterController.prototype;
569
- /**
570
- * {@inheritDoc ICharacterController.move }
571
- */ _proto.move = function move(disp, minDist, elapsedTime) {
572
- return this._pxController.move(disp, minDist, elapsedTime);
573
- };
574
- /**
575
- * {@inheritDoc ICharacterController.setWorldPosition }
576
- */ _proto.setWorldPosition = function setWorldPosition(position) {
577
- this._pxController && this._pxController.setPosition(position);
578
- };
579
- /**
580
- * {@inheritDoc ICharacterController.getWorldPosition }
581
- */ _proto.getWorldPosition = function getWorldPosition(position) {
582
- position.copyFrom(this._pxController.getPosition());
583
- };
584
- /**
585
- * {@inheritDoc ICharacterController.setStepOffset }
586
- */ _proto.setStepOffset = function setStepOffset(offset) {
587
- this._pxController.setStepOffset(offset);
588
- };
589
- /**
590
- * {@inheritDoc ICharacterController.setNonWalkableMode }
591
- */ _proto.setNonWalkableMode = function setNonWalkableMode(flag) {
592
- this._pxController.setNonWalkableMode(flag);
593
- };
594
- /**
595
- * {@inheritDoc ICharacterController.setUpDirection }
596
- */ _proto.setUpDirection = function setUpDirection(up) {
597
- this._pxController.setUpDirection(up);
598
- };
599
- /**
600
- * {@inheritDoc ICharacterController.setSlopeLimit }
601
- */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
602
- this._pxController.setSlopeLimit(slopeLimit);
603
- };
604
- /**
605
- * {@inheritDoc ICharacterController.addShape }
606
- */ _proto.addShape = function addShape(shape) {
607
- this._pxManager && this._createPXController(this._pxManager, shape);
608
- this._shape = shape;
609
- shape._controllers.add(this);
610
- };
611
- /**
612
- * {@inheritDoc ICharacterController.removeShape }
613
- */ _proto.removeShape = function removeShape(shape) {
614
- this._destroyPXController();
615
- this._shape = null;
616
- shape._controllers.delete(this);
617
- };
618
- /**
619
- * {@inheritDoc ICharacterController.destroy }
620
- */ _proto.destroy = function destroy() {
621
- this._destroyPXController();
622
- };
623
- /**
624
- * @internal
625
- */ _proto._createPXController = function _createPXController(pxManager, shape) {
626
- var desc;
627
- if (_instanceof(shape, PhysXBoxColliderShape)) {
628
- desc = new this._physXPhysics._physX.PxBoxControllerDesc();
629
- desc.halfHeight = shape._halfSize.x;
630
- desc.halfSideExtent = shape._halfSize.y;
631
- desc.halfForwardExtent = shape._halfSize.z;
632
- } else if (_instanceof(shape, PhysXCapsuleColliderShape)) {
633
- desc = new this._physXPhysics._physX.PxCapsuleControllerDesc();
634
- desc.radius = shape._radius;
635
- desc.height = shape._halfHeight * 2;
636
- desc.climbingMode = 1; // constraint mode
637
- } else {
638
- throw "unsupported shape type";
639
- }
640
- desc.setMaterial(shape._pxMaterials[0]);
641
- this._pxController = pxManager._getControllerManager().createController(desc);
642
- this._pxController.setUUID(shape._id);
643
- };
644
- /**
645
- * @internal
646
- */ _proto._destroyPXController = function _destroyPXController() {
647
- if (this._pxController) {
648
- this._pxController.release();
649
- this._pxController = null;
650
- }
651
- };
652
- return PhysXCharacterController;
653
- }();
593
+ /**
594
+ * Base class for character controllers.
595
+ */ var PhysXCharacterController = /*#__PURE__*/ function() {
596
+ function PhysXCharacterController(physXPhysics) {
597
+ this._scaledOffset = new engine.Vector3();
598
+ this._position = null;
599
+ this._physXPhysics = physXPhysics;
600
+ }
601
+ var _proto = PhysXCharacterController.prototype;
602
+ /**
603
+ * {@inheritDoc ICharacterController.move }
604
+ */ _proto.move = function move(disp, minDist, elapsedTime) {
605
+ return this._pxController.move(disp, minDist, elapsedTime);
606
+ };
607
+ /**
608
+ * {@inheritDoc ICharacterController.setWorldPosition }
609
+ */ _proto.setWorldPosition = function setWorldPosition(position) {
610
+ this._position = position;
611
+ if (this._pxController) {
612
+ engine.Vector3.add(position, this._scaledOffset, PhysXCharacterController._tempVec);
613
+ this._pxController.setPosition(PhysXCharacterController._tempVec);
614
+ }
615
+ };
616
+ /**
617
+ * {@inheritDoc ICharacterController.getWorldPosition }
618
+ */ _proto.getWorldPosition = function getWorldPosition(position) {
619
+ position.copyFrom(this._pxController.getPosition());
620
+ position.subtract(this._scaledOffset);
621
+ };
622
+ /**
623
+ * {@inheritDoc ICharacterController.setStepOffset }
624
+ */ _proto.setStepOffset = function setStepOffset(offset) {
625
+ this._pxController.setStepOffset(offset);
626
+ };
627
+ /**
628
+ * {@inheritDoc ICharacterController.setNonWalkableMode }
629
+ */ _proto.setNonWalkableMode = function setNonWalkableMode(flag) {
630
+ this._pxController.setNonWalkableMode(flag);
631
+ };
632
+ /**
633
+ * {@inheritDoc ICharacterController.setUpDirection }
634
+ */ _proto.setUpDirection = function setUpDirection(up) {
635
+ this._pxController.setUpDirection(up);
636
+ };
637
+ /**
638
+ * {@inheritDoc ICharacterController.setSlopeLimit }
639
+ */ _proto.setSlopeLimit = function setSlopeLimit(slopeLimit) {
640
+ this._pxController.setSlopeLimit(slopeLimit);
641
+ };
642
+ /**
643
+ * {@inheritDoc ICharacterController.addShape }
644
+ */ _proto.addShape = function addShape(shape) {
645
+ this._pxManager && this._createPXController(this._pxManager, shape);
646
+ this._shape = shape;
647
+ shape._controllers.add(this);
648
+ };
649
+ /**
650
+ * {@inheritDoc ICharacterController.removeShape }
651
+ */ _proto.removeShape = function removeShape(shape) {
652
+ this._destroyPXController();
653
+ this._shape = null;
654
+ shape._controllers.delete(this);
655
+ };
656
+ /**
657
+ * {@inheritDoc ICharacterController.destroy }
658
+ */ _proto.destroy = function destroy() {
659
+ this._destroyPXController();
660
+ };
661
+ /**
662
+ * @internal
663
+ */ _proto._createPXController = function _createPXController(pxManager, shape) {
664
+ var desc;
665
+ if (_instanceof(shape, PhysXBoxColliderShape)) {
666
+ desc = new this._physXPhysics._physX.PxBoxControllerDesc();
667
+ desc.halfHeight = shape._halfSize.x;
668
+ desc.halfSideExtent = shape._halfSize.y;
669
+ desc.halfForwardExtent = shape._halfSize.z;
670
+ } else if (_instanceof(shape, PhysXCapsuleColliderShape)) {
671
+ desc = new this._physXPhysics._physX.PxCapsuleControllerDesc();
672
+ desc.radius = shape._radius;
673
+ desc.height = shape._halfHeight * 2;
674
+ desc.climbingMode = 1; // constraint mode
675
+ } else {
676
+ throw "unsupported shape type";
677
+ }
678
+ desc.setMaterial(shape._pxMaterials[0]);
679
+ this._pxController = pxManager._getControllerManager().createController(desc);
680
+ this._pxController.setUUID(shape._id);
681
+ };
682
+ /**
683
+ * @internal
684
+ */ _proto._destroyPXController = function _destroyPXController() {
685
+ if (this._pxController) {
686
+ this._pxController.release();
687
+ this._pxController = null;
688
+ }
689
+ };
690
+ /**
691
+ * @internal
692
+ */ _proto._setLocalPosition = function _setLocalPosition(position, scale) {
693
+ engine.Vector3.multiply(position, scale, this._scaledOffset);
694
+ this.setWorldPosition(this._position);
695
+ };
696
+ return PhysXCharacterController;
697
+ }();
698
+ (function() {
699
+ PhysXCharacterController._tempVec = new engine.Vector3();
700
+ })();
654
701
 
655
- /**
656
- * Abstract class of physical collider.
657
- */ var PhysXCollider = /*#__PURE__*/ function() {
658
- function PhysXCollider(physXPhysics) {
659
- this._physXPhysics = physXPhysics;
660
- }
661
- var _proto = PhysXCollider.prototype;
662
- /**
663
- * {@inheritDoc ICollider.addShape }
664
- */ _proto.addShape = function addShape(shape) {
665
- this._pxActor.attachShape(shape._pxShape);
666
- };
667
- /**
668
- * {@inheritDoc ICollider.removeShape }
669
- */ _proto.removeShape = function removeShape(shape) {
670
- this._pxActor.detachShape(shape._pxShape, true);
671
- };
672
- /**
673
- * {@inheritDoc ICollider.setWorldTransform }
674
- */ _proto.setWorldTransform = function setWorldTransform(position, rotation) {
675
- this._pxActor.setGlobalPose(this._transform(position, rotation), true);
676
- };
677
- /**
678
- * {@inheritDoc ICollider.getWorldTransform }
679
- */ _proto.getWorldTransform = function getWorldTransform(outPosition, outRotation) {
680
- var transform = this._pxActor.getGlobalPose();
681
- outPosition.set(transform.translation.x, transform.translation.y, transform.translation.z);
682
- outRotation.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
683
- };
684
- /**
685
- * {@inheritDoc ICollider.destroy }
686
- */ _proto.destroy = function destroy() {
687
- this._pxActor.release();
688
- };
689
- /**
690
- * @internal
691
- */ _proto._transform = function _transform(pos, rot) {
692
- var transform = PhysXCollider._tempTransform;
693
- transform.translation = pos;
694
- transform.rotation = rot.normalize();
695
- return transform;
696
- };
697
- return PhysXCollider;
698
- }();
699
- PhysXCollider._tempTransform = {
700
- translation: null,
701
- rotation: null
702
- };
702
+ /**
703
+ * Abstract class of physical collider.
704
+ */ var PhysXCollider = /*#__PURE__*/ function() {
705
+ function PhysXCollider(physXPhysics) {
706
+ this._physXPhysics = physXPhysics;
707
+ }
708
+ var _proto = PhysXCollider.prototype;
709
+ /**
710
+ * {@inheritDoc ICollider.addShape }
711
+ */ _proto.addShape = function addShape(shape) {
712
+ this._pxActor.attachShape(shape._pxShape);
713
+ };
714
+ /**
715
+ * {@inheritDoc ICollider.removeShape }
716
+ */ _proto.removeShape = function removeShape(shape) {
717
+ this._pxActor.detachShape(shape._pxShape, true);
718
+ };
719
+ /**
720
+ * {@inheritDoc ICollider.setWorldTransform }
721
+ */ _proto.setWorldTransform = function setWorldTransform(position, rotation) {
722
+ this._pxActor.setGlobalPose(this._transform(position, rotation), true);
723
+ };
724
+ /**
725
+ * {@inheritDoc ICollider.getWorldTransform }
726
+ */ _proto.getWorldTransform = function getWorldTransform(outPosition, outRotation) {
727
+ var transform = this._pxActor.getGlobalPose();
728
+ outPosition.set(transform.translation.x, transform.translation.y, transform.translation.z);
729
+ outRotation.set(transform.rotation.x, transform.rotation.y, transform.rotation.z, transform.rotation.w);
730
+ };
731
+ /**
732
+ * {@inheritDoc ICollider.destroy }
733
+ */ _proto.destroy = function destroy() {
734
+ this._pxActor.release();
735
+ };
736
+ /**
737
+ * @internal
738
+ */ _proto._transform = function _transform(pos, rot) {
739
+ var transform = PhysXCollider._tempTransform;
740
+ transform.translation = pos;
741
+ transform.rotation = rot.normalize();
742
+ return transform;
743
+ };
744
+ return PhysXCollider;
745
+ }();
746
+ (function() {
747
+ PhysXCollider._tempTransform = {
748
+ translation: null,
749
+ rotation: null
750
+ };
751
+ })();
703
752
 
704
- var CollisionDetectionMode;
705
- (function(CollisionDetectionMode) {
706
- CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is off for this dynamic collider. */ "Discrete"] = 0] = "Discrete";
707
- CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is on for colliding with static mesh geometry. */ "Continuous"] = 1] = "Continuous";
708
- CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is on for colliding with static and dynamic geometry. */ "ContinuousDynamic"] = 2] = "ContinuousDynamic";
709
- CollisionDetectionMode[CollisionDetectionMode[/** Speculative continuous collision detection is on for static and dynamic geometries */ "ContinuousSpeculative"] = 3] = "ContinuousSpeculative";
710
- })(CollisionDetectionMode || (CollisionDetectionMode = {}));
711
- /**
712
- * A dynamic collider can act with self-defined movement or physical force
713
- */ var PhysXDynamicCollider = /*#__PURE__*/ function(PhysXCollider) {
714
- _inherits(PhysXDynamicCollider, PhysXCollider);
715
- function PhysXDynamicCollider(physXPhysics, position, rotation) {
716
- var _this;
717
- _this = PhysXCollider.call(this, physXPhysics) || this;
718
- var transform = _this._transform(position, rotation);
719
- _this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
720
- return _this;
721
- }
722
- var _proto = PhysXDynamicCollider.prototype;
723
- /**
724
- * {@inheritDoc IDynamicCollider.setLinearDamping }
725
- */ _proto.setLinearDamping = function setLinearDamping(value) {
726
- this._pxActor.setLinearDamping(value);
727
- };
728
- /**
729
- * {@inheritDoc IDynamicCollider.setAngularDamping }
730
- */ _proto.setAngularDamping = function setAngularDamping(value) {
731
- this._pxActor.setAngularDamping(value);
732
- };
733
- /**
734
- * {@inheritDoc IDynamicCollider.setLinearVelocity }
735
- */ _proto.setLinearVelocity = function setLinearVelocity(value) {
736
- this._pxActor.setLinearVelocity(value, true);
737
- };
738
- /**
739
- * {@inheritDoc IDynamicCollider.setAngularVelocity }
740
- */ _proto.setAngularVelocity = function setAngularVelocity(value) {
741
- this._pxActor.setAngularVelocity(value, true);
742
- };
743
- /**
744
- * {@inheritDoc IDynamicCollider.setMass }
745
- */ _proto.setMass = function setMass(value) {
746
- this._pxActor.setMass(value);
747
- };
748
- /**
749
- * {@inheritDoc IDynamicCollider.setCenterOfMass }
750
- */ _proto.setCenterOfMass = function setCenterOfMass(position) {
751
- this._pxActor.setCMassLocalPose(position);
752
- };
753
- /**
754
- * {@inheritDoc IDynamicCollider.setInertiaTensor }
755
- */ _proto.setInertiaTensor = function setInertiaTensor(value) {
756
- this._pxActor.setMassSpaceInertiaTensor(value);
757
- };
758
- /**
759
- * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
760
- */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
761
- this._pxActor.setMaxAngularVelocity(value);
762
- };
763
- /**
764
- * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
765
- */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
766
- this._pxActor.setMaxDepenetrationVelocity(value);
767
- };
768
- /**
769
- * {@inheritDoc IDynamicCollider.setSleepThreshold }
770
- * @default 1e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
771
- */ _proto.setSleepThreshold = function setSleepThreshold(value) {
772
- this._pxActor.setSleepThreshold(value);
773
- };
774
- /**
775
- * {@inheritDoc IDynamicCollider.setSolverIterations }
776
- */ _proto.setSolverIterations = function setSolverIterations(value) {
777
- this._pxActor.setSolverIterationCounts(value, 1);
778
- };
779
- /**
780
- * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
781
- */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
782
- switch(value){
783
- case 1:
784
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
785
- break;
786
- case 2:
787
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
788
- break;
789
- case 3:
790
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
791
- break;
792
- case 0:
793
- var physX = this._physXPhysics._physX;
794
- this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
795
- this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
796
- this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
797
- break;
798
- }
799
- };
800
- /**
801
- * {@inheritDoc IDynamicCollider.setIsKinematic }
802
- */ _proto.setIsKinematic = function setIsKinematic(value) {
803
- if (value) {
804
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
805
- } else {
806
- this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
807
- }
808
- };
809
- /**
810
- * {@inheritDoc IDynamicCollider.setConstraints }
811
- */ _proto.setConstraints = function setConstraints(flags) {
812
- this._pxActor.setRigidDynamicLockFlags(flags);
813
- };
814
- /**
815
- * {@inheritDoc IDynamicCollider.addForce }
816
- */ _proto.addForce = function addForce(force) {
817
- this._pxActor.addForce({
818
- x: force.x,
819
- y: force.y,
820
- z: force.z
821
- });
822
- };
823
- /**
824
- * {@inheritDoc IDynamicCollider.addTorque }
825
- */ _proto.addTorque = function addTorque(torque) {
826
- this._pxActor.addTorque({
827
- x: torque.x,
828
- y: torque.y,
829
- z: torque.z
830
- });
831
- };
832
- /**
833
- * {@inheritDoc IDynamicCollider.move }
834
- */ _proto.move = function move(positionOrRotation, rotation) {
835
- if (rotation) {
836
- this._pxActor.setKinematicTarget(positionOrRotation, rotation);
837
- return;
838
- }
839
- var tempTranslation = PhysXDynamicCollider._tempTranslation;
840
- var tempRotation = PhysXDynamicCollider._tempRotation;
841
- this.getWorldTransform(tempTranslation, tempRotation);
842
- if (_instanceof(positionOrRotation, engine.Vector3)) {
843
- this._pxActor.setKinematicTarget(positionOrRotation, tempRotation);
844
- } else {
845
- this._pxActor.setKinematicTarget(tempTranslation, positionOrRotation);
846
- }
847
- };
848
- /**
849
- * {@inheritDoc IDynamicCollider.sleep }
850
- */ _proto.sleep = function sleep() {
851
- return this._pxActor.putToSleep();
852
- };
853
- /**
854
- * {@inheritDoc IDynamicCollider.wakeUp }
855
- */ _proto.wakeUp = function wakeUp() {
856
- return this._pxActor.wakeUp();
857
- };
858
- return PhysXDynamicCollider;
859
- }(PhysXCollider);
860
- PhysXDynamicCollider._tempTranslation = new engine.Vector3();
861
- PhysXDynamicCollider._tempRotation = new engine.Quaternion();
753
+ var CollisionDetectionMode;
754
+ (function(CollisionDetectionMode) {
755
+ CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is off for this dynamic collider. */ "Discrete"] = 0] = "Discrete";
756
+ CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is on for colliding with static mesh geometry. */ "Continuous"] = 1] = "Continuous";
757
+ CollisionDetectionMode[CollisionDetectionMode[/** Continuous collision detection is on for colliding with static and dynamic geometry. */ "ContinuousDynamic"] = 2] = "ContinuousDynamic";
758
+ CollisionDetectionMode[CollisionDetectionMode[/** Speculative continuous collision detection is on for static and dynamic geometries */ "ContinuousSpeculative"] = 3] = "ContinuousSpeculative";
759
+ })(CollisionDetectionMode || (CollisionDetectionMode = {}));
760
+ /**
761
+ * A dynamic collider can act with self-defined movement or physical force
762
+ */ var PhysXDynamicCollider = /*#__PURE__*/ function(PhysXCollider) {
763
+ _inherits(PhysXDynamicCollider, PhysXCollider);
764
+ function PhysXDynamicCollider(physXPhysics, position, rotation) {
765
+ var _this;
766
+ _this = PhysXCollider.call(this, physXPhysics) || this;
767
+ var transform = _this._transform(position, rotation);
768
+ _this._pxActor = physXPhysics._pxPhysics.createRigidDynamic(transform);
769
+ return _this;
770
+ }
771
+ var _proto = PhysXDynamicCollider.prototype;
772
+ /**
773
+ * {@inheritDoc IDynamicCollider.setLinearDamping }
774
+ */ _proto.setLinearDamping = function setLinearDamping(value) {
775
+ this._pxActor.setLinearDamping(value);
776
+ };
777
+ /**
778
+ * {@inheritDoc IDynamicCollider.setAngularDamping }
779
+ */ _proto.setAngularDamping = function setAngularDamping(value) {
780
+ this._pxActor.setAngularDamping(value);
781
+ };
782
+ /**
783
+ * {@inheritDoc IDynamicCollider.setLinearVelocity }
784
+ */ _proto.setLinearVelocity = function setLinearVelocity(value) {
785
+ this._pxActor.setLinearVelocity(value, true);
786
+ };
787
+ /**
788
+ * {@inheritDoc IDynamicCollider.setAngularVelocity }
789
+ */ _proto.setAngularVelocity = function setAngularVelocity(value) {
790
+ this._pxActor.setAngularVelocity(value, true);
791
+ };
792
+ /**
793
+ * {@inheritDoc IDynamicCollider.setMass }
794
+ */ _proto.setMass = function setMass(value) {
795
+ this._pxActor.setMass(value);
796
+ };
797
+ /**
798
+ * {@inheritDoc IDynamicCollider.setCenterOfMass }
799
+ */ _proto.setCenterOfMass = function setCenterOfMass(position) {
800
+ this._pxActor.setCMassLocalPose(position);
801
+ };
802
+ /**
803
+ * {@inheritDoc IDynamicCollider.setInertiaTensor }
804
+ */ _proto.setInertiaTensor = function setInertiaTensor(value) {
805
+ this._pxActor.setMassSpaceInertiaTensor(value);
806
+ };
807
+ /**
808
+ * {@inheritDoc IDynamicCollider.setMaxAngularVelocity }
809
+ */ _proto.setMaxAngularVelocity = function setMaxAngularVelocity(value) {
810
+ this._pxActor.setMaxAngularVelocity(value);
811
+ };
812
+ /**
813
+ * {@inheritDoc IDynamicCollider.setMaxDepenetrationVelocity }
814
+ */ _proto.setMaxDepenetrationVelocity = function setMaxDepenetrationVelocity(value) {
815
+ this._pxActor.setMaxDepenetrationVelocity(value);
816
+ };
817
+ /**
818
+ * {@inheritDoc IDynamicCollider.setSleepThreshold }
819
+ * @default 1e-5f * PxTolerancesScale::speed * PxTolerancesScale::speed
820
+ */ _proto.setSleepThreshold = function setSleepThreshold(value) {
821
+ this._pxActor.setSleepThreshold(value);
822
+ };
823
+ /**
824
+ * {@inheritDoc IDynamicCollider.setSolverIterations }
825
+ */ _proto.setSolverIterations = function setSolverIterations(value) {
826
+ this._pxActor.setSolverIterationCounts(value, 1);
827
+ };
828
+ /**
829
+ * {@inheritDoc IDynamicCollider.setCollisionDetectionMode }
830
+ */ _proto.setCollisionDetectionMode = function setCollisionDetectionMode(value) {
831
+ switch(value){
832
+ case 1:
833
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD, true);
834
+ break;
835
+ case 2:
836
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, true);
837
+ break;
838
+ case 3:
839
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, true);
840
+ break;
841
+ case 0:
842
+ var physX = this._physXPhysics._physX;
843
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD, false);
844
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_CCD_FRICTION, false);
845
+ this._pxActor.setRigidBodyFlag(physX.PxRigidBodyFlag.eENABLE_SPECULATIVE_CCD, false);
846
+ break;
847
+ }
848
+ };
849
+ /**
850
+ * {@inheritDoc IDynamicCollider.setIsKinematic }
851
+ */ _proto.setIsKinematic = function setIsKinematic(value) {
852
+ if (value) {
853
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, true);
854
+ } else {
855
+ this._pxActor.setRigidBodyFlag(this._physXPhysics._physX.PxRigidBodyFlag.eKINEMATIC, false);
856
+ }
857
+ };
858
+ /**
859
+ * {@inheritDoc IDynamicCollider.setConstraints }
860
+ */ _proto.setConstraints = function setConstraints(flags) {
861
+ this._pxActor.setRigidDynamicLockFlags(flags);
862
+ };
863
+ /**
864
+ * {@inheritDoc IDynamicCollider.addForce }
865
+ */ _proto.addForce = function addForce(force) {
866
+ this._pxActor.addForce({
867
+ x: force.x,
868
+ y: force.y,
869
+ z: force.z
870
+ });
871
+ };
872
+ /**
873
+ * {@inheritDoc IDynamicCollider.addTorque }
874
+ */ _proto.addTorque = function addTorque(torque) {
875
+ this._pxActor.addTorque({
876
+ x: torque.x,
877
+ y: torque.y,
878
+ z: torque.z
879
+ });
880
+ };
881
+ /**
882
+ * {@inheritDoc IDynamicCollider.move }
883
+ */ _proto.move = function move(positionOrRotation, rotation) {
884
+ if (rotation) {
885
+ this._pxActor.setKinematicTarget(positionOrRotation, rotation);
886
+ return;
887
+ }
888
+ var tempTranslation = PhysXDynamicCollider._tempTranslation;
889
+ var tempRotation = PhysXDynamicCollider._tempRotation;
890
+ this.getWorldTransform(tempTranslation, tempRotation);
891
+ if (_instanceof(positionOrRotation, engine.Vector3)) {
892
+ this._pxActor.setKinematicTarget(positionOrRotation, tempRotation);
893
+ } else {
894
+ this._pxActor.setKinematicTarget(tempTranslation, positionOrRotation);
895
+ }
896
+ };
897
+ /**
898
+ * {@inheritDoc IDynamicCollider.sleep }
899
+ */ _proto.sleep = function sleep() {
900
+ return this._pxActor.putToSleep();
901
+ };
902
+ /**
903
+ * {@inheritDoc IDynamicCollider.wakeUp }
904
+ */ _proto.wakeUp = function wakeUp() {
905
+ return this._pxActor.wakeUp();
906
+ };
907
+ return PhysXDynamicCollider;
908
+ }(PhysXCollider);
909
+ (function() {
910
+ PhysXDynamicCollider._tempTranslation = new engine.Vector3();
911
+ })();
912
+ (function() {
913
+ PhysXDynamicCollider._tempRotation = new engine.Quaternion();
914
+ })();
862
915
 
863
- /**
864
- * A manager is a collection of colliders and constraints which can interact.
865
- */ var PhysXPhysicsManager = /*#__PURE__*/ function() {
866
- function PhysXPhysicsManager(physXPhysics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
867
- var _this = this;
868
- /** @internal */ this._pxControllerManager = null;
869
- this._currentEvents = new DisorderedArray();
870
- this._eventMap = {};
871
- this._eventPool = [];
872
- this._physXPhysics = physXPhysics;
873
- var physX = physXPhysics._physX;
874
- this._pxRaycastHit = new physX.PxRaycastHit();
875
- this._pxFilterData = new physX.PxQueryFilterData();
876
- this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4);
877
- this._onContactEnter = onContactEnter;
878
- this._onContactExit = onContactExit;
879
- this._onContactStay = onContactStay;
880
- this._onTriggerEnter = onTriggerEnter;
881
- this._onTriggerExit = onTriggerExit;
882
- this._onTriggerStay = onTriggerStay;
883
- var triggerCallback = {
884
- onContactBegin: function(index1, index2) {
885
- _this._onContactEnter(index1, index2);
886
- },
887
- onContactEnd: function(index1, index2) {
888
- _this._onContactExit(index1, index2);
889
- },
890
- onContactPersist: function(index1, index2) {
891
- _this._onContactStay(index1, index2);
892
- },
893
- onTriggerBegin: function(index1, index2) {
894
- var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
895
- event.state = 0;
896
- _this._currentEvents.add(event);
897
- },
898
- onTriggerEnd: function(index1, index2) {
899
- var event;
900
- if (index1 < index2) {
901
- var subMap = _this._eventMap[index1];
902
- event = subMap[index2];
903
- subMap[index2] = undefined;
904
- } else {
905
- var subMap1 = _this._eventMap[index2];
906
- event = subMap1[index1];
907
- subMap1[index1] = undefined;
908
- }
909
- event.state = 2;
910
- }
911
- };
912
- var pxPhysics = physXPhysics._pxPhysics;
913
- var physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
914
- var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, physXSimulationCallbackInstance);
915
- this._pxScene = pxPhysics.createScene(sceneDesc);
916
- }
917
- var _proto = PhysXPhysicsManager.prototype;
918
- /**
919
- * {@inheritDoc IPhysicsManager.setGravity }
920
- */ _proto.setGravity = function setGravity(value) {
921
- this._pxScene.setGravity(value);
922
- };
923
- /**
924
- * {@inheritDoc IPhysicsManager.addColliderShape }
925
- */ _proto.addColliderShape = function addColliderShape(colliderShape) {
926
- this._eventMap[colliderShape._id] = {};
927
- };
928
- /**
929
- * {@inheritDoc IPhysicsManager.removeColliderShape }
930
- */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
931
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
932
- var shapeID = colliderShape._id;
933
- for(var i = currentEvents.length - 1; i >= 0; i--){
934
- var event = currentEvents.get(i);
935
- if (event.index1 == shapeID || event.index2 == shapeID) {
936
- currentEvents.deleteByIndex(i);
937
- eventPool.push(event);
938
- }
939
- }
940
- delete this._eventMap[shapeID];
941
- };
942
- /**
943
- * {@inheritDoc IPhysicsManager.addCollider }
944
- */ _proto.addCollider = function addCollider(collider) {
945
- this._pxScene.addActor(collider._pxActor, null);
946
- };
947
- /**
948
- * {@inheritDoc IPhysicsManager.removeCollider }
949
- */ _proto.removeCollider = function removeCollider(collider) {
950
- this._pxScene.removeActor(collider._pxActor, true);
951
- };
952
- /**
953
- * {@inheritDoc IPhysicsManager.addCharacterController }
954
- */ _proto.addCharacterController = function addCharacterController(characterController) {
955
- var lastPXManager = characterController._pxManager;
956
- var shape = characterController._shape;
957
- if (shape) {
958
- if (lastPXManager !== this) {
959
- lastPXManager && characterController._destroyPXController();
960
- characterController._createPXController(this, shape);
961
- }
962
- }
963
- characterController._pxManager = this;
964
- };
965
- /**
966
- * {@inheritDoc IPhysicsManager.removeCharacterController }
967
- */ _proto.removeCharacterController = function removeCharacterController(characterController) {
968
- characterController._pxController = null;
969
- characterController._pxManager = null;
970
- };
971
- /**
972
- * {@inheritDoc IPhysicsManager.update }
973
- */ _proto.update = function update(elapsedTime) {
974
- this._simulate(elapsedTime);
975
- this._fetchResults();
976
- this._fireEvent();
977
- };
978
- /**
979
- * {@inheritDoc IPhysicsManager.raycast }
980
- */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
981
- var _this = this, pxHitResult = _this._pxRaycastHit;
982
- distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
983
- var raycastCallback = {
984
- preFilter: function(filterData, index, actor) {
985
- if (onRaycast(index)) {
986
- return 2; // eBLOCK
987
- } else {
988
- return 0; // eNONE
989
- }
990
- },
991
- postFilter: function(filterData, hit) {}
992
- };
993
- var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback));
994
- if (result && hit != undefined) {
995
- var position = PhysXPhysicsManager._tempPosition, normal = PhysXPhysicsManager._tempNormal;
996
- var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
997
- position.set(pxPosition.x, pxPosition.y, pxPosition.z);
998
- normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
999
- hit(pxHitResult.getShape().getUUID(), pxHitResult.distance, position, normal);
1000
- }
1001
- return result;
1002
- };
1003
- /**
1004
- * @internal
1005
- */ _proto._getControllerManager = function _getControllerManager() {
1006
- var pxControllerManager = this._pxControllerManager;
1007
- if (pxControllerManager === null) {
1008
- this._pxControllerManager = pxControllerManager = this._pxScene.createControllerManager();
1009
- }
1010
- return pxControllerManager;
1011
- };
1012
- _proto._simulate = function _simulate(elapsedTime) {
1013
- this._pxScene.simulate(elapsedTime, true);
1014
- };
1015
- _proto._fetchResults = function _fetchResults(block) {
1016
- if (block === void 0) block = true;
1017
- this._pxScene.fetchResults(block);
1018
- };
1019
- _proto._getTrigger = function _getTrigger(index1, index2) {
1020
- var event;
1021
- if (this._eventPool.length) {
1022
- event = this._eventPool.pop();
1023
- event.index1 = index1;
1024
- event.index2 = index2;
1025
- } else {
1026
- event = new TriggerEvent(index1, index2);
1027
- }
1028
- this._eventMap[index1][index2] = event;
1029
- return event;
1030
- };
1031
- _proto._fireEvent = function _fireEvent() {
1032
- var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
1033
- for(var i = currentEvents.length - 1; i >= 0; i--){
1034
- var event = currentEvents.get(i);
1035
- if (event.state == 0) {
1036
- this._onTriggerEnter(event.index1, event.index2);
1037
- event.state = 1;
1038
- } else if (event.state == 1) {
1039
- this._onTriggerStay(event.index1, event.index2);
1040
- } else if (event.state == 2) {
1041
- this._onTriggerExit(event.index1, event.index2);
1042
- currentEvents.deleteByIndex(i);
1043
- eventPool.push(event);
1044
- }
1045
- }
1046
- };
1047
- return PhysXPhysicsManager;
1048
- }();
1049
- PhysXPhysicsManager._tempPosition = new engine.Vector3();
1050
- PhysXPhysicsManager._tempNormal = new engine.Vector3();
1051
- var /**
1052
- * Filtering flags for scene queries.
1053
- */ QueryFlag;
1054
- (function(QueryFlag) {
1055
- QueryFlag[QueryFlag["STATIC"] = 1] = "STATIC";
1056
- QueryFlag[QueryFlag["DYNAMIC"] = 2] = "DYNAMIC";
1057
- QueryFlag[QueryFlag["PRE_FILTER"] = 4] = "PRE_FILTER";
1058
- QueryFlag[QueryFlag["POST_FILTER"] = 8] = "POST_FILTER";
1059
- QueryFlag[QueryFlag["ANY_HIT"] = 16] = "ANY_HIT";
1060
- QueryFlag[QueryFlag["NO_BLOCK"] = 32] = "NO_BLOCK";
1061
- })(QueryFlag || (QueryFlag = {}));
1062
- var /**
1063
- * Physics state
1064
- */ TriggerEventState;
1065
- (function(TriggerEventState) {
1066
- TriggerEventState[TriggerEventState["Enter"] = 0] = "Enter";
1067
- TriggerEventState[TriggerEventState["Stay"] = 1] = "Stay";
1068
- TriggerEventState[TriggerEventState["Exit"] = 2] = "Exit";
1069
- })(TriggerEventState || (TriggerEventState = {}));
1070
- /**
1071
- * Trigger event to store interactive object ids and state.
1072
- */ var TriggerEvent = function TriggerEvent(index1, index2) {
1073
- this.index1 = index1;
1074
- this.index2 = index2;
1075
- };
916
+ /**
917
+ * A manager is a collection of colliders and constraints which can interact.
918
+ */ var PhysXPhysicsManager = /*#__PURE__*/ function() {
919
+ function PhysXPhysicsManager(physXPhysics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
920
+ var _this = this;
921
+ /** @internal */ this._pxControllerManager = null;
922
+ this._currentEvents = new DisorderedArray();
923
+ this._eventMap = {};
924
+ this._eventPool = [];
925
+ this._physXPhysics = physXPhysics;
926
+ var physX = physXPhysics._physX;
927
+ this._pxRaycastHit = new physX.PxRaycastHit();
928
+ this._pxFilterData = new physX.PxQueryFilterData();
929
+ this._pxFilterData.flags = new physX.PxQueryFlags(1 | 2 | 4);
930
+ this._onContactEnter = onContactEnter;
931
+ this._onContactExit = onContactExit;
932
+ this._onContactStay = onContactStay;
933
+ this._onTriggerEnter = onTriggerEnter;
934
+ this._onTriggerExit = onTriggerExit;
935
+ this._onTriggerStay = onTriggerStay;
936
+ var triggerCallback = {
937
+ onContactBegin: function(index1, index2) {
938
+ _this._onContactEnter(index1, index2);
939
+ },
940
+ onContactEnd: function(index1, index2) {
941
+ _this._onContactExit(index1, index2);
942
+ },
943
+ onContactPersist: function(index1, index2) {
944
+ _this._onContactStay(index1, index2);
945
+ },
946
+ onTriggerBegin: function(index1, index2) {
947
+ var event = index1 < index2 ? _this._getTrigger(index1, index2) : _this._getTrigger(index2, index1);
948
+ event.state = 0;
949
+ _this._currentEvents.add(event);
950
+ },
951
+ onTriggerEnd: function(index1, index2) {
952
+ var event;
953
+ if (index1 < index2) {
954
+ var subMap = _this._eventMap[index1];
955
+ event = subMap[index2];
956
+ subMap[index2] = undefined;
957
+ } else {
958
+ var subMap1 = _this._eventMap[index2];
959
+ event = subMap1[index1];
960
+ subMap1[index1] = undefined;
961
+ }
962
+ event.state = 2;
963
+ }
964
+ };
965
+ var pxPhysics = physXPhysics._pxPhysics;
966
+ var physXSimulationCallbackInstance = physX.PxSimulationEventCallback.implement(triggerCallback);
967
+ var sceneDesc = physX.getDefaultSceneDesc(pxPhysics.getTolerancesScale(), 0, physXSimulationCallbackInstance);
968
+ this._pxScene = pxPhysics.createScene(sceneDesc);
969
+ }
970
+ var _proto = PhysXPhysicsManager.prototype;
971
+ /**
972
+ * {@inheritDoc IPhysicsManager.setGravity }
973
+ */ _proto.setGravity = function setGravity(value) {
974
+ this._pxScene.setGravity(value);
975
+ };
976
+ /**
977
+ * {@inheritDoc IPhysicsManager.addColliderShape }
978
+ */ _proto.addColliderShape = function addColliderShape(colliderShape) {
979
+ this._eventMap[colliderShape._id] = {};
980
+ };
981
+ /**
982
+ * {@inheritDoc IPhysicsManager.removeColliderShape }
983
+ */ _proto.removeColliderShape = function removeColliderShape(colliderShape) {
984
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
985
+ var shapeID = colliderShape._id;
986
+ for(var i = currentEvents.length - 1; i >= 0; i--){
987
+ var event = currentEvents.get(i);
988
+ if (event.index1 == shapeID || event.index2 == shapeID) {
989
+ currentEvents.deleteByIndex(i);
990
+ eventPool.push(event);
991
+ }
992
+ }
993
+ delete this._eventMap[shapeID];
994
+ };
995
+ /**
996
+ * {@inheritDoc IPhysicsManager.addCollider }
997
+ */ _proto.addCollider = function addCollider(collider) {
998
+ this._pxScene.addActor(collider._pxActor, null);
999
+ };
1000
+ /**
1001
+ * {@inheritDoc IPhysicsManager.removeCollider }
1002
+ */ _proto.removeCollider = function removeCollider(collider) {
1003
+ this._pxScene.removeActor(collider._pxActor, true);
1004
+ };
1005
+ /**
1006
+ * {@inheritDoc IPhysicsManager.addCharacterController }
1007
+ */ _proto.addCharacterController = function addCharacterController(characterController) {
1008
+ var lastPXManager = characterController._pxManager;
1009
+ var shape = characterController._shape;
1010
+ if (shape) {
1011
+ if (lastPXManager !== this) {
1012
+ lastPXManager && characterController._destroyPXController();
1013
+ characterController._createPXController(this, shape);
1014
+ }
1015
+ }
1016
+ characterController._pxManager = this;
1017
+ };
1018
+ /**
1019
+ * {@inheritDoc IPhysicsManager.removeCharacterController }
1020
+ */ _proto.removeCharacterController = function removeCharacterController(characterController) {
1021
+ characterController._pxController = null;
1022
+ characterController._pxManager = null;
1023
+ };
1024
+ /**
1025
+ * {@inheritDoc IPhysicsManager.update }
1026
+ */ _proto.update = function update(elapsedTime) {
1027
+ this._simulate(elapsedTime);
1028
+ this._fetchResults();
1029
+ this._fireEvent();
1030
+ };
1031
+ /**
1032
+ * {@inheritDoc IPhysicsManager.raycast }
1033
+ */ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
1034
+ var _this = this, pxHitResult = _this._pxRaycastHit;
1035
+ distance = Math.min(distance, 3.4e38); // float32 max value limit in physx raycast.
1036
+ var raycastCallback = {
1037
+ preFilter: function(filterData, index, actor) {
1038
+ if (onRaycast(index)) {
1039
+ return 2; // eBLOCK
1040
+ } else {
1041
+ return 0; // eNONE
1042
+ }
1043
+ },
1044
+ postFilter: function(filterData, hit) {}
1045
+ };
1046
+ var result = this._pxScene.raycastSingle(ray.origin, ray.direction, distance, pxHitResult, this._pxFilterData, this._physXPhysics._physX.PxQueryFilterCallback.implement(raycastCallback));
1047
+ if (result && hit != undefined) {
1048
+ var position = PhysXPhysicsManager._tempPosition, normal = PhysXPhysicsManager._tempNormal;
1049
+ var pxPosition = pxHitResult.position, pxNormal = pxHitResult.normal;
1050
+ position.set(pxPosition.x, pxPosition.y, pxPosition.z);
1051
+ normal.set(pxNormal.x, pxNormal.y, pxNormal.z);
1052
+ hit(pxHitResult.getShape().getUUID(), pxHitResult.distance, position, normal);
1053
+ }
1054
+ return result;
1055
+ };
1056
+ /**
1057
+ * @internal
1058
+ */ _proto._getControllerManager = function _getControllerManager() {
1059
+ var pxControllerManager = this._pxControllerManager;
1060
+ if (pxControllerManager === null) {
1061
+ this._pxControllerManager = pxControllerManager = this._pxScene.createControllerManager();
1062
+ }
1063
+ return pxControllerManager;
1064
+ };
1065
+ _proto._simulate = function _simulate(elapsedTime) {
1066
+ this._pxScene.simulate(elapsedTime, true);
1067
+ };
1068
+ _proto._fetchResults = function _fetchResults(block) {
1069
+ if (block === void 0) block = true;
1070
+ this._pxScene.fetchResults(block);
1071
+ };
1072
+ _proto._getTrigger = function _getTrigger(index1, index2) {
1073
+ var event;
1074
+ if (this._eventPool.length) {
1075
+ event = this._eventPool.pop();
1076
+ event.index1 = index1;
1077
+ event.index2 = index2;
1078
+ } else {
1079
+ event = new TriggerEvent(index1, index2);
1080
+ }
1081
+ this._eventMap[index1][index2] = event;
1082
+ return event;
1083
+ };
1084
+ _proto._fireEvent = function _fireEvent() {
1085
+ var _this = this, eventPool = _this._eventPool, currentEvents = _this._currentEvents;
1086
+ for(var i = currentEvents.length - 1; i >= 0; i--){
1087
+ var event = currentEvents.get(i);
1088
+ if (event.state == 0) {
1089
+ this._onTriggerEnter(event.index1, event.index2);
1090
+ event.state = 1;
1091
+ } else if (event.state == 1) {
1092
+ this._onTriggerStay(event.index1, event.index2);
1093
+ } else if (event.state == 2) {
1094
+ this._onTriggerExit(event.index1, event.index2);
1095
+ currentEvents.deleteByIndex(i);
1096
+ eventPool.push(event);
1097
+ }
1098
+ }
1099
+ };
1100
+ return PhysXPhysicsManager;
1101
+ }();
1102
+ (function() {
1103
+ PhysXPhysicsManager._tempPosition = new engine.Vector3();
1104
+ })();
1105
+ (function() {
1106
+ PhysXPhysicsManager._tempNormal = new engine.Vector3();
1107
+ })();
1108
+ var /**
1109
+ * Filtering flags for scene queries.
1110
+ */ QueryFlag;
1111
+ (function(QueryFlag) {
1112
+ QueryFlag[QueryFlag["STATIC"] = 1] = "STATIC";
1113
+ QueryFlag[QueryFlag["DYNAMIC"] = 2] = "DYNAMIC";
1114
+ QueryFlag[QueryFlag["PRE_FILTER"] = 4] = "PRE_FILTER";
1115
+ QueryFlag[QueryFlag["POST_FILTER"] = 8] = "POST_FILTER";
1116
+ QueryFlag[QueryFlag["ANY_HIT"] = 16] = "ANY_HIT";
1117
+ QueryFlag[QueryFlag["NO_BLOCK"] = 32] = "NO_BLOCK";
1118
+ })(QueryFlag || (QueryFlag = {}));
1119
+ var /**
1120
+ * Physics state
1121
+ */ TriggerEventState;
1122
+ (function(TriggerEventState) {
1123
+ TriggerEventState[TriggerEventState["Enter"] = 0] = "Enter";
1124
+ TriggerEventState[TriggerEventState["Stay"] = 1] = "Stay";
1125
+ TriggerEventState[TriggerEventState["Exit"] = 2] = "Exit";
1126
+ })(TriggerEventState || (TriggerEventState = {}));
1127
+ /**
1128
+ * Trigger event to store interactive object ids and state.
1129
+ */ var TriggerEvent = function TriggerEvent(index1, index2) {
1130
+ this.index1 = index1;
1131
+ this.index2 = index2;
1132
+ };
1076
1133
 
1077
- /**
1078
- * Physics material describes how to handle colliding objects (friction, bounciness).
1079
- */ var PhysXPhysicsMaterial = /*#__PURE__*/ function() {
1080
- function PhysXPhysicsMaterial(physXPhysics, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1081
- this._physXPhysics = physXPhysics;
1082
- var pxMaterial = physXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
1083
- pxMaterial.setFrictionCombineMode(frictionCombine);
1084
- pxMaterial.setRestitutionCombineMode(bounceCombine);
1085
- this._pxMaterial = pxMaterial;
1086
- }
1087
- var _proto = PhysXPhysicsMaterial.prototype;
1088
- /**
1089
- * {@inheritDoc IPhysicsMaterial.setBounciness }
1090
- */ _proto.setBounciness = function setBounciness(value) {
1091
- this._pxMaterial.setRestitution(value);
1092
- };
1093
- /**
1094
- * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
1095
- */ _proto.setDynamicFriction = function setDynamicFriction(value) {
1096
- this._pxMaterial.setDynamicFriction(value);
1097
- };
1098
- /**
1099
- * {@inheritDoc IPhysicsMaterial.setStaticFriction }
1100
- */ _proto.setStaticFriction = function setStaticFriction(value) {
1101
- this._pxMaterial.setStaticFriction(value);
1102
- };
1103
- /**
1104
- * {@inheritDoc IPhysicsMaterial.setBounceCombine }
1105
- */ _proto.setBounceCombine = function setBounceCombine(value) {
1106
- this._pxMaterial.setRestitutionCombineMode(value);
1107
- };
1108
- /**
1109
- * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
1110
- */ _proto.setFrictionCombine = function setFrictionCombine(value) {
1111
- this._pxMaterial.setFrictionCombineMode(value);
1112
- };
1113
- /**
1114
- * {@inheritDoc IPhysicsMaterial.destroy }
1115
- */ _proto.destroy = function destroy() {
1116
- this._pxMaterial.release();
1117
- };
1118
- return PhysXPhysicsMaterial;
1119
- }();
1120
- var /**
1121
- * Describes how physics materials of the colliding objects are combined.
1122
- */ CombineMode;
1123
- (function(CombineMode) {
1124
- CombineMode[CombineMode[/** Averages the friction/bounce of the two colliding materials. */ "Average"] = 0] = "Average";
1125
- CombineMode[CombineMode[/** Uses the smaller friction/bounce of the two colliding materials. */ "Minimum"] = 1] = "Minimum";
1126
- CombineMode[CombineMode[/** Multiplies the friction/bounce of the two colliding materials. */ "Multiply"] = 2] = "Multiply";
1127
- CombineMode[CombineMode[/** Uses the larger friction/bounce of the two colliding materials. */ "Maximum"] = 3] = "Maximum";
1128
- })(CombineMode || (CombineMode = {}));
1134
+ /**
1135
+ * Physics material describes how to handle colliding objects (friction, bounciness).
1136
+ */ var PhysXPhysicsMaterial = /*#__PURE__*/ function() {
1137
+ function PhysXPhysicsMaterial(physXPhysics, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1138
+ this._physXPhysics = physXPhysics;
1139
+ var pxMaterial = physXPhysics._pxPhysics.createMaterial(staticFriction, dynamicFriction, bounciness);
1140
+ pxMaterial.setFrictionCombineMode(frictionCombine);
1141
+ pxMaterial.setRestitutionCombineMode(bounceCombine);
1142
+ this._pxMaterial = pxMaterial;
1143
+ }
1144
+ var _proto = PhysXPhysicsMaterial.prototype;
1145
+ /**
1146
+ * {@inheritDoc IPhysicsMaterial.setBounciness }
1147
+ */ _proto.setBounciness = function setBounciness(value) {
1148
+ this._pxMaterial.setRestitution(value);
1149
+ };
1150
+ /**
1151
+ * {@inheritDoc IPhysicsMaterial.setDynamicFriction }
1152
+ */ _proto.setDynamicFriction = function setDynamicFriction(value) {
1153
+ this._pxMaterial.setDynamicFriction(value);
1154
+ };
1155
+ /**
1156
+ * {@inheritDoc IPhysicsMaterial.setStaticFriction }
1157
+ */ _proto.setStaticFriction = function setStaticFriction(value) {
1158
+ this._pxMaterial.setStaticFriction(value);
1159
+ };
1160
+ /**
1161
+ * {@inheritDoc IPhysicsMaterial.setBounceCombine }
1162
+ */ _proto.setBounceCombine = function setBounceCombine(value) {
1163
+ this._pxMaterial.setRestitutionCombineMode(value);
1164
+ };
1165
+ /**
1166
+ * {@inheritDoc IPhysicsMaterial.setFrictionCombine }
1167
+ */ _proto.setFrictionCombine = function setFrictionCombine(value) {
1168
+ this._pxMaterial.setFrictionCombineMode(value);
1169
+ };
1170
+ /**
1171
+ * {@inheritDoc IPhysicsMaterial.destroy }
1172
+ */ _proto.destroy = function destroy() {
1173
+ this._pxMaterial.release();
1174
+ };
1175
+ return PhysXPhysicsMaterial;
1176
+ }();
1177
+ var /**
1178
+ * Describes how physics materials of the colliding objects are combined.
1179
+ */ CombineMode;
1180
+ (function(CombineMode) {
1181
+ CombineMode[CombineMode[/** Averages the friction/bounce of the two colliding materials. */ "Average"] = 0] = "Average";
1182
+ CombineMode[CombineMode[/** Uses the smaller friction/bounce of the two colliding materials. */ "Minimum"] = 1] = "Minimum";
1183
+ CombineMode[CombineMode[/** Multiplies the friction/bounce of the two colliding materials. */ "Multiply"] = 2] = "Multiply";
1184
+ CombineMode[CombineMode[/** Uses the larger friction/bounce of the two colliding materials. */ "Maximum"] = 3] = "Maximum";
1185
+ })(CombineMode || (CombineMode = {}));
1129
1186
 
1130
- /**
1131
- * A static collider component that will not move.
1132
- * @remarks Mostly used for object which always stays at the same place and never moves around.
1133
- */ var PhysXStaticCollider = /*#__PURE__*/ function(PhysXCollider) {
1134
- _inherits(PhysXStaticCollider, PhysXCollider);
1135
- function PhysXStaticCollider(physXPhysics, position, rotation) {
1136
- var _this;
1137
- _this = PhysXCollider.call(this, physXPhysics) || this;
1138
- _this._pxActor = physXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
1139
- return _this;
1140
- }
1141
- return PhysXStaticCollider;
1142
- }(PhysXCollider);
1187
+ /**
1188
+ * A static collider component that will not move.
1189
+ * @remarks Mostly used for object which always stays at the same place and never moves around.
1190
+ */ var PhysXStaticCollider = /*#__PURE__*/ function(PhysXCollider) {
1191
+ _inherits(PhysXStaticCollider, PhysXCollider);
1192
+ function PhysXStaticCollider(physXPhysics, position, rotation) {
1193
+ var _this;
1194
+ _this = PhysXCollider.call(this, physXPhysics) || this;
1195
+ _this._pxActor = physXPhysics._pxPhysics.createRigidStatic(_this._transform(position, rotation));
1196
+ return _this;
1197
+ }
1198
+ return PhysXStaticCollider;
1199
+ }(PhysXCollider);
1143
1200
 
1144
- /**
1145
- * Plane collider shape in PhysX.
1146
- */ var PhysXPlaneColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
1147
- _inherits(PhysXPlaneColliderShape, PhysXColliderShape1);
1148
- function PhysXPlaneColliderShape(physXPhysics, uniqueID, material) {
1149
- var _this;
1150
- _this = PhysXColliderShape1.call(this, physXPhysics) || this;
1151
- _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
1152
- _this._physXRotation.copyFrom(_this._axis);
1153
- _this._pxGeometry = new physXPhysics._physX.PxPlaneGeometry();
1154
- _this._initialize(material, uniqueID);
1155
- _this._setLocalPose();
1156
- return _this;
1157
- }
1158
- var _proto = PhysXPlaneColliderShape.prototype;
1159
- /**
1160
- * {@inheritDoc IColliderShape.setWorldScale }
1161
- */ _proto.setWorldScale = function setWorldScale(scale) {
1162
- this._scale.copyFrom(scale);
1163
- this._setLocalPose();
1164
- };
1165
- return PhysXPlaneColliderShape;
1166
- }(PhysXColliderShape);
1201
+ /**
1202
+ * Plane collider shape in PhysX.
1203
+ */ var PhysXPlaneColliderShape = /*#__PURE__*/ function(PhysXColliderShape1) {
1204
+ _inherits(PhysXPlaneColliderShape, PhysXColliderShape1);
1205
+ function PhysXPlaneColliderShape(physXPhysics, uniqueID, material) {
1206
+ var _this;
1207
+ _this = PhysXColliderShape1.call(this, physXPhysics) || this;
1208
+ _this._axis = new engine.Quaternion(0, 0, PhysXColliderShape.halfSqrt, PhysXColliderShape.halfSqrt);
1209
+ _this._physXRotation.copyFrom(_this._axis);
1210
+ _this._pxGeometry = new physXPhysics._physX.PxPlaneGeometry();
1211
+ _this._initialize(material, uniqueID);
1212
+ _this._setLocalPose();
1213
+ return _this;
1214
+ }
1215
+ return PhysXPlaneColliderShape;
1216
+ }(PhysXColliderShape);
1167
1217
 
1168
- /**
1169
- * Sphere collider shape in PhysX.
1170
- */ var PhysXSphereColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1171
- _inherits(PhysXSphereColliderShape, PhysXColliderShape);
1172
- function PhysXSphereColliderShape(physXPhysics, uniqueID, radius, material) {
1173
- var _this;
1174
- _this = PhysXColliderShape.call(this, physXPhysics) || this;
1175
- _this._maxScale = 1;
1176
- _this._radius = radius;
1177
- _this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(_this._radius * _this._maxScale);
1178
- _this._initialize(material, uniqueID);
1179
- _this._setLocalPose();
1180
- return _this;
1181
- }
1182
- var _proto = PhysXSphereColliderShape.prototype;
1183
- /**
1184
- * {@inheritDoc ISphereColliderShape.setRadius }
1185
- */ _proto.setRadius = function setRadius(value) {
1186
- this._radius = value;
1187
- this._pxGeometry.radius = value * this._maxScale;
1188
- this._pxShape.setGeometry(this._pxGeometry);
1189
- };
1190
- /**
1191
- * {@inheritDoc IColliderShape.setWorldScale }
1192
- */ _proto.setWorldScale = function setWorldScale(scale) {
1193
- this._scale.copyFrom(scale);
1194
- this._setLocalPose();
1195
- this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
1196
- this._pxGeometry.radius = this._radius * this._maxScale;
1197
- this._pxShape.setGeometry(this._pxGeometry);
1198
- };
1199
- return PhysXSphereColliderShape;
1200
- }(PhysXColliderShape);
1218
+ /**
1219
+ * Sphere collider shape in PhysX.
1220
+ */ var PhysXSphereColliderShape = /*#__PURE__*/ function(PhysXColliderShape) {
1221
+ _inherits(PhysXSphereColliderShape, PhysXColliderShape);
1222
+ function PhysXSphereColliderShape(physXPhysics, uniqueID, radius, material) {
1223
+ var _this;
1224
+ _this = PhysXColliderShape.call(this, physXPhysics) || this;
1225
+ _this._maxScale = 1;
1226
+ _this._radius = radius;
1227
+ _this._pxGeometry = new physXPhysics._physX.PxSphereGeometry(_this._radius * _this._maxScale);
1228
+ _this._initialize(material, uniqueID);
1229
+ _this._setLocalPose();
1230
+ return _this;
1231
+ }
1232
+ var _proto = PhysXSphereColliderShape.prototype;
1233
+ /**
1234
+ * {@inheritDoc ISphereColliderShape.setRadius }
1235
+ */ _proto.setRadius = function setRadius(value) {
1236
+ this._radius = value;
1237
+ this._pxGeometry.radius = value * this._maxScale;
1238
+ this._pxShape.setGeometry(this._pxGeometry);
1239
+ };
1240
+ /**
1241
+ * {@inheritDoc IColliderShape.setWorldScale }
1242
+ */ _proto.setWorldScale = function setWorldScale(scale) {
1243
+ PhysXColliderShape.prototype.setWorldScale.call(this, scale);
1244
+ this._maxScale = Math.max(scale.x, Math.max(scale.x, scale.y));
1245
+ this._pxGeometry.radius = this._radius * this._maxScale;
1246
+ this._pxShape.setGeometry(this._pxGeometry);
1247
+ };
1248
+ return PhysXSphereColliderShape;
1249
+ }(PhysXColliderShape);
1201
1250
 
1202
- /**
1203
- * PhysX object creation.
1204
- */ var PhysXPhysics = /*#__PURE__*/ function() {
1205
- function PhysXPhysics(runtimeMode) {
1206
- if (runtimeMode === void 0) runtimeMode = exports.PhysXRuntimeMode.Auto;
1207
- this._initializeState = 0;
1208
- this._runTimeMode = runtimeMode;
1209
- }
1210
- var _proto = PhysXPhysics.prototype;
1211
- /**
1212
- * Initialize PhysXPhysics.
1213
- * @param runtimeMode - Runtime mode
1214
- * @returns Promise object
1215
- */ _proto.initialize = function initialize() {
1216
- var _this = this;
1217
- if (this._initializeState === 2) {
1218
- return Promise.resolve();
1219
- } else if (this._initializeState === 1) {
1220
- return this._initializePromise;
1221
- }
1222
- var runtimeMode = this._runTimeMode;
1223
- var scriptPromise = new Promise(function(resolve, reject) {
1224
- var script = document.createElement("script");
1225
- document.body.appendChild(script);
1226
- script.async = true;
1227
- script.onload = resolve;
1228
- script.onerror = reject;
1229
- if (runtimeMode == exports.PhysXRuntimeMode.Auto) {
1230
- var supported = function() {
1231
- try {
1232
- if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
1233
- var module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
1234
- if (_instanceof(module, WebAssembly.Module)) return _instanceof(new WebAssembly.Instance(module), WebAssembly.Instance);
1235
- }
1236
- } catch (e) {}
1237
- return false;
1238
- }();
1239
- if (supported) {
1240
- runtimeMode = exports.PhysXRuntimeMode.WebAssembly;
1241
- } else {
1242
- runtimeMode = exports.PhysXRuntimeMode.JavaScript;
1243
- }
1244
- }
1245
- if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1246
- script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js.js";
1247
- } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1248
- script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js";
1249
- }
1250
- });
1251
- var initializePromise = new Promise(function(resolve, reject) {
1252
- scriptPromise.then(function() {
1253
- return window.PHYSX().then(function(PHYSX) {
1254
- _this._init(PHYSX);
1255
- _this._initializeState = 2;
1256
- _this._initializePromise = null;
1257
- console.log("PhysX loaded.");
1258
- resolve();
1259
- }, reject);
1260
- }, reject).catch(reject);
1261
- });
1262
- this._initializePromise = initializePromise;
1263
- return initializePromise;
1264
- };
1265
- /**
1266
- * Destroy PhysXPhysics.
1267
- */ _proto.destroy = function destroy() {
1268
- this._physX.PxCloseExtensions();
1269
- this._pxPhysics.release();
1270
- this._pxFoundation.release();
1271
- this._physX = null;
1272
- this._pxFoundation = null;
1273
- this._pxPhysics = null;
1274
- };
1275
- /**
1276
- * {@inheritDoc IPhysics.createPhysicsManager }
1277
- */ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
1278
- var manager = new PhysXPhysicsManager(this, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
1279
- return manager;
1280
- };
1281
- /**
1282
- * {@inheritDoc IPhysics.createStaticCollider }
1283
- */ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
1284
- return new PhysXStaticCollider(this, position, rotation);
1285
- };
1286
- /**
1287
- * {@inheritDoc IPhysics.createDynamicCollider }
1288
- */ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
1289
- return new PhysXDynamicCollider(this, position, rotation);
1290
- };
1291
- /**
1292
- * {@inheritDoc IPhysics.createCharacterController }
1293
- */ _proto.createCharacterController = function createCharacterController() {
1294
- return new PhysXCharacterController(this);
1295
- };
1296
- /**
1297
- * {@inheritDoc IPhysics.createPhysicsMaterial }
1298
- */ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1299
- return new PhysXPhysicsMaterial(this, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1300
- };
1301
- /**
1302
- * {@inheritDoc IPhysics.createBoxColliderShape }
1303
- */ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1304
- return new PhysXBoxColliderShape(this, uniqueID, size, material);
1305
- };
1306
- /**
1307
- * {@inheritDoc IPhysics.createSphereColliderShape }
1308
- */ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1309
- return new PhysXSphereColliderShape(this, uniqueID, radius, material);
1310
- };
1311
- /**
1312
- * {@inheritDoc IPhysics.createPlaneColliderShape }
1313
- */ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1314
- return new PhysXPlaneColliderShape(this, uniqueID, material);
1315
- };
1316
- /**
1317
- * {@inheritDoc IPhysics.createCapsuleColliderShape }
1318
- */ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1319
- return new PhysXCapsuleColliderShape(this, uniqueID, radius, height, material);
1320
- };
1321
- /**
1322
- * {@inheritDoc IPhysics.createFixedJoint }
1323
- */ _proto.createFixedJoint = function createFixedJoint(collider) {
1324
- return new PhysXFixedJoint(this, collider);
1325
- };
1326
- /**
1327
- * {@inheritDoc IPhysics.createHingeJoint }
1328
- */ _proto.createHingeJoint = function createHingeJoint(collider) {
1329
- return new PhysXHingeJoint(this, collider);
1330
- };
1331
- /**
1332
- * {@inheritDoc IPhysics.createSpringJoint }
1333
- */ _proto.createSpringJoint = function createSpringJoint(collider) {
1334
- return new PhysXSpringJoint(this, collider);
1335
- };
1336
- _proto._init = function _init(physX) {
1337
- var version = physX.PX_PHYSICS_VERSION;
1338
- var defaultErrorCallback = new physX.PxDefaultErrorCallback();
1339
- var allocator = new physX.PxDefaultAllocator();
1340
- var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
1341
- var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, new physX.PxTolerancesScale(), false, null);
1342
- physX.PxInitExtensions(pxPhysics, null);
1343
- this._physX = physX;
1344
- this._pxFoundation = pxFoundation;
1345
- this._pxPhysics = pxPhysics;
1346
- };
1347
- return PhysXPhysics;
1348
- }();
1349
- var InitializeState;
1350
- (function(InitializeState) {
1351
- InitializeState[InitializeState["Uninitialized"] = 0] = "Uninitialized";
1352
- InitializeState[InitializeState["Initializing"] = 1] = "Initializing";
1353
- InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
1354
- })(InitializeState || (InitializeState = {}));
1251
+ /**
1252
+ * PhysX object creation.
1253
+ */ var PhysXPhysics = /*#__PURE__*/ function() {
1254
+ function PhysXPhysics(runtimeMode) {
1255
+ if (runtimeMode === void 0) runtimeMode = exports.PhysXRuntimeMode.Auto;
1256
+ this._initializeState = 0;
1257
+ this._runTimeMode = runtimeMode;
1258
+ }
1259
+ var _proto = PhysXPhysics.prototype;
1260
+ /**
1261
+ * Initialize PhysXPhysics.
1262
+ * @param runtimeMode - Runtime mode
1263
+ * @returns Promise object
1264
+ */ _proto.initialize = function initialize() {
1265
+ var _this = this;
1266
+ if (this._initializeState === 2) {
1267
+ return Promise.resolve();
1268
+ } else if (this._initializeState === 1) {
1269
+ return this._initializePromise;
1270
+ }
1271
+ var runtimeMode = this._runTimeMode;
1272
+ var scriptPromise = new Promise(function(resolve, reject) {
1273
+ var script = document.createElement("script");
1274
+ document.body.appendChild(script);
1275
+ script.async = true;
1276
+ script.onload = resolve;
1277
+ script.onerror = reject;
1278
+ if (runtimeMode == exports.PhysXRuntimeMode.Auto) {
1279
+ var supported = function() {
1280
+ try {
1281
+ if (typeof WebAssembly === "object" && typeof WebAssembly.instantiate === "function") {
1282
+ var module = new WebAssembly.Module(Uint8Array.of(0x0, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00));
1283
+ if (_instanceof(module, WebAssembly.Module)) return _instanceof(new WebAssembly.Instance(module), WebAssembly.Instance);
1284
+ }
1285
+ } catch (e) {}
1286
+ return false;
1287
+ }();
1288
+ if (supported) {
1289
+ runtimeMode = exports.PhysXRuntimeMode.WebAssembly;
1290
+ } else {
1291
+ runtimeMode = exports.PhysXRuntimeMode.JavaScript;
1292
+ }
1293
+ }
1294
+ if (runtimeMode == exports.PhysXRuntimeMode.JavaScript) {
1295
+ script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js.js";
1296
+ } else if (runtimeMode == exports.PhysXRuntimeMode.WebAssembly) {
1297
+ script.src = "https://gw.alipayobjects.com/os/lib/oasis-engine/physics-physx/1.0.0-alpha.4/libs/physx.release.js";
1298
+ }
1299
+ });
1300
+ var initializePromise = new Promise(function(resolve, reject) {
1301
+ scriptPromise.then(function() {
1302
+ return window.PHYSX().then(function(PHYSX) {
1303
+ _this._init(PHYSX);
1304
+ _this._initializeState = 2;
1305
+ _this._initializePromise = null;
1306
+ console.log("PhysX loaded.");
1307
+ resolve();
1308
+ }, reject);
1309
+ }, reject).catch(reject);
1310
+ });
1311
+ this._initializePromise = initializePromise;
1312
+ return initializePromise;
1313
+ };
1314
+ /**
1315
+ * Destroy PhysXPhysics.
1316
+ */ _proto.destroy = function destroy() {
1317
+ this._physX.PxCloseExtensions();
1318
+ this._pxPhysics.release();
1319
+ this._pxFoundation.release();
1320
+ this._physX = null;
1321
+ this._pxFoundation = null;
1322
+ this._pxPhysics = null;
1323
+ };
1324
+ /**
1325
+ * {@inheritDoc IPhysics.createPhysicsManager }
1326
+ */ _proto.createPhysicsManager = function createPhysicsManager(onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay) {
1327
+ var manager = new PhysXPhysicsManager(this, onContactBegin, onContactEnd, onContactStay, onTriggerBegin, onTriggerEnd, onTriggerStay);
1328
+ return manager;
1329
+ };
1330
+ /**
1331
+ * {@inheritDoc IPhysics.createStaticCollider }
1332
+ */ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
1333
+ return new PhysXStaticCollider(this, position, rotation);
1334
+ };
1335
+ /**
1336
+ * {@inheritDoc IPhysics.createDynamicCollider }
1337
+ */ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
1338
+ return new PhysXDynamicCollider(this, position, rotation);
1339
+ };
1340
+ /**
1341
+ * {@inheritDoc IPhysics.createCharacterController }
1342
+ */ _proto.createCharacterController = function createCharacterController() {
1343
+ return new PhysXCharacterController(this);
1344
+ };
1345
+ /**
1346
+ * {@inheritDoc IPhysics.createPhysicsMaterial }
1347
+ */ _proto.createPhysicsMaterial = function createPhysicsMaterial(staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine) {
1348
+ return new PhysXPhysicsMaterial(this, staticFriction, dynamicFriction, bounciness, frictionCombine, bounceCombine);
1349
+ };
1350
+ /**
1351
+ * {@inheritDoc IPhysics.createBoxColliderShape }
1352
+ */ _proto.createBoxColliderShape = function createBoxColliderShape(uniqueID, size, material) {
1353
+ return new PhysXBoxColliderShape(this, uniqueID, size, material);
1354
+ };
1355
+ /**
1356
+ * {@inheritDoc IPhysics.createSphereColliderShape }
1357
+ */ _proto.createSphereColliderShape = function createSphereColliderShape(uniqueID, radius, material) {
1358
+ return new PhysXSphereColliderShape(this, uniqueID, radius, material);
1359
+ };
1360
+ /**
1361
+ * {@inheritDoc IPhysics.createPlaneColliderShape }
1362
+ */ _proto.createPlaneColliderShape = function createPlaneColliderShape(uniqueID, material) {
1363
+ return new PhysXPlaneColliderShape(this, uniqueID, material);
1364
+ };
1365
+ /**
1366
+ * {@inheritDoc IPhysics.createCapsuleColliderShape }
1367
+ */ _proto.createCapsuleColliderShape = function createCapsuleColliderShape(uniqueID, radius, height, material) {
1368
+ return new PhysXCapsuleColliderShape(this, uniqueID, radius, height, material);
1369
+ };
1370
+ /**
1371
+ * {@inheritDoc IPhysics.createFixedJoint }
1372
+ */ _proto.createFixedJoint = function createFixedJoint(collider) {
1373
+ return new PhysXFixedJoint(this, collider);
1374
+ };
1375
+ /**
1376
+ * {@inheritDoc IPhysics.createHingeJoint }
1377
+ */ _proto.createHingeJoint = function createHingeJoint(collider) {
1378
+ return new PhysXHingeJoint(this, collider);
1379
+ };
1380
+ /**
1381
+ * {@inheritDoc IPhysics.createSpringJoint }
1382
+ */ _proto.createSpringJoint = function createSpringJoint(collider) {
1383
+ return new PhysXSpringJoint(this, collider);
1384
+ };
1385
+ _proto._init = function _init(physX) {
1386
+ var version = physX.PX_PHYSICS_VERSION;
1387
+ var defaultErrorCallback = new physX.PxDefaultErrorCallback();
1388
+ var allocator = new physX.PxDefaultAllocator();
1389
+ var pxFoundation = physX.PxCreateFoundation(version, allocator, defaultErrorCallback);
1390
+ var pxPhysics = physX.PxCreatePhysics(version, pxFoundation, new physX.PxTolerancesScale(), false, null);
1391
+ physX.PxInitExtensions(pxPhysics, null);
1392
+ this._physX = physX;
1393
+ this._pxFoundation = pxFoundation;
1394
+ this._pxPhysics = pxPhysics;
1395
+ };
1396
+ return PhysXPhysics;
1397
+ }();
1398
+ var InitializeState;
1399
+ (function(InitializeState) {
1400
+ InitializeState[InitializeState["Uninitialized"] = 0] = "Uninitialized";
1401
+ InitializeState[InitializeState["Initializing"] = 1] = "Initializing";
1402
+ InitializeState[InitializeState["Initialized"] = 2] = "Initialized";
1403
+ })(InitializeState || (InitializeState = {}));
1355
1404
 
1356
- exports.PhysXPhysics = PhysXPhysics;
1405
+ exports.PhysXPhysics = PhysXPhysics;
1357
1406
 
1358
- Object.defineProperty(exports, '__esModule', { value: true });
1407
+ Object.defineProperty(exports, '__esModule', { value: true });
1359
1408
 
1360
1409
  }));