@galacean/effects-core 2.0.4 → 2.1.0-alpha.1

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.4
6
+ * Version: v2.1.0-alpha.1
7
7
  */
8
8
 
9
9
  'use strict';
@@ -4607,87 +4607,115 @@ function getDirectStore(target) {
4607
4607
  */ var Component = /*#__PURE__*/ function(EffectsObject) {
4608
4608
  _inherits(Component, EffectsObject);
4609
4609
  function Component() {
4610
- return EffectsObject.apply(this, arguments);
4611
- }
4612
- var _proto = Component.prototype;
4613
- _proto.onAttached = function onAttached() {};
4614
- _proto.onDestroy = function onDestroy() {};
4615
- _proto.fromData = function fromData(data) {
4616
- EffectsObject.prototype.fromData.call(this, data);
4617
- if (data.item) {
4618
- this.item = data.item;
4619
- }
4620
- };
4621
- _proto.dispose = function dispose() {
4622
- this.onDestroy();
4623
- if (this.item) {
4624
- removeItem(this.item.components, this);
4625
- }
4626
- };
4627
- _create_class(Component, [
4628
- {
4629
- key: "transform",
4630
- get: /**
4631
- * 附加到的 VFXItem 对象 Transform 组件
4632
- */ function get() {
4633
- return this.item.transform;
4634
- }
4635
- }
4636
- ]);
4637
- return Component;
4638
- }(EffectsObject);
4639
- /**
4640
- * @since 2.0.0
4641
- */ var Behaviour = /*#__PURE__*/ function(Component) {
4642
- _inherits(Behaviour, Component);
4643
- function Behaviour() {
4644
4610
  var _this;
4645
- _this = Component.apply(this, arguments) || this;
4611
+ _this = EffectsObject.apply(this, arguments) || this;
4646
4612
  _this.isAwakeCalled = false;
4647
4613
  _this.isStartCalled = false;
4614
+ _this.isEnableCalled = false;
4648
4615
  _this._enabled = true;
4649
4616
  return _this;
4650
4617
  }
4651
- var _proto = Behaviour.prototype;
4618
+ var _proto = Component.prototype;
4652
4619
  /**
4653
4620
  * 生命周期函数,初始化后调用,生命周期内只调用一次
4654
- */ _proto.awake = function awake() {
4621
+ */ _proto.onAwake = function onAwake() {
4655
4622
  // OVERRIDE
4656
4623
  };
4657
4624
  /**
4658
- * 在每次设置 enabled true 时触发
4625
+ * enabled 变为 true 时触发
4659
4626
  */ _proto.onEnable = function onEnable() {
4660
4627
  // OVERRIDE
4661
4628
  };
4662
4629
  /**
4630
+ * 在 enabled 变为 false 时触发
4631
+ */ _proto.onDisable = function onDisable() {
4632
+ // OVERRIDE
4633
+ };
4634
+ /**
4663
4635
  * 生命周期函数,在第一次 update 前调用,生命周期内只调用一次
4664
- */ _proto.start = function start() {
4636
+ */ _proto.onStart = function onStart() {
4665
4637
  // OVERRIDE
4666
4638
  };
4667
4639
  /**
4668
4640
  * 生命周期函数,每帧调用一次
4669
- */ _proto.update = function update(dt) {
4641
+ */ _proto.onUpdate = function onUpdate(dt) {
4670
4642
  // OVERRIDE
4671
4643
  };
4672
4644
  /**
4673
4645
  * 生命周期函数,每帧调用一次,在 update 之后调用
4674
- */ _proto.lateUpdate = function lateUpdate(dt) {
4646
+ */ _proto.onLateUpdate = function onLateUpdate(dt) {
4675
4647
  // OVERRIDE
4676
4648
  };
4677
- _proto.onAttached = function onAttached() {
4678
- this.item.itemBehaviours.push(this);
4679
- if (!this.isAwakeCalled) {
4680
- this.awake();
4681
- this.isAwakeCalled = true;
4649
+ /**
4650
+ * 生命周期函数,在组件销毁时调用
4651
+ */ _proto.onDestroy = function onDestroy() {
4652
+ // OVERRIDE
4653
+ };
4654
+ /**
4655
+ * @internal
4656
+ */ _proto.enable = function enable() {
4657
+ if (this.item.composition) {
4658
+ this.item.composition.sceneTicking.addComponent(this);
4659
+ this.isEnableCalled = true;
4660
+ }
4661
+ this.onEnable();
4662
+ };
4663
+ /**
4664
+ * @internal
4665
+ */ _proto.disable = function disable() {
4666
+ this.onDisable();
4667
+ if (this.item.composition) {
4668
+ this.isEnableCalled = false;
4669
+ this.item.composition.sceneTicking.removeComponent(this);
4670
+ }
4671
+ };
4672
+ _proto.setVFXItem = function setVFXItem(item) {
4673
+ this.item = item;
4674
+ if (item.isDuringPlay) {
4675
+ if (!this.isAwakeCalled) {
4676
+ this.onAwake();
4677
+ this.isAwakeCalled = true;
4678
+ }
4679
+ if (item.getVisible() && this.enabled) {
4680
+ this.start();
4681
+ this.enable();
4682
+ }
4683
+ }
4684
+ };
4685
+ _proto.fromData = function fromData(data) {
4686
+ EffectsObject.prototype.fromData.call(this, data);
4687
+ if (data.item) {
4688
+ this.item = data.item;
4682
4689
  }
4683
4690
  };
4684
4691
  _proto.dispose = function dispose() {
4692
+ if (this.isEnableCalled) {
4693
+ this.disable();
4694
+ }
4695
+ if (this.isAwakeCalled) {
4696
+ this.isAwakeCalled = false;
4697
+ this.onDestroy();
4698
+ }
4685
4699
  if (this.item) {
4686
- removeItem(this.item.itemBehaviours, this);
4700
+ removeItem(this.item.components, this);
4687
4701
  }
4688
- Component.prototype.dispose.call(this);
4689
4702
  };
4690
- _create_class(Behaviour, [
4703
+ _proto.start = function start() {
4704
+ if (this.isStartCalled) {
4705
+ return;
4706
+ }
4707
+ this.isStartCalled = true;
4708
+ this.onStart();
4709
+ };
4710
+ _create_class(Component, [
4711
+ {
4712
+ key: "transform",
4713
+ get: /**
4714
+ * 附加到的 VFXItem 对象 Transform 组件
4715
+ */ function get() {
4716
+ return this.item.transform;
4717
+ }
4718
+ },
4691
4719
  {
4692
4720
  key: "isActiveAndEnabled",
4693
4721
  get: /**
@@ -4702,24 +4730,46 @@ function getDirectStore(target) {
4702
4730
  return this._enabled;
4703
4731
  },
4704
4732
  set: function set(value) {
4705
- this._enabled = value;
4706
- if (value) {
4707
- if (this.isActiveAndEnabled) {
4708
- this.onEnable();
4709
- }
4710
- if (!this.isStartCalled) {
4711
- this.start();
4712
- this.isStartCalled = true;
4733
+ if (this.enabled !== value) {
4734
+ this._enabled = value;
4735
+ if (value) {
4736
+ if (this.isActiveAndEnabled) {
4737
+ this.enable();
4738
+ if (!this.isStartCalled) {
4739
+ this.onStart();
4740
+ this.isStartCalled = true;
4741
+ }
4742
+ }
4743
+ } else {
4744
+ if (this.isEnableCalled) {
4745
+ this.disable();
4746
+ }
4713
4747
  }
4714
4748
  }
4715
4749
  }
4716
4750
  }
4717
4751
  ]);
4718
- return Behaviour;
4719
- }(Component);
4752
+ return Component;
4753
+ }(EffectsObject);
4720
4754
  __decorate([
4721
4755
  serialize()
4722
- ], Behaviour.prototype, "_enabled", void 0);
4756
+ ], Component.prototype, "_enabled", void 0);
4757
+ /**
4758
+ * @since 2.0.0
4759
+ */ var Behaviour = /*#__PURE__*/ function(Component) {
4760
+ _inherits(Behaviour, Component);
4761
+ function Behaviour() {
4762
+ return Component.apply(this, arguments);
4763
+ }
4764
+ var _proto = Behaviour.prototype;
4765
+ _proto.setVFXItem = function setVFXItem(item) {
4766
+ Component.prototype.setVFXItem.call(this, item);
4767
+ };
4768
+ _proto.dispose = function dispose() {
4769
+ Component.prototype.dispose.call(this);
4770
+ };
4771
+ return Behaviour;
4772
+ }(Component);
4723
4773
 
4724
4774
  /**
4725
4775
  * 所有渲染组件的基类
@@ -4729,19 +4779,14 @@ __decorate([
4729
4779
  function RendererComponent() {
4730
4780
  var _this;
4731
4781
  _this = Component.apply(this, arguments) || this;
4732
- _this.isStartCalled = false;
4733
4782
  _this.materials = [];
4734
4783
  _this._priority = 0;
4735
- _this._enabled = true;
4736
4784
  return _this;
4737
4785
  }
4738
4786
  var _proto = RendererComponent.prototype;
4739
- _proto.onEnable = function onEnable() {};
4740
- _proto.start = function start() {};
4741
- _proto.update = function update(dt) {};
4742
- _proto.lateUpdate = function lateUpdate(dt) {};
4743
4787
  _proto.render = function render(renderer) {};
4744
- _proto.onAttached = function onAttached() {
4788
+ _proto.setVFXItem = function setVFXItem(item) {
4789
+ Component.prototype.setVFXItem.call(this, item);
4745
4790
  this.item.rendererComponents.push(this);
4746
4791
  };
4747
4792
  _proto.fromData = function fromData(data) {
@@ -4766,26 +4811,6 @@ __decorate([
4766
4811
  this._priority = value;
4767
4812
  }
4768
4813
  },
4769
- {
4770
- key: "enabled",
4771
- get: function get() {
4772
- return this._enabled;
4773
- },
4774
- set: function set(value) {
4775
- this._enabled = value;
4776
- if (value) {
4777
- this.onEnable();
4778
- }
4779
- }
4780
- },
4781
- {
4782
- key: "isActiveAndEnabled",
4783
- get: /**
4784
- * 组件是否可以更新,true 更新,false 不更新
4785
- */ function get() {
4786
- return this.item.getVisible() && this.enabled;
4787
- }
4788
- },
4789
4814
  {
4790
4815
  key: "material",
4791
4816
  get: function get() {
@@ -4808,9 +4833,6 @@ __decorate([
4808
4833
  __decorate([
4809
4834
  serialize()
4810
4835
  ], RendererComponent.prototype, "_priority", void 0);
4811
- __decorate([
4812
- serialize()
4813
- ], RendererComponent.prototype, "_enabled", void 0);
4814
4836
 
4815
4837
  /**
4816
4838
  * 抽象插件类
@@ -4854,7 +4876,7 @@ exports.CameraController = /*#__PURE__*/ function(Behaviour) {
4854
4876
  return _this;
4855
4877
  }
4856
4878
  var _proto = CameraController.prototype;
4857
- _proto.update = function update() {
4879
+ _proto.onUpdate = function onUpdate() {
4858
4880
  if (this.item.composition && this.item.transform.getValid()) {
4859
4881
  var camera = this.item.composition.camera;
4860
4882
  camera.near = this.options.near;
@@ -10014,8 +10036,13 @@ var RandomValue = /*#__PURE__*/ function(ValueGetter) {
10014
10036
  this.min = props[0];
10015
10037
  this.max = props[1];
10016
10038
  };
10017
- _proto.getValue = function getValue(time) {
10018
- return randomInRange(this.min, this.max);
10039
+ _proto.getValue = function getValue(time, seed) {
10040
+ var randomSeed = seed != null ? seed : Math.random();
10041
+ return this.min + randomSeed * (this.max - this.min);
10042
+ };
10043
+ _proto.getIntegrateValue = function getIntegrateValue(t0, t1, timeScale) {
10044
+ var seed = timeScale != null ? timeScale : 1.0;
10045
+ return (this.min + seed * (this.max - this.min)) * (t1 - t0);
10019
10046
  };
10020
10047
  _proto.toUniform = function toUniform() {
10021
10048
  return new Float32Array([
@@ -11542,7 +11569,7 @@ var itemFrag = "precision highp float;varying vec4 vColor;varying vec2 vTexCoord
11542
11569
 
11543
11570
  var particleFrag = "#version 100\nprecision mediump float;vec4 blendColor(vec4 color,vec4 vc,float mode){vec4 ret=color*vc;float alpha=ret.a;if(mode==1.){ret.rgb*=alpha;}else if(mode==2.){ret.rgb*=alpha;ret.a=dot(ret.rgb,vec3(0.33333333));}else if(mode==3.){alpha=color.r*alpha;ret=vec4(vc.rgb*alpha,alpha);}return ret;}\n#define PATICLE_SHADER 1\nvarying float vLife;varying vec2 vTexCoord;varying vec4 vColor;uniform vec3 emissionColor;uniform float emissionIntensity;uniform sampler2D uMaskTex;uniform vec4 uColorParams;uniform vec2 uTexOffset;\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#ifdef USE_SPRITE\nvarying vec4 vTexCoordBlend;\n#endif\nvarying float vSeed;\n#ifdef PREVIEW_BORDER\nuniform vec4 uPreviewColor;\n#endif\n#ifdef USE_SPRITE\nvec4 getTextureColor(sampler2D tex,vec2 texCoord){if(vTexCoordBlend.w>0.){return mix(texture2D(tex,texCoord),texture2D(tex,vTexCoordBlend.xy+texCoord),vTexCoordBlend.z);}return texture2D(tex,texCoord);}\n#else\n#define getTextureColor texture2D\n#endif\n#ifndef WEBGL2\n#define round(a) floor(0.5+a)\n#endif\n#ifdef PREVIEW_BORDER\nvoid main(){gl_FragColor=uPreviewColor;}\n#else\nvoid main(){vec4 color=vec4(1.0);vec4 tempColor=vColor;vec2 texOffset=uTexOffset;if(vLife<0.){discard;}if(uColorParams.x>0.0){color=getTextureColor(uMaskTex,vTexCoord);}\n#ifdef COLOR_OVER_LIFETIME\n#ifndef ENABLE_VERTEX_TEXTURE\ntempColor*=texture2D(uColorOverLifetime,vec2(vLife,0.));\n#endif\n#endif\ncolor=blendColor(color,tempColor,round(uColorParams.y));if(color.a<=0.01&&uColorParams.w>0.){float _at=texture2D(uMaskTex,vTexCoord+texOffset).a+texture2D(uMaskTex,vTexCoord+texOffset*-1.).a;if(_at<=0.02){discard;}}vec3 emission=emissionColor*pow(2.0,emissionIntensity);color=vec4(pow(pow(color.rgb,vec3(2.2))+emission,vec3(1.0/2.2)),color.a);gl_FragColor=color;}\n#endif\n";
11544
11571
 
11545
- var particleVert = "#version 100\nprecision mediump float;\n#define SHADER_VERTEX 1\n#define PATICLE_SHADER 1\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nattribute float aSeed;varying float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<8;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}float calculateMovement(float t,vec2 p1,vec2 p2,vec2 p3,vec2 p4){float movement=0.0;float h=(t-p1.x)*0.05;for(int i=0;i<=20;i++){float t=float(i)*h;float nt=binarySearchT(t,p1.x,p2.x,p3.x,p4.x);float y=cubicBezier(nt,p1.y,p2.y,p3.y,p4.y);float weight=(i==0||i==20)? 1.0 :(mod(float(i),2.)!=0.)? 4.0 : 2.0;movement+=weight*y;}movement*=h/3.;return movement;}float integrateFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i+=2){vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return ret;}vec2 p1=vec2(k0.x,k0.y);vec2 p2=vec2(k0.z,k0.w);vec2 p3=vec2(k1.z,k1.w);vec2 p4=vec2(k1.x,k1.y);if(time>=k1.x){ret+=calculateMovement(k1.x,p1,p2,p3,p4);}if(time>=k0.x&&time<k1.x){return ret+calculateMovement(time,p1,p2,p3,p4);}}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w);}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w)-integrateFromBezierCurveFrames(t0,value.z,value.w);}return 0.;}const float d2r=3.141592653589793/180.;attribute vec3 aPos;attribute vec4 aOffset;attribute vec3 aVel;attribute vec3 aRot;attribute vec4 aColor;attribute vec3 aDirX;attribute vec3 aDirY;\n#ifdef USE_SPRITE\nattribute vec3 aSprite;uniform vec4 uSprite;struct UVDetail{vec2 uv0;vec3 uv1;};UVDetail getSpriteUV(vec2 uv,float lifeTime);varying vec4 vTexCoordBlend;\n#endif\n#ifdef FINAL_TARGET\nuniform vec3 uFinalTarget;uniform vec4 uForceCurve;\n#endif\nuniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;uniform mat4 effects_MatrixVP;uniform vec4 uParams;uniform vec4 uAcceleration;uniform vec4 uGravityModifierValue;uniform vec4 uOpacityOverLifetimeValue;\n#ifdef ROT_X_LIFETIME\nuniform vec4 uRXByLifeTimeValue;\n#endif\n#ifdef ROT_Y_LIFETIME\nuniform vec4 uRYByLifeTimeValue;\n#endif\n#ifdef ROT_Z_LIFETIME\nuniform vec4 uRZByLifeTimeValue;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n#if LINEAR_VEL_X\nuniform vec4 uLinearXByLifetimeValue;\n#endif\n#if LINEAR_VEL_Y\nuniform vec4 uLinearYByLifetimeValue;\n#endif\n#if LINEAR_VEL_Z\nuniform vec4 uLinearZByLifetimeValue;\n#endif\n#endif\n#ifdef SPEED_OVER_LIFETIME\nuniform vec4 uSpeedLifetimeValue;\n#endif\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n#if ORB_VEL_X\nuniform vec4 uOrbXByLifetimeValue;\n#endif\n#if ORB_VEL_Y\nuniform vec4 uOrbYByLifetimeValue;\n#endif\n#if ORB_VEL_Z\nuniform vec4 uOrbZByLifetimeValue;\n#endif\nuniform vec3 uOrbCenter;\n#endif\nuniform vec4 uSizeByLifetimeValue;\n#ifdef SIZE_Y_BY_LIFE\nuniform vec4 uSizeYByLifetimeValue;\n#endif\nvarying float vLife;varying vec4 vColor;varying vec2 vTexCoord;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvec3 calOrbitalMov(float _life,float _dur){vec3 orb=vec3(0.0);\n#ifdef AS_ORBITAL_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if ORB_VEL_X\norb.x=FUNC(uOrbXByLifetimeValue);\n#endif\n#if ORB_VEL_Y\norb.y=FUNC(uOrbYByLifetimeValue);\n#endif\n#if ORB_VEL_Z\norb.z=FUNC(uOrbZByLifetimeValue);\n#endif\n#undef FUNC\nreturn orb;}vec3 calLinearMov(float _life,float _dur){vec3 mov=vec3(0.0);\n#ifdef AS_LINEAR_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if LINEAR_VEL_X\nmov.x=FUNC(uLinearXByLifetimeValue);\n#endif\n#if LINEAR_VEL_Y\nmov.y=FUNC(uLinearYByLifetimeValue);\n#endif\n#if LINEAR_VEL_Z\nmov.z=FUNC(uLinearZByLifetimeValue);\n#endif\n#undef FUNC\nreturn mov;}mat3 mat3FromRotation(vec3 rotation){vec3 sinR=sin(rotation*d2r);vec3 cosR=cos(rotation*d2r);return mat3(cosR.z,-sinR.z,0.,sinR.z,cosR.z,0.,0.,0.,1.)*mat3(cosR.y,0.,sinR.y,0.,1.,0.,-sinR.y,0,cosR.y)*mat3(1.,0.,0.,0,cosR.x,-sinR.x,0.,sinR.x,cosR.x);}\n#ifdef USE_SPRITE\nUVDetail getSpriteUV(vec2 uv,float lifeTime){float t=fract(clamp((lifeTime-aSprite.x)/aSprite.y,0.0,1.)*aSprite.z);float frame=uSprite.z*t;float frameIndex=max(ceil(frame)-1.,0.);float row=floor((frameIndex+0.1)/uSprite.x);float col=frameIndex-row*uSprite.x;vec2 retUV=(vec2(col,row)+uv)/uSprite.xy;UVDetail ret;if(uSprite.w>0.){float blend=frame-frameIndex;float frameIndex1=min(ceil(frame),uSprite.z-1.);float row1=floor((frameIndex1+0.1)/uSprite.x);float col1=frameIndex1-row1*uSprite.x;vec2 coord=(vec2(col1,row1)+uv)/uSprite.xy-retUV;ret.uv1=vec3(coord.x,1.-coord.y,blend);}ret.uv0=vec2(retUV.x,1.-retUV.y);return ret;}\n#endif\nvec3 calculateTranslation(vec3 vel,float t0,float t1,float dur){float dt=t1-t0;float d=getIntegrateByTimeFromTime(0.,dt,uGravityModifierValue);vec3 acc=uAcceleration.xyz*d;\n#ifdef SPEED_OVER_LIFETIME\nreturn vel*getIntegrateFromTime0(dt/dur,uSpeedLifetimeValue)*dur+acc;\n#endif\nreturn vel*dt+acc;}mat3 transformFromRotation(vec3 rot,float _life,float _dur){vec3 rotation=rot;\n#ifdef ROT_LIFETIME_AS_MOVEMENT\n#define FUNC1(a) getValueFromTime(_life,a)\n#else\n#define FUNC1(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#ifdef ROT_X_LIFETIME\nrotation.x+=FUNC1(uRXByLifeTimeValue);\n#endif\n#ifdef ROT_Y_LIFETIME\nrotation.y+=FUNC1(uRYByLifeTimeValue);\n#endif\n#ifdef ROT_Z_LIFETIME\nrotation.z+=FUNC1(uRZByLifeTimeValue);\n#endif\nif(dot(rotation,rotation)==0.0){return mat3(1.0);}\n#undef FUNC1\nreturn mat3FromRotation(rotation);}void main(){float time=uParams.x-aOffset.z;float dur=aOffset.w;if(time<0.||time>dur){gl_Position=vec4(-3.,-3.,-3.,1.);}else{float life=clamp(time/dur,0.0,1.0);vLife=life;\n#ifdef USE_SPRITE\nUVDetail uvD=getSpriteUV(aOffset.xy,time);vTexCoord=uvD.uv0;vTexCoordBlend=vec4(uvD.uv1,uSprite.w);\n#else\nvTexCoord=aOffset.xy;\n#endif\nvColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(life,0.));\n#endif\n#endif\nvColor.a*=clamp(getValueFromTime(life,uOpacityOverLifetimeValue),0.,1.);vec3 size=vec3(vec2(getValueFromTime(life,uSizeByLifetimeValue)),1.0);\n#ifdef SIZE_Y_BY_LIFE\nsize.y=getValueFromTime(life,uSizeYByLifetimeValue);\n#endif\nvec3 point=transformFromRotation(aRot,life,dur)*(aDirX*size.x+aDirY*size.y);vec3 pt=calculateTranslation(aVel,aOffset.z,uParams.x,dur);vec3 _pos=aPos+pt;\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n_pos=mat3FromRotation(calOrbitalMov(life,dur))*(_pos-uOrbCenter);_pos+=uOrbCenter;\n#endif\n#if LINEAR_VEL_X + LINEAR_VEL_Y + LINEAR_VEL_Z\n_pos.xyz+=calLinearMov(life,dur);\n#endif\n#ifdef FINAL_TARGET\nfloat force=getValueFromTime(life,uForceCurve);vec4 pos=vec4(mix(_pos,uFinalTarget,force),1.);\n#else\nvec4 pos=vec4(_pos,1.0);\n#endif\n#if RENDER_MODE == 1\npos.xyz+=point;pos=effects_ObjectToWorld*pos;\n#elif RENDER_MODE == 3\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[2].xyz*point.y;\n#elif RENDER_MODE == 2\npos=effects_ObjectToWorld*pos;pos.xy+=point.xy;\n#elif RENDER_MODE == 0\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[1].xyz*point.y;\n#endif\ngl_Position=effects_MatrixVP*pos;vSeed=aSeed;gl_PointSize=6.0;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}}";
11572
+ var particleVert = "#version 100\nprecision mediump float;\n#define SHADER_VERTEX 1\n#define PATICLE_SHADER 1\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nattribute float aSeed;varying float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<8;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}float calculateMovement(float t,vec2 p1,vec2 p2,vec2 p3,vec2 p4){float movement=0.0;float h=(t-p1.x)*0.05;for(int i=0;i<=20;i++){float t=float(i)*h;float nt=binarySearchT(t,p1.x,p2.x,p3.x,p4.x);float y=cubicBezier(nt,p1.y,p2.y,p3.y,p4.y);float weight=(i==0||i==20)? 1.0 :(mod(float(i),2.)!=0.)? 4.0 : 2.0;movement+=weight*y;}movement*=h/3.;return movement;}float integrateFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i+=2){vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return ret;}vec2 p1=vec2(k0.x,k0.y);vec2 p2=vec2(k0.z,k0.w);vec2 p3=vec2(k1.z,k1.w);vec2 p4=vec2(k1.x,k1.y);if(time>=k1.x){ret+=calculateMovement(k1.x,p1,p2,p3,p4);}if(time>=k0.x&&time<k1.x){return ret+calculateMovement(time,p1,p2,p3,p4);}}return ret;}float integrateByTimeLineSeg(float t,vec2 p0,vec2 p1){float t0=p0.x;float t1=p1.x;float y0=p0.y;float y1=p1.y;vec4 tSqr=vec4(t,t,t0,t0);tSqr=tSqr*tSqr;vec4 a=vec4(2.*t,3.,-t0,3.)*tSqr;float t1y0=t1*y0;vec4 b=vec4(y0-y1,t0*y1-t1y0,2.*y0+y1,t1y0);float r=dot(a,b);return r/(t0-t1)*0.16666667;}float integrateLineSeg(float time,vec2 p0,vec2 p1){float h=time-p0.x;float y0=p0.y;return(y0+y0+(p1.y-y0)*h/(p1.x-p0.x))*h/2.;}float integrateFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateLineSeg(time,k0,k1);}ret+=integrateLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateLineSeg(time,k1,k2);}ret+=integrateLineSeg(k2.x,k1,k2);}return ret;}float integrateByTimeFromLineSeg(float time,float frameStart,float frameCount){if(time==0.){return 0.;}int start=int(frameStart);int count=int(frameCount-1.);float ret=0.;for(int i=0;i<ITR_END;i++){if(i>count){return ret;}vec4 ks=lookup_curve(i+start);vec2 k0=ks.xy;vec2 k1=ks.zw;if(time>k0.x&&time<=k1.x){return ret+integrateByTimeLineSeg(time,k0,k1);}ret+=integrateByTimeLineSeg(k1.x,k0,k1);vec2 k2=lookup_curve(i+start+1).xy;if(time>k1.x&&time<=k2.x){return ret+integrateByTimeLineSeg(time,k1,k2);}ret+=integrateByTimeLineSeg(k2.x,k1,k2);}return ret;}float getIntegrateFromTime0(float t1,vec4 value){float type=value.x;if(type==0.){return value.y*t1;}if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateLineSeg(t1,p0,p1);}if(type==3.){return integrateFromLineSeg(t1,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*t1;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w);}return 0.;}float getIntegrateByTimeFromTime(float t0,float t1,vec4 value){float type=value.x;if(type==0.){return value.y*(t1*t1-t0*t0)/2.;}else if(type==1.){vec2 p0=vec2(0.,value.y);vec2 p1=vec2(value.w,value.z);return integrateByTimeLineSeg(t1,p0,p1)-integrateByTimeLineSeg(t0,p0,p1);}if(type==3.){return integrateByTimeFromLineSeg(t1,value.y,value.z)-integrateByTimeFromLineSeg(t0,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed)*(t1*t1-t0*t0)/2.;}if(type==5.){return integrateFromBezierCurveFrames(t1,value.z,value.w)-integrateFromBezierCurveFrames(t0,value.z,value.w);}return 0.;}const float d2r=3.141592653589793/180.;attribute vec3 aPos;attribute vec4 aOffset;attribute vec4 aColor;attribute vec3 aDirX;attribute vec3 aDirY;attribute vec3 aTranslation;attribute vec3 aRotation0;attribute vec3 aRotation1;attribute vec3 aRotation2;attribute vec3 aLinearMove;\n#ifdef USE_SPRITE\nattribute vec3 aSprite;uniform vec4 uSprite;struct UVDetail{vec2 uv0;vec3 uv1;};UVDetail getSpriteUV(vec2 uv,float lifeTime);varying vec4 vTexCoordBlend;\n#endif\n#ifdef FINAL_TARGET\nuniform vec3 uFinalTarget;uniform vec4 uForceCurve;\n#endif\nuniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;uniform mat4 effects_MatrixVP;uniform vec4 uParams;uniform vec4 uOpacityOverLifetimeValue;\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\nuniform vec4 uOrbXByLifetimeValue;uniform vec4 uOrbYByLifetimeValue;uniform vec4 uOrbZByLifetimeValue;uniform vec3 uOrbCenter;uniform vec4 uSizeByLifetimeValue;\n#ifdef SIZE_Y_BY_LIFE\nuniform vec4 uSizeYByLifetimeValue;\n#endif\nvarying float vLife;varying vec4 vColor;varying vec2 vTexCoord;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvec3 calOrbitalMov(float _life,float _dur){vec3 orb=vec3(0.0);\n#ifdef AS_ORBITAL_MOVEMENT\n#define FUNC(a) getValueFromTime(_life,a)\n#else\n#define FUNC(a) getIntegrateFromTime0(_life,a) * _dur\n#endif\n#if ORB_VEL_X\norb.x=FUNC(uOrbXByLifetimeValue);\n#endif\n#if ORB_VEL_Y\norb.y=FUNC(uOrbYByLifetimeValue);\n#endif\n#if ORB_VEL_Z\norb.z=FUNC(uOrbZByLifetimeValue);\n#endif\n#undef FUNC\nreturn orb;}mat3 mat3FromRotation(vec3 rotation){vec3 sinR=sin(rotation*d2r);vec3 cosR=cos(rotation*d2r);return mat3(cosR.z,-sinR.z,0.,sinR.z,cosR.z,0.,0.,0.,1.)*mat3(cosR.y,0.,sinR.y,0.,1.,0.,-sinR.y,0,cosR.y)*mat3(1.,0.,0.,0,cosR.x,-sinR.x,0.,sinR.x,cosR.x);}\n#ifdef USE_SPRITE\nUVDetail getSpriteUV(vec2 uv,float lifeTime){float t=fract(clamp((lifeTime-aSprite.x)/aSprite.y,0.0,1.)*aSprite.z);float frame=uSprite.z*t;float frameIndex=max(ceil(frame)-1.,0.);float row=floor((frameIndex+0.1)/uSprite.x);float col=frameIndex-row*uSprite.x;vec2 retUV=(vec2(col,row)+uv)/uSprite.xy;UVDetail ret;if(uSprite.w>0.){float blend=frame-frameIndex;float frameIndex1=min(ceil(frame),uSprite.z-1.);float row1=floor((frameIndex1+0.1)/uSprite.x);float col1=frameIndex1-row1*uSprite.x;vec2 coord=(vec2(col1,row1)+uv)/uSprite.xy-retUV;ret.uv1=vec3(coord.x,1.-coord.y,blend);}ret.uv0=vec2(retUV.x,1.-retUV.y);return ret;}\n#endif\nvoid main(){float time=uParams.x-aOffset.z;float dur=aOffset.w;if(time<0.||time>dur){gl_Position=vec4(-3.,-3.,-3.,1.);}else{float life=clamp(time/dur,0.0,1.0);vLife=life;\n#ifdef USE_SPRITE\nUVDetail uvD=getSpriteUV(aOffset.xy,time);vTexCoord=uvD.uv0;vTexCoordBlend=vec4(uvD.uv1,uSprite.w);\n#else\nvTexCoord=aOffset.xy;\n#endif\nvColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(life,0.));\n#endif\n#endif\nvColor.a*=clamp(getValueFromTime(life,uOpacityOverLifetimeValue),0.,1.);vec3 size=vec3(vec2(getValueFromTime(life,uSizeByLifetimeValue)),1.0);\n#ifdef SIZE_Y_BY_LIFE\nsize.y=getValueFromTime(life,uSizeYByLifetimeValue);\n#endif\nmat3 aRotation=mat3(aRotation0,aRotation1,aRotation2);vec3 point=aRotation*(aDirX*size.x+aDirY*size.y);vec3 _pos=aPos+aTranslation;\n#if ORB_VEL_X + ORB_VEL_Y + ORB_VEL_Z\n_pos=mat3FromRotation(calOrbitalMov(life,dur))*(_pos-uOrbCenter);_pos+=uOrbCenter;\n#endif\n_pos.xyz+=aLinearMove;\n#ifdef FINAL_TARGET\nfloat force=getValueFromTime(life,uForceCurve);vec4 pos=vec4(mix(_pos,uFinalTarget,force),1.);\n#else\nvec4 pos=vec4(_pos,1.0);\n#endif\n#if RENDER_MODE == 1\npos.xyz+=point;pos=effects_ObjectToWorld*pos;\n#elif RENDER_MODE == 3\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[2].xyz*point.y;\n#elif RENDER_MODE == 2\npos=effects_ObjectToWorld*pos;pos.xy+=point.xy;\n#elif RENDER_MODE == 0\npos=effects_ObjectToWorld*pos;pos.xyz+=effects_MatrixV[0].xyz*point.x+effects_MatrixV[1].xyz*point.y;\n#endif\ngl_Position=effects_MatrixVP*pos;vSeed=aSeed;gl_PointSize=6.0;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}}";
11546
11573
 
11547
11574
  var trailVert = "#version 100\nprecision mediump float;\n#define SHADER_VERTEX 1\n#ifdef SHADER_VERTEX\n#define CURVE_VALUE_TEXTURE uVCurveValueTexture\n#define CURVE_VALUE_ARRAY uVCurveValues\n#define CURVE_VALUE_COUNT VERT_CURVE_VALUE_COUNT\n#define FRAG_CURVE_VALUE_COUNT 0\n#else\n#define CURVE_VALUE_TEXTURE uFCurveValueTexture\n#define CURVE_VALUE_ARRAY uFCurveValues\n#define CURVE_VALUE_COUNT FRAG_CURVE_VALUE_COUNT\n#define VERT_CURVE_VALUE_COUNT 0\n#endif\n#if CURVE_VALUE_COUNT > 0\n#if LOOKUP_TEXTURE_CURVE\nuniform sampler2D CURVE_VALUE_TEXTURE;const float uCurveCount=1./float(CURVE_VALUE_COUNT);\n#define lookup_curve(i) texture2D(CURVE_VALUE_TEXTURE,vec2(float(i) * uCurveCount,0.))\n#else\nuniform vec4 CURVE_VALUE_ARRAY[CURVE_VALUE_COUNT];\n#define lookup_curve(i) CURVE_VALUE_ARRAY[i]\n#endif\n#else\n#define lookup_curve(i) vec4(0.)\n#endif\n#ifdef WEBGL2\n#define ITR_END (count + 1)\n#else\n#define ITR_END MAX_C\n#endif\n#define NONE_CONST_INDEX 1\n#ifdef SHADER_VERTEX\nattribute float aSeed;varying float vSeed;\n#endif\n#ifdef SHADER_VERTEX\n#define MAX_C VERT_MAX_KEY_FRAME_COUNT\n#else\n#define MAX_C FRAG_MAX_KEY_FRAME_COUNT\n#endif\nmat4 cubicBezierMatrix=mat4(1.0,-3.0,3.0,-1.0,0.0,3.0,-6.0,3.0,0.0,0.0,3.0,-3.0,0.0,0.0,0.0,1.0);float cubicBezier(float t,float y1,float y2,float y3,float y4){vec4 tVec=vec4(1.0,t,t*t,t*t*t);vec4 yVec=vec4(y1,y2,y3,y4);vec4 result=tVec*cubicBezierMatrix*yVec;return result.x+result.y+result.z+result.w;}float binarySearchT(float x,float x1,float x2,float x3,float x4){float left=0.0;float right=1.0;float mid=0.0;float computedX;for(int i=0;i<8;i++){mid=(left+right)*0.5;computedX=cubicBezier(mid,x1,x2,x3,x4);if(abs(computedX-x)<0.0001){break;}else if(computedX>x){right=mid;}else{left=mid;}}return mid;}float valueFromBezierCurveFrames(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);for(int i=0;i<ITR_END;i+=2){if(i>=count){break;}vec4 k0=lookup_curve(i+start);vec4 k1=lookup_curve(i+1+start);if(i==0&&time<k0.x){return k0.y;}if(i==int(frameCount-2.)&&time>=k1.x){return k1.y;}if(time>=k0.x&&time<=k1.x){float t=(time-k0.x)/(k1.x-k0.x);float nt=binarySearchT(time,k0.x,k0.z,k1.z,k1.x);return cubicBezier(nt,k0.y,k0.w,k1.w,k1.y);}}}float evaluteLineSeg(float t,vec2 p0,vec2 p1){return p0.y+(p1.y-p0.y)*(t-p0.x)/(p1.x-p0.x);}float valueFromLineSegs(float time,float frameStart,float frameCount){int start=int(frameStart);int count=int(frameCount-1.);int end=start+count;for(int i=0;i<ITR_END;i++){if(i>count){return lookup_curve(i).w;}vec4 seg=lookup_curve(i+start);vec2 p0=seg.xy;vec2 p1=seg.zw;if(time>=p0.x&&time<=p1.x){return evaluteLineSeg(time,p0,p1);}vec2 p2=lookup_curve(i+start+1).xy;if(time>p1.x&&time<=p2.x){return evaluteLineSeg(time,p1,p2);}}return lookup_curve(0).y;}float getValueFromTime(float time,vec4 value){float type=value.x;if(type==0.){return value.y;}if(type==1.){return mix(value.y,value.z,time/value.w);}if(type==3.){return valueFromLineSegs(time,value.y,value.z);}if(type==4.){return mix(value.y,value.z,aSeed);}if(type==5.){return valueFromBezierCurveFrames(time,value.z,value.w);}return 0.;}attribute vec4 aPos;attribute vec3 aDir;attribute vec3 aInfo;attribute vec4 aColor;attribute float aTime;\n#ifdef ATTR_TRAIL_START\nattribute float aTrailStart;\n#else\nuniform float uTrailStart[64];attribute float aTrailStartIndex;\n#endif\nuniform mat4 effects_MatrixInvV;uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixVP;uniform vec4 uTextureMap;uniform float uTime;uniform vec4 uParams;uniform vec4 uColorParams;uniform vec4 uOpacityOverLifetimeValue;uniform vec4 uWidthOverTrail;\n#ifdef COLOR_OVER_TRAIL\nuniform sampler2D uColorOverTrail;\n#endif\n#ifdef COLOR_OVER_LIFETIME\nuniform sampler2D uColorOverLifetime;\n#endif\nvarying float vLife;varying vec2 vTexCoord;varying vec4 vColor;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvoid main(){vec4 _pa=effects_MatrixVP*vec4(aPos.xyz,1.);vec4 _pb=effects_MatrixVP*vec4(aPos.xyz+aDir,1.);vec2 dir=normalize(_pb.xy/_pb.w-_pa.xy/_pa.w);vec2 screen_xy=vec2(-dir.y,dir.x);vec4 pos=effects_ObjectToWorld*vec4(aPos.xyz,1.);\n#ifdef ATTR_TRAIL_START\nfloat ts=aTrailStart;\n#else\nfloat ts=uTrailStart[int(aTrailStartIndex)];\n#endif\nfloat trail=(ts-aInfo.y)/uParams.y;float width=aPos.w*getValueFromTime(trail,uWidthOverTrail)/max(abs(screen_xy.x),abs(screen_xy.y));pos.xyz+=(effects_MatrixInvV[0].xyz*screen_xy.x+effects_MatrixInvV[1].xyz*screen_xy.y)*width;float time=min((uTime-aTime)/aInfo.x,1.0);gl_Position=effects_MatrixVP*pos;vColor=aColor;\n#ifdef COLOR_OVER_LIFETIME\n#ifdef ENABLE_VERTEX_TEXTURE\nvColor*=texture2D(uColorOverLifetime,vec2(time,0.));\n#endif\n#endif\n#ifdef COLOR_OVER_TRAIL\nvColor*=texture2D(uColorOverTrail,vec2(trail,0.));\n#endif\nvColor.a*=clamp(getValueFromTime(time,uOpacityOverLifetimeValue),0.,1.);vLife=time;vTexCoord=uTextureMap.xy+vec2(trail,aInfo.z)*uTextureMap.zw;vSeed=aSeed;\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
11548
11575
 
@@ -13252,7 +13279,7 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13252
13279
  return _this;
13253
13280
  }
13254
13281
  var _proto = InteractComponent.prototype;
13255
- _proto.start = function start() {
13282
+ _proto.onStart = function onStart() {
13256
13283
  var _this = this;
13257
13284
  var options = this.item.props.content.options;
13258
13285
  var env = this.item.engine.renderer.env;
@@ -13288,8 +13315,11 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13288
13315
  }
13289
13316
  };
13290
13317
  };
13291
- _proto.update = function update(dt) {
13318
+ _proto.onUpdate = function onUpdate(dt) {
13292
13319
  var _this_previewContent;
13320
+ if (!this.isActiveAndEnabled) {
13321
+ return;
13322
+ }
13293
13323
  (_this_previewContent = this.previewContent) == null ? void 0 : _this_previewContent.updateMesh();
13294
13324
  if (!this.hasBeenAddedToComposition && this.item.composition) {
13295
13325
  var options = this.item.props.content.options;
@@ -13632,6 +13662,9 @@ function _assert_this_initialized(self) {
13632
13662
  this.outputs = [];
13633
13663
  this.playState = 0;
13634
13664
  this.traversalMode = 0;
13665
+ /**
13666
+ * 当前本地播放的时间
13667
+ */ this.time = 0;
13635
13668
  graph.addPlayable(this);
13636
13669
  this.inputs = new Array(inputCount);
13637
13670
  this.inputOuputPorts = new Array(inputCount);
@@ -14077,10 +14110,10 @@ exports.SpriteComponent = /*#__PURE__*/ function(RendererComponent) {
14077
14110
  this.material.setVector2("_Size", this.transform.size);
14078
14111
  renderer.drawGeometry(geo, material);
14079
14112
  };
14080
- _proto.start = function start() {
14113
+ _proto.onStart = function onStart() {
14081
14114
  this.item.getHitTestParams = this.getHitTestParams;
14082
14115
  };
14083
- _proto.update = function update(dt) {
14116
+ _proto.onUpdate = function onUpdate(dt) {
14084
14117
  if (!this.isManualTimeSet) {
14085
14118
  this.frameAnimationTime += dt / 1000;
14086
14119
  this.isManualTimeSet = false;
@@ -16503,17 +16536,18 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16503
16536
  return _this;
16504
16537
  }
16505
16538
  var _proto = ParticleSystemRenderer.prototype;
16506
- _proto.start = function start() {
16539
+ _proto.onStart = function onStart() {
16507
16540
  this._priority = this.item.renderOrder;
16508
16541
  this.particleMesh.gravityModifier.scaleXCoord(this.item.duration);
16509
16542
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
16510
16543
  var mesh = _step.value;
16511
- mesh.start();
16544
+ mesh.onStart();
16512
16545
  }
16513
16546
  };
16514
- _proto.update = function update(dt) {
16547
+ _proto.onUpdate = function onUpdate(dt) {
16515
16548
  var time = this.particleMesh.time;
16516
16549
  this.particleMesh.mesh.material.setVector4("uParams", new Vector4(time, this.item.duration, 0, 0));
16550
+ this.particleMesh.onUpdate(dt);
16517
16551
  };
16518
16552
  _proto.render = function render(renderer) {
16519
16553
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
@@ -16528,6 +16562,7 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16528
16562
  };
16529
16563
  _proto.updateTime = function updateTime(now, delta) {
16530
16564
  this.particleMesh.time = now;
16565
+ // this.particleMesh.onUpdate(delta);
16531
16566
  if (this.trailMesh) {
16532
16567
  this.trailMesh.time = now;
16533
16568
  this.trailMesh.onUpdate(delta);
@@ -16738,7 +16773,7 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16738
16773
  _proto.getTextures = function getTextures() {
16739
16774
  return this.renderer.getTextures();
16740
16775
  };
16741
- _proto.start = function start() {
16776
+ _proto.startEmit = function startEmit() {
16742
16777
  if (!this.started || this.ended) {
16743
16778
  this.reset();
16744
16779
  this.started = true;
@@ -16764,7 +16799,7 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16764
16799
  this.frozen = false;
16765
16800
  this.ended = false;
16766
16801
  };
16767
- _proto.onUpdate = function onUpdate(delta) {
16802
+ _proto.update = function update(delta) {
16768
16803
  var _this = this;
16769
16804
  if (this.started && !this.frozen) {
16770
16805
  var now = this.lastUpdate + delta / 1000;
@@ -17564,7 +17599,7 @@ function randomArrItem(arr, keepArr) {
17564
17599
  this.particleSystem = boundObject.getComponent(exports.ParticleSystem);
17565
17600
  if (this.particleSystem) {
17566
17601
  this.particleSystem.name = boundObject.name;
17567
- this.particleSystem.start();
17602
+ this.particleSystem.startEmit();
17568
17603
  this.particleSystem.initEmitterTransform();
17569
17604
  }
17570
17605
  };
@@ -17581,7 +17616,7 @@ function randomArrItem(arr, keepArr) {
17581
17616
  if (Math.abs(this.time - this.lastTime) < 0.001) {
17582
17617
  deltaTime = 0;
17583
17618
  }
17584
- particleSystem.onUpdate(deltaTime);
17619
+ particleSystem.update(deltaTime);
17585
17620
  }
17586
17621
  this.lastTime = this.time;
17587
17622
  };
@@ -17634,6 +17669,7 @@ var particleUniformTypeMap = {
17634
17669
  var ParticleMesh = /*#__PURE__*/ function() {
17635
17670
  function ParticleMesh(engine, props) {
17636
17671
  this.particleCount = 0;
17672
+ this.VERT_MAX_KEY_FRAME_COUNT = 0;
17637
17673
  var _engine_renderer;
17638
17674
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
17639
17675
  var speedOverLifetime = props.speedOverLifetime, colorOverLifetime = props.colorOverLifetime, linearVelOverLifetime = props.linearVelOverLifetime, orbitalVelOverLifetime = props.orbitalVelOverLifetime, sizeOverLifetime = props.sizeOverLifetime, rotationOverLifetime = props.rotationOverLifetime, sprite = props.sprite, gravityModifier = props.gravityModifier, maxCount = props.maxCount, textureFlip = props.textureFlip, useSprite = props.useSprite, name = props.name, gravity = props.gravity, forceTarget = props.forceTarget, side = props.side, occlusion = props.occlusion, anchor = props.anchor, blending = props.blending, maskMode = props.maskMode, mask = props.mask, transparentOcclusion = props.transparentOcclusion, meshSlots = props.meshSlots, _props_renderMode = props.renderMode, renderMode = _props_renderMode === void 0 ? 0 : _props_renderMode, _props_diffuse = props.diffuse, diffuse = _props_diffuse === void 0 ? Texture.createWithData(engine) : _props_diffuse;
@@ -17852,6 +17888,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17852
17888
  "FRAG_MAX_KEY_FRAME_COUNT",
17853
17889
  fragmentKeyFrameMeta.max
17854
17890
  ]);
17891
+ this.VERT_MAX_KEY_FRAME_COUNT = vertexKeyFrameMeta.max;
17855
17892
  var fragment = particleFrag;
17856
17893
  var originalVertex = "#define LOOKUP_TEXTURE_CURVE " + vertex_lookup_texture + "\n" + particleVert;
17857
17894
  var vertex = originalVertex;
@@ -17960,6 +17997,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17960
17997
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17961
17998
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17962
17999
  this.gravityModifier = gravityModifier;
18000
+ this.rotationOverLifetime = rotationOverLifetime;
17963
18001
  this.maxCount = maxCount;
17964
18002
  // this.duration = duration;
17965
18003
  this.textureOffsets = textureFlip ? [
@@ -18024,15 +18062,232 @@ var ParticleMesh = /*#__PURE__*/ function() {
18024
18062
  // @ts-expect-error
18025
18063
  geometry.setIndexData(new index.constructor(0));
18026
18064
  };
18065
+ _proto.onUpdate = function onUpdate(dt) {
18066
+ var aPosArray = this.geometry.getAttributeData("aPos"); // vector3
18067
+ var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18068
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18069
+ var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18070
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18071
+ // const uParams = this.mesh.material.getVector4('uParams');
18072
+ // if (!uParams) {
18073
+ // return;
18074
+ // }
18075
+ var localTime = new Float32Array([
18076
+ this.time
18077
+ ])[0];
18078
+ var particleCount = Math.ceil(aPosArray.length / 12);
18079
+ // calculate particle translation
18080
+ var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18081
+ if (aTranslationArray.length < particleCount * 3) {
18082
+ aTranslationArray = new Float32Array(particleCount * 3);
18083
+ }
18084
+ var velocity = new Vector3(0, 0, 0);
18085
+ for(var i = 0; i < particleCount; i++){
18086
+ var velOffset = i * 12 + 3;
18087
+ velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18088
+ var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18089
+ var aTranslationOffset = i * 3;
18090
+ aTranslationArray[aTranslationOffset] = trans.x;
18091
+ aTranslationArray[aTranslationOffset + 1] = trans.y;
18092
+ aTranslationArray[aTranslationOffset + 2] = trans.z;
18093
+ }
18094
+ this.geometry.setAttributeData("aTranslation", aTranslationArray);
18095
+ // calculate particle rotation
18096
+ var aRotationArray = this.geometry.getAttributeData("aRotation0");
18097
+ if (aRotationArray.length < particleCount * 9) {
18098
+ aRotationArray = new Float32Array(particleCount * 9);
18099
+ }
18100
+ for(var i1 = 0; i1 < particleCount; i1++){
18101
+ var time = localTime - aOffsetArray[i1 * 4 + 2];
18102
+ var duration = aOffsetArray[i1 * 4 + 3];
18103
+ var life = clamp$1(time / duration, 0.0, 1.0);
18104
+ var aRotOffset = i1 * 8;
18105
+ var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18106
+ var aSeed = aSeedArray[i1 * 8 + 3];
18107
+ var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18108
+ var aRotationOffset = i1 * 9;
18109
+ var matrixArray = aRotation.toArray();
18110
+ aRotationArray.set(matrixArray, aRotationOffset);
18111
+ }
18112
+ this.geometry.setAttributeData("aRotation0", aRotationArray);
18113
+ // calculate linear movement
18114
+ var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18115
+ if (aLinearMoveArray.length < particleCount * 3) {
18116
+ aLinearMoveArray = new Float32Array(particleCount * 3);
18117
+ }
18118
+ for(var i2 = 0; i2 < particleCount; i2++){
18119
+ var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18120
+ var duration1 = aOffsetArray[i2 * 4 + 3];
18121
+ // const life = math.clamp(time / duration, 0.0, 1.0);
18122
+ var aSeed1 = aSeedArray[i2 * 8 + 3];
18123
+ var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18124
+ var aLinearMoveOffset = i2 * 3;
18125
+ aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18126
+ aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18127
+ aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18128
+ }
18129
+ this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18130
+ };
18027
18131
  _proto.minusTime = function minusTime(time) {
18028
- var data = this.geometry.getAttributeData("aOffset");
18029
- assertExist(data);
18030
- for(var i = 0; i < data.length; i += 4){
18031
- data[i + 2] -= time;
18132
+ var aOffset = this.geometry.getAttributeData("aOffset");
18133
+ for(var i = 0; i < aOffset.length; i += 4){
18134
+ aOffset[i + 2] -= time;
18032
18135
  }
18033
- this.geometry.setAttributeData("aOffset", data);
18136
+ this.geometry.setAttributeData("aOffset", aOffset);
18034
18137
  this.time -= time;
18035
18138
  };
18139
+ _proto.calculateTranslation = function calculateTranslation(velocity, t0, t1, duration) {
18140
+ var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18141
+ var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18142
+ if (!uAcceleration || !uGravityModifierValue) {
18143
+ return new Vector3();
18144
+ }
18145
+ var dt = t1 - t0; // 相对delay的时间
18146
+ var d = this.gravityModifier.getIntegrateByTime(0, dt);
18147
+ var acc = [
18148
+ uAcceleration.x * d,
18149
+ uAcceleration.y * d,
18150
+ uAcceleration.z * d
18151
+ ];
18152
+ // ret.addScaledVector(velData, speedIntegrate);
18153
+ // ret.addScaledVector(acc, d);
18154
+ // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18155
+ if (this.speedOverLifetime) {
18156
+ // dt / dur 归一化
18157
+ var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18158
+ return velocity.clone().multiply(speed).add(acc);
18159
+ }
18160
+ return velocity.clone().multiply(dt).add(acc);
18161
+ };
18162
+ _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18163
+ var rotation = rot.clone();
18164
+ if (!this.rotationOverLifetime) {
18165
+ return new Matrix3();
18166
+ }
18167
+ if (this.rotationOverLifetime.asRotation) {
18168
+ // Adjust rotation based on the specified lifetime components
18169
+ if (this.rotationOverLifetime.x) {
18170
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18171
+ rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18172
+ } else {
18173
+ rotation.x += this.rotationOverLifetime.x.getValue(life);
18174
+ }
18175
+ }
18176
+ if (this.rotationOverLifetime.y) {
18177
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18178
+ rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18179
+ } else {
18180
+ rotation.y += this.rotationOverLifetime.y.getValue(life);
18181
+ }
18182
+ }
18183
+ if (this.rotationOverLifetime.z) {
18184
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18185
+ rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18186
+ } else {
18187
+ rotation.z += this.rotationOverLifetime.z.getValue(life);
18188
+ }
18189
+ }
18190
+ } else {
18191
+ // Adjust rotation based on the specified lifetime components
18192
+ if (this.rotationOverLifetime.x) {
18193
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18194
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * dur;
18195
+ } else {
18196
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, dur) * dur;
18197
+ }
18198
+ }
18199
+ if (this.rotationOverLifetime.y) {
18200
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18201
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * dur;
18202
+ } else {
18203
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, dur) * dur;
18204
+ }
18205
+ }
18206
+ if (this.rotationOverLifetime.z) {
18207
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18208
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * dur;
18209
+ } else {
18210
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, dur) * dur;
18211
+ }
18212
+ }
18213
+ }
18214
+ // If the rotation vector is zero, return the identity matrix
18215
+ if (rotation.dot(rotation) === 0.0) {
18216
+ return new Matrix3().identity();
18217
+ }
18218
+ // Return the rotation matrix derived from the rotation vector
18219
+ return this.mat3FromRotation(rotation);
18220
+ };
18221
+ _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18222
+ var d2r = Math.PI / 180;
18223
+ var sinR = rotation.clone().multiply(d2r);
18224
+ sinR.x = Math.sin(sinR.x);
18225
+ sinR.y = Math.sin(sinR.y);
18226
+ sinR.z = Math.sin(sinR.z);
18227
+ var cosR = rotation.clone().multiply(d2r);
18228
+ cosR.x = Math.cos(cosR.x);
18229
+ cosR.y = Math.cos(cosR.y);
18230
+ cosR.z = Math.cos(cosR.z);
18231
+ var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18232
+ var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18233
+ var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18234
+ var result = rotZ.multiply(rotY).multiply(rotX);
18235
+ return result;
18236
+ };
18237
+ _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18238
+ var mov = new Vector3();
18239
+ var lifetime = time / duration;
18240
+ if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18241
+ return new Vector3();
18242
+ }
18243
+ if (this.linearVelOverLifetime.asMovement) {
18244
+ if (this.linearVelOverLifetime.x) {
18245
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18246
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18247
+ } else {
18248
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime);
18249
+ }
18250
+ }
18251
+ if (this.linearVelOverLifetime.y) {
18252
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18253
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18254
+ } else {
18255
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime);
18256
+ }
18257
+ }
18258
+ if (this.linearVelOverLifetime.z) {
18259
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18260
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18261
+ } else {
18262
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime);
18263
+ }
18264
+ }
18265
+ } else {
18266
+ // Adjust rotation based on the specified lifetime components
18267
+ if (this.linearVelOverLifetime.x) {
18268
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18269
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18270
+ } else {
18271
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18272
+ }
18273
+ }
18274
+ if (this.linearVelOverLifetime.y) {
18275
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18276
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18277
+ } else {
18278
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18279
+ }
18280
+ }
18281
+ if (this.linearVelOverLifetime.z) {
18282
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18283
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18284
+ } else {
18285
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18286
+ }
18287
+ }
18288
+ }
18289
+ return mov;
18290
+ };
18036
18291
  _proto.removePoint = function removePoint(index) {
18037
18292
  if (index < this.particleCount) {
18038
18293
  this.geometry.setAttributeSubData("aOffset", index * 16, new Float32Array(16));
@@ -18234,6 +18489,32 @@ function generateGeometryProps(maxVertex, useSprite, name) {
18234
18489
  size: 4,
18235
18490
  stride: 4 * bpe,
18236
18491
  data: new Float32Array(0)
18492
+ },
18493
+ aTranslation: {
18494
+ size: 3,
18495
+ data: new Float32Array(0)
18496
+ },
18497
+ aLinearMove: {
18498
+ size: 3,
18499
+ data: new Float32Array(0)
18500
+ },
18501
+ aRotation0: {
18502
+ size: 3,
18503
+ offset: 0,
18504
+ stride: 9 * bpe,
18505
+ data: new Float32Array(0)
18506
+ },
18507
+ aRotation1: {
18508
+ size: 3,
18509
+ offset: 3 * bpe,
18510
+ stride: 9 * bpe,
18511
+ dataSource: "aRotation0"
18512
+ },
18513
+ aRotation2: {
18514
+ size: 3,
18515
+ offset: 6 * bpe,
18516
+ stride: 9 * bpe,
18517
+ dataSource: "aRotation0"
18237
18518
  }
18238
18519
  };
18239
18520
  if (useSprite) {
@@ -19311,25 +19592,15 @@ var TrackSortWrapper = function TrackSortWrapper(track, originalIndex) {
19311
19592
  this.track = track;
19312
19593
  this.originalIndex = originalIndex;
19313
19594
  };
19314
- function isAncestor(ancestorCandidate, descendantCandidate) {
19315
- var current = descendantCandidate.parent;
19316
- while(current){
19317
- if (current === ancestorCandidate) {
19318
- return true;
19319
- }
19320
- current = current.parent;
19321
- }
19322
- return false;
19323
- }
19324
19595
  function compareTracks(a, b) {
19325
19596
  var bindingA = a.track.binding;
19326
19597
  var bindingB = b.track.binding;
19327
19598
  if (!_instanceof1(bindingA, exports.VFXItem) || !_instanceof1(bindingB, exports.VFXItem)) {
19328
19599
  return a.originalIndex - b.originalIndex;
19329
19600
  }
19330
- if (isAncestor(bindingA, bindingB)) {
19601
+ if (exports.VFXItem.isAncestor(bindingA, bindingB)) {
19331
19602
  return -1;
19332
- } else if (isAncestor(bindingB, bindingA)) {
19603
+ } else if (exports.VFXItem.isAncestor(bindingB, bindingA)) {
19333
19604
  return 1;
19334
19605
  } else {
19335
19606
  return a.originalIndex - b.originalIndex; // 非父子关系的元素保持原始顺序
@@ -19353,7 +19624,7 @@ function compareTracks(a, b) {
19353
19624
  return _this;
19354
19625
  }
19355
19626
  var _proto = CompositionComponent.prototype;
19356
- _proto.start = function start() {
19627
+ _proto.onStart = function onStart() {
19357
19628
  var _this_item_props = this.item.props, _this_item_props_startTime = _this_item_props.startTime, startTime = _this_item_props_startTime === void 0 ? 0 : _this_item_props_startTime;
19358
19629
  this.startTime = startTime;
19359
19630
  this.resolveBindings();
@@ -19381,7 +19652,7 @@ function compareTracks(a, b) {
19381
19652
  _proto.getReusable = function getReusable() {
19382
19653
  return this.reusable;
19383
19654
  };
19384
- _proto.update = function update(dt) {
19655
+ _proto.onUpdate = function onUpdate(dt) {
19385
19656
  var time = this.time;
19386
19657
  this.timelinePlayable.setTime(time);
19387
19658
  this.graph.evaluate(dt);
@@ -19417,7 +19688,9 @@ function compareTracks(a, b) {
19417
19688
  props.content = itemData.content;
19418
19689
  item = assetLoader.loadGUID(itemData.id);
19419
19690
  item.composition = this.item.composition;
19420
- var compositionComponent = item.addComponent(CompositionComponent);
19691
+ var compositionComponent = new CompositionComponent(this.engine);
19692
+ compositionComponent.item = item;
19693
+ item.components.push(compositionComponent);
19421
19694
  compositionComponent.data = props;
19422
19695
  compositionComponent.refId = refId;
19423
19696
  item.transform.parentTransform = this.transform;
@@ -19871,8 +20144,8 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19871
20144
  return _this;
19872
20145
  }
19873
20146
  var _proto = TextComponent.prototype;
19874
- _proto.update = function update(dt) {
19875
- SpriteComponent.prototype.update.call(this, dt);
20147
+ _proto.onUpdate = function onUpdate(dt) {
20148
+ SpriteComponent.prototype.onUpdate.call(this, dt);
19876
20149
  this.updateTexture();
19877
20150
  };
19878
20151
  _proto.fromData = function fromData(data) {
@@ -20287,7 +20560,7 @@ exports.EffectComponent = /*#__PURE__*/ function(RendererComponent) {
20287
20560
  return _this;
20288
20561
  }
20289
20562
  var _proto = EffectComponent.prototype;
20290
- _proto.start = function start() {
20563
+ _proto.onStart = function onStart() {
20291
20564
  this.item.getHitTestParams = this.getHitTestParams;
20292
20565
  };
20293
20566
  _proto.render = function render(renderer) {
@@ -20414,7 +20687,7 @@ exports.PostProcessVolume = /*#__PURE__*/ function(Behaviour) {
20414
20687
  return _this;
20415
20688
  }
20416
20689
  var _proto = PostProcessVolume.prototype;
20417
- _proto.start = function start() {
20690
+ _proto.onStart = function onStart() {
20418
20691
  var composition = this.item.composition;
20419
20692
  if (composition) {
20420
20693
  composition.globalVolume = this;
@@ -20556,8 +20829,8 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20556
20829
  */ _this.ended = false;
20557
20830
  _this.reusable = false;
20558
20831
  _this.type = ItemType.base;
20832
+ _this.isDuringPlay = false;
20559
20833
  _this.components = [];
20560
- _this.itemBehaviours = [];
20561
20834
  _this.rendererComponents = [];
20562
20835
  /**
20563
20836
  * 元素可见性,该值的改变会触发 `handleVisibleChanged` 回调
@@ -20567,6 +20840,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20567
20840
  * 元素动画的速度
20568
20841
  */ _this.speed = 1;
20569
20842
  _this.listIndex = 0;
20843
+ _this.isEnabled = false;
20570
20844
  _this.eventProcessor = new EventEmitter();
20571
20845
  _this.name = "VFXItem";
20572
20846
  _this.transform.name = _this.name;
@@ -20639,8 +20913,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20639
20913
  */ _proto.addComponent = function addComponent(classConstructor) {
20640
20914
  var newComponent = new classConstructor(this.engine);
20641
20915
  this.components.push(newComponent);
20642
- newComponent.item = this;
20643
- newComponent.onAttached();
20916
+ newComponent.setVFXItem(this);
20644
20917
  return newComponent;
20645
20918
  };
20646
20919
  /**
@@ -20673,21 +20946,22 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20673
20946
  return res;
20674
20947
  };
20675
20948
  _proto.setParent = function setParent(vfxItem) {
20676
- if (vfxItem === this) {
20949
+ if (vfxItem === this && !vfxItem) {
20677
20950
  return;
20678
20951
  }
20679
20952
  if (this.parent) {
20680
20953
  removeItem(this.parent.children, this);
20681
20954
  }
20682
20955
  this.parent = vfxItem;
20683
- if (vfxItem) {
20684
- if (!VFXItem.isCamera(this)) {
20685
- this.transform.parentTransform = vfxItem.transform;
20686
- }
20687
- vfxItem.children.push(this);
20688
- if (!this.composition) {
20689
- this.composition = vfxItem.composition;
20690
- }
20956
+ if (!VFXItem.isCamera(this)) {
20957
+ this.transform.parentTransform = vfxItem.transform;
20958
+ }
20959
+ vfxItem.children.push(this);
20960
+ if (!this.composition) {
20961
+ this.composition = vfxItem.composition;
20962
+ }
20963
+ if (!this.isDuringPlay && vfxItem.isDuringPlay) {
20964
+ this.beginPlay();
20691
20965
  }
20692
20966
  };
20693
20967
  /**
@@ -20718,6 +20992,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20718
20992
  */ _proto.setVisible = function setVisible(visible) {
20719
20993
  if (this.visible !== visible) {
20720
20994
  this.visible = !!visible;
20995
+ this.onActiveChanged();
20721
20996
  }
20722
20997
  };
20723
20998
  /**
@@ -20842,6 +21117,57 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20842
21117
  }
20843
21118
  return undefined;
20844
21119
  };
21120
+ /**
21121
+ * @internal
21122
+ */ _proto.beginPlay = function beginPlay() {
21123
+ this.isDuringPlay = true;
21124
+ if (this.composition && this.visible && !this.isEnabled) {
21125
+ this.onEnable();
21126
+ }
21127
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
21128
+ var child = _step.value;
21129
+ if (!child.isDuringPlay) {
21130
+ child.beginPlay();
21131
+ }
21132
+ }
21133
+ };
21134
+ /**
21135
+ * @internal
21136
+ */ _proto.onActiveChanged = function onActiveChanged() {
21137
+ if (!this.isEnabled) {
21138
+ this.onEnable();
21139
+ } else {
21140
+ this.onDisable();
21141
+ }
21142
+ };
21143
+ /**
21144
+ * @internal
21145
+ */ _proto.onEnable = function onEnable() {
21146
+ this.isEnabled = true;
21147
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21148
+ var component = _step.value;
21149
+ if (component.enabled && !component.isStartCalled) {
21150
+ component.onStart();
21151
+ }
21152
+ }
21153
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.components), _step1; !(_step1 = _iterator1()).done;){
21154
+ var component1 = _step1.value;
21155
+ if (component1.enabled && !component1.isEnableCalled) {
21156
+ component1.enable();
21157
+ }
21158
+ }
21159
+ };
21160
+ /**
21161
+ * @internal
21162
+ */ _proto.onDisable = function onDisable() {
21163
+ this.isEnabled = false;
21164
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21165
+ var component = _step.value;
21166
+ if (component.enabled && component.isEnableCalled) {
21167
+ component.disable();
21168
+ }
21169
+ }
21170
+ };
20845
21171
  _proto.fromData = function fromData(data) {
20846
21172
  EffectsObject.prototype.fromData.call(this, data);
20847
21173
  var id = data.id, name = data.name, delay = data.delay, parentId = data.parentId, endBehavior = data.endBehavior, transform = data.transform, _data_listIndex = data.listIndex, listIndex = _data_listIndex === void 0 ? 0 : _data_listIndex, _data_duration = data.duration, duration = _data_duration === void 0 ? 0 : _data_duration;
@@ -20891,14 +21217,10 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20891
21217
  if (duration <= 0) {
20892
21218
  throw new Error("Item duration can't be less than 0, see " + HELP_LINK["Item duration can't be less than 0"] + ".");
20893
21219
  }
20894
- this.itemBehaviours.length = 0;
20895
21220
  this.rendererComponents.length = 0;
20896
21221
  for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
20897
21222
  var component = _step.value;
20898
21223
  component.item = this;
20899
- if (_instanceof1(component, Behaviour)) {
20900
- this.itemBehaviours.push(component);
20901
- }
20902
21224
  if (_instanceof1(component, RendererComponent)) {
20903
21225
  this.rendererComponents.push(component);
20904
21226
  }
@@ -21003,6 +21325,16 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
21003
21325
  VFXItem.isExtraCamera = function isExtraCamera(item) {
21004
21326
  return item.id === "extra-camera" && item.name === "extra-camera";
21005
21327
  };
21328
+ VFXItem.isAncestor = function isAncestor(ancestorCandidate, descendantCandidate) {
21329
+ var current = descendantCandidate.parent;
21330
+ while(current){
21331
+ if (current === ancestorCandidate) {
21332
+ return true;
21333
+ }
21334
+ current = current.parent;
21335
+ }
21336
+ return false;
21337
+ };
21006
21338
  _create_class(VFXItem, [
21007
21339
  {
21008
21340
  key: "content",
@@ -24857,6 +25189,109 @@ var listOrder = 0;
24857
25189
  return CompositionSourceManager;
24858
25190
  }();
24859
25191
 
25192
+ var SceneTicking = /*#__PURE__*/ function() {
25193
+ function SceneTicking() {
25194
+ this.update = new UpdateTickData();
25195
+ this.lateUpdate = new LateUpdateTickData();
25196
+ }
25197
+ var _proto = SceneTicking.prototype;
25198
+ _proto.addComponent = function addComponent(obj) {
25199
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25200
+ this.update.addComponent(obj);
25201
+ }
25202
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25203
+ this.lateUpdate.addComponent(obj);
25204
+ }
25205
+ };
25206
+ _proto.removeComponent = function removeComponent(obj) {
25207
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25208
+ this.update.removeComponent(obj);
25209
+ }
25210
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25211
+ this.lateUpdate.removeComponent(obj);
25212
+ }
25213
+ };
25214
+ _proto.clear = function clear() {
25215
+ this.update.clear();
25216
+ this.lateUpdate.clear();
25217
+ };
25218
+ return SceneTicking;
25219
+ }();
25220
+ var TickData = /*#__PURE__*/ function() {
25221
+ function TickData() {
25222
+ this.components = [];
25223
+ this.ticks = [];
25224
+ }
25225
+ var _proto = TickData.prototype;
25226
+ _proto.tick = function tick(dt) {
25227
+ this.tickComponents(this.components, dt);
25228
+ for(var i = 0; i < this.ticks.length; i++){
25229
+ this.ticks[i](dt);
25230
+ }
25231
+ };
25232
+ _proto.tickComponents = function tickComponents(components, dt) {
25233
+ // To be implemented in derived classes
25234
+ };
25235
+ _proto.addComponent = function addComponent(component) {
25236
+ if (!this.components.includes(component)) {
25237
+ this.components.push(component);
25238
+ }
25239
+ };
25240
+ _proto.removeComponent = function removeComponent(component) {
25241
+ var index = this.components.indexOf(component);
25242
+ if (index > -1) {
25243
+ this.components.splice(index, 1);
25244
+ }
25245
+ };
25246
+ _proto.addTick = function addTick(method, callee) {
25247
+ var tick = method.bind(callee);
25248
+ if (!this.ticks.includes(tick)) {
25249
+ this.ticks.push(tick);
25250
+ }
25251
+ };
25252
+ _proto.clear = function clear() {
25253
+ this.components = [];
25254
+ };
25255
+ return TickData;
25256
+ }();
25257
+ var UpdateTickData = /*#__PURE__*/ function(TickData) {
25258
+ _inherits(UpdateTickData, TickData);
25259
+ function UpdateTickData() {
25260
+ return TickData.apply(this, arguments);
25261
+ }
25262
+ var _proto = UpdateTickData.prototype;
25263
+ _proto.tickComponents = function tickComponents(components, dt) {
25264
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25265
+ var component = _step.value;
25266
+ component.onUpdate(dt);
25267
+ }
25268
+ };
25269
+ return UpdateTickData;
25270
+ }(TickData);
25271
+ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
25272
+ _inherits(LateUpdateTickData, TickData);
25273
+ function LateUpdateTickData() {
25274
+ return TickData.apply(this, arguments);
25275
+ }
25276
+ var _proto = LateUpdateTickData.prototype;
25277
+ _proto.tickComponents = function tickComponents(components, dt) {
25278
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25279
+ var component = _step.value;
25280
+ component.onLateUpdate(dt);
25281
+ }
25282
+ };
25283
+ return LateUpdateTickData;
25284
+ } // function compareComponents (a: Component, b: Component): number {
25285
+ // const itemA = a.item;
25286
+ // const itemB = b.item;
25287
+ // if (VFXItem.isAncestor(itemA, itemB)) {
25288
+ // return -1;
25289
+ // } else {
25290
+ // return 1;
25291
+ // }
25292
+ // }
25293
+ (TickData);
25294
+
24860
25295
  /**
24861
25296
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24862
25297
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
@@ -24866,6 +25301,7 @@ var listOrder = 0;
24866
25301
  function Composition(props, scene) {
24867
25302
  var _this;
24868
25303
  _this = EventEmitter.call(this) || this;
25304
+ _this.sceneTicking = new SceneTicking();
24869
25305
  /**
24870
25306
  * 动画播放速度
24871
25307
  */ _this.speed = 1;
@@ -24903,9 +25339,12 @@ var listOrder = 0;
24903
25339
  _this.rootItem = new exports.VFXItem(_this.getEngine(), sourceContent);
24904
25340
  _this.rootItem.name = "rootItem";
24905
25341
  _this.rootItem.composition = _assert_this_initialized(_this);
24906
- _this.rootComposition = _this.rootItem.addComponent(CompositionComponent);
25342
+ // Spawn rootCompositionComponent
25343
+ _this.rootComposition = new CompositionComponent(_this.getEngine());
24907
25344
  _this.rootComposition.startTime = sourceContent.startTime;
24908
25345
  _this.rootComposition.data = sourceContent;
25346
+ _this.rootComposition.item = _this.rootItem;
25347
+ _this.rootItem.components.push(_this.rootComposition);
24909
25348
  var imageUsage = !reusable && imgUsage;
24910
25349
  _this.width = width;
24911
25350
  _this.height = height;
@@ -24939,7 +25378,6 @@ var listOrder = 0;
24939
25378
  _this.rendererOptions = null;
24940
25379
  _this.rootComposition.createContent();
24941
25380
  _this.buildItemTree(_this.rootItem);
24942
- _this.callAwake(_this.rootItem);
24943
25381
  _this.rootItem.onEnd = function() {
24944
25382
  window.setTimeout(function() {
24945
25383
  _this.emit("end", {
@@ -24951,6 +25389,16 @@ var listOrder = 0;
24951
25389
  return _this;
24952
25390
  }
24953
25391
  var _proto = Composition.prototype;
25392
+ _proto.initializeSceneTicking = function initializeSceneTicking(item) {
25393
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25394
+ var component = _step.value;
25395
+ this.sceneTicking.addComponent(component);
25396
+ }
25397
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
25398
+ var child = _step1.value;
25399
+ this.initializeSceneTicking(child);
25400
+ }
25401
+ };
24954
25402
  /**
24955
25403
  * 获取合成的时长
24956
25404
  */ _proto.getDuration = function getDuration() {
@@ -25054,7 +25502,7 @@ var listOrder = 0;
25054
25502
  this.resume();
25055
25503
  }
25056
25504
  if (!this.rootComposition.isStartCalled) {
25057
- this.rootComposition.start();
25505
+ this.rootComposition.onStart();
25058
25506
  this.rootComposition.isStartCalled = true;
25059
25507
  }
25060
25508
  this.setSpeed(1);
@@ -25131,9 +25579,12 @@ var listOrder = 0;
25131
25579
  // 更新 model-tree-plugin
25132
25580
  this.updatePluginLoaders(deltaTime);
25133
25581
  // scene VFXItem components lifetime function.
25134
- this.callStart(this.rootItem);
25135
- this.callUpdate(this.rootItem, time);
25136
- this.callLateUpdate(this.rootItem, time);
25582
+ if (!this.rootItem.isDuringPlay) {
25583
+ this.callAwake(this.rootItem);
25584
+ this.rootItem.beginPlay();
25585
+ }
25586
+ this.sceneTicking.update.tick(time);
25587
+ this.sceneTicking.lateUpdate.tick(time);
25137
25588
  this.updateCamera();
25138
25589
  this.prepareRender();
25139
25590
  if (this.shouldDispose()) {
@@ -25186,11 +25637,11 @@ var listOrder = 0;
25186
25637
  return t;
25187
25638
  };
25188
25639
  _proto.callAwake = function callAwake(item) {
25189
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25190
- var itemBehaviour = _step.value;
25191
- if (!itemBehaviour.isAwakeCalled) {
25192
- itemBehaviour.awake();
25193
- itemBehaviour.isAwakeCalled = true;
25640
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25641
+ var component = _step.value;
25642
+ if (!component.isAwakeCalled) {
25643
+ component.onAwake();
25644
+ component.isAwakeCalled = true;
25194
25645
  }
25195
25646
  }
25196
25647
  for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
@@ -25198,72 +25649,6 @@ var listOrder = 0;
25198
25649
  this.callAwake(child);
25199
25650
  }
25200
25651
  };
25201
- _proto.callStart = function callStart(item) {
25202
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25203
- var itemBehaviour = _step.value;
25204
- if (itemBehaviour.isActiveAndEnabled && !itemBehaviour.isStartCalled) {
25205
- itemBehaviour.start();
25206
- itemBehaviour.isStartCalled = true;
25207
- }
25208
- }
25209
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25210
- var rendererComponent = _step1.value;
25211
- if (rendererComponent.isActiveAndEnabled && !rendererComponent.isStartCalled) {
25212
- rendererComponent.start();
25213
- rendererComponent.isStartCalled = true;
25214
- }
25215
- }
25216
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25217
- var child = _step2.value;
25218
- this.callStart(child);
25219
- }
25220
- };
25221
- _proto.callUpdate = function callUpdate(item, dt) {
25222
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25223
- var itemBehaviour = _step.value;
25224
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25225
- itemBehaviour.update(dt);
25226
- }
25227
- }
25228
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25229
- var rendererComponent = _step1.value;
25230
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25231
- rendererComponent.update(dt);
25232
- }
25233
- }
25234
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25235
- var child = _step2.value;
25236
- if (exports.VFXItem.isComposition(child)) {
25237
- if (child.ended && child.endBehavior === EndBehavior.restart) {
25238
- child.ended = false;
25239
- // TODO K帧动画在元素重建后需要 tick ,否则会导致元素位置和 k 帧第一帧位置不一致
25240
- this.callUpdate(child, 0);
25241
- } else {
25242
- this.callUpdate(child, dt);
25243
- }
25244
- } else {
25245
- this.callUpdate(child, dt);
25246
- }
25247
- }
25248
- };
25249
- _proto.callLateUpdate = function callLateUpdate(item, dt) {
25250
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25251
- var itemBehaviour = _step.value;
25252
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25253
- itemBehaviour.lateUpdate(dt);
25254
- }
25255
- }
25256
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25257
- var rendererComponent = _step1.value;
25258
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25259
- rendererComponent.lateUpdate(dt);
25260
- }
25261
- }
25262
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25263
- var child = _step2.value;
25264
- this.callLateUpdate(child, dt);
25265
- }
25266
- };
25267
25652
  /**
25268
25653
  * 构建父子树,同时保存到 itemCacheMap 中便于查找
25269
25654
  */ _proto.buildItemTree = function buildItemTree(compVFXItem) {
@@ -27685,7 +28070,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
27685
28070
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
27686
28071
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
27687
28072
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
27688
- var version = "2.0.4";
28073
+ var version = "2.1.0-alpha.1";
27689
28074
  logger.info("Core version: " + version + ".");
27690
28075
 
27691
28076
  exports.AbstractPlugin = AbstractPlugin;