@galacean/engine-core 1.4.9 → 1.4.11

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
@@ -10355,7 +10355,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
10355
10355
  };
10356
10356
  _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
10357
10357
  var insMaterial = material.clone();
10358
- insMaterial.name = insMaterial.name + "(Instance)";
10358
+ insMaterial.name = material.name + "(Instance)";
10359
10359
  this._addResourceReferCount(material, -1);
10360
10360
  this._addResourceReferCount(insMaterial, 1);
10361
10361
  this._materialsInstanced[index] = true;
@@ -12334,6 +12334,7 @@ var BufferUtil = /*#__PURE__*/ function() {
12334
12334
  _this = ReferResource.call(this, engine) || this, /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
12335
12335
  , _this._shaderData = new ShaderData(ShaderDataGroup.Material);
12336
12336
  _this.shader = shader;
12337
+ _this.name = shader.name;
12337
12338
  return _this;
12338
12339
  }
12339
12340
  var _proto = Material.prototype;
@@ -12341,7 +12342,7 @@ var BufferUtil = /*#__PURE__*/ function() {
12341
12342
  * Clone and return the instance.
12342
12343
  */ _proto.clone = function clone() {
12343
12344
  var dest = new Material(this._engine, this.shader);
12344
- this.cloneTo(dest);
12345
+ this._cloneToAndModifyName(dest);
12345
12346
  return dest;
12346
12347
  };
12347
12348
  /**
@@ -12358,6 +12359,10 @@ var BufferUtil = /*#__PURE__*/ function() {
12358
12359
  this.shaderData._addReferCount(value);
12359
12360
  this._shader._addReferCount(value);
12360
12361
  };
12362
+ _proto._cloneToAndModifyName = function _cloneToAndModifyName(target) {
12363
+ this.cloneTo(target);
12364
+ target.name = this.name + "(Clone)";
12365
+ };
12361
12366
  /**
12362
12367
  * @override
12363
12368
  */ _proto._onDestroy = function _onDestroy() {
@@ -12513,7 +12518,7 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
12513
12518
  * Clone and return the instance.
12514
12519
  */ _proto.clone = function clone() {
12515
12520
  var dest = new BaseMaterial(this._engine, this.shader);
12516
- this.cloneTo(dest);
12521
+ this._cloneToAndModifyName(dest);
12517
12522
  return dest;
12518
12523
  };
12519
12524
  /**
@@ -12695,7 +12700,7 @@ BaseMaterial._alphaCutoffMacro = ShaderMacro.getByName("MATERIAL_IS_ALPHA_CUTOFF
12695
12700
  var _proto = BlinnPhongMaterial.prototype;
12696
12701
  _proto.clone = function clone() {
12697
12702
  var dest = new BlinnPhongMaterial(this._engine);
12698
- this.cloneTo(dest);
12703
+ this._cloneToAndModifyName(dest);
12699
12704
  return dest;
12700
12705
  };
12701
12706
  _create_class(BlinnPhongMaterial, [
@@ -13155,7 +13160,7 @@ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material
13155
13160
  * @inheritdoc
13156
13161
  */ _proto.clone = function clone() {
13157
13162
  var dest = new PBRMaterial(this._engine);
13158
- this.cloneTo(dest);
13163
+ this._cloneToAndModifyName(dest);
13159
13164
  return dest;
13160
13165
  };
13161
13166
  _proto._onIridescenceRangeChanged = function _onIridescenceRangeChanged() {
@@ -13621,7 +13626,7 @@ PBRMaterial._thicknessTextureProp = ShaderProperty.getByName("material_Thickness
13621
13626
  * @inheritdoc
13622
13627
  */ _proto.clone = function clone() {
13623
13628
  var dest = new PBRSpecularMaterial(this._engine);
13624
- this.cloneTo(dest);
13629
+ this._cloneToAndModifyName(dest);
13625
13630
  return dest;
13626
13631
  };
13627
13632
  _create_class(PBRSpecularMaterial, [
@@ -13694,7 +13699,7 @@ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MAT
13694
13699
  * @inheritdoc
13695
13700
  */ _proto.clone = function clone() {
13696
13701
  var dest = new UnlitMaterial(this._engine);
13697
- this.cloneTo(dest);
13702
+ this._cloneToAndModifyName(dest);
13698
13703
  return dest;
13699
13704
  };
13700
13705
  _create_class(UnlitMaterial, [
@@ -17354,7 +17359,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
17354
17359
  var _this;
17355
17360
  _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._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----------------------------------------------------------------
17356
17361
  _this._invModelMatrix = new engineMath.Matrix();
17357
- _this.name = name;
17362
+ _this.name = name != null ? name : "Entity";
17358
17363
  for(var i = 0, n = components.length; i < n; i++){
17359
17364
  _this.addComponent(components[i]);
17360
17365
  }
@@ -17435,11 +17440,11 @@ var ComponentCloner = /*#__PURE__*/ function() {
17435
17440
  child = indexOrChild;
17436
17441
  }
17437
17442
  if (child._isRoot) {
17438
- child._scene._removeFromEntityList(child);
17443
+ var oldScene = child._scene;
17444
+ Entity._removeFromChildren(oldScene._rootEntities, child);
17439
17445
  child._isRoot = false;
17440
17446
  this._addToChildrenList(index, child);
17441
17447
  child._parent = this;
17442
- var oldScene = child._scene;
17443
17448
  var newScene = this._scene;
17444
17449
  var inActiveChangeFlag = ActiveChangeFlag.None;
17445
17450
  if (!this._isActiveInHierarchy) {
@@ -17644,14 +17649,8 @@ var ComponentCloner = /*#__PURE__*/ function() {
17644
17649
  */ _proto._removeFromParent = function _removeFromParent() {
17645
17650
  var oldParent = this._parent;
17646
17651
  if (oldParent != null) {
17647
- var oldSibling = oldParent._children;
17648
- var index = this._siblingIndex;
17649
- oldSibling.splice(index, 1);
17650
- for(var n = oldSibling.length; index < n; index++){
17651
- oldSibling[index]._siblingIndex--;
17652
- }
17652
+ Entity._removeFromChildren(oldParent._children, this);
17653
17653
  this._parent = null;
17654
- this._siblingIndex = -1;
17655
17654
  this._dispatchModify(EntityModifyFlags.Child, oldParent);
17656
17655
  }
17657
17656
  };
@@ -17697,21 +17696,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
17697
17696
  (_this__modifyFlagManager = this._modifyFlagManager) == null ? void 0 : _this__modifyFlagManager.dispatch(flag, param);
17698
17697
  };
17699
17698
  _proto._addToChildrenList = function _addToChildrenList(index, child) {
17700
- var children = this._children;
17701
- var childCount = children.length;
17702
- if (index === undefined) {
17703
- child._siblingIndex = childCount;
17704
- children.push(child);
17705
- } else {
17706
- if (index < 0 || index > childCount) {
17707
- throw "The index " + index + " is out of child list bounds " + childCount;
17708
- }
17709
- child._siblingIndex = index;
17710
- children.splice(index, 0, child);
17711
- for(var i = index + 1, n = childCount + 1; i < n; i++){
17712
- children[i]._siblingIndex++;
17713
- }
17714
- }
17699
+ Entity._addToChildren(this._children, child, index);
17715
17700
  this._dispatchModify(EntityModifyFlags.Child, this);
17716
17701
  };
17717
17702
  _proto._setParent = function _setParent(parent, siblingIndex) {
@@ -17890,6 +17875,39 @@ var ComponentCloner = /*#__PURE__*/ function() {
17890
17875
  }
17891
17876
  return entity;
17892
17877
  };
17878
+ /**
17879
+ * @internal
17880
+ */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
17881
+ var count = children.length - 1;
17882
+ for(var i = entity._siblingIndex; i < count; i++){
17883
+ var child = children[i + 1];
17884
+ children[i] = child;
17885
+ child._siblingIndex = i;
17886
+ }
17887
+ children.length = count;
17888
+ entity._siblingIndex = -1;
17889
+ };
17890
+ /**
17891
+ * @internal
17892
+ */ Entity._addToChildren = function _addToChildren(children, entity, index) {
17893
+ var childCount = children.length;
17894
+ children.length = childCount + 1;
17895
+ if (index === undefined) {
17896
+ children[childCount] = entity;
17897
+ entity._siblingIndex = childCount;
17898
+ } else {
17899
+ if (index < 0 || index > childCount) {
17900
+ throw "The index " + index + " is out of child list bounds " + childCount;
17901
+ }
17902
+ for(var i = childCount; i > index; i--){
17903
+ var swapChild = children[i - 1];
17904
+ swapChild._siblingIndex = i;
17905
+ children[i] = swapChild;
17906
+ }
17907
+ entity._siblingIndex = index;
17908
+ children[index] = entity;
17909
+ }
17910
+ };
17893
17911
  _create_class(Entity, [
17894
17912
  {
17895
17913
  key: "transform",
@@ -26979,11 +26997,11 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
26979
26997
  var oldScene = entity._scene;
26980
26998
  if (oldScene !== this) {
26981
26999
  if (oldScene && isRoot) {
26982
- oldScene._removeFromEntityList(entity);
27000
+ Entity._removeFromChildren(oldScene._rootEntities, entity);
26983
27001
  }
26984
- this._addToRootEntityList(index, entity);
27002
+ Entity._addToChildren(this._rootEntities, entity, index);
26985
27003
  } else if (!isRoot) {
26986
- this._addToRootEntityList(index, entity);
27004
+ Entity._addToChildren(this._rootEntities, entity, index);
26987
27005
  }
26988
27006
  // Process entity active/inActive
26989
27007
  var inActiveChangeFlag = ActiveChangeFlag.None;
@@ -27010,7 +27028,7 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
27010
27028
  * @param entity - The root entity to remove
27011
27029
  */ _proto.removeRootEntity = function removeRootEntity(entity) {
27012
27030
  if (entity._isRoot && entity._scene == this) {
27013
- this._removeFromEntityList(entity);
27031
+ Entity._removeFromChildren(this._rootEntities, entity);
27014
27032
  entity._isRoot = false;
27015
27033
  var inActiveChangeFlag = ActiveChangeFlag.None;
27016
27034
  this._isActiveInEngine && entity._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
@@ -27109,17 +27127,6 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
27109
27127
  };
27110
27128
  /**
27111
27129
  * @internal
27112
- */ _proto._removeFromEntityList = function _removeFromEntityList(entity) {
27113
- var rootEntities = this._rootEntities;
27114
- var index = entity._siblingIndex;
27115
- rootEntities.splice(index, 1);
27116
- for(var n = rootEntities.length; index < n; index++){
27117
- rootEntities[index]._siblingIndex--;
27118
- }
27119
- entity._siblingIndex = -1;
27120
- };
27121
- /**
27122
- * @internal
27123
27130
  */ _proto._onDestroy = function _onDestroy() {
27124
27131
  EngineObject.prototype._onDestroy.call(this);
27125
27132
  // Remove from sceneManager
@@ -27136,23 +27143,6 @@ PostProcessManager._tempVector3 = new engineMath.Vector3();
27136
27143
  var allCreatedScenes = sceneManager._allCreatedScenes;
27137
27144
  allCreatedScenes.splice(allCreatedScenes.indexOf(this), 1);
27138
27145
  };
27139
- _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
27140
- var rootEntities = this._rootEntities;
27141
- var rootEntityCount = rootEntities.length;
27142
- if (index === undefined) {
27143
- rootEntity._siblingIndex = rootEntityCount;
27144
- rootEntities.push(rootEntity);
27145
- } else {
27146
- if (index < 0 || index > rootEntityCount) {
27147
- throw "The index " + index + " is out of child list bounds " + rootEntityCount;
27148
- }
27149
- rootEntity._siblingIndex = index;
27150
- rootEntities.splice(index, 0, rootEntity);
27151
- for(var i = index + 1, n = rootEntityCount + 1; i < n; i++){
27152
- rootEntities[i]._siblingIndex++;
27153
- }
27154
- }
27155
- };
27156
27146
  _proto._computeLinearFogParams = function _computeLinearFogParams(fogStart, fogEnd) {
27157
27147
  var fogRange = fogEnd - fogStart;
27158
27148
  var fogParams = this._fogParams;
@@ -31211,7 +31201,7 @@ function _assert_this_initialized(self) {
31211
31201
  var _proto = SkyBoxMaterial.prototype;
31212
31202
  _proto.clone = function clone() {
31213
31203
  var dest = new SkyBoxMaterial(this._engine);
31214
- this.cloneTo(dest);
31204
+ this._cloneToAndModifyName(dest);
31215
31205
  return dest;
31216
31206
  };
31217
31207
  _create_class(SkyBoxMaterial, [
@@ -31317,7 +31307,7 @@ SkyBoxMaterial._decodeSkyRGBMMacro = ShaderMacro.getByName("MATERIAL_IS_DECODE_S
31317
31307
  * @inheritDoc
31318
31308
  */ _proto.clone = function clone() {
31319
31309
  var dest = new SkyProceduralMaterial(this._engine);
31320
- this.cloneTo(dest);
31310
+ this._cloneToAndModifyName(dest);
31321
31311
  return dest;
31322
31312
  };
31323
31313
  _create_class(SkyProceduralMaterial, [
@@ -32218,6 +32208,13 @@ __decorate([
32218
32208
  return this.constant;
32219
32209
  case ParticleCurveMode.TwoConstants:
32220
32210
  return this.constantMin + (this.constantMax - this.constantMin) * lerpFactor;
32211
+ case ParticleCurveMode.Curve:
32212
+ var _this_curve;
32213
+ return (_this_curve = this.curve) == null ? void 0 : _this_curve._evaluate(time);
32214
+ case ParticleCurveMode.TwoCurves:
32215
+ var _this_curveMin, _this_curveMax;
32216
+ var min = (_this_curveMin = this.curveMin) == null ? void 0 : _this_curveMin._evaluate(time);
32217
+ return min + (((_this_curveMax = this.curveMax) == null ? void 0 : _this_curveMax._evaluate(time)) - min) * lerpFactor;
32221
32218
  }
32222
32219
  };
32223
32220
  /**
@@ -33056,9 +33053,10 @@ __decorate([
33056
33053
  * Remove a key from the curve.
33057
33054
  * @param index - The remove key index
33058
33055
  */ _proto.removeKey = function removeKey(index) {
33059
- this._keys.splice(index, 1);
33056
+ var keys = this._keys;
33057
+ var removeKey = keys[index];
33058
+ keys.splice(index, 1);
33060
33059
  this._typeArrayDirty = true;
33061
- var removeKey = this._keys[index];
33062
33060
  removeKey._unRegisterOnValueChanged(this._updateDispatch);
33063
33061
  this._updateDispatch();
33064
33062
  };
@@ -33074,6 +33072,29 @@ __decorate([
33074
33072
  };
33075
33073
  /**
33076
33074
  * @internal
33075
+ */ _proto._evaluate = function _evaluate(normalizedAge) {
33076
+ var keys = this.keys;
33077
+ var length = keys.length;
33078
+ for(var i = 0; i < length; i++){
33079
+ var key = keys[i];
33080
+ var time = key.time;
33081
+ if (normalizedAge <= time) {
33082
+ if (i === 0) {
33083
+ // Small than first key
33084
+ return key.value;
33085
+ } else {
33086
+ // Between two keys
33087
+ var _keys_ = keys[i - 1], lastTime = _keys_.time, lastValue = _keys_.value;
33088
+ var age = (normalizedAge - lastTime) / (time - lastTime);
33089
+ return lastValue + (key.value - lastValue) * age;
33090
+ }
33091
+ }
33092
+ }
33093
+ // Large than last key
33094
+ return keys[length - 1].value;
33095
+ };
33096
+ /**
33097
+ * @internal
33077
33098
  */ _proto._getTypeArray = function _getTypeArray() {
33078
33099
  var typeArray = this._typeArray || (this._typeArray = new Float32Array(4 * 2));
33079
33100
  if (this._typeArrayDirty) {
@@ -33685,7 +33706,7 @@ __decorate([
33685
33706
  };
33686
33707
  /**
33687
33708
  * @internal
33688
- */ _proto._emit = function _emit(time, count) {
33709
+ */ _proto._emit = function _emit(playTime, count) {
33689
33710
  if (this.emission.enabled) {
33690
33711
  // Wait the existing particles to be retired
33691
33712
  var notRetireParticleCount = this._getNotRetiredParticleCount();
@@ -33698,7 +33719,7 @@ __decorate([
33698
33719
  var shape = this.emission.shape;
33699
33720
  for(var i = 0; i < count; i++){
33700
33721
  if (shape == null ? void 0 : shape.enabled) {
33701
- shape._generatePositionAndDirection(this.emission._shapeRand, time, position, direction);
33722
+ shape._generatePositionAndDirection(this.emission._shapeRand, playTime, position, direction);
33702
33723
  var positionScale = this.main._getPositionScale();
33703
33724
  position.multiply(positionScale);
33704
33725
  direction.normalize().multiply(positionScale);
@@ -33706,7 +33727,7 @@ __decorate([
33706
33727
  position.set(0, 0, 0);
33707
33728
  direction.set(0, 0, -1);
33708
33729
  }
33709
- this._addNewParticle(position, direction, transform, time);
33730
+ this._addNewParticle(position, direction, transform, playTime);
33710
33731
  }
33711
33732
  }
33712
33733
  };
@@ -34021,7 +34042,7 @@ __decorate([
34021
34042
  this._transformedBoundsArray[previousFreeElement * ParticleBufferUtils.boundsFloatStride + boundsTimeOffset] = this._playTime;
34022
34043
  }
34023
34044
  };
34024
- _proto._addNewParticle = function _addNewParticle(position, direction, transform, time) {
34045
+ _proto._addNewParticle = function _addNewParticle(position, direction, transform, playTime) {
34025
34046
  var firstFreeElement = this._firstFreeElement;
34026
34047
  var nextFreeElement = firstFreeElement + 1;
34027
34048
  if (nextFreeElement >= this._currentParticleCount) {
@@ -34051,35 +34072,30 @@ __decorate([
34051
34072
  var instanceVertices = this._instanceVertices;
34052
34073
  var offset = firstFreeElement * ParticleBufferUtils.instanceVertexFloatStride;
34053
34074
  // Position
34054
- instanceVertices[offset] = position.x;
34055
- instanceVertices[offset + 1] = position.y;
34056
- instanceVertices[offset + 2] = position.z;
34075
+ position.copyToArray(instanceVertices, offset);
34057
34076
  // Start life time
34058
34077
  instanceVertices[offset + ParticleBufferUtils.startLifeTimeOffset] = main.startLifetime.evaluate(undefined, main._startLifeTimeRand.random());
34059
34078
  // Direction
34060
- instanceVertices[offset + 4] = direction.x;
34061
- instanceVertices[offset + 5] = direction.y;
34062
- instanceVertices[offset + 6] = direction.z;
34079
+ direction.copyToArray(instanceVertices, offset + 4);
34063
34080
  // Time
34064
- instanceVertices[offset + ParticleBufferUtils.timeOffset] = time;
34081
+ instanceVertices[offset + ParticleBufferUtils.timeOffset] = playTime;
34065
34082
  // Color
34066
34083
  var startColor = ParticleGenerator._tempColor0;
34067
34084
  main.startColor.evaluate(undefined, main._startColorRand.random(), startColor);
34068
34085
  if (this._renderer.engine.settings.colorSpace === ColorSpace.Linear) {
34069
34086
  startColor.toLinear(startColor);
34070
34087
  }
34071
- instanceVertices[offset + 8] = startColor.r;
34072
- instanceVertices[offset + 9] = startColor.g;
34073
- instanceVertices[offset + 10] = startColor.b;
34074
- instanceVertices[offset + 11] = startColor.a;
34088
+ startColor.copyToArray(instanceVertices, offset + 8);
34089
+ var duration = this.main.duration;
34090
+ var normalizedEmitAge = playTime % duration / duration;
34075
34091
  // Start size
34076
34092
  var startSizeRand = main._startSizeRand;
34077
34093
  if (main.startSize3D) {
34078
- instanceVertices[offset + 12] = main.startSizeX.evaluate(undefined, startSizeRand.random());
34079
- instanceVertices[offset + 13] = main.startSizeY.evaluate(undefined, startSizeRand.random());
34080
- instanceVertices[offset + 14] = main.startSizeZ.evaluate(undefined, startSizeRand.random());
34094
+ instanceVertices[offset + 12] = main.startSizeX.evaluate(normalizedEmitAge, startSizeRand.random());
34095
+ instanceVertices[offset + 13] = main.startSizeY.evaluate(normalizedEmitAge, startSizeRand.random());
34096
+ instanceVertices[offset + 14] = main.startSizeZ.evaluate(normalizedEmitAge, startSizeRand.random());
34081
34097
  } else {
34082
- var size = main.startSize.evaluate(undefined, startSizeRand.random());
34098
+ var size = main.startSize.evaluate(normalizedEmitAge, startSizeRand.random());
34083
34099
  instanceVertices[offset + 12] = size;
34084
34100
  instanceVertices[offset + 13] = size;
34085
34101
  instanceVertices[offset + 14] = size;
@@ -34132,14 +34148,9 @@ __decorate([
34132
34148
  }
34133
34149
  if (this.main.simulationSpace === ParticleSimulationSpace.World) {
34134
34150
  // Simulation world position
34135
- instanceVertices[offset + 27] = pos.x;
34136
- instanceVertices[offset + 28] = pos.y;
34137
- instanceVertices[offset + 29] = pos.z;
34151
+ pos.copyToArray(instanceVertices, offset + 27);
34138
34152
  // Simulation world position
34139
- instanceVertices[offset + 30] = rot.x;
34140
- instanceVertices[offset + 31] = rot.y;
34141
- instanceVertices[offset + 32] = rot.z;
34142
- instanceVertices[offset + 33] = rot.w;
34153
+ rot.copyToArray(instanceVertices, offset + 30);
34143
34154
  }
34144
34155
  // Simulation UV
34145
34156
  if (textureSheetAnimation.enabled) {
@@ -34509,7 +34520,7 @@ __decorate([
34509
34520
  * @inheritdoc
34510
34521
  */ _proto.clone = function clone() {
34511
34522
  var dest = new ParticleMaterial(this._engine);
34512
- this.cloneTo(dest);
34523
+ this._cloneToAndModifyName(dest);
34513
34524
  return dest;
34514
34525
  };
34515
34526
  _create_class(ParticleMaterial, [