@galacean/effects-threejs 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 threejs plugin 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';
@@ -367,11 +367,6 @@ function colorToArr$1(hex, normalized) {
367
367
  parseInt(m[2], 16),
368
368
  parseInt(m[3], 16),
369
369
  255
370
- ] || [
371
- 0,
372
- 0,
373
- 0,
374
- 255
375
370
  ];
376
371
  }
377
372
  } else if (_instanceof1(hex, Array)) {
@@ -10234,7 +10229,7 @@ var itemFrame_frag = "#version 100\nprecision highp float;vec4 blendColor(vec4 c
10234
10229
 
10235
10230
  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.;}";
10236
10231
 
10237
- 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}";
10232
+ 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}";
10238
10233
 
10239
10234
  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;}";
10240
10235
 
@@ -12470,6 +12465,15 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12470
12465
  return out;
12471
12466
  }
12472
12467
 
12468
+ var singleSplits = [
12469
+ [
12470
+ 0,
12471
+ 0,
12472
+ 1,
12473
+ 1,
12474
+ undefined
12475
+ ]
12476
+ ];
12473
12477
  /**
12474
12478
  * @since 2.1.0
12475
12479
  */ var BaseRenderComponent = /*#__PURE__*/ function(RendererComponent) {
@@ -12477,11 +12481,12 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12477
12481
  function BaseRenderComponent(engine) {
12478
12482
  var _this;
12479
12483
  _this = RendererComponent.call(this, engine) || this;
12480
- _this.color = new Color(1, 1, 1, 1);
12481
12484
  _this.visible = true;
12485
+ _this.splits = singleSplits;
12482
12486
  /**
12483
12487
  * 用于点击测试的碰撞器
12484
12488
  */ _this.meshCollider = new MeshCollider();
12489
+ _this._color = new Color(1, 1, 1, 1);
12485
12490
  // TODO 点击测试后续抽象一个 Collider 组件
12486
12491
  _this.getHitTestParams = function(force) {
12487
12492
  var sizeMatrix = Matrix4.fromScale(_this.transform.size.x, _this.transform.size.y, 1);
@@ -12512,6 +12517,58 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12512
12517
  mask: 0,
12513
12518
  alphaMask: false
12514
12519
  };
12520
+ _this.defaultGeometry = Geometry.create(_this.engine, {
12521
+ attributes: {
12522
+ aPos: {
12523
+ type: glContext.FLOAT,
12524
+ size: 3,
12525
+ data: new Float32Array([
12526
+ -0.5,
12527
+ 0.5,
12528
+ 0,
12529
+ -0.5,
12530
+ -0.5,
12531
+ 0,
12532
+ 0.5,
12533
+ 0.5,
12534
+ 0,
12535
+ 0.5,
12536
+ -0.5,
12537
+ 0
12538
+ ])
12539
+ },
12540
+ aUV: {
12541
+ size: 2,
12542
+ offset: 0,
12543
+ releasable: true,
12544
+ type: glContext.FLOAT,
12545
+ data: new Float32Array([
12546
+ 0,
12547
+ 1,
12548
+ 0,
12549
+ 0,
12550
+ 1,
12551
+ 1,
12552
+ 1,
12553
+ 0
12554
+ ])
12555
+ }
12556
+ },
12557
+ indices: {
12558
+ data: new Uint16Array([
12559
+ 0,
12560
+ 1,
12561
+ 2,
12562
+ 2,
12563
+ 1,
12564
+ 3
12565
+ ]),
12566
+ releasable: true
12567
+ },
12568
+ mode: glContext.TRIANGLES,
12569
+ drawCount: 6
12570
+ });
12571
+ _this.geometry = _this.defaultGeometry;
12515
12572
  var material = Material.create(_this.engine, {
12516
12573
  shader: {
12517
12574
  fragment: itemFrag,
@@ -12520,12 +12577,7 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12520
12577
  }
12521
12578
  });
12522
12579
  _this.material = material;
12523
- _this.material.setColor("_Color", new Color().setFromArray([
12524
- 1,
12525
- 1,
12526
- 1,
12527
- 1
12528
- ]));
12580
+ _this.material.setColor("_Color", new Color(1, 1, 1, 1));
12529
12581
  _this.maskManager = new MaskProcessor(engine);
12530
12582
  return _this;
12531
12583
  }
@@ -12545,11 +12597,11 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12545
12597
  };
