@galacean/effects-threejs 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 threejs plugin 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';
@@ -4589,15 +4589,97 @@ function getDirectStore(target) {
4589
4589
  return decoratorInitialStore.get(classKey);
4590
4590
  }
4591
4591
 
4592
+ function _assert_this_initialized(self) {
4593
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
4594
+ return self;
4595
+ }
4596
+
4597
+ var EventEmitter = function EventEmitter() {
4598
+ var _this = this;
4599
+ var _this1 = this;
4600
+ this.listeners = {};
4601
+ /**
4602
+ * 移除事件监听器
4603
+ * @param eventName - 事件名称
4604
+ * @param listener - 事件监听器
4605
+ * @returns
4606
+ */ this.off = function(eventName, listener) {
4607
+ if (!_this.listeners[eventName]) {
4608
+ return;
4609
+ }
4610
+ _this.listeners[eventName] = _this.listeners[eventName].filter(function(param) {
4611
+ var l = param.listener;
4612
+ return l !== listener;
4613
+ });
4614
+ };
4615
+ /**
4616
+ * 监听事件
4617
+ * @param eventName - 事件名称
4618
+ * @param listener - 事件监听器
4619
+ * @param options - 事件监听器选项
4620
+ * @returns
4621
+ */ this.on = function(eventName, listener, options) {
4622
+ _this.listeners[eventName] = _this.listeners[eventName] || [];
4623
+ _this.listeners[eventName].push({
4624
+ listener: listener,
4625
+ options: options
4626
+ });
4627
+ return function() {
4628
+ return _this.off(eventName, listener);
4629
+ };
4630
+ };
4631
+ /**
4632
+ * 一次性监听事件
4633
+ * @param eventName - 事件名称
4634
+ * @param listener - 事件监听器
4635
+ */ this.once = function(eventName, listener) {
4636
+ _this.on(eventName, listener, {
4637
+ once: true
4638
+ });
4639
+ };
4640
+ /**
4641
+ * 触发事件
4642
+ * @param eventName - 事件名称
4643
+ * @param args - 事件参数
4644
+ */ this.emit = function(eventName) {
4645
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
4646
+ args[_key - 1] = arguments[_key];
4647
+ }
4648
+ var _this_listeners_eventName;
4649
+ (_this_listeners_eventName = _this1.listeners[eventName]) == null ? void 0 : _this_listeners_eventName.forEach(function(param) {
4650
+ var listener = param.listener, options = param.options;
4651
+ listener.apply(void 0, [].concat(args));
4652
+ if (options == null ? void 0 : options.once) {
4653
+ _this1.off(eventName, listener);
4654
+ }
4655
+ });
4656
+ };
4657
+ /**
4658
+ * 获取事件名称对应的所有监听器
4659
+ * @param eventName - 事件名称
4660
+ * @returns - 返回事件名称对应的所有监听器
4661
+ */ this.getListeners = function(eventName) {
4662
+ var _this_listeners_eventName;
4663
+ return ((_this_listeners_eventName = _this.listeners[eventName]) == null ? void 0 : _this_listeners_eventName.map(function(param) {
4664
+ var listener = param.listener;
4665
+ return listener;
4666
+ })) || [];
4667
+ };
4668
+ };
4669
+
4592
4670
  /**
4593
4671
  * @since 2.0.0
4594
4672
  * @internal
4595
- */ var EffectsObject = /*#__PURE__*/ function() {
4673
+ */ var EffectsObject = /*#__PURE__*/ function(EventEmitter) {
4674
+ _inherits(EffectsObject, EventEmitter);
4596
4675
  function EffectsObject(engine) {
4597
- this.engine = engine;
4598
- this.guid = generateGUID();
4599
- this.taggedProperties = {};
4600
- this.engine.addInstance(this);
4676
+ var _this;
4677
+ _this = EventEmitter.call(this) || this;
4678
+ _this.engine = engine;
4679
+ _this.guid = generateGUID();
4680
+ _this.taggedProperties = {};
4681
+ _this.engine.addInstance(_assert_this_initialized(_this));
4682
+ return _this;
4601
4683
  }
4602
4684
  var _proto = EffectsObject.prototype;
4603
4685
  _proto.getInstanceId = function getInstanceId() {
@@ -4623,7 +4705,7 @@ function getDirectStore(target) {
4623
4705
  return _instanceof1(obj, EffectsObject) && "guid" in obj;
4624
4706
  };
4625
4707
  return EffectsObject;
4626
- }();
4708
+ }(EventEmitter);
4627
4709
 
4628
4710
  /**
4629
4711
  * @since 2.0.0
@@ -9013,6 +9095,9 @@ exports.MaterialRenderType = void 0;
9013
9095
  * 初始化 GPU 资源
9014
9096
  * @override
9015
9097
  */ _proto.initialize = function initialize() {
9098
+ // OVERRIDE
9099
+ };
9100
+ _proto.createShaderVariant = function createShaderVariant() {
9016
9101
  // OVERRIDE
9017
9102
  };
9018
9103
  _proto.use = function use(render, globalUniforms) {
@@ -12723,6 +12808,7 @@ var GlobalUniforms = function GlobalUniforms() {
12723
12808
  this.floats = {};
12724
12809
  this.ints = {};
12725
12810
  // vector3s: Record<string, vec3> = {};
12811
+ this.vector4s = {};
12726
12812
  this.matrices = {};
12727
12813
  //...
12728
12814
  this.samplers = [] // 存放的sampler名称。
@@ -12959,6 +13045,9 @@ var Renderer = /*#__PURE__*/ function() {
12959
13045
  _proto.setGlobalInt = function setGlobalInt(name, value) {
12960
13046
  // OVERRIDE
12961
13047
  };
13048
+ _proto.setGlobalVector4 = function setGlobalVector4(name, value) {
13049
+ // OVERRIDE
13050
+ };
12962
13051
  _proto.setGlobalMatrix = function setGlobalMatrix(name, value) {
12963
13052
  // OVERRIDE
12964
13053
  };
@@ -13504,11 +13593,6 @@ var SpriteLoader = /*#__PURE__*/ function(AbstractPlugin) {
13504
13593
  return SpriteLoader;
13505
13594
  }(AbstractPlugin);
13506
13595
 
13507
- function _assert_this_initialized(self) {
13508
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13509
- return self;
13510
- }
13511
-
13512
13596
  /**
13513
13597
  * 动画图,负责更新所有的动画节点
13514
13598
  * @since 2.0.0
@@ -15945,6 +16029,17 @@ var Link = /*#__PURE__*/ function() {
15945
16029
  }while (node = node.pre);
15946
16030
  }
15947
16031
  };
16032
+ _proto.getNodeByIndex = function getNodeByIndex(index) {
16033
+ var i = 0, res = this.first;
16034
+ if (!res || index >= this.length || index < 0) {
16035
+ return null;
16036
+ }
16037
+ while(i < index){
16038
+ res = res.next;
16039
+ i++;
16040
+ }
16041
+ return res;
16042
+ };
15948
16043
  return Link;
15949
16044
  }();
15950
16045
 
@@ -16781,10 +16876,8 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16781
16876
  content[3].delay -= duration;
16782
16877
  });
