@galacean/effects-core 2.0.0-alpha.31 → 2.0.0-alpha.33

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 core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.0.0-alpha.31
6
+ * Version: v2.0.0-alpha.33
7
7
  */
8
8
 
9
9
  'use strict';
@@ -4567,15 +4567,97 @@ function getDirectStore(target) {
4567
4567
  return decoratorInitialStore.get(classKey);
4568
4568
  }
4569
4569
 
4570
+ function _assert_this_initialized(self) {
4571
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4572
+ return self;
4573
+ }
4574
+
4575
+ var EventEmitter = function EventEmitter() {
4576
+ var _this = this;
4577
+ var _this1 = this;
4578
+ this.listeners = {};
4579
+ /**
4580
+ * 移除事件监听器
4581
+ * @param eventName - 事件名称
4582
+ * @param listener - 事件监听器
4583
+ * @returns
4584
+ */ this.off = function(eventName, listener) {
4585
+ if (!_this.listeners[eventName]) {
4586
+ return;
4587
+ }
4588
+ _this.listeners[eventName] = _this.listeners[eventName].filter(function(param) {
4589
+ var l = param.listener;
4590
+ return l !== listener;
4591
+ });
4592
+ };
4593
+ /**
4594
+ * 监听事件
4595
+ * @param eventName - 事件名称
4596
+ * @param listener - 事件监听器
4597
+ * @param options - 事件监听器选项
4598
+ * @returns
4599
+ */ this.on = function(eventName, listener, options) {
4600
+ _this.listeners[eventName] = _this.listeners[eventName] || [];
4601
+ _this.listeners[eventName].push({
4602
+ listener: listener,
4603
+ options: options
4604
+ });
4605
+ return function() {
4606
+ return _this.off(eventName, listener);
4607
+ };
4608
+ };
4609
+ /**
4610
+ * 一次性监听事件
4611
+ * @param eventName - 事件名称
4612
+ * @param listener - 事件监听器
4613
+ */ this.once = function(eventName, listener) {
4614
+ _this.on(eventName, listener, {
4615
+ once: true
4616
+ });
4617
+ };
4618
+ /**
4619
+ * 触发事件
4620
+ * @param eventName - 事件名称
4621
+ * @param args - 事件参数
4622
+ */ this.emit = function(eventName) {
4623
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
4624
+ args[_key - 1] = arguments[_key];
4625
+ }
4626
+ var _this_listeners_eventName;
4627
+ (_this_listeners_eventName = _this1.listeners[eventName]) == null ? void 0 : _this_listeners_eventName.forEach(function(param) {
4628
+ var listener = param.listener, options = param.options;
4629
+ listener.apply(void 0, [].concat(args));
4630
+ if (options == null ? void 0 : options.once) {
4631
+ _this1.off(eventName, listener);
4632
+ }
4633
+ });
4634
+ };
4635
+ /**
4636
+ * 获取事件名称对应的所有监听器
4637
+ * @param eventName - 事件名称
4638
+ * @returns - 返回事件名称对应的所有监听器
4639
+ */ this.getListeners = function(eventName) {
4640
+ var _this_listeners_eventName;
4641
+ return ((_this_listeners_eventName = _this.listeners[eventName]) == null ? void 0 : _this_listeners_eventName.map(function(param) {
4642
+ var listener = param.listener;
4643
+ return listener;
4644
+ })) || [];
4645
+ };
4646
+ };
4647
+
4570
4648
  /**
4571
4649
  * @since 2.0.0
4572
4650
  * @internal
4573
- */ var EffectsObject = /*#__PURE__*/ function() {
4651
+ */ var EffectsObject = /*#__PURE__*/ function(EventEmitter) {
4652
+ _inherits(EffectsObject, EventEmitter);
4574
4653
  function EffectsObject(engine) {
4575
- this.engine = engine;
4576
- this.guid = generateGUID();
4577
- this.taggedProperties = {};
4578
- this.engine.addInstance(this);
4654
+ var _this;
4655
+ _this = EventEmitter.call(this) || this;
4656
+ _this.engine = engine;
4657
+ _this.guid = generateGUID();
4658
+ _this.taggedProperties = {};
4659
+ _this.engine.addInstance(_assert_this_initialized(_this));
4660
+ return _this;
4579
4661
  }
4580
4662
  var _proto = EffectsObject.prototype;
4581
4663
  _proto.getInstanceId = function getInstanceId() {
@@ -4601,7 +4683,7 @@ function getDirectStore(target) {
4601
4683
  return _instanceof1(obj, EffectsObject) && "guid" in obj;
4602
4684
  };
4603
4685
  return EffectsObject;
4604
- }();
4686
+ }(EventEmitter);
4605
4687
 
4606
4688
  /**
4607
4689
  * @since 2.0.0
@@ -8991,6 +9073,9 @@ exports.MaterialRenderType = void 0;
8991
9073
  * 初始化 GPU 资源
8992
9074
  * @override
8993
9075
  */ _proto.initialize = function initialize() {
9076
+ // OVERRIDE
9077
+ };
9078
+ _proto.createShaderVariant = function createShaderVariant() {
8994
9079
  // OVERRIDE
8995
9080
  };
8996
9081
  _proto.use = function use(render, globalUniforms) {
@@ -12701,6 +12786,7 @@ var GlobalUniforms = function GlobalUniforms() {
12701
12786
  this.floats = {};
12702
12787
  this.ints = {};
12703
12788
  // vector3s: Record<string, vec3> = {};
12789
+ this.vector4s = {};
12704
12790
  this.matrices = {};
12705
12791
  //...
12706
12792
  this.samplers = [] // 存放的sampler名称。
@@ -12937,6 +13023,9 @@ var Renderer = /*#__PURE__*/ function() {
12937
13023
  _proto.setGlobalInt = function setGlobalInt(name, value) {
12938
13024
  // OVERRIDE
12939
13025
  };
13026
+ _proto.setGlobalVector4 = function setGlobalVector4(name, value) {
13027
+ // OVERRIDE
13028
+ };
12940
13029
  _proto.setGlobalMatrix = function setGlobalMatrix(name, value) {
12941
13030
  // OVERRIDE
12942
13031
  };
@@ -13482,11 +13571,6 @@ var SpriteLoader = /*#__PURE__*/ function(AbstractPlugin) {
13482
13571
  return SpriteLoader;
13483
13572
  }(AbstractPlugin);
13484
13573
 
13485
- function _assert_this_initialized(self) {
13486
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13487
- return self;
13488
- }
13489
-
13490
13574
  /**
13491
13575
  * 动画图,负责更新所有的动画节点
13492
13576
  * @since 2.0.0
@@ -15923,6 +16007,17 @@ var Link = /*#__PURE__*/ function() {
15923
16007
  }while (node = node.pre);
15924
16008
  }
15925
16009
  };
16010
+ _proto.getNodeByIndex = function getNodeByIndex(index) {
16011
+ var i = 0, res = this.first;
16012
+ if (!res || index >= this.length || index < 0) {
16013
+ return null;
16014
+ }
16015
+ while(i < index){
16016
+ res = res.next;
16017
+ i++;
16018
+ }
16019
+ return res;
16020
+ };
15926
16021
  return Link;
15927
16022
  }();
15928
16023
 
@@ -16759,10 +16854,8 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16759
16854
  content[3].delay -= duration;
16760
16855
  });