12546
12598
  _proto.setColor = function setColor(color) {
12547
12599
  if (_instanceof1(color, Color)) {
12548
- this.color.copyFrom(color);
12600
+ this._color.copyFrom(color);
12549
12601
  } else {
12550
- this.color.setFromArray(color);
12602
+ this._color.setFromArray(color);
12551
12603
  }
12552
- this.material.setColor("_Color", this.color);
12604
+ this.material.setColor("_Color", this._color);
12553
12605
  };
12554
12606
  _proto.setTexture = function setTexture(input) {
12555
12607
  var _this = this;
@@ -12612,98 +12664,143 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12612
12664
  var boundingBox = this.meshCollider.getBoundingBox();
12613
12665
  return boundingBox;
12614
12666
  };
12615
- _proto.getItemGeometryData = function getItemGeometryData(geometry) {
12616
- var renderer = this.renderer;
12667
+ _proto.getItemGeometryData = function getItemGeometryData(renderer) {
12668
+ var _this = this, splits = _this.splits, textureSheetAnimation = _this.textureSheetAnimation;
12669
+ var sx = 1, sy = 1;
12670
+ var geometry = this.defaultGeometry;
12617
12671
  if (renderer.shape) {
12618
12672
  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;
12619
12673
  var point = new Float32Array(aPoint);
12620
12674
  var position = [];
12621
- var atlasOffset = [];
12675
+ var aUV = [];
12622
12676
  for(var i = 0; i < point.length; i += 6){
12623
- atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
12677
+ point[i] *= sx;
12678
+ point[i + 1] *= sy;
12679
+ aUV.push(aPoint[i + 2], aPoint[i + 3]);
12624
12680
  position.push(point[i], point[i + 1], 0.0);
12625
12681
  }
12626
12682
  geometry.setAttributeData("aPos", new Float32Array(position));
12627
12683
  return {
12628
12684
  index: index,
12629
- atlasOffset: atlasOffset
12685
+ aUV: aUV
12630
12686
  };
12631
- } else {
12632
- geometry.setAttributeData("aPos", new Float32Array([
12633
- -0.5,
12634
- 0.5,
12687
+ }
12688
+ var originData = [
12689
+ -.5,
12690
+ .5,
12691
+ -.5,
12692
+ -.5,
12693
+ .5,
12694
+ .5,
12695
+ .5,
12696
+ -.5
12697
+ ];
12698
+ var aUV1 = [];
12699
+ var index1 = [];
12700
+ var position1 = [];
12701
+ if (splits.length === 1) {
12702
+ var split = textureSheetAnimation ? [
12635
12703
  0,
12636
- -0.5,
12637
- -0.5,
12638
12704
  0,
12639
- 0.5,
12640
- 0.5,
12705
+ 1,
12706
+ 1,
12707
+ splits[0][4]
12708
+ ] : splits[0];
12709
+ var texOffset = split[4] ? [
12641
12710
  0,
12642
- 0.5,
12643
- -0.5,
12711
+ 0,
12712
+ 1,
12713
+ 0,
12714
+ 0,
12715
+ 1,
12716
+ 1,
12717
+ 1
12718
+ ] : [
12719
+ 0,
12720
+ 1,
12721
+ 0,
12722
+ 0,
12723
+ 1,
12724
+ 1,
12725
+ 1,
12644
12726
  0
12645
- ]));
12646
- return {
12647
- index: [
12648
- 0,
12649
- 1,
12650
- 2,
12651
- 2,
12652
- 1,
12653
- 3
12654
- ],
12655
- atlasOffset: [
12656
- 0,
12657
- 1,
12658
- 0,
12659
- 0,
12660
- 1,
12661
- 1,
12662
- 1,
12663
- 0
12664
- ]
12665
- };
12666
- }
12667
- };
12668
- _proto.createGeometry = function createGeometry() {
12669
- var geometry = Geometry.create(this.engine, {
12670
- attributes: {
12671
- aPos: {
12672
- type: glContext.FLOAT,
12673
- size: 3,
12674
- data: new Float32Array([
12675
- -0.5,
12676
- 0.5,
12727
+ ];
12728
+ var tox = split[0];
12729
+ var toy = split[1];
12730
+ var tsx = split[4] ? split[3] : split[2];
12731
+ var tsy = split[4] ? split[2] : split[3];
12732
+ 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);
12733
+ 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);
12734
+ index1.push(0, 1, 2, 2, 1, 3);
12735
+ } else {
12736
+ // TODO: 原有打包纹理拆分逻辑,待移除
12737
+ //-------------------------------------------------------------------------
12738
+ var col = 2;
12739
+ var row = 2;
12740
+ for(var x = 0; x < col; x++){
12741
+ for(var y = 0; y < row; y++){
12742
+ var base = (y * 2 + x) * 4;
12743
+ // @ts-expect-error
12744
+ var split1 = textureSheetAnimation ? [
12677
12745
  0,
12678
- -0.5,
12679
- -0.5,
12680
12746
  0,
12681
- 0.5,
12682
- 0.5,
12747
+ 1,
12748
+ 1,
12749
+ splits[0][4]
12750
+ ] : splits[y * 2 + x];
12751
+ var texOffset1 = split1[4] ? [
12683
12752
  0,
12684
- 0.5,
12685
- -0.5,
12753
+ 0,
12754
+ 1,
12755
+ 0,
12756
+ 0,
12757
+ 1,
12758
+ 1,
12759
+ 1
12760
+ ] : [
12761
+ 0,
12762
+ 1,
12763
+ 0,
12764
+ 0,
12765
+ 1,
12766
+ 1,
12767
+ 1,
12686
12768
  0
12687
- ])
12688
- },
12689
- atlasOffset: {
12690
- size: 2,
12691
- offset: 0,
12692
- releasable: true,
12693
- type: glContext.FLOAT,
12694
- data: new Float32Array(0)
12769
+ ];
12770
+ var dw = ((x + x + 1) / col - 1) / 2;
12771
+ var dh = ((y + y + 1) / row - 1) / 2;
12772
+ var tox1 = split1[0];
12773
+ var toy1 = split1[1];
12774
+ var tsx1 = split1[4] ? split1[3] : split1[2];
12775
+ var tsy1 = split1[4] ? split1[2] : split1[3];
12776
+ var origin = [
12777
+ originData[0] / col + dw,
12778
+ originData[1] / row + dh,
12779
+ originData[2] / col + dw,
12780
+ originData[3] / row + dh,
12781
+ originData[4] / col + dw,
12782
+ originData[5] / row + dh,
12783
+ originData[6] / col + dw,
12784
+ originData[7] / row + dh
12785
+ ];
12786
+ 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);
12787
+ 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);
12788
+ index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
12695
12789
  }
12696
- },
12697
- indices: {
12698
- data: new Uint16Array(0),
12699
- releasable: true
12700
- },
12701
- mode: glContext.TRIANGLES
12702
- });
12703
- var geoData = this.getItemGeometryData(geometry);
12704
- var index = geoData.index, atlasOffset = geoData.atlasOffset;
12790
+ }
12791
+ }
12792
+ geometry.setAttributeData("aPos", new Float32Array(position1));
12793
+ return {
12794
+ index: index1,
12795
+ aUV: aUV1
12796
+ };
12797
+ };
12798
+ _proto.configureDefaultGeometry = function configureDefaultGeometry(renderer) {
12799
+ var geoData = this.getItemGeometryData(renderer);
12800
+ var index = geoData.index, aUV = geoData.aUV;
12801
+ var geometry = this.defaultGeometry;
12705
12802
  geometry.setIndexData(new Uint16Array(index));
12706
- geometry.setAttributeData("atlasOffset", new Float32Array(atlasOffset));
12803
+ geometry.setAttributeData("aUV", new Float32Array(aUV));
12707
12804
  geometry.setDrawCount(index.length);
12708
12805
  return geometry;
12709
12806
  };
