@galacean/engine-physics-lite 1.2.0-beta.6 → 1.3.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.js +57 -41
- 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 +57 -41
- package/dist/main.js.map +1 -1
- package/dist/miniprogram.js +57 -41
- package/dist/module.js +57 -41
- package/dist/module.js.map +1 -1
- package/package.json +4 -4
- package/types/LitePhysicsScene.d.ts +3 -1
- package/types/StaticInterfaceImplement.d.ts +5 -0
package/dist/main.js
CHANGED
|
@@ -566,6 +566,7 @@ var /**
|
|
|
566
566
|
function LiteDynamicCollider(position, rotation) {
|
|
567
567
|
var _this;
|
|
568
568
|
_this = LiteCollider1.call(this) || this;
|
|
569
|
+
/** @internal */ _this._isStaticCollider = false;
|
|
569
570
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
570
571
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
571
572
|
return _this;
|
|
@@ -884,7 +885,8 @@ var /**
|
|
|
884
885
|
* A manager is a collection of colliders and constraints which can interact.
|
|
885
886
|
*/ var LitePhysicsScene = /*#__PURE__*/ function() {
|
|
886
887
|
function LitePhysicsScene(onContactEnter, onContactExit, onContactStay, onTriggerEnter, onTriggerExit, onTriggerStay) {
|
|
887
|
-
this.
|
|
888
|
+
this._staticColliders = [];
|
|
889
|
+
this._dynamicColliders = [];
|
|
888
890
|
this._sphere = new engine.BoundingSphere();
|
|
889
891
|
this._box = new engine.BoundingBox();
|
|
890
892
|
this._currentEvents = new DisorderedArray();
|
|
@@ -930,61 +932,49 @@ var /**
|
|
|
930
932
|
/**
|
|
931
933
|
* {@inheritDoc IPhysicsManager.addCollider }
|
|
932
934
|
*/ _proto.addCollider = function addCollider(actor) {
|
|
933
|
-
this.
|
|
935
|
+
var colliders = actor._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
936
|
+
colliders.push(actor);
|
|
934
937
|
};
|
|
935
938
|
/**
|
|
936
939
|
* {@inheritDoc IPhysicsManager.removeCollider }
|
|
937
940
|
*/ _proto.removeCollider = function removeCollider(collider) {
|
|
938
|
-
var
|
|
941
|
+
var colliders = collider._isStaticCollider ? this._staticColliders : this._dynamicColliders;
|
|
942
|
+
var index = colliders.indexOf(collider);
|
|
939
943
|
if (index !== -1) {
|
|
940
|
-
|
|
944
|
+
colliders.splice(index, 1);
|
|
941
945
|
}
|
|
942
946
|
};
|
|
943
947
|
/**
|
|
944
948
|
* {@inheritDoc IPhysicsManager.update }
|
|
945
949
|
*/ _proto.update = function update(deltaTime) {
|
|
946
|
-
var
|
|
947
|
-
for(var i = 0, len =
|
|
948
|
-
|
|
950
|
+
var dynamicColliders = this._dynamicColliders;
|
|
951
|
+
for(var i = 0, len = dynamicColliders.length; i < len; i++){
|
|
952
|
+
var collider = dynamicColliders[i];
|
|
953
|
+
this._collisionDetection(collider, this._staticColliders);
|
|
954
|
+
this._collisionDetection(collider, dynamicColliders);
|
|
949
955
|
}
|
|
950
956
|
this._fireEvent();
|
|
951
957
|
};
|
|
952
958
|
/**
|
|
953
959
|
* {@inheritDoc IPhysicsManager.raycast }
|
|
954
960
|
*/ _proto.raycast = function raycast(ray, distance, onRaycast, hit) {
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
hitResult.point.copyFrom(curHit.point);
|
|
970
|
-
hitResult.distance = curHit.distance;
|
|
971
|
-
hitResult.shapeID = curHit.shapeID;
|
|
972
|
-
} else {
|
|
973
|
-
return true;
|
|
974
|
-
}
|
|
975
|
-
distance = curHit.distance;
|
|
976
|
-
}
|
|
961
|
+
if (!hit) {
|
|
962
|
+
return this._raycast(ray, distance, onRaycast, this._staticColliders, hit) || this._raycast(ray, distance, onRaycast, this._dynamicColliders, hit);
|
|
963
|
+
} else {
|
|
964
|
+
var raycastStaticRes = this._raycast(ray, distance, onRaycast, this._staticColliders, hit);
|
|
965
|
+
var raycastDynamicRes = this._raycast(ray, LitePhysicsScene._currentHit.distance, onRaycast, this._dynamicColliders, hit);
|
|
966
|
+
var isHit = raycastStaticRes || raycastDynamicRes;
|
|
967
|
+
var hitResult = LitePhysicsScene._hitResult;
|
|
968
|
+
if (!isHit) {
|
|
969
|
+
hitResult.shapeID = -1;
|
|
970
|
+
hitResult.distance = 0;
|
|
971
|
+
hitResult.point.set(0, 0, 0);
|
|
972
|
+
hitResult.normal.set(0, 0, 0);
|
|
973
|
+
} else {
|
|
974
|
+
hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
|
|
977
975
|
}
|
|
976
|
+
return isHit;
|
|
978
977
|
}
|
|
979
|
-
if (!isHit && hitResult) {
|
|
980
|
-
hitResult.shapeID = -1;
|
|
981
|
-
hitResult.distance = 0;
|
|
982
|
-
hitResult.point.set(0, 0, 0);
|
|
983
|
-
hitResult.normal.set(0, 0, 0);
|
|
984
|
-
} else if (isHit && hitResult) {
|
|
985
|
-
hit(hitResult.shapeID, hitResult.distance, hitResult.point, hitResult.normal);
|
|
986
|
-
}
|
|
987
|
-
return isHit;
|
|
988
978
|
};
|
|
989
979
|
/**
|
|
990
980
|
* {@inheritDoc IPhysicsManager.addCharacterController }
|
|
@@ -1008,8 +998,7 @@ var /**
|
|
|
1008
998
|
this._eventMap[index1][index2] = event;
|
|
1009
999
|
return event;
|
|
1010
1000
|
};
|
|
1011
|
-
_proto._collisionDetection = function _collisionDetection(
|
|
1012
|
-
var colliders = this._colliders;
|
|
1001
|
+
_proto._collisionDetection = function _collisionDetection(myCollider, colliders) {
|
|
1013
1002
|
var myColliderShapes = myCollider._shapes;
|
|
1014
1003
|
for(var i = 0, len = myColliderShapes.length; i < len; i++){
|
|
1015
1004
|
var myShape = myColliderShapes[i];
|
|
@@ -1115,6 +1104,32 @@ var /**
|
|
|
1115
1104
|
}
|
|
1116
1105
|
return false;
|
|
1117
1106
|
};
|
|
1107
|
+
_proto._raycast = function _raycast(ray, distance, onRaycast, colliders, hit) {
|
|
1108
|
+
var hitResult;
|
|
1109
|
+
if (hit) {
|
|
1110
|
+
hitResult = LitePhysicsScene._hitResult;
|
|
1111
|
+
}
|
|
1112
|
+
var isHit = false;
|
|
1113
|
+
var curHit = LitePhysicsScene._currentHit;
|
|
1114
|
+
for(var i = 0, len = colliders.length; i < len; i++){
|
|
1115
|
+
var collider = colliders[i];
|
|
1116
|
+
if (collider._raycast(ray, onRaycast, curHit)) {
|
|
1117
|
+
isHit = true;
|
|
1118
|
+
if (curHit.distance < distance) {
|
|
1119
|
+
if (hitResult) {
|
|
1120
|
+
hitResult.normal.copyFrom(curHit.normal);
|
|
1121
|
+
hitResult.point.copyFrom(curHit.point);
|
|
1122
|
+
hitResult.distance = curHit.distance;
|
|
1123
|
+
hitResult.shapeID = curHit.shapeID;
|
|
1124
|
+
} else {
|
|
1125
|
+
return true;
|
|
1126
|
+
}
|
|
1127
|
+
distance = curHit.distance;
|
|
1128
|
+
}
|
|
1129
|
+
}
|
|
1130
|
+
}
|
|
1131
|
+
return isHit;
|
|
1132
|
+
};
|
|
1118
1133
|
/**
|
|
1119
1134
|
* Calculate the bounding box in world space from boxCollider.
|
|
1120
1135
|
* @param boxCollider - The boxCollider to calculate
|
|
@@ -1171,6 +1186,7 @@ var /**
|
|
|
1171
1186
|
function LiteStaticCollider(position, rotation) {
|
|
1172
1187
|
var _this;
|
|
1173
1188
|
_this = LiteCollider1.call(this) || this;
|
|
1189
|
+
/** @internal */ _this._isStaticCollider = true;
|
|
1174
1190
|
_this._transform.setPosition(position.x, position.y, position.z);
|
|
1175
1191
|
_this._transform.setRotationQuaternion(rotation.x, rotation.y, rotation.z, rotation.w);
|
|
1176
1192
|
return _this;
|
|
@@ -1255,7 +1271,7 @@ var LitePhysics = /*#__PURE__*/ function() {
|
|
|
1255
1271
|
}();
|
|
1256
1272
|
|
|
1257
1273
|
//@ts-ignore
|
|
1258
|
-
var version = "1.
|
|
1274
|
+
var version = "1.3.0-alpha.1";
|
|
1259
1275
|
console.log("Galacean PhysicsLite version: " + version);
|
|
1260
1276
|
|
|
1261
1277
|
exports.LitePhysics = LitePhysics;
|