@galacean/effects-core 2.4.8 → 2.5.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.4.8
6
+ * Version: v2.5.0-alpha.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -345,11 +345,6 @@ function colorToArr$1(hex, normalized) {
345
345
  parseInt(m[2], 16),
346
346
  parseInt(m[3], 16),
347
347
  255
348
- ] || [
349
- 0,
350
- 0,
351
- 0,
352
- 255
353
348
  ];
354
349
  }
355
350
  } else if (_instanceof1(hex, Array)) {
@@ -10212,7 +10207,7 @@ var itemFrame_frag = "#version 100\nprecision highp float;vec4 blendColor(vec4 c
10212
10207
 
10213
10208
  var integrate = "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.;}";
10214
10209
 
10215
- var itemVert = "precision highp float;attribute vec2 atlasOffset;attribute vec3 aPos;varying vec2 vTexCoord;varying vec3 vParams;varying vec4 vColor;uniform vec2 _Size;uniform vec3 _Scale;uniform vec4 _Color;uniform vec4 _TexParams;uniform vec4 _TexOffset;uniform mat4 effects_MatrixVP;uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvoid main(){vec4 texParams=_TexParams;vTexCoord=vec2(atlasOffset.xy*_TexOffset.zw+_TexOffset.xy);vColor=_Color;vParams=vec3(texParams.w,texParams.y,texParams.x);if(texParams.z==1.0){vec4 pos=vec4(aPos.xy*_Size,aPos.z,1.0);gl_Position=effects_MatrixVP*effects_ObjectToWorld*pos;}else{mat4 view=effects_MatrixV;vec3 camRight=vec3(view[0][0],view[1][0],view[2][0]);vec3 camUp=vec3(view[0][1],view[1][1],view[2][1]);vec3 worldPosition=vec3(effects_ObjectToWorld*vec4(0.0,0.0,0.0,1.0));vec3 vertexPosition=worldPosition+camRight*aPos.x*_Size.x*_Scale.x+camUp*aPos.y*_Size.y*_Scale.y;gl_Position=effects_MatrixVP*vec4(vertexPosition,1.0);}\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
10210
+ var itemVert = "precision highp float;attribute vec2 aUV;attribute vec3 aPos;varying vec2 vTexCoord;varying vec3 vParams;varying vec4 vColor;uniform vec2 _Size;uniform vec3 _Scale;uniform vec4 _Color;uniform vec4 _TexParams;uniform vec4 _TexOffset;uniform mat4 effects_MatrixVP;uniform mat4 effects_ObjectToWorld;uniform mat4 effects_MatrixV;\n#ifdef ENV_EDITOR\nuniform vec4 uEditorTransform;\n#endif\nvoid main(){vec4 texParams=_TexParams;vTexCoord=vec2(aUV.xy*_TexOffset.zw+_TexOffset.xy);vColor=_Color;vParams=vec3(texParams.w,texParams.y,texParams.x);if(texParams.z==1.0){vec4 pos=vec4(aPos.xy*_Size,aPos.z,1.0);gl_Position=effects_MatrixVP*effects_ObjectToWorld*pos;}else{mat4 view=effects_MatrixV;vec3 camRight=vec3(view[0][0],view[1][0],view[2][0]);vec3 camUp=vec3(view[0][1],view[1][1],view[2][1]);vec3 worldPosition=vec3(effects_ObjectToWorld*vec4(0.0,0.0,0.0,1.0));vec3 vertexPosition=worldPosition+camRight*aPos.x*_Size.x*_Scale.x+camUp*aPos.y*_Size.y*_Scale.y;gl_Position=effects_MatrixVP*vec4(vertexPosition,1.0);}\n#ifdef ENV_EDITOR\ngl_Position=vec4(gl_Position.xy*uEditorTransform.xy+uEditorTransform.zw*gl_Position.w,gl_Position.zw);\n#endif\n}";
10216
10211
 
10217
10212
  var itemFrag = "precision highp float;varying vec4 vColor;varying vec2 vTexCoord;varying vec3 vParams;uniform sampler2D _MainTex;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;}void main(){vec4 color=vec4(0.);\n#ifdef TRANSPARENT_VIDEO\nfloat halfX=vTexCoord.x*0.5;vec2 uv_rgb=vec2(halfX,vTexCoord.y);vec2 uv_alpha=vec2(halfX+0.5,vTexCoord.y);vec3 rgb=texture2D(_MainTex,uv_rgb).rgb;float alpha=max(texture2D(_MainTex,uv_alpha).r,1e-5);vec4 texColor=vec4(rgb/alpha,alpha);\n#else\nvec4 texColor=texture2D(_MainTex,vTexCoord.xy);\n#endif\ncolor=blendColor(texColor,vColor,floor(0.5+vParams.y));\n#ifdef ALPHA_CLIP\nif(color.a<0.04){discard;}\n#endif\ncolor.a=clamp(color.a,0.0,1.0);gl_FragColor=color;}";
10218
10213
 
@@ -12448,6 +12443,15 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12448
12443
  return out;
12449
12444
  }