16783
16878
  this.renderer.minusTimeForLoop(duration);
16784
- this.onIterate(this);
16785
16879
  } else {
16786
16880
  this.ended = true;
16787
- this.onEnd(this);
16788
16881
  var endBehavior = this.item.endBehavior;
16789
16882
  if (endBehavior === EndBehavior.freeze) {
16790
16883
  this.frozen = true;
@@ -16932,7 +17025,21 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16932
17025
  time: startTime
16933
17026
  });
16934
17027
  };
16935
- _proto.getPointPosition = function getPointPosition(point) {
17028
+ /**
17029
+ * 通过索引获取指定index粒子当前时刻的位置
17030
+ * @params index - 粒子索引
17031
+ */ _proto.getPointPositionByIndex = function getPointPositionByIndex(index) {
17032
+ var point = this.particleLink.getNodeByIndex(index);
17033
+ if (!point) {
17034
+ console.error("Get point error.");
17035
+ return null;
17036
+ } else {
17037
+ return this.getPointPosition(point.content[3]);
17038
+ }
17039
+ };
17040
+ /**
17041
+ * 通过粒子参数获取当前时刻粒子的位置
17042
+ */ _proto.getPointPosition = function getPointPosition(point) {
16936
17043
  var transform = point.transform, vel = point.vel, lifetime = point.lifetime, delay = point.delay, _point_gravity = point.gravity, gravity = _point_gravity === void 0 ? [] : _point_gravity;
16937
17044
  var forceTarget = this.options.forceTarget;
16938
17045
  var time = this.lastUpdate - delay;
@@ -16954,8 +17061,6 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16954
17061
  }
16955
17062
  return ret;
16956
17063
  };
