@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.mjs 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
  import * as THREE from 'three';
@@ -4605,87 +4605,115 @@ function getDirectStore(target) {
4605
4605
  */ var Component = /*#__PURE__*/ function(EffectsObject) {
4606
4606
  _inherits(Component, EffectsObject);
4607
4607
  function Component() {
4608
- return EffectsObject.apply(this, arguments);
4609
- }
4610
- var _proto = Component.prototype;
4611
- _proto.onAttached = function onAttached() {};
4612
- _proto.onDestroy = function onDestroy() {};
4613
- _proto.fromData = function fromData(data) {
4614
- EffectsObject.prototype.fromData.call(this, data);
4615
- if (data.item) {
4616
- this.item = data.item;
4617
- }
4618
- };
4619
- _proto.dispose = function dispose() {
4620
- this.onDestroy();
4621
- if (this.item) {
4622
- removeItem(this.item.components, this);
4623
- }
4624
- };
4625
- _create_class(Component, [
4626
- {
4627
- key: "transform",
4628
- get: /**
4629
- * 附加到的 VFXItem 对象 Transform 组件
4630
- */ function get() {
4631
- return this.item.transform;
4632
- }
4633
- }
4634
- ]);
4635
- return Component;
4636
- }(EffectsObject);
4637
- /**
4638
- * @since 2.0.0
4639
- */ var Behaviour = /*#__PURE__*/ function(Component) {
4640
- _inherits(Behaviour, Component);
4641
- function Behaviour() {
4642
4608
  var _this;
4643
- _this = Component.apply(this, arguments) || this;
4609
+ _this = EffectsObject.apply(this, arguments) || this;
4644
4610
  _this.isAwakeCalled = false;
4645
4611
  _this.isStartCalled = false;
4612
+ _this.isEnableCalled = false;
4646
4613
  _this._enabled = true;
4647
4614
  return _this;
4648
4615
  }
4649
- var _proto = Behaviour.prototype;
4616
+ var _proto = Component.prototype;
4650
4617
  /**
4651
4618
  * 生命周期函数,初始化后调用,生命周期内只调用一次
4652
- */ _proto.awake = function awake() {
4619
+ */ _proto.onAwake = function onAwake() {
4653
4620
  // OVERRIDE
4654
4621
  };
4655
4622
  /**
4656
- * 在每次设置 enabled true 时触发
4623
+ * enabled 变为 true 时触发
4657
4624
  */ _proto.onEnable = function onEnable() {
4658
4625
  // OVERRIDE
4659
4626
  };
4660
4627
  /**
4628
+ * 在 enabled 变为 false 时触发
4629
+ */ _proto.onDisable = function onDisable() {
4630
+ // OVERRIDE
4631
+ };
4632
+ /**
4661
4633
  * 生命周期函数,在第一次 update 前调用,生命周期内只调用一次
4662
- */ _proto.start = function start() {
4634
+ */ _proto.onStart = function onStart() {
4663
4635
  // OVERRIDE
4664
4636
  };
4665
4637
  /**
4666
4638
  * 生命周期函数,每帧调用一次
4667
- */ _proto.update = function update(dt) {
4639
+ */ _proto.onUpdate = function onUpdate(dt) {
4668
4640
  // OVERRIDE
4669
4641
  };
4670
4642
  /**
4671
4643
  * 生命周期函数,每帧调用一次,在 update 之后调用
4672
- */ _proto.lateUpdate = function lateUpdate(dt) {
4644
+ */ _proto.onLateUpdate = function onLateUpdate(dt) {
4673
4645
  // OVERRIDE
4674
4646
  };
4675
- _proto.onAttached = function onAttached() {
4676
- this.item.itemBehaviours.push(this);
4677
- if (!this.isAwakeCalled) {
4678
- this.awake();
4679
- this.isAwakeCalled = true;
4647
+ /**
4648
+ * 生命周期函数,在组件销毁时调用
4649
+ */ _proto.onDestroy = function onDestroy() {
4650
+ // OVERRIDE
4651
+ };
4652
+ /**
4653
+ * @internal
4654
+ */ _proto.enable = function enable() {
4655
+ if (this.item.composition) {
4656
+ this.item.composition.sceneTicking.addComponent(this);
4657
+ this.isEnableCalled = true;
4658
+ }
4659
+ this.onEnable();
4660
+ };
4661
+ /**
4662
+ * @internal
4663
+ */ _proto.disable = function disable() {
4664
+ this.onDisable();
4665
+ if (this.item.composition) {
4666
+ this.isEnableCalled = false;
4667
+ this.item.composition.sceneTicking.removeComponent(this);
4668
+ }
4669
+ };
4670
+ _proto.setVFXItem = function setVFXItem(item) {
4671
+ this.item = item;
4672
+ if (item.isDuringPlay) {
4673
+ if (!this.isAwakeCalled) {
4674
+ this.onAwake();
4675
+ this.isAwakeCalled = true;
4676
+ }
4677
+ if (item.getVisible() && this.enabled) {
4678
+ this.start();
4679
+ this.enable();
4680
+ }
4681
+ }
4682
+ };
4683
+ _proto.fromData = function fromData(data) {
4684
+ EffectsObject.prototype.fromData.call(this, data);
4685
+ if (data.item) {
4686
+ this.item = data.item;
4680
4687
  }
4681
4688
  };
4682
4689
  _proto.dispose = function dispose() {
4690
+ if (this.isEnableCalled) {
4691
+ this.disable();
4692
+ }
4693
+ if (this.isAwakeCalled) {
4694
+ this.isAwakeCalled = false;
4695
+ this.onDestroy();
4696
+ }
4683
4697
  if (this.item) {
4684
- removeItem(this.item.itemBehaviours, this);
4698
+ removeItem(this.item.components, this);
4685
4699
  }
4686
- Component.prototype.dispose.call(this);
4687
4700
  };
4688
- _create_class(Behaviour, [
4701
+ _proto.start = function start() {
4702
+ if (this.isStartCalled) {
4703
+ return;
4704
+ }
4705
+ this.isStartCalled = true;
4706
+ this.onStart();
4707
+ };
4708
+ _create_class(Component, [
4709
+ {
4710
+ key: "transform",
4711
+ get: /**
4712
+ * 附加到的 VFXItem 对象 Transform 组件
4713
+ */ function get() {
4714
+ return this.item.transform;
4715
+ }
4716
+ },
4689
4717
  {
4690
4718
  key: "isActiveAndEnabled",
4691
4719
  get: /**
@@ -4700,24 +4728,46 @@ function getDirectStore(target) {
4700
4728
  return this._enabled;
4701
4729
  },
4702
4730
  set: function set(value) {
4703
- this._enabled = value;
4704
- if (value) {
4705
- if (this.isActiveAndEnabled) {
4706
- this.onEnable();
4707
- }
4708
- if (!this.isStartCalled) {
4709
- this.start();
4710
- this.isStartCalled = true;
4731
+ if (this.enabled !== value) {
4732
+ this._enabled = value;
4733
+ if (value) {
4734
+ if (this.isActiveAndEnabled) {
4735
+ this.enable();
4736
+ if (!this.isStartCalled) {
4737
+ this.onStart();
4738
+ this.isStartCalled = true;
4739
+ }
4740
+ }
4741
+ } else {
4742
+ if (this.isEnableCalled) {
4743
+ this.disable();
4744
+ }
4711
4745
  }
4712
4746
  }
4713
4747
  }
4714
4748
  }
4715
4749
  ]);
4716
- return Behaviour;
4717
- }(Component);
4750
+ return Component;
4751
+ }(EffectsObject);
4718
4752
  __decorate([
4719
4753
  serialize()
4720
- ], Behaviour.prototype, "_enabled", void 0);
4754
+ ], Component.prototype, "_enabled", void 0);
4755
+ /**
4756
+ * @since 2.0.0
4757
+ */ var Behaviour = /*#__PURE__*/ function(Component) {
4758
+ _inherits(Behaviour, Component);
4759
+ function Behaviour() {
4760
+ return Component.apply(this, arguments);
4761
+ }
4762
+ var _proto = Behaviour.prototype;
4763
+ _proto.setVFXItem = function setVFXItem(item) {
4764
+ Component.prototype.setVFXItem.call(this, item);
4765
+ };
4766
+ _proto.dispose = function dispose() {
4767
+ Component.prototype.dispose.call(this);
4768
+ };
4769
+ return Behaviour;
4770
+ }(Component);
4721
4771
 
4722
4772
  /**
4723
4773
  * 所有渲染组件的基类
@@ -4727,19 +4777,14 @@ __decorate([
4727
4777
  function RendererComponent() {
4728
4778
  var _this;
4729
4779
  _this = Component.apply(this, arguments) || this;
4730
- _this.isStartCalled = false;
4731
4780
  _this.materials = [];
4732
4781
  _this._priority = 0;
4733
- _this._enabled = true;
4734
4782
  return _this;
4735
4783
  }
4736
4784
  var _proto = RendererComponent.prototype;
4737
- _proto.onEnable = function onEnable() {};
4738
- _proto.start = function start() {};
4739
- _proto.update = function update(dt) {};
4740
- _proto.lateUpdate = function lateUpdate(dt) {};
4741
4785
  _proto.render = function render(renderer) {};
4742
- _proto.onAttached = function onAttached() {
4786
+ _proto.setVFXItem = function setVFXItem(item) {
4787
+ Component.prototype.setVFXItem.call(this, item);
4743
4788
  this.item.rendererComponents.push(this);
4744
4789
  };
4745
4790
  _proto.fromData = function fromData(data) {
@@ -4764,26 +4809,6 @@ __decorate([
4764
4809
  this._priority = value;
4765
4810
  }
4766
4811
  },
4767
- {
4768
- key: "enabled",
4769
- get: function get() {
4770
- return this._enabled;
4771
- },
4772
- set: function set(value) {
4773
- this._enabled = value;
4774
- if (value) {
4775
- this.onEnable();
4776
- }
4777
- }
4778
- },
4779
- {
4780
- key: "isActiveAndEnabled",
4781
- get: /**
4782
- * 组件是否可以更新,true 更新,false 不更新
4783
- */ function get() {
4784
- return this.item.getVisible() && this.enabled;
4785
- }
4786
- },
4787
4812
  {
4788
4813
  key: "material",
4789
4814
  get: function get() {
@@ -4806,9 +4831,6 @@ __decorate([
4806
4831
  __decorate([
4807
4832
  serialize()
4808
4833
  ], RendererComponent.prototype, "_priority", void 0);
4809
- __decorate([
4810
- serialize()
4811
- ], RendererComponent.prototype, "_enabled", void 0);
4812
4834
 
4813
4835
  /**
4814
4836
  * 抽象插件类
@@ -4852,7 +4874,7 @@ var CameraController = /*#__PURE__*/ function(Behaviour) {
4852
4874
  return _this;
4853
4875
  }
4854
4876
  var _proto = CameraController.prototype;
4855
- _proto.update = function update() {
4877
+ _proto.onUpdate = function onUpdate() {
4856
4878
  if (this.item.composition && this.item.transform.getValid()) {
4857
4879
  var camera = this.item.composition.camera;
4858
4880
  camera.near = this.options.near;
@@ -10012,8 +10034,13 @@ var RandomValue = /*#__PURE__*/ function(ValueGetter) {
10012
10034
  this.min = props[0];
10013
10035
  this.max = props[1];
10014
10036
  };
10015
- _proto.getValue = function getValue(time) {
10016
- return randomInRange(this.min, this.max);
10037
+ _proto.getValue = function getValue(time, seed) {
10038
+ var randomSeed = seed != null ? seed : Math.random();
10039
+ return this.min + randomSeed * (this.max - this.min);
10040
+ };
10041
+ _proto.getIntegrateValue = function getIntegrateValue(t0, t1, timeScale) {
10042
+ var seed = timeScale != null ? timeScale : 1.0;
10043
+ return (this.min + seed * (this.max - this.min)) * (t1 - t0);
10017
10044
  };
10018
10045
  _proto.toUniform = function toUniform() {
10019
10046
  return new Float32Array([
@@ -11540,7 +11567,7 @@ var itemFrag = "precision highp float;varying vec4 vColor;varying vec2 vTexCoord
11540
11567
 
11541
11568
  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";
11542
11569
 
11543
- 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}}";
11570
+ 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}}";
11544
11571
 
11545
11572
  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}";
11546
11573
 
@@ -13250,7 +13277,7 @@ var InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13250
13277
  return _this;
13251
13278
  }
13252
13279
  var _proto = InteractComponent.prototype;
13253
- _proto.start = function start() {
13280
+ _proto.onStart = function onStart() {
13254
13281
  var _this = this;
13255
13282
  var options = this.item.props.content.options;
13256
13283
  var env = this.item.engine.renderer.env;
@@ -13286,8 +13313,11 @@ var InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13286
13313
  }
13287
13314
  };
13288
13315
  };
13289
- _proto.update = function update(dt) {
13316
+ _proto.onUpdate = function onUpdate(dt) {
13290
13317
  var _this_previewContent;
13318
+ if (!this.isActiveAndEnabled) {
13319
+ return;
13320
+ }
13291
13321
  (_this_previewContent = this.previewContent) == null ? void 0 : _this_previewContent.updateMesh();
13292
13322
  if (!this.hasBeenAddedToComposition && this.item.composition) {
13293
13323
  var options = this.item.props.content.options;
@@ -13630,6 +13660,9 @@ function _assert_this_initialized(self) {
13630
13660
  this.outputs = [];
13631
13661
  this.playState = 0;
13632
13662
  this.traversalMode = 0;
13663
+ /**
13664
+ * 当前本地播放的时间
13665
+ */ this.time = 0;
13633
13666
  graph.addPlayable(this);
13634
13667
  this.inputs = new Array(inputCount);
13635
13668
  this.inputOuputPorts = new Array(inputCount);
@@ -14075,10 +14108,10 @@ var SpriteComponent = /*#__PURE__*/ function(RendererComponent) {
14075
14108
  this.material.setVector2("_Size", this.transform.size);
14076
14109
  renderer.drawGeometry(geo, material);
14077
14110
  };
14078
- _proto.start = function start() {
14111
+ _proto.onStart = function onStart() {
14079
14112
  this.item.getHitTestParams = this.getHitTestParams;
14080
14113
  };
14081
- _proto.update = function update(dt) {
14114
+ _proto.onUpdate = function onUpdate(dt) {
14082
14115
  if (!this.isManualTimeSet) {
14083
14116
  this.frameAnimationTime += dt / 1000;
14084
14117
  this.isManualTimeSet = false;
@@ -16501,17 +16534,18 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16501
16534
  return _this;
16502
16535
  }
16503
16536
  var _proto = ParticleSystemRenderer.prototype;
16504
- _proto.start = function start() {
16537
+ _proto.onStart = function onStart() {
16505
16538
  this._priority = this.item.renderOrder;
16506
16539
  this.particleMesh.gravityModifier.scaleXCoord(this.item.duration);
16507
16540
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
16508
16541
  var mesh = _step.value;
16509
- mesh.start();
16542
+ mesh.onStart();
16510
16543
  }
16511
16544
  };
16512
- _proto.update = function update(dt) {
16545
+ _proto.onUpdate = function onUpdate(dt) {
16513
16546
  var time = this.particleMesh.time;
16514
16547
  this.particleMesh.mesh.material.setVector4("uParams", new Vector4(time, this.item.duration, 0, 0));
16548
+ this.particleMesh.onUpdate(dt);
16515
16549
  };
16516
16550
  _proto.render = function render(renderer) {
16517
16551
  for(var _iterator = _create_for_of_iterator_helper_loose(this.meshes), _step; !(_step = _iterator()).done;){
@@ -16526,6 +16560,7 @@ function getTrailMeshShader(trails, particleMaxCount, name, gpuCapability, env)
16526
16560
  };
16527
16561
  _proto.updateTime = function updateTime(now, delta) {
16528
16562
  this.particleMesh.time = now;
16563
+ // this.particleMesh.onUpdate(delta);
16529
16564
  if (this.trailMesh) {
16530
16565
  this.trailMesh.time = now;
16531
16566
  this.trailMesh.onUpdate(delta);
@@ -16736,7 +16771,7 @@ var ParticleSystem = /*#__PURE__*/ function(Component) {
16736
16771
  _proto.getTextures = function getTextures() {
16737
16772
  return this.renderer.getTextures();
16738
16773
  };
16739
- _proto.start = function start() {
16774
+ _proto.startEmit = function startEmit() {
16740
16775
  if (!this.started || this.ended) {
16741
16776
  this.reset();
16742
16777
  this.started = true;
@@ -16762,7 +16797,7 @@ var ParticleSystem = /*#__PURE__*/ function(Component) {
16762
16797
  this.frozen = false;
16763
16798
  this.ended = false;
16764
16799
  };
16765
- _proto.onUpdate = function onUpdate(delta) {
16800
+ _proto.update = function update(delta) {
16766
16801
  var _this = this;
16767
16802
  if (this.started && !this.frozen) {
16768
16803
  var now = this.lastUpdate + delta / 1000;
@@ -17562,7 +17597,7 @@ function randomArrItem(arr, keepArr) {
17562
17597
  this.particleSystem = boundObject.getComponent(ParticleSystem);
17563
17598
  if (this.particleSystem) {
17564
17599
  this.particleSystem.name = boundObject.name;
17565
- this.particleSystem.start();
17600
+ this.particleSystem.startEmit();
17566
17601
  this.particleSystem.initEmitterTransform();
17567
17602
  }
17568
17603
  };
@@ -17579,7 +17614,7 @@ function randomArrItem(arr, keepArr) {
17579
17614
  if (Math.abs(this.time - this.lastTime) < 0.001) {
17580
17615
  deltaTime = 0;
17581
17616
  }
17582
- particleSystem.onUpdate(deltaTime);
17617
+ particleSystem.update(deltaTime);
17583
17618
  }
17584
17619
  this.lastTime = this.time;
17585
17620
  };
@@ -17632,6 +17667,7 @@ var particleUniformTypeMap = {
17632
17667
  var ParticleMesh = /*#__PURE__*/ function() {
17633
17668
  function ParticleMesh(engine, props) {
17634
17669
  this.particleCount = 0;
17670
+ this.VERT_MAX_KEY_FRAME_COUNT = 0;
17635
17671
  var _engine_renderer;
17636
17672
  var env = ((_engine_renderer = engine.renderer) != null ? _engine_renderer : {}).env;
17637
17673
  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;
@@ -17850,6 +17886,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17850
17886
  "FRAG_MAX_KEY_FRAME_COUNT",
17851
17887
  fragmentKeyFrameMeta.max
17852
17888
  ]);
17889
+ this.VERT_MAX_KEY_FRAME_COUNT = vertexKeyFrameMeta.max;
17853
17890
  var fragment = particleFrag;
17854
17891
  var originalVertex = "#define LOOKUP_TEXTURE_CURVE " + vertex_lookup_texture + "\n" + particleVert;
17855
17892
  var vertex = originalVertex;
@@ -17958,6 +17995,7 @@ var ParticleMesh = /*#__PURE__*/ function() {
17958
17995
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17959
17996
  this.orbitalVelOverLifetime = orbitalVelOverLifetime;
17960
17997
  this.gravityModifier = gravityModifier;
17998
+ this.rotationOverLifetime = rotationOverLifetime;
17961
17999
  this.maxCount = maxCount;
17962
18000
  // this.duration = duration;
17963
18001
  this.textureOffsets = textureFlip ? [
@@ -18022,15 +18060,232 @@ var ParticleMesh = /*#__PURE__*/ function() {
18022
18060
  // @ts-expect-error
18023
18061
  geometry.setIndexData(new index.constructor(0));
18024
18062
  };
18063
+ _proto.onUpdate = function onUpdate(dt) {
18064
+ var aPosArray = this.geometry.getAttributeData("aPos"); // vector3
18065
+ var aVelArray = this.geometry.getAttributeData("aVel"); // vector3
18066
+ var aOffsetArray = this.geometry.getAttributeData("aOffset");
18067
+ var aRotArray = this.geometry.getAttributeData("aRot"); // vector3
18068
+ var aSeedArray = this.geometry.getAttributeData("aSeed"); // float
18069
+ // const uParams = this.mesh.material.getVector4('uParams');
18070
+ // if (!uParams) {
18071
+ // return;
18072
+ // }
18073
+ var localTime = new Float32Array([
18074
+ this.time
18075
+ ])[0];
18076
+ var particleCount = Math.ceil(aPosArray.length / 12);
18077
+ // calculate particle translation
18078
+ var aTranslationArray = this.geometry.getAttributeData("aTranslation");
18079
+ if (aTranslationArray.length < particleCount * 3) {
18080
+ aTranslationArray = new Float32Array(particleCount * 3);
18081
+ }
18082
+ var velocity = new Vector3(0, 0, 0);
18083
+ for(var i = 0; i < particleCount; i++){
18084
+ var velOffset = i * 12 + 3;
18085
+ velocity.set(aVelArray[velOffset], aVelArray[velOffset + 1], aVelArray[velOffset + 2]);
18086
+ var trans = this.calculateTranslation(velocity, aOffsetArray[i * 4 + 2], localTime, aOffsetArray[i * 4 + 3]);
18087
+ var aTranslationOffset = i * 3;
18088
+ aTranslationArray[aTranslationOffset] = trans.x;
18089
+ aTranslationArray[aTranslationOffset + 1] = trans.y;
18090
+ aTranslationArray[aTranslationOffset + 2] = trans.z;
18091
+ }
18092
+ this.geometry.setAttributeData("aTranslation", aTranslationArray);
18093
+ // calculate particle rotation
18094
+ var aRotationArray = this.geometry.getAttributeData("aRotation0");
18095
+ if (aRotationArray.length < particleCount * 9) {
18096
+ aRotationArray = new Float32Array(particleCount * 9);
18097
+ }
18098
+ for(var i1 = 0; i1 < particleCount; i1++){
18099
+ var time = localTime - aOffsetArray[i1 * 4 + 2];
18100
+ var duration = aOffsetArray[i1 * 4 + 3];
18101
+ var life = clamp$1(time / duration, 0.0, 1.0);
18102
+ var aRotOffset = i1 * 8;
18103
+ var aRot = new Vector3(aRotArray[aRotOffset], aRotArray[aRotOffset + 1], aRotArray[aRotOffset + 2]);
18104
+ var aSeed = aSeedArray[i1 * 8 + 3];
18105
+ var aRotation = this.transformFromRotation(aRot, life, duration, aSeed);
18106
+ var aRotationOffset = i1 * 9;
18107
+ var matrixArray = aRotation.toArray();
18108
+ aRotationArray.set(matrixArray, aRotationOffset);
18109
+ }
18110
+ this.geometry.setAttributeData("aRotation0", aRotationArray);
18111
+ // calculate linear movement
18112
+ var aLinearMoveArray = this.geometry.getAttributeData("aLinearMove");
18113
+ if (aLinearMoveArray.length < particleCount * 3) {
18114
+ aLinearMoveArray = new Float32Array(particleCount * 3);
18115
+ }
18116
+ for(var i2 = 0; i2 < particleCount; i2++){
18117
+ var time1 = localTime - aOffsetArray[i2 * 4 + 2];
18118
+ var duration1 = aOffsetArray[i2 * 4 + 3];
18119
+ // const life = math.clamp(time / duration, 0.0, 1.0);
18120
+ var aSeed1 = aSeedArray[i2 * 8 + 3];
18121
+ var linearMove = this.calLinearMov(time1, duration1, aSeed1);
18122
+ var aLinearMoveOffset = i2 * 3;
18123
+ aLinearMoveArray[aLinearMoveOffset] = linearMove.x;
18124
+ aLinearMoveArray[aLinearMoveOffset + 1] = linearMove.y;
18125
+ aLinearMoveArray[aLinearMoveOffset + 2] = linearMove.z;
18126
+ }
18127
+ this.geometry.setAttributeData("aLinearMove", aLinearMoveArray);
18128
+ };
18025
18129
  _proto.minusTime = function minusTime(time) {
18026
- var data = this.geometry.getAttributeData("aOffset");
18027
- assertExist(data);
18028
- for(var i = 0; i < data.length; i += 4){
18029
- data[i + 2] -= time;
18130
+ var aOffset = this.geometry.getAttributeData("aOffset");
18131
+ for(var i = 0; i < aOffset.length; i += 4){
18132
+ aOffset[i + 2] -= time;
18030
18133
  }
18031
- this.geometry.setAttributeData("aOffset", data);
18134
+ this.geometry.setAttributeData("aOffset", aOffset);
18032
18135
  this.time -= time;
18033
18136
  };
18137
+ _proto.calculateTranslation = function calculateTranslation(velocity, t0, t1, duration) {
18138
+ var uAcceleration = this.mesh.material.getVector4("uAcceleration");
18139
+ var uGravityModifierValue = this.mesh.material.getVector4("uGravityModifierValue");
18140
+ if (!uAcceleration || !uGravityModifierValue) {
18141
+ return new Vector3();
18142
+ }
18143
+ var dt = t1 - t0; // 相对delay的时间
18144
+ var d = this.gravityModifier.getIntegrateByTime(0, dt);
18145
+ var acc = [
18146
+ uAcceleration.x * d,
18147
+ uAcceleration.y * d,
18148
+ uAcceleration.z * d
18149
+ ];
18150
+ // ret.addScaledVector(velData, speedIntegrate);
18151
+ // ret.addScaledVector(acc, d);
18152
+ // speedIntegrate = speedOverLifetime.getIntegrateValue(0, time, duration);
18153
+ if (this.speedOverLifetime) {
18154
+ // dt / dur 归一化
18155
+ var speed = this.speedOverLifetime.getIntegrateValue(0, dt, duration);
18156
+ return velocity.clone().multiply(speed).add(acc);
18157
+ }
18158
+ return velocity.clone().multiply(dt).add(acc);
18159
+ };
18160
+ _proto.transformFromRotation = function transformFromRotation(rot, life, dur, aSeed) {
18161
+ var rotation = rot.clone();
18162
+ if (!this.rotationOverLifetime) {
18163
+ return new Matrix3();
18164
+ }
18165
+ if (this.rotationOverLifetime.asRotation) {
18166
+ // Adjust rotation based on the specified lifetime components
18167
+ if (this.rotationOverLifetime.x) {
18168
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18169
+ rotation.x += this.rotationOverLifetime.x.getValue(life, aSeed);
18170
+ } else {
18171
+ rotation.x += this.rotationOverLifetime.x.getValue(life);
18172
+ }
18173
+ }
18174
+ if (this.rotationOverLifetime.y) {
18175
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18176
+ rotation.y += this.rotationOverLifetime.y.getValue(life, aSeed);
18177
+ } else {
18178
+ rotation.y += this.rotationOverLifetime.y.getValue(life);
18179
+ }
18180
+ }
18181
+ if (this.rotationOverLifetime.z) {
18182
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18183
+ rotation.z += this.rotationOverLifetime.z.getValue(life, aSeed);
18184
+ } else {
18185
+ rotation.z += this.rotationOverLifetime.z.getValue(life);
18186
+ }
18187
+ }
18188
+ } else {
18189
+ // Adjust rotation based on the specified lifetime components
18190
+ if (this.rotationOverLifetime.x) {
18191
+ if (_instanceof1(this.rotationOverLifetime.x, RandomValue)) {
18192
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, aSeed) * dur;
18193
+ } else {
18194
+ rotation.x += this.rotationOverLifetime.x.getIntegrateValue(0.0, life, dur) * dur;
18195
+ }
18196
+ }
18197
+ if (this.rotationOverLifetime.y) {
18198
+ if (_instanceof1(this.rotationOverLifetime.y, RandomValue)) {
18199
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, aSeed) * dur;
18200
+ } else {
18201
+ rotation.y += this.rotationOverLifetime.y.getIntegrateValue(0.0, life, dur) * dur;
18202
+ }
18203
+ }
18204
+ if (this.rotationOverLifetime.z) {
18205
+ if (_instanceof1(this.rotationOverLifetime.z, RandomValue)) {
18206
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, aSeed) * dur;
18207
+ } else {
18208
+ rotation.z += this.rotationOverLifetime.z.getIntegrateValue(0.0, life, dur) * dur;
18209
+ }
18210
+ }
18211
+ }
18212
+ // If the rotation vector is zero, return the identity matrix
18213
+ if (rotation.dot(rotation) === 0.0) {
18214
+ return new Matrix3().identity();
18215
+ }
18216
+ // Return the rotation matrix derived from the rotation vector
18217
+ return this.mat3FromRotation(rotation);
18218
+ };
18219
+ _proto.mat3FromRotation = function mat3FromRotation(rotation) {
18220
+ var d2r = Math.PI / 180;
18221
+ var sinR = rotation.clone().multiply(d2r);
18222
+ sinR.x = Math.sin(sinR.x);
18223
+ sinR.y = Math.sin(sinR.y);
18224
+ sinR.z = Math.sin(sinR.z);
18225
+ var cosR = rotation.clone().multiply(d2r);
18226
+ cosR.x = Math.cos(cosR.x);
18227
+ cosR.y = Math.cos(cosR.y);
18228
+ cosR.z = Math.cos(cosR.z);
18229
+ var rotZ = new Matrix3(cosR.z, -sinR.z, 0., sinR.z, cosR.z, 0., 0., 0., 1.);
18230
+ var rotY = new Matrix3(cosR.y, 0., sinR.y, 0., 1., 0., -sinR.y, 0, cosR.y);
18231
+ var rotX = new Matrix3(1., 0., 0., 0, cosR.x, -sinR.x, 0., sinR.x, cosR.x);
18232
+ var result = rotZ.multiply(rotY).multiply(rotX);
18233
+ return result;
18234
+ };
18235
+ _proto.calLinearMov = function calLinearMov(time, duration, aSeed) {
18236
+ var mov = new Vector3();
18237
+ var lifetime = time / duration;
18238
+ if (!this.linearVelOverLifetime || !this.linearVelOverLifetime.enabled) {
18239
+ return new Vector3();
18240
+ }
18241
+ if (this.linearVelOverLifetime.asMovement) {
18242
+ if (this.linearVelOverLifetime.x) {
18243
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18244
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime, aSeed);
18245
+ } else {
18246
+ mov.x = this.linearVelOverLifetime.x.getValue(lifetime);
18247
+ }
18248
+ }
18249
+ if (this.linearVelOverLifetime.y) {
18250
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18251
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime, aSeed);
18252
+ } else {
18253
+ mov.y = this.linearVelOverLifetime.y.getValue(lifetime);
18254
+ }
18255
+ }
18256
+ if (this.linearVelOverLifetime.z) {
18257
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18258
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime, aSeed);
18259
+ } else {
18260
+ mov.z = this.linearVelOverLifetime.z.getValue(lifetime);
18261
+ }
18262
+ }
18263
+ } else {
18264
+ // Adjust rotation based on the specified lifetime components
18265
+ if (this.linearVelOverLifetime.x) {
18266
+ if (_instanceof1(this.linearVelOverLifetime.x, RandomValue)) {
18267
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, aSeed);
18268
+ } else {
18269
+ mov.x = this.linearVelOverLifetime.x.getIntegrateValue(0.0, time, duration);
18270
+ }
18271
+ }
18272
+ if (this.linearVelOverLifetime.y) {
18273
+ if (_instanceof1(this.linearVelOverLifetime.y, RandomValue)) {
18274
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, aSeed);
18275
+ } else {
18276
+ mov.y = this.linearVelOverLifetime.y.getIntegrateValue(0.0, time, duration);
18277
+ }
18278
+ }
18279
+ if (this.linearVelOverLifetime.z) {
18280
+ if (_instanceof1(this.linearVelOverLifetime.z, RandomValue)) {
18281
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, aSeed);
18282
+ } else {
18283
+ mov.z = this.linearVelOverLifetime.z.getIntegrateValue(0.0, time, duration);
18284
+ }
18285
+ }
18286
+ }
18287
+ return mov;
18288
+ };
18034
18289
  _proto.removePoint = function removePoint(index) {
18035
18290
  if (index < this.particleCount) {
18036
18291
  this.geometry.setAttributeSubData("aOffset", index * 16, new Float32Array(16));
@@ -18232,6 +18487,32 @@ function generateGeometryProps(maxVertex, useSprite, name) {
18232
18487
  size: 4,
18233
18488
  stride: 4 * bpe,
18234
18489
  data: new Float32Array(0)
18490
+ },
18491
+ aTranslation: {
18492
+ size: 3,
18493
+ data: new Float32Array(0)
18494
+ },
18495
+ aLinearMove: {
18496
+ size: 3,
18497
+ data: new Float32Array(0)
18498
+ },
18499
+ aRotation0: {
18500
+ size: 3,
18501
+ offset: 0,
18502
+ stride: 9 * bpe,
18503
+ data: new Float32Array(0)
18504
+ },
18505
+ aRotation1: {
18506
+ size: 3,
18507
+ offset: 3 * bpe,
18508
+ stride: 9 * bpe,
18509
+ dataSource: "aRotation0"
18510
+ },
18511
+ aRotation2: {
18512
+ size: 3,
18513
+ offset: 6 * bpe,
18514
+ stride: 9 * bpe,
18515
+ dataSource: "aRotation0"
18235
18516
  }
18236
18517
  };
18237
18518
  if (useSprite) {
@@ -19309,25 +19590,15 @@ var TrackSortWrapper = function TrackSortWrapper(track, originalIndex) {
19309
19590
  this.track = track;
19310
19591
  this.originalIndex = originalIndex;
19311
19592
  };
19312
- function isAncestor(ancestorCandidate, descendantCandidate) {
19313
- var current = descendantCandidate.parent;
19314
- while(current){
19315
- if (current === ancestorCandidate) {
19316
- return true;
19317
- }
19318
- current = current.parent;
19319
- }
19320
- return false;
19321
- }
19322
19593
  function compareTracks(a, b) {
19323
19594
  var bindingA = a.track.binding;
19324
19595
  var bindingB = b.track.binding;
19325
19596
  if (!_instanceof1(bindingA, VFXItem) || !_instanceof1(bindingB, VFXItem)) {
19326
19597
  return a.originalIndex - b.originalIndex;
19327
19598
  }
19328
- if (isAncestor(bindingA, bindingB)) {
19599
+ if (VFXItem.isAncestor(bindingA, bindingB)) {
19329
19600
  return -1;
19330
- } else if (isAncestor(bindingB, bindingA)) {
19601
+ } else if (VFXItem.isAncestor(bindingB, bindingA)) {
19331
19602
  return 1;
19332
19603
  } else {
19333
19604
  return a.originalIndex - b.originalIndex; // 非父子关系的元素保持原始顺序
@@ -19351,7 +19622,7 @@ function compareTracks(a, b) {
19351
19622
  return _this;
19352
19623
  }
19353
19624
  var _proto = CompositionComponent.prototype;
19354
- _proto.start = function start() {
19625
+ _proto.onStart = function onStart() {
19355
19626
  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;
19356
19627
  this.startTime = startTime;
19357
19628
  this.resolveBindings();
@@ -19379,7 +19650,7 @@ function compareTracks(a, b) {
19379
19650
  _proto.getReusable = function getReusable() {
19380
19651
  return this.reusable;
19381
19652
  };
19382
- _proto.update = function update(dt) {
19653
+ _proto.onUpdate = function onUpdate(dt) {
19383
19654
  var time = this.time;
19384
19655
  this.timelinePlayable.setTime(time);
19385
19656
  this.graph.evaluate(dt);
@@ -19415,7 +19686,9 @@ function compareTracks(a, b) {
19415
19686
  props.content = itemData.content;
19416
19687
  item = assetLoader.loadGUID(itemData.id);
19417
19688
  item.composition = this.item.composition;
19418
- var compositionComponent = item.addComponent(CompositionComponent);
19689
+ var compositionComponent = new CompositionComponent(this.engine);
19690
+ compositionComponent.item = item;
19691
+ item.components.push(compositionComponent);
19419
19692
  compositionComponent.data = props;
19420
19693
  compositionComponent.refId = refId;
19421
19694
  item.transform.parentTransform = this.transform;
@@ -19869,8 +20142,8 @@ var TextComponent = /*#__PURE__*/ function(SpriteComponent) {
19869
20142
  return _this;
19870
20143
  }
19871
20144
  var _proto = TextComponent.prototype;
19872
- _proto.update = function update(dt) {
19873
- SpriteComponent.prototype.update.call(this, dt);
20145
+ _proto.onUpdate = function onUpdate(dt) {
20146
+ SpriteComponent.prototype.onUpdate.call(this, dt);
19874
20147
  this.updateTexture();
19875
20148
  };
19876
20149
  _proto.fromData = function fromData(data) {
@@ -20285,7 +20558,7 @@ var EffectComponent = /*#__PURE__*/ function(RendererComponent) {
20285
20558
  return _this;
20286
20559
  }
20287
20560
  var _proto = EffectComponent.prototype;
20288
- _proto.start = function start() {
20561
+ _proto.onStart = function onStart() {
20289
20562
  this.item.getHitTestParams = this.getHitTestParams;
20290
20563
  };
20291
20564
  _proto.render = function render(renderer) {
@@ -20412,7 +20685,7 @@ var PostProcessVolume = /*#__PURE__*/ function(Behaviour) {
20412
20685
  return _this;
20413
20686
  }
20414
20687
  var _proto = PostProcessVolume.prototype;
20415
- _proto.start = function start() {
20688
+ _proto.onStart = function onStart() {
20416
20689
  var composition = this.item.composition;
20417
20690
  if (composition) {
20418
20691
  composition.globalVolume = this;
@@ -20554,8 +20827,8 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20554
20827
  */ _this.ended = false;
20555
20828
  _this.reusable = false;
20556
20829
  _this.type = ItemType.base;
20830
+ _this.isDuringPlay = false;
20557
20831
  _this.components = [];
20558
- _this.itemBehaviours = [];
20559
20832
  _this.rendererComponents = [];
20560
20833
  /**
20561
20834
  * 元素可见性,该值的改变会触发 `handleVisibleChanged` 回调
@@ -20565,6 +20838,7 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20565
20838
  * 元素动画的速度
20566
20839
  */ _this.speed = 1;
20567
20840
  _this.listIndex = 0;
20841
+ _this.isEnabled = false;
20568
20842
  _this.eventProcessor = new EventEmitter();
20569
20843
  _this.name = "VFXItem";
20570
20844
  _this.transform.name = _this.name;
@@ -20637,8 +20911,7 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20637
20911
  */ _proto.addComponent = function addComponent(classConstructor) {
20638
20912
  var newComponent = new classConstructor(this.engine);
20639
20913
  this.components.push(newComponent);
20640
- newComponent.item = this;
20641
- newComponent.onAttached();
20914
+ newComponent.setVFXItem(this);
20642
20915
  return newComponent;
20643
20916
  };
20644
20917
  /**
@@ -20671,21 +20944,22 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20671
20944
  return res;
20672
20945
  };
20673
20946
  _proto.setParent = function setParent(vfxItem) {
20674
- if (vfxItem === this) {
20947
+ if (vfxItem === this && !vfxItem) {
20675
20948
  return;
20676
20949
  }
20677
20950
  if (this.parent) {
20678
20951
  removeItem(this.parent.children, this);
20679
20952
  }
20680
20953
  this.parent = vfxItem;
20681
- if (vfxItem) {
20682
- if (!VFXItem.isCamera(this)) {
20683
- this.transform.parentTransform = vfxItem.transform;
20684
- }
20685
- vfxItem.children.push(this);
20686
- if (!this.composition) {
20687
- this.composition = vfxItem.composition;
20688
- }
20954
+ if (!VFXItem.isCamera(this)) {
20955
+ this.transform.parentTransform = vfxItem.transform;
20956
+ }
20957
+ vfxItem.children.push(this);
20958
+ if (!this.composition) {
20959
+ this.composition = vfxItem.composition;
20960
+ }
20961
+ if (!this.isDuringPlay && vfxItem.isDuringPlay) {
20962
+ this.beginPlay();
20689
20963
  }
20690
20964
  };
20691
20965
  /**
@@ -20716,6 +20990,7 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20716
20990
  */ _proto.setVisible = function setVisible(visible) {
20717
20991
  if (this.visible !== visible) {
20718
20992
  this.visible = !!visible;
20993
+ this.onActiveChanged();
20719
20994
  }
20720
20995
  };
20721
20996
  /**
@@ -20840,6 +21115,57 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20840
21115
  }
20841
21116
  return undefined;
20842
21117
  };
21118
+ /**
21119
+ * @internal
21120
+ */ _proto.beginPlay = function beginPlay() {
21121
+ this.isDuringPlay = true;
21122
+ if (this.composition && this.visible && !this.isEnabled) {
21123
+ this.onEnable();
21124
+ }
21125
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.children), _step; !(_step = _iterator()).done;){
21126
+ var child = _step.value;
21127
+ if (!child.isDuringPlay) {
21128
+ child.beginPlay();
21129
+ }
21130
+ }
21131
+ };
21132
+ /**
21133
+ * @internal
21134
+ */ _proto.onActiveChanged = function onActiveChanged() {
21135
+ if (!this.isEnabled) {
21136
+ this.onEnable();
21137
+ } else {
21138
+ this.onDisable();
21139
+ }
21140
+ };
21141
+ /**
21142
+ * @internal
21143
+ */ _proto.onEnable = function onEnable() {
21144
+ this.isEnabled = true;
21145
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21146
+ var component = _step.value;
21147
+ if (component.enabled && !component.isStartCalled) {
21148
+ component.onStart();
21149
+ }
21150
+ }
21151
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.components), _step1; !(_step1 = _iterator1()).done;){
21152
+ var component1 = _step1.value;
21153
+ if (component1.enabled && !component1.isEnableCalled) {
21154
+ component1.enable();
21155
+ }
21156
+ }
21157
+ };
21158
+ /**
21159
+ * @internal
21160
+ */ _proto.onDisable = function onDisable() {
21161
+ this.isEnabled = false;
21162
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
21163
+ var component = _step.value;
21164
+ if (component.enabled && component.isEnableCalled) {
21165
+ component.disable();
21166
+ }
21167
+ }
21168
+ };
20843
21169
  _proto.fromData = function fromData(data) {
20844
21170
  EffectsObject.prototype.fromData.call(this, data);
20845
21171
  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;
@@ -20889,14 +21215,10 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
20889
21215
  if (duration <= 0) {
20890
21216
  throw new Error("Item duration can't be less than 0, see " + HELP_LINK["Item duration can't be less than 0"] + ".");
20891
21217
  }
20892
- this.itemBehaviours.length = 0;
20893
21218
  this.rendererComponents.length = 0;
20894
21219
  for(var _iterator = _create_for_of_iterator_helper_loose(this.components), _step; !(_step = _iterator()).done;){
20895
21220
  var component = _step.value;
20896
21221
  component.item = this;
20897
- if (_instanceof1(component, Behaviour)) {
20898
- this.itemBehaviours.push(component);
20899
- }
20900
21222
  if (_instanceof1(component, RendererComponent)) {
20901
21223
  this.rendererComponents.push(component);
20902
21224
  }
@@ -21001,6 +21323,16 @@ var VFXItem = /*#__PURE__*/ function(EffectsObject) {
21001
21323
  VFXItem.isExtraCamera = function isExtraCamera(item) {
21002
21324
  return item.id === "extra-camera" && item.name === "extra-camera";
21003
21325
  };
21326
+ VFXItem.isAncestor = function isAncestor(ancestorCandidate, descendantCandidate) {
21327
+ var current = descendantCandidate.parent;
21328
+ while(current){
21329
+ if (current === ancestorCandidate) {
21330
+ return true;
21331
+ }
21332
+ current = current.parent;
21333
+ }
21334
+ return false;
21335
+ };
21004
21336
  _create_class(VFXItem, [
21005
21337
  {
21006
21338
  key: "content",
@@ -24855,6 +25187,109 @@ var listOrder = 0;
24855
25187
  return CompositionSourceManager;
24856
25188
  }();
24857
25189
 
25190
+ var SceneTicking = /*#__PURE__*/ function() {
25191
+ function SceneTicking() {
25192
+ this.update = new UpdateTickData();
25193
+ this.lateUpdate = new LateUpdateTickData();
25194
+ }
25195
+ var _proto = SceneTicking.prototype;
25196
+ _proto.addComponent = function addComponent(obj) {
25197
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25198
+ this.update.addComponent(obj);
25199
+ }
25200
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25201
+ this.lateUpdate.addComponent(obj);
25202
+ }
25203
+ };
25204
+ _proto.removeComponent = function removeComponent(obj) {
25205
+ if (obj.onUpdate !== Component.prototype.onUpdate) {
25206
+ this.update.removeComponent(obj);
25207
+ }
25208
+ if (obj.onLateUpdate !== Component.prototype.onLateUpdate) {
25209
+ this.lateUpdate.removeComponent(obj);
25210
+ }
25211
+ };
25212
+ _proto.clear = function clear() {
25213
+ this.update.clear();
25214
+ this.lateUpdate.clear();
25215
+ };
25216
+ return SceneTicking;
25217
+ }();
25218
+ var TickData = /*#__PURE__*/ function() {
25219
+ function TickData() {
25220
+ this.components = [];
25221
+ this.ticks = [];
25222
+ }
25223
+ var _proto = TickData.prototype;
25224
+ _proto.tick = function tick(dt) {
25225
+ this.tickComponents(this.components, dt);
25226
+ for(var i = 0; i < this.ticks.length; i++){
25227
+ this.ticks[i](dt);
25228
+ }
25229
+ };
25230
+ _proto.tickComponents = function tickComponents(components, dt) {
25231
+ // To be implemented in derived classes
25232
+ };
25233
+ _proto.addComponent = function addComponent(component) {
25234
+ if (!this.components.includes(component)) {
25235
+ this.components.push(component);
25236
+ }
25237
+ };
25238
+ _proto.removeComponent = function removeComponent(component) {
25239
+ var index = this.components.indexOf(component);
25240
+ if (index > -1) {
25241
+ this.components.splice(index, 1);
25242
+ }
25243
+ };
25244
+ _proto.addTick = function addTick(method, callee) {
25245
+ var tick = method.bind(callee);
25246
+ if (!this.ticks.includes(tick)) {
25247
+ this.ticks.push(tick);
25248
+ }
25249
+ };
25250
+ _proto.clear = function clear() {
25251
+ this.components = [];
25252
+ };
25253
+ return TickData;
25254
+ }();
25255
+ var UpdateTickData = /*#__PURE__*/ function(TickData) {
25256
+ _inherits(UpdateTickData, TickData);
25257
+ function UpdateTickData() {
25258
+ return TickData.apply(this, arguments);
25259
+ }
25260
+ var _proto = UpdateTickData.prototype;
25261
+ _proto.tickComponents = function tickComponents(components, dt) {
25262
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25263
+ var component = _step.value;
25264
+ component.onUpdate(dt);
25265
+ }
25266
+ };
25267
+ return UpdateTickData;
25268
+ }(TickData);
25269
+ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
25270
+ _inherits(LateUpdateTickData, TickData);
25271
+ function LateUpdateTickData() {
25272
+ return TickData.apply(this, arguments);
25273
+ }
25274
+ var _proto = LateUpdateTickData.prototype;
25275
+ _proto.tickComponents = function tickComponents(components, dt) {
25276
+ for(var _iterator = _create_for_of_iterator_helper_loose(components), _step; !(_step = _iterator()).done;){
25277
+ var component = _step.value;
25278
+ component.onLateUpdate(dt);
25279
+ }
25280
+ };
25281
+ return LateUpdateTickData;
25282
+ } // function compareComponents (a: Component, b: Component): number {
25283
+ // const itemA = a.item;
25284
+ // const itemB = b.item;
25285
+ // if (VFXItem.isAncestor(itemA, itemB)) {
25286
+ // return -1;
25287
+ // } else {
25288
+ // return 1;
25289
+ // }
25290
+ // }
25291
+ (TickData);
25292
+
24858
25293
  /**
24859
25294
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24860
25295
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
@@ -24864,6 +25299,7 @@ var listOrder = 0;
24864
25299
  function Composition(props, scene) {
24865
25300
  var _this;
24866
25301
  _this = EventEmitter.call(this) || this;
25302
+ _this.sceneTicking = new SceneTicking();
24867
25303
  /**
24868
25304
  * 动画播放速度
24869
25305
  */ _this.speed = 1;
@@ -24901,9 +25337,12 @@ var listOrder = 0;
24901
25337
  _this.rootItem = new VFXItem(_this.getEngine(), sourceContent);
24902
25338
  _this.rootItem.name = "rootItem";
24903
25339
  _this.rootItem.composition = _assert_this_initialized(_this);
24904
- _this.rootComposition = _this.rootItem.addComponent(CompositionComponent);
25340
+ // Spawn rootCompositionComponent
25341
+ _this.rootComposition = new CompositionComponent(_this.getEngine());
24905
25342
  _this.rootComposition.startTime = sourceContent.startTime;
24906
25343
  _this.rootComposition.data = sourceContent;
25344
+ _this.rootComposition.item = _this.rootItem;
25345
+ _this.rootItem.components.push(_this.rootComposition);
24907
25346
  var imageUsage = !reusable && imgUsage;
24908
25347
  _this.width = width;
24909
25348
  _this.height = height;
@@ -24937,7 +25376,6 @@ var listOrder = 0;
24937
25376
  _this.rendererOptions = null;
24938
25377
  _this.rootComposition.createContent();
24939
25378
  _this.buildItemTree(_this.rootItem);
24940
- _this.callAwake(_this.rootItem);
24941
25379
  _this.rootItem.onEnd = function() {
24942
25380
  window.setTimeout(function() {
24943
25381
  _this.emit("end", {
@@ -24949,6 +25387,16 @@ var listOrder = 0;
24949
25387
  return _this;
24950
25388
  }
24951
25389
  var _proto = Composition.prototype;
25390
+ _proto.initializeSceneTicking = function initializeSceneTicking(item) {
25391
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25392
+ var component = _step.value;
25393
+ this.sceneTicking.addComponent(component);
25394
+ }
25395
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
25396
+ var child = _step1.value;
25397
+ this.initializeSceneTicking(child);
25398
+ }
25399
+ };
24952
25400
  /**
24953
25401
  * 获取合成的时长
24954
25402
  */ _proto.getDuration = function getDuration() {
@@ -25052,7 +25500,7 @@ var listOrder = 0;
25052
25500
  this.resume();
25053
25501
  }
25054
25502
  if (!this.rootComposition.isStartCalled) {
25055
- this.rootComposition.start();
25503
+ this.rootComposition.onStart();
25056
25504
  this.rootComposition.isStartCalled = true;
25057
25505
  }
25058
25506
  this.setSpeed(1);
@@ -25129,9 +25577,12 @@ var listOrder = 0;
25129
25577
  // 更新 model-tree-plugin
25130
25578
  this.updatePluginLoaders(deltaTime);
25131
25579
  // scene VFXItem components lifetime function.
25132
- this.callStart(this.rootItem);
25133
- this.callUpdate(this.rootItem, time);
25134
- this.callLateUpdate(this.rootItem, time);
25580
+ if (!this.rootItem.isDuringPlay) {
25581
+ this.callAwake(this.rootItem);
25582
+ this.rootItem.beginPlay();
25583
+ }
25584
+ this.sceneTicking.update.tick(time);
25585
+ this.sceneTicking.lateUpdate.tick(time);
25135
25586
  this.updateCamera();
25136
25587
  this.prepareRender();
25137
25588
  if (this.shouldDispose()) {
@@ -25184,11 +25635,11 @@ var listOrder = 0;
25184
25635
  return t;
25185
25636
  };
25186
25637
  _proto.callAwake = function callAwake(item) {
25187
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25188
- var itemBehaviour = _step.value;
25189
- if (!itemBehaviour.isAwakeCalled) {
25190
- itemBehaviour.awake();
25191
- itemBehaviour.isAwakeCalled = true;
25638
+ for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
25639
+ var component = _step.value;
25640
+ if (!component.isAwakeCalled) {
25641
+ component.onAwake();
25642
+ component.isAwakeCalled = true;
25192
25643
  }
25193
25644
  }
25194
25645
  for(var _iterator1 = _create_for_of_iterator_helper_loose(item.children), _step1; !(_step1 = _iterator1()).done;){
@@ -25196,72 +25647,6 @@ var listOrder = 0;
25196
25647
  this.callAwake(child);
25197
25648
  }
25198
25649
  };
25199
- _proto.callStart = function callStart(item) {
25200
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25201
- var itemBehaviour = _step.value;
25202
- if (itemBehaviour.isActiveAndEnabled && !itemBehaviour.isStartCalled) {
25203
- itemBehaviour.start();
25204
- itemBehaviour.isStartCalled = true;
25205
- }
25206
- }
25207
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25208
- var rendererComponent = _step1.value;
25209
- if (rendererComponent.isActiveAndEnabled && !rendererComponent.isStartCalled) {
25210
- rendererComponent.start();
25211
- rendererComponent.isStartCalled = true;
25212
- }
25213
- }
25214
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25215
- var child = _step2.value;
25216
- this.callStart(child);
25217
- }
25218
- };
25219
- _proto.callUpdate = function callUpdate(item, dt) {
25220
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25221
- var itemBehaviour = _step.value;
25222
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25223
- itemBehaviour.update(dt);
25224
- }
25225
- }
25226
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25227
- var rendererComponent = _step1.value;
25228
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25229
- rendererComponent.update(dt);
25230
- }
25231
- }
25232
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25233
- var child = _step2.value;
25234
- if (VFXItem.isComposition(child)) {
25235
- if (child.ended && child.endBehavior === EndBehavior.restart) {
25236
- child.ended = false;
25237
- // TODO K帧动画在元素重建后需要 tick ,否则会导致元素位置和 k 帧第一帧位置不一致
25238
- this.callUpdate(child, 0);
25239
- } else {
25240
- this.callUpdate(child, dt);
25241
- }
25242
- } else {
25243
- this.callUpdate(child, dt);
25244
- }
25245
- }
25246
- };
25247
- _proto.callLateUpdate = function callLateUpdate(item, dt) {
25248
- for(var _iterator = _create_for_of_iterator_helper_loose(item.itemBehaviours), _step; !(_step = _iterator()).done;){
25249
- var itemBehaviour = _step.value;
25250
- if (itemBehaviour.isActiveAndEnabled && itemBehaviour.isStartCalled) {
25251
- itemBehaviour.lateUpdate(dt);
25252
- }
25253
- }
25254
- for(var _iterator1 = _create_for_of_iterator_helper_loose(item.rendererComponents), _step1; !(_step1 = _iterator1()).done;){
25255
- var rendererComponent = _step1.value;
25256
- if (rendererComponent.isActiveAndEnabled && rendererComponent.isStartCalled) {
25257
- rendererComponent.lateUpdate(dt);
25258
- }
25259
- }
25260
- for(var _iterator2 = _create_for_of_iterator_helper_loose(item.children), _step2; !(_step2 = _iterator2()).done;){
25261
- var child = _step2.value;
25262
- this.callLateUpdate(child, dt);
25263
- }
25264
- };
25265
25650
  /**
25266
25651
  * 构建父子树,同时保存到 itemCacheMap 中便于查找
25267
25652
  */ _proto.buildItemTree = function buildItemTree(compVFXItem) {
@@ -27683,7 +28068,7 @@ registerPlugin("sprite", SpriteLoader, VFXItem, true);
27683
28068
  registerPlugin("particle", ParticleLoader, VFXItem, true);
27684
28069
  registerPlugin("cal", CalculateLoader, VFXItem, true);
27685
28070
  registerPlugin("interact", InteractLoader, VFXItem, true);
27686
- var version$1 = "2.0.4";
28071
+ var version$1 = "2.1.0-alpha.1";
27687
28072
  logger.info("Core version: " + version$1 + ".");
27688
28073
 
27689
28074
  var _obj;
@@ -28616,8 +29001,8 @@ var seed = 1;
28616
29001
  this.material = mtl;
28617
29002
  this.mesh.material = mtl.material;
28618
29003
  };
28619
- _proto.start = function start() {
28620
- Mesh.prototype.start.call(this);
29004
+ _proto.onStart = function onStart() {
29005
+ Mesh.prototype.onStart.call(this);
28621
29006
  this.engine.threeGroup.add(this.mesh);
28622
29007
  };
28623
29008
  /**
@@ -29224,8 +29609,8 @@ var ThreeSpriteComponent = /*#__PURE__*/ function(SpriteComponent) {
29224
29609
  }
29225
29610
  }
29226
29611
  };
29227
- _proto.start = function start() {
29228
- SpriteComponent.prototype.start.call(this);
29612
+ _proto.onStart = function onStart() {
29613
+ SpriteComponent.prototype.onStart.call(this);
29229
29614
  this.engine.threeGroup.add(this.threeMesh);
29230
29615
  };
29231
29616
  _proto.render = function render(renderer) {
@@ -29296,8 +29681,8 @@ var ThreeTextComponent = /*#__PURE__*/ function(ThreeSpriteComponent) {
29296
29681
  return _this;
29297
29682
  }
29298
29683
  var _proto = ThreeTextComponent.prototype;
29299
- _proto.update = function update(dt) {
29300
- ThreeSpriteComponent.prototype.update.call(this, dt);
29684
+ _proto.onUpdate = function onUpdate(dt) {
29685
+ ThreeSpriteComponent.prototype.onUpdate.call(this, dt);
29301
29686
  this.updateTexture(false);
29302
29687
  };
29303
29688
  _proto.fromData = function fromData(data) {
@@ -29364,7 +29749,7 @@ setMaxSpriteMeshItemCount(8);
29364
29749
  */ Mesh.create = function(engine, props) {
29365
29750
  return new ThreeMesh(engine, props);
29366
29751
  };
29367
- var version = "2.0.4";
29752
+ var version = "2.1.0-alpha.1";
29368
29753
  logger.info("THREEJS plugin version: " + version + ".");
29369
29754
 
29370
29755
  export { AbstractPlugin, ActivationPlayable, ActivationPlayableAsset, ActivationTrack, AnimationClip, AnimationClipPlayable, AssetLoader, AssetManager, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, BezierCurveQuat, BinaryAsset, COMPRESSED_TEXTURE, CONSTANT_MAP_BLEND, CONSTANT_MAP_DEPTH, CONSTANT_MAP_STENCIL_FUNC, CONSTANT_MAP_STENCIL_OP, COPY_FRAGMENT_SHADER, COPY_MESH_SHADER_ID, COPY_VERTEX_SHADER, CalculateLoader, Camera, CameraController, CameraVFXItemLoader, Component, Composition, CompositionComponent, CompositionSourceManager, DEFAULT_FONTS, DEFAULT_FPS, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, EffectsPackage, Engine, EventEmitter, EventSystem, FilterMode, Float16ArrayWrapper, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractComponent, InteractLoader, InteractMesh, Item, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, ObjectBindingTrack, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleBehaviourPlayableAsset, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, PassTextureCache, PathSegments, PluginSystem, PostProcessVolume, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderbuffer, Renderer, RendererComponent, RuntimeClip, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_0, SEMANTIC_MAIN_PRE_COLOR_ATTACHMENT_SIZE_0, SEMANTIC_PRE_COLOR_ATTACHMENT_0, SEMANTIC_PRE_COLOR_ATTACHMENT_SIZE_0, SPRITE_VERTEX_STRIDE, SemanticMap, SerializationHelper, Shader, ShaderCompileResultStatus, ShaderFactory, ShaderType, ShaderVariant, SpriteColorPlayable, SpriteColorPlayableAsset, SpriteColorTrack, SpriteComponent, SpriteLoader, StaticValue, SubCompositionPlayableAsset, SubCompositionTrack, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextComponent, TextComponentBase, TextLayout, TextLoader, TextStyle, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeEngine, ThreeMaterial, ThreeSpriteComponent, ThreeTextComponent, ThreeTexture, Ticker, TimelineAsset, TimelineClip, TimelinePlayable, TrackAsset, TrackSortWrapper, TrackType, Transform, TransformAnimationPlayable, TransformPlayableAsset, TransformTrack, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, applyMixins, assertExist, asserts, base64ToFile, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, createCopyShader, createGLContext, createKeyFrameMeta, createShape, createValueGetter, decimalEqual, defaultGlobalVolume, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateTransparentTexture, generateWhiteTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAlipayMiniApp, isAndroid, isArray, isCanvas, isFunction, isIOS, isIOSByUA, isMiniProgram, isObject, isSceneJSON, isSceneURL, isSceneWithOptions, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isValidFontFamily, isWebGL2, isWechatMiniApp, itemFrag, itemFrameFrag, itemVert, loadAVIFOptional, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, randomInRange, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecFill, vecMulCombine, version, vertexFormatType2GLType };