@galacean/effects-threejs 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 threejs plugin 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';
@@ -4629,87 +4629,115 @@ function getDirectStore(target) {
4629
4629
  */ var Component = /*#__PURE__*/ function(EffectsObject) {
4630
4630
  _inherits(Component, EffectsObject);
4631
4631
  function Component() {
4632
- return EffectsObject.apply(this, arguments);
4633
- }
4634
- var _proto = Component.prototype;
4635
- _proto.onAttached = function onAttached() {};
4636
- _proto.onDestroy = function onDestroy() {};
4637
- _proto.fromData = function fromData(data) {
4638
- EffectsObject.prototype.fromData.call(this, data);
4639
- if (data.item) {
4640
- this.item = data.item;
4641
- }
4642
- };
4643
- _proto.dispose = function dispose() {
4644
- this.onDestroy();
4645
- if (this.item) {
4646
- removeItem(this.item.components, this);
4647
- }
4648
- };
4649
- _create_class(Component, [
4650
- {
4651
- key: "transform",
4652
- get: /**
4653
- * 附加到的 VFXItem 对象 Transform 组件
4654
- */ function get() {
4655
- return this.item.transform;
4656
- }
4657
- }
4658
- ]);
4659
- return Component;
4660
- }(EffectsObject);
4661
- /**
4662
- * @since 2.0.0
4663
- */ var Behaviour = /*#__PURE__*/ function(Component) {
4664
- _inherits(Behaviour, Component);
4665
- function Behaviour() {
4666
4632
  var _this;
4667
- _this = Component.apply(this, arguments) || this;
4633
+ _this = EffectsObject.apply(this, arguments) || this;
4668
4634
  _this.isAwakeCalled = false;
4669
4635
  _this.isStartCalled = false;
4636
+ _this.isEnableCalled = false;
4670
4637
  _this._enabled = true;
4671
4638
  return _this;
4672
4639
  }
4673
- var _proto = Behaviour.prototype;
4640
+ var _proto = Component.prototype;
4674
4641
  /**
4675
4642
  * 生命周期函数,初始化后调用,生命周期内只调用一次
4676
- */ _proto.awake = function awake() {
4643
+ */ _proto.onAwake = function onAwake() {
4677
4644
  // OVERRIDE
4678
4645
  };
4679
4646
  /**
4680
- * 在每次设置 enabled true 时触发
4647
+ * enabled 变为 true 时触发
4681
4648
  */ _proto.onEnable = function onEnable() {
4682
4649
  // OVERRIDE
4683
4650
  };
4684
4651
  /**
4652
+ * 在 enabled 变为 false 时触发
4653
+ */ _proto.onDisable = function onDisable() {
4654
+ // OVERRIDE
4655
+ };
4656
+ /**
4685
4657
  * 生命周期函数,在第一次 update 前调用,生命周期内只调用一次
4686
- */ _proto.start = function start() {
4658
+ */ _proto.onStart = function onStart() {
4687
4659
  // OVERRIDE
4688
4660
  };
4689
4661
  /**
4690
4662
  * 生命周期函数,每帧调用一次
4691
- */ _proto.update = function update(dt) {
4663
+ */ _proto.onUpdate = function onUpdate(dt) {
4692
4664
  // OVERRIDE
4693
4665
  };
4694
4666
  /**
4695
4667
  * 生命周期函数,每帧调用一次,在 update 之后调用
4696
- */ _proto.lateUpdate = function lateUpdate(dt) {
4668
+ */ _proto.onLateUpdate = function onLateUpdate(dt) {
4697
4669
  // OVERRIDE
4698
4670
  };
4699
- _proto.onAttached = function onAttached() {
4700
- this.item.itemBehaviours.push(this);
4701
- if (!this.isAwakeCalled) {
4702
- this.awake();
4703
- this.isAwakeCalled = true;
4671
+ /**
4672
+ * 生命周期函数,在组件销毁时调用
4673
+ */ _proto.onDestroy = function onDestroy() {
4674
+ // OVERRIDE
4675
+ };
4676
+ /**
4677
+ * @internal
4678
+ */ _proto.enable = function enable() {
4679
+ if (this.item.composition) {
4680
+ this.item.composition.sceneTicking.addComponent(this);
4681
+ this.isEnableCalled = true;
4682
+ }
4683
+ this.onEnable();
4684
+ };
4685
+ /**
4686
+ * @internal
4687
+ */ _proto.disable = function disable() {
4688
+ this.onDisable();
4689
+ if (this.item.composition) {
4690
+ this.isEnableCalled = false;
4691
+ this.item.composition.sceneTicking.removeComponent(this);
4692
+ }
4693
+ };
4694
+ _proto.setVFXItem = function setVFXItem(item) {
4695
+ this.item = item;
4696
+ if (item.isDuringPlay) {
4697
+ if (!this.isAwakeCalled) {
4698
+ this.onAwake();
4699
+ this.isAwakeCalled = true;
4700
+ }
4701
+ if (item.getVisible() && this.enabled) {
4702
+ this.start();
4703
+ this.enable();
4704
+ }
4705
+ }
4706
+ };
4707
+ _proto.fromData = function fromData(data) {
4708
+ EffectsObject.prototype.fromData.call(this, data);
4709
+ if (data.item) {
4710
+ this.item = data.item;
4704
4711
  }
4705
4712
  };
4706
4713
  _proto.dispose = function dispose() {
4714
+ if (this.isEnableCalled) {
4715
+ this.disable();
4716
+ }
4717
+ if (this.isAwakeCalled) {
4718
+ this.isAwakeCalled = false;
4719
+ this.onDestroy();
4720
+ }
4707
4721
  if (this.item) {
4708
- removeItem(this.item.itemBehaviours, this);
4722
+ removeItem(this.item.components, this);
4709
4723
  }
4710
- Component.prototype.dispose.call(this);
4711
4724
  };
4712
- _create_class(Behaviour, [
4725
+ _proto.start = function start() {
4726
+ if (this.isStartCalled) {
4727
+ return;
4728
+ }
4729
+ this.isStartCalled = true;
4730
+ this.onStart();
4731
+ };
4732
+ _create_class(Component, [
4733
+ {
4734
+ key: "transform",
4735
+ get: /**
4736
+ * 附加到的 VFXItem 对象 Transform 组件
4737
+ */ function get() {
4738
+ return this.item.transform;
4739
+ }
4740
+ },
4713
4741
  {
4714
4742
  key: "isActiveAndEnabled",
4715
4743
  get: /**
@@ -4724,24 +4752,46 @@ function getDirectStore(target) {
4724
4752
  return this._enabled;
4725
4753
  },
4726
4754
  set: function set(value) {
4727
- this._enabled = value;
4728
- if (value) {
4729
- if (this.isActiveAndEnabled) {
4730
- this.onEnable();
4731
- }
4732
- if (!this.isStartCalled) {
4733
- this.start();
4734
- this.isStartCalled = true;
4755
+ if (this.enabled !== value) {
4756
+ this._enabled = value;
4757
+ if (value) {
4758
+ if (this.isActiveAndEnabled) {
4759
+ this.enable();
4760
+ if (!this.isStartCalled) {
4761
+ this.onStart();
4762
+ this.isStartCalled = true;
4763
+ }
4764
+ }
4765
+ } else {
4766
+ if (this.isEnableCalled) {
4767
+ this.disable();
4768
+ }
4735
4769
  }
4736
4770
  }
4737
4771
  }
4738
4772
  }
4739
4773
  ]);
4740
- return Behaviour;
4741
- }(Component);
4774
+ return Component;
4775
+ }(EffectsObject);
4742
4776
  __decorate([
4743
4777
  serialize()
4744
- ], Behaviour.prototype, "_enabled", void 0);
4778
+ ], Component.prototype, "_enabled", void 0);
4779
+ /**
4780
+ * @since 2.0.0
4781
+ */ var Behaviour = /*#__PURE__*/ function(Component) {
4782
+ _inherits(Behaviour, Component);
4783
+ function Behaviour() {
4784
+ return Component.apply(this, arguments);
4785
+ }
4786
+ var _proto = Behaviour.prototype;
4787
+ _proto.setVFXItem = function setVFXItem(item) {
4788
+ Component.prototype.setVFXItem.call(this, item);
4789
+ };
4790
+ _proto.dispose = function dispose() {
4791
+ Component.prototype.dispose.call(this);
4792
+ };
4793
+ return Behaviour;
4794
+ }(Component);
4745
4795
 
4746
4796
  /**
4747
4797
  * 所有渲染组件的基类
@@ -4751,19 +4801,14 @@ __decorate([
4751
4801
  function RendererComponent() {
4752
4802
  var _this;
4753
4803
  _this = Component.apply(this, arguments) || this;
4754
- _this.isStartCalled = false;
4755
4804
  _this.materials = [];
4756
4805
  _this._priority = 0;
4757
- _this._enabled = true;
4758
4806
  return _this;
4759
4807
  }
4760
4808
  var _proto = RendererComponent.prototype;
4761
- _proto.onEnable = function onEnable() {};
4762
- _proto.start = function start() {};
4763
- _proto.update = function update(dt) {};
4764
- _proto.lateUpdate = function lateUpdate(dt) {};
4765
4809
  _proto.render = function render(renderer) {};
4766
- _proto.onAttached = function onAttached() {
4810
+ _proto.setVFXItem = function setVFXItem(item) {
4811
+ Component.prototype.setVFXItem.call(this, item);
4767
4812
  this.item.rendererComponents.push(this);
4768
4813
  };
4769
4814
  _proto.fromData = function fromData(data) {
@@ -4788,26 +4833,6 @@ __decorate([
4788
4833
  this._priority = value;
4789
4834
  }
4790
4835
  },
4791
- {
4792
- key: "enabled",
4793
- get: function get() {
4794
- return this._enabled;
4795
- },
4796
- set: function set(value) {
4797
- this._enabled = value;
4798
- if (value) {
4799
- this.onEnable();
4800
- }
4801
- }
4802
- },
4803
- {
4804
- key: "isActiveAndEnabled",
4805
- get: /**
4806
- * 组件是否可以更新,true 更新,false 不更新
4807
- */ function get() {
4808
- return this.item.getVisible() && this.enabled;
4809
- }
4810
- },
4811
4836
  {
4812
4837
  key: "material",
4813
4838
  get: function get() {
@@ -4830,9 +4855,6 @@ __decorate([
4830
4855
  __decorate([
4831
4856
  serialize()
4832
4857
  ], RendererComponent.prototype, "_priority", void 0);
4833
- __decorate([
4834
- serialize()
4835
- ], RendererComponent.prototype, "_enabled", void 0);
4836
4858
 
4837
4859
  /**
4838
4860
  * 抽象插件类
@@ -4876,7 +4898,7 @@ exports.CameraController = /*#__PURE__*/ function(Behaviour) {
4876
4898
  return _this;
4877
4899
  }
4878
4900
  var _proto = CameraController.prototype;
4879
- _proto.update = function update() {
4901
+ _proto.onUpdate = function onUpdate() {
4880
4902
  if (this.item.composition && this.item.transform.getValid()) {
4881
4903
  var camera = this.item.composition.camera;
4882
4904
  camera.near = this.options.near;
@@ -10036,8 +10058,13 @@ var RandomValue = /*#__PURE__*/ function(ValueGetter) {
10036
10058
  this.min = props[0];
10037
10059
  this.max = props[1];
10038
10060
  };
10039
- _proto.getValue = function getValue(time) {
10040
- return randomInRange(this.min, this.max);
10061
+ _proto.getValue = function getValue(time, seed) {
10062
+ var randomSeed = seed != null ? seed : Math.random();
10063
+ return this.min + randomSeed * (this.max - this.min);
10064
+ };
10065
+ _proto.getIntegrateValue = function getIntegrateValue(t0, t1, timeScale) {
10066
+ var seed = timeScale != null ? timeScale : 1.0;
10067
+ return (this.min + seed * (this.max - this.min)) * (t1 - t0);
10041
10068
  };
10042
10069
  _proto.toUniform = function toUniform() {
10043
10070
  return new Float32Array([
@@ -11564,7 +11591,7 @@ var itemFrag = "precision highp float;varying vec4 vColor;varying vec2 vTexCoord
11564
11591
 
11565
11592
  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";
11566
11593
 
11567
- 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}}";
11594
+ 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}}";
11568
11595
 
11569
11596
  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}";
11570
11597
 
@@ -13274,7 +13301,7 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13274
13301
  return _this;
13275
13302
  }
13276
13303
  var _proto = InteractComponent.prototype;
13277
- _proto.start = function start() {
13304
+ _proto.onStart = function onStart() {
13278
13305
  var _this = this;
13279
13306
  var options = this.item.props.content.options;
13280
13307
  var env = this.item.engine.renderer.env;
@@ -13310,8 +13337,11 @@ exports.InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13310
13337
  }
13311
13338
  };
13312
13339
  };
13313
- _proto.update = function update(dt) {
13340
+ _proto.onUpdate = function onUpdate(dt) {
13314
13341
  var _this_previewContent;
13342
+ if (!this.isActiveAndEnabled) {
13343
+ return;
13344
+ }
13315
13345
  (_this_previewContent = this.previewContent) == null ? void 0 : _this_previewContent.updateMesh();
13316
13346
  if (!this.hasBeenAddedToComposition && this.item.composition) {
13317
13347
  var options = this.item.props.content.options;
@@ -13654,6 +13684,9 @@ function _assert_this_initialized(self) {
13654
13684
  this.outputs = [];
13655
13685
  this.playState = 0;
13656
13686
  this.traversalMode = 0;
13687
+ /**
13688
+ * 当前本地播放的时间
13689
+ */ this.time = 0;
13657
13690
  graph.addPlayable(this);
13658
13691
  this.inputs = new Array(inputCount);
13659
13692
  this.inputOuputPorts = new Array(inputCount);
@@ -14099,10 +14132,10 @@ exports.SpriteComponent = /*#__PURE__*/ function(RendererComponent) {
14099
14132
  this.material.setVector2("_Size", this.transform.size);
14100
14133
  renderer.drawGeometry(geo, material);
14101
14134
  };
14102
- _proto.start = function start() {
14135
+ _proto.onStart = function onStart() {
14103
14136
  this.item.getHitTestParams = this.getHitTestParams;
14104
14137
  };
14105
- _proto.update = function update(dt) {
14138
+ _proto.onUpdate = function onUpdate(dt) {
14106
14139
  if (!this.isManualTimeSet) {
14107
14140
  this.frameAnimationTime += dt / 1000;
14108
14141
  this.isManualTimeSet = false;
@@ -16525,17 +16558,18 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16525
16558
  return _this;
16526
16559
  }
16527
16560
  var _proto = ParticleSystemRenderer.prototype;
16528
- _proto.start = function start() {
16561
+ _proto.onStart = function onStart() {
16529
16562
  this._priority = this.item.renderOrder;
16530
16563
  this.particleMesh.gravityModifier.scaleXCoord(this.item.duration);
16531
16564
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
16532
16565
  var mesh = _step.value;
16533
- mesh.start();
16566
+ mesh.onStart();
16534
16567
  }
16535
16568
  };
16536
- _proto.update = function update(dt) {
16569
+ _proto.onUpdate = function onUpdate(dt) {
16537
16570
  var time = this.particleMesh.time;
16538
16571
  this.particleMesh.mesh.material.setVector4("uParams", new Vector4(time, this.item.duration, 0, 0));
16572
+ this.particleMesh.onUpdate(dt);
16539
16573
  };
16540
16574
  _proto.render = function render(renderer) {
16541
16575
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
@@ -16550,6 +16584,7 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16550
16584
  };
16551
16585
  _proto.updateTime = function updateTime(now, delta) {
16552
16586
  this.particleMesh.time = now;
16587
+ // this.particleMesh.onUpdate(delta);
16553
16588
  if (this.trailMesh) {
16554
16589
  this.trailMesh.time = now;
16555
16590
  this.trailMesh.onUpdate(delta);
@@ -16760,7 +16795,7 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16760
16795
  _proto.getTextures = function getTextures() {
16761
16796
  return this.renderer.getTextures();
16762
16797
  };
16763
- _proto.start = function start() {
16798
+ _proto.startEmit = function startEmit() {
16764
16799
  if (!this.started || this.ended) {
16765
16800
  this.reset();
16766
16801
  this.started = true;
@@ -16786,7 +16821,7 @@ exports.ParticleSystem = /*#__PURE__*/ function(Component) {
16786
16821
  this.frozen = false;
16787
16822
  this.ended = false;
16788
16823
  };
16789
- _proto.onUpdate = function onUpdate(delta) {
16824
+ _proto.update = function update(delta) {
16790
16825
  var _this = this;
16791
16826
  if (this.started && !this.frozen) {
16792
16827
  var now = this.lastUpdate + delta / 1000;
@@ -17586,7 +17621,7 @@ function randomArrItem(arr, keepArr) {
17586
17621
  this.particleSystem = boundObject.getComponent(exports.ParticleSystem);
17587
17622
  if (this.particleSystem) {
17588
17623
  this.particleSystem.name = boundObject.name;
17589
- this.particleSystem.start();
17624
+ this.particleSystem.startEmit();
17590
17625
  this.particleSystem.initEmitterTransform();
17591
17626
  }
17592
17627
  };
@@ -17603,7 +17638,7 @@ function randomArrItem(arr, keepArr) {
17603
17638
  if (Math.abs(this.time - this.lastTime) < 0.001) {
17604
17639
  deltaTime = 0;
17605
17640
  }
17606
- particleSystem.onUpdate(deltaTime);
17641
+ particleSystem.update(deltaTime);
17607
17642
  }
17608
17643
  this.lastTime = this.time;
17609
17644
  };
@@ -17656,6 +17691,7 @@ var particleUniformTypeMap = {
17656
17691
  var ParticleMesh = /*#__PURE__*/ function() {
17657
17692
  function ParticleMesh(engine, props) {
17658
17693
  this.particleCount = 0;
17694
+ this.VERT_MAX_KEY_FRAME_COUNT = 0;
17659
17695
  var _engine_renderer;
17660
17696
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
17661
17697
  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;
@@ -17874,6 +17910,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17874
17910
  "FRAG_MAX_KEY_FRAME_COUNT",
17875
17911
  fragmentKeyFrameMeta.max
17876
17912
  ]);
17913
+ this.VERT_MAX_KEY_FRAME_COUNT = vertexKeyFrameMeta.max;
17877
17914
  var fragment = particleFrag;
17878
17915
  var originalVertex = "#define LOOKUP_TEXTURE_CURVE " + vertex_lookup_texture + "\n" + particleVert;
17879
17916
  var vertex = originalVertex;
@@ -17982,6 +18019,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17982
18019
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17983
18020
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17984
18021
  this.gravityModifier = gravityModifier;
18022
+ this.rotationOverLifetime = rotationOverLifetime;
17985
18023
  this.maxCount = maxCount;
17986
18024
  // this.duration = duration;
17987
18025
  this.textureOffsets = textureFlip ? [
@@ -18046,15 +18084,232 @@ var ParticleMesh = /*#__PURE__*/ function() {
18046
18084
  // @ts-expect-error
18047
18085
  geometry.setIndexData(new index.constructor(0));
18048
18086
  };
18087
+ _proto.onUpdate = function onUpdate(dt) {
18088
+ var aPosArray = this.geometry.getAttributeData("aPos"); // vector3
18089
+ var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18090
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18091
+ var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18092
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18093
+ // const uParams = this.mesh.material.getVector4('uParams');
18094
+ // if (!uParams) {
18095
+ // return;
18096
+ // }
18097
+ var localTime = new Float32Array([
18098
+ this.time
18099
+ ])[0];
18100
+ var particleCount = Math.ceil(aPosArray.length / 12);
18101
+ // calculate particle translation
18102
+ var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18103
+ if (aTranslationArray.length < particleCount * 3) {
18104
+ aTranslationArray = new Float32Array(particleCount * 3);
18105
+ }
18106
+ var velocity = new Vector3(0, 0, 0);
18107
+ for(var i = 0; i < particleCount; i++){
18108
+ var velOffset = i * 12 + 3;
18109
+ velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18110
+ var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18111
+ var aTranslationOffset = i * 3;
18112
+ aTranslationArray[aTranslationOffset] = trans.x;
18113
+ aTranslationArray[aTranslationOffset + 1] = trans.y;
18114
+ aTranslationArray[aTranslationOffset + 2] = trans.z;
18115
+ }
18116
+ this.geometry.setAttributeData("aTranslation", aTranslationArray);
18117
+ // calculate particle rotation
18118
+ var aRotationArray = this.geometry.getAttributeData("aRotation0");
18119
+ if (aRotationArray.length < particleCount * 9) {
18120
+ aRotationArray = new Float32Array(particleCount * 9);
18121
+ }
18122
+ for(var i1 = 0; i1 < particleCount; i1++){
18123
+ var time = localTime - aOffsetArray[i1 * 4 + 2];
18124
+ var duration = aOffsetArray[i1 * 4 + 3];
18125
+ var life = clamp$1(time / duration, 0.0, 1.0);
18126
+ var aRotOffset = i1 * 8;
18127
+ var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18128
+ var aSeed = aSeedArray[i1 * 8 + 3];
18129
+ var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18130
+ var aRotationOffset = i1 * 9;
18131
+ var matrixArray = aRotation.toArray();
18132
+ aRotationArray.set(matrixArray, aRotationOffset);
18133
+ }
18134
+ this.geometry.setAttributeData("aRotation0", aRotationArray);
18135
+ // calculate linear movement
18136
+ var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18137
+ if (aLinearMoveArray.length < particleCount * 3) {
18138
+ aLinearMoveArray = new Float32Array(particleCount * 3);
18139
+ }
18140
+ for(var i2 = 0; i2 < particleCount; i2++){
18141
+ var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18142
+ var duration1 = aOffsetArray[i2 * 4 + 3];
18143
+ // const life = math.clamp(time / duration, 0.0, 1.0);
18144
+ var aSeed1 = aSeedArray[i2 * 8 + 3];
18145
+ var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18146
+ var aLinearMoveOffset = i2 * 3;
18147
+ aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18148
+ aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18149
+ aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18150
+ }
18151
+ this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18152
+ };
18049
18153
  _proto.minusTime = function minusTime(time) {
18050
- var data = this.geometry.getAttributeData("aOffset");
18051
- assertExist(data);
18052
- for(var i = 0; i < data.length; i += 4){
18053
- data[i + 2] -= time;
18154
+ var aOffset = this.geometry.getAttributeData("aOffset");
18155
+ for(var i = 0; i < aOffset.length; i += 4){
18156
+ aOffset[i + 2] -= time;
18054
18157
  }
18055
- this.geometry.setAttributeData("aOffset", data);
18158
+ this.geometry.setAttributeData("aOffset", aOffset);
18056
18159
  this.time -= time;
18057
18160
  };
18161
+ _proto.calculateTranslation = function calculateTranslation(velocity, t0, t1, duration) {
18162
+ var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18163
+ var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18164
+ if (!uAcceleration || !uGravityModifierValue) {
18165
+ return new Vector3();
18166
+ }
18167
+ var dt = t1 - t0; // 相对delay的时间
18168
+ var d = this.gravityModifier.getIntegrateByTime(0, dt);
18169
+ var acc = [
18170
+ uAcceleration.x * d,
18171
+ uAcceleration.y * d,
18172
+ uAcceleration.z * d
18173
+ ];
18174
+ // ret.addScaledVector(velData, speedIntegrate);
18175
+ // ret.addScaledVector(acc, d);
18176
+ // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18177
+ if (this.speedOverLifetime) {
18178
+ // dt / dur 归一化
18179
+ var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18180
+ return velocity.clone().multiply(speed).add(acc);
18181
+ }
18182
+ return velocity.clone().multiply(dt).add(acc);
18183
+ };
18184
+ _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18185
+ var rotation = rot.clone();
18186
+ if (!this.rotationOverLifetime) {
18187
+ return new Matrix3();
18188
+ }
18189
+ if (this.rotationOverLifetime.asRotation) {
18190
+ // Adjust rotation based on the specified lifetime components
18191
+ if (this.rotationOverLifetime.x) {
18192
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18193
+ rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18194
+ } else {
18195
+ rotation.x += this.rotationOverLifetime.x.getValue(life);
18196
+ }
18197
+ }
18198
+ if (this.rotationOverLifetime.y) {
18199
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18200
+ rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18201
+ } else {
18202
+ rotation.y += this.rotationOverLifetime.y.getValue(life);
18203
+ }
18204
+ }
18205
+ if (this.rotationOverLifetime.z) {
18206
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18207
+ rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18208
+ } else {
18209
+ rotation.z += this.rotationOverLifetime.z.getValue(life);
18210
+ }
18211
+ }
18212
+ } else {
18213
+ // Adjust rotation based on the specified lifetime components
18214
+ if (this.rotationOverLifetime.x) {
18215
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18216
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * dur;
18217
+ } else {
18218
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, dur) * dur;
18219
+ }
18220
+ }
18221
+ if (this.rotationOverLifetime.y) {
18222
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18223
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * dur;
18224
+ } else {
18225
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, dur) * dur;
18226
+ }
18227
+ }
18228
+ if (this.rotationOverLifetime.z) {
18229
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18230
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * dur;
18231
+ } else {
18232
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, dur) * dur;
18233
+ }
18234
+ }
18235
+ }
18236
+ // If the rotation vector is zero, return the identity matrix
18237
+ if (rotation.dot(rotation) === 0.0) {
18238
+ return new Matrix3().identity();
18239
+ }
18240
+ // Return the rotation matrix derived from the rotation vector
18241
+ return this.mat3FromRotation(rotation);
18242
+ };
18243
+ _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18244
+ var d2r = Math.PI / 180;
18245
+ var sinR = rotation.clone().multiply(d2r);
18246
+ sinR.x = Math.sin(sinR.x);
18247
+ sinR.y = Math.sin(sinR.y);
18248
+ sinR.z = Math.sin(sinR.z);
18249
+ var cosR = rotation.clone().multiply(d2r);
18250
+ cosR.x = Math.cos(cosR.x);
18251
+ cosR.y = Math.cos(cosR.y);
18252
+ cosR.z = Math.cos(cosR.z);
18253
+ var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18254
+ var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18255
+ var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18256
+ var result = rotZ.multiply(rotY).multiply(rotX);
18257
+ return result;
18258
+ };
18259
+ _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18260
+ var mov = new Vector3();
18261
+ var lifetime = time / duration;
18262
+ if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18263
+ return new Vector3();
18264
+ }
18265
+ if (this.linearVelOverLifetime.asMovement) {
18266
+ if (this.linearVelOverLifetime.x) {
18267
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18268
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18269
+ } else {
18270
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime);
18271
+ }
18272
+ }
18273
+ if (this.linearVelOverLifetime.y) {
18274
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18275
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18276
+ } else {
18277
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime);
18278
+ }
18279
+ }
18280
+ if (this.linearVelOverLifetime.z) {
18281
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18282
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18283
+ } else {
18284
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime);
18285
+ }
18286
+ }
18287
+ } else {
18288
+ // Adjust rotation based on the specified lifetime components
18289
+ if (this.linearVelOverLifetime.x) {
18290
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18291
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18292
+ } else {
18293
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18294
+ }
18295
+ }
18296
+ if (this.linearVelOverLifetime.y) {
18297
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18298
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18299
+ } else {
18300
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18301
+ }
18302
+ }
18303
+ if (this.linearVelOverLifetime.z) {
18304
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18305
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18306
+ } else {
18307
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18308
+ }
18309
+ }
18310
+ }
18311
+ return mov;
18312
+ };
18058
18313
  _proto.removePoint = function removePoint(index) {
18059
18314
  if (index < this.particleCount) {
18060
18315
  this.geometry.setAttributeSubData("aOffset", index * 16, new Float32Array(16));
@@ -18256,6 +18511,32 @@ function generateGeometryProps(maxVertex, useSprite, name) {
18256
18511
  size: 4,
18257
18512
  stride: 4 * bpe,
18258
18513
  data: new Float32Array(0)
18514
+ },
18515
+ aTranslation: {
18516
+ size: 3,
18517
+ data: new Float32Array(0)
18518
+ },
18519
+ aLinearMove: {
18520
+ size: 3,
18521
+ data: new Float32Array(0)
18522
+ },
18523
+ aRotation0: {
18524
+ size: 3,
18525
+ offset: 0,
18526
+ stride: 9 * bpe,
18527
+ data: new Float32Array(0)
18528
+ },
18529
+ aRotation1: {
18530
+ size: 3,
18531
+ offset: 3 * bpe,
18532
+ stride: 9 * bpe,
18533
+ dataSource: "aRotation0"
18534
+ },
18535
+ aRotation2: {
18536
+ size: 3,
18537
+ offset: 6 * bpe,
18538
+ stride: 9 * bpe,
18539
+ dataSource: "aRotation0"
18259
18540
  }
18260
18541
  };
18261
18542
  if (useSprite) {
@@ -19333,25 +19614,15 @@ var TrackSortWrapper = function TrackSortWrapper(track, originalIndex) {
19333
19614
  this.track = track;
19334
19615
  this.originalIndex = originalIndex;
19335
19616
  };
19336
- function isAncestor(ancestorCandidate, descendantCandidate) {
19337
- var current = descendantCandidate.parent;
19338
- while(current){
19339
- if (current === ancestorCandidate) {
19340
- return true;
19341
- }
19342
- current = current.parent;
19343
- }
19344
- return false;
19345
- }
19346
19617
  function compareTracks(a, b) {
19347
19618
  var bindingA = a.track.binding;
19348
19619
  var bindingB = b.track.binding;
19349
19620
  if (!_instanceof1(bindingA, exports.VFXItem) || !_instanceof1(bindingB, exports.VFXItem)) {
19350
19621
  return a.originalIndex - b.originalIndex;
19351
19622
  }
19352
- if (isAncestor(bindingA, bindingB)) {
19623
+ if (exports.VFXItem.isAncestor(bindingA, bindingB)) {
19353
19624
  return -1;
19354
- } else if (isAncestor(bindingB, bindingA)) {
19625
+ } else if (exports.VFXItem.isAncestor(bindingB, bindingA)) {
19355
19626
  return 1;
19356
19627
  } else {
19357
19628
  return a.originalIndex - b.originalIndex; // 非父子关系的元素保持原始顺序
@@ -19375,7 +19646,7 @@ function compareTracks(a, b) {
19375
19646
  return _this;
19376
19647
  }
19377
19648
  var _proto = CompositionComponent.prototype;
19378
- _proto.start = function start() {
19649
+ _proto.onStart = function onStart() {
19379
19650
  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;
19380
19651
  this.startTime = startTime;
19381
19652
  this.resolveBindings();
@@ -19403,7 +19674,7 @@ function compareTracks(a, b) {
19403
19674
  _proto.getReusable = function getReusable() {
19404
19675
  return this.reusable;
19405
19676
  };
19406
- _proto.update = function update(dt) {
19677
+ _proto.onUpdate = function onUpdate(dt) {
19407
19678
  var time = this.time;
19408
19679
  this.timelinePlayable.setTime(time);
19409
19680
  this.graph.evaluate(dt);
@@ -19439,7 +19710,9 @@ function compareTracks(a, b) {
19439
19710
  props.content = itemData.content;
19440
19711
  item = assetLoader.loadGUID(itemData.id);
19441
19712
  item.composition = this.item.composition;
19442
- var compositionComponent = item.addComponent(CompositionComponent);
19713
+ var compositionComponent = new CompositionComponent(this.engine);
19714
+ compositionComponent.item = item;
19715
+ item.components.push(compositionComponent);
19443
19716
  compositionComponent.data = props;
19444
19717
  compositionComponent.refId = refId;
19445
19718
  item.transform.parentTransform = this.transform;
@@ -19893,8 +20166,8 @@ exports.TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19893
20166
  return _this;
19894
20167
  }
19895
20168
  var _proto = TextComponent.prototype;
19896
- _proto.update = function update(dt) {
19897
- SpriteComponent.prototype.update.call(this, dt);
20169
+ _proto.onUpdate = function onUpdate(dt) {
20170
+ SpriteComponent.prototype.onUpdate.call(this, dt);
19898
20171
  this.updateTexture();
19899
20172
  };
19900
20173
  _proto.fromData = function fromData(data) {
@@ -20309,7 +20582,7 @@ exports.EffectComponent = /*#__PURE__*/ function(RendererComponent) {
20309
20582
  return _this;
20310
20583
  }
20311
20584
  var _proto = EffectComponent.prototype;
20312
- _proto.start = function start() {
20585
+ _proto.onStart = function onStart() {
20313
20586
  this.item.getHitTestParams = this.getHitTestParams;
20314
20587
  };
20315
20588
  _proto.render = function render(renderer) {
@@ -20436,7 +20709,7 @@ exports.PostProcessVolume = /*#__PURE__*/ function(Behaviour) {
20436
20709
  return _this;
20437
20710
  }
20438
20711
  var _proto = PostProcessVolume.prototype;
20439
- _proto.start = function start() {
20712
+ _proto.onStart = function onStart() {
20440
20713
  var composition = this.item.composition;
20441
20714
  if (composition) {
20442
20715
  composition.globalVolume = this;
@@ -20578,8 +20851,8 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20578
20851
  */ _this.ended = false;
20579
20852
  _this.reusable = false;
20580
20853
  _this.type = ItemType.base;
20854
+ _this.isDuringPlay = false;
20581
20855
  _this.components = [];
20582
- _this.itemBehaviours = [];
20583
20856
  _this.rendererComponents = [];
20584
20857
  /**
20585
20858
  * 元素可见性,该值的改变会触发 `handleVisibleChanged` 回调
@@ -20589,6 +20862,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20589
20862
  * 元素动画的速度
20590
20863
  */ _this.speed = 1;
20591
20864
  _this.listIndex = 0;
20865
+ _this.isEnabled = false;
20592
20866
  _this.eventProcessor = new EventEmitter();
20593
20867
  _this.name = "VFXItem";
20594
20868
  _this.transform.name = _this.name;
@@ -20661,8 +20935,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20661
20935
  */ _proto.addComponent = function addComponent(classConstructor) {
20662
20936
  var newComponent = new classConstructor(this.engine);
20663
20937
  this.components.push(newComponent);
20664
- newComponent.item = this;
20665
- newComponent.onAttached();
20938
+ newComponent.setVFXItem(this);
20666
20939
  return newComponent;
20667
20940
  };
20668
20941
  /**
@@ -20695,21 +20968,22 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20695
20968
  return res;
20696
20969
  };
20697
20970
  _proto.setParent = function setParent(vfxItem) {
20698
- if (vfxItem === this) {
20971
+ if (vfxItem === this && !vfxItem) {
20699
20972
  return;
20700
20973
  }
20701
20974
  if (this.parent) {
20702
20975
  removeItem(this.parent.children, this);
20703
20976
  }
20704
20977
  this.parent = vfxItem;
20705
- if (vfxItem) {
20706
- if (!VFXItem.isCamera(this)) {
20707
- this.transform.parentTransform = vfxItem.transform;
20708
- }
20709
- vfxItem.children.push(this);
20710
- if (!this.composition) {
20711
- this.composition = vfxItem.composition;
20712
- }
20978
+ if (!VFXItem.isCamera(this)) {
20979
+ this.transform.parentTransform = vfxItem.transform;
20980
+ }
20981
+ vfxItem.children.push(this);
20982
+ if (!this.composition) {
20983
+ this.composition = vfxItem.composition;
20984
+ }
20985
+ if (!this.isDuringPlay && vfxItem.isDuringPlay) {
20986
+ this.beginPlay();
20713
20987
  }
20714
20988
  };
20715
20989
  /**
@@ -20740,6 +21014,7 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20740
21014
  */ _proto.setVisible = function setVisible(visible) {
20741
21015
  if (this.visible !== visible) {
20742
21016
  this.visible = !!visible;
21017
+ this.onActiveChanged();
20743
21018
  }
20744
21019
  };
20745
21020
  /**
@@ -20864,6 +21139,57 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20864
21139
  }
20865
21140
  return undefined;
20866
21141
  };
21142
+ /**
21143
+ * @internal
21144
+ */ _proto.beginPlay = function beginPlay() {
21145
+ this.isDuringPlay = true;
21146
+ if (this.composition && this.visible && !this.isEnabled) {
21147
+ this.onEnable();
21148
+ }
21149
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
21150
+ var child = _step.value;
21151
+ if (!child.isDuringPlay) {
21152
+ child.beginPlay();
21153
+ }
21154
+ }
21155
+ };
21156
+ /**
21157
+ * @internal
21158
+ */ _proto.onActiveChanged = function onActiveChanged() {
21159
+ if (!this.isEnabled) {
21160
+ this.onEnable();
21161
+ } else {
21162
+ this.onDisable();
21163
+ }
21164
+ };
21165
+ /**
21166
+ * @internal
21167
+ */ _proto.onEnable = function onEnable() {
21168
+ this.isEnabled = true;
21169
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21170
+ var component = _step.value;
21171
+ if (component.enabled && !component.isStartCalled) {
21172
+ component.onStart();
21173
+ }
21174
+ }
21175
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.components), _step1; !(_step1 = _iterator1()).done;){
21176
+ var component1 = _step1.value;
21177
+ if (component1.enabled && !component1.isEnableCalled) {
21178
+ component1.enable();
21179
+ }
21180
+ }
21181
+ };
21182
+ /**
21183
+ * @internal
21184
+ */ _proto.onDisable = function onDisable() {
21185
+ this.isEnabled = false;
21186
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21187
+ var component = _step.value;
21188
+ if (component.enabled && component.isEnableCalled) {
21189
+ component.disable();
21190
+ }
21191
+ }
21192
+ };
20867
21193
  _proto.fromData = function fromData(data) {
20868
21194
  EffectsObject.prototype.fromData.call(this, data);
20869
21195
  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;
@@ -20913,14 +21239,10 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
20913
21239
  if (duration <= 0) {
20914
21240
  throw new Error("Item duration can't be less than 0, see " + HELP_LINK["Item duration can't be less than 0"] + ".");
20915
21241
  }
20916
- this.itemBehaviours.length = 0;
20917
21242
  this.rendererComponents.length = 0;
20918
21243
  for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
20919
21244
  var component = _step.value;
20920
21245
  component.item = this;
20921
- if (_instanceof1(component, Behaviour)) {
20922
- this.itemBehaviours.push(component);
20923
- }
20924
21246
  if (_instanceof1(component, RendererComponent)) {
20925
21247
  this.rendererComponents.push(component);
20926
21248
  }
@@ -21025,6 +21347,16 @@ exports.VFXItem = /*#__PURE__*/ function(EffectsObject) {
21025
21347
  VFXItem.isExtraCamera = function isExtraCamera(item) {
21026
21348
  return item.id === "extra-camera" && item.name === "extra-camera";
21027
21349
  };
21350
+ VFXItem.isAncestor = function isAncestor(ancestorCandidate, descendantCandidate) {
21351
+ var current = descendantCandidate.parent;
21352
+ while(current){
21353
+ if (current === ancestorCandidate) {
21354
+ return true;
21355
+ }
21356
+ current = current.parent;
21357
+ }
21358
+ return false;
21359
+ };
21028
21360
  _create_class(VFXItem, [
21029
21361
  {
21030
21362
  key: "content",
@@ -24879,6 +25211,109 @@ var listOrder = 0;
24879
25211
  return CompositionSourceManager;
24880
25212
  }();
24881
25213
 
25214
+ var SceneTicking = /*#__PURE__*/ function() {
25215
+ function SceneTicking() {
25216
+ this.update = new UpdateTickData();
25217
+ this.lateUpdate = new LateUpdateTickData();
25218
+ }
25219
+ var _proto = SceneTicking.prototype;
25220
+ _proto.addComponent = function addComponent(obj) {
25221
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25222
+ this.update.addComponent(obj);
25223
+ }
25224
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25225
+ this.lateUpdate.addComponent(obj);
25226
+ }
25227
+ };
25228
+ _proto.removeComponent = function removeComponent(obj) {
25229
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25230
+ this.update.removeComponent(obj);
25231
+ }
25232
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25233
+ this.lateUpdate.removeComponent(obj);
25234
+ }
25235
+ };
25236
+ _proto.clear = function clear() {
25237
+ this.update.clear();
25238
+ this.lateUpdate.clear();
25239
+ };
25240
+ return SceneTicking;
25241
+ }();
25242
+ var TickData = /*#__PURE__*/ function() {
25243
+ function TickData() {
25244
+ this.components = [];
25245
+ this.ticks = [];
25246
+ }
25247
+ var _proto = TickData.prototype;
25248
+ _proto.tick = function tick(dt) {
25249
+ this.tickComponents(this.components, dt);
25250
+ for(var i = 0; i < this.ticks.length; i++){
25251
+ this.ticks[i](dt);
25252
+ }
25253
+ };
25254
+ _proto.tickComponents = function tickComponents(components, dt) {
25255
+ // To be implemented in derived classes
25256
+ };
25257
+ _proto.addComponent = function addComponent(component) {
25258
+ if (!this.components.includes(component)) {
25259
+ this.components.push(component);
25260
+ }
25261
+ };
25262
+ _proto.removeComponent = function removeComponent(component) {
25263
+ var index = this.components.indexOf(component);
25264
+ if (index > -1) {
25265
+ this.components.splice(index, 1);
25266
+ }
25267
+ };
25268
+ _proto.addTick = function addTick(method, callee) {
25269
+ var tick = method.bind(callee);
25270
+ if (!this.ticks.includes(tick)) {
25271
+ this.ticks.push(tick);
25272
+ }
25273
+ };
25274
+ _proto.clear = function clear() {
25275
+ this.components = [];
25276
+ };
25277
+ return TickData;
25278
+ }();
25279
+ var UpdateTickData = /*#__PURE__*/ function(TickData) {
25280
+ _inherits(UpdateTickData, TickData);
25281
+ function UpdateTickData() {
25282
+ return TickData.apply(this, arguments);
25283
+ }
25284
+ var _proto = UpdateTickData.prototype;
25285
+ _proto.tickComponents = function tickComponents(components, dt) {
25286
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25287
+ var component = _step.value;
25288
+ component.onUpdate(dt);
25289
+ }
25290
+ };
25291
+ return UpdateTickData;
25292
+ }(TickData);
25293
+ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
25294
+ _inherits(LateUpdateTickData, TickData);
25295
+ function LateUpdateTickData() {
25296
+ return TickData.apply(this, arguments);
25297
+ }
25298
+ var _proto = LateUpdateTickData.prototype;
25299
+ _proto.tickComponents = function tickComponents(components, dt) {
25300
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25301
+ var component = _step.value;
25302
+ component.onLateUpdate(dt);
25303
+ }
25304
+ };
25305
+ return LateUpdateTickData;
25306
+ } // function compareComponents (a: Component, b: Component): number {
25307
+ // const itemA = a.item;
25308
+ // const itemB = b.item;
25309
+ // if (VFXItem.isAncestor(itemA, itemB)) {
25310
+ // return -1;
25311
+ // } else {
25312
+ // return 1;
25313
+ // }
25314
+ // }
25315
+ (TickData);
25316
+
24882
25317
  /**
24883
25318
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24884
25319
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
@@ -24888,6 +25323,7 @@ var listOrder = 0;
24888
25323
  function Composition(props, scene) {
24889
25324
  var _this;
24890
25325
  _this = EventEmitter.call(this) || this;
25326
+ _this.sceneTicking = new SceneTicking();
24891
25327
  /**
24892
25328
  * 动画播放速度
24893
25329
  */ _this.speed = 1;
@@ -24925,9 +25361,12 @@ var listOrder = 0;
24925
25361
  _this.rootItem = new exports.VFXItem(_this.getEngine(), sourceContent);
24926
25362
  _this.rootItem.name = "rootItem";
24927
25363
  _this.rootItem.composition = _assert_this_initialized(_this);
24928
- _this.rootComposition = _this.rootItem.addComponent(CompositionComponent);
25364
+ // Spawn rootCompositionComponent
25365
+ _this.rootComposition = new CompositionComponent(_this.getEngine());
24929
25366
  _this.rootComposition.startTime = sourceContent.startTime;
24930
25367
  _this.rootComposition.data = sourceContent;
25368
+ _this.rootComposition.item = _this.rootItem;
25369
+ _this.rootItem.components.push(_this.rootComposition);
24931
25370
  var imageUsage = !reusable && imgUsage;
24932
25371
  _this.width = width;
24933
25372
  _this.height = height;
@@ -24961,7 +25400,6 @@ var listOrder = 0;
24961
25400
  _this.rendererOptions = null;
24962
25401
  _this.rootComposition.createContent();
24963
25402
  _this.buildItemTree(_this.rootItem);
24964
- _this.callAwake(_this.rootItem);
24965
25403
  _this.rootItem.onEnd = function() {
24966
25404
  window.setTimeout(function() {
24967
25405
  _this.emit("end", {
@@ -24973,6 +25411,16 @@ var listOrder = 0;
24973
25411
  return _this;
24974
25412
  }
24975
25413
  var _proto = Composition.prototype;
25414
+ _proto.initializeSceneTicking = function initializeSceneTicking(item) {
25415
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25416
+ var component = _step.value;
25417
+ this.sceneTicking.addComponent(component);
25418
+ }
25419
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
25420
+ var child = _step1.value;
25421
+ this.initializeSceneTicking(child);
25422
+ }
25423
+ };
24976
25424
  /**
24977
25425
  * 获取合成的时长
24978
25426
  */ _proto.getDuration = function getDuration() {
@@ -25076,7 +25524,7 @@ var listOrder = 0;
25076
25524
  this.resume();
25077
25525
  }
25078
25526
  if (!this.rootComposition.isStartCalled) {
25079
- this.rootComposition.start();
25527
+ this.rootComposition.onStart();
25080
25528
  this.rootComposition.isStartCalled = true;
25081
25529
  }
25082
25530
  this.setSpeed(1);
@@ -25153,9 +25601,12 @@ var listOrder = 0;
25153
25601
  // 更新 model-tree-plugin
25154
25602
  this.updatePluginLoaders(deltaTime);
25155
25603
  // scene VFXItem components lifetime function.
25156
- this.callStart(this.rootItem);
25157
- this.callUpdate(this.rootItem, time);
25158
- this.callLateUpdate(this.rootItem, time);
25604
+ if (!this.rootItem.isDuringPlay) {
25605
+ this.callAwake(this.rootItem);
25606
+ this.rootItem.beginPlay();
25607
+ }
25608
+ this.sceneTicking.update.tick(time);
25609
+ this.sceneTicking.lateUpdate.tick(time);
25159
25610
  this.updateCamera();
25160
25611
  this.prepareRender();
25161
25612
  if (this.shouldDispose()) {
@@ -25208,11 +25659,11 @@ var listOrder = 0;
25208
25659
  return t;
25209
25660
  };
25210
25661
  _proto.callAwake = function callAwake(item) {
25211
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25212
- var itemBehaviour = _step.value;
25213
- if (!itemBehaviour.isAwakeCalled) {
25214
- itemBehaviour.awake();
25215
- itemBehaviour.isAwakeCalled = true;
25662
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25663
+ var component = _step.value;
25664
+ if (!component.isAwakeCalled) {
25665
+ component.onAwake();
25666
+ component.isAwakeCalled = true;
25216
25667
  }
25217
25668
  }
25218
25669
  for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
@@ -25220,72 +25671,6 @@ var listOrder = 0;
25220
25671
  this.callAwake(child);
25221
25672
  }
25222
25673
  };
25223
- _proto.callStart = function callStart(item) {
25224
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25225
- var itemBehaviour = _step.value;
25226
- if (itemBehaviour.isActiveAndEnabled && !itemBehaviour.isStartCalled) {
25227
- itemBehaviour.start();
25228
- itemBehaviour.isStartCalled = true;
25229
- }
25230
- }
25231
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25232
- var rendererComponent = _step1.value;
25233
- if (rendererComponent.isActiveAndEnabled && !rendererComponent.isStartCalled) {
25234
- rendererComponent.start();
25235
- rendererComponent.isStartCalled = true;
25236
- }
25237
- }
25238
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25239
- var child = _step2.value;
25240
- this.callStart(child);
25241
- }
25242
- };
25243
- _proto.callUpdate = function callUpdate(item, dt) {
25244
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25245
- var itemBehaviour = _step.value;
25246
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25247
- itemBehaviour.update(dt);
25248
- }
25249
- }
25250
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25251
- var rendererComponent = _step1.value;
25252
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25253
- rendererComponent.update(dt);
25254
- }
25255
- }
25256
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25257
- var child = _step2.value;
25258
- if (exports.VFXItem.isComposition(child)) {
25259
- if (child.ended && child.endBehavior === EndBehavior.restart) {
25260
- child.ended = false;
25261
- // TODO K帧动画在元素重建后需要 tick ,否则会导致元素位置和 k 帧第一帧位置不一致
25262
- this.callUpdate(child, 0);
25263
- } else {
25264
- this.callUpdate(child, dt);
25265
- }
25266
- } else {
25267
- this.callUpdate(child, dt);
25268
- }
25269
- }
25270
- };
25271
- _proto.callLateUpdate = function callLateUpdate(item, dt) {
25272
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25273
- var itemBehaviour = _step.value;
25274
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25275
- itemBehaviour.lateUpdate(dt);
25276
- }
25277
- }
25278
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25279
- var rendererComponent = _step1.value;
25280
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25281
- rendererComponent.lateUpdate(dt);
25282
- }
25283
- }
25284
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25285
- var child = _step2.value;
25286
- this.callLateUpdate(child, dt);
25287
- }
25288
- };
25289
25674
  /**
25290
25675
  * 构建父子树,同时保存到 itemCacheMap 中便于查找
25291
25676
  */ _proto.buildItemTree = function buildItemTree(compVFXItem) {
@@ -27707,7 +28092,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem, true);
27707
28092
  registerPlugin("particle", ParticleLoader, exports.VFXItem, true);
27708
28093
  registerPlugin("cal", CalculateLoader, exports.VFXItem, true);
27709
28094
  registerPlugin("interact", InteractLoader, exports.VFXItem, true);
27710
- var version$1 = "2.0.4";
28095
+ var version$1 = "2.1.0-alpha.1";
27711
28096
  logger.info("Core version: " + version$1 + ".");
27712
28097
 
27713
28098
  var _obj;
@@ -28640,8 +29025,8 @@ var seed = 1;
28640
29025
  this.material = mtl;
28641
29026
  this.mesh.material = mtl.material;
28642
29027
  };
28643
- _proto.start = function start() {
28644
- Mesh.prototype.start.call(this);
29028
+ _proto.onStart = function onStart() {
29029
+ Mesh.prototype.onStart.call(this);
28645
29030
  this.engine.threeGroup.add(this.mesh);
28646
29031
  };
28647
29032
  /**
@@ -29248,8 +29633,8 @@ exports.ThreeSpriteComponent = /*#__PURE__*/ function(SpriteComponent) {
29248
29633
  }
29249
29634
  }
29250
29635
  };
29251
- _proto.start = function start() {
29252
- SpriteComponent.prototype.start.call(this);
29636
+ _proto.onStart = function onStart() {
29637
+ SpriteComponent.prototype.onStart.call(this);
29253
29638
  this.engine.threeGroup.add(this.threeMesh);
29254
29639
  };
29255
29640
  _proto.render = function render(renderer) {
@@ -29320,8 +29705,8 @@ exports.ThreeTextComponent = /*#__PURE__*/ function(ThreeSpriteComponent) {
29320
29705
  return _this;
29321
29706
  }
29322
29707
  var _proto = ThreeTextComponent.prototype;
29323
- _proto.update = function update(dt) {
29324
- ThreeSpriteComponent.prototype.update.call(this, dt);
29708
+ _proto.onUpdate = function onUpdate(dt) {
29709
+ ThreeSpriteComponent.prototype.onUpdate.call(this, dt);
29325
29710
  this.updateTexture(false);
29326
29711
  };
29327
29712
  _proto.fromData = function fromData(data) {
@@ -29388,7 +29773,7 @@ setMaxSpriteMeshItemCount(8);
29388
29773
  */ Mesh.create = function(engine, props) {
29389
29774
  return new ThreeMesh(engine, props);
29390
29775
  };
29391
- var version = "2.0.4";
29776
+ var version = "2.1.0-alpha.1";
29392
29777
  logger.info("THREEJS plugin version: " + version + ".");
29393
29778
 
29394
29779
  exports.AbstractPlugin = AbstractPlugin;