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