16957
- _proto.onEnd = function onEnd(particle) {};
16958
- _proto.onIterate = function onIterate(particle) {};
16959
17064
  _proto.initPoint = function initPoint(data) {
16960
17065
  var options = this.options;
16961
17066
  var lifetime = this.lifetime;
@@ -17914,31 +18019,6 @@ var ParticleMesh = /*#__PURE__*/ function() {
17914
18019
  data[i + 3]
17915
18020
  ];
17916
18021
  };
17917
- /**
17918
- * 待废弃
17919
- * @deprecated - 使用 `particle-system.getPointPosition` 替代
17920
- */ _proto.getPointPosition = function getPointPosition(index) {
17921
- var geo = this.geometry;
17922
- var posIndex = index * 48;
17923
- var posData = geo.getAttributeData("aPos");
17924
- var offsetData = geo.getAttributeData("aOffset");
17925
- var time = this.time - offsetData[index * 16 + 2];
17926
- var pointDur = offsetData[index * 16 + 3];
17927
- var mtl = this.mesh.material;
17928
- var acc = mtl.getVector4("uAcceleration").toVector3();
17929
- var pos = Vector3.fromArray(posData, posIndex);
17930
- var vel = Vector3.fromArray(posData, posIndex + 3);
17931
- var ret = calculateTranslation(new Vector3(), this, acc, time, pointDur, pos, vel);
17932
- if (this.forceTarget) {
17933
- var target = mtl.getVector3("uFinalTarget");
17934
- var life = this.forceTarget.curve.getValue(time / pointDur);
17935
- var dl = 1 - life;
17936
- ret.x = ret.x * dl + target.x * life;
17937
- ret.y = ret.y * dl + target.y * life;
17938
- ret.z = ret.z * dl + target.z * life;
17939
- }
17940
- return ret;
17941
- };
17942
18022
  _proto.clearPoints = function clearPoints() {
17943
18023
  this.resetGeometryData(this.geometry);
17944
18024
  this.particleCount = 0;
@@ -19329,10 +19409,6 @@ function compareTracks(a, b) {
19329
19409
  };
19330
19410
  _proto.update = function update(dt) {
19331
19411
  var time = this.time;
19332
- // 主合成 rootItem 没有绑定轨道,增加结束行为判断。
19333
- if (this.item.isEnded(this.time) && !this.item.parent) {
19334
- this.item.ended = true;
19335
- }
19336
19412
  this.timelinePlayable.setTime(time);
19337
19413
  this.graph.evaluate(dt);
19338
19414
  };
@@ -19465,6 +19541,8 @@ function compareTracks(a, b) {
19465
19541
  hitPositions: hitPositions,
19466
19542
  behavior: hitParams.behavior
19467
19543
  };
19544
+ // 触发单个元素的点击事件
19545
+ item.emit("click", region);
19468
19546
  regions.push(region);
19469
19547
  if (stop(region)) {
19470
19548
  return {
@@ -20700,8 +20778,6 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20700
20778
  this.parentId = parentId;
20701
20779
  this.duration = duration;
20702
20780
  this.endBehavior = endBehavior;
20703
- //@ts-expect-error
20704
- this.oldId = data.oldId;
20705
20781
  if (!data.content) {
20706
20782
  data.content = {
20707
20783
  options: {}
@@ -24710,89 +24786,93 @@ var listOrder = 0;
24710
24786
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24711
24787
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
24712
24788
  * 也负责 Item 相关的动画播放控制,和持有渲染帧数据。
24713
- */ var Composition = /*#__PURE__*/ function() {
24789
+ */ var Composition = /*#__PURE__*/ function(EventEmitter) {
24790
+ _inherits(Composition, EventEmitter);
24714
24791
  function Composition(props, scene) {
24715
- var _this = this;
24792
+ var _this;
24793
+ _this = EventEmitter.call(this) || this;
24716
24794
  /**
24717
24795
  * 动画播放速度
24718
- */ this.speed = 1;
24796
+ */ _this.speed = 1;
24719
24797
  /**
24720
24798
  * 用于保存与当前合成相关的插件数据
24721
- */ this.loaderData = {};
24799
+ */ _this.loaderData = {};
24722
24800
  /**
24723
24801
  * 预合成数组
24724
- */ this.refContent = [];
24802
+ */ _this.refContent = [];
24725
24803
  /**
24726
24804
  * 预合成的合成属性,在 content 中会被其元素属性覆盖
24727
- */ this.refCompositionProps = new Map();
24805
+ */ _this.refCompositionProps = new Map();
24728
24806
  // TODO: 待优化
24729
- this.assigned = false;
24807
+ _this.assigned = false;
24730
24808
  /**
24731
24809
  * 销毁状态位
24732
- */ this.destroyed = false;
24733
- this.postLoaders = [];
24810
+ */ _this.destroyed = false;
24811
+ _this.postLoaders = [];
24734
24812
  /**
24735
24813
  * 合成暂停/播放 标识
24736
- */ this.paused = false;
24737
- this.lastVideoUpdateTime = 0;
24738
- 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;
24739
- this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24814
+ */ _this.paused = false;
24815
+ _this.lastVideoUpdateTime = 0;
24816
+ 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;
24817
+ _this.compositionSourceManager = new CompositionSourceManager(scene, renderer.engine);
24740
24818
  scene.jsonScene.imgUsage = undefined;
24741
24819
  if (reusable) {
24742
- this.keepResource = true;
24820
+ _this.keepResource = true;
24743
24821
  scene.textures = undefined;
24744
24822
  scene.consumed = true;
24745
24823
  }
24746
- 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;
24824
+ 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;
24747
24825
  assertExist(sourceContent);
24748
- this.renderer = renderer;
24749
- this.refCompositionProps = refCompositionProps;
24750
- this.rootItem = new exports.VFXItem(this.getEngine(), sourceContent);
24751
- this.rootItem.name = "rootItem";
24752
- this.rootItem.composition = this;
24753
- this.rootComposition = this.rootItem.addComponent(CompositionComponent);
24754
- this.rootComposition.data = sourceContent;
24826
+ _this.renderer = renderer;
24827
+ _this.refCompositionProps = refCompositionProps;
24828
+ _this.rootItem = new exports.VFXItem(_this.getEngine(), sourceContent);
24829
+ _this.rootItem.name = "rootItem";
24830
+ _this.rootItem.composition = _assert_this_initialized(_this);
24831
+ _this.rootComposition = _this.rootItem.addComponent(CompositionComponent);
24832
+ _this.rootComposition.startTime = sourceContent.startTime;
24833
+ _this.rootComposition.data = sourceContent;
24755
24834
  var imageUsage = !reusable && imgUsage;
24756
- this.width = width;
24757
- this.height = height;
24758
- this.renderOrder = baseRenderOrder;
24759
- this.id = sourceContent.id;
24760
- this.renderer = renderer;
24761
- this.texInfo = imageUsage != null ? imageUsage : {};
24762
- this.event = event;
24835
+ _this.width = width;
24836
+ _this.height = height;
24837
+ _this.renderOrder = baseRenderOrder;
24838
+ _this.id = sourceContent.id;
24839
+ _this.renderer = renderer;
24840
+ _this.texInfo = imageUsage != null ? imageUsage : {};
24841
+ _this.event = event;
24763
24842
  var _scene_startTime, _scene_timeInfos_asyncCompile;
24764
- this.statistic = {
24843
+ _this.statistic = {
24765
24844
  loadTime: totalTime != null ? totalTime : 0,
24766
24845
  loadStart: (_scene_startTime = scene.startTime) != null ? _scene_startTime : 0,
24767
24846
  firstFrameTime: 0,
24768
24847
  precompileTime: (_scene_timeInfos_asyncCompile = scene.timeInfos["asyncCompile"]) != null ? _scene_timeInfos_asyncCompile : scene.timeInfos["syncCompile"]
24769
24848
  };
24770
- this.reusable = reusable;
24771
- this.speed = speed;
24772
- this.autoRefTex = !this.keepResource && imageUsage && this.rootItem.endBehavior !== EndBehavior.restart;
24773
- this.name = sourceContent.name;
24774
- this.pluginSystem = pluginSystem;
24775
- this.pluginSystem.initializeComposition(this, scene);
24776
- this.camera = new Camera(this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24849
+ _this.reusable = reusable;
24850
+ _this.speed = speed;
24851
+ _this.autoRefTex = !_this.keepResource && imageUsage && _this.rootItem.endBehavior !== EndBehavior.restart;
24852
+ _this.name = sourceContent.name;
24853
+ _this.pluginSystem = pluginSystem;
24854
+ _this.pluginSystem.initializeComposition(_assert_this_initialized(_this), scene);
24855
+ _this.camera = new Camera(_this.name, _extends({}, sourceContent == null ? void 0 : sourceContent.camera, {
24777
24856
  aspect: width / height
24778
24857
  }));
24779
- this.url = scene.url;
24780
- this.assigned = true;
24781
- this.globalTime = 0;
24782
- this.interactive = true;
24783
- this.onPlayerPause = onPlayerPause;
24784
- this.onMessageItem = onMessageItem;
24785
- this.onEnd = onEnd;
24786
- this.createRenderFrame();
24787
- this.rendererOptions = null;
24788
- this.rootComposition.createContent();
24789
- this.buildItemTree(this.rootItem);
24790
- this.rootItem.onEnd = function() {
24858
+ _this.url = scene.url;
24859
+ _this.assigned = true;
24860
+ _this.globalTime = 0;
24861
+ _this.interactive = true;
24862
+ _this.handleItemMessage = handleItemMessage;
24863
+ _this.createRenderFrame();
24864
+ _this.rendererOptions = null;
24865
+ _this.rootComposition.createContent();
24866
+ _this.buildItemTree(_this.rootItem);
24867
+ _this.rootItem.onEnd = function() {
24791
24868
  window.setTimeout(function() {
24792
- _this.onEnd == null ? void 0 : _this.onEnd.call(_this, _this);
24869
+ _this.emit("end", {
24870
+ composition: _assert_this_initialized(_this)
24871
+ });
24793
24872
  }, 0);
24794
24873
  };
24795
- this.pluginSystem.resetComposition(this, this.renderFrame);
24874
+ _this.pluginSystem.resetComposition(_assert_this_initialized(_this), _this.renderFrame);
24875
+ return _this;
24796
24876
  }
24797
24877
  var _proto = Composition.prototype;
24798
24878
  /**
@@ -24843,7 +24923,7 @@ var listOrder = 0;
24843
24923
  if (this.rootItem.ended && this.reusable) {
24844
24924
  this.restart();
24845
24925
  }
24846
- if (!this.rootComposition.started) {
24926
+ if (this.rootComposition.started) {
24847
24927
  this.gotoAndPlay(this.time - this.startTime);
24848
24928
  } else {
24849
24929
  this.gotoAndPlay(0);
@@ -24866,18 +24946,14 @@ var listOrder = 0;
24866
24946
  * 跳转合成到指定时间播放
24867
24947
  * @param time - 相对 startTime 的时间
24868
24948
  */ _proto.gotoAndPlay = function gotoAndPlay(time) {
24949
+ this.setTime(time);
24869
24950
  this.resume();
24870
- if (!this.rootComposition.started) {
24871
- this.rootComposition.start();
24872
- this.rootComposition.started = true;
24873
- }
24874
- this.forwardTime(time + this.startTime);
24875
24951
  };
24876
24952
  /**
24877
24953
  * 跳转合成到指定时间并暂停
24878
24954
  * @param time - 相对 startTime 的时间
24879
24955
  */ _proto.gotoAndStop = function gotoAndStop(time) {
24880
- this.gotoAndPlay(time);
24956
+ this.setTime(time);
24881
24957
  this.pause();
24882
24958
  };
24883
24959
  /**
@@ -24904,7 +24980,7 @@ var listOrder = 0;
24904
24980
  this.rootComposition.start();
24905
24981
  this.rootComposition.started = true;
24906
24982
  }
24907
- this.forwardTime(time + this.startTime, true);
24983
+ this.forwardTime(time + this.startTime);
24908
24984
  if (pause) {
24909
24985
  this.pause();
24910
24986
  }
@@ -24917,17 +24993,16 @@ var listOrder = 0;
24917
24993
  * 前进合成到指定时间
24918
24994
  * @param time - 相对0时刻的时间
24919
24995
  * @param skipRender - 是否跳过渲染
24920
- */ _proto.forwardTime = function forwardTime(time, skipRender) {
24921
- if (skipRender === void 0) skipRender = false;
24996
+ */ _proto.forwardTime = function forwardTime(time) {
24922
24997
  var deltaTime = time * 1000 - this.rootComposition.time * 1000;
24923
24998
  var reverse = deltaTime < 0;
24924
24999
  var step = 15;
24925
25000
  var t = Math.abs(deltaTime);
24926
25001
  var ss = reverse ? -step : step;
24927
25002
  for(t; t > step; t -= step){
24928
- this.update(ss, skipRender);
25003
+ this.update(ss);
24929
25004
  }
24930
- this.update(reverse ? -t : t, skipRender);
25005
+ this.update(reverse ? -t : t);
24931
25006
  };
24932
25007
  /**
24933
25008
  * 重置状态函数
@@ -24965,74 +25040,68 @@ var listOrder = 0;
24965
25040
  }
24966
25041
  };
24967
25042
  /**
24968
- * 是否合成需要重新播放
24969
- * @returns 重新播放合成标志位
24970
- */ _proto.shouldRestart = function shouldRestart() {
24971
- var _this_rootItem = this.rootItem, ended = _this_rootItem.ended, endBehavior = _this_rootItem.endBehavior;
24972
- return ended && endBehavior === EndBehavior.restart;
24973
- };
24974
- /**
24975
- * 是否合成需要销毁
24976
- * @returns 销毁合成标志位
24977
- */ _proto.shouldDispose = function shouldDispose() {
24978
- if (this.reusable) {
24979
- return false;
24980
- }
24981
- var _this_rootItem = this.rootItem, ended = _this_rootItem.ended, endBehavior = _this_rootItem.endBehavior;
24982
- // TODO: 合成结束行为
24983
- return ended && (!endBehavior || endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY);
24984
- };
24985
- /**
24986
25043
  * 合成更新,针对所有 item 的更新
24987
25044
  * @param deltaTime - 更新的时间步长
24988
25045
  * @param skipRender - 是否需要渲染
24989
- */ _proto.update = function update(deltaTime, skipRender) {
24990
- if (skipRender === void 0) skipRender = false;
25046
+ */ _proto.update = function update(deltaTime) {
24991
25047
  if (!this.assigned || this.paused) {
24992
25048
  return;
24993
25049
  }
24994
- if (this.shouldRestart()) {
24995
- this.restart();
24996
- // restart then tick to avoid flicker
24997
- }
24998
25050
  var time = this.getUpdateTime(deltaTime * this.speed);
24999
25051
  this.globalTime += time;
25000
- if (this.rootComposition.isActiveAndEnabled) {
25001
- var localTime = this.toLocalTime(this.globalTime / 1000);
25002
- this.rootComposition.time = localTime;
25003
- }
25052
+ this.updateRootComposition();
25004
25053
  this.updateVideo();
25005
25054
  // 更新 model-tree-plugin
25006
25055
  this.updatePluginLoaders(deltaTime);
25056
+ // scene VFXItem components lifetime function.
25007
25057
  this.callStart(this.rootItem);
25008
25058
  this.callUpdate(this.rootItem, time);
25009
25059
  this.callLateUpdate(this.rootItem, time);
25010
- // this.extraCamera?.getComponent(TimelineComponent)?.update(deltaTime);
25011
25060
  this.updateCamera();
25061
+ this.prepareRender();
25012
25062
  if (this.shouldDispose()) {
25013
- this.onEnd == null ? void 0 : this.onEnd.call(this, this);
25014
25063
  this.dispose();
25015
- } else {
25016
- if (!skipRender) {
25017
- this.prepareRender();
25018
- }
25019
25064
  }
25020
25065
  };
25021
25066
  _proto.toLocalTime = function toLocalTime(time) {
25022
25067
  var localTime = time - this.rootItem.start;
25023
25068
  var duration = this.rootItem.duration;
25024
25069
  if (localTime - duration > 0.001) {
25025
- if (this.rootItem.endBehavior === EndBehavior.restart) {
25026
- localTime = localTime % duration;
25027
- } else if (this.rootItem.endBehavior === EndBehavior.freeze) {
25028
- localTime = Math.min(duration, localTime);
25070
+ if (!this.rootItem.ended) {
25071
+ this.rootItem.ended = true;
25072
+ this.emit("end", {
25073
+ composition: this
25074
+ });
25075
+ }
25076
+ switch(this.rootItem.endBehavior){
25077
+ case EndBehavior.restart:
25078
+ {
25079
+ localTime = localTime % duration;
25080
+ this.restart();
25081
+ break;
25082
+ }
25083
+ case EndBehavior.freeze:
25084
+ {
25085
+ localTime = Math.min(duration, localTime);
25086
+ break;
25087
+ }
25088
+ case EndBehavior.forward:
25089
+ {
25090
+ break;
25091
+ }
25092
+ case EndBehavior.destroy:
25093
+ {
25094
+ break;
25095
+ }
25029
25096
  }
25030
25097
  }
25031
25098
  return localTime;
25032
25099
  };
25100
+ _proto.shouldDispose = function shouldDispose() {
25101
+ return this.rootItem.ended && this.rootItem.endBehavior === EndBehavior.destroy && !this.reusable;
25102
+ };
25033
25103
  _proto.getUpdateTime = function getUpdateTime(t) {
25034
25104
  var startTimeInMs = this.startTime * 1000;
25035
- // const content = this.rootItem;
25036
25105
  var now = this.rootComposition.time * 1000;
25037
25106
  if (t < 0 && now + t < startTimeInMs) {
25038
25107
  return startTimeInMs - now;
@@ -25180,6 +25249,14 @@ var listOrder = 0;
25180
25249
  });
25181
25250
  };
25182
25251
  /**
25252
+ * 更新主合成组件
25253
+ */ _proto.updateRootComposition = function updateRootComposition() {
25254
+ if (this.rootComposition.isActiveAndEnabled) {
25255
+ var localTime = this.toLocalTime(this.globalTime / 1000);
25256
+ this.rootComposition.time = localTime;
25257
+ }
25258
+ };
25259
+ /**
25183
25260
  * 通过名称获取元素
25184
25261
  * @param name - 元素名称
25185
25262
  * @returns 元素对象
@@ -25228,12 +25305,17 @@ var listOrder = 0;
25228
25305
  * @param type - 交互类型
25229
25306
  */ _proto.addInteractiveItem = function addInteractiveItem(item, type) {
25230
25307
  if (type === InteractType.MESSAGE) {
25231
- this.onMessageItem == null ? void 0 : this.onMessageItem.call(this, {
25308
+ this.handleItemMessage({
25232
25309
  name: item.name,
25233
25310
  phrase: MESSAGE_ITEM_PHRASE_BEGIN,
25234
25311
  id: item.id,
25235
25312
  compositionId: this.id
25236
25313
  });
25314
+ item.emit("message", {
25315
+ name: item.name,
25316
+ phrase: MESSAGE_ITEM_PHRASE_BEGIN,
25317
+ id: item.id
25318
+ });
25237
25319
  return item.id;
25238
25320
  }
25239
25321
  };
@@ -25242,14 +25324,19 @@ var listOrder = 0;
25242
25324
  * @param item - 交互元素
25243
25325
  * @param type - 交互类型
25244
25326
  */ _proto.removeInteractiveItem = function removeInteractiveItem(item, type) {
25245
- // MESSAGE ITEM的结束行为
25327
+ // MESSAGE ITEM 的结束行为
25246
25328
  if (type === InteractType.MESSAGE) {
25247
- this.onMessageItem == null ? void 0 : this.onMessageItem.call(this, {
25329
+ this.handleItemMessage({
25248
25330
  name: item.name,
25249
25331
  phrase: MESSAGE_ITEM_PHRASE_END,
25250
25332
  id: item.id,
25251
25333
  compositionId: this.id
25252
25334
  });
25335
+ item.emit("message", {
25336
+ name: item.name,
25337
+ phrase: MESSAGE_ITEM_PHRASE_END,
25338
+ id: item.id
25339
+ });
25253
25340
  }
25254
25341
  };
25255
25342
  /**
@@ -25343,9 +25430,10 @@ var listOrder = 0;
25343
25430
  (_this_rendererOptions = this.rendererOptions) == null ? void 0 : _this_rendererOptions.emptyTexture.dispose();
25344
25431
  (_this_pluginSystem = this.pluginSystem) == null ? void 0 : _this_pluginSystem.destroyComposition(this);
25345
25432
  this.update = function() {
25346
- logger.error("Update disposed composition: " + _this.name + ".");
25433
+ {
25434
+ logger.error("Update disposed composition: " + _this.name + ".");
25435
+ }
25347
25436
  };
25348
- this.onPlayerPause = noop;
25349
25437
  this.dispose = noop;
25350
25438
  if (textures && this.keepResource) {
25351
25439
  textures.forEach(function(tex) {
@@ -25543,7 +25631,7 @@ var listOrder = 0;
25543
25631
  }
25544
25632
  ]);
25545
25633
  return Composition;
25546
- }();
25634
+ }(EventEmitter);
25547
25635
 
25548
25636
  var SIZEOF_SHORT = 2;
25549
25637
  var SIZEOF_INT = 4;
@@ -27507,7 +27595,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
27507
27595
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
27508
27596
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
27509
27597
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
27510
- var version$1 = "2.0.0-alpha.31";
27598
+ var version$1 = "2.0.0-alpha.33";
27511
27599
  logger.info("Core version: " + version$1 + ".");
27512
27600
 
27513
27601
  var _obj;
@@ -27581,6 +27669,13 @@ var _obj3;
27581
27669
  */ _this.uniforms = {};
27582
27670
  var shader = props == null ? void 0 : props.shader;
27583
27671
  var level = engine.gpuCapability.level;
27672
+ _this.shader = new exports.Shader(engine);
27673
+ _this.shader.shaderData = _extends({}, shader, {
27674
+ id: generateGUID(),
27675
+ dataType: DataType.Shader,
27676
+ vertex: (shader == null ? void 0 : shader.vertex) || "",
27677
+ fragment: (shader == null ? void 0 : shader.fragment) || ""
27678
+ });
27584
27679
  for(var i = 0; i < exports.maxSpriteMeshItemCount; i++){
27585
27680
  _this.uniforms["uSampler" + i] = new THREE__namespace.Uniform(null);
27586
27681
  }
@@ -28761,6 +28856,8 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
28761
28856
  var _this;
28762
28857
  _this = Renderer.call(this) || this;
28763
28858
  _this.engine = new ThreeEngine(gl);
28859
+ _this.engine.renderer = _assert_this_initialized(_this);
28860
+ _this.env = "";
28764
28861
  _this.renderingData = {
28765
28862
  //@ts-expect-error
28766
28863
  currentFrame: {}
@@ -28788,8 +28885,8 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
28788
28885
  var _this;
28789
28886
  _this = _THREE_Group.call(this) || this;
28790
28887
  _this.compositions = [];
28791
- _this.baseCompositionIndex = 0;
28792
28888
  _this.env = "";
28889
+ _this.baseCompositionIndex = 0;
28793
28890
  var width = options.width, height = options.height, camera = options.camera;
28794
28891
  _this.renderer = new ThreeRenderer(context);
28795
28892
  _this.width = width;
@@ -28858,6 +28955,19 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
28858
28955
  });
28859
28956
  })();
28860
28957
  };
28958
+ _proto.pause = function pause() {
28959
+ this.dispatchEvent({
28960
+ type: "pause"
28961
+ });
28962
+ this.compositions.forEach(function(composition) {
28963
+ composition.pause();
28964
+ });
28965
+ };
28966
+ _proto.resume = function resume() {
28967
+ this.compositions.forEach(function(composition) {
28968
+ composition.resume();
28969
+ });
28970
+ };
28861
28971
  _proto.createComposition = function createComposition(url, options) {
28862
28972
  if (options === void 0) options = {};
28863
28973
  var _this = this;
@@ -28914,8 +29024,20 @@ var ThreeRenderer = /*#__PURE__*/ function(Renderer) {
28914
29024
  composition = new ThreeComposition(_extends({}, opts, {
28915
29025
  width: _this.width,
28916
29026
  height: _this.height,
28917
- renderer: _this.renderer
29027
+ renderer: _this.renderer,
29028
+ handleItemMessage: function(message) {
29029
+ _this.dispatchEvent({
29030
+ type: "message",
29031
+ message: message
29032
+ });
29033
+ }
28918
29034
  }), scene);
29035
+ composition.on("end", function() {
29036
+ _this.dispatchEvent({
29037
+ type: "end",
29038
+ composition: composition
29039
+ });
29040
+ });
28919
29041
  _this.renderer.engine.setOptions({
28920
29042
  threeCamera: _this.camera,
28921
29043
  threeGroup: _this,
@@ -29140,7 +29262,7 @@ setMaxSpriteMeshItemCount(8);
29140
29262
  */ Mesh.create = function(engine, props) {
29141
29263
  return new ThreeMesh(engine, props);
29142
29264
  };
29143
- var version = "2.0.0-alpha.31";
29265
+ var version = "2.0.0-alpha.33";
29144
29266
  logger.info("THREEJS plugin version: " + version + ".");
29145
29267
 
29146
29268
  exports.AbstractPlugin = AbstractPlugin;
@@ -29178,6 +29300,7 @@ exports.EVENT_TYPE_TOUCH_START = EVENT_TYPE_TOUCH_START;
29178
29300
  exports.EffectsObject = EffectsObject;
29179
29301
  exports.EffectsPackage = EffectsPackage;
29180
29302
  exports.Engine = Engine;
29303
+ exports.EventEmitter = EventEmitter;
29181
29304
  exports.EventSystem = EventSystem;
29182
29305
  exports.Float16ArrayWrapper = Float16ArrayWrapper;
29183
29306
  exports.Framebuffer = Framebuffer;