@galacean/engine-core 1.4.14 → 1.4.16
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/main.js +410 -367
- package/dist/main.js.map +1 -1
- package/dist/module.js +410 -367
- package/dist/module.js.map +1 -1
- package/package.json +3 -3
- package/types/asset/AssetPromise.d.ts +30 -5
package/dist/module.js
CHANGED
|
@@ -2583,7 +2583,7 @@ var Utils = /*#__PURE__*/ function() {
|
|
|
2583
2583
|
return relativeUrl;
|
|
2584
2584
|
}
|
|
2585
2585
|
if (!/^https?:/.test(baseUrl)) {
|
|
2586
|
-
var fileSchema = "
|
|
2586
|
+
var fileSchema = "file://";
|
|
2587
2587
|
baseUrl = fileSchema + baseUrl;
|
|
2588
2588
|
return new URL(relativeUrl, baseUrl).href.substring(fileSchema.length);
|
|
2589
2589
|
}
|
|
@@ -19387,12 +19387,24 @@ var AssetPromise = /*#__PURE__*/ function() {
|
|
|
19387
19387
|
this._onCancelHandler && this._onCancelHandler();
|
|
19388
19388
|
return this;
|
|
19389
19389
|
};
|
|
19390
|
-
|
|
19391
|
-
|
|
19392
|
-
|
|
19393
|
-
|
|
19394
|
-
|
|
19395
|
-
|
|
19390
|
+
AssetPromise.resolve = function resolve(value) {
|
|
19391
|
+
if (value === undefined) {
|
|
19392
|
+
return new AssetPromise(function(resolve) {
|
|
19393
|
+
return resolve();
|
|
19394
|
+
});
|
|
19395
|
+
} else if (_instanceof(value, AssetPromise) || _instanceof(value, Promise)) {
|
|
19396
|
+
return new AssetPromise(function(resolve, reject) {
|
|
19397
|
+
value.then(function(resolved) {
|
|
19398
|
+
return resolve(resolved);
|
|
19399
|
+
}, reject);
|
|
19400
|
+
});
|
|
19401
|
+
} else {
|
|
19402
|
+
return new AssetPromise(function(resolve) {
|
|
19403
|
+
return resolve(value);
|
|
19404
|
+
});
|
|
19405
|
+
}
|
|
19406
|
+
};
|
|
19407
|
+
AssetPromise.all = function all(values) {
|
|
19396
19408
|
return new AssetPromise(function(resolve, reject, setTaskCompleteProgress) {
|
|
19397
19409
|
var onComplete = function onComplete(index, resultValue) {
|
|
19398
19410
|
completed++;
|
|
@@ -19403,7 +19415,7 @@ var AssetPromise = /*#__PURE__*/ function() {
|
|
|
19403
19415
|
}
|
|
19404
19416
|
};
|
|
19405
19417
|
var onProgress = function onProgress(promise, index) {
|
|
19406
|
-
if (_instanceof(promise,
|
|
19418
|
+
if (_instanceof(promise, AssetPromise) || _instanceof(promise, Promise)) {
|
|
19407
19419
|
promise.then(function(value) {
|
|
19408
19420
|
onComplete(index, value);
|
|
19409
19421
|
}, reject);
|
|
@@ -19413,14 +19425,14 @@ var AssetPromise = /*#__PURE__*/ function() {
|
|
|
19413
19425
|
});
|
|
19414
19426
|
}
|
|
19415
19427
|
};
|
|
19416
|
-
var count =
|
|
19428
|
+
var count = Array.from(values).length;
|
|
19417
19429
|
var results = new Array(count);
|
|
19418
19430
|
var completed = 0;
|
|
19419
19431
|
if (count === 0) {
|
|
19420
19432
|
return resolve(results);
|
|
19421
19433
|
}
|
|
19422
19434
|
for(var i = 0; i < count; i++){
|
|
19423
|
-
onProgress(
|
|
19435
|
+
onProgress(values[i], i);
|
|
19424
19436
|
}
|
|
19425
19437
|
});
|
|
19426
19438
|
};
|
|
@@ -20003,12 +20015,12 @@ var MultiExecutor = /*#__PURE__*/ function() {
|
|
|
20003
20015
|
var obj = this._objectPool[refId];
|
|
20004
20016
|
var promise;
|
|
20005
20017
|
if (obj) {
|
|
20006
|
-
promise =
|
|
20018
|
+
promise = AssetPromise.resolve(obj);
|
|
20007
20019
|
} else {
|
|
20008
20020
|
var resourceConfig = this._idResourceMap[refId];
|
|
20009
20021
|
if (!resourceConfig) {
|
|
20010
20022
|
Logger.warn("refId:" + refId + " is not find in this._idResourceMap.");
|
|
20011
|
-
return
|
|
20023
|
+
return AssetPromise.resolve(null);
|
|
20012
20024
|
}
|
|
20013
20025
|
var url = resourceConfig.virtualPath;
|
|
20014
20026
|
if (key) {
|
|
@@ -20819,347 +20831,6 @@ Collider = __decorate([
|
|
|
20819
20831
|
dependentComponents(Transform, DependentMode.CheckOnly)
|
|
20820
20832
|
], Collider);
|
|
20821
20833
|
|
|
20822
|
-
/**
|
|
20823
|
-
* Describes a contact point where the collision occurs.
|
|
20824
|
-
*/ var ContactPoint = function ContactPoint() {
|
|
20825
|
-
/** The position of the contact point between the shapes, in world space. */ this.position = new Vector3();
|
|
20826
|
-
/** The normal of the contacting surfaces at the contact point. The normal direction points from the other shape to the self shape. */ this.normal = new Vector3();
|
|
20827
|
-
/** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */ this.impulse = new Vector3();
|
|
20828
|
-
};
|
|
20829
|
-
|
|
20830
|
-
/**
|
|
20831
|
-
* Collision information between two shapes when they collide.
|
|
20832
|
-
*/ var Collision = /*#__PURE__*/ function() {
|
|
20833
|
-
function Collision() {}
|
|
20834
|
-
var _proto = Collision.prototype;
|
|
20835
|
-
/**
|
|
20836
|
-
* Get contact points.
|
|
20837
|
-
* @param outContacts - The result of contact points
|
|
20838
|
-
* @returns The actual count of contact points
|
|
20839
|
-
*
|
|
20840
|
-
* @remarks To optimize performance, the engine does not modify the length of the array you pass.
|
|
20841
|
-
* You need to obtain the actual number of contact points from the function's return value.
|
|
20842
|
-
*/ _proto.getContacts = function getContacts(outContacts) {
|
|
20843
|
-
var nativeCollision = this._nativeCollision;
|
|
20844
|
-
var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
|
|
20845
|
-
var factor = this.shape.id === smallerShapeId ? 1 : -1;
|
|
20846
|
-
var nativeContactPoints = nativeCollision.getContacts();
|
|
20847
|
-
var length = nativeContactPoints.size();
|
|
20848
|
-
for(var i = 0; i < length; i++){
|
|
20849
|
-
var _outContacts, _i;
|
|
20850
|
-
var nativeContractPoint = nativeContactPoints.get(i);
|
|
20851
|
-
var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
|
|
20852
|
-
contact.position.copyFrom(nativeContractPoint.position);
|
|
20853
|
-
contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
|
|
20854
|
-
contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
|
|
20855
|
-
contact.separation = nativeContractPoint.separation;
|
|
20856
|
-
}
|
|
20857
|
-
return length;
|
|
20858
|
-
};
|
|
20859
|
-
_create_class(Collision, [
|
|
20860
|
-
{
|
|
20861
|
-
key: "contactCount",
|
|
20862
|
-
get: /**
|
|
20863
|
-
* Count of contact points.
|
|
20864
|
-
*/ function get() {
|
|
20865
|
-
return this._nativeCollision.contactCount;
|
|
20866
|
-
}
|
|
20867
|
-
}
|
|
20868
|
-
]);
|
|
20869
|
-
return Collision;
|
|
20870
|
-
}();
|
|
20871
|
-
|
|
20872
|
-
/**
|
|
20873
|
-
* A physics scene is a collection of colliders and constraints which can interact.
|
|
20874
|
-
*/ var PhysicsScene = /*#__PURE__*/ function() {
|
|
20875
|
-
function PhysicsScene(scene) {
|
|
20876
|
-
this._restTime = 0;
|
|
20877
|
-
this._fixedTimeStep = 1 / 60;
|
|
20878
|
-
this._colliders = new DisorderedArray();
|
|
20879
|
-
this._gravity = new Vector3(0, -9.81, 0);
|
|
20880
|
-
this._onContactEnter = function(nativeCollision) {
|
|
20881
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20882
|
-
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
20883
|
-
var shape1 = physicalObjectsMap[shape0Id];
|
|
20884
|
-
var shape2 = physicalObjectsMap[shape1Id];
|
|
20885
|
-
var collision = PhysicsScene._collision;
|
|
20886
|
-
collision._nativeCollision = nativeCollision;
|
|
20887
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20888
|
-
collision.shape = shape2;
|
|
20889
|
-
element.onCollisionEnter(collision);
|
|
20890
|
-
}, function(element, index) {
|
|
20891
|
-
element._entityScriptsIndex = index;
|
|
20892
|
-
});
|
|
20893
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20894
|
-
collision.shape = shape1;
|
|
20895
|
-
element.onCollisionEnter(collision);
|
|
20896
|
-
}, function(element, index) {
|
|
20897
|
-
element._entityScriptsIndex = index;
|
|
20898
|
-
});
|
|
20899
|
-
};
|
|
20900
|
-
this._onContactExit = function(nativeCollision) {
|
|
20901
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20902
|
-
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
20903
|
-
var shape1 = physicalObjectsMap[shape0Id];
|
|
20904
|
-
var shape2 = physicalObjectsMap[shape1Id];
|
|
20905
|
-
var collision = PhysicsScene._collision;
|
|
20906
|
-
collision._nativeCollision = nativeCollision;
|
|
20907
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20908
|
-
collision.shape = shape2;
|
|
20909
|
-
element.onCollisionExit(collision);
|
|
20910
|
-
}, function(element, index) {
|
|
20911
|
-
element._entityScriptsIndex = index;
|
|
20912
|
-
});
|
|
20913
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20914
|
-
collision.shape = shape1;
|
|
20915
|
-
element.onCollisionExit(collision);
|
|
20916
|
-
}, function(element, index) {
|
|
20917
|
-
element._entityScriptsIndex = index;
|
|
20918
|
-
});
|
|
20919
|
-
};
|
|
20920
|
-
this._onContactStay = function(nativeCollision) {
|
|
20921
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20922
|
-
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
20923
|
-
var shape1 = physicalObjectsMap[shape0Id];
|
|
20924
|
-
var shape2 = physicalObjectsMap[shape1Id];
|
|
20925
|
-
var collision = PhysicsScene._collision;
|
|
20926
|
-
collision._nativeCollision = nativeCollision;
|
|
20927
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20928
|
-
collision.shape = shape2;
|
|
20929
|
-
element.onCollisionStay(collision);
|
|
20930
|
-
}, function(element, index) {
|
|
20931
|
-
element._entityScriptsIndex = index;
|
|
20932
|
-
});
|
|
20933
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20934
|
-
collision.shape = shape1;
|
|
20935
|
-
element.onCollisionStay(collision);
|
|
20936
|
-
}, function(element, index) {
|
|
20937
|
-
element._entityScriptsIndex = index;
|
|
20938
|
-
});
|
|
20939
|
-
};
|
|
20940
|
-
this._onTriggerEnter = function(obj1, obj2) {
|
|
20941
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20942
|
-
var shape1 = physicalObjectsMap[obj1];
|
|
20943
|
-
var shape2 = physicalObjectsMap[obj2];
|
|
20944
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20945
|
-
element.onTriggerEnter(shape2);
|
|
20946
|
-
}, function(element, index) {
|
|
20947
|
-
element._entityScriptsIndex = index;
|
|
20948
|
-
});
|
|
20949
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20950
|
-
element.onTriggerEnter(shape1);
|
|
20951
|
-
}, function(element, index) {
|
|
20952
|
-
element._entityScriptsIndex = index;
|
|
20953
|
-
});
|
|
20954
|
-
};
|
|
20955
|
-
this._onTriggerExit = function(obj1, obj2) {
|
|
20956
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20957
|
-
var shape1 = physicalObjectsMap[obj1];
|
|
20958
|
-
var shape2 = physicalObjectsMap[obj2];
|
|
20959
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20960
|
-
element.onTriggerExit(shape2);
|
|
20961
|
-
}, function(element, index) {
|
|
20962
|
-
element._entityScriptsIndex = index;
|
|
20963
|
-
});
|
|
20964
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20965
|
-
element.onTriggerExit(shape1);
|
|
20966
|
-
}, function(element, index) {
|
|
20967
|
-
element._entityScriptsIndex = index;
|
|
20968
|
-
});
|
|
20969
|
-
};
|
|
20970
|
-
this._onTriggerStay = function(obj1, obj2) {
|
|
20971
|
-
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
20972
|
-
var shape1 = physicalObjectsMap[obj1];
|
|
20973
|
-
var shape2 = physicalObjectsMap[obj2];
|
|
20974
|
-
shape1.collider.entity._scripts.forEach(function(element) {
|
|
20975
|
-
element.onTriggerStay(shape2);
|
|
20976
|
-
}, function(element, index) {
|
|
20977
|
-
element._entityScriptsIndex = index;
|
|
20978
|
-
});
|
|
20979
|
-
shape2.collider.entity._scripts.forEach(function(element) {
|
|
20980
|
-
element.onTriggerStay(shape1);
|
|
20981
|
-
}, function(element, index) {
|
|
20982
|
-
element._entityScriptsIndex = index;
|
|
20983
|
-
});
|
|
20984
|
-
};
|
|
20985
|
-
this._scene = scene;
|
|
20986
|
-
this._setGravity = this._setGravity.bind(this);
|
|
20987
|
-
//@ts-ignore
|
|
20988
|
-
this._gravity._onValueChanged = this._setGravity;
|
|
20989
|
-
var engine = scene.engine;
|
|
20990
|
-
if (engine._physicsInitialized) {
|
|
20991
|
-
this._nativePhysicsScene = PhysicsScene._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
|
|
20992
|
-
}
|
|
20993
|
-
}
|
|
20994
|
-
var _proto = PhysicsScene.prototype;
|
|
20995
|
-
_proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
|
|
20996
|
-
var hitResult;
|
|
20997
|
-
var distance = Number.MAX_VALUE;
|
|
20998
|
-
if (typeof distanceOrResult === "number") {
|
|
20999
|
-
distance = distanceOrResult;
|
|
21000
|
-
} else if (distanceOrResult != undefined) {
|
|
21001
|
-
hitResult = distanceOrResult;
|
|
21002
|
-
}
|
|
21003
|
-
var layerMask = Layer.Everything;
|
|
21004
|
-
if (typeof layerMaskOrResult === "number") {
|
|
21005
|
-
layerMask = layerMaskOrResult;
|
|
21006
|
-
} else if (layerMaskOrResult != undefined) {
|
|
21007
|
-
hitResult = layerMaskOrResult;
|
|
21008
|
-
}
|
|
21009
|
-
if (outHitResult) {
|
|
21010
|
-
hitResult = outHitResult;
|
|
21011
|
-
}
|
|
21012
|
-
var onRaycast = function(obj) {
|
|
21013
|
-
var shape = Engine._physicalObjectsMap[obj];
|
|
21014
|
-
if (!shape) {
|
|
21015
|
-
return false;
|
|
21016
|
-
}
|
|
21017
|
-
return shape.collider.entity.layer & layerMask && shape.isSceneQuery;
|
|
21018
|
-
};
|
|
21019
|
-
var outIDX;
|
|
21020
|
-
var outDistance;
|
|
21021
|
-
var outPosition;
|
|
21022
|
-
var outNormal;
|
|
21023
|
-
if (hitResult != undefined) {
|
|
21024
|
-
var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
|
|
21025
|
-
outIDX = idx;
|
|
21026
|
-
outDistance = distance;
|
|
21027
|
-
outPosition = position;
|
|
21028
|
-
outNormal = normal;
|
|
21029
|
-
});
|
|
21030
|
-
if (result) {
|
|
21031
|
-
var hitShape = Engine._physicalObjectsMap[outIDX];
|
|
21032
|
-
hitResult.entity = hitShape._collider.entity;
|
|
21033
|
-
hitResult.shape = hitShape;
|
|
21034
|
-
hitResult.distance = outDistance;
|
|
21035
|
-
hitResult.point.copyFrom(outPosition);
|
|
21036
|
-
hitResult.normal.copyFrom(outNormal);
|
|
21037
|
-
return true;
|
|
21038
|
-
} else {
|
|
21039
|
-
hitResult.entity = null;
|
|
21040
|
-
hitResult.shape = null;
|
|
21041
|
-
hitResult.distance = 0;
|
|
21042
|
-
hitResult.point.set(0, 0, 0);
|
|
21043
|
-
hitResult.normal.set(0, 0, 0);
|
|
21044
|
-
return false;
|
|
21045
|
-
}
|
|
21046
|
-
} else {
|
|
21047
|
-
return this._nativePhysicsScene.raycast(ray, distance, onRaycast);
|
|
21048
|
-
}
|
|
21049
|
-
};
|
|
21050
|
-
/**
|
|
21051
|
-
* Call on every frame to update pose of objects.
|
|
21052
|
-
* @internal
|
|
21053
|
-
*/ _proto._update = function _update(deltaTime) {
|
|
21054
|
-
var _this = this, fixedTimeStep = _this._fixedTimeStep, nativePhysicsManager = _this._nativePhysicsScene;
|
|
21055
|
-
var componentsManager = this._scene._componentsManager;
|
|
21056
|
-
var simulateTime = this._restTime + deltaTime;
|
|
21057
|
-
var step = Math.floor(simulateTime / fixedTimeStep);
|
|
21058
|
-
this._restTime = simulateTime - step * fixedTimeStep;
|
|
21059
|
-
for(var i = 0; i < step; i++){
|
|
21060
|
-
componentsManager.callScriptOnPhysicsUpdate();
|
|
21061
|
-
this._callColliderOnUpdate();
|
|
21062
|
-
nativePhysicsManager.update(fixedTimeStep);
|
|
21063
|
-
this._callColliderOnLateUpdate();
|
|
21064
|
-
}
|
|
21065
|
-
};
|
|
21066
|
-
/**
|
|
21067
|
-
* Add collider into the manager.
|
|
21068
|
-
* @param collider - StaticCollider or DynamicCollider.
|
|
21069
|
-
* @internal
|
|
21070
|
-
*/ _proto._addCollider = function _addCollider(collider) {
|
|
21071
|
-
if (collider._index === -1) {
|
|
21072
|
-
collider._index = this._colliders.length;
|
|
21073
|
-
this._colliders.add(collider);
|
|
21074
|
-
}
|
|
21075
|
-
this._nativePhysicsScene.addCollider(collider._nativeCollider);
|
|
21076
|
-
};
|
|
21077
|
-
/**
|
|
21078
|
-
* Add character controller into the manager.
|
|
21079
|
-
* @param controller - Character Controller.
|
|
21080
|
-
* @internal
|
|
21081
|
-
*/ _proto._addCharacterController = function _addCharacterController(controller) {
|
|
21082
|
-
if (controller._index === -1) {
|
|
21083
|
-
controller._index = this._colliders.length;
|
|
21084
|
-
this._colliders.add(controller);
|
|
21085
|
-
}
|
|
21086
|
-
this._nativePhysicsScene.addCharacterController(controller._nativeCollider);
|
|
21087
|
-
};
|
|
21088
|
-
/**
|
|
21089
|
-
* Remove collider.
|
|
21090
|
-
* @param collider - StaticCollider or DynamicCollider.
|
|
21091
|
-
* @internal
|
|
21092
|
-
*/ _proto._removeCollider = function _removeCollider(collider) {
|
|
21093
|
-
var replaced = this._colliders.deleteByIndex(collider._index);
|
|
21094
|
-
replaced && (replaced._index = collider._index);
|
|
21095
|
-
collider._index = -1;
|
|
21096
|
-
this._nativePhysicsScene.removeCollider(collider._nativeCollider);
|
|
21097
|
-
};
|
|
21098
|
-
/**
|
|
21099
|
-
* Remove collider.
|
|
21100
|
-
* @param controller - Character Controller.
|
|
21101
|
-
* @internal
|
|
21102
|
-
*/ _proto._removeCharacterController = function _removeCharacterController(controller) {
|
|
21103
|
-
var replaced = this._colliders.deleteByIndex(controller._index);
|
|
21104
|
-
replaced && (replaced._index = controller._index);
|
|
21105
|
-
controller._index = -1;
|
|
21106
|
-
this._nativePhysicsScene.removeCharacterController(controller._nativeCollider);
|
|
21107
|
-
};
|
|
21108
|
-
/**
|
|
21109
|
-
* @internal
|
|
21110
|
-
*/ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
|
|
21111
|
-
var elements = this._colliders._elements;
|
|
21112
|
-
for(var i = this._colliders.length - 1; i >= 0; --i){
|
|
21113
|
-
elements[i]._onUpdate();
|
|
21114
|
-
}
|
|
21115
|
-
};
|
|
21116
|
-
/**
|
|
21117
|
-
* @internal
|
|
21118
|
-
*/ _proto._callColliderOnLateUpdate = function _callColliderOnLateUpdate() {
|
|
21119
|
-
var elements = this._colliders._elements;
|
|
21120
|
-
for(var i = this._colliders.length - 1; i >= 0; --i){
|
|
21121
|
-
elements[i]._onLateUpdate();
|
|
21122
|
-
}
|
|
21123
|
-
};
|
|
21124
|
-
/**
|
|
21125
|
-
* @internal
|
|
21126
|
-
*/ _proto._gc = function _gc() {
|
|
21127
|
-
this._colliders.garbageCollection();
|
|
21128
|
-
};
|
|
21129
|
-
_proto._setGravity = function _setGravity() {
|
|
21130
|
-
this._nativePhysicsScene.setGravity(this._gravity);
|
|
21131
|
-
};
|
|
21132
|
-
_create_class(PhysicsScene, [
|
|
21133
|
-
{
|
|
21134
|
-
key: "gravity",
|
|
21135
|
-
get: /**
|
|
21136
|
-
* The gravity of physics scene.
|
|
21137
|
-
*/ function get() {
|
|
21138
|
-
return this._gravity;
|
|
21139
|
-
},
|
|
21140
|
-
set: function set(value) {
|
|
21141
|
-
var gravity = this._gravity;
|
|
21142
|
-
if (gravity !== value) {
|
|
21143
|
-
gravity.copyFrom(value);
|
|
21144
|
-
}
|
|
21145
|
-
}
|
|
21146
|
-
},
|
|
21147
|
-
{
|
|
21148
|
-
key: "fixedTimeStep",
|
|
21149
|
-
get: /**
|
|
21150
|
-
* The fixed time step in seconds at which physics are performed.
|
|
21151
|
-
*/ function get() {
|
|
21152
|
-
return this._fixedTimeStep;
|
|
21153
|
-
},
|
|
21154
|
-
set: function set(value) {
|
|
21155
|
-
this._fixedTimeStep = Math.max(value, MathUtil.zeroTolerance);
|
|
21156
|
-
}
|
|
21157
|
-
}
|
|
21158
|
-
]);
|
|
21159
|
-
return PhysicsScene;
|
|
21160
|
-
}();
|
|
21161
|
-
PhysicsScene._collision = new Collision();
|
|
21162
|
-
|
|
21163
20834
|
/**
|
|
21164
20835
|
* The up axis of the collider shape.
|
|
21165
20836
|
*/ var ControllerNonWalkableMode = /*#__PURE__*/ function(ControllerNonWalkableMode) {
|
|
@@ -21175,7 +20846,7 @@ PhysicsScene._collision = new Collision();
|
|
|
21175
20846
|
function CharacterController(entity) {
|
|
21176
20847
|
var _this;
|
|
21177
20848
|
_this = Collider.call(this, entity) || this, _this._stepOffset = 0.5, _this._nonWalkableMode = ControllerNonWalkableMode.PreventClimbing, _this._upDirection = new Vector3(0, 1, 0), _this._slopeLimit = 45;
|
|
21178
|
-
_this._nativeCollider =
|
|
20849
|
+
_this._nativeCollider = Engine._nativePhysics.createCharacterController();
|
|
21179
20850
|
_this._setUpDirection = _this._setUpDirection.bind(_this);
|
|
21180
20851
|
//@ts-ignore
|
|
21181
20852
|
_this._upDirection._onValueChanged = _this._setUpDirection;
|
|
@@ -21325,7 +20996,7 @@ __decorate([
|
|
|
21325
20996
|
var _this;
|
|
21326
20997
|
_this = Collider.call(this, entity) || this, _this._linearDamping = 0, _this._angularDamping = 0.05, _this._linearVelocity = new Vector3(), _this._angularVelocity = new Vector3(), _this._mass = 1.0, _this._centerOfMass = new Vector3(), _this._inertiaTensor = new Vector3(1, 1, 1), _this._maxAngularVelocity = 18000 / Math.PI, _this._maxDepenetrationVelocity = 1.0000000331813535e32, _this._solverIterations = 4, _this._useGravity = true, _this._isKinematic = false, _this._constraints = 0, _this._collisionDetectionMode = 0, _this._sleepThreshold = 5e-3, _this._automaticCenterOfMass = true, _this._automaticInertiaTensor = true;
|
|
21327
20998
|
var transform = _this.entity.transform;
|
|
21328
|
-
_this._nativeCollider =
|
|
20999
|
+
_this._nativeCollider = Engine._nativePhysics.createDynamicCollider(transform.worldPosition, transform.worldRotationQuaternion);
|
|
21329
21000
|
_this._setLinearVelocity = _this._setLinearVelocity.bind(_this);
|
|
21330
21001
|
_this._setAngularVelocity = _this._setAngularVelocity.bind(_this);
|
|
21331
21002
|
_this._handleCenterOfMassChanged = _this._handleCenterOfMassChanged.bind(_this);
|
|
@@ -21799,7 +21470,7 @@ __decorate([
|
|
|
21799
21470
|
this._staticFriction = 0.6;
|
|
21800
21471
|
this._bounceCombine = PhysicsMaterialCombineMode.Average;
|
|
21801
21472
|
this._frictionCombine = PhysicsMaterialCombineMode.Average;
|
|
21802
|
-
this._nativeMaterial =
|
|
21473
|
+
this._nativeMaterial = Engine._nativePhysics.createPhysicsMaterial(this._staticFriction, this._dynamicFriction, this._bounciness, this._bounceCombine, this._frictionCombine);
|
|
21803
21474
|
}
|
|
21804
21475
|
var _proto = PhysicsMaterial.prototype;
|
|
21805
21476
|
/**
|
|
@@ -21883,6 +21554,353 @@ __decorate([
|
|
|
21883
21554
|
return PhysicsMaterial;
|
|
21884
21555
|
}();
|
|
21885
21556
|
|
|
21557
|
+
/**
|
|
21558
|
+
* Describes a contact point where the collision occurs.
|
|
21559
|
+
*/ var ContactPoint = function ContactPoint() {
|
|
21560
|
+
/** The position of the contact point between the shapes, in world space. */ this.position = new Vector3();
|
|
21561
|
+
/** The normal of the contacting surfaces at the contact point. The normal direction points from the other shape to the self shape. */ this.normal = new Vector3();
|
|
21562
|
+
/** The impulse applied at the contact point, in world space. Divide by the simulation time step to get a force value. */ this.impulse = new Vector3();
|
|
21563
|
+
};
|
|
21564
|
+
|
|
21565
|
+
/**
|
|
21566
|
+
* Collision information between two shapes when they collide.
|
|
21567
|
+
*/ var Collision = /*#__PURE__*/ function() {
|
|
21568
|
+
function Collision() {}
|
|
21569
|
+
var _proto = Collision.prototype;
|
|
21570
|
+
/**
|
|
21571
|
+
* Get contact points.
|
|
21572
|
+
* @param outContacts - The result of contact points
|
|
21573
|
+
* @returns The actual count of contact points
|
|
21574
|
+
*
|
|
21575
|
+
* @remarks To optimize performance, the engine does not modify the length of the array you pass.
|
|
21576
|
+
* You need to obtain the actual number of contact points from the function's return value.
|
|
21577
|
+
*/ _proto.getContacts = function getContacts(outContacts) {
|
|
21578
|
+
var nativeCollision = this._nativeCollision;
|
|
21579
|
+
var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
|
|
21580
|
+
var factor = this.shape.id === smallerShapeId ? 1 : -1;
|
|
21581
|
+
var nativeContactPoints = nativeCollision.getContacts();
|
|
21582
|
+
var length = nativeContactPoints.size();
|
|
21583
|
+
for(var i = 0; i < length; i++){
|
|
21584
|
+
var _outContacts, _i;
|
|
21585
|
+
var nativeContractPoint = nativeContactPoints.get(i);
|
|
21586
|
+
var contact = (_outContacts = outContacts)[_i = i] || (_outContacts[_i] = new ContactPoint());
|
|
21587
|
+
contact.position.copyFrom(nativeContractPoint.position);
|
|
21588
|
+
contact.normal.copyFrom(nativeContractPoint.normal).scale(factor);
|
|
21589
|
+
contact.impulse.copyFrom(nativeContractPoint.impulse).scale(factor);
|
|
21590
|
+
contact.separation = nativeContractPoint.separation;
|
|
21591
|
+
}
|
|
21592
|
+
return length;
|
|
21593
|
+
};
|
|
21594
|
+
_create_class(Collision, [
|
|
21595
|
+
{
|
|
21596
|
+
key: "contactCount",
|
|
21597
|
+
get: /**
|
|
21598
|
+
* Count of contact points.
|
|
21599
|
+
*/ function get() {
|
|
21600
|
+
return this._nativeCollision.contactCount;
|
|
21601
|
+
}
|
|
21602
|
+
}
|
|
21603
|
+
]);
|
|
21604
|
+
return Collision;
|
|
21605
|
+
}();
|
|
21606
|
+
|
|
21607
|
+
/**
|
|
21608
|
+
* A physics scene is a collection of colliders and constraints which can interact.
|
|
21609
|
+
*/ var PhysicsScene = /*#__PURE__*/ function() {
|
|
21610
|
+
function PhysicsScene(scene) {
|
|
21611
|
+
this._restTime = 0;
|
|
21612
|
+
this._fixedTimeStep = 1 / 60;
|
|
21613
|
+
this._colliders = new DisorderedArray();
|
|
21614
|
+
this._gravity = new Vector3(0, -9.81, 0);
|
|
21615
|
+
this._onContactEnter = function(nativeCollision) {
|
|
21616
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21617
|
+
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
21618
|
+
var shape1 = physicalObjectsMap[shape0Id];
|
|
21619
|
+
var shape2 = physicalObjectsMap[shape1Id];
|
|
21620
|
+
var collision = PhysicsScene._collision;
|
|
21621
|
+
collision._nativeCollision = nativeCollision;
|
|
21622
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21623
|
+
collision.shape = shape2;
|
|
21624
|
+
element.onCollisionEnter(collision);
|
|
21625
|
+
}, function(element, index) {
|
|
21626
|
+
element._entityScriptsIndex = index;
|
|
21627
|
+
});
|
|
21628
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21629
|
+
collision.shape = shape1;
|
|
21630
|
+
element.onCollisionEnter(collision);
|
|
21631
|
+
}, function(element, index) {
|
|
21632
|
+
element._entityScriptsIndex = index;
|
|
21633
|
+
});
|
|
21634
|
+
};
|
|
21635
|
+
this._onContactExit = function(nativeCollision) {
|
|
21636
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21637
|
+
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
21638
|
+
var shape1 = physicalObjectsMap[shape0Id];
|
|
21639
|
+
var shape2 = physicalObjectsMap[shape1Id];
|
|
21640
|
+
var collision = PhysicsScene._collision;
|
|
21641
|
+
collision._nativeCollision = nativeCollision;
|
|
21642
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21643
|
+
collision.shape = shape2;
|
|
21644
|
+
element.onCollisionExit(collision);
|
|
21645
|
+
}, function(element, index) {
|
|
21646
|
+
element._entityScriptsIndex = index;
|
|
21647
|
+
});
|
|
21648
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21649
|
+
collision.shape = shape1;
|
|
21650
|
+
element.onCollisionExit(collision);
|
|
21651
|
+
}, function(element, index) {
|
|
21652
|
+
element._entityScriptsIndex = index;
|
|
21653
|
+
});
|
|
21654
|
+
};
|
|
21655
|
+
this._onContactStay = function(nativeCollision) {
|
|
21656
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21657
|
+
var shape0Id = nativeCollision.shape0Id, shape1Id = nativeCollision.shape1Id;
|
|
21658
|
+
var shape1 = physicalObjectsMap[shape0Id];
|
|
21659
|
+
var shape2 = physicalObjectsMap[shape1Id];
|
|
21660
|
+
var collision = PhysicsScene._collision;
|
|
21661
|
+
collision._nativeCollision = nativeCollision;
|
|
21662
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21663
|
+
collision.shape = shape2;
|
|
21664
|
+
element.onCollisionStay(collision);
|
|
21665
|
+
}, function(element, index) {
|
|
21666
|
+
element._entityScriptsIndex = index;
|
|
21667
|
+
});
|
|
21668
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21669
|
+
collision.shape = shape1;
|
|
21670
|
+
element.onCollisionStay(collision);
|
|
21671
|
+
}, function(element, index) {
|
|
21672
|
+
element._entityScriptsIndex = index;
|
|
21673
|
+
});
|
|
21674
|
+
};
|
|
21675
|
+
this._onTriggerEnter = function(obj1, obj2) {
|
|
21676
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21677
|
+
var shape1 = physicalObjectsMap[obj1];
|
|
21678
|
+
var shape2 = physicalObjectsMap[obj2];
|
|
21679
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21680
|
+
element.onTriggerEnter(shape2);
|
|
21681
|
+
}, function(element, index) {
|
|
21682
|
+
element._entityScriptsIndex = index;
|
|
21683
|
+
});
|
|
21684
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21685
|
+
element.onTriggerEnter(shape1);
|
|
21686
|
+
}, function(element, index) {
|
|
21687
|
+
element._entityScriptsIndex = index;
|
|
21688
|
+
});
|
|
21689
|
+
};
|
|
21690
|
+
this._onTriggerExit = function(obj1, obj2) {
|
|
21691
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21692
|
+
var shape1 = physicalObjectsMap[obj1];
|
|
21693
|
+
var shape2 = physicalObjectsMap[obj2];
|
|
21694
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21695
|
+
element.onTriggerExit(shape2);
|
|
21696
|
+
}, function(element, index) {
|
|
21697
|
+
element._entityScriptsIndex = index;
|
|
21698
|
+
});
|
|
21699
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21700
|
+
element.onTriggerExit(shape1);
|
|
21701
|
+
}, function(element, index) {
|
|
21702
|
+
element._entityScriptsIndex = index;
|
|
21703
|
+
});
|
|
21704
|
+
};
|
|
21705
|
+
this._onTriggerStay = function(obj1, obj2) {
|
|
21706
|
+
var physicalObjectsMap = Engine._physicalObjectsMap;
|
|
21707
|
+
var shape1 = physicalObjectsMap[obj1];
|
|
21708
|
+
var shape2 = physicalObjectsMap[obj2];
|
|
21709
|
+
shape1.collider.entity._scripts.forEach(function(element) {
|
|
21710
|
+
element.onTriggerStay(shape2);
|
|
21711
|
+
}, function(element, index) {
|
|
21712
|
+
element._entityScriptsIndex = index;
|
|
21713
|
+
});
|
|
21714
|
+
shape2.collider.entity._scripts.forEach(function(element) {
|
|
21715
|
+
element.onTriggerStay(shape1);
|
|
21716
|
+
}, function(element, index) {
|
|
21717
|
+
element._entityScriptsIndex = index;
|
|
21718
|
+
});
|
|
21719
|
+
};
|
|
21720
|
+
this._scene = scene;
|
|
21721
|
+
this._setGravity = this._setGravity.bind(this);
|
|
21722
|
+
//@ts-ignore
|
|
21723
|
+
this._gravity._onValueChanged = this._setGravity;
|
|
21724
|
+
var engine = scene.engine;
|
|
21725
|
+
if (engine._physicsInitialized) {
|
|
21726
|
+
this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager, this._onContactEnter, this._onContactExit, this._onContactStay, this._onTriggerEnter, this._onTriggerExit, this._onTriggerStay);
|
|
21727
|
+
}
|
|
21728
|
+
}
|
|
21729
|
+
var _proto = PhysicsScene.prototype;
|
|
21730
|
+
_proto.raycast = function raycast(ray, distanceOrResult, layerMaskOrResult, outHitResult) {
|
|
21731
|
+
var hitResult;
|
|
21732
|
+
var distance = Number.MAX_VALUE;
|
|
21733
|
+
if (typeof distanceOrResult === "number") {
|
|
21734
|
+
distance = distanceOrResult;
|
|
21735
|
+
} else if (distanceOrResult != undefined) {
|
|
21736
|
+
hitResult = distanceOrResult;
|
|
21737
|
+
}
|
|
21738
|
+
var layerMask = Layer.Everything;
|
|
21739
|
+
if (typeof layerMaskOrResult === "number") {
|
|
21740
|
+
layerMask = layerMaskOrResult;
|
|
21741
|
+
} else if (layerMaskOrResult != undefined) {
|
|
21742
|
+
hitResult = layerMaskOrResult;
|
|
21743
|
+
}
|
|
21744
|
+
if (outHitResult) {
|
|
21745
|
+
hitResult = outHitResult;
|
|
21746
|
+
}
|
|
21747
|
+
var onRaycast = function(obj) {
|
|
21748
|
+
var shape = Engine._physicalObjectsMap[obj];
|
|
21749
|
+
if (!shape) {
|
|
21750
|
+
return false;
|
|
21751
|
+
}
|
|
21752
|
+
return shape.collider.entity.layer & layerMask && shape.isSceneQuery;
|
|
21753
|
+
};
|
|
21754
|
+
var outIDX;
|
|
21755
|
+
var outDistance;
|
|
21756
|
+
var outPosition;
|
|
21757
|
+
var outNormal;
|
|
21758
|
+
if (hitResult != undefined) {
|
|
21759
|
+
var result = this._nativePhysicsScene.raycast(ray, distance, onRaycast, function(idx, distance, position, normal) {
|
|
21760
|
+
outIDX = idx;
|
|
21761
|
+
outDistance = distance;
|
|
21762
|
+
outPosition = position;
|
|
21763
|
+
outNormal = normal;
|
|
21764
|
+
});
|
|
21765
|
+
if (result) {
|
|
21766
|
+
var hitShape = Engine._physicalObjectsMap[outIDX];
|
|
21767
|
+
hitResult.entity = hitShape._collider.entity;
|
|
21768
|
+
hitResult.shape = hitShape;
|
|
21769
|
+
hitResult.distance = outDistance;
|
|
21770
|
+
hitResult.point.copyFrom(outPosition);
|
|
21771
|
+
hitResult.normal.copyFrom(outNormal);
|
|
21772
|
+
return true;
|
|
21773
|
+
} else {
|
|
21774
|
+
hitResult.entity = null;
|
|
21775
|
+
hitResult.shape = null;
|
|
21776
|
+
hitResult.distance = 0;
|
|
21777
|
+
hitResult.point.set(0, 0, 0);
|
|
21778
|
+
hitResult.normal.set(0, 0, 0);
|
|
21779
|
+
return false;
|
|
21780
|
+
}
|
|
21781
|
+
} else {
|
|
21782
|
+
return this._nativePhysicsScene.raycast(ray, distance, onRaycast);
|
|
21783
|
+
}
|
|
21784
|
+
};
|
|
21785
|
+
/**
|
|
21786
|
+
* Call on every frame to update pose of objects.
|
|
21787
|
+
* @internal
|
|
21788
|
+
*/ _proto._update = function _update(deltaTime) {
|
|
21789
|
+
var _this = this, fixedTimeStep = _this._fixedTimeStep, nativePhysicsManager = _this._nativePhysicsScene;
|
|
21790
|
+
var componentsManager = this._scene._componentsManager;
|
|
21791
|
+
var simulateTime = this._restTime + deltaTime;
|
|
21792
|
+
var step = Math.floor(simulateTime / fixedTimeStep);
|
|
21793
|
+
this._restTime = simulateTime - step * fixedTimeStep;
|
|
21794
|
+
for(var i = 0; i < step; i++){
|
|
21795
|
+
componentsManager.callScriptOnPhysicsUpdate();
|
|
21796
|
+
this._callColliderOnUpdate();
|
|
21797
|
+
nativePhysicsManager.update(fixedTimeStep);
|
|
21798
|
+
this._callColliderOnLateUpdate();
|
|
21799
|
+
}
|
|
21800
|
+
};
|
|
21801
|
+
/**
|
|
21802
|
+
* Add collider into the manager.
|
|
21803
|
+
* @param collider - StaticCollider or DynamicCollider.
|
|
21804
|
+
* @internal
|
|
21805
|
+
*/ _proto._addCollider = function _addCollider(collider) {
|
|
21806
|
+
if (collider._index === -1) {
|
|
21807
|
+
collider._index = this._colliders.length;
|
|
21808
|
+
this._colliders.add(collider);
|
|
21809
|
+
}
|
|
21810
|
+
this._nativePhysicsScene.addCollider(collider._nativeCollider);
|
|
21811
|
+
};
|
|
21812
|
+
/**
|
|
21813
|
+
* Add character controller into the manager.
|
|
21814
|
+
* @param controller - Character Controller.
|
|
21815
|
+
* @internal
|
|
21816
|
+
*/ _proto._addCharacterController = function _addCharacterController(controller) {
|
|
21817
|
+
if (controller._index === -1) {
|
|
21818
|
+
controller._index = this._colliders.length;
|
|
21819
|
+
this._colliders.add(controller);
|
|
21820
|
+
}
|
|
21821
|
+
this._nativePhysicsScene.addCharacterController(controller._nativeCollider);
|
|
21822
|
+
};
|
|
21823
|
+
/**
|
|
21824
|
+
* Remove collider.
|
|
21825
|
+
* @param collider - StaticCollider or DynamicCollider.
|
|
21826
|
+
* @internal
|
|
21827
|
+
*/ _proto._removeCollider = function _removeCollider(collider) {
|
|
21828
|
+
var replaced = this._colliders.deleteByIndex(collider._index);
|
|
21829
|
+
replaced && (replaced._index = collider._index);
|
|
21830
|
+
collider._index = -1;
|
|
21831
|
+
this._nativePhysicsScene.removeCollider(collider._nativeCollider);
|
|
21832
|
+
};
|
|
21833
|
+
/**
|
|
21834
|
+
* Remove collider.
|
|
21835
|
+
* @param controller - Character Controller.
|
|
21836
|
+
* @internal
|
|
21837
|
+
*/ _proto._removeCharacterController = function _removeCharacterController(controller) {
|
|
21838
|
+
var replaced = this._colliders.deleteByIndex(controller._index);
|
|
21839
|
+
replaced && (replaced._index = controller._index);
|
|
21840
|
+
controller._index = -1;
|
|
21841
|
+
this._nativePhysicsScene.removeCharacterController(controller._nativeCollider);
|
|
21842
|
+
};
|
|
21843
|
+
/**
|
|
21844
|
+
* @internal
|
|
21845
|
+
*/ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
|
|
21846
|
+
var elements = this._colliders._elements;
|
|
21847
|
+
for(var i = this._colliders.length - 1; i >= 0; --i){
|
|
21848
|
+
elements[i]._onUpdate();
|
|
21849
|
+
}
|
|
21850
|
+
};
|
|
21851
|
+
/**
|
|
21852
|
+
* @internal
|
|
21853
|
+
*/ _proto._callColliderOnLateUpdate = function _callColliderOnLateUpdate() {
|
|
21854
|
+
var elements = this._colliders._elements;
|
|
21855
|
+
for(var i = this._colliders.length - 1; i >= 0; --i){
|
|
21856
|
+
elements[i]._onLateUpdate();
|
|
21857
|
+
}
|
|
21858
|
+
};
|
|
21859
|
+
/**
|
|
21860
|
+
* @internal
|
|
21861
|
+
*/ _proto._gc = function _gc() {
|
|
21862
|
+
this._colliders.garbageCollection();
|
|
21863
|
+
};
|
|
21864
|
+
/**
|
|
21865
|
+
* @internal
|
|
21866
|
+
*/ _proto._destroy = function _destroy() {
|
|
21867
|
+
var _this__nativePhysicsScene;
|
|
21868
|
+
(_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.destroy();
|
|
21869
|
+
};
|
|
21870
|
+
_proto._setGravity = function _setGravity() {
|
|
21871
|
+
this._nativePhysicsScene.setGravity(this._gravity);
|
|
21872
|
+
};
|
|
21873
|
+
_create_class(PhysicsScene, [
|
|
21874
|
+
{
|
|
21875
|
+
key: "gravity",
|
|
21876
|
+
get: /**
|
|
21877
|
+
* The gravity of physics scene.
|
|
21878
|
+
*/ function get() {
|
|
21879
|
+
return this._gravity;
|
|
21880
|
+
},
|
|
21881
|
+
set: function set(value) {
|
|
21882
|
+
var gravity = this._gravity;
|
|
21883
|
+
if (gravity !== value) {
|
|
21884
|
+
gravity.copyFrom(value);
|
|
21885
|
+
}
|
|
21886
|
+
}
|
|
21887
|
+
},
|
|
21888
|
+
{
|
|
21889
|
+
key: "fixedTimeStep",
|
|
21890
|
+
get: /**
|
|
21891
|
+
* The fixed time step in seconds at which physics are performed.
|
|
21892
|
+
*/ function get() {
|
|
21893
|
+
return this._fixedTimeStep;
|
|
21894
|
+
},
|
|
21895
|
+
set: function set(value) {
|
|
21896
|
+
this._fixedTimeStep = Math.max(value, MathUtil.zeroTolerance);
|
|
21897
|
+
}
|
|
21898
|
+
}
|
|
21899
|
+
]);
|
|
21900
|
+
return PhysicsScene;
|
|
21901
|
+
}();
|
|
21902
|
+
PhysicsScene._collision = new Collision();
|
|
21903
|
+
|
|
21886
21904
|
/**
|
|
21887
21905
|
* A static collider component that will not move.
|
|
21888
21906
|
* @remarks Mostly used for object which always stays at the same place and never moves around.
|
|
@@ -21892,7 +21910,7 @@ __decorate([
|
|
|
21892
21910
|
var _this;
|
|
21893
21911
|
_this = Collider.call(this, entity) || this;
|
|
21894
21912
|
var transform = _this.entity.transform;
|
|
21895
|
-
_this._nativeCollider =
|
|
21913
|
+
_this._nativeCollider = Engine._nativePhysics.createStaticCollider(transform.worldPosition, transform.worldRotationQuaternion);
|
|
21896
21914
|
return _this;
|
|
21897
21915
|
}
|
|
21898
21916
|
return StaticCollider;
|
|
@@ -22248,7 +22266,7 @@ __decorate([
|
|
|
22248
22266
|
_proto._createJoint = function _createJoint() {
|
|
22249
22267
|
var colliderInfo = this._colliderInfo;
|
|
22250
22268
|
colliderInfo.collider = this.entity.getComponent(Collider);
|
|
22251
|
-
this._nativeJoint =
|
|
22269
|
+
this._nativeJoint = Engine._nativePhysics.createFixedJoint(colliderInfo.collider._nativeCollider);
|
|
22252
22270
|
};
|
|
22253
22271
|
return FixedJoint;
|
|
22254
22272
|
}(Joint);
|
|
@@ -22290,7 +22308,7 @@ __decorate([
|
|
|
22290
22308
|
_proto._createJoint = function _createJoint() {
|
|
22291
22309
|
var colliderInfo = this._colliderInfo;
|
|
22292
22310
|
colliderInfo.collider = this.entity.getComponent(Collider);
|
|
22293
|
-
this._nativeJoint =
|
|
22311
|
+
this._nativeJoint = Engine._nativePhysics.createHingeJoint(colliderInfo.collider._nativeCollider);
|
|
22294
22312
|
};
|
|
22295
22313
|
_proto._syncNative = function _syncNative() {
|
|
22296
22314
|
Joint.prototype._syncNative.call(this);
|
|
@@ -22485,7 +22503,7 @@ __decorate([
|
|
|
22485
22503
|
_proto._createJoint = function _createJoint() {
|
|
22486
22504
|
var colliderInfo = this._colliderInfo;
|
|
22487
22505
|
colliderInfo.collider = this.entity.getComponent(Collider);
|
|
22488
|
-
this._nativeJoint =
|
|
22506
|
+
this._nativeJoint = Engine._nativePhysics.createSpringJoint(colliderInfo.collider._nativeCollider);
|
|
22489
22507
|
};
|
|
22490
22508
|
_proto._syncNative = function _syncNative() {
|
|
22491
22509
|
Joint.prototype._syncNative.call(this);
|
|
@@ -22945,7 +22963,7 @@ __decorate([
|
|
|
22945
22963
|
function BoxColliderShape() {
|
|
22946
22964
|
var _this;
|
|
22947
22965
|
_this = ColliderShape.call(this) || this, _this._size = new Vector3(1, 1, 1);
|
|
22948
|
-
_this._nativeShape =
|
|
22966
|
+
_this._nativeShape = Engine._nativePhysics.createBoxColliderShape(_this._id, _this._size, _this._material._nativeMaterial);
|
|
22949
22967
|
//@ts-ignore
|
|
22950
22968
|
_this._size._onValueChanged = _this._setSize.bind(_this);
|
|
22951
22969
|
return _this;
|
|
@@ -22989,7 +23007,7 @@ __decorate([
|
|
|
22989
23007
|
function SphereColliderShape() {
|
|
22990
23008
|
var _this;
|
|
22991
23009
|
_this = ColliderShape.call(this) || this, _this._radius = 1;
|
|
22992
|
-
_this._nativeShape =
|
|
23010
|
+
_this._nativeShape = Engine._nativePhysics.createSphereColliderShape(_this._id, _this._radius, _this._material._nativeMaterial);
|
|
22993
23011
|
return _this;
|
|
22994
23012
|
}
|
|
22995
23013
|
var _proto = SphereColliderShape.prototype;
|
|
@@ -23023,7 +23041,7 @@ __decorate([
|
|
|
23023
23041
|
function PlaneColliderShape() {
|
|
23024
23042
|
var _this;
|
|
23025
23043
|
_this = ColliderShape.call(this) || this;
|
|
23026
|
-
_this._nativeShape =
|
|
23044
|
+
_this._nativeShape = Engine._nativePhysics.createPlaneColliderShape(_this._id, _this._material._nativeMaterial);
|
|
23027
23045
|
return _this;
|
|
23028
23046
|
}
|
|
23029
23047
|
var _proto = PlaneColliderShape.prototype;
|
|
@@ -23041,7 +23059,7 @@ __decorate([
|
|
|
23041
23059
|
function CapsuleColliderShape() {
|
|
23042
23060
|
var _this;
|
|
23043
23061
|
_this = ColliderShape.call(this) || this, _this._radius = 1, _this._height = 2, _this._upAxis = ColliderShapeUpAxis.Y;
|
|
23044
|
-
_this._nativeShape =
|
|
23062
|
+
_this._nativeShape = Engine._nativePhysics.createCapsuleColliderShape(_this._id, _this._radius, _this._height, _this._material._nativeMaterial);
|
|
23045
23063
|
return _this;
|
|
23046
23064
|
}
|
|
23047
23065
|
var _proto = CapsuleColliderShape.prototype;
|
|
@@ -24122,7 +24140,7 @@ var fragBlurH = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\
|
|
|
24122
24140
|
|
|
24123
24141
|
var fragBlurV = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n vec2 texelSize = renderer_texelSize.xy;\n\n // Optimized bilinear 5-tap gaussian on the same-sized source (9-tap equivalent)\n mediump vec4 c0 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 3.23076923));\n mediump vec4 c1 = sampleTexture(renderer_BlitTexture, v_uv - vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c2 = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 c3 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 1.38461538));\n mediump vec4 c4 = sampleTexture(renderer_BlitTexture, v_uv + vec2(0.0, texelSize.y * 3.23076923));\n\n gl_FragColor = c0 * 0.07027027 + c1 * 0.31621622\n + c2 * 0.22702703\n + c3 * 0.31621622 + c4 * 0.07027027;\n\n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
|
|
24124
24142
|
|
|
24125
|
-
var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\t#ifdef BLOOM_HQ\n vec2 texelSize = renderer_texelSize.xy;\n mediump vec4 A = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, -1.0));\n mediump vec4 C = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, -1.0));\n mediump vec4 D = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, -0.5));\n mediump vec4 F = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 H = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 0.0));\n mediump vec4 I = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, 0.5));\n mediump vec4 K = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, 1.0));\n mediump vec4 M = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 1.0));\n\n mediump vec2 scale = vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 samplerColor = (D + E + I + J) * div.x;\n samplerColor += (A + B + G + F) * div.y;\n samplerColor += (B + C + H + G) * div.y;\n samplerColor += (F + G + L + K) * div.y;\n samplerColor += (G + H + M + L) * div.y;\n #else\n mediump vec4 samplerColor = sampleTexture(renderer_BlitTexture, v_uv);\n #endif\n\n mediump vec3 color = samplerColor.rgb;\n\n // User controlled clamp to limit crazy high broken spec\n color = min(color, HALF_MAX);\n\n // Thresholding\n mediump float brightness = max3(color);\n float threshold = material_BloomParams.x;\n float thresholdKnee = material_BloomParams.y;\n mediump float softness = clamp(brightness - threshold + thresholdKnee, 0.0, 2.0 * thresholdKnee);\n softness = (softness * softness) / (4.0 * thresholdKnee + 1e-4);\n mediump float multiplier = max(brightness - threshold, softness) / max(brightness, 1e-4);\n color *= multiplier;\n\n // Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.\n color = max(color, 0.0);\n\n gl_FragColor = vec4(color,
|
|
24143
|
+
var fragPrefilter = "#define GLSLIFY 1\n#include <PostCommon>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 renderer_texelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n\t#ifdef BLOOM_HQ\n vec2 texelSize = renderer_texelSize.xy;\n mediump vec4 A = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, -1.0));\n mediump vec4 B = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, -1.0));\n mediump vec4 C = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, -1.0));\n mediump vec4 D = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, -0.5));\n mediump vec4 E = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, -0.5));\n mediump vec4 F = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 0.0));\n mediump vec4 G = sampleTexture(renderer_BlitTexture, v_uv);\n mediump vec4 H = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 0.0));\n mediump vec4 I = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-0.5, 0.5));\n mediump vec4 J = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.5, 0.5));\n mediump vec4 K = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(-1.0, 1.0));\n mediump vec4 L = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(0.0, 1.0));\n mediump vec4 M = sampleTexture(renderer_BlitTexture, v_uv + texelSize * vec2(1.0, 1.0));\n\n mediump vec2 scale = vec2(0.5, 0.125);\n mediump vec2 div = (1.0 / 4.0) * scale;\n\n mediump vec4 samplerColor = (D + E + I + J) * div.x;\n samplerColor += (A + B + G + F) * div.y;\n samplerColor += (B + C + H + G) * div.y;\n samplerColor += (F + G + L + K) * div.y;\n samplerColor += (G + H + M + L) * div.y;\n #else\n mediump vec4 samplerColor = sampleTexture(renderer_BlitTexture, v_uv);\n #endif\n\n mediump vec3 color = samplerColor.rgb;\n\n // User controlled clamp to limit crazy high broken spec\n color = min(color, HALF_MAX);\n\n // Thresholding\n mediump float brightness = max3(color);\n float threshold = material_BloomParams.x;\n float thresholdKnee = material_BloomParams.y;\n mediump float softness = clamp(brightness - threshold + thresholdKnee, 0.0, 2.0 * thresholdKnee);\n softness = (softness * softness) / (4.0 * thresholdKnee + 1e-4);\n mediump float multiplier = max(brightness - threshold, softness) / max(brightness, 1e-4);\n color *= multiplier;\n\n // Clamp colors to positive once in prefilter. Encode can have a sqrt, and sqrt(-x) == NaN. Up/Downsample passes would then spread the NaN.\n color = max(color, 0.0);\n\n // Bloom is addtive blend mode, we should set alpha 0 to avoid browser background color dark when canvas alpha and premultiplyAlpha is true\n gl_FragColor = vec4(color, 0.0);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}\n"; // eslint-disable-line
|
|
24126
24144
|
|
|
24127
24145
|
var fragUpsample = "#define GLSLIFY 1\n#include <PostCommon>\n#include <Filtering>\n\nvarying vec2 v_uv;\nuniform sampler2D renderer_BlitTexture;\nuniform sampler2D material_lowMipTexture;\nuniform vec4 material_BloomParams; // x: threshold (linear), y: threshold knee, z: scatter\nuniform vec4 material_lowMipTexelSize; // x: 1/width, y: 1/height, z: width, w: height\n\nvoid main(){\n mediump vec4 highMip = sampleTexture(renderer_BlitTexture, v_uv);\n\n #ifdef BLOOM_HQ\n mediump vec4 lowMip = sampleTexture2DBicubic(material_lowMipTexture, v_uv, material_lowMipTexelSize);\n #else\n mediump vec4 lowMip = sampleTexture(material_lowMipTexture, v_uv);\n #endif\n \n gl_FragColor = mix(highMip, lowMip, material_BloomParams.z);\n \n #ifndef ENGINE_IS_COLORSPACE_GAMMA\n gl_FragColor = linearToGamma(gl_FragColor);\n #endif\n}"; // eslint-disable-line
|
|
24128
24146
|
|
|
@@ -25109,7 +25127,10 @@ ShaderPool.init();
|
|
|
25109
25127
|
var initializePromises = new Array();
|
|
25110
25128
|
if (physics) {
|
|
25111
25129
|
initializePromises.push(physics.initialize().then(function() {
|
|
25112
|
-
|
|
25130
|
+
if (Engine._nativePhysics) {
|
|
25131
|
+
console.warn("A physics engine has already been configured. All physics operations will now be handled by the newly specified physics engine.");
|
|
25132
|
+
}
|
|
25133
|
+
Engine._nativePhysics = physics;
|
|
25113
25134
|
_this._nativePhysicsManager = physics.createPhysicsManager();
|
|
25114
25135
|
_this._physicsInitialized = true;
|
|
25115
25136
|
return _this;
|
|
@@ -27181,6 +27202,7 @@ PostProcessManager._tempVector3 = new Vector3();
|
|
|
27181
27202
|
this._maskManager.destroy();
|
|
27182
27203
|
var allCreatedScenes = sceneManager._allCreatedScenes;
|
|
27183
27204
|
allCreatedScenes.splice(allCreatedScenes.indexOf(this), 1);
|
|
27205
|
+
this.physics._destroy();
|
|
27184
27206
|
};
|
|
27185
27207
|
_proto._computeLinearFogParams = function _computeLinearFogParams(fogStart, fogEnd) {
|
|
27186
27208
|
var fogRange = fogEnd - fogStart;
|
|
@@ -35857,10 +35879,11 @@ __decorate([
|
|
|
35857
35879
|
function Polyfill() {}
|
|
35858
35880
|
Polyfill.registerPolyfill = function registerPolyfill() {
|
|
35859
35881
|
Polyfill._registerMatchAll();
|
|
35882
|
+
Polyfill._registerAudioContext();
|
|
35860
35883
|
};
|
|
35861
35884
|
Polyfill._registerMatchAll = function _registerMatchAll() {
|
|
35862
35885
|
if (!String.prototype.matchAll) {
|
|
35863
|
-
Logger.info("
|
|
35886
|
+
Logger.info("Polyfill String.prototype.matchAll");
|
|
35864
35887
|
String.prototype.matchAll = function(pattern) {
|
|
35865
35888
|
var flags = pattern.flags;
|
|
35866
35889
|
var globalFlagIdx = flags.indexOf("g");
|
|
@@ -35914,6 +35937,26 @@ __decorate([
|
|
|
35914
35937
|
};
|
|
35915
35938
|
}
|
|
35916
35939
|
};
|
|
35940
|
+
Polyfill._registerAudioContext = function _registerAudioContext() {
|
|
35941
|
+
// IOS 12 and the following system do not support AudioContext, need to switch to webkitAudioContext
|
|
35942
|
+
if (!window.AudioContext && window.webkitAudioContext) {
|
|
35943
|
+
Logger.info("Polyfill window.AudioContext");
|
|
35944
|
+
window.AudioContext = window.webkitAudioContext;
|
|
35945
|
+
var originalDecodeAudioData = AudioContext.prototype.decodeAudioData;
|
|
35946
|
+
AudioContext.prototype.decodeAudioData = function(arrayBuffer, successCallback, errorCallback) {
|
|
35947
|
+
var _this = this;
|
|
35948
|
+
return new Promise(function(resolve, reject) {
|
|
35949
|
+
originalDecodeAudioData.call(_this, arrayBuffer, function(buffer) {
|
|
35950
|
+
successCallback == null ? void 0 : successCallback(buffer);
|
|
35951
|
+
resolve(buffer);
|
|
35952
|
+
}, function(error) {
|
|
35953
|
+
errorCallback == null ? void 0 : errorCallback(error);
|
|
35954
|
+
reject(error);
|
|
35955
|
+
});
|
|
35956
|
+
});
|
|
35957
|
+
};
|
|
35958
|
+
}
|
|
35959
|
+
};
|
|
35917
35960
|
return Polyfill;
|
|
35918
35961
|
}();
|
|
35919
35962
|
|