@galacean/engine-physics-lite 1.5.0-alpha.0 → 1.5.0-alpha.2
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/module.js
CHANGED
|
@@ -477,10 +477,11 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
477
477
|
/**
|
|
478
478
|
* Abstract class of physical collider.
|
|
479
479
|
*/ var LiteCollider = /*#__PURE__*/ function() {
|
|
480
|
-
function LiteCollider() {
|
|
480
|
+
function LiteCollider(litePhysics) {
|
|
481
481
|
/** @internal */ this._shapes = [];
|
|
482
482
|
/** @internal */ this._transform = new LiteTransform();
|
|
483
483
|
this._transform.owner = this;
|
|
484
|
+
this._litePhysics = litePhysics;
|
|
484
485
|
}
|
|
485
486
|
var _proto = LiteCollider.prototype;
|
|
486
487
|
/**
|
|
@@ -522,6 +523,11 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
522
523
|
outRotation.set(rotationQuaternion.x, rotationQuaternion.y, rotationQuaternion.z, rotationQuaternion.w);
|
|
523
524
|
};
|
|
524
525
|
/**
|
|
526
|
+
* {@inheritDoc ICollider.setCollisionLayer }
|
|
527
|
+
*/ _proto.setCollisionLayer = function setCollisionLayer(collisionLayer) {
|
|
528
|
+
this._litePhysics.setColliderLayer(this, collisionLayer);
|
|
529
|
+
};
|
|
530
|
+
/**
|
|
525
531
|
* {@inheritDoc ICollider.destroy }
|
|
526
532
|
*/ _proto.destroy = function destroy() {};
|
|
527
533
|
/**
|
|
@@ -542,9 +548,9 @@ LiteTransform._tempMat42 = new Matrix();
|
|
|
542
548
|
* A dynamic collider can act with self-defined movement or physical force
|
|
543
549
|
*/ var LiteDynamicCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
544
550
|
_inherits(LiteDynamicCollider, LiteCollider);
|
|
545
|
-
function LiteDynamicCollider(position, rotation) {
|
|
551
|
+
function LiteDynamicCollider(litePhysics, position, rotation) {
|
|
546
552
|
var _this;
|
|
547
|
-
_this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = false;
|
|
553
|
+
_this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = false;
|
|
548
554
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
549
555
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
550
556
|
return _this;
|
|
@@ -906,7 +912,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
906
912
|
/**
|
|
907
913
|
* A manager is a collection of colliders and constraints which can interact.
|
|
908
914
|
*/ var LitePhysicsScene = /*#__PURE__*/ function() {
|
|
909
|
-
function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
915
|
+
function LitePhysicsScene(physics, onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
910
916
|
this._staticColliders = [];
|
|
911
917
|
this._dynamicColliders = [];
|
|
912
918
|
this._sphere = new BoundingSphere();
|
|
@@ -914,6 +920,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
914
920
|
this._currentEvents = new DisorderedArray();
|
|
915
921
|
this._eventMap = {};
|
|
916
922
|
this._eventPool = [];
|
|
923
|
+
this._physics = physics;
|
|
917
924
|
this._onContactEnter = onContactEnter;
|
|
918
925
|
this._onContactExit = onContactExit;
|
|
919
926
|
this._onContactStay = onContactStay;
|
|
@@ -923,12 +930,12 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
923
930
|
}
|
|
924
931
|
var _proto = LitePhysicsScene.prototype;
|
|
925
932
|
/**
|
|
926
|
-
* {@inheritDoc
|
|
933
|
+
* {@inheritDoc IPhysicsScene.setGravity }
|
|
927
934
|
*/ _proto.setGravity = function setGravity(value) {
|
|
928
935
|
console.log("Physics-lite don't support gravity. Use Physics-PhysX instead!");
|
|
929
936
|
};
|
|
930
937
|
/**
|
|
931
|
-
* {@inheritDoc
|
|
938
|
+
* {@inheritDoc IPhysicsScene.addCollider }
|
|
932
939
|
*/ _proto.addCollider = function addCollider(actor) {
|
|
933
940
|
actor._scene = this;
|
|
934
941
|
var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
@@ -939,7 +946,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
939
946
|
}
|
|
940
947
|
};
|
|
941
948
|
/**
|
|
942
|
-
* {@inheritDoc
|
|
949
|
+
* {@inheritDoc IPhysicsScene.removeCollider }
|
|
943
950
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
944
951
|
collider._scene = null;
|
|
945
952
|
var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
@@ -951,7 +958,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
951
958
|
}
|
|
952
959
|
};
|
|
953
960
|
/**
|
|
954
|
-
* {@inheritDoc
|
|
961
|
+
* {@inheritDoc IPhysicsScene.update }
|
|
955
962
|
*/ _proto.update = function update(deltaTime) {
|
|
956
963
|
var dynamicColliders = this._dynamicColliders;
|
|
957
964
|
for(var i = 0, len = dynamicColliders.length; i < len; i++){
|
|
@@ -962,7 +969,7 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
962
969
|
this._fireEvent();
|
|
963
970
|
};
|
|
964
971
|
/**
|
|
965
|
-
* {@inheritDoc
|
|
972
|
+
* {@inheritDoc IPhysicsScene.raycast }
|
|
966
973
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
967
974
|
if (!hit) {
|
|
968
975
|
return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
|
|
@@ -986,16 +993,19 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
986
993
|
}
|
|
987
994
|
};
|
|
988
995
|
/**
|
|
989
|
-
* {@inheritDoc
|
|
996
|
+
* {@inheritDoc IPhysicsScene.addCharacterController }
|
|
990
997
|
*/ _proto.addCharacterController = function addCharacterController(characterController) {
|
|
991
998
|
throw "Physics-lite don't support addCharacterController. Use Physics-PhysX instead!";
|
|
992
999
|
};
|
|
993
1000
|
/**
|
|
994
|
-
* {@inheritDoc
|
|
1001
|
+
* {@inheritDoc IPhysicsScene.removeCharacterController }
|
|
995
1002
|
*/ _proto.removeCharacterController = function removeCharacterController(characterController) {
|
|
996
1003
|
throw "Physics-lite don't support removeCharacterController. Use Physics-PhysX instead!";
|
|
997
1004
|
};
|
|
998
1005
|
/**
|
|
1006
|
+
* {@inheritDoc IPhysicsScene.destroy }
|
|
1007
|
+
*/ _proto.destroy = function destroy() {};
|
|
1008
|
+
/**
|
|
999
1009
|
* @internal
|
|
1000
1010
|
*/ _proto._addColliderShape = function _addColliderShape(colliderShape) {
|
|
1001
1011
|
this._eventMap[colliderShape._id] = {};
|
|
@@ -1037,7 +1047,12 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
1037
1047
|
if (_instanceof(myShape, LiteBoxColliderShape)) {
|
|
1038
1048
|
LitePhysicsScene._updateWorldBox(myShape, this._box);
|
|
1039
1049
|
for(var j = 0, len1 = colliders.length; j < len1; j++){
|
|
1040
|
-
var
|
|
1050
|
+
var collider = colliders[j];
|
|
1051
|
+
var colliderShape = collider._shapes;
|
|
1052
|
+
// Skip collision check if layers can't collide
|
|
1053
|
+
if (!this._checkColliderCollide(collider, myCollider)) {
|
|
1054
|
+
continue;
|
|
1055
|
+
}
|
|
1041
1056
|
for(var k = 0, len2 = colliderShape.length; k < len2; k++){
|
|
1042
1057
|
var shape = colliderShape[k];
|
|
1043
1058
|
var index1 = shape._id;
|
|
@@ -1064,7 +1079,12 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
1064
1079
|
} else if (_instanceof(myShape, LiteSphereColliderShape)) {
|
|
1065
1080
|
LitePhysicsScene._upWorldSphere(myShape, this._sphere);
|
|
1066
1081
|
for(var j1 = 0, len3 = colliders.length; j1 < len3; j1++){
|
|
1067
|
-
var
|
|
1082
|
+
var collider1 = colliders[j1];
|
|
1083
|
+
var colliderShape1 = collider1._shapes;
|
|
1084
|
+
// Skip collision check if layers can't collide
|
|
1085
|
+
if (!this._checkColliderCollide(collider1, myCollider)) {
|
|
1086
|
+
continue;
|
|
1087
|
+
}
|
|
1068
1088
|
for(var k1 = 0, len4 = colliderShape1.length; k1 < len4; k1++){
|
|
1069
1089
|
var shape1 = colliderShape1[k1];
|
|
1070
1090
|
var index11 = shape1._id;
|
|
@@ -1155,6 +1175,14 @@ LiteSphereColliderShape._tempSphere = new BoundingSphere();
|
|
|
1155
1175
|
}
|
|
1156
1176
|
return isHit;
|
|
1157
1177
|
};
|
|
1178
|
+
_proto._checkColliderCollide = function _checkColliderCollide(collider1, collider2) {
|
|
1179
|
+
var group1 = collider1._collisionLayer;
|
|
1180
|
+
var group2 = collider2._collisionLayer;
|
|
1181
|
+
if (group1 === group2) {
|
|
1182
|
+
return true;
|
|
1183
|
+
}
|
|
1184
|
+
return this._physics.getColliderLayerCollision(group1, group2);
|
|
1185
|
+
};
|
|
1158
1186
|
/**
|
|
1159
1187
|
* Calculate the bounding box in world space from boxCollider.
|
|
1160
1188
|
* @param boxCollider - The boxCollider to calculate
|
|
@@ -1192,9 +1220,9 @@ LitePhysicsScene._hitResult = new LiteHitResult();
|
|
|
1192
1220
|
* @remarks Mostly used for object which always stays at the same place and never moves around.
|
|
1193
1221
|
*/ var LiteStaticCollider = /*#__PURE__*/ function(LiteCollider) {
|
|
1194
1222
|
_inherits(LiteStaticCollider, LiteCollider);
|
|
1195
|
-
function LiteStaticCollider(position, rotation) {
|
|
1223
|
+
function LiteStaticCollider(litePhysics, position, rotation) {
|
|
1196
1224
|
var _this;
|
|
1197
|
-
_this = LiteCollider.call(this) || this, /** @internal */ _this._isStaticCollider = true;
|
|
1225
|
+
_this = LiteCollider.call(this, litePhysics) || this, /** @internal */ _this._isStaticCollider = true;
|
|
1198
1226
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
1199
1227
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
1200
1228
|
return _this;
|
|
@@ -1203,7 +1231,9 @@ LitePhysicsScene._hitResult = new LiteHitResult();
|
|
|
1203
1231
|
}(LiteCollider);
|
|
1204
1232
|
|
|
1205
1233
|
var LitePhysics = /*#__PURE__*/ function() {
|
|
1206
|
-
function LitePhysics() {
|
|
1234
|
+
function LitePhysics() {
|
|
1235
|
+
this._layerCollisionMatrix = [];
|
|
1236
|
+
}
|
|
1207
1237
|
var _proto = LitePhysics.prototype;
|
|
1208
1238
|
/**
|
|
1209
1239
|
* {@inheritDoc IPhysics.initialize }
|
|
@@ -1218,17 +1248,17 @@ var LitePhysics = /*#__PURE__*/ function() {
|
|
|
1218
1248
|
/**
|
|
1219
1249
|
* {@inheritDoc IPhysics.createPhysicsScene }
|
|
1220
1250
|
*/ _proto.createPhysicsScene = function createPhysicsScene(physicsManager, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist) {
|
|
1221
|
-
return new LitePhysicsScene(onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
|
|
1251
|
+
return new LitePhysicsScene(this, onContactBegin, onContactEnd, onContactPersist, onTriggerBegin, onTriggerEnd, onTriggerPersist);
|
|
1222
1252
|
};
|
|
1223
1253
|
/**
|
|
1224
1254
|
* {@inheritDoc IPhysics.createStaticCollider }
|
|
1225
1255
|
*/ _proto.createStaticCollider = function createStaticCollider(position, rotation) {
|
|
1226
|
-
return new LiteStaticCollider(position, rotation);
|
|
1256
|
+
return new LiteStaticCollider(this, position, rotation);
|
|
1227
1257
|
};
|
|
1228
1258
|
/**
|
|
1229
1259
|
* {@inheritDoc IPhysics.createDynamicCollider }
|
|
1230
1260
|
*/ _proto.createDynamicCollider = function createDynamicCollider(position, rotation) {
|
|
1231
|
-
return new LiteDynamicCollider(position, rotation);
|
|
1261
|
+
return new LiteDynamicCollider(this, position, rotation);
|
|
1232
1262
|
};
|
|
1233
1263
|
/**
|
|
1234
1264
|
* {@inheritDoc IPhysics.createCharacterController }
|
|
@@ -1275,11 +1305,48 @@ var LitePhysics = /*#__PURE__*/ function() {
|
|
|
1275
1305
|
*/ _proto.createSpringJoint = function createSpringJoint(collider) {
|
|
1276
1306
|
throw "Physics-lite don't support CapsuleColliderShape. Use Physics-PhysX instead!";
|
|
1277
1307
|
};
|
|
1308
|
+
/**
|
|
1309
|
+
* {@inheritDoc IPhysics.setColliderLayer }
|
|
1310
|
+
*/ _proto.setColliderLayer = function setColliderLayer(collider, layer) {
|
|
1311
|
+
collider._collisionLayer = layer;
|
|
1312
|
+
};
|
|
1313
|
+
/**
|
|
1314
|
+
* {@inheritDoc IPhysics.getColliderLayerCollision }
|
|
1315
|
+
*/ _proto.getColliderLayerCollision = function getColliderLayerCollision(layer1, layer2) {
|
|
1316
|
+
var index = this._getColliderLayerIndex(layer1, layer2);
|
|
1317
|
+
if (index > -1) {
|
|
1318
|
+
var _this__layerCollisionMatrix_index;
|
|
1319
|
+
return (_this__layerCollisionMatrix_index = this._layerCollisionMatrix[index]) != null ? _this__layerCollisionMatrix_index : true;
|
|
1320
|
+
}
|
|
1321
|
+
// If either layer is Layer.Nothing, they cant collide
|
|
1322
|
+
return false;
|
|
1323
|
+
};
|
|
1324
|
+
/**
|
|
1325
|
+
* {@inheritDoc IPhysics.setColliderLayerCollision }
|
|
1326
|
+
*/ _proto.setColliderLayerCollision = function setColliderLayerCollision(layer1, layer2, collide) {
|
|
1327
|
+
var index = this._getColliderLayerIndex(layer1, layer2);
|
|
1328
|
+
if (index > -1) {
|
|
1329
|
+
this._layerCollisionMatrix[index] = collide;
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
/**
|
|
1333
|
+
* {@inheritDoc IPhysics.destroy }
|
|
1334
|
+
*/ _proto.destroy = function destroy() {};
|
|
1335
|
+
_proto._getColliderLayerIndex = function _getColliderLayerIndex(layer1, layer2) {
|
|
1336
|
+
if (layer1 === 32 || layer2 === 32) {
|
|
1337
|
+
return -1;
|
|
1338
|
+
}
|
|
1339
|
+
var min = Math.min(layer1, layer2);
|
|
1340
|
+
var max = Math.max(layer1, layer2);
|
|
1341
|
+
// Calculate a unique index for the layer pair using the triangular number formula
|
|
1342
|
+
// This ensures that each layer combination maps to a unique index in the collision matrix
|
|
1343
|
+
return max * (max + 1) / 2 + min;
|
|
1344
|
+
};
|
|
1278
1345
|
return LitePhysics;
|
|
1279
1346
|
}();
|
|
1280
1347
|
|
|
1281
1348
|
//@ts-ignore
|
|
1282
|
-
var version = "1.5.0-alpha.
|
|
1349
|
+
var version = "1.5.0-alpha.2";
|
|
1283
1350
|
console.log("Galacean Engine Physics Lite Version: " + version);
|
|
1284
1351
|
|
|
1285
1352
|
export { LitePhysics, version };
|