@galacean/effects-core 2.1.0-alpha.2 → 2.1.0-alpha.4

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/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.1.0-alpha.2
6
+ * Version: v2.1.0-alpha.4
7
7
  */
8
8
 
9
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -4251,6 +4251,9 @@ var MaterialBlending;
4251
4251
  /**
4252
4252
  * 自发光
4253
4253
  */ RenderMode3D["emissive"] = "emissive";
4254
+ /**
4255
+ * 漫反射
4256
+ */ RenderMode3D["diffuse"] = "diffuse";
4254
4257
  })(RenderMode3D || (RenderMode3D = {}));
4255
4258
 
4256
4259
  var TextOverflow;
@@ -10303,10 +10306,11 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10303
10306
  timeEnd: Number(e.x)
10304
10307
  };
10305
10308
  }
10309
+ this.keyTimeData = Object.keys(this.curveMap);
10306
10310
  };
10307
10311
  _proto.getValue = function getValue(time) {
10308
10312
  var result = 0;
10309
- var keyTimeData = Object.keys(this.curveMap);
10313
+ var keyTimeData = this.keyTimeData;
10310
10314
  var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10311
10315
  var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
10312
10316
  // const keyTimeStart = Number(keyTimeData[0].split('&')[0]);
@@ -13601,25 +13605,25 @@ function _assert_this_initialized(self) {
13601
13605
  }
13602
13606
  var _proto = PlayableGraph.prototype;
13603
13607
  _proto.evaluate = function evaluate(dt) {
13604
- // 初始化节点状态
13605
- for(var _iterator = _create_for_of_iterator_helper_loose(this.playables), _step; !(_step = _iterator()).done;){
13606
- var playable = _step.value;
13607
- this.updatePlayableTime(playable, dt);
13608
- }
13609
13608
  // 初始化输出节点状态
13610
- for(var _iterator1 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step1; !(_step1 = _iterator1()).done;){
13611
- var playableOutput = _step1.value;
13609
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.playableOutputs), _step; !(_step = _iterator()).done;){
13610
+ var playableOutput = _step.value;
13612
13611
  playableOutput.context.deltaTime = dt;
13613
13612
  }
13614
13613
  // 执行生命周期函数
13615
- for(var _iterator2 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step2; !(_step2 = _iterator2()).done;){
13616
- var playableOutput1 = _step2.value;
13614
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step1; !(_step1 = _iterator1()).done;){
13615
+ var playableOutput1 = _step1.value;
13617
13616
  this.prepareFrameWithRoot(playableOutput1);
13618
13617
  }
13619
- for(var _iterator3 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step3; !(_step3 = _iterator3()).done;){
13620
- var playableOutput2 = _step3.value;
13618
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step2; !(_step2 = _iterator2()).done;){
13619
+ var playableOutput2 = _step2.value;
13621
13620
  this.processFrameWithRoot(playableOutput2);
13622
13621
  }
13622
+ // 更新节点时间
13623
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(this.playables), _step3; !(_step3 = _iterator3()).done;){
13624
+ var playable = _step3.value;
13625
+ this.updatePlayableTime(playable, dt);
13626
+ }
13623
13627
  };
13624
13628
  _proto.connect = function connect(source, sourceOutputPort, destination, destinationInputPort) {
13625
13629
  destination.connectInput(destinationInputPort, source, sourceOutputPort);
@@ -13642,11 +13646,7 @@ function _assert_this_initialized(self) {
13642
13646
  if (playable.getPlayState() !== 0) {
13643
13647
  return;
13644
13648
  }
13645
- if (playable.overrideTimeNextEvaluation) {
13646
- playable.overrideTimeNextEvaluation = false;
13647
- } else {
13648
- playable.setTime(playable.getTime() + deltaTime);
13649
- }
13649
+ playable.setTime(playable.getTime() + deltaTime);
13650
13650
  };
13651
13651
  return PlayableGraph;
13652
13652
  }();
