@galacean/effects-threejs 2.0.0-alpha.11 → 2.0.0-alpha.12

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.0-alpha.11
6
+ * Version: v2.0.0-alpha.12
7
7
  */
8
8
 
9
9
  import * as THREE from 'three';
@@ -3935,6 +3935,17 @@ Euler.tempMat0 = new Matrix4();
3935
3935
  * 水平右侧 垂直底部
3936
3936
  */ ParticleOrigin[ParticleOrigin["PARTICLE_ORIGIN_RIGHT_BOTTOM"] = 8] = "PARTICLE_ORIGIN_RIGHT_BOTTOM";
3937
3937
  })(ParticleOrigin || (ParticleOrigin = {}));
3938
+ var RenderType;
3939
+ (function(RenderType) {
3940
+ RenderType["Opaque"] = "Opaque";
3941
+ RenderType["Transparent"] = "Transparent";
3942
+ })(RenderType || (RenderType = {}));
3943
+ var RenderFace;
3944
+ (function(RenderFace) {
3945
+ RenderFace["Both"] = "Both";
3946
+ RenderFace["Back"] = "Back";
3947
+ RenderFace["Front"] = "Front";
3948
+ })(RenderFace || (RenderFace = {}));
3938
3949
 
3939
3950
  var END_BEHAVIOR_DESTROY = 0;
3940
3951
  var END_BEHAVIOR_PAUSE = 1;
@@ -4254,6 +4265,7 @@ var DataType;
4254
4265
  DataType["CameraController"] = "CameraController";
4255
4266
  DataType["Geometry"] = "Geometry";
4256
4267
  DataType["Texture"] = "Texture";
4268
+ DataType["AnimationClip"] = "AnimationClip";
4257
4269
  DataType["TextComponent"] = "TextComponent";
4258
4270
  // FIXME: 先完成ECS的场景转换,后面移到spec中
4259
4271
  DataType["MeshComponent"] = "MeshComponent";
@@ -4287,6 +4299,60 @@ var GeometryType;
4287
4299
  * Draw a connected group of triangles. Each vertex connects to the previous and the first vertex in the fan.
4288
4300
  */ GeometryType[GeometryType["TRIANGLE_FAN"] = 6] = "TRIANGLE_FAN";
4289
4301
  })(GeometryType || (GeometryType = {}));
4302
+ var VertexFormatType;
4303
+ (function(VertexFormatType) {
4304
+ VertexFormatType[VertexFormatType["Float32"] = 0] = "Float32";
4305
+ VertexFormatType[VertexFormatType["Int16"] = 1] = "Int16";
4306
+ VertexFormatType[VertexFormatType["Int8"] = 2] = "Int8";
4307
+ VertexFormatType[VertexFormatType["UInt16"] = 3] = "UInt16";
4308
+ VertexFormatType[VertexFormatType["UInt8"] = 4] = "UInt8";
4309
+ })(VertexFormatType || (VertexFormatType = {}));
4310
+ var IndexFormatType;
4311
+ (function(IndexFormatType) {
4312
+ IndexFormatType[IndexFormatType["UInt16"] = 0] = "UInt16";
4313
+ IndexFormatType[IndexFormatType["UInt32"] = 1] = "UInt32";
4314
+ })(IndexFormatType || (IndexFormatType = {}));
4315
+ // BINORMAL[n] Binormal float4
4316
+ // BLENDINDICES[n] 混合索引 uint
4317
+ // BLENDWEIGHT[n] 混合权重 FLOAT
4318
+ // COLOR[n] 漫射和反射颜色 float4
4319
+ // NORMAL[n] 法向矢量 float4
4320
+ // POSITION[n] 对象空间中的顶点位置。 float4
4321
+ // POSITIONT 变换的顶点位置。 float4
4322
+ // PSIZE[n] 点大小 FLOAT
4323
+ // TANGENT[n] 正切 float4
4324
+ // TEXCOORD[n] 纹理坐标 float4
4325
+ // POSITION_BS[n] Blend Shape 空间中的顶点位置 float4
4326
+ // NORMAL_BS[n] Blend Shape 空间中的法向矢量 float4
4327
+ // TANGENT_BS[n] Blend Shape 空间中的正切矢量 float4
4328
+ var VertexBufferSemantic;
4329
+ (function(VertexBufferSemantic) {
4330
+ VertexBufferSemantic["Position"] = "POSITION";
4331
+ VertexBufferSemantic["Uv"] = "TEXCOORD0";
4332
+ VertexBufferSemantic["Uv2"] = "TEXCOORD1";
4333
+ VertexBufferSemantic["Normal"] = "NORMAL";
4334
+ VertexBufferSemantic["Tangent"] = "TANGENT";
4335
+ VertexBufferSemantic["Color"] = "COLOR";
4336
+ VertexBufferSemantic["Joints"] = "JOINTS";
4337
+ VertexBufferSemantic["Weights"] = "WEIGHTS";
4338
+ //
4339
+ VertexBufferSemantic["PositionBS0"] = "POSITION_BS0";
4340
+ VertexBufferSemantic["PositionBS1"] = "POSITION_BS1";
4341
+ VertexBufferSemantic["PositionBS2"] = "POSITION_BS2";
4342
+ VertexBufferSemantic["PositionBS3"] = "POSITION_BS3";
4343
+ VertexBufferSemantic["PositionBS4"] = "POSITION_BS4";
4344
+ VertexBufferSemantic["PositionBS5"] = "POSITION_BS5";
4345
+ VertexBufferSemantic["PositionBS6"] = "POSITION_BS6";
4346
+ VertexBufferSemantic["PositionBS7"] = "POSITION_BS7";
4347
+ VertexBufferSemantic["NormalBS0"] = "NORMAL_BS0";
4348
+ VertexBufferSemantic["NormalBS1"] = "NORMAL_BS1";
4349
+ VertexBufferSemantic["NormalBS2"] = "NORMAL_BS2";
4350
+ VertexBufferSemantic["NormalBS3"] = "NORMAL_BS3";
4351
+ VertexBufferSemantic["TangentBS0"] = "TANGENT_BS0";
4352
+ VertexBufferSemantic["TangentBS1"] = "TANGENT_BS1";
4353
+ VertexBufferSemantic["TangentBS2"] = "TANGENT_BS2";
4354
+ VertexBufferSemantic["TangentBS3"] = "TANGENT_BS3";
4355
+ })(VertexBufferSemantic || (VertexBufferSemantic = {}));
4290
4356
 
4291
4357
  var BuiltinObjectGUID = function BuiltinObjectGUID() {
4292
4358
  };
