@galacean/engine-core 2.0.0-alpha.45 → 2.0.0-alpha.47

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 CHANGED
@@ -5022,10 +5022,25 @@ registerDefaultCloneMode(Component, CloneMode.Remap);
5022
5022
  };
5023
5023
  /**
5024
5024
  * @internal
5025
- */ ComponentsDependencies._removeCheck = function _removeCheck(entity, type) {
5025
+ */ ComponentsDependencies._hasDependencies = function _hasDependencies(type) {
5026
+ while(type !== Component){
5027
+ if (ComponentsDependencies._dependenciesMap.has(type)) {
5028
+ return true;
5029
+ }
5030
+ type = Object.getPrototypeOf(type);
5031
+ }
5032
+ return false;
5033
+ };
5034
+ /**
5035
+ * @internal
5036
+ */ ComponentsDependencies._removeCheck = function _removeCheck(entity, type, replace) {
5026
5037
  var components = entity._components;
5027
5038
  var n = components.length;
5028
5039
  while(type !== Component){
5040
+ // The replacement still satisfies this type and all of its base types
5041
+ if (replace && (replace === type || _instanceof(replace.prototype, type))) {
5042
+ return;
5043
+ }
5029
5044
  var count = 0;
5030
5045
  for(var i = 0; i < n; i++){
5031
5046
  if (_instanceof(components[i], type) && ++count > 1) return;
@@ -5142,6 +5157,7 @@ registerDefaultCloneMode(UpdateFlag, CloneMode.Ignore);
5142
5157
 
5143
5158
  /**
5144
5159
  * Used to implement transformation related functions.
5160
+ * @remarks A `Transform` subclass must not declare component dependencies.
5145
5161
  */ var Transform = /*#__PURE__*/ function(Component) {
5146
5162
  _inherits(Transform, Component);
5147
5163
  function Transform(entity) {
@@ -5171,6 +5187,13 @@ registerDefaultCloneMode(UpdateFlag, CloneMode.Ignore);
5171
5187
  return _this;
5172
5188
  }
5173
5189
  var _proto = Transform.prototype;
5190
+ _proto.destroy = function destroy() {
5191
+ var entity = this._entity;
5192
+ if (entity.transform === this && !entity.destroyed) {
5193
+ throw "Transform cannot be destroyed directly; replace it by adding another Transform-compatible component";
5194
+ }
5195
+ Component.prototype.destroy.call(this);
5196
+ };
5174
5197
  /**
5175
5198
  * Set local position by X, Y, Z value.
5176
5199
  * @param x - X coordinate
@@ -5309,22 +5332,35 @@ registerDefaultCloneMode(UpdateFlag, CloneMode.Ignore);
5309
5332
  return isInvert;
5310
5333
  };
5311
5334
  /**
5335
+ * @internal
5336
+ */ _proto._copyLocalPoseFrom = function _copyLocalPoseFrom(source) {
5337
+ var _this = this, position = _this._position, rotation = _this._rotation, rotationQuaternion = _this._rotationQuaternion, scale = _this._scale;
5338
+ //@ts-ignore
5339
+ position._onValueChanged = rotation._onValueChanged = scale._onValueChanged = null;
5340
+ //@ts-ignore
5341
+ rotationQuaternion._onValueChanged = null;
5342
+ position.copyFrom(source._position);
5343
+ scale.copyFrom(source._scale);
5344
+ rotation.copyFrom(source._rotation);
5345
+ rotationQuaternion.copyFrom(source._rotationQuaternion);
5346
+ //@ts-ignore
5347
+ position._onValueChanged = this._onPositionChanged;
5348
+ //@ts-ignore
5349
+ rotation._onValueChanged = this._onRotationChanged;
5350
+ //@ts-ignore
5351
+ rotationQuaternion._onValueChanged = this._onRotationQuaternionChanged;
5352
+ //@ts-ignore
5353
+ scale._onValueChanged = this._onScaleChanged;
5354
+ this._localUniformScaling = source._localUniformScaling;
5355
+ var rotationDirtyBits = 1 | 2;
5356
+ this._dirtyFlag = this._dirtyFlag & ~rotationDirtyBits | source._dirtyFlag & rotationDirtyBits;
5357
+ this._setDirtyFlagTrue(64);
5358
+ this._updateAllWorldFlag(444);
5359
+ };
5360
+ /**
5312
5361
  * @inheritdoc
5313
5362
  */ _proto._onClone = function _onClone(target) {
5314
- var position = target._position, rotation = target._rotation, scale = target._scale;
5315
- // @ts-ignore
5316
- position._onValueChanged = rotation._onValueChanged = scale._onValueChanged = null;
5317
- position.copyFrom(this.position);
5318
- rotation.copyFrom(this.rotation);
5319
- scale.copyFrom(this.scale);
5320
- // @ts-ignore
5321
- position._onValueChanged = target._onPositionChanged;
5322
- // @ts-ignore
5323
- rotation._onValueChanged = target._onRotationChanged;
5324
- // @ts-ignore
5325
- scale._onValueChanged = target._onScaleChanged;
5326
- // When cloning, other components may obtain properties such as `rotationQuaternion` in the constructor, local related dirty flags need to be corrected
5327
- target._setDirtyFlagTrue(2 | 64);
5363
+ target._copyLocalPoseFrom(this);
5328
5364
  };
5329
5365
  _proto._onLocalMatrixChanging = function _onLocalMatrixChanging() {
5330
5366
  this._setDirtyFlagFalse(64);
@@ -6175,10 +6211,27 @@ function _construct(Parent, args, Class) {
6175
6211
  _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._scriptsVersion = 0, /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
6176
6212
  _this._invModelMatrix = new engineMath.Matrix();
6177
6213
  _this.name = name != null ? name : "Entity";
6178
- for(var i = 0, n = components.length; i < n; i++){
6179
- _this.addComponent(components[i]);
6214
+ var transformType = Transform;
6215
+ var n = components.length;
6216
+ for(var i = n - 1; i >= 0; i--){
6217
+ var componentType = components[i];
6218
+ if (Entity._isTransformType(componentType)) {
6219
+ transformType = componentType;
6220
+ break;
6221
+ }
6222
+ }
6223
+ Entity._checkTransformDependencies(transformType);
6224
+ var transform = new transformType(_this);
6225
+ // Constructors may add components, but Transform always owns slot zero
6226
+ _this._components.unshift(transform);
6227
+ _this._transform = transform;
6228
+ transform._setActive(true, ActiveChangeFlag.All);
6229
+ for(var i1 = 0; i1 < n; i1++){
6230
+ var componentType1 = components[i1];
6231
+ if (!Entity._isTransformType(componentType1)) {
6232
+ _this.addComponent(componentType1);
6233
+ }
6180
6234
  }
6181
- !_this._transform && _this.addComponent(Transform);
6182
6235
  _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
6183
6236
  return _this;
6184
6237
  }
@@ -6192,13 +6245,21 @@ function _construct(Parent, args, Class) {
6192
6245
  for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
6193
6246
  args[_key - 1] = arguments[_key];
6194
6247
  }
6195
- ComponentsDependencies._addCheck(this, type);
6248
+ var isTransform = Entity._isTransformType(type);
6249
+ if (isTransform) {
6250
+ Entity._checkTransformDependencies(type);
6251
+ ComponentsDependencies._removeCheck(this, this._transform.constructor, type);
6252
+ } else {
6253
+ ComponentsDependencies._addCheck(this, type);
6254
+ }
6196
6255
  var component = _construct(type, [].concat([
6197
6256
  this
6198
6257
  ], args));
6199
- this._components.push(component);
6200
- // @todo: temporary solution
6201
- if (_instanceof(component, Transform)) this._setTransform(component);
6258
+ if (isTransform) {
6259
+ this._replaceTransform(component);
6260
+ } else {
6261
+ this._components.push(component);
6262
+ }
6202
6263
  component._setActive(true, ActiveChangeFlag.All);
6203
6264
  return component;
6204
6265
  };
@@ -6346,6 +6407,7 @@ function _construct(Parent, args, Class) {
6346
6407
  _proto._createCloneEntity = function _createCloneEntity(cloneMap) {
6347
6408
  var componentConstructors = Entity._tempComponentConstructors;
6348
6409
  var components = this._components;
6410
+ componentConstructors.length = components.length;
6349
6411
  for(var i = 0, n = components.length; i < n; i++){
6350
6412
  componentConstructors[i] = components[i].constructor;
6351
6413
  }
@@ -6413,9 +6475,13 @@ function _construct(Parent, args, Class) {
6413
6475
  /**
6414
6476
  * @internal
6415
6477
  */ _proto._removeComponent = function _removeComponent(component) {
6416
- ComponentsDependencies._removeCheck(this, component.constructor);
6417
6478
  var components = this._components;
6418
- components.splice(components.indexOf(component), 1);
6479
+ var index = components.indexOf(component);
6480
+ // A replaced Transform is detached from the component slot immediately but
6481
+ // can still reach here later because object destruction may be deferred
6482
+ if (index < 0) return;
6483
+ ComponentsDependencies._removeCheck(this, component.constructor);
6484
+ components.splice(index, 1);
6419
6485
  };
6420
6486
  /**
6421
6487
  * @internal
@@ -6617,15 +6683,16 @@ function _construct(Parent, args, Class) {
6617
6683
  }
6618
6684
  }
6619
6685
  };
6620
- _proto._setTransform = function _setTransform(value) {
6621
- var _this__transform;
6622
- (_this__transform = this._transform) == null ? void 0 : _this__transform.destroy();
6623
- this._transform = value;
6686
+ _proto._replaceTransform = function _replaceTransform(replacement) {
6687
+ var previous = this._transform;
6688
+ replacement._copyLocalPoseFrom(previous);
6689
+ this._components[0] = replacement;
6690
+ this._transform = replacement;
6624
6691
  var children = this._children;
6625
6692
  for(var i = 0, n = children.length; i < n; i++){
6626
- var _children_i_transform;
6627
- (_children_i_transform = children[i].transform) == null ? void 0 : _children_i_transform._parentChange();
6693
+ children[i].transform._parentChange();
6628
6694
  }
6695
+ previous.destroy();
6629
6696
  };
6630
6697
  /**
6631
6698
  * @deprecated
@@ -6636,6 +6703,14 @@ function _construct(Parent, args, Class) {
6636
6703
  }
6637
6704
  return this._invModelMatrix;
6638
6705
  };
6706
+ Entity._isTransformType = function _isTransformType(type) {
6707
+ return type === Transform || _instanceof(type.prototype, Transform);
6708
+ };
6709
+ Entity._checkTransformDependencies = function _checkTransformDependencies(type) {
6710
+ if (ComponentsDependencies._hasDependencies(type)) {
6711
+ throw "Transform-compatible component " + type.name + " cannot declare component dependencies";
6712
+ }
6713
+ };
6639
6714
  /**
6640
6715
  * @internal
6641
6716
  */ Entity._findChildByName = function _findChildByName(entity, childIndex, paths, pathIndex) {
@@ -14751,6 +14826,7 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
14751
14826
 
14752
14827
  /**
14753
14828
  * Mesh containing common vertex elements of the model.
14829
+ * Define draw ranges with `addSubMesh()` and assign a material to each corresponding MeshRenderer slot.
14754
14830
  */ var ModelMesh = /*#__PURE__*/ function(Mesh) {
14755
14831
  _inherits(ModelMesh, Mesh);
14756
14832
  function ModelMesh(engine, name) {
@@ -15084,8 +15160,8 @@ BlendShapeManager._blendShapeTextureInfoProperty = ShaderProperty.getByName("ren
15084
15160
  return blendShapes[index].name;
15085
15161
  };
15086
15162
  /**
15087
- * Upload data to GPU set by `setPositions()`, `setNormals()`, `setColors()`, `setBoneWeights()`, `setBoneIndices()`, `setTangents()`, `setUVs()`, `setIndices()` methods.
15088
- * This method will be auto generate vertex element and vertex buffer binding if needed.
15163
+ * Upload mesh data to the GPU, generating vertex elements and buffer bindings as needed.
15164
+ * Bounds must be set separately for culling.
15089
15165
  *
15090
15166
  * @param releaseData - Whether to release the data cache, release data can reduce memory usage.
15091
15167
  */ _proto.uploadData = function uploadData(releaseData) {
@@ -19509,7 +19585,7 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
19509
19585
  * Pointer.
19510
19586
  */ var Pointer = /*#__PURE__*/ function() {
19511
19587
  function Pointer(id) {
19512
- /** The phase of pointer. */ this.phase = PointerPhase.Leave;
19588
+ /** The current phase of this pointer. */ this.phase = PointerPhase.Leave;
19513
19589
  /** The position of the pointer in screen space pixel coordinates. */ this.position = new engineMath.Vector2();
19514
19590
  /** The change of the pointer. */ this.deltaPosition = new engineMath.Vector2();
19515
19591
  /** @internal */ this._events = [];
@@ -22988,9 +23064,9 @@ PointerEventEmitter._tempRay = new engineMath.Ray();
22988
23064
  }
22989
23065
  };
22990
23066
  /**
22991
- * Whether the pointer starts to be pressed down during the current frame, if there is no parameter, return whether any pointer starts to be pressed down during the current frame.
22992
- * @param pointerButton - The pointerButton on a pointer device
22993
- * @returns Whether the pointer starts to be pressed down during the current frame
23067
+ * Whether any pointer was pressed this frame.
23068
+ * @param pointerButton - The button to query; omit to include all buttons
23069
+ * @returns The result remains true for the frame, even if a release also occurred
22994
23070
  */ _proto.isPointerDown = function isPointerDown(pointerButton) {
22995
23071
  if (this._initialized) {
22996
23072
  if (pointerButton === undefined) {
@@ -23003,9 +23079,9 @@ PointerEventEmitter._tempRay = new engineMath.Ray();
23003
23079
  }
23004
23080
  };
23005
23081
  /**
23006
- * Whether the pointer is released during the current frame, if there is no parameter, return whether any pointer released during the current frame.
23007
- * @param pointerButton - The pointerButtons on a mouse device
23008
- * @returns Whether the pointer is released during the current frame
23082
+ * Whether any pointer was released this frame.
23083
+ * @param pointerButton - The button to query; omit to include all buttons
23084
+ * @returns The result remains true for the frame, even if a press also occurred
23009
23085
  */ _proto.isPointerUp = function isPointerUp(pointerButton) {
23010
23086
  if (this._initialized) {
23011
23087
  if (pointerButton === undefined) {