16761
16856
  this.renderer.minusTimeForLoop(duration);
16762
- this.onIterate(this);
16763
16857
  } else {
16764
16858
  this.ended = true;
16765
- this.onEnd(this);
16766
16859
  var endBehavior = this.item.endBehavior;
16767
16860
  if (endBehavior === EndBehavior.freeze) {
16768
16861
  this.frozen = true;
@@ -16910,7 +17003,21 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16910
17003
  time: startTime
16911
17004
  });
16912
17005
  };
16913
- _proto.getPointPosition = function getPointPosition(point) {
17006
+ /**
17007
+ * 通过索引获取指定index粒子当前时刻的位置
17008
+ * @params index - 粒子索引
17009
+ */ _proto.getPointPositionByIndex = function getPointPositionByIndex(index) {
17010
+ var point = this.particleLink.getNodeByIndex(index);
17011
+ if (!point) {
17012
+ console.error("Get point error.");
17013
+ return null;
17014
+ } else {
17015
+ return this.getPointPosition(point.content[3]);
17016
+ }
17017
+ };
17018
+ /**
17019
+ * 通过粒子参数获取当前时刻粒子的位置
17020
+ */ _proto.getPointPosition = function getPointPosition(point) {
16914
17021
  var transform = point.transform, vel = point.vel, lifetime = point.lifetime, delay = point.delay, _point_gravity = point.gravity, gravity = _point_gravity === void 0 ? [] : _point_gravity;
16915
17022
  var forceTarget = this.options.forceTarget;
16916
17023
  var time = this.lastUpdate - delay;
@@ -16932,8 +17039,6 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16932
17039
  }
16933
17040
  return ret;
16934
17041
  };