@@ -4307,6 +4373,8 @@ var index$1 = /*#__PURE__*/Object.freeze({
4307
4373
  get ItemType () { return ItemType; },
4308
4374
  get RenderMode () { return RenderMode; },
4309
4375
  get ParticleOrigin () { return ParticleOrigin; },
4376
+ get RenderType () { return RenderType; },
4377
+ get RenderFace () { return RenderFace; },
4310
4378
  get CameraClipMode () { return CameraClipMode; },
4311
4379
  get CompositionEndBehavior () { return CompositionEndBehavior; },
4312
4380
  get BackgroundType () { return BackgroundType; },
@@ -4340,6 +4408,9 @@ var index$1 = /*#__PURE__*/Object.freeze({
4340
4408
  get FontStyle () { return FontStyle; },
4341
4409
  get DataType () { return DataType; },
4342
4410
  get GeometryType () { return GeometryType; },
4411
+ get VertexFormatType () { return VertexFormatType; },
4412
+ get IndexFormatType () { return IndexFormatType; },
4413
+ get VertexBufferSemantic () { return VertexBufferSemantic; },
4343
4414
  BuiltinObjectGUID: BuiltinObjectGUID
4344
4415
  });
4345
4416
 
@@ -7735,6 +7806,10 @@ function buildEasingCurve(leftKeyframe, rightKeyframe) {
7735
7806
  }
7736
7807
  }
7737
7808
 
7809
+ var CURVE_PRO_TIME = 0;
7810
+ var CURVE_PRO_VALUE = 1;
7811
+ var CURVE_PRO_IN_TANGENT = 2;
7812
+ var CURVE_PRO_OUT_TANGENT = 3;
7738
7813
  var NOT_IMPLEMENT = "not_implement";
7739
7814
  var ValueGetter = /*#__PURE__*/ function() {
7740
7815
  function ValueGetter(arg) {
@@ -8204,6 +8279,54 @@ var BezierCurve = /*#__PURE__*/ function(ValueGetter) {
8204
8279
  };
8205
8280
  return BezierCurve;
8206
8281
  }(ValueGetter);
8282
+ var PathSegments = /*#__PURE__*/ function(ValueGetter) {
8283
+ _inherits(PathSegments, ValueGetter);
8284
+ function PathSegments() {
8285
+ return ValueGetter.apply(this, arguments);
8286
+ }
8287
+ var _proto = PathSegments.prototype;
8288
+ _proto.onCreate = function onCreate(props) {
8289
+ this.keys = props[0];
8290
+ this.values = props[1];
8291
+ };
8292
+ _proto.getValue = function getValue(time) {
8293
+ var keys = this.keys;
8294
+ var values = this.values;
8295
+ for(var i = 0; i < keys.length - 1; i++){
8296
+ var k0 = keys[i];
8297
+ var k1 = keys[i + 1];
8298
+ if (k0[0] <= time && k1[0] >= time) {
8299
+ var dis = k1[1] - k0[1];
8300
+ var dt = void 0;
8301
+ if (dis === 0) {
8302
+ dt = (time - k0[0]) / (k1[0] - k0[0]);
8303
+ } else {
8304
+ var val = curveValueEvaluate(time, k0, k1);
8305
+ dt = (val - k0[1]) / dis;
8306
+ }
8307
+ return this.calculateVec(i, dt);
8308
+ }
8309
+ }
8310
+ if (time <= keys[0][0]) {
8311
+ return values[0].slice();
8312
+ }
8313
+ return values[values.length - 1].slice();
8314
+ };
8315
+ _proto.calculateVec = function calculateVec(i, dt) {
8316
+ var vec0 = this.values[i];
8317
+ var vec1 = this.values[i + 1];
8318
+ var ret = [
8319
+ 0,
8320
+ 0,
8321
+ 0
8322
+ ];
8323
+ for(var j = 0; j < vec0.length; j++){
8324
+ ret[j] = vec0[j] * (1 - dt) + vec1[j] * dt;
8325
+ }
8326
+ return ret;
8327
+ };
8328
+ return PathSegments;
8329
+ }(ValueGetter);
8207
8330
  var BezierCurvePath = /*#__PURE__*/ function(ValueGetter) {
8208
8331
  _inherits(BezierCurvePath, ValueGetter);
8209
8332
  function BezierCurvePath() {
@@ -8304,10 +8427,9 @@ var map$1 = (_obj$6 = {}, _obj$6[ValueType.RANDOM] = function(props) {
8304
8427
  return new LineSegments(props);
8305
8428
  }, _obj$6[ValueType.GRADIENT_COLOR] = function(props) {
8306
8429
  return new GradientValue(props);
8307
- }, // [spec.ValueType.LINEAR_PATH] (pros: number[][][]) {
8308
- // return new PathSegments(pros);
8309
- // },
8310
- _obj$6[ValueType.BEZIER_CURVE] = function(props) {
8430
+ }, _obj$6[ValueType.LINEAR_PATH] = function(pros) {
8431
+ return new PathSegments(pros);
8432
+ }, _obj$6[ValueType.BEZIER_CURVE] = function(props) {
8311
8433
  if (props.length === 1) {
8312
8434
  return new StaticValue(props[0][1][1]);
8313
8435
  }
@@ -8342,6 +8464,20 @@ function lineSegIntegrateByTime(t, t0, t1, y0, y1) {
8342
8464
  var t03 = t02 * t0;
8343
8465
  return (2 * t3 * (y0 - y1) + 3 * t2 * (t0 * y1 - t1 * y0) - t03 * (2 * y0 + y1) + 3 * t02 * t1 * y0) / (6 * (t0 - t1));
8344
8466
  }
8467
+ function curveValueEvaluate(time, keyframe0, keyframe1) {
8468
+ var dt = keyframe1[CURVE_PRO_TIME] - keyframe0[CURVE_PRO_TIME];
8469
+ var m0 = keyframe0[CURVE_PRO_OUT_TANGENT] * dt;
8470
+ var m1 = keyframe1[CURVE_PRO_IN_TANGENT] * dt;
8471
+ var t = (time - keyframe0[CURVE_PRO_TIME]) / dt;
8472
+ var t2 = t * t;
8473
+ var t3 = t2 * t;
8474
+ var a = 2 * t3 - 3 * t2 + 1;
8475
+ var b = t3 - 2 * t2 + t;
8476
+ var c = t3 - t2;
8477
+ var d = -2 * t3 + 3 * t2;
8478
+ //(2*v0+m0+m1-2*v1)*(t-t0)^3/k^3+(3*v1-3*v0-2*m0-m1)*(t-t0)^2/k^2+m0 *(t-t0)/k+v0
8479
+ return a * keyframe0[CURVE_PRO_VALUE] + b * m0 + c * m1 + d * keyframe1[CURVE_PRO_VALUE];
8480
+ }
8345
8481
  function getKeyFrameMetaByRawValue(meta, value) {
8346
8482
  if (value) {
8347
8483
  var type = value[0];
@@ -9267,6 +9403,38 @@ function copy(target) {
9267
9403
  }
9268
9404
  }
9269
9405
  }
9406
+ function vertexFormatType2GLType(formatType) {
9407
+ switch(formatType){
9408
+ case VertexFormatType.Float32:
9409
+ return WebGLRenderingContext["FLOAT"];
9410
+ case VertexFormatType.Int16:
9411
+ return WebGLRenderingContext["SHORT"];
9412
+ case VertexFormatType.Int8:
9413
+ return WebGLRenderingContext["BYTE"];
9414
+ case VertexFormatType.UInt16:
9415
+ return WebGLRenderingContext["UNSIGNED_SHORT"];
9416
+ case VertexFormatType.UInt8:
9417
+ return WebGLRenderingContext["UNSIGNED_BYTE"];
9418
+ default:
9419
+ return WebGLRenderingContext["FLOAT"];
9420
+ }
9421
+ }
9422
+ function glType2VertexFormatType(webglType) {
9423
+ switch(webglType){
9424
+ case WebGLRenderingContext["FLOAT"]:
9425
+ return VertexFormatType.Float32;
9426
+ case WebGLRenderingContext["SHORT"]:
9427
+ return VertexFormatType.Int16;
9428
+ case WebGLRenderingContext["BYTE"]:
9429
+ return VertexFormatType.Int8;
9430
+ case WebGLRenderingContext["UNSIGNED_SHORT"]:
9431
+ return VertexFormatType.UInt16;
9432
+ case WebGLRenderingContext["UNSIGNED_BYTE"]:
9433
+ return VertexFormatType.UInt8;
9434
+ default:
9435
+ return VertexFormatType.Float32;
9436
+ }
9437
+ }
9270
9438
 
9271
9439
  var ShaderType;
9272
9440
  (function(ShaderType) {
@@ -10108,6 +10276,29 @@ function generateHalfFloatTexture(engine, data, width, height) {
10108
10276
  wrapT: glContext.CLAMP_TO_EDGE
10109
10277
  });
10110
10278
  }
10279
+ function generateWhiteTexture(engine) {
10280
+ return Texture.create(engine, {
10281
+ id: "whitetexture00000000000000000000",
10282
+ data: {
10283
+ width: 1,
10284
+ height: 1,
10285
+ data: new Uint8Array([
10286
+ 255,
10287
+ 255,
10288
+ 255,
10289
+ 255
10290
+ ])
10291
+ },
10292
+ sourceType: TextureSourceType.data,
10293
+ type: glContext.UNSIGNED_BYTE,
10294
+ format: glContext.RGBA,
10295
+ internalFormat: glContext.RGBA,
10296
+ wrapS: glContext.MIRRORED_REPEAT,
10297
+ wrapT: glContext.MIRRORED_REPEAT,
10298
+ minFilter: glContext.NEAREST,
10299
+ magFilter: glContext.NEAREST
10300
+ });
10301
+ }
10111
10302
 
10112
10303
  var HEADER_LEN = 12 + 13 * 4; // identifier + header elements (not including key value meta-data pairs)
10113
10304
  var COMPRESSED_2D = 0; // uses a gl.compressedTexImage2D()
@@ -11281,8 +11472,8 @@ var seed$6 = 1;
11281
11472
  /**
11282
11473
  * 配置当前pass的RT,在每帧渲染前调用
11283
11474
  */ _proto.configure = function configure(renderer) {
11284
- if (this.frameBuffer) {
11285
- renderer.setFrameBuffer(this.frameBuffer);
11475
+ if (this.framebuffer) {
11476
+ renderer.setFramebuffer(this.framebuffer);
11286
11477
  } else {
11287
11478
  var _this_getViewport = this.getViewport(), x = _this_getViewport[0], y = _this_getViewport[1], width = _this_getViewport[2], height = _this_getViewport[3];
11288
11479
  renderer.setViewport(x, y, width, height);
@@ -11329,9 +11520,9 @@ var seed$6 = 1;
11329
11520
  return !att.externalTexture && att.dispose();
11330
11521
  });
11331
11522
  this.attachments = attachments;
11332
- if (this.frameBuffer) {
11333
- this.frameBuffer.bind();
11334
- this.frameBuffer.resetColorTextures(colors.map(function(color) {
11523
+ if (this.framebuffer) {
11524
+ this.framebuffer.bind();
11525
+ this.framebuffer.resetColorTextures(colors.map(function(color) {
11335
11526
  return color;
11336
11527
  }));
11337
11528
  }
@@ -11352,18 +11543,18 @@ var seed$6 = 1;
11352
11543
  this.isCustomViewport = true;
11353
11544
  this.viewportScale = 1;
11354
11545
  this.customViewport = options.viewport.slice(0, 4);
11355
- if (this.frameBuffer) {
11546
+ if (this.framebuffer) {
11356
11547
  var vp = this.customViewport;
11357
11548
  // TODO 为什么framebuffer和renderpass的isCustomViewport不一样?
11358
- this.frameBuffer.isCustomViewport = false;
11359
- this.frameBuffer.resize(vp[0], vp[1], vp[2], vp[3]);
11549
+ this.framebuffer.isCustomViewport = false;
11550
+ this.framebuffer.resize(vp[0], vp[1], vp[2], vp[3]);
11360
11551
  }
11361
11552
  } else {
11362
11553
  this.isCustomViewport = false;
11363
11554
  this.viewportScale = options.viewportScale || 1;
11364
- if (this.frameBuffer) {
11365
- this.frameBuffer.isCustomViewport = true;
11366
- this.frameBuffer.viewportScale = this.viewportScale;
11555
+ if (this.framebuffer) {
11556
+ this.framebuffer.isCustomViewport = true;
11557
+ this.framebuffer.viewportScale = this.viewportScale;
11367
11558
  }
11368
11559
  }
11369
11560
  };
@@ -11373,16 +11564,15 @@ var seed$6 = 1;
11373
11564
  var renderer = this.renderer;
11374
11565
  var options = this.options;
11375
11566
  if (this.attachments.length) {
11376
- var _this_frameBuffer;
11567
+ var _this_framebuffer;
11377
11568
  this.attachments.forEach(function(att) {
11378
11569
  return !att.externalTexture && att.dispose();
11379
11570
  });
11380
11571
  this.attachments.length = 0;
11381
- (_this_frameBuffer = this.frameBuffer) == null ? void 0 : _this_frameBuffer.dispose({
11572
+ (_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.dispose({
11382
11573
  depthStencilAttachment: 2
11383
11574
  });
11384
- // @ts-expect-error safe to assign
11385
- this.frameBuffer = null;
11575
+ this.framebuffer = null;
11386
11576
  }
11387
11577
  var vs = this.viewportScale;
11388
11578
  // renderpass 的 viewport 相关参数都需要动态的修改
@@ -11407,7 +11597,7 @@ var seed$6 = 1;
11407
11597
  return attachment;
11408
11598
  });
11409
11599
  this.attachments = attachments;
11410
- var framebuffer = FrameBuffer.create({
11600
+ var framebuffer = Framebuffer.create({
11411
11601
  storeAction: this.storeAction,
11412
11602
  name: name,
11413
11603
  viewport: viewport,
@@ -11422,7 +11612,7 @@ var seed$6 = 1;
11422
11612
  }, renderer);
11423
11613
  framebuffer.bind();
11424
11614
  framebuffer.unbind();
11425
- this.frameBuffer = framebuffer;
11615
+ this.framebuffer = framebuffer;
11426
11616
  } else {
11427
11617
  this.attachments.length = 0;
11428
11618
  }
@@ -11430,8 +11620,8 @@ var seed$6 = 1;
11430
11620
  /**
11431
11621
  * 获取当前视口大小,格式:[x偏移,y偏移,宽度,高度]
11432
11622
  */ _proto.getViewport = function getViewport() {
11433
- var _this_frameBuffer;
11434
- var ret = ((_this_frameBuffer = this.frameBuffer) == null ? void 0 : _this_frameBuffer.viewport) || this.customViewport;
11623
+ var _this_framebuffer;
11624
+ var ret = ((_this_framebuffer = this.framebuffer) == null ? void 0 : _this_framebuffer.viewport) || this.customViewport;
11435
11625
  if (ret) {
11436
11626
  return ret;
11437
11627
  }
@@ -11452,24 +11642,24 @@ var seed$6 = 1;
11452
11642
  /**
11453
11643
  * 获取深度 Attachment,可能没有
11454
11644
  */ _proto.getDepthAttachment = function getDepthAttachment() {
11455
- var frameBuffer = this.frameBuffer;
11456
- if (frameBuffer) {
11645
+ var framebuffer = this.framebuffer;
11646
+ if (framebuffer) {
11457
11647
  return {
11458
- storageType: frameBuffer.depthStencilStorageType,
11459
- storage: frameBuffer.depthStorage,
11460
- texture: frameBuffer.getDepthTexture() ? this.getDepthTexture(frameBuffer.getDepthTexture(), frameBuffer.externalStorage) : undefined
11648
+ storageType: framebuffer.depthStencilStorageType,
11649
+ storage: framebuffer.depthStorage,
11650
+ texture: framebuffer.getDepthTexture() ? this.getDepthTexture(framebuffer.getDepthTexture(), framebuffer.externalStorage) : undefined
11461
11651
  };
11462
11652
  }
11463
11653
  };
11464
11654
  /**
11465
11655
  * 获取蒙版 Attachment,可能没有
11466
11656
  */ _proto.getStencilAttachment = function getStencilAttachment() {
11467
- var frameBuffer = this.frameBuffer;
11468
- if (frameBuffer) {
11657
+ var framebuffer = this.framebuffer;
11658
+ if (framebuffer) {
11469
11659
  return {
11470
- storageType: frameBuffer.depthStencilStorageType,
11471
- storage: frameBuffer.stencilStorage,
11472
- texture: frameBuffer.getStencilTexture() ? this.getStencilTexture(frameBuffer.getStencilTexture(), frameBuffer.externalStorage) : undefined
11660
+ storageType: framebuffer.depthStencilStorageType,
11661
+ storage: framebuffer.stencilStorage,
11662
+ texture: framebuffer.getStencilTexture() ? this.getStencilTexture(framebuffer.getStencilTexture(), framebuffer.externalStorage) : undefined
11473
11663
  };
11474
11664
  }
11475
11665
  };
@@ -11534,7 +11724,7 @@ var seed$6 = 1;
11534
11724
  }
11535
11725
  this.destroyed = true;
11536
11726
  var depthStencilOpt = (options == null ? void 0 : options.depthStencilAttachment) ? options.depthStencilAttachment : 0;
11537
- var fbo = this.frameBuffer;
11727
+ var fbo = this.framebuffer;
11538
11728
  if (fbo) {
11539
11729
  fbo.dispose({
11540
11730
  depthStencilAttachment: depthStencilOpt
@@ -11664,9 +11854,9 @@ var BloomThresholdPass = /*#__PURE__*/ function(RenderPass) {
11664
11854
  }
11665
11855
  var _proto = BloomThresholdPass.prototype;
11666
11856
  _proto.configure = function configure(renderer) {
11667
- this.mainTexture = renderer.getFrameBuffer().getColorTextures()[0];
11857
+ this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
11668
11858
  this.sceneTextureHandle.texture = this.mainTexture;
11669
- renderer.setFrameBuffer(this.frameBuffer);
11859
+ renderer.setFramebuffer(this.framebuffer);
11670
11860
  };
11671
11861
  _proto.execute = function execute(renderer) {
11672
11862
  renderer.clear({
@@ -11736,8 +11926,8 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
11736
11926
  }
11737
11927
  var _proto = HQGaussianDownSamplePass.prototype;
11738
11928
  _proto.configure = function configure(renderer) {
11739
- this.mainTexture = renderer.getFrameBuffer().getColorTextures()[0];
11740
- renderer.setFrameBuffer(this.frameBuffer);
11929
+ this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
11930
+ renderer.setFramebuffer(this.framebuffer);
11741
11931
  };
11742
11932
  _proto.execute = function execute(renderer) {
11743
11933
  renderer.clear({
@@ -11751,7 +11941,7 @@ var HQGaussianDownSamplePass = /*#__PURE__*/ function(RenderPass) {
11751
11941
  this.screenMesh
11752
11942
  ]);
11753
11943
  if (this.type === "V") {
11754
- this.gaussianResult.texture = renderer.getFrameBuffer().getColorTextures()[0];
11944
+ this.gaussianResult.texture = renderer.getFramebuffer().getColorTextures()[0];
11755
11945
  }
11756
11946
  };
11757
11947
  return HQGaussianDownSamplePass;
@@ -11806,8 +11996,8 @@ var HQGaussianUpSamplePass = /*#__PURE__*/ function(RenderPass) {
11806
11996
  }
11807
11997
  var _proto = HQGaussianUpSamplePass.prototype;
11808
11998
  _proto.configure = function configure(renderer) {
11809
- this.mainTexture = renderer.getFrameBuffer().getColorTextures()[0];
11810
- renderer.setFrameBuffer(this.frameBuffer);
11999
+ this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
12000
+ renderer.setFramebuffer(this.framebuffer);
11811
12001
  };
11812
12002
  _proto.execute = function execute(renderer) {
11813
12003
  renderer.clear({
@@ -11876,11 +12066,11 @@ var ToneMappingPass = /*#__PURE__*/ function(RenderPass) {
11876
12066
  }
11877
12067
  var _proto = ToneMappingPass.prototype;
11878
12068
  _proto.configure = function configure(renderer) {
11879
- this.mainTexture = renderer.getFrameBuffer().getColorTextures()[0];
12069
+ this.mainTexture = renderer.getFramebuffer().getColorTextures()[0];
11880
12070
  if (!this.sceneTextureHandle.texture) {
11881
12071
  this.sceneTextureHandle.texture = this.mainTexture;
11882
12072
  }
11883
- renderer.setFrameBuffer(null);
12073
+ renderer.setFramebuffer(null);
11884
12074
  };
11885
12075
  _proto.execute = function execute(renderer) {
11886
12076
  renderer.clear({
@@ -12400,7 +12590,7 @@ var seed$5 = 1;
12400
12590
  this.destroyed = true;
12401
12591
  };
12402
12592
  /**
12403
- * 重置 RenderPass ColorAttachment,解决 FrameBuffer 即读又写的问题
12593
+ * 重置 RenderPass ColorAttachment,解决 Framebuffer 即读又写的问题
12404
12594
  * @param renderPasses - RenderPass 对象数组
12405
12595
  * @param startIndex - 开始重置的索引
12406
12596
  */ _proto.resetRenderPassDefaultAttachment = function resetRenderPassDefaultAttachment(renderPasses, startIndex) {
@@ -12613,7 +12803,7 @@ var seed$5 = 1;
12613
12803
  // TODO tex和size没有地方用到。
12614
12804
  /**
12615
12805
  * 创建拷贝 RenderPass 用到的 Mesh 对象
12616
- * @param semantics - RenderPass 渲染时 FrameBuffer 的颜色和深度纹理、大小和是否混合
12806
+ * @param semantics - RenderPass 渲染时 Framebuffer 的颜色和深度纹理、大小和是否混合
12617
12807
  */ _proto.createCopyMesh = function createCopyMesh(semantics) {
12618
12808
  var name = EFFECTS_COPY_MESH_NAME;
12619
12809
  var engine = this.renderer.engine;
@@ -12704,8 +12894,8 @@ var FinalCopyRP = /*#__PURE__*/ function(RenderPass) {
12704
12894
  }
12705
12895
  var _proto = FinalCopyRP.prototype;
12706
12896
  _proto.configure = function configure(renderer) {
12707
- this.prePassTexture = renderer.getFrameBuffer().getColorTextures()[0];
12708
- renderer.setFrameBuffer(null);
12897
+ this.prePassTexture = renderer.getFramebuffer().getColorTextures()[0];
12898
+ renderer.setFramebuffer(null);
12709
12899
  };
12710
12900
  _proto.execute = function execute(renderer) {
12711
12901
  renderer.clear(this.clearAction);
@@ -12730,8 +12920,8 @@ var GlobalUniforms = function GlobalUniforms() {
12730
12920
  ;
12731
12921
  };
12732
12922
 
12733
- var RenderBuffer = /*#__PURE__*/ function() {
12734
- function RenderBuffer(props) {
12923
+ var Renderbuffer = /*#__PURE__*/ function() {
12924
+ function Renderbuffer(props) {
12735
12925
  this.size = [
12736
12926
  0,
12737
12927
  0
@@ -12743,7 +12933,7 @@ var RenderBuffer = /*#__PURE__*/ function() {
12743
12933
  this.format = format;
12744
12934
  this.attachment = attachment;
12745
12935
  }
12746
- _create_class(RenderBuffer, [
12936
+ _create_class(Renderbuffer, [
12747
12937
  {
12748
12938
  key: "isDestroyed",
12749
12939
  get: function get() {
@@ -12751,7 +12941,7 @@ var RenderBuffer = /*#__PURE__*/ function() {
12751
12941
  }
12752
12942
  }
12753
12943
  ]);
12754
- return RenderBuffer;
12944
+ return Renderbuffer;
12755
12945
  }();
12756
12946
 
12757
12947
  var isWebGL2Available = typeof WebGL2RenderingContext === "function";
@@ -12899,9 +13089,9 @@ var RenderTextureFormat;
12899
13089
  })(RenderTextureFormat || (RenderTextureFormat = {}));
12900
13090
  /**
12901
13091
  *
12902
- */ var FrameBuffer = /*#__PURE__*/ function() {
12903
- function FrameBuffer() {}
12904
- var _proto = FrameBuffer.prototype;
13092
+ */ var Framebuffer = /*#__PURE__*/ function() {
13093
+ function Framebuffer() {}
13094
+ var _proto = Framebuffer.prototype;
12905
13095
  _proto.resize = function resize(x, y, width, height) {
12906
13096
  // OVERRIDE
12907
13097
  };
@@ -12929,7 +13119,7 @@ var RenderTextureFormat;
12929
13119
  _proto.dispose = function dispose(opt) {
12930
13120
  // OVERRIDE
12931
13121
  };
12932
- _create_class(FrameBuffer, [
13122
+ _create_class(Framebuffer, [
12933
13123
  {
12934
13124
  key: "stencilStorage",
12935
13125
  get: function get() {
@@ -12945,7 +13135,7 @@ var RenderTextureFormat;
12945
13135
  }
12946
13136
  }
12947
13137
  ]);
12948
- return FrameBuffer;
13138
+ return Framebuffer;
12949
13139
  }();
12950
13140
 
12951
13141
  var Renderer = /*#__PURE__*/ function() {
@@ -12960,11 +13150,11 @@ var Renderer = /*#__PURE__*/ function() {
12960
13150
  _proto.setGlobalMatrix = function setGlobalMatrix(name, value) {
12961
13151
  // OVERRIDE
12962
13152
  };
12963
- _proto.getFrameBuffer = function getFrameBuffer() {
13153
+ _proto.getFramebuffer = function getFramebuffer() {
12964
13154
  // OVERRIDE
12965
13155
  return null;
12966
13156
  };
12967
- _proto.setFrameBuffer = function setFrameBuffer(frameBuffer) {};
13157
+ _proto.setFramebuffer = function setFramebuffer(framebuffer) {};
12968
13158
  _proto.setViewport = function setViewport(x, y, width, height) {
12969
13159
  // OVERRIDE
12970
13160
  };
@@ -13021,7 +13211,7 @@ var Renderer = /*#__PURE__*/ function() {
13021
13211
  _proto.renderMeshes = function renderMeshes(meshes) {
13022
13212
  // OVERRIDE
13023
13213
  };
13024
- _proto.drawGeometry = function drawGeometry(geometry, material) {
13214
+ _proto.drawGeometry = function drawGeometry(geometry, material, subMeshIndex) {
13025
13215
  // OVERRIDE
13026
13216
  };
13027
13217
  _proto.getTemporaryRT = function getTemporaryRT(name, width, height, depthBuffer, filter, format) {
@@ -13320,7 +13510,7 @@ var InteractComponent = /*#__PURE__*/ function(RendererComponent) {
13320
13510
  };
13321
13511
  _proto.getBoundingBox = function getBoundingBox() {
13322
13512
  var worldMatrix = this.transform.getWorldMatrix();
13323
- var triangles = trianglesFromRect(Vector3.ZERO, 0.5, 0.5);
13513
+ var triangles = trianglesFromRect(Vector3.ZERO, 0.5 * this.transform.size.x, 0.5 * this.transform.size.y);
13324
13514
  triangles.forEach(function(triangle) {
13325
13515
  worldMatrix.transformPoint(triangle.p0);
13326
13516
  worldMatrix.transformPoint(triangle.p1);
@@ -13551,1330 +13741,833 @@ var PlayableAsset = /*#__PURE__*/ function() {
13551
13741
  return PlayableAsset;
13552
13742
  }();
13553
13743
 
13554
- /**
13555
- * @since 2.0.0
13556
- * @internal
13557
- */ var Track = /*#__PURE__*/ function(PlayableAsset) {
13558
- _inherits(Track, PlayableAsset);
13559
- function Track() {
13744
+ var singleSplits = [
13745
+ [
13746
+ 0,
13747
+ 0,
13748
+ 1,
13749
+ 1,
13750
+ undefined
13751
+ ]
13752
+ ];
13753
+ var tempColor = [
13754
+ 1,
13755
+ 1,
13756
+ 1,
13757
+ 1
13758
+ ];
13759
+ var seed$3 = 0;
13760
+ var SpriteColorPlayable = /*#__PURE__*/ function(Playable) {
13761
+ _inherits(SpriteColorPlayable, Playable);
13762
+ function SpriteColorPlayable() {
13560
13763
  var _this;
13561
- _this = PlayableAsset.apply(this, arguments) || this;
13562
- _this.clips = [];
13563
- _this.clipSeed = 0;
13764
+ _this = Playable.apply(this, arguments) || this;
13765
+ _this.renderColor = [
13766
+ 1,
13767
+ 1,
13768
+ 1,
13769
+ 1
13770
+ ];
13564
13771
  return _this;
13565
13772
  }
13566
- var _proto = Track.prototype;
13567
- _proto.createOutput = function createOutput() {
13568
- var output = new PlayableOutput();
13569
- return output;
13570
- };
13571
- /**
13572
- * 重写该方法以创建自定义混合器
13573
- */ _proto.createMixerPlayable = function createMixerPlayable() {
13574
- return new Playable();
13773
+ var _proto = SpriteColorPlayable.prototype;
13774
+ _proto.onPlayablePlay = function onPlayablePlay() {
13775
+ this.spriteMaterial = this.bindingItem.getComponent(SpriteComponent).material;
13575
13776
  };
13576
- _proto.createPlayable = function createPlayable() {
13577
- var defaultMixPlayable = this.createMixerPlayable();
13578
- for(var _iterator = _create_for_of_iterator_helper_loose(this.clips), _step; !(_step = _iterator()).done;){
13579
- var clip = _step.value;
13580
- defaultMixPlayable.connect(clip.playable);
13777
+ _proto.processFrame = function processFrame(dt) {
13778
+ var colorInc = vecFill(tempColor, 1);
13779
+ var colorChanged;
13780
+ var life = this.time / this.bindingItem.duration;
13781
+ var opacityOverLifetime = this.opacityOverLifetime;
13782
+ var colorOverLifetime = this.colorOverLifetime;
13783
+ if (colorOverLifetime) {
13784
+ colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
13785
+ colorChanged = true;
13581
13786
  }
13582
- return defaultMixPlayable;
13583
- };
13584
- _proto.createClip = function createClip(classConstructor, name) {
13585
- var newClip = new TimelineClip();
13586
- newClip.playable = new classConstructor();
13587
- newClip.name = name ? name : "TimelineClip" + newClip.id;
13588
- this.addClip(newClip);
13589
- return newClip;
13590
- };
13591
- _proto.getClips = function getClips() {
13592
- return this.clips;
13593
- };
13594
- _proto.findClip = function findClip(name) {
13595
- for(var _iterator = _create_for_of_iterator_helper_loose(this.clips), _step; !(_step = _iterator()).done;){
13596
- var clip = _step.value;
13597
- if (clip.name === name) {
13598
- return clip;
13599
- }
13787
+ if (opacityOverLifetime) {
13788
+ colorInc[3] *= opacityOverLifetime.getValue(life);
13789
+ colorChanged = true;
13600
13790
  }
13601
- };
13602
- _proto.addClip = function addClip(clip) {
13603
- clip.playable.bindingItem = this.bindingItem;
13604
- clip.id = (this.clipSeed++).toString();
13605
- this.clips.push(clip);
13606
- };
13607
- return Track;
13608
- }(PlayableAsset);
13609
- /**
13610
- * @since 2.0.0
13611
- * @internal
13612
- */ var TimelineClip = function TimelineClip() {
13613
- this.start = 0;
13614
- this.duration = 0;
13615
- };
13616
-
13617
- function _assert_this_initialized(self) {
13618
- if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
13619
- return self;
13620
- }
13621
-
13622
- var AnimationStream = /*#__PURE__*/ function() {
13623
- function AnimationStream(playable) {
13624
- this.curveValues = {};
13625
- this.playable = playable;
13626
- }
13627
- var _proto = AnimationStream.prototype;
13628
- _proto.setCurveValue = function setCurveValue(componentType, propertyName, value) {
13629
- if (!this.findCurveValue(componentType, propertyName)) {
13630
- this.curveValues[componentType + propertyName] = {
13631
- componentType: componentType,
13632
- propertyName: propertyName,
13633
- value: value
13634
- };
13635
- } else {
13636
- this.curveValues[componentType + propertyName].value = value;
13791
+ if (colorChanged) {
13792
+ vecMulCombine(this.renderColor, colorInc, this.startColor);
13793
+ this.spriteMaterial.getVector4("_Color").setFromArray(this.renderColor);
13637
13794
  }
13638
- return this.curveValues[componentType + propertyName];
13639
- };
13640
- _proto.findCurveValue = function findCurveValue(componentType, propertyName) {
13641
- return this.curveValues[componentType + propertyName];
13642
13795
  };
13643
- _proto.getInputStream = function getInputStream(index) {
13644
- var inputPlayable = this.playable.getInput(index);
13645
- if (_instanceof1(inputPlayable, AnimationPlayable)) {
13646
- return inputPlayable.animationStream;
13796
+ _proto.fromData = function fromData(clipData) {
13797
+ this.clipData = clipData;
13798
+ var colorOverLifetime = clipData.colorOverLifetime;
13799
+ if (colorOverLifetime) {
13800
+ var _colorOverLifetime_opacity;
13801
+ this.opacityOverLifetime = createValueGetter((_colorOverLifetime_opacity = colorOverLifetime.opacity) != null ? _colorOverLifetime_opacity : 1);
13802
+ if (colorOverLifetime.color && colorOverLifetime.color[0] === ValueType.GRADIENT_COLOR) {
13803
+ this.colorOverLifetime = colorStopsFromGradient(colorOverLifetime.color[1]);
13804
+ }
13647
13805
  }
13806
+ this.startColor = clipData.startColor || [
13807
+ 1,
13808
+ 1,
13809
+ 1,
13810
+ 1
13811
+ ];
13812
+ return this;
13648
13813
  };
13649
- return AnimationStream;
13650
- }();
13651
-
13652
- var AnimationPlayable = /*#__PURE__*/ function(Playable) {
13653
- _inherits(AnimationPlayable, Playable);
13654
- function AnimationPlayable() {
13814
+ return SpriteColorPlayable;
13815
+ }(Playable);
13816
+ var SpriteComponent = /*#__PURE__*/ function(RendererComponent) {
13817
+ _inherits(SpriteComponent, RendererComponent);
13818
+ function SpriteComponent(engine, props) {
13655
13819
  var _this;
13656
- _this = Playable.call(this) || this;
13657
- _this.animationStream = new AnimationStream(_assert_this_initialized(_this));
13820
+ _this = RendererComponent.call(this, engine) || this;
13821
+ _this.frameAnimationTime = 0;
13822
+ _this.color = [
13823
+ 1,
13824
+ 1,
13825
+ 1,
13826
+ 1
13827
+ ];
13828
+ _this.visible = true;
13829
+ _this.getHitTestParams = function(force) {
13830
+ var ui = _this.interaction;
13831
+ if (force || ui) {
13832
+ var area = _this.getBoundingBox();
13833
+ if (area) {
13834
+ var _this_interaction;
13835
+ return {
13836
+ behavior: ((_this_interaction = _this.interaction) == null ? void 0 : _this_interaction.behavior) || 0,
13837
+ type: area.type,
13838
+ triangles: area.area,
13839
+ backfaceCulling: _this.renderer.side === SideMode.FRONT
13840
+ };
13841
+ }
13842
+ }
13843
+ };
13844
+ if (props) {
13845
+ _this.fromData(props);
13846
+ }
13658
13847
  return _this;
13659
13848
  }
13660
- return AnimationPlayable;
13661
- }(Playable);
13662
-
13663
- var tempRot$1 = new Euler();
13664
- var tempSize$1 = new Vector3(1, 1, 1);
13665
- var tempPos = new Vector3();
13666
- /**
13667
- * @since 2.0.0
13668
- * @internal
13669
- */ var TransformAnimationPlayable = /*#__PURE__*/ function(AnimationPlayable) {
13670
- _inherits(TransformAnimationPlayable, AnimationPlayable);
13671
- function TransformAnimationPlayable() {
13672
- return AnimationPlayable.apply(this, arguments);
13673
- }
13674
- var _proto = TransformAnimationPlayable.prototype;
13675
- _proto.processFrame = function processFrame(dt) {
13676
- if (this.bindingItem.composition) {
13677
- this.sampleAnimation();
13678
- }
13849
+ var _proto = SpriteComponent.prototype;
13850
+ /**
13851
+ * 设置当前 Mesh 的可见性。
13852
+ * @param visible - true:可见,false:不可见
13853
+ */ _proto.setVisible = function setVisible(visible) {
13854
+ this.visible = visible;
13679
13855
  };
13680
13856
  /**
13681
- * 应用时间轴K帧数据到对象
13682
- */ _proto.sampleAnimation = function sampleAnimation() {
13683
- var _this = this;
13684
- var duration = this.bindingItem.duration;
13685
- var life = this.time / duration;
13686
- life = life < 0 ? 0 : life > 1 ? 1 : life;
13687
- if (this.sizeXOverLifetime) {
13688
- tempSize$1.x = this.sizeXOverLifetime.getValue(life);
13689
- if (this.sizeSeparateAxes) {
13690
- tempSize$1.y = this.sizeYOverLifetime.getValue(life);
13691
- tempSize$1.z = this.sizeZOverLifetime.getValue(life);
13692
- } else {
13693
- tempSize$1.z = tempSize$1.y = tempSize$1.x;
13694
- }
13695
- var startSize = this.originalTransform.scale;
13696
- this.bindingItem.transform.setScale(tempSize$1.x * startSize.x, tempSize$1.y * startSize.y, tempSize$1.z * startSize.z);
13697
- // this.animationStream.setCurveValue('transform', 'scale.x', tempSize.x * startSize.x);
13698
- // this.animationStream.setCurveValue('transform', 'scale.y', tempSize.y * startSize.y);
13699
- // this.animationStream.setCurveValue('transform', 'scale.z', tempSize.z * startSize.z);
13700
- }
13701
- if (this.rotationOverLifetime) {
13702
- var func = function(v) {
13703
- return _this.rotationOverLifetime.asRotation ? v.getValue(life) : v.getIntegrateValue(0, life, duration);
13704
- };
13705
- var incZ = func(this.rotationOverLifetime.z);
13706
- var separateAxes = this.rotationOverLifetime.separateAxes;
13707
- tempRot$1.x = separateAxes ? func(this.rotationOverLifetime.x) : 0;
13708
- tempRot$1.y = separateAxes ? func(this.rotationOverLifetime.y) : 0;
13709
- tempRot$1.z = incZ;
13710
- var rot = tempRot$1.addEulers(this.originalTransform.rotation, tempRot$1);
13711
- this.bindingItem.transform.setRotation(rot.x, rot.y, rot.z);
13712
- // this.animationStream.setCurveValue('transform', 'rotation.x', rot.x);
13713
- // this.animationStream.setCurveValue('transform', 'rotation.y', rot.y);
13714
- // this.animationStream.setCurveValue('transform', 'rotation.z', rot.z);
13857
+ * 获取当前 Mesh 的可见性。
13858
+ */ _proto.getVisible = function getVisible() {
13859
+ return this.visible;
13860
+ };
13861
+ /**
13862
+ * 设置当前图层的颜色
13863
+ * > Tips: 透明度也属于颜色的一部分,当有透明度/颜色 K 帧变化时,该 API 会失效
13864
+ * @since 2.0.0
13865
+ * @param color - 颜色值
13866
+ */ _proto.setColor = function setColor(color) {
13867
+ this.color = color;
13868
+ this.material.setVector4("_Color", new Vector4().setFromArray(color));
13869
+ };
13870
+ /**
13871
+ * 设置当前 Mesh 的纹理
13872
+ * @since 2.0.0
13873
+ * @param texture - 纹理对象
13874
+ */ _proto.setTexture = function setTexture(texture) {
13875
+ this.renderer.texture = texture;
13876
+ this.material.setTexture("uSampler0", texture);
13877
+ };
13878
+ _proto.render = function render(renderer) {
13879
+ if (!this.getVisible()) {
13880
+ return;
13715
13881
  }
13716
- if (this.positionOverLifetime) {
13717
- var pos = tempPos;
13718
- calculateTranslation(pos, this, this.gravity, this.time, duration, this.originalTransform.position, this.velocity);
13719
- if (this.originalTransform.path) {
13720
- pos.add(this.originalTransform.path.getValue(life));
13721
- }
13722
- this.bindingItem.transform.setPosition(pos.x, pos.y, pos.z);
13723
- // this.animationStream.setCurveValue('transform', 'position.x', pos.x);
13724
- // this.animationStream.setCurveValue('transform', 'position.y', pos.y);
13725
- // this.animationStream.setCurveValue('transform', 'position.z', pos.z);
13882
+ var material = this.material;
13883
+ var geo = this.geometry;
13884
+ if (renderer.renderingData.currentFrame.globalUniforms) {
13885
+ renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
13726
13886
  }
13887
+ this.material.setVector2("_Size", this.transform.size);
13888
+ renderer.drawGeometry(geo, material);
13727
13889
  };
13728
- _proto.fromData = function fromData(data) {
13729
- var scale = this.bindingItem.transform.scale;
13730
- this.originalTransform = {
13731
- position: this.bindingItem.transform.position.clone(),
13732
- rotation: this.bindingItem.transform.getRotation().clone(),
13733
- // TODO 编辑器 scale 没有z轴控制
13734
- scale: new Vector3(scale.x, scale.y, scale.x)
13735
- };
13736
- var positionOverLifetime = data.positionOverLifetime;
13737
- var rotationOverLifetime = data.rotationOverLifetime;
13738
- var sizeOverLifetime = data.sizeOverLifetime;
13739
- // TODO: 没有 K 帧数据的不需要传 positionOverLifetime 空对象
13740
- if (positionOverLifetime && Object.keys(positionOverLifetime).length !== 0) {
13741
- this.positionOverLifetime = positionOverLifetime;
13742
- if (positionOverLifetime.path) {
13743
- this.originalTransform.path = createValueGetter(positionOverLifetime.path);
13744
- }
13745
- var linearVelEnable = positionOverLifetime.linearX || positionOverLifetime.linearY || positionOverLifetime.linearZ;
13746
- if (linearVelEnable) {
13747
- this.linearVelOverLifetime = {
13748
- x: positionOverLifetime.linearX && createValueGetter(positionOverLifetime.linearX),
13749
- y: positionOverLifetime.linearY && createValueGetter(positionOverLifetime.linearY),
13750
- z: positionOverLifetime.linearZ && createValueGetter(positionOverLifetime.linearZ),
13751
- asMovement: positionOverLifetime.asMovement,
13752
- enabled: !!linearVelEnable
13753
- };
13754
- }
13755
- var orbitalVelEnable = positionOverLifetime.orbitalX || positionOverLifetime.orbitalY || positionOverLifetime.orbitalZ;
13756
- if (orbitalVelEnable) {
13757
- this.orbitalVelOverLifetime = {
13758
- x: positionOverLifetime.orbitalX && createValueGetter(positionOverLifetime.orbitalX),
13759
- y: positionOverLifetime.orbitalY && createValueGetter(positionOverLifetime.orbitalY),
13760
- z: positionOverLifetime.orbitalZ && createValueGetter(positionOverLifetime.orbitalZ),
13761
- center: ensureVec3(positionOverLifetime.orbCenter),
13762
- asRotation: positionOverLifetime.asRotation,
13763
- enabled: !!orbitalVelEnable
13764
- };
13890
+ _proto.start = function start() {
13891
+ this.priority = this.item.listIndex;
13892
+ this.item.getHitTestParams = this.getHitTestParams;
13893
+ };
13894
+ _proto.update = function update(dt) {
13895
+ this.frameAnimationTime += dt / 1000;
13896
+ var time = this.frameAnimationTime;
13897
+ var duration = this.item.duration;
13898
+ var life = Math.min(Math.max(time / duration, 0.0), 1.0);
13899
+ var ta = this.textureSheetAnimation;
13900
+ if (ta) {
13901
+ var total = ta.total || ta.row * ta.col;
13902
+ var texRectX = 0;
13903
+ var texRectY = 0;
13904
+ var texRectW = 1;
13905
+ var texRectH = 1;
13906
+ var flip;
13907
+ if (this.splits) {
13908
+ var sp = this.splits[0];
13909
+ flip = sp[4];
13910
+ texRectX = sp[0];
13911
+ texRectY = sp[1];
13912
+ if (flip) {
13913
+ texRectW = sp[3];
13914
+ texRectH = sp[2];
13915
+ } else {
13916
+ texRectW = sp[2];
13917
+ texRectH = sp[3];
13918
+ }
13765
13919
  }
13766
- this.speedOverLifetime = positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime);
13767
- }
13768
- if (sizeOverLifetime) {
13769
- if (sizeOverLifetime.separateAxes) {
13770
- this.sizeSeparateAxes = true;
13771
- this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.x || 1);
13772
- this.sizeYOverLifetime = createValueGetter(sizeOverLifetime.y || 1);
13773
- this.sizeZOverLifetime = createValueGetter(sizeOverLifetime.z || 1);
13920
+ var dx, dy;
13921
+ if (flip) {
13922
+ dx = 1 / ta.row * texRectW;
13923
+ dy = 1 / ta.col * texRectH;
13774
13924
  } else {
13775
- this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.size || 1);
13925
+ dx = 1 / ta.col * texRectW;
13926
+ dy = 1 / ta.row * texRectH;
13776
13927
  }
13777
- }
13778
- if (rotationOverLifetime) {
13779
- this.rotationOverLifetime = {
13780
- asRotation: rotationOverLifetime.asRotation,
13781
- separateAxes: rotationOverLifetime.separateAxes,
13782
- z: createValueGetter(rotationOverLifetime.z || 0)
13783
- };
13784
- if (rotationOverLifetime.separateAxes) {
13785
- var rotLt = this.rotationOverLifetime;
13786
- rotLt.x = createValueGetter(rotationOverLifetime.x || 0);
13787
- rotLt.y = createValueGetter(rotationOverLifetime.y || 0);
13928
+ var texOffset;
13929
+ if (ta.animate) {
13930
+ var frameIndex = Math.round(life * (total - 1));
13931
+ var yIndex = Math.floor(frameIndex / ta.col);
13932
+ var xIndex = frameIndex - yIndex * ta.col;
13933
+ texOffset = flip ? [
13934
+ dx * yIndex,
13935
+ dy * (ta.col - xIndex)
13936
+ ] : [
13937
+ dx * xIndex,
13938
+ dy * (1 + yIndex)
13939
+ ];
13940
+ } else {
13941
+ texOffset = [
13942
+ 0,
13943
+ dy
13944
+ ];
13788
13945
  }
13946
+ this.material.getVector4("_TexOffset").setFromArray([
13947
+ texRectX + texOffset[0],
13948
+ texRectH + texRectY - texOffset[1],
13949
+ dx,
13950
+ dy
13951
+ ]);
13789
13952
  }
13790
- this.gravity = Vector3.fromArray((positionOverLifetime == null ? void 0 : positionOverLifetime.gravity) || []);
13791
- var _positionOverLifetime_gravityOverLifetime;
13792
- this.gravityModifier = createValueGetter((_positionOverLifetime_gravityOverLifetime = positionOverLifetime == null ? void 0 : positionOverLifetime.gravityOverLifetime) != null ? _positionOverLifetime_gravityOverLifetime : 0);
13793
- this.direction = (positionOverLifetime == null ? void 0 : positionOverLifetime.direction) ? Vector3.fromArray(positionOverLifetime.direction).normalize() : new Vector3();
13794
- this.startSpeed = (positionOverLifetime == null ? void 0 : positionOverLifetime.startSpeed) || 0;
13795
- this.velocity = this.direction.clone();
13796
- this.velocity.multiply(this.startSpeed);
13797
- };
13798
- return TransformAnimationPlayable;
13799
- }(AnimationPlayable);
13800
- var TransformAnimationPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
13801
- _inherits(TransformAnimationPlayableAsset, PlayableAsset);
13802
- function TransformAnimationPlayableAsset() {
13803
- return PlayableAsset.apply(this, arguments);
13804
- }
13805
- var _proto = TransformAnimationPlayableAsset.prototype;
13806
- _proto.createPlayable = function createPlayable() {
13807
- var transformAnimationPlayable = new TransformAnimationPlayable();
13808
- transformAnimationPlayable.fromData(this.transformAnimationData);
13809
- return transformAnimationPlayable;
13810
- };
13811
- _proto.fromData = function fromData(data) {
13812
- this.transformAnimationData = data;
13813
- };
13814
- return TransformAnimationPlayableAsset;
13815
- }(PlayableAsset);
13816
- /**
13817
- * @since 2.0.0
13818
- * @internal
13819
- */ var ActivationPlayable = /*#__PURE__*/ function(Playable) {
13820
- _inherits(ActivationPlayable, Playable);
13821
- function ActivationPlayable() {
13822
- return Playable.apply(this, arguments);
13823
- }
13824
- var _proto = ActivationPlayable.prototype;
13825
- _proto.onGraphStart = function onGraphStart() {
13826
- this.bindingItem.transform.setValid(false);
13827
- this.hideRendererComponents();
13828
- };
13829
- _proto.onPlayablePlay = function onPlayablePlay() {
13830
- this.bindingItem.transform.setValid(true);
13831
- this.showRendererComponents();
13832
13953
  };
13833
- _proto.onPlayableDestroy = function onPlayableDestroy() {
13834
- this.bindingItem.transform.setValid(false);
13835
- this.hideRendererComponents();
13954
+ _proto.onDestroy = function onDestroy() {
13955
+ if (this.item && this.item.composition) {
13956
+ this.item.composition.destroyTextures(this.getTextures());
13957
+ }
13836
13958
  };
13837
- _proto.hideRendererComponents = function hideRendererComponents() {
13838
- for(var _iterator = _create_for_of_iterator_helper_loose(this.bindingItem.rendererComponents), _step; !(_step = _iterator()).done;){
13839
- var rendererComponent = _step.value;
13840
- if (rendererComponent.enabled) {
13841
- rendererComponent.enabled = false;
13959
+ _proto.getItemInitData = function getItemInitData(item, idx, pointStartIndex, textureIndex) {
13960
+ var geoData = item.geoData;
13961
+ if (!geoData) {
13962
+ geoData = item.geoData = this.getItemGeometryData(item, idx);
13963
+ }
13964
+ var index = geoData.index;
13965
+ var idxCount = index.length;
13966
+ // @ts-expect-error
13967
+ var indexData = this.wireframe ? new Uint8Array([
13968
+ 0,
13969
+ 1,
13970
+ 1,
13971
+ 3,
13972
+ 2,
13973
+ 3,
13974
+ 2,
13975
+ 0
13976
+ ]) : new index.constructor(idxCount);
13977
+ if (!this.wireframe) {
13978
+ for(var i = 0; i < idxCount; i++){
13979
+ indexData[i] = pointStartIndex + index[i];
13842
13980
  }
13843
13981
  }
13982
+ return {
13983
+ atlasOffset: geoData.atlasOffset,
13984
+ index: indexData
13985
+ };
13844
13986
  };
13845
- _proto.showRendererComponents = function showRendererComponents() {
13846
- for(var _iterator = _create_for_of_iterator_helper_loose(this.bindingItem.rendererComponents), _step; !(_step = _iterator()).done;){
13847
- var rendererComponent = _step.value;
13848
- if (!rendererComponent.enabled) {
13849
- rendererComponent.enabled = true;
13850
- }
13851
- }
13852
- };
13853
- return ActivationPlayable;
13854
- }(Playable);
13855
-
13856
- /**
13857
- * @since 2.0.0
13858
- * @internal
13859
- */ var TimelineComponent = /*#__PURE__*/ function(ItemBehaviour) {
13860
- _inherits(TimelineComponent, ItemBehaviour);
13861
- function TimelineComponent(engine) {
13862
- var _this;
13863
- _this = ItemBehaviour.call(this, engine) || this;
13864
- _this.reusable = false;
13865
- _this.timelineStarted = false;
13866
- _this.playableGraph = new PlayableGraph();
13867
- /**
13868
- * 元素动画已经播放的时间
13869
- */ _this.time = 0;
13870
- _this.tracks = [];
13871
- _this.trackSeed = 0;
13872
- return _this;
13873
- }
13874
- var _proto = TimelineComponent.prototype;
13875
- _proto.start = function start() {
13876
- // TODO TimelineClip 需要传入 start 和 duration 数据
13877
- for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
13878
- var track = _step.value;
13879
- for(var _iterator1 = _create_for_of_iterator_helper_loose(track.getClips()), _step1; !(_step1 = _iterator1()).done;){
13880
- var clip = _step1.value;
13881
- clip.start = this.item.start;
13882
- clip.duration = this.item.duration;
13883
- }
13987
+ _proto.setItem = function setItem() {
13988
+ var textures = [];
13989
+ var texture = this.renderer.texture;
13990
+ if (texture) {
13991
+ addItem(textures, texture);
13884
13992
  }
13885
- this.compileTracks(this.playableGraph);
13886
- };
13887
- // TODO: [1.31] @十弦 vfx-item 下 onUpdate 的改动验证
13888
- _proto.update = function update(dt) {
13889
- if (this.item.stopped || !this.item.composition) {
13890
- return;
13993
+ texture = this.renderer.texture;
13994
+ var textureIndex = texture ? textures.indexOf(texture) : -1;
13995
+ var data = this.getItemInitData(this, 0, 0, textureIndex);
13996
+ var renderer = this.renderer;
13997
+ var texParams = this.material.getVector4("_TexParams");
13998
+ texParams.x = renderer.occlusion ? +renderer.transparentOcclusion : 1;
13999
+ texParams.y = +this.preMultiAlpha;
14000
+ texParams.z = renderer.renderMode;
14001
+ var attributes = {
14002
+ atlasOffset: new Float32Array(data.atlasOffset.length),
14003
+ index: new Uint16Array(data.index.length)
14004
+ };
14005
+ attributes.atlasOffset.set(data.atlasOffset);
14006
+ attributes.index.set(data.index);
14007
+ var _this = this, material = _this.material, geometry = _this.geometry;
14008
+ var indexData = attributes.index;
14009
+ geometry.setIndexData(indexData);
14010
+ geometry.setAttributeData("atlasOffset", attributes.atlasOffset);
14011
+ geometry.setDrawCount(data.index.length);
14012
+ for(var i = 0; i < textures.length; i++){
14013
+ var texture1 = textures[i];
14014
+ material.setTexture("uSampler" + i, texture1);
13891
14015
  }
13892
- if (!this.timelineStarted) {
13893
- for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
13894
- var track = _step.value;
13895
- for(var _iterator1 = _create_for_of_iterator_helper_loose(track.getClips()), _step1; !(_step1 = _iterator1()).done;){
13896
- var clip = _step1.value;
13897
- clip.playable.onGraphStart();
13898
- }
13899
- }
13900
- this.timelineStarted = true;
14016
+ // FIXME: 内存泄漏的临时方案,后面再调整
14017
+ var emptyTexture = this.emptyTexture;
14018
+ for(var k = textures.length; k < maxSpriteMeshItemCount; k++){
14019
+ material.setTexture("uSampler" + k, emptyTexture);
13901
14020
  }
13902
- var now = this.time;
13903
- // 判断动画是否开始
13904
- if (this.item.delaying && now >= 0 && now <= this.item.duration) {
13905
- this.item.delaying = false;
13906
- for(var _iterator2 = _create_for_of_iterator_helper_loose(this.tracks), _step2; !(_step2 = _iterator2()).done;){
13907
- var track1 = _step2.value;
13908
- for(var _iterator3 = _create_for_of_iterator_helper_loose(track1.getClips()), _step3; !(_step3 = _iterator3()).done;){
13909
- var clip1 = _step3.value;
13910
- clip1.playable.onPlayablePlay();
14021
+ };
14022
+ _proto.createGeometry = function createGeometry(mode) {
14023
+ var maxVertex = 12 * this.splits.length;
14024
+ return Geometry.create(this.engine, {
14025
+ attributes: {
14026
+ aPos: {
14027
+ type: glContext.FLOAT,
14028
+ size: 3,
14029
+ data: new Float32Array([
14030
+ -0.5,
14031
+ 0.5,
14032
+ 0,
14033
+ -0.5,
14034
+ -0.5,
14035
+ 0,
14036
+ 0.5,
14037
+ 0.5,
14038
+ 0,
14039
+ 0.5,
14040
+ -0.5,
14041
+ 0
14042
+ ])
14043
+ },
14044
+ atlasOffset: {
14045
+ size: 2,
14046
+ offset: 0,
14047
+ releasable: true,
14048
+ type: glContext.FLOAT,
14049
+ data: new Float32Array(0)
13911
14050
  }
13912
- }
13913
- }
13914
- // 判断动画是否结束
13915
- var ended;
13916
- if (VFXItem.isParticle(this.item)) {
13917
- ended = this.item.isEnded(now) && this.item.content.destoryed;
13918
- } else {
13919
- ended = this.item.isEnded(now);
14051
+ },
14052
+ indices: {
14053
+ data: new Uint16Array(0),
14054
+ releasable: true
14055
+ },
14056
+ mode: mode,
14057
+ maxVertex: maxVertex
14058
+ });
14059
+ };
14060
+ _proto.createMaterial = function createMaterial(renderInfo, count) {
14061
+ var side = renderInfo.side, occlusion = renderInfo.occlusion, blending = renderInfo.blending, maskMode = renderInfo.maskMode, mask = renderInfo.mask;
14062
+ var materialProps = {
14063
+ shader: spriteMeshShaderFromRenderInfo(renderInfo, count, 1)
14064
+ };
14065
+ this.preMultiAlpha = getPreMultiAlpha(blending);
14066
+ var material = Material.create(this.engine, materialProps);
14067
+ var states = {
14068
+ side: side,
14069
+ blending: true,
14070
+ blendMode: blending,
14071
+ mask: mask,
14072
+ maskMode: maskMode,
14073
+ depthTest: true,
14074
+ depthMask: occlusion
14075
+ };
14076
+ material.blending = states.blending;
14077
+ material.stencilRef = states.mask !== undefined ? [
14078
+ states.mask,
14079
+ states.mask
14080
+ ] : undefined;
14081
+ material.depthTest = states.depthTest;
14082
+ material.depthMask = states.depthMask;
14083
+ setBlendMode(material, states.blendMode);
14084
+ setMaskMode(material, states.maskMode);
14085
+ setSideMode(material, states.side);
14086
+ if (!material.hasUniform("_Color")) {
14087
+ material.setVector4("_Color", new Vector4(0, 0, 0, 1));
13920
14088
  }
13921
- if (ended) {
13922
- var endBehavior = this.item.endBehavior;
13923
- if (!this.item.ended) {
13924
- this.item.ended = true;
13925
- this.item.onEnd();
13926
- if (endBehavior === ItemEndBehavior.destroy) {
13927
- for(var _iterator4 = _create_for_of_iterator_helper_loose(this.tracks), _step4; !(_step4 = _iterator4()).done;){
13928
- var track2 = _step4.value;
13929
- for(var _iterator5 = _create_for_of_iterator_helper_loose(track2.getClips()), _step5; !(_step5 = _iterator5()).done;){
13930
- var clip2 = _step5.value;
13931
- clip2.playable.onPlayableDestroy();
13932
- }
13933
- }
13934
- this.item.delaying = true;
13935
- if (!this.item.reusable && !this.reusable) {
13936
- this.item.dispose();
13937
- return;
13938
- }
13939
- }
13940
- }
14089
+ if (!material.hasUniform("_TexOffset")) {
14090
+ material.setVector4("_TexOffset", new Vector4());
13941
14091
  }
13942
- // TODO: [1.31] @茂安 验证 https://github.com/galacean/effects-runtime/commits/main/packages/effects-core/src/vfx-item.ts
13943
- // 在生命周期内更新动画
13944
- if (!this.item.delaying) {
13945
- var lifetime = this.time / this.item.duration;
13946
- this.item.lifetime = lifetime;
13947
- for(var _iterator6 = _create_for_of_iterator_helper_loose(this.tracks), _step6; !(_step6 = _iterator6()).done;){
13948
- var track3 = _step6.value;
13949
- for(var _iterator7 = _create_for_of_iterator_helper_loose(track3.getClips()), _step7; !(_step7 = _iterator7()).done;){
13950
- var clip3 = _step7.value;
13951
- clip3.playable.setTime(this.time);
13952
- }
13953
- }
13954
- this.playableGraph.evaluate(dt);
14092
+ if (!material.hasUniform("_TexParams")) {
14093
+ material.setVector4("_TexParams", new Vector4());
13955
14094
  }
14095
+ return material;
13956
14096
  };
13957
- // time 单位秒
13958
- _proto.setTime = function setTime(time) {
13959
- this.time = time;
13960
- };
13961
- _proto.getTime = function getTime() {
13962
- return this.time;
13963
- };
13964
- _proto.toLocalTime = function toLocalTime(time) {
13965
- var localTime = time - this.options.start;
13966
- var duration = this.options.duration;
13967
- if (localTime - duration > 0.001) {
13968
- if (this.options.endBehavior === END_BEHAVIOR_RESTART) {
13969
- localTime = localTime % duration;
13970
- } else if (this.options.endBehavior === END_BEHAVIOR_FREEZE) {
13971
- localTime = Math.min(duration, localTime);
14097
+ _proto.getItemGeometryData = function getItemGeometryData(item, aIndex) {
14098
+ var splits = item.splits, renderer = item.renderer, textureSheetAnimation = item.textureSheetAnimation;
14099
+ var sx = 1, sy = 1;
14100
+ if (renderer.shape) {
14101
+ var _renderer_shape = renderer.shape, index = _renderer_shape.index, aPoint = _renderer_shape.aPoint;
14102
+ var point = new Float32Array(aPoint);
14103
+ var position = [];
14104
+ var atlasOffset = [];
14105
+ for(var i = 0; i < point.length; i += 6){
14106
+ point[i] *= sx;
14107
+ point[i + 1] *= sy;
14108
+ atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
14109
+ position.push(point[i], point[i + 1], 0.0);
13972
14110
  }
14111
+ this.geometry.setAttributeData("aPos", new Float32Array(position));
14112
+ return {
14113
+ index: index,
14114
+ atlasOffset: atlasOffset
14115
+ };
13973
14116
  }
13974
- return localTime;
13975
- };
13976
- _proto.createTrack = function createTrack(classConstructor, name) {
13977
- var newTrack = new classConstructor();
13978
- newTrack.bindingItem = this.item;
13979
- newTrack.id = (this.trackSeed++).toString();
13980
- newTrack.name = name ? name : "Track" + newTrack.id;
13981
- this.tracks.push(newTrack);
13982
- return newTrack;
13983
- };
13984
- _proto.getTracks = function getTracks() {
13985
- return this.tracks;
13986
- };
13987
- _proto.findTrack = function findTrack(name) {
13988
- for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
13989
- var track = _step.value;
13990
- if (track.name === name) {
13991
- return track;
14117
+ var originData = [
14118
+ -.5,
14119
+ .5,
14120
+ -.5,
14121
+ -.5,
14122
+ .5,
14123
+ .5,
14124
+ .5,
14125
+ -.5
14126
+ ];
14127
+ var atlasOffset1 = [];
14128
+ var index1 = [];
14129
+ var col = 2;
14130
+ var row = 2;
14131
+ if (splits.length === 1) {
14132
+ col = 1;
14133
+ row = 1;
14134
+ }
14135
+ var position1 = [];
14136
+ for(var x = 0; x < col; x++){
14137
+ for(var y = 0; y < row; y++){
14138
+ var base = (y * 2 + x) * 4;
14139
+ // @ts-expect-error
14140
+ var split = textureSheetAnimation ? [
14141
+ 0,
14142
+ 0,
14143
+ 1,
14144
+ 1,
14145
+ splits[0][4]
14146
+ ] : splits[y * 2 + x];
14147
+ var texOffset = split[4] ? [
14148
+ 0,
14149
+ 0,
14150
+ 1,
14151
+ 0,
14152
+ 0,
14153
+ 1,
14154
+ 1,
14155
+ 1
14156
+ ] : [
14157
+ 0,
14158
+ 1,
14159
+ 0,
14160
+ 0,
14161
+ 1,
14162
+ 1,
14163
+ 1,
14164
+ 0
14165
+ ];
14166
+ var dw = ((x + x + 1) / col - 1) / 2;
14167
+ var dh = ((y + y + 1) / row - 1) / 2;
14168
+ var tox = split[0];
14169
+ var toy = split[1];
14170
+ var tsx = split[4] ? split[3] : split[2];
14171
+ var tsy = split[4] ? split[2] : split[3];
14172
+ var origin = [
14173
+ originData[0] / col + dw,
14174
+ originData[1] / row + dh,
14175
+ originData[2] / col + dw,
14176
+ originData[3] / row + dh,
14177
+ originData[4] / col + dw,
14178
+ originData[5] / row + dh,
14179
+ originData[6] / col + dw,
14180
+ originData[7] / row + dh
14181
+ ];
14182
+ 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);
14183
+ 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);
14184
+ index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
13992
14185
  }
13993
14186
  }
14187
+ this.geometry.setAttributeData("aPos", new Float32Array(position1));
14188
+ return {
14189
+ index: index1,
14190
+ atlasOffset: atlasOffset1
14191
+ };
13994
14192
  };
13995
- _proto.rebuildGraph = function rebuildGraph() {
13996
- this.playableGraph = new PlayableGraph();
13997
- this.compileTracks(this.playableGraph);
14193
+ _proto.getTextures = function getTextures() {
14194
+ var ret = [];
14195
+ var tex = this.renderer.texture;
14196
+ if (tex) {
14197
+ ret.push(tex);
14198
+ }
14199
+ return ret;
13998
14200
  };
13999
- _proto.compileTracks = function compileTracks(graph) {
14000
- for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
14001
- var track = _step.value;
14002
- var trackMixPlayable = track.createPlayable();
14003
- var trackOutput = track.createOutput();
14004
- graph.addOutput(trackOutput);
14005
- trackOutput.setSourcePlayeble(trackMixPlayable);
14201
+ /**
14202
+ * 获取图层包围盒的类型和世界坐标
14203
+ * @returns
14204
+ */ _proto.getBoundingBox = function getBoundingBox() {
14205
+ if (!this.item) {
14206
+ return;
14006
14207
  }
14208
+ var worldMatrix = this.transform.getWorldMatrix();
14209
+ var triangles = trianglesFromRect(Vector3.ZERO, 0.5 * this.transform.size.x, 0.5 * this.transform.size.y);
14210
+ triangles.forEach(function(triangle) {
14211
+ worldMatrix.transformPoint(triangle.p0);
14212
+ worldMatrix.transformPoint(triangle.p1);
14213
+ worldMatrix.transformPoint(triangle.p2);
14214
+ });
14215
+ return {
14216
+ type: HitTestType.triangle,
14217
+ area: triangles
14218
+ };
14007
14219
  };
14220
+ // TODO: [1.31] @十弦 https://github.com/galacean/effects-runtime/commit/fe8736540b9a461d8e96658f4d755ff8089a263b#diff-a3618f4527c5fe6e842f20d67d5c82984568502c6bf6fdfcbd24f69e2894ca90
14008
14221
  _proto.fromData = function fromData(data) {
14009
- ItemBehaviour.prototype.fromData.call(this, data);
14010
- this.options = {
14011
- start: this.item.start,
14012
- duration: this.item.duration,
14013
- looping: this.item.endBehavior === ItemEndBehavior.loop,
14014
- endBehavior: this.item.endBehavior || ItemEndBehavior.destroy
14015
- };
14016
- this.id = this.item.id;
14017
- this.name = this.item.name;
14018
- var activationTrack = this.createTrack(Track, "ActivationTrack");
14019
- activationTrack.createClip(ActivationPlayable, "ActivationTimelineClip");
14020
- //@ts-expect-error
14021
- if (data.tracks) {
14222
+ RendererComponent.prototype.fromData.call(this, data);
14223
+ var interaction = data.interaction, options = data.options, _data_listIndex = data.listIndex, listIndex = _data_listIndex === void 0 ? 0 : _data_listIndex;
14224
+ var renderer = data.renderer;
14225
+ if (!renderer) {
14022
14226
  //@ts-expect-error
14023
- var tracks = data.tracks;
14024
- for(var _iterator = _create_for_of_iterator_helper_loose(tracks), _step; !(_step = _iterator()).done;){
14025
- var track = _step.value;
14026
- var newTrack = this.createTrack(Track);
14027
- for(var _iterator1 = _create_for_of_iterator_helper_loose(track.clips), _step1; !(_step1 = _iterator1()).done;){
14028
- var clipAsset = _step1.value;
14029
- switch(clipAsset.dataType){
14030
- case "TransformAnimationPlayableAsset":
14031
- newTrack.name = "AnimationTrack";
14032
- newTrack.createClip(TransformAnimationPlayable, "AnimationTimelineClip").playable.fromData(clipAsset.animationClip);
14033
- break;
14034
- case "SpriteColorAnimationPlayableAsset":
14035
- newTrack.name = "SpriteColorTrack";
14036
- newTrack.createClip(SpriteColorPlayable, "SpriteColorClip").playable.fromData(clipAsset.animationClip);
14037
- break;
14038
- }
14039
- }
14040
- }
14227
+ renderer = {};
14041
14228
  }
14042
- };
14043
- _proto.toData = function toData() {
14044
- ItemBehaviour.prototype.toData.call(this);
14045
- };
14046
- return TimelineComponent;
14047
- }(ItemBehaviour);
14048
- __decorate([
14049
- serialize()
14050
- ], TimelineComponent.prototype, "time", void 0);
14051
-
14052
- var singleSplits = [
14053
- [
14054
- 0,
14055
- 0,
14056
- 1,
14057
- 1,
14058
- undefined
14059
- ]
14060
- ];
14061
- var tempColor = [
14062
- 1,
14063
- 1,
14064
- 1,
14065
- 1
14066
- ];
14067
- var seed$3 = 0;
14068
- var SpriteColorPlayable = /*#__PURE__*/ function(Playable) {
14069
- _inherits(SpriteColorPlayable, Playable);
14070
- function SpriteColorPlayable() {
14071
- var _this;
14072
- _this = Playable.apply(this, arguments) || this;
14073
- _this.renderColor = [
14229
+ this.interaction = interaction;
14230
+ var _renderer_renderMode, _renderer_blending, _renderer_texture, _renderer_side, _renderer_mask, _renderer_maskMode;
14231
+ this.renderer = {
14232
+ renderMode: (_renderer_renderMode = renderer.renderMode) != null ? _renderer_renderMode : RenderMode.BILLBOARD,
14233
+ blending: (_renderer_blending = renderer.blending) != null ? _renderer_blending : BlendingMode.ALPHA,
14234
+ texture: (_renderer_texture = renderer.texture) != null ? _renderer_texture : this.engine.emptyTexture,
14235
+ occlusion: !!renderer.occlusion,
14236
+ transparentOcclusion: !!renderer.transparentOcclusion || renderer.maskMode === MaskMode.MASK,
14237
+ side: (_renderer_side = renderer.side) != null ? _renderer_side : SideMode.DOUBLE,
14238
+ shape: renderer.shape,
14239
+ mask: (_renderer_mask = renderer.mask) != null ? _renderer_mask : 0,
14240
+ maskMode: (_renderer_maskMode = renderer.maskMode) != null ? _renderer_maskMode : MaskMode.NONE,
14241
+ order: listIndex
14242
+ };
14243
+ this.emptyTexture = this.engine.emptyTexture;
14244
+ this.splits = data.splits || singleSplits;
14245
+ this.textureSheetAnimation = data.textureSheetAnimation;
14246
+ this.cachePrefix = "-";
14247
+ this.renderInfo = getImageItemRenderInfo(this);
14248
+ var geometry = this.createGeometry(glContext.TRIANGLES);
14249
+ var material = this.createMaterial(this.renderInfo, 2);
14250
+ this.worldMatrix = Matrix4.fromIdentity();
14251
+ this.material = material;
14252
+ this.geometry = geometry;
14253
+ this.name = "MSprite" + seed$3++;
14254
+ var startColor = options.startColor || [
14074
14255
  1,
14075
14256
  1,
14076
14257
  1,
14077
14258
  1
14078
14259
  ];
14079
- return _this;
14080
- }
14081
- var _proto = SpriteColorPlayable.prototype;
14082
- _proto.onPlayablePlay = function onPlayablePlay() {
14083
- this.spriteMaterial = this.bindingItem.getComponent(SpriteComponent).material;
14084
- };
14085
- _proto.processFrame = function processFrame(dt) {
14086
- var colorInc = vecFill(tempColor, 1);
14087
- var colorChanged;
14088
- var life = this.time / this.bindingItem.duration;
14089
- var opacityOverLifetime = this.opacityOverLifetime;
14090
- var colorOverLifetime = this.colorOverLifetime;
14091
- if (colorOverLifetime) {
14092
- colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
14093
- colorChanged = true;
14094
- }
14095
- if (opacityOverLifetime) {
14096
- colorInc[3] *= opacityOverLifetime.getValue(life);
14097
- colorChanged = true;
14098
- }
14099
- if (colorChanged) {
14100
- vecMulCombine(this.renderColor, colorInc, this.startColor);
14101
- this.spriteMaterial.getVector4("_Color").setFromArray(this.renderColor);
14102
- }
14103
- };
14104
- _proto.fromData = function fromData(clipData) {
14105
- this.clipData = clipData;
14106
- var colorOverLifetime = clipData.colorOverLifetime;
14107
- if (colorOverLifetime) {
14108
- var _colorOverLifetime_opacity;
14109
- this.opacityOverLifetime = createValueGetter((_colorOverLifetime_opacity = colorOverLifetime.opacity) != null ? _colorOverLifetime_opacity : 1);
14110
- if (colorOverLifetime.color && colorOverLifetime.color[0] === ValueType.GRADIENT_COLOR) {
14111
- this.colorOverLifetime = colorStopsFromGradient(colorOverLifetime.color[1]);
14112
- }
14113
- }
14114
- this.startColor = clipData.startColor || [
14115
- 1,
14116
- 1,
14260
+ this.material.setVector4("_Color", new Vector4().setFromArray(startColor));
14261
+ this.material.setVector4("_TexOffset", new Vector4().setFromArray([
14262
+ 0,
14263
+ 0,
14117
14264
  1,
14118
14265
  1
14119
- ];
14120
- return this;
14266
+ ]));
14267
+ this.setItem();
14121
14268
  };
14122
- return SpriteColorPlayable;
14123
- }(Playable);
14124
- var SpriteComponent = /*#__PURE__*/ function(RendererComponent) {
14125
- _inherits(SpriteComponent, RendererComponent);
14126
- function SpriteComponent(engine, props) {
14127
- var _this;
14128
- _this = RendererComponent.call(this, engine) || this;
14129
- _this.color = [
14130
- 1,
14131
- 1,
14132
- 1,
14133
- 1
14134
- ];
14135
- _this.visible = true;
14136
- _this.getHitTestParams = function(force) {
14137
- var ui = _this.interaction;
14138
- if (force || ui) {
14139
- var area = _this.getBoundingBox();
14140
- if (area) {
14141
- var _this_interaction;
14142
- return {
14143
- behavior: ((_this_interaction = _this.interaction) == null ? void 0 : _this_interaction.behavior) || 0,
14144
- type: area.type,
14145
- triangles: area.area,
14146
- backfaceCulling: _this.renderer.side === SideMode.FRONT
14147
- };
14148
- }
14149
- }
14269
+ _proto.toData = function toData() {
14270
+ RendererComponent.prototype.toData.call(this);
14271
+ };
14272
+ return SpriteComponent;
14273
+ }(RendererComponent);
14274
+ SpriteComponent = __decorate([
14275
+ effectsClass(DataType.SpriteComponent)
14276
+ ], SpriteComponent);
14277
+
14278
+ var RUNTIME_ENV = "runtime_env";
14279
+ var RENDER_PREFER_LOOKUP_TEXTURE = "lookup_texture";
14280
+ // 文本元素使用 offscreen canvas 绘制
14281
+ var TEMPLATE_USE_OFFSCREEN_CANVAS = "offscreen_canvas";
14282
+ // 后处理配置相关
14283
+ var POST_PROCESS_SETTINGS = "post_process_settings";
14284
+ var config = {};
14285
+ function getConfig(name) {
14286
+ return config[name];
14287
+ }
14288
+ function setConfig(name, value) {
14289
+ return config[name] = value;
14290
+ }
14291
+
14292
+ var Cone = /*#__PURE__*/ function() {
14293
+ function Cone(props) {
14294
+ var _this = this;
14295
+ Object.keys(props).forEach(function(key) {
14296
+ _this[key] = props[key];
14297
+ });
14298
+ }
14299
+ var _proto = Cone.prototype;
14300
+ _proto.generate = function generate(opt) {
14301
+ var arc = getArcAngle(this.arc, this.arcMode, opt);
14302
+ var a = arc * DEG2RAD;
14303
+ var x = Math.cos(a) * this.radius;
14304
+ var y = Math.sin(a) * this.radius;
14305
+ var position = new Vector3(x, y, 0);
14306
+ var l = Math.tan(this.angle * DEG2RAD);
14307
+ var dir = position.clone().multiply(l);
14308
+ // dir + [0,0,1]
14309
+ dir.z += 1;
14310
+ return {
14311
+ position: position.multiply(random(0, 1)),
14312
+ direction: dir.normalize()
14150
14313
  };
14151
- if (props) {
14152
- _this.fromData(props);
14153
- }
14154
- return _this;
14314
+ };
14315
+ return Cone;
14316
+ }();
14317
+ function getArcAngle(arc, arcMode, opt) {
14318
+ if (arcMode === ShapeArcMode.RANDOM) {
14319
+ arc = random(0, arc);
14320
+ } else if (arcMode === ShapeArcMode.UNIDIRECTIONAL_CYCLE) {
14321
+ var d = opt.index % (opt.total + 1);
14322
+ arc = arc / opt.total * d;
14323
+ } else if (arcMode === ShapeArcMode.BIDIRECTIONAL_CYCLE) {
14324
+ var d1 = opt.index / (opt.total + 1);
14325
+ var i = d1 - Math.floor(d1);
14326
+ arc = arc * (Math.floor(d1) % 2 ? 1 - i : i);
14327
+ } else if (arcMode === ShapeArcMode.UNIFORM_BURST) {
14328
+ arc = arc * opt.burstIndex / opt.burstCount;
14155
14329
  }
14156
- var _proto = SpriteComponent.prototype;
14157
- /**
14158
- * 设置当前 Mesh 的可见性。
14159
- * @param visible - true:可见,false:不可见
14160
- */ _proto.setVisible = function setVisible(visible) {
14161
- this.visible = visible;
14330
+ return arc;
14331
+ }
14332
+
14333
+ var Circle = /*#__PURE__*/ function() {
14334
+ function Circle(props) {
14335
+ var _this = this;
14336
+ Object.keys(props).forEach(function(key) {
14337
+ _this[key] = props[key];
14338
+ });
14339
+ }
14340
+ var _proto = Circle.prototype;
14341
+ _proto.generate = function generate(opt) {
14342
+ var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14343
+ var direction = new Vector3(Math.cos(arc), Math.sin(arc), 0);
14344
+ var radius = this.radius;
14345
+ return {
14346
+ direction: direction,
14347
+ position: direction.clone().multiply(radius)
14348
+ };
14162
14349
  };
14163
- /**
14164
- * 获取当前 Mesh 的可见性。
14165
- */ _proto.getVisible = function getVisible() {
14166
- return this.visible;
14350
+ return Circle;
14351
+ }();
14352
+ var Rectangle = /*#__PURE__*/ function() {
14353
+ function Rectangle(arg) {
14354
+ this._d = (arg.width || 1) / 2;
14355
+ this._h = (arg.height || 1) / 2;
14356
+ }
14357
+ var _proto = Rectangle.prototype;
14358
+ _proto.generate = function generate(opt) {
14359
+ var x = random(-this._d, this._d);
14360
+ var y = random(-this._h, this._h);
14361
+ return {
14362
+ direction: new Vector3(0, 0, 1),
14363
+ position: new Vector3(x, y, 0)
14364
+ };
14167
14365
  };
14168
- /**
14169
- * 设置当前图层的颜色
14170
- * > Tips: 透明度也属于颜色的一部分,当有透明度/颜色 K 帧变化时,该 API 会失效
14171
- * @since 2.0.0
14172
- * @param color - 颜色值
14173
- */ _proto.setColor = function setColor(color) {
14174
- this.color = color;
14175
- this.material.setVector4("_Color", new Vector4().setFromArray(color));
14366
+ return Rectangle;
14367
+ }();
14368
+ var RectangleEdge = /*#__PURE__*/ function() {
14369
+ function RectangleEdge(arg) {
14370
+ this._d = (arg.width || 1) / 2;
14371
+ this._h = (arg.height || 1) / 2;
14372
+ this.arcMode = arg.arcMode;
14373
+ this.arc = arg.arc;
14374
+ }
14375
+ var _proto = RectangleEdge.prototype;
14376
+ _proto.generate = function generate(opt) {
14377
+ var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14378
+ var direction = new Vector3(Math.cos(arc), Math.sin(arc), 0);
14379
+ var w = this._d;
14380
+ var h = this._h;
14381
+ var r0 = Math.atan2(h, w);
14382
+ var tan = Math.tan(arc);
14383
+ var position = new Vector3();
14384
+ if (arc < r0) {
14385
+ position.set(w, w * tan, 0);
14386
+ } else if (arc >= r0 && arc < Math.PI - r0) {
14387
+ position.set(h / tan, h, 0);
14388
+ } else if (arc < Math.PI + r0) {
14389
+ position.set(-w, -w * tan, 0);
14390
+ } else if (arc < Math.PI * 2 - r0) {
14391
+ position.set(-h / tan, -h, 0);
14392
+ } else {
14393
+ position.set(w, w * tan, 0);
14394
+ }
14395
+ return {
14396
+ direction: direction,
14397
+ position: position
14398
+ };
14176
14399
  };
14177
- /**
14178
- * 设置当前 Mesh 的纹理
14179
- * @since 2.0.0
14180
- * @param texture - 纹理对象
14181
- */ _proto.setTexture = function setTexture(texture) {
14182
- this.renderer.texture = texture;
14183
- this.material.setTexture("uSampler0", texture);
14400
+ return RectangleEdge;
14401
+ }();
14402
+ var Edge = /*#__PURE__*/ function() {
14403
+ function Edge(args) {
14404
+ // TODO: 为通过帧对比暂时使用老计算,修复粒子发射器直线宽度问题下面一行改为: this._d = args.width || 1 ;
14405
+ this._d = (args.width || 1) / 2;
14406
+ this.arcMode = args.arcMode;
14407
+ }
14408
+ var _proto = Edge.prototype;
14409
+ _proto.generate = function generate(options) {
14410
+ var x = this.arcMode === ShapeArcMode.UNIFORM_BURST ? options.burstIndex % options.burstCount / (options.burstCount - 1) : random(0, 1);
14411
+ return {
14412
+ direction: new Vector3(0, 1, 0),
14413
+ position: new Vector3(this._d * (x - 0.5), 0, 0)
14414
+ };
14184
14415
  };
14185
- _proto.render = function render(renderer) {
14186
- if (!this.getVisible()) {
14187
- return;
14188
- }
14189
- var material = this.material;
14190
- var geo = this.geometry;
14191
- if (renderer.renderingData.currentFrame.globalUniforms) {
14192
- renderer.setGlobalMatrix("effects_ObjectToWorld", this.transform.getWorldMatrix());
14193
- }
14194
- this.material.setVector2("_Size", this.transform.size);
14195
- renderer.drawGeometry(geo, material);
14416
+ return Edge;
14417
+ }();
14418
+
14419
+ var tempMat4$2 = new Matrix4();
14420
+ var Donut = /*#__PURE__*/ function() {
14421
+ function Donut(props) {
14422
+ var _this = this;
14423
+ Object.keys(props).forEach(function(key) {
14424
+ _this[key] = props[key];
14425
+ });
14426
+ }
14427
+ var _proto = Donut.prototype;
14428
+ _proto.generate = function generate(opt) {
14429
+ var dradius = this.donutRadius;
14430
+ var center = this.radius - dradius;
14431
+ var angle = random(0, Math.PI * 2);
14432
+ var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14433
+ var rot = tempMat4$2.setFromRotationZ(arc);
14434
+ var direction = new Vector3(Math.cos(angle), Math.sin(angle), 0);
14435
+ var position = new Vector3(center + Math.cos(angle) * dradius, 0, Math.sin(angle) * dradius);
14436
+ return {
14437
+ direction: rot.transformNormal(direction),
14438
+ position: rot.transformPoint(position)
14439
+ };
14196
14440
  };
14197
- _proto.start = function start() {
14198
- this.priority = this.item.listIndex;
14199
- this.timelineComponent = this.item.getComponent(TimelineComponent);
14200
- this.item.getHitTestParams = this.getHitTestParams;
14441
+ return Donut;
14442
+ }();
14443
+
14444
+ var tempMat4$1 = new Matrix4();
14445
+ var Sphere = /*#__PURE__*/ function() {
14446
+ function Sphere(props) {
14447
+ var _this = this;
14448
+ Object.keys(props).forEach(function(key) {
14449
+ _this[key] = props[key];
14450
+ });
14451
+ }
14452
+ var _proto = Sphere.prototype;
14453
+ _proto.getHorizontalAngle = function getHorizontalAngle() {
14454
+ return random(-90, 90);
14201
14455
  };
14202
- _proto.update = function update(dt) {
14203
- var time = this.timelineComponent.getTime();
14204
- var duration = this.item.duration;
14205
- var life = Math.min(Math.max(time / duration, 0.0), 1.0);
14206
- var ta = this.textureSheetAnimation;
14207
- if (ta) {
14208
- var total = ta.total || ta.row * ta.col;
14209
- var texRectX = 0;
14210
- var texRectY = 0;
14211
- var texRectW = 1;
14212
- var texRectH = 1;
14213
- var flip;
14214
- if (this.splits) {
14215
- var sp = this.splits[0];
14216
- flip = sp[4];
14217
- texRectX = sp[0];
14218
- texRectY = sp[1];
14219
- if (flip) {
14220
- texRectW = sp[3];
14221
- texRectH = sp[2];
14222
- } else {
14223
- texRectW = sp[2];
14224
- texRectH = sp[3];
14225
- }
14226
- }
14227
- var dx, dy;
14228
- if (flip) {
14229
- dx = 1 / ta.row * texRectW;
14230
- dy = 1 / ta.col * texRectH;
14231
- } else {
14232
- dx = 1 / ta.col * texRectW;
14233
- dy = 1 / ta.row * texRectH;
14234
- }
14235
- var texOffset;
14236
- if (ta.animate) {
14237
- var frameIndex = Math.round(life * (total - 1));
14238
- var yIndex = Math.floor(frameIndex / ta.col);
14239
- var xIndex = frameIndex - yIndex * ta.col;
14240
- texOffset = flip ? [
14241
- dx * yIndex,
14242
- dy * (ta.col - xIndex)
14243
- ] : [
14244
- dx * xIndex,
14245
- dy * (1 + yIndex)
14246
- ];
14247
- } else {
14248
- texOffset = [
14249
- 0,
14250
- dy
14251
- ];
14252
- }
14253
- this.material.getVector4("_TexOffset").setFromArray([
14254
- texRectX + texOffset[0],
14255
- texRectH + texRectY - texOffset[1],
14256
- dx,
14257
- dy
14258
- ]);
14259
- }
14260
- };
14261
- _proto.onDestroy = function onDestroy() {
14262
- if (this.item && this.item.composition) {
14263
- this.item.composition.destroyTextures(this.getTextures());
14264
- }
14265
- };
14266
- _proto.getItemInitData = function getItemInitData(item, idx, pointStartIndex, textureIndex) {
14267
- var geoData = item.geoData;
14268
- if (!geoData) {
14269
- geoData = item.geoData = this.getItemGeometryData(item, idx);
14270
- }
14271
- var index = geoData.index;
14272
- var idxCount = index.length;
14273
- // @ts-expect-error
14274
- var indexData = this.wireframe ? new Uint8Array([
14275
- 0,
14276
- 1,
14277
- 1,
14278
- 3,
14279
- 2,
14280
- 3,
14281
- 2,
14282
- 0
14283
- ]) : new index.constructor(idxCount);
14284
- if (!this.wireframe) {
14285
- for(var i = 0; i < idxCount; i++){
14286
- indexData[i] = pointStartIndex + index[i];
14287
- }
14288
- }
14456
+ _proto.generate = function generate(opt) {
14457
+ var rz = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14458
+ var rh = this.getHorizontalAngle() * DEG2RAD;
14459
+ var radius = this.radius;
14460
+ var point = new Vector3(Math.cos(rh), 0, Math.sin(rh));
14461
+ var mat4 = tempMat4$1.setFromRotationZ(rz);
14462
+ var p = mat4.transformNormal(point);
14289
14463
  return {
14290
- atlasOffset: geoData.atlasOffset,
14291
- index: indexData
14292
- };
14293
- };
14294
- _proto.setItem = function setItem() {
14295
- var textures = [];
14296
- var texture = this.renderer.texture;
14297
- if (texture) {
14298
- addItem(textures, texture);
14299
- }
14300
- texture = this.renderer.texture;
14301
- var textureIndex = texture ? textures.indexOf(texture) : -1;
14302
- var data = this.getItemInitData(this, 0, 0, textureIndex);
14303
- var renderer = this.renderer;
14304
- var texParams = this.material.getVector4("_TexParams");
14305
- texParams.x = renderer.occlusion ? +renderer.transparentOcclusion : 1;
14306
- texParams.y = +this.preMultiAlpha;
14307
- texParams.z = renderer.renderMode;
14308
- var attributes = {
14309
- atlasOffset: new Float32Array(data.atlasOffset.length),
14310
- index: new Uint16Array(data.index.length)
14464
+ position: p.clone().multiply(radius),
14465
+ direction: p
14311
14466
  };
14312
- attributes.atlasOffset.set(data.atlasOffset);
14313
- attributes.index.set(data.index);
14314
- var _this = this, material = _this.material, geometry = _this.geometry;
14315
- var indexData = attributes.index;
14316
- geometry.setIndexData(indexData);
14317
- geometry.setAttributeData("atlasOffset", attributes.atlasOffset);
14318
- geometry.setDrawCount(data.index.length);
14319
- for(var i = 0; i < textures.length; i++){
14320
- var texture1 = textures[i];
14321
- material.setTexture("uSampler" + i, texture1);
14322
- }
14323
- // FIXME: 内存泄漏的临时方案,后面再调整
14324
- var emptyTexture = this.emptyTexture;
14325
- for(var k = textures.length; k < maxSpriteMeshItemCount; k++){
14326
- material.setTexture("uSampler" + k, emptyTexture);
14327
- }
14328
14467
  };
14329
- _proto.createGeometry = function createGeometry(mode) {
14330
- var maxVertex = 12 * this.splits.length;
14331
- return Geometry.create(this.engine, {
14332
- attributes: {
14333
- aPos: {
14334
- type: glContext.FLOAT,
14335
- size: 3,
14336
- data: new Float32Array([
14337
- -0.5,
14338
- 0.5,
14339
- 0,
14340
- -0.5,
14341
- -0.5,
14342
- 0,
14343
- 0.5,
14344
- 0.5,
14345
- 0,
14346
- 0.5,
14347
- -0.5,
14348
- 0
14349
- ])
14350
- },
14351
- atlasOffset: {
14352
- size: 2,
14353
- offset: 0,
14354
- releasable: true,
14355
- type: glContext.FLOAT,
14356
- data: new Float32Array(0)
14357
- }
14358
- },
14359
- indices: {
14360
- data: new Uint16Array(0),
14361
- releasable: true
14362
- },
14363
- mode: mode,
14364
- maxVertex: maxVertex
14365
- });
14468
+ return Sphere;
14469
+ }();
14470
+ var Hemisphere = /*#__PURE__*/ function(Sphere) {
14471
+ _inherits(Hemisphere, Sphere);
14472
+ function Hemisphere() {
14473
+ return Sphere.apply(this, arguments);
14474
+ }
14475
+ var _proto = Hemisphere.prototype;
14476
+ _proto.getHorizontalAngle = function getHorizontalAngle() {
14477
+ return random(0, 90);
14366
14478
  };
14367
- _proto.createMaterial = function createMaterial(renderInfo, count) {
14368
- var side = renderInfo.side, occlusion = renderInfo.occlusion, blending = renderInfo.blending, maskMode = renderInfo.maskMode, mask = renderInfo.mask;
14369
- var materialProps = {
14370
- shader: spriteMeshShaderFromRenderInfo(renderInfo, count, 1)
14479
+ return Hemisphere;
14480
+ }(Sphere);
14481
+
14482
+ var TextureShape = /*#__PURE__*/ function() {
14483
+ function TextureShape(arg) {
14484
+ var detail = arg.detail || {
14485
+ anchors: [
14486
+ 0.5,
14487
+ 0.5
14488
+ ],
14489
+ block: [
14490
+ 0,
14491
+ 0
14492
+ ]
14371
14493
  };
14372
- this.preMultiAlpha = getPreMultiAlpha(blending);
14373
- var material = Material.create(this.engine, materialProps);
14374
- var states = {
14375
- side: side,
14376
- blending: true,
14377
- blendMode: blending,
14378
- mask: mask,
14379
- maskMode: maskMode,
14380
- depthTest: true,
14381
- depthMask: occlusion
14494
+ this.anchors = new Float32Array(detail.anchors);
14495
+ this.width = arg.width || 1;
14496
+ this.height = arg.height || 1;
14497
+ this.block = detail.block;
14498
+ this.arcMode = arg.arcMode;
14499
+ this.random = clamp$1(arg.random || 0, 0, 1);
14500
+ }
14501
+ var _proto = TextureShape.prototype;
14502
+ _proto.generate = function generate(opt) {
14503
+ var anchors = this.anchors;
14504
+ var pointCount = anchors.length / 2 - 1;
14505
+ var index = Math.floor(getArcAngle(pointCount, this.arcMode, opt));
14506
+ var pointX = (anchors[index * 2] + this.block[0] * this.random * Math.random()) % 1 - 0.5;
14507
+ var pointY = (anchors[index * 2 + 1] + this.block[1] * this.random * Math.random()) % 1 - 0.5;
14508
+ var dir = new Vector3(pointX, pointY, 0);
14509
+ return {
14510
+ position: new Vector3(pointX * this.width, pointY * this.height, 0),
14511
+ direction: dir.normalize()
14382
14512
  };
14383
- material.blending = states.blending;
14384
- material.stencilRef = states.mask !== undefined ? [
14385
- states.mask,
14386
- states.mask
14387
- ] : undefined;
14388
- material.depthTest = states.depthTest;
14389
- material.depthMask = states.depthMask;
14390
- setBlendMode(material, states.blendMode);
14391
- setMaskMode(material, states.maskMode);
14392
- setSideMode(material, states.side);
14393
- if (!material.hasUniform("_Color")) {
14394
- material.setVector4("_Color", new Vector4(0, 0, 0, 1));
14395
- }
14396
- if (!material.hasUniform("_TexOffset")) {
14397
- material.setVector4("_TexOffset", new Vector4());
14398
- }
14399
- if (!material.hasUniform("_TexParams")) {
14400
- material.setVector4("_TexParams", new Vector4());
14401
- }
14402
- return material;
14403
14513
  };
14404
- _proto.getItemGeometryData = function getItemGeometryData(item, aIndex) {
14405
- var splits = item.splits, renderer = item.renderer, textureSheetAnimation = item.textureSheetAnimation;
14406
- var sx = 1, sy = 1;
14407
- if (renderer.shape) {
14408
- var _renderer_shape = renderer.shape, index = _renderer_shape.index, aPoint = _renderer_shape.aPoint;
14409
- var point = new Float32Array(aPoint);
14410
- var position = [];
14411
- var atlasOffset = [];
14412
- for(var i = 0; i < point.length; i += 6){
14413
- point[i] *= sx;
14414
- point[i + 1] *= sy;
14415
- atlasOffset.push(aPoint[i + 2], aPoint[i + 3]);
14416
- position.push(point[i], point[i + 1], 0.0);
14417
- }
14418
- this.geometry.setAttributeData("aPos", new Float32Array(position));
14419
- return {
14420
- index: index,
14421
- atlasOffset: atlasOffset
14422
- };
14423
- }
14424
- var originData = [
14425
- -.5,
14426
- .5,
14427
- -.5,
14428
- -.5,
14429
- .5,
14430
- .5,
14431
- .5,
14432
- -.5
14433
- ];
14434
- var atlasOffset1 = [];
14435
- var index1 = [];
14436
- var col = 2;
14437
- var row = 2;
14438
- if (splits.length === 1) {
14439
- col = 1;
14440
- row = 1;
14441
- }
14442
- var position1 = [];
14443
- for(var x = 0; x < col; x++){
14444
- for(var y = 0; y < row; y++){
14445
- var base = (y * 2 + x) * 4;
14446
- // @ts-expect-error
14447
- var split = textureSheetAnimation ? [
14448
- 0,
14449
- 0,
14450
- 1,
14451
- 1,
14452
- splits[0][4]
14453
- ] : splits[y * 2 + x];
14454
- var texOffset = split[4] ? [
14455
- 0,
14456
- 0,
14457
- 1,
14458
- 0,
14459
- 0,
14460
- 1,
14461
- 1,
14462
- 1
14463
- ] : [
14464
- 0,
14465
- 1,
14466
- 0,
14467
- 0,
14468
- 1,
14469
- 1,
14470
- 1,
14471
- 0
14472
- ];
14473
- var dw = ((x + x + 1) / col - 1) / 2;
14474
- var dh = ((y + y + 1) / row - 1) / 2;
14475
- var tox = split[0];
14476
- var toy = split[1];
14477
- var tsx = split[4] ? split[3] : split[2];
14478
- var tsy = split[4] ? split[2] : split[3];
14479
- var origin = [
14480
- originData[0] / col + dw,
14481
- originData[1] / row + dh,
14482
- originData[2] / col + dw,
14483
- originData[3] / row + dh,
14484
- originData[4] / col + dw,
14485
- originData[5] / row + dh,
14486
- originData[6] / col + dw,
14487
- originData[7] / row + dh
14488
- ];
14489
- 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);
14490
- 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);
14491
- index1.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
14492
- }
14493
- }
14494
- this.geometry.setAttributeData("aPos", new Float32Array(position1));
14495
- return {
14496
- index: index1,
14497
- atlasOffset: atlasOffset1
14498
- };
14499
- };
14500
- _proto.getTextures = function getTextures() {
14501
- var ret = [];
14502
- var tex = this.renderer.texture;
14503
- if (tex) {
14504
- ret.push(tex);
14505
- }
14506
- return ret;
14507
- };
14508
- /**
14509
- * 获取图层包围盒的类型和世界坐标
14510
- * @returns
14511
- */ _proto.getBoundingBox = function getBoundingBox() {
14512
- if (!this.item) {
14513
- return;
14514
- }
14515
- var worldMatrix = this.transform.getWorldMatrix();
14516
- var triangles = trianglesFromRect(Vector3.ZERO, 1 / 2, 1 / 2);
14517
- triangles.forEach(function(triangle) {
14518
- worldMatrix.transformPoint(triangle.p0);
14519
- worldMatrix.transformPoint(triangle.p1);
14520
- worldMatrix.transformPoint(triangle.p2);
14521
- });
14514
+ return TextureShape;
14515
+ }();
14516
+
14517
+ var ShapeNone = /*#__PURE__*/ function() {
14518
+ function ShapeNone() {}
14519
+ var _proto = ShapeNone.prototype;
14520
+ _proto.generate = function generate() {
14522
14521
  return {
14523
- type: HitTestType.triangle,
14524
- area: triangles
14522
+ position: new Vector3(),
14523
+ direction: new Vector3()
14525
14524
  };
14526
14525
  };
14527
- // TODO: [1.31] @十弦 https://github.com/galacean/effects-runtime/commit/fe8736540b9a461d8e96658f4d755ff8089a263b#diff-a3618f4527c5fe6e842f20d67d5c82984568502c6bf6fdfcbd24f69e2894ca90
14528
- _proto.fromData = function fromData(data) {
14529
- RendererComponent.prototype.fromData.call(this, data);
14530
- var interaction = data.interaction, options = data.options, _data_listIndex = data.listIndex, listIndex = _data_listIndex === void 0 ? 0 : _data_listIndex;
14531
- var renderer = data.renderer;
14532
- if (!renderer) {
14533
- //@ts-expect-error
14534
- renderer = {};
14535
- }
14536
- this.interaction = interaction;
14537
- var _renderer_renderMode, _renderer_blending, _renderer_texture, _renderer_side, _renderer_mask, _renderer_maskMode;
14538
- this.renderer = {
14539
- renderMode: (_renderer_renderMode = renderer.renderMode) != null ? _renderer_renderMode : RenderMode.BILLBOARD,
14540
- blending: (_renderer_blending = renderer.blending) != null ? _renderer_blending : BlendingMode.ALPHA,
14541
- texture: (_renderer_texture = renderer.texture) != null ? _renderer_texture : this.engine.emptyTexture,
14542
- occlusion: !!renderer.occlusion,
14543
- transparentOcclusion: !!renderer.transparentOcclusion || renderer.maskMode === MaskMode.MASK,
14544
- side: (_renderer_side = renderer.side) != null ? _renderer_side : SideMode.DOUBLE,
14545
- shape: renderer.shape,
14546
- mask: (_renderer_mask = renderer.mask) != null ? _renderer_mask : 0,
14547
- maskMode: (_renderer_maskMode = renderer.maskMode) != null ? _renderer_maskMode : MaskMode.NONE,
14548
- order: listIndex
14549
- };
14550
- this.emptyTexture = this.engine.emptyTexture;
14551
- this.splits = data.splits || singleSplits;
14552
- this.textureSheetAnimation = data.textureSheetAnimation;
14553
- this.cachePrefix = "-";
14554
- this.renderInfo = getImageItemRenderInfo(this);
14555
- var geometry = this.createGeometry(glContext.TRIANGLES);
14556
- var material = this.createMaterial(this.renderInfo, 2);
14557
- this.worldMatrix = Matrix4.fromIdentity();
14558
- this.material = material;
14559
- this.geometry = geometry;
14560
- this.name = "MSprite" + seed$3++;
14561
- var startColor = options.startColor || [
14562
- 1,
14563
- 1,
14564
- 1,
14565
- 1
14566
- ];
14567
- this.material.setVector4("_Color", new Vector4().setFromArray(startColor));
14568
- this.material.setVector4("_TexOffset", new Vector4().setFromArray([
14526
+ return ShapeNone;
14527
+ }();
14528
+ var _obj$3;
14529
+ var map = (_obj$3 = {}, _obj$3[ShapeType.NONE] = ShapeNone, _obj$3[ShapeType.CONE] = Cone, _obj$3[ShapeType.SPHERE] = Sphere, _obj$3[ShapeType.HEMISPHERE] = Hemisphere, _obj$3[ShapeType.CIRCLE] = Circle, _obj$3[ShapeType.DONUT] = Donut, _obj$3[ShapeType.RECTANGLE] = Rectangle, _obj$3[ShapeType.EDGE] = Edge, _obj$3[ShapeType.RECTANGLE_EDGE] = RectangleEdge, _obj$3[ShapeType.TEXTURE] = TextureShape, _obj$3);
14530
+ function createShape(shapeOptions) {
14531
+ if (!shapeOptions) {
14532
+ return new ShapeNone();
14533
+ }
14534
+ var options = _extends({
14535
+ radius: 1,
14536
+ arc: 360,
14537
+ angle: 0,
14538
+ arcMode: ShapeArcMode.RANDOM
14539
+ }, shapeOptions);
14540
+ var type = shapeOptions.type;
14541
+ var Ctrl = map[type];
14542
+ if (!Ctrl) {
14543
+ throw Error("invalid shape:" + type);
14544
+ }
14545
+ var ctrl = new Ctrl(options);
14546
+ if (type !== ShapeType.NONE) {
14547
+ var alignSpeedDirection = shapeOptions.alignSpeedDirection, _shapeOptions_upDirection = shapeOptions.upDirection, upDirection = _shapeOptions_upDirection === void 0 ? [
14569
14548
  0,
14570
14549
  0,
14571
- 1,
14572
14550
  1
14573
- ]));
14574
- this.setItem();
14575
- };
14576
- _proto.toData = function toData() {
14577
- RendererComponent.prototype.toData.call(this);
14578
- };
14579
- return SpriteComponent;
14580
- }(RendererComponent);
14581
- SpriteComponent = __decorate([
14582
- effectsClass(DataType.SpriteComponent)
14583
- ], SpriteComponent);
14584
-
14585
- var RUNTIME_ENV = "runtime_env";
14586
- var RENDER_PREFER_LOOKUP_TEXTURE = "lookup_texture";
14587
- // 文本元素使用 offscreen canvas 绘制
14588
- var TEMPLATE_USE_OFFSCREEN_CANVAS = "offscreen_canvas";
14589
- // 后处理配置相关
14590
- var POST_PROCESS_SETTINGS = "post_process_settings";
14591
- var config = {};
14592
- function getConfig(name) {
14593
- return config[name];
14594
- }
14595
- function setConfig(name, value) {
14596
- return config[name] = value;
14551
+ ] : _shapeOptions_upDirection;
14552
+ ctrl.alignSpeedDirection = alignSpeedDirection;
14553
+ ctrl.upDirection = Vector3.fromArray(upDirection).normalize();
14554
+ }
14555
+ return ctrl;
14597
14556
  }
14598
14557
 
14599
- var Cone = /*#__PURE__*/ function() {
14600
- function Cone(props) {
14601
- var _this = this;
14602
- Object.keys(props).forEach(function(key) {
14603
- _this[key] = props[key];
14604
- });
14558
+ // create a circular doubly linked list from polygon points in the specified winding order
14559
+ function linkedList(data, start, end, dim, clockwise) {
14560
+ var i, last;
14561
+ if (clockwise === signedArea(data, start, end, dim) > 0) {
14562
+ for(i = start; i < end; i += dim)last = insertNode(i, data[i], data[i + 1], last);
14563
+ } else {
14564
+ for(i = end - dim; i >= start; i -= dim)last = insertNode(i, data[i], data[i + 1], last);
14605
14565
  }
14606
- var _proto = Cone.prototype;
14607
- _proto.generate = function generate(opt) {
14608
- var arc = getArcAngle(this.arc, this.arcMode, opt);
14609
- var a = arc * DEG2RAD;
14610
- var x = Math.cos(a) * this.radius;
14611
- var y = Math.sin(a) * this.radius;
14612
- var position = new Vector3(x, y, 0);
14613
- var l = Math.tan(this.angle * DEG2RAD);
14614
- var dir = position.clone().multiply(l);
14615
- // dir + [0,0,1]
14616
- dir.z += 1;
14617
- return {
14618
- position: position.multiply(random(0, 1)),
14619
- direction: dir.normalize()
14620
- };
14621
- };
14622
- return Cone;
14623
- }();
14624
- function getArcAngle(arc, arcMode, opt) {
14625
- if (arcMode === ShapeArcMode.RANDOM) {
14626
- arc = random(0, arc);
14627
- } else if (arcMode === ShapeArcMode.UNIDIRECTIONAL_CYCLE) {
14628
- var d = opt.index % (opt.total + 1);
14629
- arc = arc / opt.total * d;
14630
- } else if (arcMode === ShapeArcMode.BIDIRECTIONAL_CYCLE) {
14631
- var d1 = opt.index / (opt.total + 1);
14632
- var i = d1 - Math.floor(d1);
14633
- arc = arc * (Math.floor(d1) % 2 ? 1 - i : i);
14634
- } else if (arcMode === ShapeArcMode.UNIFORM_BURST) {
14635
- arc = arc * opt.burstIndex / opt.burstCount;
14566
+ if (last && equals(last, last.next)) {
14567
+ removeNode(last);
14568
+ last = last.next;
14636
14569
  }
14637
- return arc;
14638
- }
14639
-
14640
- var Circle = /*#__PURE__*/ function() {
14641
- function Circle(props) {
14642
- var _this = this;
14643
- Object.keys(props).forEach(function(key) {
14644
- _this[key] = props[key];
14645
- });
14646
- }
14647
- var _proto = Circle.prototype;
14648
- _proto.generate = function generate(opt) {
14649
- var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14650
- var direction = new Vector3(Math.cos(arc), Math.sin(arc), 0);
14651
- var radius = this.radius;
14652
- return {
14653
- direction: direction,
14654
- position: direction.clone().multiply(radius)
14655
- };
14656
- };
14657
- return Circle;
14658
- }();
14659
- var Rectangle = /*#__PURE__*/ function() {
14660
- function Rectangle(arg) {
14661
- this._d = (arg.width || 1) / 2;
14662
- this._h = (arg.height || 1) / 2;
14663
- }
14664
- var _proto = Rectangle.prototype;
14665
- _proto.generate = function generate(opt) {
14666
- var x = random(-this._d, this._d);
14667
- var y = random(-this._h, this._h);
14668
- return {
14669
- direction: new Vector3(0, 0, 1),
14670
- position: new Vector3(x, y, 0)
14671
- };
14672
- };
14673
- return Rectangle;
14674
- }();
14675
- var RectangleEdge = /*#__PURE__*/ function() {
14676
- function RectangleEdge(arg) {
14677
- this._d = (arg.width || 1) / 2;
14678
- this._h = (arg.height || 1) / 2;
14679
- this.arcMode = arg.arcMode;
14680
- this.arc = arg.arc;
14681
- }
14682
- var _proto = RectangleEdge.prototype;
14683
- _proto.generate = function generate(opt) {
14684
- var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14685
- var direction = new Vector3(Math.cos(arc), Math.sin(arc), 0);
14686
- var w = this._d;
14687
- var h = this._h;
14688
- var r0 = Math.atan2(h, w);
14689
- var tan = Math.tan(arc);
14690
- var position = new Vector3();
14691
- if (arc < r0) {
14692
- position.set(w, w * tan, 0);
14693
- } else if (arc >= r0 && arc < Math.PI - r0) {
14694
- position.set(h / tan, h, 0);
14695
- } else if (arc < Math.PI + r0) {
14696
- position.set(-w, -w * tan, 0);
14697
- } else if (arc < Math.PI * 2 - r0) {
14698
- position.set(-h / tan, -h, 0);
14699
- } else {
14700
- position.set(w, w * tan, 0);
14701
- }
14702
- return {
14703
- direction: direction,
14704
- position: position
14705
- };
14706
- };
14707
- return RectangleEdge;
14708
- }();
14709
- var Edge = /*#__PURE__*/ function() {
14710
- function Edge(args) {
14711
- // TODO: 为通过帧对比暂时使用老计算,修复粒子发射器直线宽度问题下面一行改为: this._d = args.width || 1 ;
14712
- this._d = (args.width || 1) / 2;
14713
- this.arcMode = args.arcMode;
14714
- }
14715
- var _proto = Edge.prototype;
14716
- _proto.generate = function generate(options) {
14717
- var x = this.arcMode === ShapeArcMode.UNIFORM_BURST ? options.burstIndex % options.burstCount / (options.burstCount - 1) : random(0, 1);
14718
- return {
14719
- direction: new Vector3(0, 1, 0),
14720
- position: new Vector3(this._d * (x - 0.5), 0, 0)
14721
- };
14722
- };
14723
- return Edge;
14724
- }();
14725
-
14726
- var tempMat4$2 = new Matrix4();
14727
- var Donut = /*#__PURE__*/ function() {
14728
- function Donut(props) {
14729
- var _this = this;
14730
- Object.keys(props).forEach(function(key) {
14731
- _this[key] = props[key];
14732
- });
14733
- }
14734
- var _proto = Donut.prototype;
14735
- _proto.generate = function generate(opt) {
14736
- var dradius = this.donutRadius;
14737
- var center = this.radius - dradius;
14738
- var angle = random(0, Math.PI * 2);
14739
- var arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14740
- var rot = tempMat4$2.setFromRotationZ(arc);
14741
- var direction = new Vector3(Math.cos(angle), Math.sin(angle), 0);
14742
- var position = new Vector3(center + Math.cos(angle) * dradius, 0, Math.sin(angle) * dradius);
14743
- return {
14744
- direction: rot.transformNormal(direction),
14745
- position: rot.transformPoint(position)
14746
- };
14747
- };
14748
- return Donut;
14749
- }();
14750
-
14751
- var tempMat4$1 = new Matrix4();
14752
- var Sphere = /*#__PURE__*/ function() {
14753
- function Sphere(props) {
14754
- var _this = this;
14755
- Object.keys(props).forEach(function(key) {
14756
- _this[key] = props[key];
14757
- });
14758
- }
14759
- var _proto = Sphere.prototype;
14760
- _proto.getHorizontalAngle = function getHorizontalAngle() {
14761
- return random(-90, 90);
14762
- };
14763
- _proto.generate = function generate(opt) {
14764
- var rz = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
14765
- var rh = this.getHorizontalAngle() * DEG2RAD;
14766
- var radius = this.radius;
14767
- var point = new Vector3(Math.cos(rh), 0, Math.sin(rh));
14768
- var mat4 = tempMat4$1.setFromRotationZ(rz);
14769
- var p = mat4.transformNormal(point);
14770
- return {
14771
- position: p.clone().multiply(radius),
14772
- direction: p
14773
- };
14774
- };
14775
- return Sphere;
14776
- }();
14777
- var Hemisphere = /*#__PURE__*/ function(Sphere) {
14778
- _inherits(Hemisphere, Sphere);
14779
- function Hemisphere() {
14780
- return Sphere.apply(this, arguments);
14781
- }
14782
- var _proto = Hemisphere.prototype;
14783
- _proto.getHorizontalAngle = function getHorizontalAngle() {
14784
- return random(0, 90);
14785
- };
14786
- return Hemisphere;
14787
- }(Sphere);
14788
-
14789
- var TextureShape = /*#__PURE__*/ function() {
14790
- function TextureShape(arg) {
14791
- var detail = arg.detail || {
14792
- anchors: [
14793
- 0.5,
14794
- 0.5
14795
- ],
14796
- block: [
14797
- 0,
14798
- 0
14799
- ]
14800
- };
14801
- this.anchors = new Float32Array(detail.anchors);
14802
- this.width = arg.width || 1;
14803
- this.height = arg.height || 1;
14804
- this.block = detail.block;
14805
- this.arcMode = arg.arcMode;
14806
- this.random = clamp$1(arg.random || 0, 0, 1);
14807
- }
14808
- var _proto = TextureShape.prototype;
14809
- _proto.generate = function generate(opt) {
14810
- var anchors = this.anchors;
14811
- var pointCount = anchors.length / 2 - 1;
14812
- var index = Math.floor(getArcAngle(pointCount, this.arcMode, opt));
14813
- var pointX = (anchors[index * 2] + this.block[0] * this.random * Math.random()) % 1 - 0.5;
14814
- var pointY = (anchors[index * 2 + 1] + this.block[1] * this.random * Math.random()) % 1 - 0.5;
14815
- var dir = new Vector3(pointX, pointY, 0);
14816
- return {
14817
- position: new Vector3(pointX * this.width, pointY * this.height, 0),
14818
- direction: dir.normalize()
14819
- };
14820
- };
14821
- return TextureShape;
14822
- }();
14823
-
14824
- var ShapeNone = /*#__PURE__*/ function() {
14825
- function ShapeNone() {}
14826
- var _proto = ShapeNone.prototype;
14827
- _proto.generate = function generate() {
14828
- return {
14829
- position: new Vector3(),
14830
- direction: new Vector3()
14831
- };
14832
- };
14833
- return ShapeNone;
14834
- }();
14835
- var _obj$3;
14836
- var map = (_obj$3 = {}, _obj$3[ShapeType.NONE] = ShapeNone, _obj$3[ShapeType.CONE] = Cone, _obj$3[ShapeType.SPHERE] = Sphere, _obj$3[ShapeType.HEMISPHERE] = Hemisphere, _obj$3[ShapeType.CIRCLE] = Circle, _obj$3[ShapeType.DONUT] = Donut, _obj$3[ShapeType.RECTANGLE] = Rectangle, _obj$3[ShapeType.EDGE] = Edge, _obj$3[ShapeType.RECTANGLE_EDGE] = RectangleEdge, _obj$3[ShapeType.TEXTURE] = TextureShape, _obj$3);
14837
- function createShape(shapeOptions) {
14838
- if (!shapeOptions) {
14839
- return new ShapeNone();
14840
- }
14841
- var options = _extends({
14842
- radius: 1,
14843
- arc: 360,
14844
- angle: 0,
14845
- arcMode: ShapeArcMode.RANDOM
14846
- }, shapeOptions);
14847
- var type = shapeOptions.type;
14848
- var Ctrl = map[type];
14849
- if (!Ctrl) {
14850
- throw Error("invalid shape:" + type);
14851
- }
14852
- var ctrl = new Ctrl(options);
14853
- if (type !== ShapeType.NONE) {
14854
- var alignSpeedDirection = shapeOptions.alignSpeedDirection, _shapeOptions_upDirection = shapeOptions.upDirection, upDirection = _shapeOptions_upDirection === void 0 ? [
14855
- 0,
14856
- 0,
14857
- 1
14858
- ] : _shapeOptions_upDirection;
14859
- ctrl.alignSpeedDirection = alignSpeedDirection;
14860
- ctrl.upDirection = Vector3.fromArray(upDirection).normalize();
14861
- }
14862
- return ctrl;
14863
- }
14864
-
14865
- // create a circular doubly linked list from polygon points in the specified winding order
14866
- function linkedList(data, start, end, dim, clockwise) {
14867
- var i, last;
14868
- if (clockwise === signedArea(data, start, end, dim) > 0) {
14869
- for(i = start; i < end; i += dim)last = insertNode(i, data[i], data[i + 1], last);
14870
- } else {
14871
- for(i = end - dim; i >= start; i -= dim)last = insertNode(i, data[i], data[i + 1], last);
14872
- }
14873
- if (last && equals(last, last.next)) {
14874
- removeNode(last);
14875
- last = last.next;
14876
- }
14877
- return last;
14570
+ return last;
14878
14571
  }
14879
14572
  // eliminate colinear or duplicate points
14880
14573
  function filterPoints(start, end) {
@@ -15216,274 +14909,889 @@ function earcut(data, holeIndices, dim, ib) {
15216
14909
  if (!outerNode || outerNode.next === outerNode.prev) {
15217
14910
  return triangles;
15218
14911
  }
15219
- var minX, minY, maxX, maxY, x, y, invSize;
15220
- if (hasHoles) {
15221
- outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
14912
+ var minX, minY, maxX, maxY, x, y, invSize;
14913
+ if (hasHoles) {
14914
+ outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
14915
+ }
14916
+ // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
14917
+ if (data.length > 80 * dim) {
14918
+ minX = maxX = data[0];
14919
+ minY = maxY = data[1];
14920
+ for(var i = dim; i < outerLen; i += dim){
14921
+ x = data[i];
14922
+ y = data[i + 1];
14923
+ if (x < minX) {
14924
+ minX = x;
14925
+ }
14926
+ if (y < minY) {
14927
+ minY = y;
14928
+ }
14929
+ if (x > maxX) {
14930
+ maxX = x;
14931
+ }
14932
+ if (y > maxY) {
14933
+ maxY = y;
14934
+ }
14935
+ }
14936
+ // minX, minY and invSize are later used to transform coords into integers for z-order calculation
14937
+ invSize = Math.max(maxX - minX, maxY - minY);
14938
+ invSize = invSize !== 0 ? 1 / invSize : 0;
14939
+ }
14940
+ hackEarcutLinked(outerNode, triangles, dim, minX, minY, invSize);
14941
+ return triangles;
14942
+ }
14943
+ // main ear slicing loop which triangulates a polygon (given as a linked list)
14944
+ function hackEarcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
14945
+ if (!ear) {
14946
+ return;
14947
+ }
14948
+ // interlink polygon nodes in z-order
14949
+ if (!pass && invSize) {
14950
+ indexCurve(ear, minX, minY, invSize);
14951
+ }
14952
+ var stop = ear, prev, next;
14953
+ // iterate through ears, slicing them one by one
14954
+ while(ear.prev !== ear.next){
14955
+ prev = ear.prev;
14956
+ next = ear.next;
14957
+ if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
14958
+ // cut off the triangle
14959
+ triangles.push(prev.i / dim + indexBase);
14960
+ triangles.push(ear.i / dim + indexBase);
14961
+ triangles.push(next.i / dim + indexBase);
14962
+ removeNode(ear);
14963
+ // skipping the next vertex leads to less sliver triangles
14964
+ ear = next.next;
14965
+ stop = next.next;
14966
+ continue;
14967
+ }
14968
+ ear = next;
14969
+ // if we looped through the whole remaining polygon and can't find any more ears
14970
+ if (ear === stop) {
14971
+ // try filtering triangles and slicing again
14972
+ if (!pass) {
14973
+ hackEarcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
14974
+ // if this didn't work, try curing all small self-intersections locally
14975
+ } else if (pass === 1) {
14976
+ ear = hackCureLocalIntersections(filterPoints(ear), triangles, dim);
14977
+ hackEarcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
14978
+ // as a last resort, try splitting the remaining polygon into two
14979
+ } else if (pass === 2) {
14980
+ hackSplitEarcut(ear, triangles, dim, minX, minY, invSize);
14981
+ }
14982
+ break;
14983
+ }
14984
+ }
14985
+ }
14986
+ // go through all polygon nodes and cure small local self-intersections
14987
+ function hackCureLocalIntersections(start, triangles, dim) {
14988
+ var p = start;
14989
+ do {
14990
+ var a = p.prev, b = p.next.next;
14991
+ if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
14992
+ triangles.push(a.i / dim + indexBase);
14993
+ triangles.push(p.i / dim + indexBase);
14994
+ triangles.push(b.i / dim + indexBase);
14995
+ // remove two nodes involved
14996
+ removeNode(p);
14997
+ removeNode(p.next);
14998
+ p = start = b;
14999
+ }
15000
+ p = p.next;
15001
+ }while (p !== start);
15002
+ return filterPoints(p);
15003
+ }
15004
+ // try splitting polygon into two and triangulate them independently
15005
+ function hackSplitEarcut(start, triangles, dim, minX, minY, invSize) {
15006
+ // look for a valid diagonal that divides the polygon into two
15007
+ var a = start;
15008
+ do {
15009
+ var b = a.next.next;
15010
+ while(b !== a.prev){
15011
+ if (a.i !== b.i && isValidDiagonal(a, b)) {
15012
+ // split the polygon in two by the diagonal
15013
+ var c = splitPolygon(a, b);
15014
+ // filter colinear triangles around the cuts
15015
+ a = filterPoints(a, a.next);
15016
+ c = filterPoints(c, c.next);
15017
+ // run earcut on each half
15018
+ hackEarcutLinked(a, triangles, dim, minX, minY, invSize);
15019
+ hackEarcutLinked(c, triangles, dim, minX, minY, invSize);
15020
+ return;
15021
+ }
15022
+ b = b.next;
15023
+ }
15024
+ a = a.next;
15025
+ }while (a !== start);
15026
+ }
15027
+
15028
+ var POINT_INDEX = 2;
15029
+ function getGeometryTriangles(geometry, options) {
15030
+ var s = geometry.s, p = geometry.p;
15031
+ var segments = s[1];
15032
+ var points = p[1];
15033
+ var pointCount = 0;
15034
+ for(var i = 0; i < segments.length; i++){
15035
+ var segment = segments[i];
15036
+ pointCount += segment.length - 1;
15037
+ }
15038
+ var pointData = new Float32Array(pointCount * SPRITE_VERTEX_STRIDE);
15039
+ var _options_indexBase = options.indexBase, indexBase = _options_indexBase === void 0 ? 0 : _options_indexBase, uvTransform = options.uvTransform;
15040
+ var index = 0;
15041
+ var dx = 0, dy = 0, sw = 1, sh = 1, r;
15042
+ if (uvTransform) {
15043
+ dx = uvTransform[0];
15044
+ dy = uvTransform[1];
15045
+ r = uvTransform[4];
15046
+ sw = r ? uvTransform[3] : uvTransform[2];
15047
+ sh = r ? uvTransform[2] : uvTransform[3];
15048
+ }
15049
+ var temp = [
15050
+ 0,
15051
+ 0
15052
+ ];
15053
+ var angle = r === 0 ? 0 : -Math.PI / 2;
15054
+ for(var i1 = 0; i1 < segments.length; i1++){
15055
+ var segment1 = segments[i1];
15056
+ var p0 = points[i1];
15057
+ var p1 = points[i1 + 1] || points[0];
15058
+ var keys = segment1;
15059
+ var point = [
15060
+ 0,
15061
+ 0
15062
+ ];
15063
+ for(var j = 0; j < keys.length - 1; j++){
15064
+ var key = keys[j];
15065
+ getBezier2DValue(point, key, p0, p1, p0[4], p0[5], p1[2], p1[3]);
15066
+ setPoint(point[0], point[1]);
15067
+ }
15068
+ }
15069
+ var indices = earcut(Array.from(pointData), null, SPRITE_VERTEX_STRIDE, indexBase);
15070
+ return {
15071
+ aPoint: pointData,
15072
+ index: new Uint16Array(indices)
15073
+ };
15074
+ function setPoint(x, y) {
15075
+ pointData[index++] = x / 2;
15076
+ pointData[index++] = y / 2;
15077
+ if (uvTransform) {
15078
+ temp[0] = x;
15079
+ temp[1] = y;
15080
+ rotateVec2(temp, temp, angle);
15081
+ pointData[index++] = dx + (temp[0] + 1) / 2 * sw;
15082
+ pointData[index++] = dy + (temp[1] + 1) / 2 * sh;
15083
+ } else {
15084
+ pointData[index++] = (x + 1) / 2;
15085
+ pointData[index++] = (y + 1) / 2;
15086
+ }
15087
+ index += POINT_INDEX;
15088
+ }
15089
+ }
15090
+ /**
15091
+ * 根据新老版形状数据获取形状几何数据
15092
+ * @param shape 新老版形状数据
15093
+ */ function getGeometriesByShapeData(shape) {
15094
+ var geometries = [];
15095
+ // 该版本的单个形状数据可以包含多个形状,可以加个埋点,五福之后没有就可以下掉
15096
+ if (shape.gs) {
15097
+ shape.gs.forEach(function(gs) {
15098
+ geometries.push({
15099
+ p: [
15100
+ ValueType.SHAPE_POINTS,
15101
+ gs.p
15102
+ ],
15103
+ s: [
15104
+ ValueType.SHAPE_SPLITS,
15105
+ gs.s
15106
+ ]
15107
+ });
15108
+ });
15109
+ } else if (shape.g) {
15110
+ geometries.push({
15111
+ p: [
15112
+ ValueType.SHAPE_POINTS,
15113
+ shape.g.p
15114
+ ],
15115
+ s: [
15116
+ ValueType.SHAPE_SPLITS,
15117
+ shape.g.s
15118
+ ]
15119
+ });
15120
+ } else {
15121
+ geometries.push(shape);
15122
+ }
15123
+ return geometries;
15124
+ }
15125
+ function getGeometryByShape(shape, uvTransform) {
15126
+ var datas = [];
15127
+ // 老数据兼容处理
15128
+ var geometries = getGeometriesByShapeData(shape);
15129
+ var indexBase = 0;
15130
+ var aPoint = 0;
15131
+ var index = 0;
15132
+ for(var i = 0; i < geometries.length; i++){
15133
+ var geometry = geometries[i];
15134
+ var data = getGeometryTriangles(geometry, {
15135
+ indexBase: indexBase,
15136
+ uvTransform: uvTransform
15137
+ });
15138
+ indexBase += data.aPoint.length / 5;
15139
+ datas.push(data);
15140
+ aPoint += data.aPoint.length;
15141
+ index += data.index.length;
15142
+ }
15143
+ if (datas.length === 1) {
15144
+ return datas[0];
15145
+ }
15146
+ var aPointData = new Float32Array(aPoint);
15147
+ var indexData = new Uint16Array(index);
15148
+ // @ts-expect-error
15149
+ for(var i1 = 0, pointIndex = 0, idx = 0; i1 < datas[i1]; i1++){
15150
+ var data1 = datas[i1];
15151
+ aPointData.set(data1.aPoint, pointIndex);
15152
+ pointIndex += data1.aPoint.length;
15153
+ indexData.set(data1.index, idx);
15154
+ idx += data1.index.length;
15155
+ }
15156
+ return {
15157
+ aPoint: aPointData,
15158
+ index: indexData
15159
+ };
15160
+ }
15161
+ function rotateVec2(out, vec2, angleInRad) {
15162
+ var c = Math.cos(angleInRad);
15163
+ var s = Math.sin(angleInRad);
15164
+ var x = vec2[0];
15165
+ var y = vec2[1];
15166
+ out[0] = c * x + s * y;
15167
+ out[1] = -s * x + c * y;
15168
+ return out;
15169
+ }
15170
+ function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
15171
+ var ddt = 1 - t;
15172
+ var a = ddt * ddt * ddt;
15173
+ var b = 3 * t * ddt * ddt;
15174
+ var c = 3 * t * t * ddt;
15175
+ var d = t * t * t;
15176
+ out[0] = a * p0[0] + b * cpx0 + c * cpx1 + d * p1[0];
15177
+ out[1] = a * p0[1] + b * cpy0 + c * cpy1 + d * p1[1];
15178
+ return out;
15179
+ }
15180
+
15181
+ /**
15182
+ * @since 2.0.0
15183
+ * @internal
15184
+ */ var Track = /*#__PURE__*/ function(PlayableAsset) {
15185
+ _inherits(Track, PlayableAsset);
15186
+ function Track() {
15187
+ var _this;
15188
+ _this = PlayableAsset.apply(this, arguments) || this;
15189
+ _this.clips = [];
15190
+ _this.clipSeed = 0;
15191
+ return _this;
15192
+ }
15193
+ var _proto = Track.prototype;
15194
+ _proto.createOutput = function createOutput() {
15195
+ var output = new PlayableOutput();
15196
+ return output;
15197
+ };
15198
+ /**
15199
+ * 重写该方法以创建自定义混合器
15200
+ */ _proto.createMixerPlayable = function createMixerPlayable() {
15201
+ return new Playable();
15202
+ };
15203
+ _proto.createPlayable = function createPlayable() {
15204
+ var defaultMixPlayable = this.createMixerPlayable();
15205
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.clips), _step; !(_step = _iterator()).done;){
15206
+ var clip = _step.value;
15207
+ defaultMixPlayable.connect(clip.playable);
15208
+ }
15209
+ return defaultMixPlayable;
15210
+ };
15211
+ _proto.createClip = function createClip(classConstructor, name) {
15212
+ var newClip = new TimelineClip();
15213
+ newClip.playable = new classConstructor();
15214
+ newClip.name = name ? name : "TimelineClip" + newClip.id;
15215
+ this.addClip(newClip);
15216
+ return newClip;
15217
+ };
15218
+ _proto.getClips = function getClips() {
15219
+ return this.clips;
15220
+ };
15221
+ _proto.findClip = function findClip(name) {
15222
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.clips), _step; !(_step = _iterator()).done;){
15223
+ var clip = _step.value;
15224
+ if (clip.name === name) {
15225
+ return clip;
15226
+ }
15227
+ }
15228
+ };
15229
+ _proto.addClip = function addClip(clip) {
15230
+ clip.playable.bindingItem = this.bindingItem;
15231
+ clip.id = (this.clipSeed++).toString();
15232
+ this.clips.push(clip);
15233
+ };
15234
+ return Track;
15235
+ }(PlayableAsset);
15236
+ /**
15237
+ * @since 2.0.0
15238
+ * @internal
15239
+ */ var TimelineClip = function TimelineClip() {
15240
+ this.start = 0;
15241
+ this.duration = 0;
15242
+ };
15243
+
15244
+ function _assert_this_initialized(self) {
15245
+ if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
15246
+ return self;
15247
+ }
15248
+
15249
+ var AnimationStream = /*#__PURE__*/ function() {
15250
+ function AnimationStream(playable) {
15251
+ this.curveValues = {};
15252
+ this.playable = playable;
15253
+ }
15254
+ var _proto = AnimationStream.prototype;
15255
+ _proto.setCurveValue = function setCurveValue(componentType, propertyName, value) {
15256
+ if (!this.findCurveValue(componentType, propertyName)) {
15257
+ this.curveValues[componentType + propertyName] = {
15258
+ componentType: componentType,
15259
+ propertyName: propertyName,
15260
+ value: value
15261
+ };
15262
+ } else {
15263
+ this.curveValues[componentType + propertyName].value = value;
15264
+ }
15265
+ return this.curveValues[componentType + propertyName];
15266
+ };
15267
+ _proto.findCurveValue = function findCurveValue(componentType, propertyName) {
15268
+ return this.curveValues[componentType + propertyName];
15269
+ };
15270
+ _proto.getInputStream = function getInputStream(index) {
15271
+ var inputPlayable = this.playable.getInput(index);
15272
+ if (_instanceof1(inputPlayable, AnimationPlayable)) {
15273
+ return inputPlayable.animationStream;
15274
+ }
15275
+ };
15276
+ return AnimationStream;
15277
+ }();
15278
+
15279
+ var AnimationPlayable = /*#__PURE__*/ function(Playable) {
15280
+ _inherits(AnimationPlayable, Playable);
15281
+ function AnimationPlayable() {
15282
+ var _this;
15283
+ _this = Playable.call(this) || this;
15284
+ _this.animationStream = new AnimationStream(_assert_this_initialized(_this));
15285
+ return _this;
15286
+ }
15287
+ return AnimationPlayable;
15288
+ }(Playable);
15289
+
15290
+ var tempRot$1 = new Euler();
15291
+ var tempSize$1 = new Vector3(1, 1, 1);
15292
+ var tempPos = new Vector3();
15293
+ /**
15294
+ * @since 2.0.0
15295
+ * @internal
15296
+ */ var TransformAnimationPlayable = /*#__PURE__*/ function(AnimationPlayable) {
15297
+ _inherits(TransformAnimationPlayable, AnimationPlayable);
15298
+ function TransformAnimationPlayable() {
15299
+ return AnimationPlayable.apply(this, arguments);
15300
+ }
15301
+ var _proto = TransformAnimationPlayable.prototype;
15302
+ _proto.processFrame = function processFrame(dt) {
15303
+ if (this.bindingItem.composition) {
15304
+ this.sampleAnimation();
15305
+ }
15306
+ };
15307
+ /**
15308
+ * 应用时间轴K帧数据到对象
15309
+ */ _proto.sampleAnimation = function sampleAnimation() {
15310
+ var _this = this;
15311
+ var duration = this.bindingItem.duration;
15312
+ var life = this.time / duration;
15313
+ life = life < 0 ? 0 : life > 1 ? 1 : life;
15314
+ if (this.sizeXOverLifetime) {
15315
+ tempSize$1.x = this.sizeXOverLifetime.getValue(life);
15316
+ if (this.sizeSeparateAxes) {
15317
+ tempSize$1.y = this.sizeYOverLifetime.getValue(life);
15318
+ tempSize$1.z = this.sizeZOverLifetime.getValue(life);
15319
+ } else {
15320
+ tempSize$1.z = tempSize$1.y = tempSize$1.x;
15321
+ }
15322
+ var startSize = this.originalTransform.scale;
15323
+ this.bindingItem.transform.setScale(tempSize$1.x * startSize.x, tempSize$1.y * startSize.y, tempSize$1.z * startSize.z);
15324
+ // this.animationStream.setCurveValue('transform', 'scale.x', tempSize.x * startSize.x);
15325
+ // this.animationStream.setCurveValue('transform', 'scale.y', tempSize.y * startSize.y);
15326
+ // this.animationStream.setCurveValue('transform', 'scale.z', tempSize.z * startSize.z);
15327
+ }
15328
+ if (this.rotationOverLifetime) {
15329
+ var func = function(v) {
15330
+ return _this.rotationOverLifetime.asRotation ? v.getValue(life) : v.getIntegrateValue(0, life, duration);
15331
+ };
15332
+ var incZ = func(this.rotationOverLifetime.z);
15333
+ var separateAxes = this.rotationOverLifetime.separateAxes;
15334
+ tempRot$1.x = separateAxes ? func(this.rotationOverLifetime.x) : 0;
15335
+ tempRot$1.y = separateAxes ? func(this.rotationOverLifetime.y) : 0;
15336
+ tempRot$1.z = incZ;
15337
+ var rot = tempRot$1.addEulers(this.originalTransform.rotation, tempRot$1);
15338
+ this.bindingItem.transform.setRotation(rot.x, rot.y, rot.z);
15339
+ // this.animationStream.setCurveValue('transform', 'rotation.x', rot.x);
15340
+ // this.animationStream.setCurveValue('transform', 'rotation.y', rot.y);
15341
+ // this.animationStream.setCurveValue('transform', 'rotation.z', rot.z);
15342
+ }
15343
+ if (this.positionOverLifetime) {
15344
+ var pos = tempPos;
15345
+ calculateTranslation(pos, this, this.gravity, this.time, duration, this.originalTransform.position, this.velocity);
15346
+ if (this.originalTransform.path) {
15347
+ pos.add(this.originalTransform.path.getValue(life));
15348
+ }
15349
+ this.bindingItem.transform.setPosition(pos.x, pos.y, pos.z);
15350
+ // this.animationStream.setCurveValue('transform', 'position.x', pos.x);
15351
+ // this.animationStream.setCurveValue('transform', 'position.y', pos.y);
15352
+ // this.animationStream.setCurveValue('transform', 'position.z', pos.z);
15353
+ }
15354
+ };
15355
+ _proto.fromData = function fromData(data) {
15356
+ var scale = this.bindingItem.transform.scale;
15357
+ this.originalTransform = {
15358
+ position: this.bindingItem.transform.position.clone(),
15359
+ rotation: this.bindingItem.transform.getRotation().clone(),
15360
+ // TODO 编辑器 scale 没有z轴控制
15361
+ scale: new Vector3(scale.x, scale.y, scale.x)
15362
+ };
15363
+ var positionOverLifetime = data.positionOverLifetime;
15364
+ var rotationOverLifetime = data.rotationOverLifetime;
15365
+ var sizeOverLifetime = data.sizeOverLifetime;
15366
+ // TODO: 没有 K 帧数据的不需要传 positionOverLifetime 空对象
15367
+ if (positionOverLifetime && Object.keys(positionOverLifetime).length !== 0) {
15368
+ this.positionOverLifetime = positionOverLifetime;
15369
+ if (positionOverLifetime.path) {
15370
+ this.originalTransform.path = createValueGetter(positionOverLifetime.path);
15371
+ }
15372
+ var linearVelEnable = positionOverLifetime.linearX || positionOverLifetime.linearY || positionOverLifetime.linearZ;
15373
+ if (linearVelEnable) {
15374
+ this.linearVelOverLifetime = {
15375
+ x: positionOverLifetime.linearX && createValueGetter(positionOverLifetime.linearX),
15376
+ y: positionOverLifetime.linearY && createValueGetter(positionOverLifetime.linearY),
15377
+ z: positionOverLifetime.linearZ && createValueGetter(positionOverLifetime.linearZ),
15378
+ asMovement: positionOverLifetime.asMovement,
15379
+ enabled: !!linearVelEnable
15380
+ };
15381
+ }
15382
+ var orbitalVelEnable = positionOverLifetime.orbitalX || positionOverLifetime.orbitalY || positionOverLifetime.orbitalZ;
15383
+ if (orbitalVelEnable) {
15384
+ this.orbitalVelOverLifetime = {
15385
+ x: positionOverLifetime.orbitalX && createValueGetter(positionOverLifetime.orbitalX),
15386
+ y: positionOverLifetime.orbitalY && createValueGetter(positionOverLifetime.orbitalY),
15387
+ z: positionOverLifetime.orbitalZ && createValueGetter(positionOverLifetime.orbitalZ),
15388
+ center: ensureVec3(positionOverLifetime.orbCenter),
15389
+ asRotation: positionOverLifetime.asRotation,
15390
+ enabled: !!orbitalVelEnable
15391
+ };
15392
+ }
15393
+ this.speedOverLifetime = positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime);
15394
+ }
15395
+ if (sizeOverLifetime) {
15396
+ if (sizeOverLifetime.separateAxes) {
15397
+ this.sizeSeparateAxes = true;
15398
+ this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.x || 1);
15399
+ this.sizeYOverLifetime = createValueGetter(sizeOverLifetime.y || 1);
15400
+ this.sizeZOverLifetime = createValueGetter(sizeOverLifetime.z || 1);
15401
+ } else {
15402
+ this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.size || 1);
15403
+ }
15404
+ }
15405
+ if (rotationOverLifetime) {
15406
+ this.rotationOverLifetime = {
15407
+ asRotation: rotationOverLifetime.asRotation,
15408
+ separateAxes: rotationOverLifetime.separateAxes,
15409
+ z: createValueGetter(rotationOverLifetime.z || 0)
15410
+ };
15411
+ if (rotationOverLifetime.separateAxes) {
15412
+ var rotLt = this.rotationOverLifetime;
15413
+ rotLt.x = createValueGetter(rotationOverLifetime.x || 0);
15414
+ rotLt.y = createValueGetter(rotationOverLifetime.y || 0);
15415
+ }
15416
+ }
15417
+ this.gravity = Vector3.fromArray((positionOverLifetime == null ? void 0 : positionOverLifetime.gravity) || []);
15418
+ var _positionOverLifetime_gravityOverLifetime;
15419
+ this.gravityModifier = createValueGetter((_positionOverLifetime_gravityOverLifetime = positionOverLifetime == null ? void 0 : positionOverLifetime.gravityOverLifetime) != null ? _positionOverLifetime_gravityOverLifetime : 0);
15420
+ this.direction = (positionOverLifetime == null ? void 0 : positionOverLifetime.direction) ? Vector3.fromArray(positionOverLifetime.direction).normalize() : new Vector3();
15421
+ this.startSpeed = (positionOverLifetime == null ? void 0 : positionOverLifetime.startSpeed) || 0;
15422
+ this.velocity = this.direction.clone();
15423
+ this.velocity.multiply(this.startSpeed);
15424
+ };
15425
+ return TransformAnimationPlayable;
15426
+ }(AnimationPlayable);
15427
+ var TransformAnimationPlayableAsset = /*#__PURE__*/ function(PlayableAsset) {
15428
+ _inherits(TransformAnimationPlayableAsset, PlayableAsset);
15429
+ function TransformAnimationPlayableAsset() {
15430
+ return PlayableAsset.apply(this, arguments);
15431
+ }
15432
+ var _proto = TransformAnimationPlayableAsset.prototype;
15433
+ _proto.createPlayable = function createPlayable() {
15434
+ var transformAnimationPlayable = new TransformAnimationPlayable();
15435
+ transformAnimationPlayable.fromData(this.transformAnimationData);
15436
+ return transformAnimationPlayable;
15437
+ };
15438
+ _proto.fromData = function fromData(data) {
15439
+ this.transformAnimationData = data;
15440
+ };
15441
+ return TransformAnimationPlayableAsset;
15442
+ }(PlayableAsset);
15443
+ /**
15444
+ * @since 2.0.0
15445
+ * @internal
15446
+ */ var ActivationPlayable = /*#__PURE__*/ function(Playable) {
15447
+ _inherits(ActivationPlayable, Playable);
15448
+ function ActivationPlayable() {
15449
+ return Playable.apply(this, arguments);
15222
15450
  }
15223
- // if the shape is not too simple, we'll use z-order curve hash later; calculate polygon bbox
15224
- if (data.length > 80 * dim) {
15225
- minX = maxX = data[0];
15226
- minY = maxY = data[1];
15227
- for(var i = dim; i < outerLen; i += dim){
15228
- x = data[i];
15229
- y = data[i + 1];
15230
- if (x < minX) {
15231
- minX = x;
15451
+ var _proto = ActivationPlayable.prototype;
15452
+ _proto.onGraphStart = function onGraphStart() {
15453
+ this.bindingItem.transform.setValid(false);
15454
+ this.hideRendererComponents();
15455
+ };
15456
+ _proto.onPlayablePlay = function onPlayablePlay() {
15457
+ this.bindingItem.transform.setValid(true);
15458
+ this.showRendererComponents();
15459
+ };
15460
+ _proto.onPlayableDestroy = function onPlayableDestroy() {
15461
+ this.bindingItem.transform.setValid(false);
15462
+ this.hideRendererComponents();
15463
+ };
15464
+ _proto.hideRendererComponents = function hideRendererComponents() {
15465
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.bindingItem.rendererComponents), _step; !(_step = _iterator()).done;){
15466
+ var rendererComponent = _step.value;
15467
+ if (rendererComponent.enabled) {
15468
+ rendererComponent.enabled = false;
15232
15469
  }
15233
- if (y < minY) {
15234
- minY = y;
15470
+ }
15471
+ };
15472
+ _proto.showRendererComponents = function showRendererComponents() {
15473
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.bindingItem.rendererComponents), _step; !(_step = _iterator()).done;){
15474
+ var rendererComponent = _step.value;
15475
+ if (!rendererComponent.enabled) {
15476
+ rendererComponent.enabled = true;
15235
15477
  }
15236
- if (x > maxX) {
15237
- maxX = x;
15478
+ }
15479
+ };
15480
+ return ActivationPlayable;
15481
+ }(Playable);
15482
+ var AnimationClip = /*#__PURE__*/ function(EffectsObject) {
15483
+ _inherits(AnimationClip, EffectsObject);
15484
+ function AnimationClip() {
15485
+ var _this;
15486
+ _this = EffectsObject.apply(this, arguments) || this;
15487
+ _this.positionCurves = [];
15488
+ _this.eulerCurves = [];
15489
+ _this.scaleCurves = [];
15490
+ _this.floatCurves = [];
15491
+ return _this;
15492
+ }
15493
+ var _proto = AnimationClip.prototype;
15494
+ _proto.sampleAnimation = function sampleAnimation(vfxItem, time) {
15495
+ var duration = vfxItem.duration;
15496
+ var life = time / duration;
15497
+ life = life < 0 ? 0 : life > 1 ? 1 : life;
15498
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.positionCurves), _step; !(_step = _iterator()).done;){
15499
+ var curve = _step.value;
15500
+ var value = curve.keyFrames.getValue(life);
15501
+ var target = this.findTarget(vfxItem, curve.path);
15502
+ target == null ? void 0 : target.transform.setPosition(value.x, value.y, value.z);
15503
+ }
15504
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(this.eulerCurves), _step1; !(_step1 = _iterator1()).done;){
15505
+ var curve1 = _step1.value;
15506
+ var value1 = curve1.keyFrames.getValue(life);
15507
+ var target1 = this.findTarget(vfxItem, curve1.path);
15508
+ target1 == null ? void 0 : target1.transform.setRotation(value1.x, value1.y, value1.z);
15509
+ }
15510
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.scaleCurves), _step2; !(_step2 = _iterator2()).done;){
15511
+ var curve2 = _step2.value;
15512
+ var value2 = curve2.keyFrames.getValue(life);
15513
+ var target2 = this.findTarget(vfxItem, curve2.path);
15514
+ target2 == null ? void 0 : target2.transform.setScale(value2.x, value2.y, value2.z);
15515
+ }
15516
+ // TODO float curves 采样
15517
+ };
15518
+ _proto.fromData = function fromData(data) {
15519
+ this.positionCurves.length = 0;
15520
+ this.eulerCurves.length = 0;
15521
+ this.scaleCurves.length = 0;
15522
+ this.floatCurves.length = 0;
15523
+ for(var _iterator = _create_for_of_iterator_helper_loose(data.positionCurves), _step; !(_step = _iterator()).done;){
15524
+ var positionCurveData = _step.value;
15525
+ var curve = {
15526
+ path: positionCurveData.path,
15527
+ keyFrames: createValueGetter(positionCurveData.keyFrames)
15528
+ };
15529
+ this.positionCurves.push(curve);
15530
+ }
15531
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(data.eulerCurves), _step1; !(_step1 = _iterator1()).done;){
15532
+ var eulerCurveData = _step1.value;
15533
+ var curve1 = {
15534
+ path: eulerCurveData.path,
15535
+ keyFrames: createValueGetter(eulerCurveData.keyFrames)
15536
+ };
15537
+ this.eulerCurves.push(curve1);
15538
+ }
15539
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(data.scaleCurves), _step2; !(_step2 = _iterator2()).done;){
15540
+ var scaleCurvesData = _step2.value;
15541
+ var curve2 = {
15542
+ path: scaleCurvesData.path,
15543
+ keyFrames: createValueGetter(scaleCurvesData.keyFrames)
15544
+ };
15545
+ this.scaleCurves.push(curve2);
15546
+ }
15547
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(data.floatCurves), _step3; !(_step3 = _iterator3()).done;){
15548
+ var floatCurveData = _step3.value;
15549
+ var curve3 = {
15550
+ path: floatCurveData.path,
15551
+ keyFrames: createValueGetter(floatCurveData.keyFrames),
15552
+ property: floatCurveData.property,
15553
+ className: floatCurveData.className
15554
+ };
15555
+ this.floatCurves.push(curve3);
15556
+ }
15557
+ };
15558
+ _proto.findTarget = function findTarget(vfxItem, path) {
15559
+ var target = vfxItem;
15560
+ for(var _iterator = _create_for_of_iterator_helper_loose(path), _step; !(_step = _iterator()).done;){
15561
+ var name = _step.value;
15562
+ var findTag = false;
15563
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(target.children), _step1; !(_step1 = _iterator1()).done;){
15564
+ var child = _step1.value;
15565
+ if (child.name === name) {
15566
+ target = child;
15567
+ findTag = true;
15568
+ break;
15569
+ }
15238
15570
  }
15239
- if (y > maxY) {
15240
- maxY = y;
15571
+ if (!findTag) {
15572
+ return;
15241
15573
  }
15242
15574
  }
15243
- // minX, minY and invSize are later used to transform coords into integers for z-order calculation
15244
- invSize = Math.max(maxX - minX, maxY - minY);
15245
- invSize = invSize !== 0 ? 1 / invSize : 0;
15246
- }
15247
- hackEarcutLinked(outerNode, triangles, dim, minX, minY, invSize);
15248
- return triangles;
15249
- }
15250
- // main ear slicing loop which triangulates a polygon (given as a linked list)
15251
- function hackEarcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
15252
- if (!ear) {
15253
- return;
15575
+ return target;
15576
+ };
15577
+ return AnimationClip;
15578
+ }(EffectsObject);
15579
+ var AnimationClipPlayable = /*#__PURE__*/ function(Playable) {
15580
+ _inherits(AnimationClipPlayable, Playable);
15581
+ function AnimationClipPlayable() {
15582
+ return Playable.apply(this, arguments);
15254
15583
  }
15255
- // interlink polygon nodes in z-order
15256
- if (!pass && invSize) {
15257
- indexCurve(ear, minX, minY, invSize);
15584
+ var _proto = AnimationClipPlayable.prototype;
15585
+ _proto.processFrame = function processFrame(dt) {
15586
+ if (this.bindingItem.composition) {
15587
+ this.clip.sampleAnimation(this.bindingItem, this.time);
15588
+ }
15589
+ };
15590
+ _proto.fromData = function fromData(data) {
15591
+ this.clip = data.clip;
15592
+ };
15593
+ return AnimationClipPlayable;
15594
+ }(Playable);
15595
+
15596
+ /**
15597
+ * @since 2.0.0
15598
+ * @internal
15599
+ */ var TimelineComponent = /*#__PURE__*/ function(ItemBehaviour) {
15600
+ _inherits(TimelineComponent, ItemBehaviour);
15601
+ function TimelineComponent(engine) {
15602
+ var _this;
15603
+ _this = ItemBehaviour.call(this, engine) || this;
15604
+ _this.reusable = false;
15605
+ _this.timelineStarted = false;
15606
+ _this.playableGraph = new PlayableGraph();
15607
+ /**
15608
+ * 元素动画已经播放的时间
15609
+ */ _this.time = 0;
15610
+ _this.tracks = [];
15611
+ _this.trackSeed = 0;
15612
+ return _this;
15258
15613
  }
15259
- var stop = ear, prev, next;
15260
- // iterate through ears, slicing them one by one
15261
- while(ear.prev !== ear.next){
15262
- prev = ear.prev;
15263
- next = ear.next;
15264
- if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
15265
- // cut off the triangle
15266
- triangles.push(prev.i / dim + indexBase);
15267
- triangles.push(ear.i / dim + indexBase);
15268
- triangles.push(next.i / dim + indexBase);
15269
- removeNode(ear);
15270
- // skipping the next vertex leads to less sliver triangles
15271
- ear = next.next;
15272
- stop = next.next;
15273
- continue;
15614
+ var _proto = TimelineComponent.prototype;
15615
+ _proto.start = function start() {
15616
+ // TODO TimelineClip 需要传入 start 和 duration 数据
15617
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
15618
+ var track = _step.value;
15619
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(track.getClips()), _step1; !(_step1 = _iterator1()).done;){
15620
+ var clip = _step1.value;
15621
+ clip.start = this.item.start;
15622
+ clip.duration = this.item.duration;
15623
+ }
15274
15624
  }
15275
- ear = next;
15276
- // if we looped through the whole remaining polygon and can't find any more ears
15277
- if (ear === stop) {
15278
- // try filtering triangles and slicing again
15279
- if (!pass) {
15280
- hackEarcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
15281
- // if this didn't work, try curing all small self-intersections locally
15282
- } else if (pass === 1) {
15283
- ear = hackCureLocalIntersections(filterPoints(ear), triangles, dim);
15284
- hackEarcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
15285
- // as a last resort, try splitting the remaining polygon into two
15286
- } else if (pass === 2) {
15287
- hackSplitEarcut(ear, triangles, dim, minX, minY, invSize);
15625
+ this.compileTracks(this.playableGraph);
15626
+ };
15627
+ // TODO: [1.31] @十弦 vfx-item 下 onUpdate 的改动验证
15628
+ _proto.update = function update(dt) {
15629
+ if (this.item.stopped || !this.item.composition) {
15630
+ return;
15631
+ }
15632
+ if (!this.timelineStarted) {
15633
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
15634
+ var track = _step.value;
15635
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(track.getClips()), _step1; !(_step1 = _iterator1()).done;){
15636
+ var clip = _step1.value;
15637
+ clip.playable.onGraphStart();
15638
+ }
15288
15639
  }
15289
- break;
15640
+ this.timelineStarted = true;
15290
15641
  }
15291
- }
15292
- }
15293
- // go through all polygon nodes and cure small local self-intersections
15294
- function hackCureLocalIntersections(start, triangles, dim) {
15295
- var p = start;
15296
- do {
15297
- var a = p.prev, b = p.next.next;
15298
- if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
15299
- triangles.push(a.i / dim + indexBase);
15300
- triangles.push(p.i / dim + indexBase);
15301
- triangles.push(b.i / dim + indexBase);
15302
- // remove two nodes involved
15303
- removeNode(p);
15304
- removeNode(p.next);
15305
- p = start = b;
15642
+ var now = this.time;
15643
+ // 判断动画是否开始
15644
+ if (this.item.delaying && now >= 0 && now <= this.item.duration) {
15645
+ this.item.delaying = false;
15646
+ for(var _iterator2 = _create_for_of_iterator_helper_loose(this.tracks), _step2; !(_step2 = _iterator2()).done;){
15647
+ var track1 = _step2.value;
15648
+ for(var _iterator3 = _create_for_of_iterator_helper_loose(track1.getClips()), _step3; !(_step3 = _iterator3()).done;){
15649
+ var clip1 = _step3.value;
15650
+ clip1.playable.onPlayablePlay();
15651
+ }
15652
+ }
15653
+ }
15654
+ // 判断动画是否结束
15655
+ var ended;
15656
+ if (VFXItem.isParticle(this.item)) {
15657
+ ended = this.item.isEnded(now) && this.item.content.destoryed;
15658
+ } else {
15659
+ ended = this.item.isEnded(now);
15660
+ }
15661
+ if (ended) {
15662
+ var endBehavior = this.item.endBehavior;
15663
+ if (!this.item.ended) {
15664
+ this.item.ended = true;
15665
+ this.item.onEnd();
15666
+ if (endBehavior === ItemEndBehavior.destroy) {
15667
+ for(var _iterator4 = _create_for_of_iterator_helper_loose(this.tracks), _step4; !(_step4 = _iterator4()).done;){
15668
+ var track2 = _step4.value;
15669
+ for(var _iterator5 = _create_for_of_iterator_helper_loose(track2.getClips()), _step5; !(_step5 = _iterator5()).done;){
15670
+ var clip2 = _step5.value;
15671
+ clip2.playable.onPlayableDestroy();
15672
+ }
15673
+ }
15674
+ this.item.delaying = true;
15675
+ if (!this.item.reusable && !this.reusable) {
15676
+ this.item.dispose();
15677
+ return;
15678
+ }
15679
+ }
15680
+ }
15681
+ }
15682
+ // TODO: [1.31] @茂安 验证 https://github.com/galacean/effects-runtime/commits/main/packages/effects-core/src/vfx-item.ts
15683
+ // 在生命周期内更新动画
15684
+ if (!this.item.delaying) {
15685
+ var lifetime = this.time / this.item.duration;
15686
+ this.item.lifetime = lifetime;
15687
+ for(var _iterator6 = _create_for_of_iterator_helper_loose(this.tracks), _step6; !(_step6 = _iterator6()).done;){
15688
+ var track3 = _step6.value;
15689
+ for(var _iterator7 = _create_for_of_iterator_helper_loose(track3.getClips()), _step7; !(_step7 = _iterator7()).done;){
15690
+ var clip3 = _step7.value;
15691
+ clip3.playable.setTime(this.time);
15692
+ }
15693
+ }
15694
+ this.playableGraph.evaluate(dt);
15695
+ }
15696
+ };
15697
+ // time 单位秒
15698
+ _proto.setTime = function setTime(time) {
15699
+ this.time = time;
15700
+ };
15701
+ _proto.getTime = function getTime() {
15702
+ return this.time;
15703
+ };
15704
+ _proto.toLocalTime = function toLocalTime(time) {
15705
+ var localTime = time - this.options.start;
15706
+ var duration = this.options.duration;
15707
+ if (localTime - duration > 0.001) {
15708
+ if (this.options.endBehavior === END_BEHAVIOR_RESTART) {
15709
+ localTime = localTime % duration;
15710
+ } else if (this.options.endBehavior === END_BEHAVIOR_FREEZE) {
15711
+ localTime = Math.min(duration, localTime);
15712
+ }
15306
15713
  }
15307
- p = p.next;
15308
- }while (p !== start);
15309
- return filterPoints(p);
15310
- }
15311
- // try splitting polygon into two and triangulate them independently
15312
- function hackSplitEarcut(start, triangles, dim, minX, minY, invSize) {
15313
- // look for a valid diagonal that divides the polygon into two
15314
- var a = start;
15315
- do {
15316
- var b = a.next.next;
15317
- while(b !== a.prev){
15318
- if (a.i !== b.i && isValidDiagonal(a, b)) {
15319
- // split the polygon in two by the diagonal
15320
- var c = splitPolygon(a, b);
15321
- // filter colinear triangles around the cuts
15322
- a = filterPoints(a, a.next);
15323
- c = filterPoints(c, c.next);
15324
- // run earcut on each half
15325
- hackEarcutLinked(a, triangles, dim, minX, minY, invSize);
15326
- hackEarcutLinked(c, triangles, dim, minX, minY, invSize);
15327
- return;
15714
+ return localTime;
15715
+ };
15716
+ _proto.createTrack = function createTrack(classConstructor, name) {
15717
+ var newTrack = new classConstructor();
15718
+ newTrack.bindingItem = this.item;
15719
+ newTrack.id = (this.trackSeed++).toString();
15720
+ newTrack.name = name ? name : "Track" + newTrack.id;
15721
+ this.tracks.push(newTrack);
15722
+ return newTrack;
15723
+ };
15724
+ _proto.getTracks = function getTracks() {
15725
+ return this.tracks;
15726
+ };
15727
+ _proto.findTrack = function findTrack(name) {
15728
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
15729
+ var track = _step.value;
15730
+ if (track.name === name) {
15731
+ return track;
15328
15732
  }
15329
- b = b.next;
15330
15733
  }
15331
- a = a.next;
15332
- }while (a !== start);
15333
- }
15334
-
15335
- var POINT_INDEX = 2;
15336
- function getGeometryTriangles(geometry, options) {
15337
- var s = geometry.s, p = geometry.p;
15338
- var segments = s[1];
15339
- var points = p[1];
15340
- var pointCount = 0;
15341
- for(var i = 0; i < segments.length; i++){
15342
- var segment = segments[i];
15343
- pointCount += segment.length - 1;
15344
- }
15345
- var pointData = new Float32Array(pointCount * SPRITE_VERTEX_STRIDE);
15346
- var _options_indexBase = options.indexBase, indexBase = _options_indexBase === void 0 ? 0 : _options_indexBase, uvTransform = options.uvTransform;
15347
- var index = 0;
15348
- var dx = 0, dy = 0, sw = 1, sh = 1, r;
15349
- if (uvTransform) {
15350
- dx = uvTransform[0];
15351
- dy = uvTransform[1];
15352
- r = uvTransform[4];
15353
- sw = r ? uvTransform[3] : uvTransform[2];
15354
- sh = r ? uvTransform[2] : uvTransform[3];
15355
- }
15356
- var temp = [
15357
- 0,
15358
- 0
15359
- ];
15360
- var angle = r === 0 ? 0 : -Math.PI / 2;
15361
- for(var i1 = 0; i1 < segments.length; i1++){
15362
- var segment1 = segments[i1];
15363
- var p0 = points[i1];
15364
- var p1 = points[i1 + 1] || points[0];
15365
- var keys = segment1;
15366
- var point = [
15367
- 0,
15368
- 0
15369
- ];
15370
- for(var j = 0; j < keys.length - 1; j++){
15371
- var key = keys[j];
15372
- getBezier2DValue(point, key, p0, p1, p0[4], p0[5], p1[2], p1[3]);
15373
- setPoint(point[0], point[1]);
15734
+ };
15735
+ _proto.rebuildGraph = function rebuildGraph() {
15736
+ this.playableGraph = new PlayableGraph();
15737
+ this.compileTracks(this.playableGraph);
15738
+ };
15739
+ _proto.compileTracks = function compileTracks(graph) {
15740
+ for(var _iterator = _create_for_of_iterator_helper_loose(this.tracks), _step; !(_step = _iterator()).done;){
15741
+ var track = _step.value;
15742
+ var trackMixPlayable = track.createPlayable();
15743
+ var trackOutput = track.createOutput();
15744
+ graph.addOutput(trackOutput);
15745
+ trackOutput.setSourcePlayeble(trackMixPlayable);
15374
15746
  }
15375
- }
15376
- var indices = earcut(Array.from(pointData), null, SPRITE_VERTEX_STRIDE, indexBase);
15377
- return {
15378
- aPoint: pointData,
15379
- index: new Uint16Array(indices)
15380
15747
  };
15381
- function setPoint(x, y) {
15382
- pointData[index++] = x / 2;
15383
- pointData[index++] = y / 2;
15384
- if (uvTransform) {
15385
- temp[0] = x;
15386
- temp[1] = y;
15387
- rotateVec2(temp, temp, angle);
15388
- pointData[index++] = dx + (temp[0] + 1) / 2 * sw;
15389
- pointData[index++] = dy + (temp[1] + 1) / 2 * sh;
15390
- } else {
15391
- pointData[index++] = (x + 1) / 2;
15392
- pointData[index++] = (y + 1) / 2;
15748
+ _proto.fromData = function fromData(data) {
15749
+ ItemBehaviour.prototype.fromData.call(this, data);
15750
+ this.options = {
15751
+ start: this.item.start,
15752
+ duration: this.item.duration,
15753
+ looping: this.item.endBehavior === ItemEndBehavior.loop,
15754
+ endBehavior: this.item.endBehavior || ItemEndBehavior.destroy
15755
+ };
15756
+ this.id = this.item.id;
15757
+ this.name = this.item.name;
15758
+ var activationTrack = this.createTrack(Track, "ActivationTrack");
15759
+ activationTrack.createClip(ActivationPlayable, "ActivationTimelineClip");
15760
+ //@ts-expect-error
15761
+ if (data.tracks) {
15762
+ //@ts-expect-error
15763
+ var tracks = data.tracks;
15764
+ for(var _iterator = _create_for_of_iterator_helper_loose(tracks), _step; !(_step = _iterator()).done;){
15765
+ var track = _step.value;
15766
+ var newTrack = this.createTrack(Track);
15767
+ for(var _iterator1 = _create_for_of_iterator_helper_loose(track.clips), _step1; !(_step1 = _iterator1()).done;){
15768
+ var clipAsset = _step1.value;
15769
+ switch(clipAsset.dataType){
15770
+ case "TransformAnimationPlayableAsset":
15771
+ newTrack.name = "TransformAnimationTrack";
15772
+ newTrack.createClip(TransformAnimationPlayable, "TransformAnimationTimelineClip").playable.fromData(clipAsset.animationClip);
15773
+ break;
15774
+ case "SpriteColorAnimationPlayableAsset":
15775
+ newTrack.name = "SpriteColorTrack";
15776
+ newTrack.createClip(SpriteColorPlayable, "SpriteColorClip").playable.fromData(clipAsset.animationClip);
15777
+ break;
15778
+ case "AnimationClipPlayableAsset":
15779
+ newTrack.name = "AnimationTrack";
15780
+ newTrack.createClip(AnimationClipPlayable, "AnimationTimelineClip").playable.fromData(clipAsset.animationClip);
15781
+ break;
15782
+ }
15783
+ }
15784
+ }
15393
15785
  }
15394
- index += POINT_INDEX;
15395
- }
15396
- }
15397
- /**
15398
- * 根据新老版形状数据获取形状几何数据
15399
- * @param shape 新老版形状数据
15400
- */ function getGeometriesByShapeData(shape) {
15401
- var geometries = [];
15402
- // 该版本的单个形状数据可以包含多个形状,可以加个埋点,五福之后没有就可以下掉
15403
- if (shape.gs) {
15404
- shape.gs.forEach(function(gs) {
15405
- geometries.push({
15406
- p: [
15407
- ValueType.SHAPE_POINTS,
15408
- gs.p
15409
- ],
15410
- s: [
15411
- ValueType.SHAPE_SPLITS,
15412
- gs.s
15413
- ]
15414
- });
15415
- });
15416
- } else if (shape.g) {
15417
- geometries.push({
15418
- p: [
15419
- ValueType.SHAPE_POINTS,
15420
- shape.g.p
15421
- ],
15422
- s: [
15423
- ValueType.SHAPE_SPLITS,
15424
- shape.g.s
15425
- ]
15426
- });
15427
- } else {
15428
- geometries.push(shape);
15429
- }
15430
- return geometries;
15431
- }
15432
- function getGeometryByShape(shape, uvTransform) {
15433
- var datas = [];
15434
- // 老数据兼容处理
15435
- var geometries = getGeometriesByShapeData(shape);
15436
- var indexBase = 0;
15437
- var aPoint = 0;
15438
- var index = 0;
15439
- for(var i = 0; i < geometries.length; i++){
15440
- var geometry = geometries[i];
15441
- var data = getGeometryTriangles(geometry, {
15442
- indexBase: indexBase,
15443
- uvTransform: uvTransform
15444
- });
15445
- indexBase += data.aPoint.length / 5;
15446
- datas.push(data);
15447
- aPoint += data.aPoint.length;
15448
- index += data.index.length;
15449
- }
15450
- if (datas.length === 1) {
15451
- return datas[0];
15452
- }
15453
- var aPointData = new Float32Array(aPoint);
15454
- var indexData = new Uint16Array(index);
15455
- // @ts-expect-error
15456
- for(var i1 = 0, pointIndex = 0, idx = 0; i1 < datas[i1]; i1++){
15457
- var data1 = datas[i1];
15458
- aPointData.set(data1.aPoint, pointIndex);
15459
- pointIndex += data1.aPoint.length;
15460
- indexData.set(data1.index, idx);
15461
- idx += data1.index.length;
15462
- }
15463
- return {
15464
- aPoint: aPointData,
15465
- index: indexData
15466
15786
  };
15467
- }
15468
- function rotateVec2(out, vec2, angleInRad) {
15469
- var c = Math.cos(angleInRad);
15470
- var s = Math.sin(angleInRad);
15471
- var x = vec2[0];
15472
- var y = vec2[1];
15473
- out[0] = c * x + s * y;
15474
- out[1] = -s * x + c * y;
15475
- return out;
15476
- }
15477
- function getBezier2DValue(out, t, p0, p1, cpx0, cpy0, cpx1, cpy1) {
15478
- var ddt = 1 - t;
15479
- var a = ddt * ddt * ddt;
15480
- var b = 3 * t * ddt * ddt;
15481
- var c = 3 * t * t * ddt;
15482
- var d = t * t * t;
15483
- out[0] = a * p0[0] + b * cpx0 + c * cpx1 + d * p1[0];
15484
- out[1] = a * p0[1] + b * cpy0 + c * cpy1 + d * p1[1];
15485
- return out;
15486
- }
15787
+ _proto.toData = function toData() {
15788
+ ItemBehaviour.prototype.toData.call(this);
15789
+ };
15790
+ return TimelineComponent;
15791
+ }(ItemBehaviour);
15792
+ __decorate([
15793
+ serialize()
15794
+ ], TimelineComponent.prototype, "time", void 0);
15487
15795
 
15488
15796
  var Burst = /*#__PURE__*/ function() {
15489
15797
  function Burst(opts) {
@@ -20403,7 +20711,6 @@ function getStandardCameraContent(model) {
20403
20711
  }
20404
20712
  }
20405
20713
  });
20406
- var itemGuidMap = {};
20407
20714
  for(var _iterator = _create_for_of_iterator_helper_loose(composition.items), _step; !(_step = _iterator()).done;){
20408
20715
  var item = _step.value;
20409
20716
  itemGuidMap[item.id] = generateGUID();
@@ -23213,17 +23520,6 @@ var tmpScale = new Vector3(1, 1, 1);
23213
23520
  })();
23214
23521
  };
23215
23522
  _create_class(Composition, [
23216
- {
23217
- key: "handleEnd",
23218
- set: /**
23219
- * 合成结束回调
23220
- * @param {(composition: Composition) => void} func
23221
- * @deprecated since 2.0 - use `onEnd` instead
23222
- */ function set(func) {
23223
- console.warn("The handleEnd property is deprecated. Use onEnd instead.");
23224
- this.onEnd = func;
23225
- }
23226
- },
23227
23523
  {
23228
23524
  key: "textures",
23229
23525
  get: /**
@@ -26021,8 +26317,8 @@ setMaxSpriteMeshItemCount(8);
26021
26317
  */ Mesh.create = function(engine, props) {
26022
26318
  return new ThreeMesh(engine, props);
26023
26319
  };
26024
- var version = "2.0.0-alpha.11";
26320
+ var version = "2.0.0-alpha.12";
26025
26321
  logger.info("THREEJS plugin version: " + version);
26026
26322
 
26027
- export { AbstractPlugin, ActivationPlayable, AssetLoader, AssetManager, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, 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, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, Engine, EventSystem, FilterMode, Float16ArrayWrapper, FrameBuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractBehavior, InteractComponent, InteractLoader, InteractMesh, Item, ItemBehaviour, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, PassTextureCache, PluginSystem, RENDER_PASS_NAME_PREFIX, RENDER_PREFER_LOOKUP_TEXTURE, RUNTIME_ENV, RandomSetValue, RandomValue, RandomVectorValue, RenderBuffer, RenderFrame, RenderPass, RenderPassAttachmentStorageType, RenderPassDestroyAttachmentType, RenderPassPriorityNormal, RenderPassPriorityPostprocess, RenderPassPriorityPrepare, RenderTargetHandle, RenderTextureFormat, Renderer, RendererComponent, 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, ShaderType, ShaderVariant, SpriteColorPlayable, SpriteComponent, SpriteLoader, StaticValue, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextComponent, TextLoader, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeEngine, ThreeMaterial, ThreeSpriteComponent, ThreeTexture, Ticker, TimelineClip, TimelineComponent, Track, Transform, TransformAnimationPlayable, TransformAnimationPlayableAsset, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, assertExist, asserts, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, compatible_frag as compatibleFrag, compatible_vert as compatibleVert, createCopyShader, createGLContext, createKeyFrameMeta, createShaderWithMarcos, createShape, createVFXItem, createValueGetter, decimalEqual, deepClone, defaultGlobalVolume, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTemplateCanvasPool, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAndroid, isArray, isFunction, isIOS, isObject, isSceneJSON, isSceneURL, isSceneWithOptions, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isWebGL2, itemFrag, itemFrameFrag, itemVert, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, maxSpriteTextureCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, pointOnLine, random, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxFragmentTextures, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecAssign, vecFill, vecMulCombine, vecNormalize, version };
26323
+ export { AbstractPlugin, ActivationPlayable, AnimationClip, AnimationClipPlayable, AssetLoader, AssetManager, BYTES_TYPE_MAP, Behaviour, BezierCurve, BezierCurvePath, 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, Database, DestroyOptions, Downloader, EFFECTS_COPY_MESH_NAME, EVENT_TYPE_CLICK, EVENT_TYPE_TOUCH_END, EVENT_TYPE_TOUCH_MOVE, EVENT_TYPE_TOUCH_START, EffectComponent, EffectsObject, Engine, EventSystem, FilterMode, Float16ArrayWrapper, Framebuffer, GLSLVersion, GPUCapability, Geometry, GlobalUniforms, GradientValue, HELP_LINK, HitTestType, InteractBehavior, InteractComponent, InteractLoader, InteractMesh, Item, ItemBehaviour, KTXTexture, LineSegments, LinearValue, Material, MaterialDataBlock, MaterialRenderType, Mesh, OrderType, PLAYER_OPTIONS_ENV_EDITOR, POST_PROCESS_SETTINGS, ParticleBehaviourPlayable, ParticleLoader, ParticleMesh, ParticleSystem, ParticleSystemRenderer, PassTextureCache, PathSegments, PluginSystem, 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, 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, ShaderType, ShaderVariant, SpriteColorPlayable, SpriteComponent, SpriteLoader, StaticValue, TEMPLATE_USE_OFFSCREEN_CANVAS, TEXTURE_UNIFORM_MAP, TextComponent, TextLoader, Texture, TextureFactory, TextureLoadAction, TextureSourceType, TextureStoreAction, ThreeComposition, ThreeDisplayObject, ThreeEngine, ThreeMaterial, ThreeSpriteComponent, ThreeTexture, Ticker, TimelineClip, TimelineComponent, Track, Transform, TransformAnimationPlayable, TransformAnimationPlayableAsset, VFXItem, ValueGetter, addByOrder, addItem, addItemWithOrder, assertExist, asserts, blend, calculateTranslation, canvasPool, colorGradingFrag, colorStopsFromGradient, colorToArr$1 as colorToArr, combineImageTemplate, compatible_frag as compatibleFrag, compatible_vert as compatibleVert, createCopyShader, createGLContext, createKeyFrameMeta, createShaderWithMarcos, createShape, createVFXItem, createValueGetter, decimalEqual, deepClone, defaultGlobalVolume, defaultPlugins, deserializeMipmapTexture, earcut, effectsClass, effectsClassStore, enlargeBuffer, ensureFixedNumber, ensureVec3, findPreviousRenderPass, gaussianDown_frag as gaussianDownFrag, gaussianDownHFrag, gaussianDownVFrag, gaussianUpFrag, generateEmptyTypedArray, generateGUID, generateHalfFloatTexture, generateWhiteTexture, getBackgroundImage, getColorFromGradientStops, getConfig, getDefaultTemplateCanvasPool, getDefaultTextureFactory, getGeometryByShape, getGeometryTriangles, getImageItemRenderInfo, getKTXTextureOptions, getKeyFrameMetaByRawValue, getMergedStore, getParticleMeshShader, getPixelRatio, getPreMultiAlpha, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, getTextureSize, glContext, glType2VertexFormatType, gpuTimer, imageDataFromColor, imageDataFromGradient, initErrors, initGLContext, integrate, interpolateColor, isAndroid, isArray, isFunction, isIOS, isObject, isSceneJSON, isSceneURL, isSceneWithOptions, isSimulatorCellPhone, isString, isUniformStruct, isUniformStructArray, isWebGL2, itemFrag, itemFrameFrag, itemVert, loadBinary, loadBlob, loadImage, loadMedia, loadVideo, loadWebPOptional, logger, index as math, maxSpriteMeshItemCount, maxSpriteTextureCount, modifyMaxKeyframeShader, nearestPowerOfTwo, noop, normalizeColor, numberToFix, parsePercent$1 as parsePercent, particleFrag, particleOriginTranslateMap$1 as particleOriginTranslateMap, particleUniformTypeMap, particleVert, pluginLoaderMap, pointOnLine, random, registerPlugin, removeItem, rotateVec2, screenMeshVert, serialize, setBlendMode, setConfig, setDefaultTextureFactory, setMaskMode, setMaxSpriteMeshItemCount, setRayFromCamera, setSideMode, setSpriteMeshMaxFragmentTextures, setSpriteMeshMaxItemCountByGPU, setUniformValue, sortByOrder, index$1 as spec, spriteMeshShaderFromFilter, spriteMeshShaderFromRenderInfo, spriteMeshShaderIdFromRenderInfo, thresholdFrag, throwDestroyedError, trailVert, translatePoint, trianglesFromRect, unregisterPlugin, valIfUndefined, value, valueDefine, vecAssign, vecFill, vecMulCombine, vecNormalize, version, vertexFormatType2GLType };
26028
26324
  //# sourceMappingURL=index.mjs.map