12450
12445
 
12446
+ var singleSplits = [
12447
+ [
12448
+ 0,
12449
+ 0,
12450
+ 1,
12451
+ 1,
12452
+ undefined
12453
+ ]
12454
+ ];
12451
12455
  /**
12452
12456
  * @since 2.1.0
12453
12457
  */ var BaseRenderComponent = /*#__PURE__*/ function(RendererComponent) {
@@ -12455,11 +12459,12 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12455
12459
  function BaseRenderComponent(engine) {
12456
12460
  var _this;
12457
12461
  _this = RendererComponent.call(this, engine) || this;
12458
- _this.color = new Color(1, 1, 1, 1);
12459
12462
  _this.visible = true;
12463
+ _this.splits = singleSplits;
12460
12464
  /**
12461
12465
  * 用于点击测试的碰撞器
12462
12466
  */ _this.meshCollider = new MeshCollider();
12467
+ _this._color = new Color(1, 1, 1, 1);
12463
12468
  // TODO 点击测试后续抽象一个 Collider 组件
12464
12469
  _this.getHitTestParams = function(force) {
12465
12470
  var sizeMatrix = Matrix4.fromScale(_this.transform.size.x, _this.transform.size.y, 1);
@@ -12490,6 +12495,58 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12490
12495
  mask: 0,
12491
12496
  alphaMask: false
12492
12497
  };
12498
+ _this.defaultGeometry = Geometry.create(_this.engine, {
12499
+ attributes: {
12500
+ aPos: {
12501
+ type: glContext.FLOAT,
12502
+ size: 3,
12503
+ data: new Float32Array([
12504
+ -0.5,
12505
+ 0.5,
12506
+ 0,
12507
+ -0.5,
12508
+ -0.5,
12509
+ 0,
12510
+ 0.5,
12511
+ 0.5,
12512
+ 0,
12513
+ 0.5,
12514
+ -0.5,
12515
+ 0
12516
+ ])
12517
+ },
12518
+ aUV: {
12519
+ size: 2,
12520
+ offset: 0,
12521
+ releasable: true,
12522
+ type: glContext.FLOAT,
12523
+ data: new Float32Array([
12524
+ 0,
12525
+ 1,
12526
+ 0,
12527
+ 0,
12528
+ 1,
12529
+ 1,
12530
+ 1,
12531
+ 0
12532
+ ])
12533
+ }
12534
+ },
12535
+ indices: {
12536
+ data: new Uint16Array([
12537
+ 0,
12538
+ 1,
12539
+ 2,
12540
+ 2,
12541
+ 1,
12542
+ 3
12543
+ ]),
12544
+ releasable: true
12545
+ },
12546
+ mode: glContext.TRIANGLES,
12547
+ drawCount: 6
12548
+ });
12549
+ _this.geometry = _this.defaultGeometry;
12493
12550
  var material = Material.create(_this.engine, {
12494
12551
  shader: {
12495
12552
  fragment: itemFrag,
@@ -12498,12 +12555,7 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12498
12555
  }
12499
12556
  });
12500
12557
  _this.material = material;
12501
- _this.material.setColor("_Color", new Color().setFromArray([
12502
- 1,
12503
- 1,
12504
- 1,
12505
- 1
12506
- ]));
12558
+ _this.material.setColor("_Color", new Color(1, 1, 1, 1));
12507
12559
  _this.maskManager = new MaskProcessor(engine);
12508
12560
  return _this;
12509
12561
  }
@@ -12523,11 +12575,11 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12523
12575
  };
12524
12576
  _proto.setColor = function setColor(color) {
12525
12577
  if (_instanceof1(color, Color)) {
12526
- this.color.copyFrom(color);
12578
+ this._color.copyFrom(color);
12527
12579
  } else {
12528
- this.color.setFromArray(color);
12580
+ this._color.setFromArray(color);
12529
12581
  }
12530
- this.material.setColor("_Color", this.color);
12582
+ this.material.setColor("_Color", this._color);
12531
12583
  };