@@ -12722,13 +12819,12 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12722
12819
  setMaskMode(material, maskMode);
12723
12820
  setSideMode(material, side);
12724
12821
  material.shader.shaderData.properties = '_MainTex("_MainTex",2D) = "white" {}';
12725
- material.setColor("_Color", new Color(0, 0, 0, 1));
12726
12822
  material.setVector4("_TexOffset", new Vector4(0, 0, 1, 1));
12727
12823
  material.setTexture("_MainTex", texture);
12728
- this.preMultiAlpha = getPreMultiAlpha(blendMode);
12824
+ var preMultiAlpha = getPreMultiAlpha(blendMode);
12729
12825
  var texParams = new Vector4();
12730
12826
  texParams.x = renderer.occlusion ? +renderer.transparentOcclusion : 1;
12731
- texParams.y = +this.preMultiAlpha;
12827
+ texParams.y = preMultiAlpha;
12732
12828
  texParams.z = renderer.renderMode;
12733
12829
  texParams.w = renderer.maskMode;
12734
12830
  material.setVector4("_TexParams", texParams);
@@ -12754,8 +12850,11 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12754
12850
  };
12755
12851
  _proto.fromData = function fromData(data) {
12756
12852
  RendererComponent.prototype.fromData.call(this, data);
12757
- var _data_renderer;
12758
- var renderer = (_data_renderer = data.renderer) != null ? _data_renderer : {};
12853
+ var baseRenderComponentData = data;
12854
+ var _baseRenderComponentData_renderer;
12855
+ var renderer = (_baseRenderComponentData_renderer = baseRenderComponentData.renderer) != null ? _baseRenderComponentData_renderer : {};
12856
+ var splits = baseRenderComponentData.splits;
12857
+ var textureSheetAnimation = baseRenderComponentData.textureSheetAnimation;
12759
12858
  var maskProps = data.mask;
12760
12859
  if (maskProps && maskProps.ref) {
12761
12860
  maskProps.ref = this.engine.findObject(maskProps.ref);
@@ -12764,14 +12863,15 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12764
12863
  // TODO 新蒙板上线后移除
12765
12864
  //-------------------------------------------------------------------------
12766
12865
  var shapeData = renderer.shape;
12767
- //@ts-expect-error
12768
- var split = data.splits && !data.textureSheetAnimation ? data.splits[0] : undefined;
12866
+ var split = splits && !textureSheetAnimation ? splits[0] : undefined;
12769
12867
  var shapeGeometry = undefined;
12770
12868
  if (shapeData !== undefined && shapeData !== null && !("aPoint" in shapeData && "index" in shapeData)) {
12771
12869
  shapeGeometry = getGeometryByShape(shapeData, split);
12772
12870
  }
12773
- var _renderer_renderMode, _renderer_blending, _renderer_side, _renderer_alphaMask;
12774
12871
  //-------------------------------------------------------------------------
12872
+ this.splits = splits || singleSplits;
12873
+ this.textureSheetAnimation = textureSheetAnimation;
12874
+ var _renderer_renderMode, _renderer_blending, _renderer_side, _renderer_alphaMask;
12775
12875
  this.renderer = {
12776
12876
  renderMode: (_renderer_renderMode = renderer.renderMode) != null ? _renderer_renderMode : RenderMode.MESH,
12777
12877
  blending: (_renderer_blending = renderer.blending) != null ? _renderer_blending : BlendingMode.ALPHA,
@@ -12786,7 +12886,31 @@ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
12786
12886
  alphaMask: (_renderer_alphaMask = renderer.alphaMask) != null ? _renderer_alphaMask : false
12787
12887
  };
12788
12888
  this.configureMaterial(this.renderer);
12889
+ if (baseRenderComponentData.geometry) {
12890
+ this.geometry = this.engine.findObject(baseRenderComponentData.geometry);
12891
+ } else {
12892
+ this.geometry = this.defaultGeometry;
12893
+ this.configureDefaultGeometry(this.renderer);
12894
+ }
12789
12895
  };
12896
+ _create_class(BaseRenderComponent, [
12897
+ {
12898
+ key: "color",
12899
+ get: /**
12900
+ * 获取当前图层的颜色
12901
+ * @since 2.5.0
12902
+ */ function get() {
12903
+ return this._color;
12904
+ },
12905
+ set: /**
12906
+ * 设置当前图层的颜色
12907
+ * @since 2.5.0
12908
+ */ function set(value) {
12909
+ this._color = value;
12910
+ this.material.setColor("_Color", this._color);
12911
+ }
12912
+ }
12913
+ ]);
12790
12914
  return BaseRenderComponent;
12791
12915
  }(RendererComponent);
