@galacean/engine-physics-lite 1.5.0-alpha.1 → 1.5.0-beta.0
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 +87 -20
- package/dist/browser.js.map +1 -1
- package/dist/browser.min.js +1 -1
- package/dist/browser.min.js.map +1 -1
- package/dist/main.js +87 -20
- package/dist/main.js.map +1 -1
- package/dist/module.js +87 -20
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/LiteCollider.d.ts +8 -2
- package/types/LiteDynamicCollider.d.ts +2 -1
- package/types/LitePhysics.d.ts +19 -1
- package/types/LitePhysicsScene.d.ts +15 -8
- package/types/LiteStaticCollider.d.ts +2 -1
package/dist/browser.js
CHANGED
|
@@ -481,10 +481,11 @@
|
|
|
481
481
|
/**
|
|
482
482
|
* Abstract class of physical collider.
|
|
483
483
|
*/ var LiteCollider = /*#__PURE__*/ function() {
|
|
484
|
-
function LiteCollider() {
|
|
484
|
+
function LiteCollider(litePhysics) {
|
|
485
485
|
/** @internal */ this._shapes = [];
|
|
486
486
|
/** @internal */ this._transform = new LiteTransform();
|
|
487
487
|
this._transform.owner = this;
|
|
488
|
+
this._litePhysics = litePhysics;
|
|
488
489
|
}
|
|
489
490
|
var _proto = LiteCollider.prototype;
|
|
490
491
|
/**
|
|
@@ -526,6 +527,11 @@
|
|
|
526
527
|
outRotation.set(rotationQuaternion.x, rotationQuaternion.y, rotationQuaternion.z, rotationQuaternion.w);
|
|
527
528
|
};
|
|
528
529
|
/**
|
|
530
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
531
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(collisionLayer) {
|
|
532
|
+
this._litePhysics.setColliderLayer(this, collisionLayer);
|
|
533
|
+
};
|
|
534
|
+
/**
|
|
529
535
|
* {@inheritDoc ICollider.destroy }
|
|
530
536
|
*/ _proto.destroy = function destroy() {};
|
|
531
537
|
/**
|
|
@@ -546,9 +552,9 @@
|
|
|
546
552
|
* A dynamic collider can act with self-defined movement or physical force
|
|
547
553
|
*/ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
548
554
|
_inherits(LiteDynamicCollider, LiteCollider);
|
|
549
|
-
function LiteDynamicCollider(position, rotation) {
|
|
555
|
+
function LiteDynamicCollider(litePhysics, position, rotation) {
|
|
550
556
|
var _this;
|
|
551
|
-
_this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = false;
|
|
557
|
+
_this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = false;
|
|
552
558
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
553
559
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
554
560
|
return _this;
|
|
@@ -910,7 +916,7 @@
|
|
|
910
916
|
/**
|
|
911
917
|
* A manager is a collection of colliders and constraints which can interact.
|
|
912
918
|
*/ var LitePhysicsScene = /*#__PURE__*/ function() {
|
|
913
|
-
function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
919
|
+
function LitePhysicsScene(physics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
914
920
|
this._staticColliders = [];
|
|
915
921
|
this._dynamicColliders = [];
|
|
916
922
|
this._sphere = new engine.BoundingSphere();
|
|
@@ -918,6 +924,7 @@
|
|
|
918
924
|
this._currentEvents = new engine.DisorderedArray();
|
|
919
925
|
this._eventMap = {};
|
|
920
926
|
this._eventPool = [];
|
|
927
|
+
this._physics = physics;
|
|
921
928
|
this._onContactEnter = onContactEnter;
|
|
922
929
|
this._onContactExit = onContactExit;
|
|
923
930
|
this._onContactStay = onContactStay;
|
|
@@ -927,12 +934,12 @@
|
|
|
927
934
|
}
|
|
928
935
|
var _proto = LitePhysicsScene.prototype;
|
|
929
936
|
/**
|
|
930
|
-
* {@inheritDoc
|
|
937
|
+
* {@inheritDoc IPhysicsScene.setGravity }
|
|
931
938
|
*/ _proto.setGravity = function setGravity(value) {
|
|
932
939
|
console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
|
|
933
940
|
};
|
|
934
941
|
/**
|
|
935
|
-
* {@inheritDoc
|
|
942
|
+
* {@inheritDoc IPhysicsScene.addCollider }
|
|
936
943
|
*/ _proto.addCollider = function addCollider(actor) {
|
|
937
944
|
actor._scene = this;
|
|
938
945
|
var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
@@ -943,7 +950,7 @@
|
|
|
943
950
|
}
|
|
944
951
|
};
|
|
945
952
|
/**
|
|
946
|
-
* {@inheritDoc
|
|
953
|
+
* {@inheritDoc IPhysicsScene.removeCollider }
|
|
947
954
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
948
955
|
collider._scene = null;
|
|
949
956
|
var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
@@ -955,7 +962,7 @@
|
|
|
955
962
|
}
|
|
956
963
|
};
|
|
957
964
|
/**
|
|
958
|
-
* {@inheritDoc
|
|
965
|
+
* {@inheritDoc IPhysicsScene.update }
|
|
959
966
|
*/ _proto.update = function update(deltaTime) {
|
|
960
967
|
var dynamicColliders = this._dynamicColliders;
|
|
961
968
|
for(var i = 0, len = dynamicColliders.length; i < len; i++){
|
|
@@ -966,7 +973,7 @@
|
|
|
966
973
|
this._fireEvent();
|
|
967
974
|
};
|
|
968
975
|
/**
|
|
969
|
-
* {@inheritDoc
|
|
976
|
+
* {@inheritDoc IPhysicsScene.raycast }
|
|
970
977
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
971
978
|
if (!hit) {
|
|
972
979
|
return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
|
|
@@ -990,16 +997,19 @@
|
|
|
990
997
|
}
|
|
991
998
|
};
|
|
992
999
|
/**
|
|
993
|
-
* {@inheritDoc
|
|
1000
|
+
* {@inheritDoc IPhysicsScene.addCharacterController }
|
|
994
1001
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
995
1002
|
throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
|
|
996
1003
|
};
|
|
997
1004
|
/**
|
|
998
|
-
* {@inheritDoc
|
|
1005
|
+
* {@inheritDoc IPhysicsScene.removeCharacterController }
|
|
999
1006
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
1000
1007
|
throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
|
|
1001
1008
|
};
|
|
1002
1009
|
/**
|
|
1010
|
+
* {@inheritDoc IPhysicsScene.destroy }
|
|
1011
|
+
*/ _proto.destroy = function destroy() {};
|
|
1012
|
+
/**
|
|
1003
1013
|
* @internal
|
|
1004
1014
|
*/ _proto._addColliderShape = function _addColliderShape(colliderShape) {
|
|
1005
1015
|
this._eventMap[colliderShape._id] = {};
|
|
@@ -1041,7 +1051,12 @@
|
|
|
1041
1051
|
if (_instanceof(myShape, LiteBoxColliderShape)) {
|
|
1042
1052
|
LitePhysicsScene._updateWorldBox(myShape, this._box);
|
|
1043
1053
|
for(var j = 0, len1 = colliders.length; j < len1; j++){
|
|
1044
|
-
var
|
|
1054
|
+
var collider = colliders[j];
|
|
1055
|
+
var colliderShape = collider._shapes;
|
|
1056
|
+
// Skip collision check if layers can't collide
|
|
1057
|
+
if (!this._checkColliderCollide(collider, myCollider)) {
|
|
1058
|
+
continue;
|
|
1059
|
+
}
|
|
1045
1060
|
for(var k = 0, len2 = colliderShape.length; k < len2; k++){
|
|
1046
1061
|
var shape = colliderShape[k];
|
|
1047
1062
|
var index1 = shape._id;
|
|
@@ -1068,7 +1083,12 @@
|
|
|
1068
1083
|
} else if (_instanceof(myShape, LiteSphereColliderShape)) {
|
|
1069
1084
|
LitePhysicsScene._upWorldSphere(myShape, this._sphere);
|
|
1070
1085
|
for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
|
|
1071
|
-
var
|
|
1086
|
+
var collider1 = colliders[j1];
|
|
1087
|
+
var colliderShape1 = collider1._shapes;
|
|
1088
|
+
// Skip collision check if layers can't collide
|
|
1089
|
+
if (!this._checkColliderCollide(collider1, myCollider)) {
|
|
1090
|
+
continue;
|
|
1091
|
+
}
|
|
1072
1092
|
for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
|
|
1073
1093
|
var shape1 = colliderShape1[k1];
|
|
1074
1094
|
var index11 = shape1._id;
|
|
@@ -1159,6 +1179,14 @@
|
|
|
1159
1179
|
}
|
|
1160
1180
|
return isHit;
|
|
1161
1181
|
};
|
|
1182
|
+
_proto._checkColliderCollide = function _checkColliderCollide(collider1, collider2) {
|
|
1183
|
+
var group1 = collider1._collisionLayer;
|
|
1184
|
+
var group2 = collider2._collisionLayer;
|
|
1185
|
+
if (group1 === group2) {
|
|
1186
|
+
return true;
|
|
1187
|
+
}
|
|
1188
|
+
return this._physics.getColliderLayerCollision(group1, group2);
|
|
1189
|
+
};
|
|
1162
1190
|
/**
|
|
1163
1191
|
* Calculate the bounding box in world space from boxCollider.
|
|
1164
1192
|
* @param boxCollider - The boxCollider to calculate
|
|
@@ -1196,9 +1224,9 @@
|
|
|
1196
1224
|
* @remarks Mostly used for object which always stays at the same place and never moves around.
|
|
1197
1225
|
*/ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
1198
1226
|
_inherits(LiteStaticCollider, LiteCollider);
|
|
1199
|
-
function LiteStaticCollider(position, rotation) {
|
|
1227
|
+
function LiteStaticCollider(litePhysics, position, rotation) {
|
|
1200
1228
|
var _this;
|
|
1201
|
-
_this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = true;
|
|
1229
|
+
_this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = true;
|
|
1202
1230
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
1203
1231
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
1204
1232
|
return _this;
|
|
@@ -1207,7 +1235,9 @@
|
|
|
1207
1235
|
}(LiteCollider);
|
|
1208
1236
|
|
|
1209
1237
|
var LitePhysics = /*#__PURE__*/ function() {
|
|
1210
|
-
function LitePhysics() {
|
|
1238
|
+
function LitePhysics() {
|
|
1239
|
+
this._layerCollisionMatrix = [];
|
|
1240
|
+
}
|
|
1211
1241
|
var _proto = LitePhysics.prototype;
|
|
1212
1242
|
/**
|
|
1213
1243
|
* {@inheritDoc IPhysics.initialize }
|
|
@@ -1222,17 +1252,17 @@
|
|
|
1222
1252
|
/**
|
|
1223
1253
|
* {@inheritDoc IPhysics.createPhysicsScene }
|
|
1224
1254
|
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
|
|
1225
|
-
return new LitePhysicsScene(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
|
|
1255
|
+
return new LitePhysicsScene(this, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
|
|
1226
1256
|
};
|
|
1227
1257
|
/**
|
|
1228
1258
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
1229
1259
|
*/ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
|
|
1230
|
-
return new LiteStaticCollider(position, rotation);
|
|
1260
|
+
return new LiteStaticCollider(this, position, rotation);
|
|
1231
1261
|
};
|
|
1232
1262
|
/**
|
|
1233
1263
|
* {@inheritDoc IPhysics.createDynamicCollider }
|
|
1234
1264
|
*/ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
|
|
1235
|
-
return new LiteDynamicCollider(position, rotation);
|
|
1265
|
+
return new LiteDynamicCollider(this, position, rotation);
|
|
1236
1266
|
};
|
|
1237
1267
|
/**
|
|
1238
1268
|
* {@inheritDoc IPhysics.createCharacterController }
|
|
@@ -1279,11 +1309,48 @@
|
|
|
1279
1309
|
*/ _proto.createSpringJoint = function createSpringJoint(collider) {
|
|
1280
1310
|
throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
|
|
1281
1311
|
};
|
|
1312
|
+
/**
|
|
1313
|
+
* {@inheritDoc IPhysics.setColliderLayer }
|
|
1314
|
+
*/ _proto.setColliderLayer = function setColliderLayer(collider, layer) {
|
|
1315
|
+
collider._collisionLayer = layer;
|
|
1316
|
+
};
|
|
1317
|
+
/**
|
|
1318
|
+
* {@inheritDoc IPhysics.getColliderLayerCollision }
|
|
1319
|
+
*/ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
|
|
1320
|
+
var index = this._getColliderLayerIndex(layer1, layer2);
|
|
1321
|
+
if (index > -1) {
|
|
1322
|
+
var _this__layerCollisionMatrix_index;
|
|
1323
|
+
return (_this__layerCollisionMatrix_index = this._layerCollisionMatrix[index]) != null ? _this__layerCollisionMatrix_index : true;
|
|
1324
|
+
}
|
|
1325
|
+
// If either layer is Layer.Nothing, they cant collide
|
|
1326
|
+
return false;
|
|
1327
|
+
};
|
|
1328
|
+
/**
|
|
1329
|
+
* {@inheritDoc IPhysics.setColliderLayerCollision }
|
|
1330
|
+
*/ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, collide) {
|
|
1331
|
+
var index = this._getColliderLayerIndex(layer1, layer2);
|
|
1332
|
+
if (index > -1) {
|
|
1333
|
+
this._layerCollisionMatrix[index] = collide;
|
|
1334
|
+
}
|
|
1335
|
+
};
|
|
1336
|
+
/**
|
|
1337
|
+
* {@inheritDoc IPhysics.destroy }
|
|
1338
|
+
*/ _proto.destroy = function destroy() {};
|
|
1339
|
+
_proto._getColliderLayerIndex = function _getColliderLayerIndex(layer1, layer2) {
|
|
1340
|
+
if (layer1 === 32 || layer2 === 32) {
|
|
1341
|
+
return -1;
|
|
1342
|
+
}
|
|
1343
|
+
var min = Math.min(layer1, layer2);
|
|
1344
|
+
var max = Math.max(layer1, layer2);
|
|
1345
|
+
// Calculate a unique index for the layer pair using the triangular number formula
|
|
1346
|
+
// This ensures that each layer combination maps to a unique index in the collision matrix
|
|
1347
|
+
return max * (max + 1) / 2 + min;
|
|
1348
|
+
};
|
|
1282
1349
|
return LitePhysics;
|
|
1283
1350
|
}();
|
|
1284
1351
|
|
|
1285
1352
|
//@ts-ignore
|
|
1286
|
-
var version = "1.5.0-
|
|
1353
|
+
var version = "1.5.0-beta.0";
|
|
1287
1354
|
console.log("Galacean Engine Physics Lite Version: " + version);
|
|
1288
1355
|
|
|
1289
1356
|
exports.LitePhysics = LitePhysics;
|