12532
12584
  _proto.setTexture = function setTexture(input) {
12533
12585
  var _this = this;
@@ -12590,98 +12642,143 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12590
12642
  var boundingBox = this.meshCollider.getBoundingBox();
12591
12643
  return boundingBox;
12592
12644
  };
12593
- _proto.getItemGeometryData = function getItemGeometryData(geometry) {
12594
- var renderer = this.renderer;
12645
+ _proto.getItemGeometryData = function getItemGeometryData(renderer) {
12646
+ var _this = this, splits = _this.splits, textureSheetAnimation = _this.textureSheetAnimation;
12647
+ var sx = 1, sy = 1;
12648
+ var geometry = this.defaultGeometry;
12595
12649
  if (renderer.shape) {
12596
12650
  var _renderer_shape = renderer.shape, _renderer_shape_index = _renderer_shape.index, index = _renderer_shape_index === void 0 ? [] : _renderer_shape_index, _renderer_shape_aPoint = _renderer_shape.aPoint, aPoint = _renderer_shape_aPoint === void 0 ? [] : _renderer_shape_aPoint;
12597
12651
  var point = new Float32Array(aPoint);
12598
12652
  var position = [];
12599
- var atlasOffset = [];
12653
+ var aUV = [];
12600
12654
  for(var i = 0; i < point.length; i += 6){
12601
- atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
12655
+ point[i] *= sx;
12656
+ point[i + 1] *= sy;
12657
+ aUV.push(aPoint[i + 2], aPoint[i + 3]);
12602
12658
  position.push(point[i], point[i + 1], 0.0);
12603
12659
  }
12604
12660
  geometry.setAttributeData("aPos", new Float32Array(position));
12605
12661
  return {
12606
12662
  index: index,
12607
- atlasOffset: atlasOffset
12663
+ aUV: aUV
12608
12664
  };
12609
- } else {
12610
- geometry.setAttributeData("aPos", new Float32Array([
12611
- -0.5,
12612
- 0.5,
12665
+ }
12666
+ var originData = [
12667
+ -.5,
12668
+ .5,
12669
+ -.5,
12670
+ -.5,
12671
+ .5,
12672
+ .5,
12673
+ .5,
12674
+ -.5
12675
+ ];
12676
+ var aUV1 = [];
12677
+ var index1 = [];
12678
+ var position1 = [];
12679
+ if (splits.length === 1) {
12680
+ var split = textureSheetAnimation ? [
12613
12681
  0,
12614
- -0.5,
12615
- -0.5,
12616
12682
  0,
12617
- 0.5,
12618
- 0.5,
12683
+ 1,
12684
+ 1,
12685
+ splits[0][4]
12686
+ ] : splits[0];
12687
+ var texOffset = split[4] ? [
12619
12688
  0,
12620
- 0.5,
12621
- -0.5,
12689
+ 0,
12690
+ 1,
12691
+ 0,
12692
+ 0,
12693
+ 1,
12694
+ 1,
12695
+ 1
12696
+ ] : [
12697
+ 0,
12698
+ 1,
12699
+ 0,
12700
+ 0,
12701
+ 1,
12702
+ 1,
12703
+ 1,
12622
12704
  0
12623
- ]));
12624
- return {
12625
- index: [
12626
- 0,
12627
- 1,
12628
- 2,
12629
- 2,
12630
- 1,
12631
- 3
12632
- ],
12633
- atlasOffset: [
12634
- 0,
12635
- 1,
12636
- 0,
12637
- 0,
12638
- 1,
12639
- 1,
12640
- 1,
12641
- 0
12642
- ]
12643
- };
12644
- }
12645
- };
12646
- _proto.createGeometry = function createGeometry() {
12647
- var geometry = Geometry.create(this.engine, {
12648
- attributes: {
12649
- aPos: {
12650
- type: glContext.FLOAT,
12651
- size: 3,
12652
- data: new Float32Array([
12653
- -0.5,
12654
- 0.5,
12705
+ ];
12706
+ var tox = split[0];
12707
+ var toy = split[1];
12708
+ var tsx = split[4] ? split[3] : split[2];
12709
+ var tsy = split[4] ? split[2] : split[3];
12710
+ aUV1.push(texOffset[0] * tsx + tox, texOffset[1] * tsy + toy, texOffset[2] * tsx + tox, texOffset[3] * tsy + toy, texOffset[4] * tsx + tox, texOffset[5] * tsy + toy, texOffset[6] * tsx + tox, texOffset[7] * tsy + toy);
12711
+ position1.push(originData[0], originData[1], 0.0, originData[2], originData[3], 0.0, originData[4], originData[5], 0.0, originData[6], originData[7], 0.0);
12712
+ index1.push(0, 1, 2, 2, 1, 3);
12713
+ } else {
12714
+ // TODO: 原有打包纹理拆分逻辑,待移除
12715
+ //-------------------------------------------------------------------------
12716
+ var col = 2;
12717
+ var row = 2;
12718
+ for(var x = 0; x < col; x++){
12719
+ for(var y = 0; y < row; y++){
12720
+ var base = (y * 2 + x) * 4;
12721
+ // @ts-expect-error
12722
+ var split1 = textureSheetAnimation ? [
12655
12723
  0,
12656
- -0.5,
12657
- -0.5,
12658
12724
  0,
12659
- 0.5,
12660
- 0.5,
12725
+ 1,
12726
+ 1,
12727
+ splits[0][4]
12728
+ ] : splits[y * 2 + x];
12729
+ var texOffset1 = split1[4] ? [
12661
12730
  0,
12662
- 0.5,
12663
- -0.5,
12731
+ 0,
12732
+ 1,
12733
+ 0,
12734
+ 0,
12735
+ 1,
12736
+ 1,
12737
+ 1
12738
+ ] : [
12739
+ 0,
12740
+ 1,
12741
+ 0,
12742
+ 0,
12743
+ 1,
12744
+ 1,
12745
+ 1,
12664
12746
  0
12665
- ])
12666
- },
12667
- atlasOffset: {
12668
- size: 2,
12669
- offset: 0,
12670
- releasable: true,
12671
- type: glContext.FLOAT,
12672
- data: new Float32Array(0)
12747
+ ];
12748
+ var dw = ((x + x + 1) / col - 1) / 2;
12749
+ var dh = ((y + y + 1) / row - 1) / 2;
12750
+ var tox1 = split1[0];
12751
+ var toy1 = split1[1];
12752
+ var tsx1 = split1[4] ? split1[3] : split1[2];
12753
+ var tsy1 = split1[4] ? split1[2] : split1[3];
12754
+ var origin = [
12755
+ originData[0] / col + dw,
12756
+ originData[1] / row + dh,
12757
+ originData[2] / col + dw,
12758
+ originData[3] / row + dh,
12759
+ originData[4] / col + dw,
12760
+ originData[5] / row + dh,
12761
+ originData[6] / col + dw,
12762
+ originData[7] / row + dh
12763
+ ];
12764
+ aUV1.push(texOffset1[0] * tsx1 + tox1, texOffset1[1] * tsy1 + toy1, texOffset1[2] * tsx1 + tox1, texOffset1[3] * tsy1 + toy1, texOffset1[4] * tsx1 + tox1, texOffset1[5] * tsy1 + toy1, texOffset1[6] * tsx1 + tox1, texOffset1[7] * tsy1 + toy1);
12765
+ position1.push(origin[0] * sx, origin[1] * sy, 0.0, origin[2] * sx, origin[3] * sy, 0.0, origin[4] * sx, origin[5] * sy, 0.0, origin[6] * sx, origin[7] * sy, 0.0);
12766
+ index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
12673
12767
  }
12674
- },
12675
- indices: {
12676
- data: new Uint16Array(0),
12677
- releasable: true
12678
- },
12679
- mode: glContext.TRIANGLES
12680
- });
12681
- var geoData = this.getItemGeometryData(geometry);
12682
- var index = geoData.index, atlasOffset = geoData.atlasOffset;
12768
+ }
12769
+ }
12770
+ geometry.setAttributeData("aPos", new Float32Array(position1));
12771
+ return {
12772
+ index: index1,
12773
+ aUV: aUV1
12774
+ };
12775
+ };
12776
+ _proto.configureDefaultGeometry = function configureDefaultGeometry(renderer) {
12777
+ var geoData = this.getItemGeometryData(renderer);
12778
+ var index = geoData.index, aUV = geoData.aUV;
12779
+ var geometry = this.defaultGeometry;
12683
12780
  geometry.setIndexData(new Uint16Array(index));
12684
- geometry.setAttributeData("atlasOffset", new Float32Array(atlasOffset));
12781
+ geometry.setAttributeData("aUV", new Float32Array(aUV));
12685
12782
  geometry.setDrawCount(index.length);
12686
12783
  return geometry;
12687
12784
  };
@@ -12700,13 +12797,12 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12700
12797
  setMaskMode(material, maskMode);
12701
12798
  setSideMode(material, side);
12702
12799
  material.shader.shaderData.properties = '_MainTex("_MainTex",2D) = "white" {}';
12703
- material.setColor("_Color", new Color(0, 0, 0, 1));
12704
12800
  material.setVector4("_TexOffset", new Vector4(0, 0, 1, 1));
12705
12801
  material.setTexture("_MainTex", texture);
12706
- this.preMultiAlpha = getPreMultiAlpha(blendMode);
12802
+ var preMultiAlpha = getPreMultiAlpha(blendMode);
12707
12803
  var texParams = new Vector4();
12708
12804
  texParams.x = renderer.occlusion ? +renderer.transparentOcclusion : 1;
12709
- texParams.y = +this.preMultiAlpha;
12805
+ texParams.y = preMultiAlpha;
12710
12806
  texParams.z = renderer.renderMode;
12711
12807
  texParams.w = renderer.maskMode;
12712
12808
  material.setVector4("_TexParams", texParams);
@@ -12732,8 +12828,11 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12732
12828
  };