@@ -13658,7 +13658,6 @@ function _assert_this_initialized(self) {
13658
13658
  if (inputCount === void 0) inputCount = 0;
13659
13659
  this.onPlayablePlayFlag = true;
13660
13660
  this.onPlayablePauseFlag = false;
13661
- this.overrideTimeNextEvaluation = false;
13662
13661
  this.destroyed = false;
13663
13662
  this.inputs = [];
13664
13663
  this.inputOuputPorts = [];
@@ -13747,7 +13746,6 @@ function _assert_this_initialized(self) {
13747
13746
  };
13748
13747
  _proto.setTime = function setTime(time) {
13749
13748
  this.time = time;
13750
- this.overrideTimeNextEvaluation = true;
13751
13749
  };
13752
13750
  _proto.getTime = function getTime() {
13753
13751
  return this.time;
@@ -16550,8 +16548,9 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16550
16548
  };
16551
16549
  _proto.onUpdate = function onUpdate(dt) {
16552
16550
  var time = this.particleMesh.time;
16553
- this.particleMesh.mesh.material.setVector4("uParams", new Vector4(time, this.item.duration, 0, 0));
16554
- this.particleMesh.onUpdate(dt);
16551
+ var _this_particleMesh_mesh_material_getVector4;
16552
+ var uParams = (_this_particleMesh_mesh_material_getVector4 = this.particleMesh.mesh.material.getVector4("uParams")) != null ? _this_particleMesh_mesh_material_getVector4 : new Vector4();
16553
+ this.particleMesh.mesh.material.setVector4("uParams", uParams.set(time, this.item.duration, 0, 0));
16555
16554
  };
16556
16555
  _proto.render = function render(renderer) {
16557
16556
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
@@ -16566,7 +16565,7 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16566
16565
  };
16567
16566
  _proto.updateTime = function updateTime(now, delta) {
16568
16567
  this.particleMesh.time = now;
16569
- // this.particleMesh.onUpdate(delta);
16568
+ this.particleMesh.onUpdate(delta);
16570
16569
  if (this.trailMesh) {
16571
16570
  this.trailMesh.time = now;
16572
16571
  this.trailMesh.onUpdate(delta);
@@ -16860,7 +16859,7 @@ var ParticleSystem = /*#__PURE__*/ function(Component) {
16860
16859
  break;
16861
16860
  }
16862
16861
  var burst = bursts[j];
16863
- var opts = burst.getGeneratorOptions(timePassed, lifetime);
16862
+ var opts = !burst.disabled && burst.getGeneratorOptions(timePassed, lifetime);
16864
16863
  if (opts) {
16865
16864
  var originVec = [
16866
16865
  0,
@@ -16869,6 +16868,9 @@ var ParticleSystem = /*#__PURE__*/ function(Component) {
16869
16868
  ];
16870
16869
  var offsets = emission.burstOffsets[j];
16871
16870
  var burstOffset = offsets && offsets[opts.cycleIndex] || originVec;
16871
+ if (burst.once) {
16872
+ this.removeBurst(j);
16873
+ }
16872
16874
  for(var i1 = 0; i1 < opts.count && cursor < maxCount; i1++){
16873
16875
  var _p_transform;
16874
16876
  if (shouldSkipGenerate()) {
@@ -17673,12 +17675,10 @@ var particleUniformTypeMap = {
17673
17675
  var ParticleMesh = /*#__PURE__*/ function() {
17674
17676
  function ParticleMesh(engine, props) {
17675
17677
  this.particleCount = 0;
17676
- this.cachedVelocity = new Vector3();
17677
17678
  this.cachedRotationVector3 = new Vector3();
17678
17679
  this.cachedRotationMatrix = new Matrix3();
17679
17680
  this.cachedLinearMove = new Vector3();
17680
17681
  this.tempMatrix3 = new Matrix3();
17681
- this.tempVector3 = new Vector3();
17682
17682
  this.VERT_MAX_KEY_FRAME_COUNT = 0;
17683
17683
  var _engine_renderer;
17684
17684
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
@@ -18074,72 +18074,10 @@ var ParticleMesh = /*#__PURE__*/ function() {
18074
18074
  };
18075
18075
  _proto.onUpdate = function onUpdate(dt) {
18076
18076
  var aPosArray = this.geometry.getAttributeData("aPos"); // vector3
18077
- var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18078
- var aOffsetArray = this.geometry.getAttributeData("aOffset");
18079
- var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18080
- var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18081
- // const uParams = this.mesh.material.getVector4('uParams');
18082
- // if (!uParams) {
18083
- // return;
18084
- // }
18085
- var localTime = this.time;
18086
- var particleCount = Math.ceil(aPosArray.length / 12);
18087
- // calculate particle translation
18088
- var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18089
- if (aTranslationArray.length < particleCount * 3) {
18090
- aTranslationArray = this.expandArray(aTranslationArray, particleCount * 3);
18091
- }
18092
- var velocity = this.cachedVelocity;
18093
- for(var i = 0; i < particleCount; i++){
18094
- var velOffset = i * 12 + 3;
18095
- velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18096
- this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18097
- var aTranslationOffset = i * 3;
18098
- if (aOffsetArray[i * 4 + 2] < localTime) {
18099
- var translation = velocity.multiply(dt / 1000);
18100
- aTranslationArray[aTranslationOffset] += translation.x;
18101
- aTranslationArray[aTranslationOffset + 1] += translation.y;
18102
- aTranslationArray[aTranslationOffset + 2] += translation.z;
18103
- }
18104
- }
18105
- this.geometry.setAttributeData("aTranslation", aTranslationArray);
18106
- // calculate particle rotation
18107
- var aRotationArray = this.geometry.getAttributeData("aRotation0");
18108
- if (aRotationArray.length < particleCount * 9) {
18109
- aRotationArray = this.expandArray(aRotationArray, particleCount * 9);
18110
- }
18111
- for(var i1 = 0; i1 < particleCount; i1++){
18112
- var time = localTime - aOffsetArray[i1 * 4 + 2];
18113
- var duration = aOffsetArray[i1 * 4 + 3];
18114
- var life = clamp$1(time / duration, 0.0, 1.0);
18115
- var aRotOffset = i1 * 8;
18116
- var aRot = this.cachedRotationVector3.set(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18117
- var aSeed = aSeedArray[i1 * 8 + 3];
18118
- var aRotation = this.transformFromRotation(aRot, life, duration, aSeed, this.cachedRotationMatrix);
18119
- var aRotationOffset = i1 * 9;
18120
- var matrixArray = aRotation.toArray();
18121
- aRotationArray.set(matrixArray, aRotationOffset);
18122
- }
18123
- this.geometry.setAttributeData("aRotation0", aRotationArray);
18124
- // calculate linear movement
18125
- var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18126
- if (aLinearMoveArray.length < particleCount * 3) {
18127
- aLinearMoveArray = this.expandArray(aLinearMoveArray, particleCount * 3);
18128
- }
18129
- var linearMove = this.cachedLinearMove;
18130
- for(var i2 = 0; i2 < particleCount; i2++){
18131
- var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18132
- var duration1 = aOffsetArray[i2 * 4 + 3];
18133
- // const life = math.clamp(time / duration, 0.0, 1.0);
18134
- var aSeed1 = aSeedArray[i2 * 8 + 3];
18135
- linearMove.setZero();
18136
- this.calLinearMov(time1, duration1, aSeed1, linearMove);
18137
- var aLinearMoveOffset = i2 * 3;
18138
- aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18139
- aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18140
- aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18141
- }
18142
- this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18077
+ var vertexCount = Math.ceil(aPosArray.length / 12);
18078
+ this.applyTranslation(vertexCount, dt);
18079
+ this.applyRotation(vertexCount, dt);
18080
+ this.applyLinearMove(vertexCount, dt);
18143
18081
  };
18144
18082
  _proto.minusTime = function minusTime(time) {
18145
18083
  var aOffset = this.geometry.getAttributeData("aOffset");
@@ -18149,153 +18087,6 @@ var ParticleMesh = /*#__PURE__*/ function() {
18149
18087
  this.geometry.setAttributeData("aOffset", aOffset);
18150
18088
  this.time -= time;
18151
18089
  };
18152
- _proto.calculateTranslation = function calculateTranslation(velocity, t0, t1, duration) {
18153
- var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18154
- var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18155
- if (!uAcceleration || !uGravityModifierValue) {
18156
- return velocity;
18157
- }
18158
- var dt = t1 - t0; // 相对delay的时间
18159
- var d = this.gravityModifier.getIntegrateValue(0, dt, duration);
18160
- var acc = this.tempVector3.set(uAcceleration.x * d, uAcceleration.y * d, uAcceleration.z * d);
18161
- // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18162
- if (this.speedOverLifetime) {
18163
- // dt / dur 归一化
18164
- var speed = this.speedOverLifetime.getValue(dt / duration);
18165
- return velocity.multiply(speed).add(acc);
18166
- }
18167
- return velocity.add(acc);
18168
- };
18169
- _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed, result) {
18170
- var rotation = rot;
18171
- if (!this.rotationOverLifetime) {
18172
- return result.setZero();
18173
- }
18174
- if (this.rotationOverLifetime.asRotation) {
18175
- // Adjust rotation based on the specified lifetime components
18176
- if (this.rotationOverLifetime.x) {
18177
- if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18178
- rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18179
- } else {
18180
- rotation.x += this.rotationOverLifetime.x.getValue(life);
18181
- }
18182
- }
18183
- if (this.rotationOverLifetime.y) {
18184
- if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18185
- rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18186
- } else {
18187
- rotation.y += this.rotationOverLifetime.y.getValue(life);
18188
- }
18189
- }
18190
- if (this.rotationOverLifetime.z) {
18191
- if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18192
- rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18193
- } else {
18194
- rotation.z += this.rotationOverLifetime.z.getValue(life);
18195
- }
18196
- }
18197
- } else {
18198
- // Adjust rotation based on the specified lifetime components
18199
- if (this.rotationOverLifetime.x) {
18200
- if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18201
- rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * dur;
18202
- } else {
18203
- rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, dur) * dur;
18204
- }
18205
- }
18206
- if (this.rotationOverLifetime.y) {
18207
- if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18208
- rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * dur;
18209
- } else {
18210
- rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, dur) * dur;
18211
- }
18212
- }
18213
- if (this.rotationOverLifetime.z) {
18214
- if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18215
- rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * dur;
18216
- } else {
18217
- rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, dur) * dur;
18218
- }
18219
- }
18220
- }
18221
- // If the rotation vector is zero, return the identity matrix
18222
- if (rotation.dot(rotation) === 0.0) {
18223
- return result.identity();
18224
- }
18225
- // Return the rotation matrix derived from the rotation vector
18226
- return this.mat3FromRotation(rotation, result);
18227
- };
18228
- _proto.mat3FromRotation = function mat3FromRotation(rotation, result) {
18229
- var d2r = Math.PI / 180;
18230
- var rotationXD2r = rotation.x * d2r;
18231
- var rotationYD2r = rotation.y * d2r;
18232
- var rotationZD2r = rotation.z * d2r;
18233
- var sinRX = Math.sin(rotationXD2r);
18234
- var sinRY = Math.sin(rotationYD2r);
18235
- var sinRZ = Math.sin(rotationZD2r);
18236
- var cosRX = Math.cos(rotationXD2r);
18237
- var cosRY = Math.cos(rotationYD2r);
18238
- var cosRZ = Math.cos(rotationZD2r);
18239
- // rotZ * rotY * rotX
18240
- result.set(cosRZ, -sinRZ, 0., sinRZ, cosRZ, 0., 0., 0., 1.); //rotZ
18241
- result.multiply(this.tempMatrix3.set(cosRY, 0., sinRY, 0., 1., 0., -sinRY, 0, cosRY)); //rotY
18242
- result.multiply(this.tempMatrix3.set(1., 0., 0., 0, cosRX, -sinRX, 0., sinRX, cosRX)); //rotX
18243
- return result;
18244
- };
18245
- _proto.calLinearMov = function calLinearMov(time, duration, aSeed, result) {
18246
- var mov = result;
18247
- var lifetime = time / duration;
18248
- if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18249
- return mov;
18250
- }
18251
- if (this.linearVelOverLifetime.asMovement) {
18252
- if (this.linearVelOverLifetime.x) {
18253
- if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18254
- mov.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18255
- } else {
18256
- mov.x = this.linearVelOverLifetime.x.getValue(lifetime);
18257
- }
18258
- }
18259
- if (this.linearVelOverLifetime.y) {
18260
- if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18261
- mov.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18262
- } else {
18263
- mov.y = this.linearVelOverLifetime.y.getValue(lifetime);
18264
- }
18265
- }
18266
- if (this.linearVelOverLifetime.z) {
18267
- if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18268
- mov.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18269
- } else {
18270
- mov.z = this.linearVelOverLifetime.z.getValue(lifetime);
18271
- }
18272
- }
18273
- } else {
18274
- // Adjust rotation based on the specified lifetime components
18275
- if (this.linearVelOverLifetime.x) {
18276
- if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18277
- mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18278
- } else {
18279
- mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18280
- }
18281
- }
18282
- if (this.linearVelOverLifetime.y) {
18283
- if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18284
- mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18285
- } else {
18286
- mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18287
- }
18288
- }
18289
- if (this.linearVelOverLifetime.z) {
18290
- if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18291
- mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18292
- } else {
18293
- mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18294
- }
18295
- }
18296
- }
18297
- return mov;
18298
- };
18299
18090
  _proto.removePoint = function removePoint(index) {
18300
18091
  if (index < this.particleCount) {
18301
18092
  this.geometry.setAttributeSubData("aOffset", index * 16, new Float32Array(16));
@@ -18429,6 +18220,247 @@ var ParticleMesh = /*#__PURE__*/ function() {
18429
18220
  geometry.setDrawCount(this.particleCount * 6);
18430
18221
  }
18431
18222
  };
18223
+ _proto.applyTranslation = function applyTranslation(vertexCount, deltaTime) {
18224
+ var localTime = this.time;
18225
+ var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18226
+ var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18227
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18228
+ if (aTranslationArray.length < vertexCount * 3) {
18229
+ aTranslationArray = this.expandArray(aTranslationArray, vertexCount * 3);
18230
+ }
18231
+ // const velocity = this.cachedVelocity;
18232
+ var velocityX = 0;
18233
+ var velocityY = 0;
18234
+ var velocityZ = 0;
18235
+ var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18236
+ var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18237
+ for(var i = 0; i < vertexCount; i += 4){
18238
+ var velOffset = i * 12 + 3;
18239
+ velocityX = aVelArray[velOffset];
18240
+ velocityY = aVelArray[velOffset + 1];
18241
+ velocityZ = aVelArray[velOffset + 2];
18242
+ // velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18243
+ var dt = localTime - aOffsetArray[i * 4 + 2]; // 相对delay的时间
18244
+ var duration = aOffsetArray[i * 4 + 3];
18245
+ if (uAcceleration && uGravityModifierValue) {
18246
+ var d = this.gravityModifier.getIntegrateValue(0, dt, duration);
18247
+ // const acc = this.tempVector3.set(uAcceleration.x * d, uAcceleration.y * d, uAcceleration.z * d);
18248
+ var accX = uAcceleration.x * d;
18249
+ var accY = uAcceleration.y * d;
18250
+ var accZ = uAcceleration.z * d;
18251
+ // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18252
+ if (this.speedOverLifetime) {
18253
+ // dt / dur 归一化
18254
+ var speed = this.speedOverLifetime.getValue(dt / duration);
18255
+ velocityX = velocityX * speed + accX;
18256
+ velocityY = velocityY * speed + accY;
18257
+ velocityZ = velocityZ * speed + accZ;
18258
+ // velocity.multiply(speed).add(acc);
18259
+ } else {
18260
+ velocityX = velocityX + accX;
18261
+ velocityY = velocityY + accY;
18262
+ velocityZ = velocityZ + accZ;
18263
+ // velocity.add(acc);
18264
+ }
18265
+ }
18266
+ var aTranslationOffset = i * 3;
18267
+ if (aOffsetArray[i * 4 + 2] < localTime) {
18268
+ // const translation = velocity.multiply(deltaTime / 1000);
18269
+ var aTranslationX = velocityX * (deltaTime / 1000);
18270
+ var aTranslationY = velocityY * (deltaTime / 1000);
18271
+ var aTranslationZ = velocityZ * (deltaTime / 1000);
18272
+ aTranslationArray[aTranslationOffset] += aTranslationX;
18273
+ aTranslationArray[aTranslationOffset + 1] += aTranslationY;
18274
+ aTranslationArray[aTranslationOffset + 2] += aTranslationZ;
18275
+ aTranslationArray[aTranslationOffset + 3] += aTranslationX;
18276
+ aTranslationArray[aTranslationOffset + 4] += aTranslationY;
18277
+ aTranslationArray[aTranslationOffset + 5] += aTranslationZ;
18278
+ aTranslationArray[aTranslationOffset + 6] += aTranslationX;
18279
+ aTranslationArray[aTranslationOffset + 7] += aTranslationY;
18280
+ aTranslationArray[aTranslationOffset + 8] += aTranslationZ;
18281
+ aTranslationArray[aTranslationOffset + 9] += aTranslationX;
18282
+ aTranslationArray[aTranslationOffset + 10] += aTranslationY;
18283
+ aTranslationArray[aTranslationOffset + 11] += aTranslationZ;
18284
+ }
18285
+ }
18286
+ this.geometry.setAttributeData("aTranslation", aTranslationArray);
18287
+ };
18288
+ _proto.applyRotation = function applyRotation(vertexCount, deltaTime) {
18289
+ var aRotationArray = this.geometry.getAttributeData("aRotation0");
18290
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18291
+ var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18292
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18293
+ var localTime = this.time;
18294
+ var aRotationMatrix = this.cachedRotationMatrix;
18295
+ if (aRotationArray.length < vertexCount * 9) {
18296
+ aRotationArray = this.expandArray(aRotationArray, vertexCount * 9);
18297
+ }
18298
+ for(var i = 0; i < vertexCount; i += 4){
18299
+ var time = localTime - aOffsetArray[i * 4 + 2];
18300
+ var duration = aOffsetArray[i * 4 + 3];
18301
+ var life = clamp$1(time / duration, 0.0, 1.0);
18302
+ var aRotOffset = i * 8;
18303
+ var aRot = this.cachedRotationVector3.set(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18304
+ var aSeed = aSeedArray[i * 8 + 3];
18305
+ var rotation = aRot;
18306
+ if (!this.rotationOverLifetime) {
18307
+ aRotationMatrix.setZero();
18308
+ } else if (this.rotationOverLifetime.asRotation) {
18309
+ // Adjust rotation based on the specified lifetime components
18310
+ if (this.rotationOverLifetime.x) {
18311
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18312
+ rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18313
+ } else {
18314
+ rotation.x += this.rotationOverLifetime.x.getValue(life);
18315
+ }
18316
+ }
18317
+ if (this.rotationOverLifetime.y) {
18318
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18319
+ rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18320
+ } else {
18321
+ rotation.y += this.rotationOverLifetime.y.getValue(life);
18322
+ }
18323
+ }
18324
+ if (this.rotationOverLifetime.z) {
18325
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18326
+ rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18327
+ } else {
18328
+ rotation.z += this.rotationOverLifetime.z.getValue(life);
18329
+ }
18330
+ }
18331
+ } else {
18332
+ // Adjust rotation based on the specified lifetime components
18333
+ if (this.rotationOverLifetime.x) {
18334
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18335
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * duration;
18336
+ } else {
18337
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, duration) * duration;
18338
+ }
18339
+ }
18340
+ if (this.rotationOverLifetime.y) {
18341
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18342
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * duration;
18343
+ } else {
18344
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, duration) * duration;
18345
+ }
18346
+ }
18347
+ if (this.rotationOverLifetime.z) {
18348
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18349
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * duration;
18350
+ } else {
18351
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, duration) * duration;
18352
+ }
18353
+ }
18354
+ }
18355
+ // If the rotation vector is zero, return the identity matrix
18356
+ if (rotation.dot(rotation) === 0.0) {
18357
+ aRotationMatrix.identity();
18358
+ }
18359
+ var d2r = Math.PI / 180;
18360
+ var rotationXD2r = rotation.x * d2r;
18361
+ var rotationYD2r = rotation.y * d2r;
18362
+ var rotationZD2r = rotation.z * d2r;
18363
+ var sinRX = Math.sin(rotationXD2r);
18364
+ var sinRY = Math.sin(rotationYD2r);
18365
+ var sinRZ = Math.sin(rotationZD2r);
18366
+ var cosRX = Math.cos(rotationXD2r);
18367
+ var cosRY = Math.cos(rotationYD2r);
18368
+ var cosRZ = Math.cos(rotationZD2r);
18369
+ // rotZ * rotY * rotX
18370
+ aRotationMatrix.set(cosRZ, -sinRZ, 0., sinRZ, cosRZ, 0., 0., 0., 1.); //rotZ
18371
+ aRotationMatrix.multiply(this.tempMatrix3.set(cosRY, 0., sinRY, 0., 1., 0., -sinRY, 0, cosRY)); //rotY
18372
+ aRotationMatrix.multiply(this.tempMatrix3.set(1., 0., 0., 0, cosRX, -sinRX, 0., sinRX, cosRX)); //rotX
18373
+ var aRotationOffset = i * 9;
18374
+ var matrixArray = aRotationMatrix.elements;
18375
+ aRotationArray.set(matrixArray, aRotationOffset);
18376
+ if (i + 4 <= vertexCount) {
18377
+ aRotationArray.set(matrixArray, aRotationOffset + 9);
18378
+ aRotationArray.set(matrixArray, aRotationOffset + 18);
18379
+ aRotationArray.set(matrixArray, aRotationOffset + 27);
18380
+ }
18381
+ }
18382
+ this.geometry.setAttributeData("aRotation0", aRotationArray);
18383
+ };
18384
+ _proto.applyLinearMove = function applyLinearMove(vertexCount, deltaTime) {
18385
+ var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18386
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18387
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18388
+ var localTime = this.time;
18389
+ if (aLinearMoveArray.length < vertexCount * 3) {
18390
+ aLinearMoveArray = this.expandArray(aLinearMoveArray, vertexCount * 3);
18391
+ }
18392
+ var linearMove = this.cachedLinearMove;
18393
+ if (this.linearVelOverLifetime && this.linearVelOverLifetime.enabled) {
18394
+ for(var i = 0; i < vertexCount; i += 4){
18395
+ var time = localTime - aOffsetArray[i * 4 + 2];
18396
+ var duration = aOffsetArray[i * 4 + 3];
18397
+ // const life = math.clamp(time / duration, 0.0, 1.0);
18398
+ var lifetime = time / duration;
18399
+ var aSeed = aSeedArray[i * 8 + 3];
18400
+ linearMove.setZero();
18401
+ if (this.linearVelOverLifetime.asMovement) {
18402
+ if (this.linearVelOverLifetime.x) {
18403
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18404
+ linearMove.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18405
+ } else {
18406
+ linearMove.x = this.linearVelOverLifetime.x.getValue(lifetime);
18407
+ }
18408
+ }
18409
+ if (this.linearVelOverLifetime.y) {
18410
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18411
+ linearMove.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18412
+ } else {
18413
+ linearMove.y = this.linearVelOverLifetime.y.getValue(lifetime);
18414
+ }
18415
+ }
18416
+ if (this.linearVelOverLifetime.z) {
18417
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18418
+ linearMove.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18419
+ } else {
18420
+ linearMove.z = this.linearVelOverLifetime.z.getValue(lifetime);
18421
+ }
18422
+ }
18423
+ } else {
18424
+ // Adjust rotation based on the specified lifetime components
18425
+ if (this.linearVelOverLifetime.x) {
18426
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18427
+ linearMove.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18428
+ } else {
18429
+ linearMove.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18430
+ }
18431
+ }
18432
+ if (this.linearVelOverLifetime.y) {
18433
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18434
+ linearMove.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18435
+ } else {
18436
+ linearMove.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18437
+ }
18438
+ }
18439
+ if (this.linearVelOverLifetime.z) {
18440
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18441
+ linearMove.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18442
+ } else {
18443
+ linearMove.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18444
+ }
18445
+ }
18446
+ }
18447
+ var aLinearMoveOffset = i * 3;
18448
+ aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18449
+ aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18450
+ aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18451
+ aLinearMoveArray[aLinearMoveOffset + 3] = linearMove.x;
18452
+ aLinearMoveArray[aLinearMoveOffset + 4] = linearMove.y;
18453
+ aLinearMoveArray[aLinearMoveOffset + 5] = linearMove.z;
18454
+ aLinearMoveArray[aLinearMoveOffset + 6] = linearMove.x;
18455
+ aLinearMoveArray[aLinearMoveOffset + 7] = linearMove.y;
18456
+ aLinearMoveArray[aLinearMoveOffset + 8] = linearMove.z;
18457
+ aLinearMoveArray[aLinearMoveOffset + 9] = linearMove.x;
18458
+ aLinearMoveArray[aLinearMoveOffset + 10] = linearMove.y;
18459
+ aLinearMoveArray[aLinearMoveOffset + 11] = linearMove.z;
18460
+ }
18461
+ }
18462
+ this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18463
+ };
18432
18464
  _proto.expandArray = function expandArray(array, newSize) {
18433
18465
  var newArr = new Float32Array(newSize);
18434
18466
  newArr.set(array);
@@ -19065,7 +19097,13 @@ TransformPlayableAsset = __decorate([
19065
19097
  return Playable.apply(this, arguments);
19066
19098
  }
19067
19099
  var _proto = ActivationPlayable.prototype;
19068
- _proto.processFrame = function processFrame(context) {};
19100
+ _proto.processFrame = function processFrame(context) {
19101
+ var vfxItem = context.output.getUserData();
19102
+ if (!_instanceof1(vfxItem, VFXItem)) {
19103
+ return;
19104
+ }
19105
+ vfxItem.time = this.time;
19106
+ };
19069
19107
  return ActivationPlayable;
19070
19108
  }(Playable);
19071
19109
  var ActivationPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
@@ -19218,7 +19256,7 @@ var AnimationClipPlayable = /*#__PURE__*/ function(Playable) {
19218
19256
  _proto.toLocalTime = function toLocalTime(time) {
19219
19257
  var localTime = time - this.start;
19220
19258
  var duration = this.duration;
19221
- if (localTime - duration > 0.001) {
19259
+ if (localTime - duration > 0) {
19222
19260
  if (this.endBehavior === EndBehavior.restart) {
19223
19261
  localTime = localTime % duration;
19224
19262
  } else if (this.endBehavior === EndBehavior.freeze) {
@@ -19347,7 +19385,7 @@ var RuntimeClip = /*#__PURE__*/ function() {
19347
19385
  var ended = false;
19348
19386
  var started = false;
19349
19387
  var boundObject = this.track.binding;
19350
- if (localTime > clip.start + clip.duration + 0.001 && clip.endBehavior === EndBehavior.destroy) {
19388
+ if (localTime >= clip.start + clip.duration && clip.endBehavior === EndBehavior.destroy) {
19351
19389
  if (_instanceof1(boundObject, VFXItem) && VFXItem.isParticle(boundObject) && this.particleSystem && !this.particleSystem.destroyed) {
19352
19390
  weight = 1.0;
19353
19391
  } else {
@@ -20577,6 +20615,12 @@ var EffectComponent = /*#__PURE__*/ function(RendererComponent) {
20577
20615
  _proto.onStart = function onStart() {
20578
20616
  this.item.getHitTestParams = this.getHitTestParams;
20579
20617
  };
20618
+ _proto.onUpdate = function onUpdate(dt) {
20619
+ var time = this.item.time;
20620
+ var _this_material_getVector4;
20621
+ var _Time = (_this_material_getVector4 = this.material.getVector4("_Time")) != null ? _this_material_getVector4 : new Vector4();
20622
+ this.material.setVector4("_Time", _Time.set(time / 20, time, time * 2, time * 3));
20623
+ };
20580
20624
  _proto.render = function render(renderer) {
20581
20625
  if (renderer.renderingData.currentFrame.globalUniforms) {
20582
20626
  renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
@@ -20830,6 +20874,9 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20830
20874
  * 元素的变换包含位置、旋转、缩放。
20831
20875
  */ _this.transform = new Transform();
20832
20876
  /**
20877
+ * 元素动画的当前时间
20878
+ */ _this.time = 0;
20879
+ /**
20833
20880
  * 元素动画的持续时间
20834
20881
  */ _this.duration = 0;
20835
20882
  /**
@@ -21162,6 +21209,7 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
21162
21209
  var component = _step.value;
21163
21210
  if (component.enabled && !component.isStartCalled) {
21164
21211
  component.onStart();
21212
+ component.isStartCalled = true;
21165
21213
  }
21166
21214
  }
21167
21215
  for(var _iterator1 = _create_for_of_iterator_helper_loose(this.components), _step1; !(_step1 = _iterator1()).done;){
@@ -28084,7 +28132,7 @@ registerPlugin("sprite", SpriteLoader, VFXItem, true);
28084
28132
  registerPlugin("particle", ParticleLoader, VFXItem, true);
28085
28133
  registerPlugin("cal", CalculateLoader, VFXItem, true);
28086
28134
  registerPlugin("interact", InteractLoader, VFXItem, true);
28087
- var version = "2.1.0-alpha.2";
28135
+ var version = "2.1.0-alpha.4";
28088
28136
  logger.info("Core version: " + version + ".");
28089
28137
 
28090
28138
  export { AbstractPlugin, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AnimationClip, AnimationClipPlayable, AssetLoader, AssetManager, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, COMPRESSED_TEXTURE, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateLoader, Camera, CameraController, CameraVFXItemLoader, Component, Composition, CompositionComponent, CompositionSourceManager, DEFAULT_FONTS, DEFAULT_FPS, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, EffectsPackage, Engine, EventEmitter, EventSystem, FilterMode, Float16ArrayWrapper, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, ObjectBindingTrack, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, PassTextureCache, PathSegments, PluginSystem, PostProcessVolume, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderbuffer, Renderer, RendererComponent, RuntimeClip, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, SemanticMap, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, SpriteColorPlayable, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteLoader, StaticValue, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, Ticker, TimelineAsset, TimelineClip, TimelinePlayable, TrackAsset, TrackSortWrapper, TrackType, Transform, TransformAnimationPlayable, TransformPlayableAsset, TransformTrack, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createCopyShader, createGLContext, createKeyFrameMeta, createShape, createValueGetter, decimalEqual, defaultGlobalVolume, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateTransparentTexture, generateWhiteTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvas, isFunction, isIOS, isIOSByUA, isMiniProgram, isObject, isSceneJSON, isSceneURL, isSceneWithOptions, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, isWechatMiniApp, itemFrag, itemFrameFrag, itemVert, loadAVIFOptional, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxItemCountByGPU, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };