@galacean/effects-threejs 2.1.0-alpha.1 → 2.1.0-alpha.3

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.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime threejs plugin for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.1.0-alpha.1
6
+ * Version: v2.1.0-alpha.3
7
7
  */
8
8
 
9
9
  'use strict';
@@ -8374,7 +8374,7 @@ var seed$9 = 1;
8374
8374
  * 通过 URL 创建 Texture 对象。
8375
8375
  * @param url - 要创建的 Texture URL
8376
8376
  * @since 2.0.0
8377
- */ Texture.fromImage = function fromImage(url, engine) {
8377
+ */ Texture.fromImage = function fromImage(url, engine, options) {
8378
8378
  return _async_to_generator(function() {
8379
8379
  var image, texture;
8380
8380
  return __generator(this, function(_state) {
@@ -8386,12 +8386,13 @@ var seed$9 = 1;
8386
8386
  ];
8387
8387
  case 1:
8388
8388
  image = _state.sent();
8389
- texture = Texture.create(engine, {
8389
+ texture = Texture.create(engine, _extends({
8390
8390
  sourceType: exports.TextureSourceType.image,
8391
8391
  image: image,
8392
+ target: glContext.TEXTURE_2D,
8392
8393
  id: generateGUID(),
8393
8394
  flipY: true
8394
- });
8395
+ }, options));
8395
8396
  texture.initialize();
8396
8397
  return [
8397
8398
  2,
@@ -10323,15 +10324,19 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10323
10324
  points: points,
10324
10325
  timeInterval: timeInterval,
10325
10326
  valueInterval: valueInterval,
10326
- curve: curve
10327
+ curve: curve,
10328
+ timeStart: Number(s.x),
10329
+ timeEnd: Number(e.x)
10327
10330
  };
10328
10331
  }
10329
10332
  };
10330
10333
  _proto.getValue = function getValue(time) {
10331
10334
  var result = 0;
10332
10335
  var keyTimeData = Object.keys(this.curveMap);
10333
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10334
- var keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split("&")[1]);
10336
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10337
+ var keyTimeEnd = this.curveMap[keyTimeData[keyTimeData.length - 1]].timeEnd;
10338
+ // const keyTimeStart = Number(keyTimeData[0].split('&')[0]);
10339
+ // const keyTimeEnd = Number(keyTimeData[keyTimeData.length - 1].split('&')[1]);
10335
10340
  if (time <= keyTimeStart) {
10336
10341
  return this.getCurveValue(keyTimeData[0], keyTimeStart);
10337
10342
  }
@@ -10339,7 +10344,9 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10339
10344
  return this.getCurveValue(keyTimeData[keyTimeData.length - 1], keyTimeEnd);
10340
10345
  }
10341
10346
  for(var i = 0; i < keyTimeData.length; i++){
10342
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10347
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10348
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10349
+ // const [xMin, xMax] = keyTimeData[i].split('&');
10343
10350
  if (time >= Number(xMin) && time < Number(xMax)) {
10344
10351
  result = this.getCurveValue(keyTimeData[i], time);
10345
10352
  break;
@@ -10352,12 +10359,13 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
10352
10359
  var time = (t1 - t0) / ts;
10353
10360
  var result = 0;
10354
10361
  var keyTimeData = Object.keys(this.curveMap);
10355
- var keyTimeStart = Number(keyTimeData[0].split("&")[0]);
10362
+ var keyTimeStart = this.curveMap[keyTimeData[0]].timeStart;
10356
10363
  if (time <= keyTimeStart) {
10357
10364
  return 0;
10358
10365
  }
10359
10366
  for(var i = 0; i < keyTimeData.length; i++){
10360
- var _keyTimeData_i_split = keyTimeData[i].split("&"), xMin = _keyTimeData_i_split[0], xMax = _keyTimeData_i_split[1];
10367
+ var xMin = this.curveMap[keyTimeData[i]].timeStart;
10368
+ var xMax = this.curveMap[keyTimeData[i]].timeEnd;
10361
10369
  if (time >= Number(xMax)) {
10362
10370
  result += ts * this.getCurveIntegrateValue(keyTimeData[i], Number(xMax));
10363
10371
  }
@@ -13619,25 +13627,25 @@ function _assert_this_initialized(self) {
13619
13627
  }
13620
13628
  var _proto = PlayableGraph.prototype;
13621
13629
  _proto.evaluate = function evaluate(dt) {
13622
- // 初始化节点状态
13623
- for(var _iterator = _create_for_of_iterator_helper_loose(this.playables), _step; !(_step = _iterator()).done;){
13624
- var playable = _step.value;
13625
- this.updatePlayableTime(playable, dt);
13626
- }
13627
13630
  // 初始化输出节点状态
13628
- for(var _iterator1 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step1; !(_step1 = _iterator1()).done;){
13629
- var playableOutput = _step1.value;
13631
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.playableOutputs), _step; !(_step = _iterator()).done;){
13632
+ var playableOutput = _step.value;
13630
13633
  playableOutput.context.deltaTime = dt;
13631
13634
  }
13632
13635
  // 执行生命周期函数
13633
- for(var _iterator2 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step2; !(_step2 = _iterator2()).done;){
13634
- var playableOutput1 = _step2.value;
13636
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step1; !(_step1 = _iterator1()).done;){
13637
+ var playableOutput1 = _step1.value;
13635
13638
  this.prepareFrameWithRoot(playableOutput1);
13636
13639
  }
13637
- for(var _iterator3 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step3; !(_step3 = _iterator3()).done;){
13638
- var playableOutput2 = _step3.value;
13640
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.playableOutputs), _step2; !(_step2 = _iterator2()).done;){
13641
+ var playableOutput2 = _step2.value;
13639
13642
  this.processFrameWithRoot(playableOutput2);
13640
13643
  }
13644
+ // 更新节点时间
13645
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(this.playables), _step3; !(_step3 = _iterator3()).done;){
13646
+ var playable = _step3.value;
13647
+ this.updatePlayableTime(playable, dt);
13648
+ }
13641
13649
  };
13642
13650
  _proto.connect = function connect(source, sourceOutputPort, destination, destinationInputPort) {
13643
13651
  destination.connectInput(destinationInputPort, source, sourceOutputPort);
@@ -13660,11 +13668,7 @@ function _assert_this_initialized(self) {
13660
13668
  if (playable.getPlayState() !== 0) {
13661
13669
  return;
13662
13670
  }
13663
- if (playable.overrideTimeNextEvaluation) {
13664
- playable.overrideTimeNextEvaluation = false;
13665
- } else {
13666
- playable.setTime(playable.getTime() + deltaTime);
13667
- }
13671
+ playable.setTime(playable.getTime() + deltaTime);
13668
13672
  };
13669
13673
  return PlayableGraph;
13670
13674
  }();
@@ -13676,7 +13680,6 @@ function _assert_this_initialized(self) {
13676
13680
  if (inputCount === void 0) inputCount = 0;
13677
13681
  this.onPlayablePlayFlag = true;
13678
13682
  this.onPlayablePauseFlag = false;
13679
- this.overrideTimeNextEvaluation = false;
13680
13683
  this.destroyed = false;
13681
13684
  this.inputs = [];
13682
13685
  this.inputOuputPorts = [];
@@ -13765,7 +13768,6 @@ function _assert_this_initialized(self) {
13765
13768
  };
13766
13769
  _proto.setTime = function setTime(time) {
13767
13770
  this.time = time;
13768
- this.overrideTimeNextEvaluation = true;
13769
13771
  };
13770
13772
  _proto.getTime = function getTime() {
13771
13773
  return this.time;
@@ -16568,8 +16570,9 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16568
16570
  };
16569
16571
  _proto.onUpdate = function onUpdate(dt) {
16570
16572
  var time = this.particleMesh.time;
16571
- this.particleMesh.mesh.material.setVector4("uParams", new Vector4(time, this.item.duration, 0, 0));
16572
- this.particleMesh.onUpdate(dt);
16573
+ var _this_particleMesh_mesh_material_getVector4;
16574
+ var uParams = (_this_particleMesh_mesh_material_getVector4 = this.particleMesh.mesh.material.getVector4("uParams")) != null ? _this_particleMesh_mesh_material_getVector4 : new Vector4();
16575
+ this.particleMesh.mesh.material.setVector4("uParams", uParams.set(time, this.item.duration, 0, 0));
16573
16576
  };
16574
16577
  _proto.render = function render(renderer) {
16575
16578
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
@@ -16584,7 +16587,7 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16584
16587
  };
16585
16588
  _proto.updateTime = function updateTime(now, delta) {
16586
16589
  this.particleMesh.time = now;
16587
- // this.particleMesh.onUpdate(delta);
16590
+ this.particleMesh.onUpdate(delta);
16588
16591
  if (this.trailMesh) {
16589
16592
  this.trailMesh.time = now;
16590
16593
  this.trailMesh.onUpdate(delta);
@@ -16878,7 +16881,7 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16878
16881
  break;
16879
16882
  }
16880
16883
  var burst = bursts[j];
16881
- var opts = burst.getGeneratorOptions(timePassed, lifetime);
16884
+ var opts = !burst.disabled && burst.getGeneratorOptions(timePassed, lifetime);
16882
16885
  if (opts) {
16883
16886
  var originVec = [
16884
16887
  0,
@@ -16887,6 +16890,9 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16887
16890
  ];
16888
16891
  var offsets = emission.burstOffsets[j];
16889
16892
  var burstOffset = offsets && offsets[opts.cycleIndex] || originVec;
16893
+ if (burst.once) {
16894
+ this.removeBurst(j);
16895
+ }
16890
16896
  for(var i1 = 0; i1 < opts.count && cursor < maxCount; i1++){
16891
16897
  var _p_transform;
16892
16898
  if (shouldSkipGenerate()) {
@@ -17691,6 +17697,10 @@ var particleUniformTypeMap = {
17691
17697
  var ParticleMesh = /*#__PURE__*/ function() {
17692
17698
  function ParticleMesh(engine, props) {
17693
17699
  this.particleCount = 0;
17700
+ this.cachedRotationVector3 = new Vector3();
17701
+ this.cachedRotationMatrix = new Matrix3();
17702
+ this.cachedLinearMove = new Vector3();
17703
+ this.tempMatrix3 = new Matrix3();
17694
17704
  this.VERT_MAX_KEY_FRAME_COUNT = 0;
17695
17705
  var _engine_renderer;
17696
17706
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
@@ -18086,69 +18096,10 @@ var ParticleMesh = /*#__PURE__*/ function() {
18086
18096
  };
18087
18097
  _proto.onUpdate = function onUpdate(dt) {
18088
18098
  var aPosArray = this.geometry.getAttributeData("aPos"); // vector3
18089
- var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18090
- var aOffsetArray = this.geometry.getAttributeData("aOffset");
18091
- var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18092
- var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18093
- // const uParams = this.mesh.material.getVector4('uParams');
18094
- // if (!uParams) {
18095
- // return;
18096
- // }
18097
- var localTime = new Float32Array([
18098
- this.time
18099
- ])[0];
18100
18099
  var particleCount = Math.ceil(aPosArray.length / 12);
18101
- // calculate particle translation
18102
- var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18103
- if (aTranslationArray.length < particleCount * 3) {
18104
- aTranslationArray = new Float32Array(particleCount * 3);
18105
- }
18106
- var velocity = new Vector3(0, 0, 0);
18107
- for(var i = 0; i < particleCount; i++){
18108
- var velOffset = i * 12 + 3;
18109
- velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18110
- var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18111
- var aTranslationOffset = i * 3;
18112
- aTranslationArray[aTranslationOffset] = trans.x;
18113
- aTranslationArray[aTranslationOffset + 1] = trans.y;
18114
- aTranslationArray[aTranslationOffset + 2] = trans.z;
18115
- }
18116
- this.geometry.setAttributeData("aTranslation", aTranslationArray);
18117
- // calculate particle rotation
18118
- var aRotationArray = this.geometry.getAttributeData("aRotation0");
18119
- if (aRotationArray.length < particleCount * 9) {
18120
- aRotationArray = new Float32Array(particleCount * 9);
18121
- }
18122
- for(var i1 = 0; i1 < particleCount; i1++){
18123
- var time = localTime - aOffsetArray[i1 * 4 + 2];
18124
- var duration = aOffsetArray[i1 * 4 + 3];
18125
- var life = clamp$1(time / duration, 0.0, 1.0);
18126
- var aRotOffset = i1 * 8;
18127
- var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18128
- var aSeed = aSeedArray[i1 * 8 + 3];
18129
- var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18130
- var aRotationOffset = i1 * 9;
18131
- var matrixArray = aRotation.toArray();
18132
- aRotationArray.set(matrixArray, aRotationOffset);
18133
- }
18134
- this.geometry.setAttributeData("aRotation0", aRotationArray);
18135
- // calculate linear movement
18136
- var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18137
- if (aLinearMoveArray.length < particleCount * 3) {
18138
- aLinearMoveArray = new Float32Array(particleCount * 3);
18139
- }
18140
- for(var i2 = 0; i2 < particleCount; i2++){
18141
- var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18142
- var duration1 = aOffsetArray[i2 * 4 + 3];
18143
- // const life = math.clamp(time / duration, 0.0, 1.0);
18144
- var aSeed1 = aSeedArray[i2 * 8 + 3];
18145
- var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18146
- var aLinearMoveOffset = i2 * 3;
18147
- aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18148
- aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18149
- aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18150
- }
18151
- this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18100
+ this.applyTranslation(particleCount, dt);
18101
+ this.applyRotation(particleCount, dt);
18102
+ this.applyLinearMove(particleCount, dt);
18152
18103
  };
18153
18104
  _proto.minusTime = function minusTime(time) {
18154
18105
  var aOffset = this.geometry.getAttributeData("aOffset");
@@ -18158,158 +18109,6 @@ var ParticleMesh = /*#__PURE__*/ function() {
18158
18109
  this.geometry.setAttributeData("aOffset", aOffset);
18159
18110
  this.time -= time;
18160
18111
  };
18161
- _proto.calculateTranslation = function calculateTranslation(velocity, t0, t1, duration) {
18162
- var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18163
- var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18164
- if (!uAcceleration || !uGravityModifierValue) {
18165
- return new Vector3();
18166
- }
18167
- var dt = t1 - t0; // 相对delay的时间
18168
- var d = this.gravityModifier.getIntegrateByTime(0, dt);
18169
- var acc = [
18170
- uAcceleration.x * d,
18171
- uAcceleration.y * d,
18172
- uAcceleration.z * d
18173
- ];
18174
- // ret.addScaledVector(velData, speedIntegrate);
18175
- // ret.addScaledVector(acc, d);
18176
- // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18177
- if (this.speedOverLifetime) {
18178
- // dt / dur 归一化
18179
- var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18180
- return velocity.clone().multiply(speed).add(acc);
18181
- }
18182
- return velocity.clone().multiply(dt).add(acc);
18183
- };
18184
- _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18185
- var rotation = rot.clone();
18186
- if (!this.rotationOverLifetime) {
18187
- return new Matrix3();
18188
- }
18189
- if (this.rotationOverLifetime.asRotation) {
18190
- // Adjust rotation based on the specified lifetime components
18191
- if (this.rotationOverLifetime.x) {
18192
- if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18193
- rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18194
- } else {
18195
- rotation.x += this.rotationOverLifetime.x.getValue(life);
18196
- }
18197
- }
18198
- if (this.rotationOverLifetime.y) {
18199
- if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18200
- rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18201
- } else {
18202
- rotation.y += this.rotationOverLifetime.y.getValue(life);
18203
- }
18204
- }
18205
- if (this.rotationOverLifetime.z) {
18206
- if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18207
- rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18208
- } else {
18209
- rotation.z += this.rotationOverLifetime.z.getValue(life);
18210
- }
18211
- }
18212
- } else {
18213
- // Adjust rotation based on the specified lifetime components
18214
- if (this.rotationOverLifetime.x) {
18215
- if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18216
- rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * dur;
18217
- } else {
18218
- rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, dur) * dur;
18219
- }
18220
- }
18221
- if (this.rotationOverLifetime.y) {
18222
- if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18223
- rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * dur;
18224
- } else {
18225
- rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, dur) * dur;
18226
- }
18227
- }
18228
- if (this.rotationOverLifetime.z) {
18229
- if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18230
- rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * dur;
18231
- } else {
18232
- rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, dur) * dur;
18233
- }
18234
- }
18235
- }
18236
- // If the rotation vector is zero, return the identity matrix
18237
- if (rotation.dot(rotation) === 0.0) {
18238
- return new Matrix3().identity();
18239
- }
18240
- // Return the rotation matrix derived from the rotation vector
18241
- return this.mat3FromRotation(rotation);
18242
- };
18243
- _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18244
- var d2r = Math.PI / 180;
18245
- var sinR = rotation.clone().multiply(d2r);
18246
- sinR.x = Math.sin(sinR.x);
18247
- sinR.y = Math.sin(sinR.y);
18248
- sinR.z = Math.sin(sinR.z);
18249
- var cosR = rotation.clone().multiply(d2r);
18250
- cosR.x = Math.cos(cosR.x);
18251
- cosR.y = Math.cos(cosR.y);
18252
- cosR.z = Math.cos(cosR.z);
18253
- var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18254
- var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18255
- var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18256
- var result = rotZ.multiply(rotY).multiply(rotX);
18257
- return result;
18258
- };
18259
- _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18260
- var mov = new Vector3();
18261
- var lifetime = time / duration;
18262
- if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18263
- return new Vector3();
18264
- }
18265
- if (this.linearVelOverLifetime.asMovement) {
18266
- if (this.linearVelOverLifetime.x) {
18267
- if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18268
- mov.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18269
- } else {
18270
- mov.x = this.linearVelOverLifetime.x.getValue(lifetime);
18271
- }
18272
- }
18273
- if (this.linearVelOverLifetime.y) {
18274
- if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18275
- mov.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18276
- } else {
18277
- mov.y = this.linearVelOverLifetime.y.getValue(lifetime);
18278
- }
18279
- }
18280
- if (this.linearVelOverLifetime.z) {
18281
- if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18282
- mov.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18283
- } else {
18284
- mov.z = this.linearVelOverLifetime.z.getValue(lifetime);
18285
- }
18286
- }
18287
- } else {
18288
- // Adjust rotation based on the specified lifetime components
18289
- if (this.linearVelOverLifetime.x) {
18290
- if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18291
- mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18292
- } else {
18293
- mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18294
- }
18295
- }
18296
- if (this.linearVelOverLifetime.y) {
18297
- if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18298
- mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18299
- } else {
18300
- mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18301
- }
18302
- }
18303
- if (this.linearVelOverLifetime.z) {
18304
- if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18305
- mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18306
- } else {
18307
- mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18308
- }
18309
- }
18310
- }
18311
- return mov;
18312
- };
18313
18112
  _proto.removePoint = function removePoint(index) {
18314
18113
  if (index < this.particleCount) {
18315
18114
  this.geometry.setAttributeSubData("aOffset", index * 16, new Float32Array(16));
@@ -18333,7 +18132,8 @@ var ParticleMesh = /*#__PURE__*/ function() {
18333
18132
  var pointData = {
18334
18133
  aPos: new Float32Array(48),
18335
18134
  aRot: new Float32Array(32),
18336
- aOffset: new Float32Array(16)
18135
+ aOffset: new Float32Array(16),
18136
+ aTranslation: new Float32Array(12)
18337
18137
  };
18338
18138
  var useSprite = this.useSprite;
18339
18139
  if (useSprite) {
@@ -18442,6 +18242,226 @@ var ParticleMesh = /*#__PURE__*/ function() {
18442
18242
  geometry.setDrawCount(this.particleCount * 6);
18443
18243
  }
18444
18244
  };
18245
+ _proto.applyTranslation = function applyTranslation(particleCount, deltaTime) {
18246
+ var localTime = this.time;
18247
+ var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18248
+ var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18249
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18250
+ if (aTranslationArray.length < particleCount * 3) {
18251
+ aTranslationArray = this.expandArray(aTranslationArray, particleCount * 3);
18252
+ }
18253
+ // const velocity = this.cachedVelocity;
18254
+ var velocityX = 0;
18255
+ var velocityY = 0;
18256
+ var velocityZ = 0;
18257
+ var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18258
+ var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18259
+ for(var i = 0; i < particleCount; i++){
18260
+ var velOffset = i * 12 + 3;
18261
+ velocityX = aVelArray[velOffset];
18262
+ velocityY = aVelArray[velOffset + 1];
18263
+ velocityZ = aVelArray[velOffset + 2];
18264
+ // velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18265
+ var dt = localTime - aOffsetArray[i * 4 + 2]; // 相对delay的时间
18266
+ var duration = aOffsetArray[i * 4 + 3];
18267
+ if (uAcceleration && uGravityModifierValue) {
18268
+ var d = this.gravityModifier.getIntegrateValue(0, dt, duration);
18269
+ // const acc = this.tempVector3.set(uAcceleration.x * d, uAcceleration.y * d, uAcceleration.z * d);
18270
+ var accX = uAcceleration.x * d;
18271
+ var accY = uAcceleration.y * d;
18272
+ var accZ = uAcceleration.z * d;
18273
+ // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18274
+ if (this.speedOverLifetime) {
18275
+ // dt / dur 归一化
18276
+ var speed = this.speedOverLifetime.getValue(dt / duration);
18277
+ velocityX = velocityX * speed + accX;
18278
+ velocityY = velocityY * speed + accY;
18279
+ velocityZ = velocityZ * speed + accZ;
18280
+ // velocity.multiply(speed).add(acc);
18281
+ } else {
18282
+ velocityX = velocityX + accX;
18283
+ velocityY = velocityY + accY;
18284
+ velocityZ = velocityZ + accZ;
18285
+ // velocity.add(acc);
18286
+ }
18287
+ }
18288
+ var aTranslationOffset = i * 3;
18289
+ if (aOffsetArray[i * 4 + 2] < localTime) {
18290
+ // const translation = velocity.multiply(deltaTime / 1000);
18291
+ aTranslationArray[aTranslationOffset] += velocityX * (deltaTime / 1000);
18292
+ aTranslationArray[aTranslationOffset + 1] += velocityY * (deltaTime / 1000);
18293
+ aTranslationArray[aTranslationOffset + 2] += velocityZ * (deltaTime / 1000);
18294
+ }
18295
+ }
18296
+ this.geometry.setAttributeData("aTranslation", aTranslationArray);
18297
+ };
18298
+ _proto.applyRotation = function applyRotation(particleCount, deltaTime) {
18299
+ var aRotationArray = this.geometry.getAttributeData("aRotation0");
18300
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18301
+ var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18302
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18303
+ var localTime = this.time;
18304
+ var aRotationMatrix = this.cachedRotationMatrix;
18305
+ if (aRotationArray.length < particleCount * 9) {
18306
+ aRotationArray = this.expandArray(aRotationArray, particleCount * 9);
18307
+ }
18308
+ for(var i = 0; i < particleCount; i++){
18309
+ var time = localTime - aOffsetArray[i * 4 + 2];
18310
+ var duration = aOffsetArray[i * 4 + 3];
18311
+ var life = clamp$1(time / duration, 0.0, 1.0);
18312
+ var aRotOffset = i * 8;
18313
+ var aRot = this.cachedRotationVector3.set(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18314
+ var aSeed = aSeedArray[i * 8 + 3];
18315
+ var rotation = aRot;
18316
+ if (!this.rotationOverLifetime) {
18317
+ aRotationMatrix.setZero();
18318
+ } else if (this.rotationOverLifetime.asRotation) {
18319
+ // Adjust rotation based on the specified lifetime components
18320
+ if (this.rotationOverLifetime.x) {
18321
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18322
+ rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18323
+ } else {
18324
+ rotation.x += this.rotationOverLifetime.x.getValue(life);
18325
+ }
18326
+ }
18327
+ if (this.rotationOverLifetime.y) {
18328
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18329
+ rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18330
+ } else {
18331
+ rotation.y += this.rotationOverLifetime.y.getValue(life);
18332
+ }
18333
+ }
18334
+ if (this.rotationOverLifetime.z) {
18335
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18336
+ rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18337
+ } else {
18338
+ rotation.z += this.rotationOverLifetime.z.getValue(life);
18339
+ }
18340
+ }
18341
+ } else {
18342
+ // Adjust rotation based on the specified lifetime components
18343
+ if (this.rotationOverLifetime.x) {
18344
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18345
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * duration;
18346
+ } else {
18347
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, duration) * duration;
18348
+ }
18349
+ }
18350
+ if (this.rotationOverLifetime.y) {
18351
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18352
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * duration;
18353
+ } else {
18354
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, duration) * duration;
18355
+ }
18356
+ }
18357
+ if (this.rotationOverLifetime.z) {
18358
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18359
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * duration;
18360
+ } else {
18361
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, duration) * duration;
18362
+ }
18363
+ }
18364
+ }
18365
+ // If the rotation vector is zero, return the identity matrix
18366
+ if (rotation.dot(rotation) === 0.0) {
18367
+ aRotationMatrix.identity();
18368
+ }
18369
+ var d2r = Math.PI / 180;
18370
+ var rotationXD2r = rotation.x * d2r;
18371
+ var rotationYD2r = rotation.y * d2r;
18372
+ var rotationZD2r = rotation.z * d2r;
18373
+ var sinRX = Math.sin(rotationXD2r);
18374
+ var sinRY = Math.sin(rotationYD2r);
18375
+ var sinRZ = Math.sin(rotationZD2r);
18376
+ var cosRX = Math.cos(rotationXD2r);
18377
+ var cosRY = Math.cos(rotationYD2r);
18378
+ var cosRZ = Math.cos(rotationZD2r);
18379
+ // rotZ * rotY * rotX
18380
+ aRotationMatrix.set(cosRZ, -sinRZ, 0., sinRZ, cosRZ, 0., 0., 0., 1.); //rotZ
18381
+ aRotationMatrix.multiply(this.tempMatrix3.set(cosRY, 0., sinRY, 0., 1., 0., -sinRY, 0, cosRY)); //rotY
18382
+ aRotationMatrix.multiply(this.tempMatrix3.set(1., 0., 0., 0, cosRX, -sinRX, 0., sinRX, cosRX)); //rotX
18383
+ var aRotationOffset = i * 9;
18384
+ var matrixArray = aRotationMatrix.elements;
18385
+ aRotationArray.set(matrixArray, aRotationOffset);
18386
+ }
18387
+ this.geometry.setAttributeData("aRotation0", aRotationArray);
18388
+ };
18389
+ _proto.applyLinearMove = function applyLinearMove(particleCount, deltaTime) {
18390
+ var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18391
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18392
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18393
+ var localTime = this.time;
18394
+ if (aLinearMoveArray.length < particleCount * 3) {
18395
+ aLinearMoveArray = this.expandArray(aLinearMoveArray, particleCount * 3);
18396
+ }
18397
+ var linearMove = this.cachedLinearMove;
18398
+ if (this.linearVelOverLifetime && this.linearVelOverLifetime.enabled) {
18399
+ for(var i = 0; i < particleCount; i++){
18400
+ var time = localTime - aOffsetArray[i * 4 + 2];
18401
+ var duration = aOffsetArray[i * 4 + 3];
18402
+ // const life = math.clamp(time / duration, 0.0, 1.0);
18403
+ var lifetime = time / duration;
18404
+ var aSeed = aSeedArray[i * 8 + 3];
18405
+ linearMove.setZero();
18406
+ if (this.linearVelOverLifetime.asMovement) {
18407
+ if (this.linearVelOverLifetime.x) {
18408
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18409
+ linearMove.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18410
+ } else {
18411
+ linearMove.x = this.linearVelOverLifetime.x.getValue(lifetime);
18412
+ }
18413
+ }
18414
+ if (this.linearVelOverLifetime.y) {
18415
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18416
+ linearMove.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18417
+ } else {
18418
+ linearMove.y = this.linearVelOverLifetime.y.getValue(lifetime);
18419
+ }
18420
+ }
18421
+ if (this.linearVelOverLifetime.z) {
18422
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18423
+ linearMove.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18424
+ } else {
18425
+ linearMove.z = this.linearVelOverLifetime.z.getValue(lifetime);
18426
+ }
18427
+ }
18428
+ } else {
18429
+ // Adjust rotation based on the specified lifetime components
18430
+ if (this.linearVelOverLifetime.x) {
18431
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18432
+ linearMove.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18433
+ } else {
18434
+ linearMove.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18435
+ }
18436
+ }
18437
+ if (this.linearVelOverLifetime.y) {
18438
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18439
+ linearMove.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18440
+ } else {
18441
+ linearMove.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18442
+ }
18443
+ }
18444
+ if (this.linearVelOverLifetime.z) {
18445
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18446
+ linearMove.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18447
+ } else {
18448
+ linearMove.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18449
+ }
18450
+ }
18451
+ }
18452
+ var aLinearMoveOffset = i * 3;
18453
+ aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18454
+ aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18455
+ aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18456
+ }
18457
+ }
18458
+ this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18459
+ };
18460
+ _proto.expandArray = function expandArray(array, newSize) {
18461
+ var newArr = new Float32Array(newSize);
18462
+ newArr.set(array);
18463
+ return newArr;
18464
+ };
18445
18465
  return ParticleMesh;
18446
18466
  }();
18447
18467
  var gl2UniformSlots = [
@@ -19073,7 +19093,13 @@ exports.TransformPlayableAsset = __decorate([
19073
19093
  return Playable.apply(this, arguments);
19074
19094
  }
19075
19095
  var _proto = ActivationPlayable.prototype;
19076
- _proto.processFrame = function processFrame(context) {};
19096
+ _proto.processFrame = function processFrame(context) {
19097
+ var vfxItem = context.output.getUserData();
19098
+ if (!_instanceof1(vfxItem, exports.VFXItem)) {
19099
+ return;
19100
+ }
19101
+ vfxItem.time = this.time;
19102
+ };
19077
19103
  return ActivationPlayable;
19078
19104
  }(Playable);
19079
19105
  exports.ActivationPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
@@ -19226,7 +19252,7 @@ var AnimationClipPlayable = /*#__PURE__*/ function(Playable) {
19226
19252
  _proto.toLocalTime = function toLocalTime(time) {
19227
19253
  var localTime = time - this.start;
19228
19254
  var duration = this.duration;
19229
- if (localTime - duration > 0.001) {
19255
+ if (localTime - duration > 0) {
19230
19256
  if (this.endBehavior === EndBehavior.restart) {
19231
19257
  localTime = localTime % duration;
19232
19258
  } else if (this.endBehavior === EndBehavior.freeze) {
@@ -19355,7 +19381,7 @@ var RuntimeClip = /*#__PURE__*/ function() {
19355
19381
  var ended = false;
19356
19382
  var started = false;
19357
19383
  var boundObject = this.track.binding;
19358
- if (localTime > clip.start + clip.duration + 0.001 && clip.endBehavior === EndBehavior.destroy) {
19384
+ if (localTime >= clip.start + clip.duration && clip.endBehavior === EndBehavior.destroy) {
19359
19385
  if (_instanceof1(boundObject, exports.VFXItem) && exports.VFXItem.isParticle(boundObject) && this.particleSystem && !this.particleSystem.destroyed) {
19360
19386
  weight = 1.0;
19361
19387
  } else {
@@ -20585,6 +20611,12 @@ exports.EffectComponent = /*#__PURE__*/ function(RendererComponent) {
20585
20611
  _proto.onStart = function onStart() {
20586
20612
  this.item.getHitTestParams = this.getHitTestParams;
20587
20613
  };
20614
+ _proto.onUpdate = function onUpdate(dt) {
20615
+ var time = this.item.time;
20616
+ var _this_material_getVector4;
20617
+ var _Time = (_this_material_getVector4 = this.material.getVector4("_Time")) != null ? _this_material_getVector4 : new Vector4();
20618
+ this.material.setVector4("_Time", _Time.set(time / 20, time, time * 2, time * 3));
20619
+ };
20588
20620
  _proto.render = function render(renderer) {
20589
20621
  if (renderer.renderingData.currentFrame.globalUniforms) {
20590
20622
  renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
@@ -20838,6 +20870,9 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20838
20870
  * 元素的变换包含位置、旋转、缩放。
20839
20871
  */ _this.transform = new Transform();
20840
20872
  /**
20873
+ * 元素动画的当前时间
20874
+ */ _this.time = 0;
20875
+ /**
20841
20876
  * 元素动画的持续时间
20842
20877
  */ _this.duration = 0;
20843
20878
  /**
@@ -28092,7 +28127,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
28092
28127
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
28093
28128
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
28094
28129
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
28095
- var version$1 = "2.1.0-alpha.1";
28130
+ var version$1 = "2.1.0-alpha.3";
28096
28131
  logger.info("Core version: " + version$1 + ".");
28097
28132
 
28098
28133
  var _obj;
@@ -29773,7 +29808,7 @@ setMaxSpriteMeshItemCount(8);
29773
29808
  */ Mesh.create = function(engine, props) {
29774
29809
  return new ThreeMesh(engine, props);
29775
29810
  };
29776
- var version = "2.1.0-alpha.1";
29811
+ var version = "2.1.0-alpha.3";
29777
29812
  logger.info("THREEJS plugin version: " + version + ".");
29778
29813
 
29779
29814
  exports.AbstractPlugin = AbstractPlugin;