12733
12829
  _proto.fromData = function fromData(data) {
12734
12830
  RendererComponent.prototype.fromData.call(this, data);
12735
- var _data_renderer;
12736
- var renderer = (_data_renderer = data.renderer) != null ? _data_renderer : {};
12831
+ var baseRenderComponentData = data;
12832
+ var _baseRenderComponentData_renderer;
12833
+ var renderer = (_baseRenderComponentData_renderer = baseRenderComponentData.renderer) != null ? _baseRenderComponentData_renderer : {};
12834
+ var splits = baseRenderComponentData.splits;
12835
+ var textureSheetAnimation = baseRenderComponentData.textureSheetAnimation;
12737
12836
  var maskProps = data.mask;
12738
12837
  if (maskProps && maskProps.ref) {
12739
12838
  maskProps.ref = this.engine.findObject(maskProps.ref);
@@ -12742,14 +12841,15 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12742
12841
  // TODO 新蒙板上线后移除
12743
12842
  //-------------------------------------------------------------------------
12744
12843
  var shapeData = renderer.shape;
12745
- //@ts-expect-error
12746
- var split = data.splits && !data.textureSheetAnimation ? data.splits[0] : undefined;
12844
+ var split = splits && !textureSheetAnimation ? splits[0] : undefined;
12747
12845
  var shapeGeometry = undefined;
12748
12846
  if (shapeData !== undefined && shapeData !== null && !("aPoint" in shapeData && "index" in shapeData)) {
12749
12847
  shapeGeometry = getGeometryByShape(shapeData, split);
12750
12848
  }
12751
- var _renderer_renderMode, _renderer_blending, _renderer_side, _renderer_alphaMask;
12752
12849
  //-------------------------------------------------------------------------
12850
+ this.splits = splits || singleSplits;
12851
+ this.textureSheetAnimation = textureSheetAnimation;
12852
+ var _renderer_renderMode, _renderer_blending, _renderer_side, _renderer_alphaMask;
12753
12853
  this.renderer = {
12754
12854
  renderMode: (_renderer_renderMode = renderer.renderMode) != null ? _renderer_renderMode : RenderMode.MESH,
12755
12855
  blending: (_renderer_blending = renderer.blending) != null ? _renderer_blending : BlendingMode.ALPHA,
@@ -12764,7 +12864,31 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12764
12864
  alphaMask: (_renderer_alphaMask = renderer.alphaMask) != null ? _renderer_alphaMask : false
12765
12865
  };
12766
12866
  this.configureMaterial(this.renderer);
12867
+ if (baseRenderComponentData.geometry) {
12868
+ this.geometry = this.engine.findObject(baseRenderComponentData.geometry);
12869
+ } else {
12870
+ this.geometry = this.defaultGeometry;
12871
+ this.configureDefaultGeometry(this.renderer);
12872
+ }
12767
12873
  };
12874
+ _create_class(BaseRenderComponent, [
12875
+ {
12876
+ key: "color",
12877
+ get: /**
12878
+ * 获取当前图层的颜色
12879
+ * @since 2.5.0
12880
+ */ function get() {
12881
+ return this._color;
12882
+ },
12883
+ set: /**
12884
+ * 设置当前图层的颜色
12885
+ * @since 2.5.0
12886
+ */ function set(value) {
12887
+ this._color = value;
12888
+ this.material.setColor("_Color", this._color);
12889
+ }
12890
+ }
12891
+ ]);
12768
12892
  return BaseRenderComponent;
12769
12893
  }(RendererComponent);
