@galacean/engine-core 2.0.0-alpha.41 → 2.0.0-alpha.44

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/module.js CHANGED
@@ -3061,7 +3061,7 @@ var Utils = /*#__PURE__*/ function() {
3061
3061
  * @param url - The url to be judged.
3062
3062
  * @returns Whether the url is absolute url.
3063
3063
  */ Utils.isAbsoluteUrl = function isAbsoluteUrl(url) {
3064
- return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
3064
+ return /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(url);
3065
3065
  };
3066
3066
  /**
3067
3067
  * Judge whether the url is base64 url.
@@ -3086,16 +3086,15 @@ var Utils = /*#__PURE__*/ function() {
3086
3086
  if (Utils.isAbsoluteUrl(relativeUrl)) {
3087
3087
  return relativeUrl;
3088
3088
  }
3089
- if (Utils.isBase64Url(relativeUrl)) {
3090
- return relativeUrl;
3091
- }
3092
3089
  if (Utils.isAbsoluteUrl(baseUrl)) {
3093
3090
  return relativeUrl ? new URL(relativeUrl, baseUrl).href : baseUrl;
3094
3091
  }
3095
- var head = "file://";
3096
- var encodedBaseUrl = head + this._encodePathComponents(baseUrl);
3092
+ // Use an empty file URL host to preserve path casing
3093
+ var hasLeadingSlash = baseUrl.startsWith("/") || relativeUrl.startsWith("/");
3094
+ var encodedBaseUrl = "file:///" + this._encodePathComponents(baseUrl.replace(/^\/+/, ""));
3097
3095
  var encodedRelativeUrl = this._encodePathComponents(relativeUrl);
3098
- return decodeURIComponent(new URL(encodedRelativeUrl, encodedBaseUrl).href.slice(head.length));
3096
+ var resolvedPath = decodeURIComponent(new URL(encodedRelativeUrl, encodedBaseUrl).pathname);
3097
+ return hasLeadingSlash ? resolvedPath : resolvedPath.slice(1);
3099
3098
  };
3100
3099
  /**
3101
3100
  * @internal
@@ -6320,8 +6319,8 @@ function _construct(Parent, args, Class) {
6320
6319
  children.length = 0;
6321
6320
  };
6322
6321
  /**
6323
- * Clone this entity include children and components.
6324
- * @returns Cloned entity
6322
+ * Clone this Entity, including children and components.
6323
+ * @returns A detached clone that must be added to a parent Entity or Scene to update and render
6325
6324
  */ _proto.clone = function clone() {
6326
6325
  var cloneMap = new Map();
6327
6326
  var cloneEntity = this._createCloneEntity(cloneMap);
@@ -7787,6 +7786,7 @@ var RendererUpdateFlags = /*#__PURE__*/ function(RendererUpdateFlags) {
7787
7786
  this._intView = new Int32Array(this._data);
7788
7787
  (_this_buffer = this.buffer) == null ? void 0 : _this_buffer.destroy();
7789
7788
  this.buffer = new Buffer(this._engine, BufferBindFlag.ConstantBuffer, totalBytes, BufferUsage.Dynamic);
7789
+ this.buffer.isGCIgnored = true;
7790
7790
  }
7791
7791
  };
7792
7792
  /**
@@ -15947,10 +15947,10 @@ var BufferUpdateInfo = /*#__PURE__*/ function() {
15947
15947
  return mesh;
15948
15948
  };
15949
15949
  /**
15950
- * Create a plane mesh.
15950
+ * Create a plane mesh with U mapped along local +X and V along local +Z.
15951
15951
  * @param engine - Engine
15952
- * @param width - Plane width
15953
- * @param height - Plane height
15952
+ * @param width - Plane width along the local X axis
15953
+ * @param height - Plane height along the local Z axis
15954
15954
  * @param horizontalSegments - Plane horizontal segments
15955
15955
  * @param verticalSegments - Plane vertical segments
15956
15956
  * @param noLongerAccessible - No longer access the vertices of the mesh after creation
@@ -18630,11 +18630,11 @@ var MultiExecutor = /*#__PURE__*/ function() {
18630
18630
  };
18631
18631
  /**
18632
18632
  * Get the resource from cache by asset url, return the resource object if it loaded, otherwise return null.
18633
- * @param url - Resource url
18633
+ * @param url - Resource URL
18634
18634
  * @returns Resource object
18635
18635
  */ _proto.getFromCache = function getFromCache(url) {
18636
- var _this__assetUrlPool_url;
18637
- return (_this__assetUrlPool_url = this._assetUrlPool[url]) != null ? _this__assetUrlPool_url : null;
18636
+ var _this__assetUrlPool_this__getRemoteUrl;
18637
+ return (_this__assetUrlPool_this__getRemoteUrl = this._assetUrlPool[this._getRemoteUrl(url)]) != null ? _this__assetUrlPool_this__getRemoteUrl : null;
18638
18638
  };
18639
18639
  /**
18640
18640
  * Find the resource by type.
@@ -18659,19 +18659,18 @@ var MultiExecutor = /*#__PURE__*/ function() {
18659
18659
  return this._assetPool[instanceId];
18660
18660
  };
18661
18661
  _proto.cancelNotLoaded = function cancelNotLoaded(url) {
18662
- var _this = this;
18663
18662
  if (!url) {
18664
18663
  Utils.objectValues(this._loadingPromises).forEach(function(promise) {
18665
18664
  promise.cancel();
18666
18665
  });
18667
18666
  } else if (typeof url === "string") {
18668
- var _this__loadingPromises_url;
18669
- (_this__loadingPromises_url = this._loadingPromises[url]) == null ? void 0 : _this__loadingPromises_url.cancel();
18667
+ var _this__loadingPromises_this__getLoadingKey;
18668
+ (_this__loadingPromises_this__getLoadingKey = this._loadingPromises[this._getLoadingKey(url)]) == null ? void 0 : _this__loadingPromises_this__getLoadingKey.cancel();
18670
18669
  } else {
18671
- url.forEach(function(p) {
18672
- var _this__loadingPromises_p;
18673
- (_this__loadingPromises_p = _this._loadingPromises[p]) == null ? void 0 : _this__loadingPromises_p.cancel();
18674
- });
18670
+ for(var i = 0, n = url.length; i < n; i++){
18671
+ var _this__loadingPromises_this__getLoadingKey1;
18672
+ (_this__loadingPromises_this__getLoadingKey1 = this._loadingPromises[this._getLoadingKey(url[i])]) == null ? void 0 : _this__loadingPromises_this__getLoadingKey1.cancel();
18673
+ }
18675
18674
  }
18676
18675
  };
18677
18676
  /**
@@ -18693,7 +18692,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
18693
18692
  */ _proto._getRemoteUrl = function _getRemoteUrl(url) {
18694
18693
  var _this__virtualPathResourceMap_url;
18695
18694
  var _this__virtualPathResourceMap_url_path;
18696
- return (_this__virtualPathResourceMap_url_path = (_this__virtualPathResourceMap_url = this._virtualPathResourceMap[url]) == null ? void 0 : _this__virtualPathResourceMap_url.path) != null ? _this__virtualPathResourceMap_url_path : url;
18695
+ return (_this__virtualPathResourceMap_url_path = (_this__virtualPathResourceMap_url = this._virtualPathResourceMap[url]) == null ? void 0 : _this__virtualPathResourceMap_url.path) != null ? _this__virtualPathResourceMap_url_path : this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, url) : url;
18697
18696
  };
18698
18697
  /**
18699
18698
  * @internal
@@ -18708,17 +18707,14 @@ var MultiExecutor = /*#__PURE__*/ function() {
18708
18707
  };
18709
18708
  /**
18710
18709
  * @internal
18711
- */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetBaseURL, assetSubPath, value) {
18712
- var _this__virtualPathResourceMap_assetBaseURL, _this__subAssetPromiseCallbacks_remoteAssetBaseURL;
18713
- var _this__virtualPathResourceMap_assetBaseURL_path;
18714
- var remoteAssetBaseURL = (_this__virtualPathResourceMap_assetBaseURL_path = (_this__virtualPathResourceMap_assetBaseURL = this._virtualPathResourceMap[assetBaseURL]) == null ? void 0 : _this__virtualPathResourceMap_assetBaseURL.path) != null ? _this__virtualPathResourceMap_assetBaseURL_path : assetBaseURL;
18715
- var subPromiseCallback = (_this__subAssetPromiseCallbacks_remoteAssetBaseURL = this._subAssetPromiseCallbacks[remoteAssetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_remoteAssetBaseURL[assetSubPath];
18710
+ */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(remoteAssetBaseURL, assetSubPath, value) {
18711
+ var _this__subAssetPromiseCallbacks, _remoteAssetBaseURL;
18712
+ var subAssetPromiseCallbacks = (_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_remoteAssetBaseURL = remoteAssetBaseURL] || (_this__subAssetPromiseCallbacks[_remoteAssetBaseURL] = {});
18713
+ var subPromiseCallback = subAssetPromiseCallbacks[assetSubPath];
18716
18714
  if (subPromiseCallback) {
18717
18715
  subPromiseCallback.resolve(value);
18718
18716
  } else {
18719
- var // Pending
18720
- _this__subAssetPromiseCallbacks, _remoteAssetBaseURL;
18721
- ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_remoteAssetBaseURL = remoteAssetBaseURL] || (_this__subAssetPromiseCallbacks[_remoteAssetBaseURL] = {}))[assetSubPath] = {
18717
+ subAssetPromiseCallbacks[assetSubPath] = {
18722
18718
  resolvedValue: value
18723
18719
  };
18724
18720
  }
@@ -18830,13 +18826,10 @@ var MultiExecutor = /*#__PURE__*/ function() {
18830
18826
  // Parse url
18831
18827
  var _this__parseURL = this._parseURL(item.url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18832
18828
  var paths = queryPath ? this._parseQueryPath(queryPath) : [];
18833
- // Get remote asset base url
18834
18829
  var virtualResourceEntry = this._virtualPathResourceMap[assetBaseURL];
18835
18830
  this._resolveLoadItemOptions(item, virtualResourceEntry);
18836
- // Not absolute and base url is set
18837
- item.url = !Utils.isAbsoluteUrl(assetBaseURL) && this.baseUrl ? Utils.resolveAbsoluteUrl(this.baseUrl, assetBaseURL) : assetBaseURL;
18838
- var _virtualResourceEntry_path;
18839
- var remoteAssetBaseURL = (_virtualResourceEntry_path = virtualResourceEntry == null ? void 0 : virtualResourceEntry.path) != null ? _virtualResourceEntry_path : item.url;
18831
+ var remoteAssetBaseURL = this._getRemoteUrl(assetBaseURL);
18832
+ item.url = assetBaseURL;
18840
18833
  // Check cache
18841
18834
  var cacheObject = this._assetUrlPool[remoteAssetBaseURL];
18842
18835
  if (cacheObject) {
@@ -18844,15 +18837,7 @@ var MultiExecutor = /*#__PURE__*/ function() {
18844
18837
  resolve(_this._getResolveResource(cacheObject, paths));
18845
18838
  });
18846
18839
  }
18847
- // Get asset url
18848
- var remoteAssetURL = remoteAssetBaseURL;
18849
- if (queryPath) {
18850
- remoteAssetURL += "?q=" + paths.shift();
18851
- var index;
18852
- while(index = paths.shift()){
18853
- remoteAssetURL += "[" + index + "]";
18854
- }
18855
- }
18840
+ var remoteAssetURL = this._getRemoteAssetURL(remoteAssetBaseURL, paths);
18856
18841
  // Check is loading
18857
18842
  var loadingPromises = this._loadingPromises;
18858
18843
  var loadingPromise = loadingPromises[remoteAssetURL];
@@ -18958,6 +18943,21 @@ var MultiExecutor = /*#__PURE__*/ function() {
18958
18943
  }
18959
18944
  return subResource;
18960
18945
  };
18946
+ _proto._getLoadingKey = function _getLoadingKey(url) {
18947
+ var _this__parseURL = this._parseURL(url), assetBaseURL = _this__parseURL.assetBaseURL, queryPath = _this__parseURL.queryPath;
18948
+ var remoteAssetBaseURL = this._getRemoteUrl(assetBaseURL);
18949
+ return queryPath ? this._getRemoteAssetURL(remoteAssetBaseURL, this._parseQueryPath(queryPath)) : remoteAssetBaseURL;
18950
+ };
18951
+ _proto._getRemoteAssetURL = function _getRemoteAssetURL(remoteAssetBaseURL, paths) {
18952
+ var remoteAssetURL = remoteAssetBaseURL;
18953
+ if (paths.length > 0) {
18954
+ remoteAssetURL += "?q=" + paths[0];
18955
+ for(var i = 1, n = paths.length; i < n; i++){
18956
+ remoteAssetURL += "[" + paths[i] + "]";
18957
+ }
18958
+ }
18959
+ return remoteAssetURL;
18960
+ };
18961
18961
  _proto._parseURL = function _parseURL(path) {
18962
18962
  var _path_split = path.split("?"), baseUrl = _path_split[0], searchStr = _path_split[1];
18963
18963
  var queryPath = undefined;
@@ -19599,6 +19599,7 @@ var Collider = /*#__PURE__*/ function(Component) {
19599
19599
  var _proto = Collider.prototype;
19600
19600
  /**
19601
19601
  * Add collider shape on this collider.
19602
+ * @remarks If the shape belongs to another Collider, it is moved to this Collider.
19602
19603
  * @param shape - Collider shape
19603
19604
  */ _proto.addShape = function addShape(shape) {
19604
19605
  var oldCollider = shape._collider;
@@ -20501,7 +20502,7 @@ __decorate([
20501
20502
  };
20502
20503
  _proto._syncNative = function _syncNative() {
20503
20504
  // Non-convex triangle meshes require a kinematic native actor before attachment
20504
- this._nativeCollider.setIsKinematic(this._isKinematic);
20505
+ this._nativeCollider.setMotionState(this._isKinematic, this._collisionDetectionMode);
20505
20506
  Collider.prototype._syncNative.call(this);
20506
20507
  this._nativeCollider.setLinearDamping(this._linearDamping);
20507
20508
  this._nativeCollider.setAngularDamping(this._angularDamping);
@@ -20520,7 +20521,6 @@ __decorate([
20520
20521
  this._nativeCollider.setSolverIterations(this._solverIterations);
20521
20522
  this._nativeCollider.setUseGravity(this._useGravity);
20522
20523
  this._nativeCollider.setConstraints(this._constraints);
20523
- this._nativeCollider.setCollisionDetectionMode(this._collisionDetectionMode);
20524
20524
  };
20525
20525
  _proto._setMassAndUpdateInertia = function _setMassAndUpdateInertia() {
20526
20526
  // Kinematic bodies don't need mass/inertia computation (PhysX doc: mass is not used in kinematic mode)
@@ -20797,13 +20797,9 @@ __decorate([
20797
20797
  }
20798
20798
  }
20799
20799
  this._isKinematic = value;
20800
- this._nativeCollider.setIsKinematic(value);
20801
- // Resync properties that PhysX ignores/resets during kinematic mode
20802
- if (!value) {
20803
- this._nativeCollider.setCollisionDetectionMode(this._collisionDetectionMode);
20804
- if (this._automaticCenterOfMass || this._automaticInertiaTensor) {
20805
- this._setMassAndUpdateInertia();
20806
- }
20800
+ this._nativeCollider.setMotionState(value, this._collisionDetectionMode);
20801
+ if (!value && (this._automaticCenterOfMass || this._automaticInertiaTensor)) {
20802
+ this._setMassAndUpdateInertia();
20807
20803
  }
20808
20804
  }
20809
20805
  }
@@ -20825,14 +20821,16 @@ __decorate([
20825
20821
  {
20826
20822
  key: "collisionDetectionMode",
20827
20823
  get: /**
20828
- * The colliders' collision detection mode.
20824
+ * The collision detection mode.
20825
+ * @remarks With the PhysX backend, Continuous and ContinuousDynamic are mapped to speculative CCD while the collider
20826
+ * is kinematic.
20829
20827
  */ function get() {
20830
20828
  return this._collisionDetectionMode;
20831
20829
  },
20832
20830
  set: function set(value) {
20833
20831
  if (this._collisionDetectionMode !== value) {
20834
20832
  this._collisionDetectionMode = value;
20835
- this._nativeCollider.setCollisionDetectionMode(value);
20833
+ this._nativeCollider.setMotionState(this._isKinematic, value);
20836
20834
  }
20837
20835
  }
20838
20836
  }
@@ -20919,8 +20917,7 @@ __decorate([
20919
20917
  * You need to obtain the actual number of contact points from the function's return value.
20920
20918
  */ _proto.getContacts = function getContacts(outContacts) {
20921
20919
  var nativeCollision = this._nativeCollision;
20922
- var smallerShapeId = Math.min(nativeCollision.shape0Id, nativeCollision.shape1Id);
20923
- var factor = this.shape.id === smallerShapeId ? 1 : -1;
20920
+ var factor = this.shape.id === nativeCollision.shape1Id ? 1 : -1;
20924
20921
  var nativeContactPoints = nativeCollision.getContacts();
20925
20922
  var length = nativeContactPoints.size();
20926
20923
  for(var i = 0; i < length; i++){
@@ -20955,6 +20952,7 @@ __decorate([
20955
20952
  this._fixedTimeStep = 1 / 60;
20956
20953
  this._colliders = new DisorderedArray();
20957
20954
  this._gravity = new Vector3(0, -9.81, 0);
20955
+ this._contactEventConsumerCount = 0;
20958
20956
  this._scene = scene;
20959
20957
  this._setGravity = this._setGravity.bind(this);
20960
20958
  //@ts-ignore
@@ -20962,6 +20960,7 @@ __decorate([
20962
20960
  var engine = scene.engine;
20963
20961
  if (engine._physicsInitialized) {
20964
20962
  this._nativePhysicsScene = Engine._nativePhysics.createPhysicsScene(engine._nativePhysicsManager);
20963
+ this._nativePhysicsScene.setContactEventEnabled(false);
20965
20964
  }
20966
20965
  }
20967
20966
  var _proto = PhysicsScene.prototype;
@@ -21220,6 +21219,17 @@ __decorate([
21220
21219
  };
21221
21220
  /**
21222
21221
  * @internal
21222
+ */ _proto._addContactEventConsumer = function _addContactEventConsumer(delta) {
21223
+ var wasEnabled = this._contactEventConsumerCount > 0;
21224
+ this._contactEventConsumerCount += delta;
21225
+ var enabled = this._contactEventConsumerCount > 0;
21226
+ if (wasEnabled !== enabled) {
21227
+ var _this__nativePhysicsScene;
21228
+ (_this__nativePhysicsScene = this._nativePhysicsScene) == null ? void 0 : _this__nativePhysicsScene.setContactEventEnabled(enabled);
21229
+ }
21230
+ };
21231
+ /**
21232
+ * @internal
21223
21233
  */ _proto._callColliderOnUpdate = function _callColliderOnUpdate() {
21224
21234
  var elements = this._colliders._elements;
21225
21235
  for(var i = this._colliders.length - 1; i >= 0; --i){
@@ -29443,6 +29453,9 @@ Scene._prefilterdDFGProperty = ShaderProperty.getByName("scene_PrefilteredDFG");
29443
29453
  }
29444
29454
  }
29445
29455
  this._entity._addScript(this);
29456
+ if (this._hasCollisionEventCallbacks()) {
29457
+ this.scene.physics._addContactEventConsumer(1);
29458
+ }
29446
29459
  };
29447
29460
  /**
29448
29461
  * @internal
@@ -29462,6 +29475,9 @@ Scene._prefilterdDFGProperty = ShaderProperty.getByName("scene_PrefilteredDFG");
29462
29475
  componentsManager.removeOnPhysicsUpdateScript(this);
29463
29476
  }
29464
29477
  this._entity._removeScript(this);
29478
+ if (this._hasCollisionEventCallbacks()) {
29479
+ this.scene.physics._addContactEventConsumer(-1);
29480
+ }
29465
29481
  };
29466
29482
  /**
29467
29483
  * @internal
@@ -29469,6 +29485,10 @@ Scene._prefilterdDFGProperty = ShaderProperty.getByName("scene_PrefilteredDFG");
29469
29485
  Component.prototype._onDestroy.call(this);
29470
29486
  this.onDestroy();
29471
29487
  };
29488
+ _proto._hasCollisionEventCallbacks = function _hasCollisionEventCallbacks() {
29489
+ var prototype = Script.prototype;
29490
+ return this.onCollisionEnter !== prototype.onCollisionEnter || this.onCollisionExit !== prototype.onCollisionExit || this.onCollisionStay !== prototype.onCollisionStay;
29491
+ };
29472
29492
  return Script;
29473
29493
  }(Component);
29474
29494
  __decorate([
@@ -35152,6 +35172,23 @@ __decorate([
35152
35172
  this._gradients.delete(name);
35153
35173
  };
35154
35174
  /**
35175
+ * Remove all custom data streams.
35176
+ */ _proto.clear = function clear() {
35177
+ var shaderData = this._generator._renderer.shaderData;
35178
+ var curveStreams = this._curveStreams;
35179
+ for(var i = 0, n = curveStreams.length; i < n; i++){
35180
+ this._zeroCurveUniforms(shaderData, curveStreams[i]);
35181
+ }
35182
+ var gradientStreams = this._gradientStreams;
35183
+ for(var i1 = 0, n1 = gradientStreams.length; i1 < n1; i1++){
35184
+ this._zeroGradientUniforms(shaderData, gradientStreams[i1]);
35185
+ }
35186
+ this._curves.clear();
35187
+ this._gradients.clear();
35188
+ curveStreams.length = 0;
35189
+ gradientStreams.length = 0;
35190
+ };
35191
+ /**
35155
35192
  * @internal
35156
35193
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
35157
35194
  if (!this.enabled) {
@@ -35277,7 +35314,7 @@ CustomDataModule._zeroVector4 = new Vector4(0, 0, 0, 0);
35277
35314
  _this = DataObject.call(this) || this, _this._updateManager = new UpdateFlagManager(), _this._mode = ParticleCurveMode.Constant, _this._constantMin = 0, _this._constantMax = 0;
35278
35315
  _this._updateDispatch = _this._updateManager.dispatch.bind(_this._updateManager);
35279
35316
  if (typeof constantOrCurve === "number") {
35280
- if (constantMaxOrCurveMax) {
35317
+ if (constantMaxOrCurveMax !== undefined) {
35281
35318
  _this.constantMin = constantOrCurve;
35282
35319
  _this.constantMax = constantMaxOrCurveMax;
35283
35320
  _this.mode = ParticleCurveMode.TwoConstants;
@@ -35286,7 +35323,7 @@ CustomDataModule._zeroVector4 = new Vector4(0, 0, 0, 0);
35286
35323
  _this.mode = ParticleCurveMode.Constant;
35287
35324
  }
35288
35325
  } else {
35289
- if (constantMaxOrCurveMax) {
35326
+ if (constantMaxOrCurveMax !== undefined) {
35290
35327
  _this.curveMin = constantOrCurve;
35291
35328
  _this.curveMax = constantMaxOrCurveMax;
35292
35329
  _this.mode = ParticleCurveMode.TwoCurves;
@@ -37971,6 +38008,15 @@ __decorate([
37971
38008
  this._generator._setTransformFeedback();
37972
38009
  };
37973
38010
  /**
38011
+ * Remove all sub-emitter slots.
38012
+ */ _proto.clear = function clear() {
38013
+ if (this._subEmitters.length === 0) {
38014
+ return;
38015
+ }
38016
+ this._subEmitters.length = 0;
38017
+ this._generator._setTransformFeedback();
38018
+ };
38019
+ /**
37974
38020
  * @internal
37975
38021
  */ _proto._dispatchEvent = function _dispatchEvent(type, worldPosition, parentColor, parentSize, parentRotation, worldDirection) {
37976
38022
  var subEmitters = this.subEmitters;