16935
- _proto.onEnd = function onEnd(particle) {};
16936
- _proto.onIterate = function onIterate(particle) {};
16937
17042
  _proto.initPoint = function initPoint(data) {
16938
17043
  var options = this.options;
16939
17044
  var lifetime = this.lifetime;
@@ -17892,31 +17997,6 @@ var ParticleMesh = /*#__PURE__*/ function() {
17892
17997
  data[i + 3]
17893
17998
  ];
17894
17999
  };
17895
- /**
17896
- * 待废弃
17897
- * @deprecated - 使用 `particle-system.getPointPosition` 替代
17898
- */ _proto.getPointPosition = function getPointPosition(index) {
17899
- var geo = this.geometry;
17900
- var posIndex = index * 48;
17901
- var posData = geo.getAttributeData("aPos");
17902
- var offsetData = geo.getAttributeData("aOffset");
17903
- var time = this.time - offsetData[index * 16 + 2];
17904
- var pointDur = offsetData[index * 16 + 3];
17905
- var mtl = this.mesh.material;
17906
- var acc = mtl.getVector4("uAcceleration").toVector3();
17907
- var pos = Vector3.fromArray(posData, posIndex);
17908
- var vel = Vector3.fromArray(posData, posIndex + 3);
17909
- var ret = calculateTranslation(new Vector3(), this, acc, time, pointDur, pos, vel);
17910
- if (this.forceTarget) {
17911
- var target = mtl.getVector3("uFinalTarget");
17912
- var life = this.forceTarget.curve.getValue(time / pointDur);
17913
- var dl = 1 - life;
17914
- ret.x = ret.x * dl + target.x * life;
17915
- ret.y = ret.y * dl + target.y * life;
17916
- ret.z = ret.z * dl + target.z * life;
17917
- }
17918
- return ret;
17919
- };
17920
18000
  _proto.clearPoints = function clearPoints() {
17921
18001
  this.resetGeometryData(this.geometry);
17922
18002
  this.particleCount = 0;
@@ -19307,10 +19387,6 @@ function compareTracks(a, b) {
19307
19387
  };
19308
19388
  _proto.update = function update(dt) {
19309
19389
  var time = this.time;
19310
- // 主合成 rootItem 没有绑定轨道,增加结束行为判断。
19311
- if (this.item.isEnded(this.time) && !this.item.parent) {
19312
- this.item.ended = true;
19313
- }
19314
19390
  this.timelinePlayable.setTime(time);
19315
19391
  this.graph.evaluate(dt);
19316
19392
  };
@@ -19443,6 +19519,8 @@ function compareTracks(a, b) {
19443
19519
  hitPositions: hitPositions,
19444
19520
  behavior: hitParams.behavior
19445
19521
  };
19522
+ // 触发单个元素的点击事件
19523
+ item.emit("click", region);
19446
19524
  regions.push(region);
19447
19525
  if (stop(region)) {
19448
19526
  return {
@@ -20678,8 +20756,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20678
20756
  this.parentId = parentId;
20679
20757
  this.duration = duration;
20680
20758
  this.endBehavior = endBehavior;
20681
- //@ts-expect-error
20682
- this.oldId = data.oldId;
20683
20759
  if (!data.content) {
20684
20760
  data.content = {
20685
20761
  options: {}
@@ -24688,89 +24764,93 @@ var listOrder = 0;
24688
24764
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24689
24765
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
24690
24766
  * 也负责 Item 相关的动画播放控制,和持有渲染帧数据。
24691
- */ var Composition = /*#__PURE__*/ function() {
24767
+ */ var Composition = /*#__PURE__*/ function(EventEmitter) {
24768
+ _inherits(Composition, EventEmitter);
24692
24769
  function Composition(props, scene) {
24693
- var _this = this;
24770
+ var _this;
24771
+ _this = EventEmitter.call(this) || this;
24694
24772
  /**
24695
24773
  * 动画播放速度
24696
- */ this.speed = 1;
24774
+ */ _this.speed = 1;
24697
24775
  /**
24698
24776
  * 用于保存与当前合成相关的插件数据
24699
- */ this.loaderData = {};
24777
+ */ _this.loaderData = {};
24700
24778
  /**
24701
24779
  * 预合成数组
24702
- */ this.refContent = [];
24780
+ */ _this.refContent = [];
24703
24781
  /**
24704
24782
  * 预合成的合成属性,在 content 中会被其元素属性覆盖
24705
- */ this.refCompositionProps = new Map();
24783
+ */ _this.refCompositionProps = new Map();
24706
24784
  // TODO: 待优化
24707
- this.assigned = false;
24785
+ _this.assigned = false;
24708
24786
  /**
24709
24787
  * 销毁状态位
24710
- */ this.destroyed = false;
24711
- this.postLoaders = [];
24788
+ */ _this.destroyed = false;
24789
+ _this.postLoaders = [];
24712
24790
  /**
24713
24791
  * 合成暂停/播放 标识
24714
- */ this.paused = false;
24715
- this.lastVideoUpdateTime = 0;
24716
- var _props_reusable = props.reusable, reusable = _props_reusable === void 0 ? false : _props_reusable, _props_speed = props.speed, speed = _props_speed === void 0 ? 1 : _props_speed, _props_baseRenderOrder = props.baseRenderOrder, baseRenderOrder = _props_baseRenderOrder === void 0 ? 0 : _props_baseRenderOrder, renderer = props.renderer, onPlayerPause = props.onPlayerPause, onMessageItem = props.onMessageItem, onEnd = props.onEnd, event = props.event, width = props.width, height = props.height;
24717
- this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24792
+ */ _this.paused = false;
24793
+ _this.lastVideoUpdateTime = 0;
24794
+ var _props_reusable = props.reusable, reusable = _props_reusable === void 0 ? false : _props_reusable, _props_speed = props.speed, speed = _props_speed === void 0 ? 1 : _props_speed, _props_baseRenderOrder = props.baseRenderOrder, baseRenderOrder = _props_baseRenderOrder === void 0 ? 0 : _props_baseRenderOrder, renderer = props.renderer, event = props.event, width = props.width, height = props.height, handleItemMessage = props.handleItemMessage;
24795
+ _this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24718
24796
  scene.jsonScene.imgUsage = undefined;
24719
24797
  if (reusable) {
24720
- this.keepResource = true;
24798
+ _this.keepResource = true;
24721
24799
  scene.textures = undefined;
24722
24800
  scene.consumed = true;
24723
24801
  }
24724
- var _this_compositionSourceManager = this.compositionSourceManager, sourceContent = _this_compositionSourceManager.sourceContent, pluginSystem = _this_compositionSourceManager.pluginSystem, imgUsage = _this_compositionSourceManager.imgUsage, totalTime = _this_compositionSourceManager.totalTime, refCompositionProps = _this_compositionSourceManager.refCompositionProps;
24802
+ var _this_compositionSourceManager = _this.compositionSourceManager, sourceContent = _this_compositionSourceManager.sourceContent, pluginSystem = _this_compositionSourceManager.pluginSystem, imgUsage = _this_compositionSourceManager.imgUsage, totalTime = _this_compositionSourceManager.totalTime, refCompositionProps = _this_compositionSourceManager.refCompositionProps;
24725
24803
  assertExist(sourceContent);
24726
- this.renderer = renderer;
24727
- this.refCompositionProps = refCompositionProps;
24728
- this.rootItem = new exports.VFXItem(this.getEngine(), sourceContent);
24729
- this.rootItem.name = "rootItem";
24730
- this.rootItem.composition = this;
24731
- this.rootComposition = this.rootItem.addComponent(CompositionComponent);
24732
- this.rootComposition.data = sourceContent;
24804
+ _this.renderer = renderer;
24805
+ _this.refCompositionProps = refCompositionProps;
24806
+ _this.rootItem = new exports.VFXItem(_this.getEngine(), sourceContent);
24807
+ _this.rootItem.name = "rootItem";
24808
+ _this.rootItem.composition = _assert_this_initialized(_this);
24809
+ _this.rootComposition = _this.rootItem.addComponent(CompositionComponent);
24810
+ _this.rootComposition.startTime = sourceContent.startTime;
24811
+ _this.rootComposition.data = sourceContent;
24733
24812
  var imageUsage = !reusable && imgUsage;
24734
- this.width = width;
24735
- this.height = height;
24736
- this.renderOrder = baseRenderOrder;
24737
- this.id = sourceContent.id;
24738
- this.renderer = renderer;
24739
- this.texInfo = imageUsage != null ? imageUsage : {};
24740
- this.event = event;
24813
+ _this.width = width;
24814
+ _this.height = height;
24815
+ _this.renderOrder = baseRenderOrder;
24816
+ _this.id = sourceContent.id;
24817
+ _this.renderer = renderer;
24818
+ _this.texInfo = imageUsage != null ? imageUsage : {};
24819
+ _this.event = event;
24741
24820
  var _scene_startTime, _scene_timeInfos_asyncCompile;
24742
- this.statistic = {
24821
+ _this.statistic = {
24743
24822
  loadTime: totalTime != null ? totalTime : 0,
24744
24823
  loadStart: (_scene_startTime = scene.startTime) != null ? _scene_startTime : 0,
24745
24824
  firstFrameTime: 0,
24746
24825
  precompileTime: (_scene_timeInfos_asyncCompile = scene.timeInfos["asyncCompile"]) != null ? _scene_timeInfos_asyncCompile : scene.timeInfos["syncCompile"]
24747
24826
  };
24748
- this.reusable = reusable;
24749
- this.speed = speed;
24750
- this.autoRefTex = !this.keepResource && imageUsage && this.rootItem.endBehavior !== EndBehavior.restart;
24751
- this.name = sourceContent.name;
24752
- this.pluginSystem = pluginSystem;
24753
- this.pluginSystem.initializeComposition(this, scene);
24754
- this.camera = new Camera(this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24827
+ _this.reusable = reusable;
24828
+ _this.speed = speed;
24829
+ _this.autoRefTex = !_this.keepResource && imageUsage && _this.rootItem.endBehavior !== EndBehavior.restart;
24830
+ _this.name = sourceContent.name;
24831
+ _this.pluginSystem = pluginSystem;
24832
+ _this.pluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24833
+ _this.camera = new Camera(_this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24755
24834
  aspect: width / height
24756
24835
  }));
24757
- this.url = scene.url;
24758
- this.assigned = true;
24759
- this.globalTime = 0;
24760
- this.interactive = true;
24761
- this.onPlayerPause = onPlayerPause;
24762
- this.onMessageItem = onMessageItem;
24763
- this.onEnd = onEnd;
24764
- this.createRenderFrame();
24765
- this.rendererOptions = null;
24766
- this.rootComposition.createContent();
24767
- this.buildItemTree(this.rootItem);
24768
- this.rootItem.onEnd = function() {
24836
+ _this.url = scene.url;
24837
+ _this.assigned = true;
24838
+ _this.globalTime = 0;
24839
+ _this.interactive = true;
24840
+ _this.handleItemMessage = handleItemMessage;
24841
+ _this.createRenderFrame();
24842
+ _this.rendererOptions = null;
24843
+ _this.rootComposition.createContent();
24844
+ _this.buildItemTree(_this.rootItem);
24845
+ _this.rootItem.onEnd = function() {
24769
24846
  window.setTimeout(function() {
24770
- _this.onEnd == null ? void 0 : _this.onEnd.call(_this, _this);
24847
+ _this.emit("end", {
24848
+ composition: _assert_this_initialized(_this)
24849
+ });
24771
24850
  }, 0);
24772
24851
  };
24773
- this.pluginSystem.resetComposition(this, this.renderFrame);
24852
+ _this.pluginSystem.resetComposition(_assert_this_initialized(_this), _this.renderFrame);
24853
+ return _this;
24774
24854
  }
24775
24855
  var _proto = Composition.prototype;
24776
24856
  /**
@@ -24821,7 +24901,7 @@ var listOrder = 0;
24821
24901
  if (this.rootItem.ended && this.reusable) {
24822
24902
  this.restart();
24823
24903
  }
24824
- if (!this.rootComposition.started) {
24904
+ if (this.rootComposition.started) {
24825
24905
  this.gotoAndPlay(this.time - this.startTime);
24826
24906
  } else {
24827
24907
  this.gotoAndPlay(0);
@@ -24844,18 +24924,14 @@ var listOrder = 0;
24844
24924
  * 跳转合成到指定时间播放
24845
24925
  * @param time - 相对 startTime 的时间
24846
24926
  */ _proto.gotoAndPlay = function gotoAndPlay(time) {
24927
+ this.setTime(time);
24847
24928
  this.resume();
24848
- if (!this.rootComposition.started) {
24849
- this.rootComposition.start();
24850
- this.rootComposition.started = true;
24851
- }
24852
- this.forwardTime(time + this.startTime);
24853
24929
  };
24854
24930
  /**
24855
24931
  * 跳转合成到指定时间并暂停
24856
24932
  * @param time - 相对 startTime 的时间
24857
24933
  */ _proto.gotoAndStop = function gotoAndStop(time) {
24858
- this.gotoAndPlay(time);
24934
+ this.setTime(time);
24859
24935
  this.pause();
24860
24936
  };
24861
24937
  /**
@@ -24882,7 +24958,7 @@ var listOrder = 0;
24882
24958
  this.rootComposition.start();
24883
24959
  this.rootComposition.started = true;
24884
24960
  }
24885
- this.forwardTime(time + this.startTime, true);
24961
+ this.forwardTime(time + this.startTime);
24886
24962
  if (pause) {
24887
24963
  this.pause();
24888
24964
  }
@@ -24895,17 +24971,16 @@ var listOrder = 0;
24895
24971
  * 前进合成到指定时间
24896
24972
  * @param time - 相对0时刻的时间
24897
24973
  * @param skipRender - 是否跳过渲染
24898
- */ _proto.forwardTime = function forwardTime(time, skipRender) {
24899
- if (skipRender === void 0) skipRender = false;
24974
+ */ _proto.forwardTime = function forwardTime(time) {
24900
24975
  var deltaTime = time * 1000 - this.rootComposition.time * 1000;
24901
24976
  var reverse = deltaTime < 0;
24902
24977
  var step = 15;
24903
24978
  var t = Math.abs(deltaTime);
24904
24979
  var ss = reverse ? -step : step;
24905
24980
  for(t; t > step; t -= step){
24906
- this.update(ss, skipRender);
24981
+ this.update(ss);
24907
24982
  }
24908
- this.update(reverse ? -t : t, skipRender);
24983
+ this.update(reverse ? -t : t);
24909
24984
  };
24910
24985
  /**
24911
24986
  * 重置状态函数
@@ -24943,74 +25018,68 @@ var listOrder = 0;
24943
25018
  }
24944
25019
  };
24945
25020
  /**
24946
- * 是否合成需要重新播放
24947
- * @returns 重新播放合成标志位
24948
- */ _proto.shouldRestart = function shouldRestart() {
24949
- var _this_rootItem = this.rootItem, ended = _this_rootItem.ended, endBehavior = _this_rootItem.endBehavior;
24950
- return ended && endBehavior === EndBehavior.restart;
24951
- };
24952
- /**
24953
- * 是否合成需要销毁
24954
- * @returns 销毁合成标志位
24955
- */ _proto.shouldDispose = function shouldDispose() {
24956
- if (this.reusable) {
24957
- return false;
24958
- }
24959
- var _this_rootItem = this.rootItem, ended = _this_rootItem.ended, endBehavior = _this_rootItem.endBehavior;
24960
- // TODO: 合成结束行为
24961
- return ended && (!endBehavior || endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY);
24962
- };
24963
- /**
24964
25021
  * 合成更新,针对所有 item 的更新
24965
25022
  * @param deltaTime - 更新的时间步长
24966
25023
  * @param skipRender - 是否需要渲染
24967
- */ _proto.update = function update(deltaTime, skipRender) {
24968
- if (skipRender === void 0) skipRender = false;
25024
+ */ _proto.update = function update(deltaTime) {
24969
25025
  if (!this.assigned || this.paused) {
24970
25026
  return;
24971
25027
  }
24972
- if (this.shouldRestart()) {
24973
- this.restart();
24974
- // restart then tick to avoid flicker
24975
- }
24976
25028
  var time = this.getUpdateTime(deltaTime * this.speed);
24977
25029
  this.globalTime += time;
24978
- if (this.rootComposition.isActiveAndEnabled) {
24979
- var localTime = this.toLocalTime(this.globalTime / 1000);
24980
- this.rootComposition.time = localTime;
24981
- }
25030
+ this.updateRootComposition();
24982
25031
  this.updateVideo();
24983
25032
  // 更新 model-tree-plugin
24984
25033
  this.updatePluginLoaders(deltaTime);
25034
+ // scene VFXItem components lifetime function.
24985
25035
  this.callStart(this.rootItem);
24986
25036
  this.callUpdate(this.rootItem, time);
24987
25037
  this.callLateUpdate(this.rootItem, time);
24988
- // this.extraCamera?.getComponent(TimelineComponent)?.update(deltaTime);
24989
25038
  this.updateCamera();
25039
+ this.prepareRender();
24990
25040
  if (this.shouldDispose()) {
24991
- this.onEnd == null ? void 0 : this.onEnd.call(this, this);
24992
25041
  this.dispose();
24993
- } else {
24994
- if (!skipRender) {
24995
- this.prepareRender();
24996
- }
24997
25042
  }
24998
25043
  };
24999
25044
  _proto.toLocalTime = function toLocalTime(time) {
25000
25045
  var localTime = time - this.rootItem.start;
25001
25046
  var duration = this.rootItem.duration;
25002
25047
  if (localTime - duration > 0.001) {
25003
- if (this.rootItem.endBehavior === EndBehavior.restart) {
25004
- localTime = localTime % duration;
25005
- } else if (this.rootItem.endBehavior === EndBehavior.freeze) {
25006
- localTime = Math.min(duration, localTime);
25048
+ if (!this.rootItem.ended) {
25049
+ this.rootItem.ended = true;
25050
+ this.emit("end", {
25051
+ composition: this
25052
+ });
25053
+ }
25054
+ switch(this.rootItem.endBehavior){
25055
+ case EndBehavior.restart:
25056
+ {
25057
+ localTime = localTime % duration;
25058
+ this.restart();
25059
+ break;
25060
+ }
25061
+ case EndBehavior.freeze:
25062
+ {
25063
+ localTime = Math.min(duration, localTime);
25064
+ break;
25065
+ }
25066
+ case EndBehavior.forward:
25067
+ {
25068
+ break;
25069
+ }
25070
+ case EndBehavior.destroy:
25071
+ {
25072
+ break;
25073
+ }
25007
25074
  }
25008
25075
  }
25009
25076
  return localTime;
25010
25077
  };
25078
+ _proto.shouldDispose = function shouldDispose() {
25079
+ return this.rootItem.ended && this.rootItem.endBehavior === EndBehavior.destroy && !this.reusable;
25080
+ };
25011
25081
  _proto.getUpdateTime = function getUpdateTime(t) {
25012
25082
  var startTimeInMs = this.startTime * 1000;
25013
- // const content = this.rootItem;
25014
25083
  var now = this.rootComposition.time * 1000;
25015
25084
  if (t < 0 && now + t < startTimeInMs) {
25016
25085
  return startTimeInMs - now;
@@ -25158,6 +25227,14 @@ var listOrder = 0;
25158
25227
  });
25159
25228
  };
25160
25229
  /**
25230
+ * 更新主合成组件
25231
+ */ _proto.updateRootComposition = function updateRootComposition() {
25232
+ if (this.rootComposition.isActiveAndEnabled) {
25233
+ var localTime = this.toLocalTime(this.globalTime / 1000);
25234
+ this.rootComposition.time = localTime;
25235
+ }
25236
+ };
25237
+ /**
25161
25238
  * 通过名称获取元素
25162
25239
  * @param name - 元素名称
25163
25240
  * @returns 元素对象
@@ -25206,12 +25283,17 @@ var listOrder = 0;
25206
25283
  * @param type - 交互类型
25207
25284
  */ _proto.addInteractiveItem = function addInteractiveItem(item, type) {
25208
25285
  if (type === InteractType.MESSAGE) {
25209
- this.onMessageItem == null ? void 0 : this.onMessageItem.call(this, {
25286
+ this.handleItemMessage({
25210
25287
  name: item.name,
25211
25288
  phrase: MESSAGE_ITEM_PHRASE_BEGIN,
25212
25289
  id: item.id,
25213
25290
  compositionId: this.id
25214
25291
  });
25292
+ item.emit("message", {
25293
+ name: item.name,
25294
+ phrase: MESSAGE_ITEM_PHRASE_BEGIN,
25295
+ id: item.id
25296
+ });
25215
25297
  return item.id;
25216
25298
  }
25217
25299
  };
@@ -25220,14 +25302,19 @@ var listOrder = 0;
25220
25302
  * @param item - 交互元素
25221
25303
  * @param type - 交互类型
25222
25304
  */ _proto.removeInteractiveItem = function removeInteractiveItem(item, type) {
25223
- // MESSAGE ITEM的结束行为
25305
+ // MESSAGE ITEM 的结束行为
25224
25306
  if (type === InteractType.MESSAGE) {
25225
- this.onMessageItem == null ? void 0 : this.onMessageItem.call(this, {
25307
+ this.handleItemMessage({
25226
25308
  name: item.name,
25227
25309
  phrase: MESSAGE_ITEM_PHRASE_END,
25228
25310
  id: item.id,
25229
25311
  compositionId: this.id
25230
25312
  });
25313
+ item.emit("message", {
25314
+ name: item.name,
25315
+ phrase: MESSAGE_ITEM_PHRASE_END,
25316
+ id: item.id
25317
+ });
25231
25318
  }
25232
25319
  };
25233
25320
  /**
@@ -25321,9 +25408,10 @@ var listOrder = 0;
25321
25408
  (_this_rendererOptions = this.rendererOptions) == null ? void 0 : _this_rendererOptions.emptyTexture.dispose();
25322
25409
  (_this_pluginSystem = this.pluginSystem) == null ? void 0 : _this_pluginSystem.destroyComposition(this);
25323
25410
  this.update = function() {
25324
- logger.error("Update disposed composition: " + _this.name + ".");
25411
+ {
25412
+ logger.error("Update disposed composition: " + _this.name + ".");
25413
+ }
25325
25414
  };
25326
- this.onPlayerPause = noop;
25327
25415
  this.dispose = noop;
25328
25416
  if (textures && this.keepResource) {
25329
25417
  textures.forEach(function(tex) {
@@ -25521,7 +25609,7 @@ var listOrder = 0;
25521
25609
  }
25522
25610
  ]);
25523
25611
  return Composition;
25524
- }();
25612
+ }(EventEmitter);
25525
25613
 
25526
25614
  var SIZEOF_SHORT = 2;
25527
25615
  var SIZEOF_INT = 4;
@@ -27485,7 +27573,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
27485
27573
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
27486
27574
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
27487
27575
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
27488
- var version = "2.0.0-alpha.31";
27576
+ var version = "2.0.0-alpha.33";
27489
27577
  logger.info("Core version: " + version + ".");
27490
27578
 
27491
27579
  exports.AbstractPlugin = AbstractPlugin;
@@ -27519,6 +27607,7 @@ exports.EVENT_TYPE_TOUCH_START = EVENT_TYPE_TOUCH_START;
27519
27607
  exports.EffectsObject = EffectsObject;
27520
27608
  exports.EffectsPackage = EffectsPackage;
27521
27609
  exports.Engine = Engine;
27610
+ exports.EventEmitter = EventEmitter;
27522
27611
  exports.EventSystem = EventSystem;
27523
27612
  exports.Float16ArrayWrapper = Float16ArrayWrapper;
27524
27613
  exports.Framebuffer = Framebuffer;