12770
12894
 
@@ -12779,37 +12903,8 @@ exports.ShapeComponent = /*#__PURE__*/ function(BaseRenderComponent) {
12779
12903
  _this.graphicsPath = new GraphicsPath();
12780
12904
  _this.vert = "\nprecision highp float;\n\nattribute vec3 aPos;//x y\n\nuniform mat4 effects_MatrixVP;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_ObjectToWorld;\n\nvoid main() {\n vec4 pos = vec4(aPos.xyz, 1.0);\n gl_Position = effects_MatrixVP * effects_ObjectToWorld * pos;\n}\n";
12781
12905
  _this.frag = "\nprecision highp float;\n\nuniform vec4 _Color;\n\nvoid main() {\n vec4 color = _Color;\n color.rgb *= color.a;\n gl_FragColor = color;\n}\n";
12782
- // Create Geometry
12906
+ // Add Geometry SubMesh
12783
12907
  //-------------------------------------------------------------------------
12784
- _this.geometry = Geometry.create(engine, {
12785
- attributes: {
12786
- aPos: {
12787
- type: glContext.FLOAT,
12788
- size: 3,
12789
- data: new Float32Array([
12790
- -0.5,
12791
- 0.5,
12792
- 0,
12793
- -0.5,
12794
- -0.5,
12795
- 0,
12796
- 0.5,
12797
- 0.5,
12798
- 0,
12799
- 0.5,
12800
- -0.5,
12801
- 0
12802
- ])
12803
- },
12804
- aUV: {
12805
- type: glContext.FLOAT,
12806
- size: 2,
12807
- data: new Float32Array()
12808
- }
12809
- },
12810
- mode: glContext.TRIANGLES,
12811
- drawCount: 4
12812
- });
12813
12908
  _this.geometry.subMeshes.push({
12814
12909
  offset: 0,
12815
12910
  indexCount: 0,
@@ -20139,7 +20234,7 @@ var RuntimeClip = /*#__PURE__*/ function() {
20139
20234
  this.playable.play();
20140
20235
  }
20141
20236
  this.parentMixer.setClipWeight(this.playable, weight);
20142
- var clipTime = clip.toLocalTime(localTime);
20237
+ var clipTime = parseFloat(clip.toLocalTime(localTime).toFixed(3));
20143
20238
  this.playable.setTime(clipTime);
20144
20239
  // 判断动画是否结束
20145
20240
  if (ended) {
@@ -21328,12 +21423,11 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21328
21423
  * 前进合成到指定时间
21329
21424
  * @param time - 相对0时刻的时间
21330
21425
  */ _proto.forwardTime = function forwardTime(time) {
21331
- var deltaTime = time * 1000 - this.time * 1000;
21426
+ var deltaTime = time * 1000 - this.rootComposition.time * 1000;
21332
21427
  var reverse = deltaTime < 0;
21333
21428
  var step = 15;
21334
21429
  var t = Math.abs(deltaTime);
21335
21430
  var ss = reverse ? -step : step;
21336
- // FIXME Update 中可能会修改合成时间,这边需要优化更新逻辑
21337
21431
  for(t; t > step; t -= step){
21338
21432
  this.update(ss);
21339
21433
  }
@@ -21373,14 +21467,13 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21373
21467
  this.callAwake(this.rootItem);
21374
21468
  this.rootItem.beginPlay();
21375
21469
  }
21376
- var previousCompositionTime = this.time;
21377
- this.updateCompositionTime(deltaTime * this.speed / 1000);
21378
- var deltaTimeInMs = (this.time - previousCompositionTime) * 1000;
21470
+ var dt = parseFloat(this.getUpdateTime(deltaTime * this.speed).toFixed(0));
21471
+ this.updateRootComposition(dt / 1000);
21379
21472
  this.updateVideo();
21380
21473
  // 更新 model-tree-plugin
21381
- this.updatePluginLoaders(deltaTimeInMs);
21382
- this.sceneTicking.update.tick(deltaTimeInMs);
21383
- this.sceneTicking.lateUpdate.tick(deltaTimeInMs);
21474
+ this.updatePluginLoaders(deltaTime);
21475
+ this.sceneTicking.update.tick(dt);
21476
+ this.sceneTicking.lateUpdate.tick(dt);
21384
21477
  this.updateCamera();
21385
21478
  this.prepareRender();
21386
21479
  if (this.isEnded && !this.isEndCalled) {
@@ -21396,6 +21489,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21396
21489
  _proto.shouldDispose = function shouldDispose() {
21397
21490
  return this.isEnded && this.rootItem.endBehavior === EndBehavior.destroy && !this.reusable;
21398
21491
  };
21492
+ _proto.getUpdateTime = function getUpdateTime(t) {
21493
+ var startTimeInMs = this.startTime * 1000;
21494
+ var now = this.rootComposition.time * 1000;
21495
+ if (t < 0 && now + t < startTimeInMs) {
21496
+ return startTimeInMs - now;
21497
+ }
21498
+ return t;
21499
+ };
21399
21500
  _proto.callAwake = function callAwake(item) {
21400
21501
  for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
21401
21502
  var component = _step.value;
@@ -21440,18 +21541,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21440
21541
  };
21441
21542
  /**
21442
21543
  * 更新主合成组件
21443
- */ _proto.updateCompositionTime = function updateCompositionTime(deltaTime) {
21544
+ */ _proto.updateRootComposition = function updateRootComposition(deltaTime) {
21444
21545
  if (this.rootComposition.state === PlayState.Paused || !this.rootComposition.isActiveAndEnabled) {
21445
21546
  return;
21446
21547
  }
21447
- // 相对于合成开始时间的时间
21448
- var localTime = this.time + deltaTime - this.startTime;
21449
- if (deltaTime < 0 && localTime < 0) {
21450
- localTime = 0;
21451
- }
21548
+ var localTime = parseFloat((this.time + deltaTime - this.rootItem.start).toFixed(3));
21549
+ var isEnded = false;
21452
21550
  var duration = this.rootItem.duration;
21453
21551
  var endBehavior = this.rootItem.endBehavior;
21454
- var isEnded = false;
21455
21552
  if (localTime - duration > 0.001) {
21456
21553
  isEnded = true;
21457
21554
  switch(endBehavior){
@@ -21476,7 +21573,7 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21476
21573
  }
21477
21574
  }
21478
21575
  }
21479
- this.rootComposition.time = localTime + this.startTime;
21576
+ this.rootComposition.time = localTime;
21480
21577
  // end state changed, handle onEnd flags
21481
21578
  if (this.isEnded !== isEnded) {
21482
21579
  if (isEnded) {
@@ -22632,15 +22729,6 @@ var ColorPlayable = /*#__PURE__*/ function(Playable) {
22632
22729
  return ColorPlayable;
22633
22730
  }(Playable);
22634
22731
 
22635
- var singleSplits = [
22636
- [
22637
- 0,
22638
- 0,
22639
- 1,
22640
- 1,
22641
- undefined
22642
- ]
22643
- ];
22644
22732
  var seed$2 = 0;
22645
22733
  exports.SpriteColorPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
22646
22734
  _inherits(SpriteColorPlayableAsset, PlayableAsset);
@@ -22666,10 +22754,8 @@ exports.SpriteComponent = /*#__PURE__*/ function(BaseRenderComponent) {
22666
22754
  function SpriteComponent(engine, props) {
22667
22755
  var _this;
22668
22756
  _this = BaseRenderComponent.call(this, engine) || this;
22669
- _this.splits = singleSplits;
22670
22757
  _this.frameAnimationLoop = false;
22671
22758
  _this.name = "MSprite" + seed$2++;
22672
- _this.geometry = _this.createGeometry();
22673
22759
  if (props) {
22674
22760
  _this.fromData(props);
22675
22761
  }
@@ -22759,111 +22845,10 @@ exports.SpriteComponent = /*#__PURE__*/ function(BaseRenderComponent) {
22759
22845
  source.video.load();
22760
22846
  }
22761
22847
  };
22762
- _proto.getItemGeometryData = function getItemGeometryData(geometry) {
22763
- var _this = this, splits = _this.splits, textureSheetAnimation = _this.textureSheetAnimation;
22764
- var sx = 1, sy = 1;
22765
- var renderer = this.renderer;
22766
- if (renderer.shape) {
22767
- var _renderer_shape = renderer.shape, _renderer_shape_index = _renderer_shape.index, index = _renderer_shape_index === void 0 ? [] : _renderer_shape_index, _renderer_shape_aPoint = _renderer_shape.aPoint, aPoint = _renderer_shape_aPoint === void 0 ? [] : _renderer_shape_aPoint;
22768
- var point = new Float32Array(aPoint);
22769
- var position = [];
22770
- var atlasOffset = [];
22771
- for(var i = 0; i < point.length; i += 6){
22772
- point[i] *= sx;
22773
- point[i + 1] *= sy;
22774
- atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
22775
- position.push(point[i], point[i + 1], 0.0);
22776
- }
22777
- geometry.setAttributeData("aPos", new Float32Array(position));
22778
- return {
22779
- index: index,
22780
- atlasOffset: atlasOffset
22781
- };
22782
- }
22783
- var originData = [
22784
- -.5,
22785
- .5,
22786
- -.5,
22787
- -.5,
22788
- .5,
22789
- .5,
22790
- .5,
22791
- -.5
22792
- ];
22793
- var atlasOffset1 = [];
22794
- var index1 = [];
22795
- var col = 2;
22796
- var row = 2;
22797
- if (splits.length === 1) {
22798
- col = 1;
22799
- row = 1;
22800
- }
22801
- var position1 = [];
22802
- for(var x = 0; x < col; x++){
22803
- for(var y = 0; y < row; y++){
22804
- var base = (y * 2 + x) * 4;
22805
- // @ts-expect-error
22806
- var split = textureSheetAnimation ? [
22807
- 0,
22808
- 0,
22809
- 1,
22810
- 1,
22811
- splits[0][4]
22812
- ] : splits[y * 2 + x];
22813
- var texOffset = split[4] ? [
22814
- 0,
22815
- 0,
22816
- 1,
22817
- 0,
22818
- 0,
22819
- 1,
22820
- 1,
22821
- 1
22822
- ] : [
22823
- 0,
22824
- 1,
22825
- 0,
22826
- 0,
22827
- 1,
22828
- 1,
22829
- 1,
22830
- 0
22831
- ];
22832
- var dw = ((x + x + 1) / col - 1) / 2;
22833
- var dh = ((y + y + 1) / row - 1) / 2;
22834
- var tox = split[0];
22835
- var toy = split[1];
22836
- var tsx = split[4] ? split[3] : split[2];
22837
- var tsy = split[4] ? split[2] : split[3];
22838
- var origin = [
22839
- originData[0] / col + dw,
22840
- originData[1] / row + dh,
22841
- originData[2] / col + dw,
22842
- originData[3] / row + dh,
22843
- originData[4] / col + dw,
22844
- originData[5] / row + dh,
22845
- originData[6] / col + dw,
22846
- originData[7] / row + dh
22847
- ];
22848
- atlasOffset1.push(texOffset[0] * tsx + tox, texOffset[1] * tsy + toy, texOffset[2] * tsx + tox, texOffset[3] * tsy + toy, texOffset[4] * tsx + tox, texOffset[5] * tsy + toy, texOffset[6] * tsx + tox, texOffset[7] * tsy + toy);
22849
- position1.push(origin[0] * sx, origin[1] * sy, 0.0, origin[2] * sx, origin[3] * sy, 0.0, origin[4] * sx, origin[5] * sy, 0.0, origin[6] * sx, origin[7] * sy, 0.0);
22850
- index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
22851
- }
22852
- }
22853
- geometry.setAttributeData("aPos", new Float32Array(position1));
22854
- return {
22855
- index: index1,
22856
- atlasOffset: atlasOffset1
22857
- };
22858
- };
22859
22848
  _proto.fromData = function fromData(data) {
22860
22849
  BaseRenderComponent.prototype.fromData.call(this, data);
22861
22850
  var interaction = data.interaction, options = data.options;
22862
22851
  this.interaction = interaction;
22863
- this.splits = data.splits || singleSplits;
22864
- this.textureSheetAnimation = data.textureSheetAnimation;
22865
- var geometry = this.createGeometry();
22866
- this.geometry = geometry;
22867
22852
  var startColor = options.startColor || [
22868
22853
  1,
22869
22854
  1,
@@ -26142,7 +26127,6 @@ exports.TextComponent = /*#__PURE__*/ function(BaseRenderComponent) {
26142
26127
  _this.SCALE_FACTOR = 0.1;
26143
26128
  _this.ALPHA_FIX_VALUE = 1 / 255;
26144
26129
  _this.name = "MText" + seed$1++;
26145
- _this.geometry = _this.createGeometry();
26146
26130
  if (props) {
26147
26131
  _this.fromData(props);
26148
26132
  }
@@ -27023,11 +27007,6 @@ function colorToArr(hex, normalized) {
27023
27007
  parseInt(m[2], 16),
27024
27008
  parseInt(m[3], 16),
27025
27009
  255
27026
- ] || [
27027
- 0,
27028
- 0,
27029
- 0,
27030
- 255
27031
27010
  ];
27032
27011
  }
27033
27012
  } else if (_instanceof1(hex, Array)) {
@@ -31626,7 +31605,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
31626
31605
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
31627
31606
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
31628
31607
  registerPlugin("interact", InteractLoader, exports.VFXItem);
31629
- var version = "2.4.8";
31608
+ var version = "2.5.0-alpha.0";
31630
31609
  logger.info("Core version: " + version + ".");
31631
31610
 
31632
31611
  exports.AbstractPlugin = AbstractPlugin;