12792
12916
 
@@ -12801,37 +12925,8 @@ exports.ShapeComponent = /*#__PURE__*/ function(BaseRenderComponent) {
12801
12925
  _this.graphicsPath = new GraphicsPath();
12802
12926
  _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";
12803
12927
  _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";
12804
- // Create Geometry
12928
+ // Add Geometry SubMesh
12805
12929
  //-------------------------------------------------------------------------
12806
- _this.geometry = Geometry.create(engine, {
12807
- attributes: {
12808
- aPos: {
12809
- type: glContext.FLOAT,
12810
- size: 3,
12811
- data: new Float32Array([
12812
- -0.5,
12813
- 0.5,
12814
- 0,
12815
- -0.5,
12816
- -0.5,
12817
- 0,
12818
- 0.5,
12819
- 0.5,
12820
- 0,
12821
- 0.5,
12822
- -0.5,
12823
- 0
12824
- ])
12825
- },
12826
- aUV: {
12827
- type: glContext.FLOAT,
12828
- size: 2,
12829
- data: new Float32Array()
12830
- }
12831
- },
12832
- mode: glContext.TRIANGLES,
12833
- drawCount: 4
12834
- });
12835
12930
  _this.geometry.subMeshes.push({
12836
12931
  offset: 0,
12837
12932
  indexCount: 0,
@@ -20161,7 +20256,7 @@ var RuntimeClip = /*#__PURE__*/ function() {
20161
20256
  this.playable.play();
20162
20257
  }
20163
20258
  this.parentMixer.setClipWeight(this.playable, weight);
20164
- var clipTime = clip.toLocalTime(localTime);
20259
+ var clipTime = parseFloat(clip.toLocalTime(localTime).toFixed(3));
20165
20260
  this.playable.setTime(clipTime);
20166
20261
  // 判断动画是否结束
20167
20262
  if (ended) {
@@ -21350,12 +21445,11 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21350
21445
  * 前进合成到指定时间
21351
21446
  * @param time - 相对0时刻的时间
21352
21447
  */ _proto.forwardTime = function forwardTime(time) {
21353
- var deltaTime = time * 1000 - this.time * 1000;
21448
+ var deltaTime = time * 1000 - this.rootComposition.time * 1000;
21354
21449
  var reverse = deltaTime < 0;
21355
21450
  var step = 15;
21356
21451
  var t = Math.abs(deltaTime);
21357
21452
  var ss = reverse ? -step : step;
21358
- // FIXME Update 中可能会修改合成时间,这边需要优化更新逻辑
21359
21453
  for(t; t > step; t -= step){
21360
21454
  this.update(ss);
21361
21455
  }
@@ -21395,14 +21489,13 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21395
21489
  this.callAwake(this.rootItem);
21396
21490
  this.rootItem.beginPlay();
21397
21491
  }
21398
- var previousCompositionTime = this.time;
21399
- this.updateCompositionTime(deltaTime * this.speed / 1000);
21400
- var deltaTimeInMs = (this.time - previousCompositionTime) * 1000;
21492
+ var dt = parseFloat(this.getUpdateTime(deltaTime * this.speed).toFixed(0));
21493
+ this.updateRootComposition(dt / 1000);
21401
21494
  this.updateVideo();
21402
21495
  // 更新 model-tree-plugin
21403
- this.updatePluginLoaders(deltaTimeInMs);
21404
- this.sceneTicking.update.tick(deltaTimeInMs);
21405
- this.sceneTicking.lateUpdate.tick(deltaTimeInMs);
21496
+ this.updatePluginLoaders(deltaTime);
21497
+ this.sceneTicking.update.tick(dt);
21498
+ this.sceneTicking.lateUpdate.tick(dt);
21406
21499
  this.updateCamera();
21407
21500
  this.prepareRender();
21408
21501
  if (this.isEnded && !this.isEndCalled) {
@@ -21418,6 +21511,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21418
21511
  _proto.shouldDispose = function shouldDispose() {
21419
21512
  return this.isEnded && this.rootItem.endBehavior === EndBehavior.destroy && !this.reusable;
21420
21513
  };
21514
+ _proto.getUpdateTime = function getUpdateTime(t) {
21515
+ var startTimeInMs = this.startTime * 1000;
21516
+ var now = this.rootComposition.time * 1000;
21517
+ if (t < 0 && now + t < startTimeInMs) {
21518
+ return startTimeInMs - now;
21519
+ }
21520
+ return t;
21521
+ };
21421
21522
  _proto.callAwake = function callAwake(item) {
21422
21523
  for(var _iterator = _create_for_of_iterator_helper_loose(item.components), _step; !(_step = _iterator()).done;){
21423
21524
  var component = _step.value;
@@ -21462,18 +21563,14 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21462
21563
  };
21463
21564
  /**
21464
21565
  * 更新主合成组件
21465
- */ _proto.updateCompositionTime = function updateCompositionTime(deltaTime) {
21566
+ */ _proto.updateRootComposition = function updateRootComposition(deltaTime) {
21466
21567
  if (this.rootComposition.state === PlayState.Paused || !this.rootComposition.isActiveAndEnabled) {
21467
21568
  return;
21468
21569
  }
21469
- // 相对于合成开始时间的时间
21470
- var localTime = this.time + deltaTime - this.startTime;
21471
- if (deltaTime < 0 && localTime < 0) {
21472
- localTime = 0;
21473
- }
21570
+ var localTime = parseFloat((this.time + deltaTime - this.rootItem.start).toFixed(3));
21571
+ var isEnded = false;
21474
21572
  var duration = this.rootItem.duration;
21475
21573
  var endBehavior = this.rootItem.endBehavior;
21476
- var isEnded = false;
21477
21574
  if (localTime - duration > 0.001) {
21478
21575
  isEnded = true;
21479
21576
  switch(endBehavior){
@@ -21498,7 +21595,7 @@ var LateUpdateTickData = /*#__PURE__*/ function(TickData) {
21498
21595
  }
21499
21596
  }
21500
21597
  }
21501
- this.rootComposition.time = localTime + this.startTime;
21598
+ this.rootComposition.time = localTime;
21502
21599
  // end state changed, handle onEnd flags
21503
21600
  if (this.isEnded !== isEnded) {
21504
21601
  if (isEnded) {
@@ -22654,15 +22751,6 @@ var ColorPlayable = /*#__PURE__*/ function(Playable) {
22654
22751
  return ColorPlayable;
22655
22752
  }(Playable);
22656
22753
 
22657
- var singleSplits = [
22658
- [
22659
- 0,
22660
- 0,
22661
- 1,
22662
- 1,
22663
- undefined
22664
- ]
22665
- ];
22666
22754
  var seed$3 = 0;
22667
22755
  exports.SpriteColorPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
22668
22756
  _inherits(SpriteColorPlayableAsset, PlayableAsset);
@@ -22688,10 +22776,8 @@ exports.SpriteComponent = /*#__PURE__*/ function(BaseRenderComponent) {
22688
22776
  function SpriteComponent(engine, props) {
22689
22777
  var _this;
22690
22778
  _this = BaseRenderComponent.call(this, engine) || this;
22691
- _this.splits = singleSplits;
22692
22779
  _this.frameAnimationLoop = false;
22693
22780
  _this.name = "MSprite" + seed$3++;
22694
- _this.geometry = _this.createGeometry();
22695
22781
  if (props) {
22696
22782
  _this.fromData(props);
22697
22783
  }
@@ -22781,111 +22867,10 @@ exports.SpriteComponent = /*#__PURE__*/ function(BaseRenderComponent) {
22781
22867
  source.video.load();
22782
22868
  }
22783
22869
  };
22784
- _proto.getItemGeometryData = function getItemGeometryData(geometry) {
22785
- var _this = this, splits = _this.splits, textureSheetAnimation = _this.textureSheetAnimation;
22786
- var sx = 1, sy = 1;
22787
- var renderer = this.renderer;
22788
- if (renderer.shape) {
22789
- 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;
22790
- var point = new Float32Array(aPoint);
22791
- var position = [];
22792
- var atlasOffset = [];
22793
- for(var i = 0; i < point.length; i += 6){
22794
- point[i] *= sx;
22795
- point[i + 1] *= sy;
22796
- atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
22797
- position.push(point[i], point[i + 1], 0.0);
22798
- }
22799
- geometry.setAttributeData("aPos", new Float32Array(position));
22800
- return {
22801
- index: index,
22802
- atlasOffset: atlasOffset
22803
- };
22804
- }
22805
- var originData = [
22806
- -.5,
22807
- .5,
22808
- -.5,
22809
- -.5,
22810
- .5,
22811
- .5,
22812
- .5,
22813
- -.5
22814
- ];
22815
- var atlasOffset1 = [];
22816
- var index1 = [];
22817
- var col = 2;
22818
- var row = 2;
22819
- if (splits.length === 1) {
22820
- col = 1;
22821
- row = 1;
22822
- }
22823
- var position1 = [];
22824
- for(var x = 0; x < col; x++){
22825
- for(var y = 0; y < row; y++){
22826
- var base = (y * 2 + x) * 4;
22827
- // @ts-expect-error
22828
- var split = textureSheetAnimation ? [
22829
- 0,
22830
- 0,
22831
- 1,
22832
- 1,
22833
- splits[0][4]
22834
- ] : splits[y * 2 + x];
22835
- var texOffset = split[4] ? [
22836
- 0,
22837
- 0,
22838
- 1,
22839
- 0,
22840
- 0,
22841
- 1,
22842
- 1,
22843
- 1
22844
- ] : [
22845
- 0,
22846
- 1,
22847
- 0,
22848
- 0,
22849
- 1,
22850
- 1,
22851
- 1,
22852
- 0
22853
- ];
22854
- var dw = ((x + x + 1) / col - 1) / 2;
22855
- var dh = ((y + y + 1) / row - 1) / 2;
22856
- var tox = split[0];
22857
- var toy = split[1];
22858
- var tsx = split[4] ? split[3] : split[2];
22859
- var tsy = split[4] ? split[2] : split[3];
22860
- var origin = [
22861
- originData[0] / col + dw,
22862
- originData[1] / row + dh,
22863
- originData[2] / col + dw,
22864
- originData[3] / row + dh,
22865
- originData[4] / col + dw,
22866
- originData[5] / row + dh,
22867
- originData[6] / col + dw,
22868
- originData[7] / row + dh
22869
- ];
22870
- 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);
22871
- 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);
22872
- index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
22873
- }
22874
- }
22875
- geometry.setAttributeData("aPos", new Float32Array(position1));
22876
- return {
22877
- index: index1,
22878
- atlasOffset: atlasOffset1
22879
- };
22880
- };
22881
22870
  _proto.fromData = function fromData(data) {
22882
22871
  BaseRenderComponent.prototype.fromData.call(this, data);
22883
22872
  var interaction = data.interaction, options = data.options;
22884
22873
  this.interaction = interaction;
22885
- this.splits = data.splits || singleSplits;
22886
- this.textureSheetAnimation = data.textureSheetAnimation;
22887
- var geometry = this.createGeometry();
22888
- this.geometry = geometry;
22889
22874
  var startColor = options.startColor || [
22890
22875
  1,
22891
22876
  1,
@@ -26164,7 +26149,6 @@ exports.TextComponent = /*#__PURE__*/ function(BaseRenderComponent) {
26164
26149
  _this.SCALE_FACTOR = 0.1;
26165
26150
  _this.ALPHA_FIX_VALUE = 1 / 255;
26166
26151
  _this.name = "MText" + seed$2++;
26167
- _this.geometry = _this.createGeometry();
26168
26152
  if (props) {
26169
26153
  _this.fromData(props);
26170
26154
  }
@@ -27045,11 +27029,6 @@ function colorToArr(hex, normalized) {
27045
27029
  parseInt(m[2], 16),
27046
27030
  parseInt(m[3], 16),
27047
27031
  255
27048
- ] || [
27049
- 0,
27050
- 0,
27051
- 0,
27052
- 255
27053
27032
  ];
27054
27033
  }
27055
27034
  } else if (_instanceof1(hex, Array)) {
@@ -31648,7 +31627,7 @@ registerPlugin("sprite", SpriteLoader, exports.VFXItem);
31648
31627
  registerPlugin("particle", ParticleLoader, exports.VFXItem);
31649
31628
  registerPlugin("cal", CalculateLoader, exports.VFXItem);
31650
31629
  registerPlugin("interact", InteractLoader, exports.VFXItem);
31651
- var version$1 = "2.4.8";
31630
+ var version$1 = "2.5.0-alpha.0";
31652
31631
  logger.info("Core version: " + version$1 + ".");
31653
31632
 
31654
31633
  var _obj;
@@ -33250,7 +33229,7 @@ setMaxSpriteMeshItemCount(8);
33250
33229
  */ Mesh.create = function(engine, props) {
33251
33230
  return new ThreeMesh(engine, props);
33252
33231
  };
33253
- var version = "2.4.8";
33232
+ var version = "2.5.0-alpha.0";
33254
33233
  logger.info("THREEJS plugin version: " + version + ".");
33255
33234
 
33256
33235
  exports.AbstractPlugin = AbstractPlugin;