@galacean/effects-core 2.0.0-alpha.13 → 2.0.0-alpha.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.0.0-alpha.13
6
+ * Version: v2.0.0-alpha.14
7
7
  */
8
8
 
9
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
@@ -17448,6 +17448,9 @@ class ActivationPlayableAsset extends PlayableAsset {
17448
17448
  return new ActivationPlayable(graph);
17449
17449
  }
17450
17450
  }
17451
+ ActivationPlayableAsset = __decorate([
17452
+ effectsClass('ActivationPlayableAsset')
17453
+ ], ActivationPlayableAsset);
17451
17454
  class AnimationClip extends EffectsObject {
17452
17455
  sampleAnimation(vfxItem, time) {
17453
17456
  const duration = vfxItem.duration;
@@ -17595,6 +17598,9 @@ class TrackAsset extends PlayableAsset {
17595
17598
  getChildTracks() {
17596
17599
  return this.children;
17597
17600
  }
17601
+ addChild(child) {
17602
+ this.children.push(child);
17603
+ }
17598
17604
  createClip(classConstructor, name) {
17599
17605
  const newClip = new TimelineClip();
17600
17606
  newClip.asset = new classConstructor(this.engine);
@@ -17676,9 +17682,10 @@ class RuntimeClip {
17676
17682
  let weight = 1.0;
17677
17683
  let ended = false;
17678
17684
  let started = false;
17685
+ const boundItem = this.track.binding;
17679
17686
  if (localTime > clip.start + clip.duration + 0.001 && clip.endBehaviour === ItemEndBehavior.destroy) {
17680
- var _this_track_binding_getComponent;
17681
- if (VFXItem.isParticle(this.track.binding) && !((_this_track_binding_getComponent = this.track.binding.getComponent(ParticleSystem)) == null ? void 0 : _this_track_binding_getComponent.destroyed)) {
17687
+ var _boundItem_getComponent;
17688
+ if (VFXItem.isParticle(boundItem) && !((_boundItem_getComponent = boundItem.getComponent(ParticleSystem)) == null ? void 0 : _boundItem_getComponent.destroyed)) {
17682
17689
  weight = 1.0;
17683
17690
  } else {
17684
17691
  weight = 0.0;
@@ -17694,7 +17701,6 @@ class RuntimeClip {
17694
17701
  this.playable.play();
17695
17702
  }
17696
17703
  this.parentMixer.setInputWeight(this.playable, weight);
17697
- const boundItem = this.track.binding;
17698
17704
  // 判断动画是否结束
17699
17705
  if (ended && !boundItem.ended) {
17700
17706
  boundItem.ended = true;
@@ -17723,6 +17729,53 @@ class RuntimeClip {
17723
17729
  }
17724
17730
  }
17725
17731
 
17732
+ class ObjectBindingTrack extends TrackAsset {
17733
+ create(timelineAsset) {
17734
+ const boundItem = this.binding;
17735
+ this.options = {
17736
+ start: boundItem.start,
17737
+ duration: boundItem.duration,
17738
+ looping: boundItem.endBehavior === ItemEndBehavior.loop,
17739
+ endBehavior: boundItem.endBehavior || ItemEndBehavior.destroy
17740
+ };
17741
+ this.name = boundItem.name;
17742
+ // 添加粒子动画 clip
17743
+ if (boundItem.getComponent(ParticleSystem)) {
17744
+ const particleTrack = timelineAsset.createTrack(TrackAsset, this, 'ParticleTrack');
17745
+ particleTrack.binding = this.binding;
17746
+ const particleClip = particleTrack.createClip(ParticleBehaviourPlayableAsset);
17747
+ particleClip.start = boundItem.start;
17748
+ particleClip.duration = boundItem.duration;
17749
+ particleClip.endBehaviour = boundItem.endBehavior;
17750
+ }
17751
+ }
17752
+ toLocalTime(time) {
17753
+ let localTime = time - this.options.start;
17754
+ const duration = this.options.duration;
17755
+ if (localTime - duration > 0.001) {
17756
+ if (this.options.endBehavior === END_BEHAVIOR_RESTART) {
17757
+ localTime = localTime % duration;
17758
+ } else if (this.options.endBehavior === END_BEHAVIOR_FREEZE) {
17759
+ localTime = Math.min(duration, localTime);
17760
+ }
17761
+ }
17762
+ return localTime;
17763
+ }
17764
+ fromData(data) {
17765
+ super.fromData(data);
17766
+ this.data = data;
17767
+ }
17768
+ }
17769
+ ObjectBindingTrack = __decorate([
17770
+ effectsClass('ObjectBindingTrack')
17771
+ ], ObjectBindingTrack);
17772
+
17773
+ class TransformTrack extends TrackAsset {
17774
+ }
17775
+ TransformTrack = __decorate([
17776
+ effectsClass('TransformTrack')
17777
+ ], TransformTrack);
17778
+
17726
17779
  class ActivationMixerPlayable extends Playable {
17727
17780
  processFrame(context) {
17728
17781
  if (!this.bindingItem) {
@@ -17764,6 +17817,9 @@ class ActivationMixerPlayable extends Playable {
17764
17817
  }
17765
17818
 
17766
17819
  class ActivationTrack extends TrackAsset {
17820
+ initializeBinding(parentBinding) {
17821
+ this.binding = parentBinding;
17822
+ }
17767
17823
  createTrackMixer(graph) {
17768
17824
  return new ActivationMixerPlayable(graph);
17769
17825
  }
@@ -17772,73 +17828,6 @@ ActivationTrack = __decorate([
17772
17828
  effectsClass('ActivationTrack')
17773
17829
  ], ActivationTrack);
17774
17830
 
17775
- class ObjectBindingTrack extends TrackAsset {
17776
- create() {
17777
- this.options = {
17778
- start: this.binding.start,
17779
- duration: this.binding.duration,
17780
- looping: this.binding.endBehavior === ItemEndBehavior.loop,
17781
- endBehavior: this.binding.endBehavior || ItemEndBehavior.destroy
17782
- };
17783
- this.id = this.binding.id;
17784
- this.name = this.binding.name;
17785
- const activationTrack = this.createTrack(ActivationTrack, 'ActivationTrack');
17786
- activationTrack.binding = this.binding;
17787
- activationTrack.createClip(ActivationPlayableAsset, 'ActivationTimelineClip');
17788
- // 添加粒子动画 clip
17789
- if (this.binding.getComponent(ParticleSystem)) {
17790
- const particleTrack = this.createTrack(TrackAsset, 'ParticleTrack');
17791
- particleTrack.binding = this.binding;
17792
- particleTrack.createClip(ParticleBehaviourPlayableAsset);
17793
- }
17794
- // TODO TimelineClip 需要传入 start 和 duration 数据
17795
- for (const track of this.children){
17796
- for (const clip of track.getClips()){
17797
- clip.start = this.binding.start;
17798
- clip.duration = this.binding.duration;
17799
- clip.endBehaviour = this.binding.endBehavior;
17800
- }
17801
- }
17802
- }
17803
- toLocalTime(time) {
17804
- let localTime = time - this.options.start;
17805
- const duration = this.options.duration;
17806
- if (localTime - duration > 0.001) {
17807
- if (this.options.endBehavior === END_BEHAVIOR_RESTART) {
17808
- localTime = localTime % duration;
17809
- } else if (this.options.endBehavior === END_BEHAVIOR_FREEZE) {
17810
- localTime = Math.min(duration, localTime);
17811
- }
17812
- }
17813
- return localTime;
17814
- }
17815
- createTrack(classConstructor, name) {
17816
- const newTrack = new classConstructor(this.engine);
17817
- newTrack.binding = this.binding;
17818
- newTrack.id = (this.trackSeed++).toString();
17819
- newTrack.name = name ? name : 'Track' + newTrack.id;
17820
- this.children.push(newTrack);
17821
- return newTrack;
17822
- }
17823
- fromData(data) {
17824
- super.fromData(data);
17825
- this.data = data;
17826
- }
17827
- constructor(...args){
17828
- super(...args);
17829
- this.trackSeed = 0;
17830
- }
17831
- }
17832
- ObjectBindingTrack = __decorate([
17833
- effectsClass('ObjectBindingTrack')
17834
- ], ObjectBindingTrack);
17835
-
17836
- class TransformTrack extends TrackAsset {
17837
- }
17838
- TransformTrack = __decorate([
17839
- effectsClass('TransformTrack')
17840
- ], TransformTrack);
17841
-
17842
17831
  class SpriteColorTrack extends TrackAsset {
17843
17832
  }
17844
17833
  SpriteColorTrack = __decorate([
@@ -17850,17 +17839,29 @@ class TimelineAsset extends PlayableAsset {
17850
17839
  this.graph = graph;
17851
17840
  const timelinePlayable = new TimelinePlayable(graph);
17852
17841
  timelinePlayable.setTraversalMode(PlayableTraversalMode.Passthrough);
17842
+ for (const track of this.tracks){
17843
+ if (track instanceof ObjectBindingTrack) {
17844
+ track.create(this);
17845
+ }
17846
+ }
17853
17847
  timelinePlayable.compileTracks(graph, this.tracks);
17854
17848
  return timelinePlayable;
17855
17849
  }
17856
- fromData(data) {
17857
- this.tracks = data.tracks;
17850
+ createTrack(classConstructor, parent, name) {
17851
+ const newTrack = new classConstructor(this.engine);
17852
+ newTrack.name = name ? name : classConstructor.name;
17853
+ parent.addChild(newTrack);
17854
+ return newTrack;
17858
17855
  }
17856
+ fromData(data) {}
17859
17857
  constructor(...args){
17860
17858
  super(...args);
17861
17859
  this.tracks = [];
17862
17860
  }
17863
17861
  }
17862
+ __decorate([
17863
+ serialize()
17864
+ ], TimelineAsset.prototype, "tracks", void 0);
17864
17865
  TimelineAsset = __decorate([
17865
17866
  effectsClass('TimelineAsset')
17866
17867
  ], TimelineAsset);
@@ -17877,12 +17878,6 @@ class TimelinePlayable extends Playable {
17877
17878
  }
17878
17879
  compileTracks(graph, tracks) {
17879
17880
  this.sortTracks(tracks);
17880
- for (const track of tracks){
17881
- if (track instanceof ObjectBindingTrack) {
17882
- track.create();
17883
- }
17884
- this.masterTracks.push(track);
17885
- }
17886
17881
  const outputTrack = [];
17887
17882
  for (const masterTrack of tracks){
17888
17883
  outputTrack.push(masterTrack);
@@ -17919,7 +17914,6 @@ class TimelinePlayable extends Playable {
17919
17914
  constructor(...args){
17920
17915
  super(...args);
17921
17916
  this.clips = [];
17922
- this.masterTracks = [];
17923
17917
  }
17924
17918
  }
17925
17919
  class TrackSortWrapper {
@@ -17939,9 +17933,14 @@ function isAncestor(ancestorCandidate, descendantCandidate) {
17939
17933
  return false;
17940
17934
  }
17941
17935
  function compareTracks(a, b) {
17942
- if (isAncestor(a.track.binding, b.track.binding)) {
17936
+ const bindingA = a.track.binding;
17937
+ const bindingB = b.track.binding;
17938
+ if (!(bindingA instanceof VFXItem) || !(bindingB instanceof VFXItem)) {
17939
+ return a.originalIndex - b.originalIndex;
17940
+ }
17941
+ if (isAncestor(bindingA, bindingB)) {
17943
17942
  return -1;
17944
- } else if (isAncestor(b.track.binding, a.track.binding)) {
17943
+ } else if (isAncestor(bindingB, bindingA)) {
17945
17944
  return 1;
17946
17945
  } else {
17947
17946
  return a.originalIndex - b.originalIndex; // 非父子关系的元素保持原始顺序
@@ -20651,7 +20650,7 @@ function getStandardCameraContent(model) {
20651
20650
  content.renderer.anchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
20652
20651
  }
20653
20652
  // 修复相机K帧缺失 asMovement 参数
20654
- if (item.type === ItemType.camera) {
20653
+ if (item.type === ItemType.camera && item.content.positionOverLifetime && Object.keys(item.content.positionOverLifetime).length !== 0) {
20655
20654
  item.content.positionOverLifetime.asMovement = true;
20656
20655
  }
20657
20656
  // 动画数据转化 TODO: 动画数据移到 TimelineComponentData
@@ -20813,8 +20812,32 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
20813
20812
  for (const itemDataPath of composition.items){
20814
20813
  const item = guidToItemMap[itemDataPath.id];
20815
20814
  const subTrackDatas = [];
20815
+ const newActivationPlayableAsset = {
20816
+ id: generateGUID(),
20817
+ dataType: 'ActivationPlayableAsset'
20818
+ };
20819
+ playableAssetDatas.push(newActivationPlayableAsset);
20820
+ const newActivationTrackData = {
20821
+ id: generateGUID(),
20822
+ dataType: 'ActivationTrack',
20823
+ children: [],
20824
+ clips: [
20825
+ {
20826
+ start: item.delay,
20827
+ duration: item.duration,
20828
+ endBehaviour: item.endBehavior,
20829
+ asset: {
20830
+ id: newActivationPlayableAsset.id
20831
+ }
20832
+ }
20833
+ ]
20834
+ };
20835
+ subTrackDatas.push({
20836
+ id: newActivationTrackData.id
20837
+ });
20838
+ trackDatas.push(newActivationTrackData);
20816
20839
  if (item.type !== ItemType.particle) {
20817
- const newPlayableAssetData = {
20840
+ const newTransformPlayableAssetData = {
20818
20841
  id: generateGUID(),
20819
20842
  dataType: 'TransformPlayableAsset',
20820
20843
  //@ts-expect-error
@@ -20824,15 +20847,18 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
20824
20847
  //@ts-expect-error
20825
20848
  positionOverLifetime: item.content.positionOverLifetime
20826
20849
  };
20827
- playableAssetDatas.push(newPlayableAssetData);
20850
+ playableAssetDatas.push(newTransformPlayableAssetData);
20828
20851
  const newTrackData = {
20829
20852
  id: generateGUID(),
20830
20853
  dataType: 'TransformTrack',
20831
20854
  children: [],
20832
20855
  clips: [
20833
20856
  {
20857
+ start: item.delay,
20858
+ duration: item.duration,
20859
+ endBehaviour: item.endBehavior,
20834
20860
  asset: {
20835
- id: newPlayableAssetData.id
20861
+ id: newTransformPlayableAssetData.id
20836
20862
  }
20837
20863
  }
20838
20864
  ]
@@ -20843,21 +20869,24 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
20843
20869
  trackDatas.push(newTrackData);
20844
20870
  }
20845
20871
  if (item.type === ItemType.sprite) {
20846
- const newPlayableAssetData = {
20872
+ const newSpriteColorPlayableAssetData = {
20847
20873
  id: generateGUID(),
20848
20874
  dataType: 'SpriteColorPlayableAsset',
20849
20875
  colorOverLifetime: item.content.colorOverLifetime,
20850
20876
  startColor: item.content.options.startColor
20851
20877
  };
20852
- playableAssetDatas.push(newPlayableAssetData);
20878
+ playableAssetDatas.push(newSpriteColorPlayableAssetData);
20853
20879
  const newTrackData = {
20854
20880
  id: generateGUID(),
20855
20881
  dataType: 'SpriteColorTrack',
20856
20882
  children: [],
20857
20883
  clips: [
20858
20884
  {
20885
+ start: item.delay,
20886
+ duration: item.duration,
20887
+ endBehaviour: item.endBehavior,
20859
20888
  asset: {
20860
- id: newPlayableAssetData.id
20889
+ id: newSpriteColorPlayableAssetData.id
20861
20890
  }
20862
20891
  }
20863
20892
  ]
@@ -22067,14 +22096,17 @@ const tmpScale = new Vector3(1, 1, 1);
22067
22096
  this.timelinePlayable = this.timelineAsset.createPlayable(this.graph);
22068
22097
  this.timelinePlayable.play();
22069
22098
  for (const track of this.timelineAsset.tracks){
22070
- // 重播不销毁元素
22071
- if (this.item.endBehavior !== ItemEndBehavior.destroy || this.reusable) {
22072
- if (track instanceof ObjectBindingTrack) {
22073
- track.binding.reusable = true;
22074
- }
22075
- const subCompositionComponent = track.binding.getComponent(CompositionComponent);
22076
- if (subCompositionComponent) {
22077
- subCompositionComponent.reusable = true;
22099
+ const binding = track.binding;
22100
+ if (binding instanceof VFXItem) {
22101
+ // 重播不销毁元素
22102
+ if (this.item.endBehavior !== ItemEndBehavior.destroy || this.reusable) {
22103
+ if (track instanceof ObjectBindingTrack) {
22104
+ binding.reusable = true;
22105
+ }
22106
+ const subCompositionComponent = binding.getComponent(CompositionComponent);
22107
+ if (subCompositionComponent) {
22108
+ subCompositionComponent.reusable = true;
22109
+ }
22078
22110
  }
22079
22111
  }
22080
22112
  this.masterTracks.push(track);