@galacean/effects 2.0.0-alpha.0 → 2.0.0-alpha.2

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/weapp.js CHANGED
@@ -8191,7 +8191,7 @@ function loadMipmapImage(pointer, bins) {
8191
8191
  });
8192
8192
  }
8193
8193
 
8194
- var seed$e = 1;
8194
+ var seed$d = 1;
8195
8195
  /**
8196
8196
  * Texture 抽象类
8197
8197
  */
@@ -8200,7 +8200,7 @@ var Texture = /** @class */ (function (_super) {
8200
8200
  function Texture(engine) {
8201
8201
  var _this = _super.call(this, engine) || this;
8202
8202
  _this.destroyed = false;
8203
- _this.id = 'Tex' + seed$e++;
8203
+ _this.id = 'Tex' + seed$d++;
8204
8204
  return _this;
8205
8205
  }
8206
8206
  Object.defineProperty(Texture.prototype, "isDestroyed", {
@@ -8602,7 +8602,7 @@ exports.MaterialRenderType = void 0;
8602
8602
  * 用于设置材质默认名称的自增序号
8603
8603
  * @internal
8604
8604
  */
8605
- var seed$d = 1;
8605
+ var seed$c = 1;
8606
8606
  /**
8607
8607
  * Material 抽象类
8608
8608
  */
@@ -8617,7 +8617,7 @@ var Material = /** @class */ (function (_super) {
8617
8617
  _this.destroyed = false;
8618
8618
  _this.initialized = false;
8619
8619
  if (props) {
8620
- var _a = props.name, name_1 = _a === void 0 ? 'Material' + seed$d++ : _a, _b = props.renderType, renderType = _b === void 0 ? exports.MaterialRenderType.normal : _b, shader = props.shader, uniformSemantics = props.uniformSemantics;
8620
+ var _a = props.name, name_1 = _a === void 0 ? 'Material' + seed$c++ : _a, _b = props.renderType, renderType = _b === void 0 ? exports.MaterialRenderType.normal : _b, shader = props.shader, uniformSemantics = props.uniformSemantics;
8621
8621
  _this.name = name_1;
8622
8622
  _this.renderType = renderType; // TODO 没有地方用到
8623
8623
  _this.shaderSource = shader;
@@ -8625,7 +8625,7 @@ var Material = /** @class */ (function (_super) {
8625
8625
  _this.uniformSemantics = __assign$1({}, uniformSemantics); // TODO 废弃,待移除
8626
8626
  }
8627
8627
  else {
8628
- _this.name = 'Material' + seed$d++;
8628
+ _this.name = 'Material' + seed$c++;
8629
8629
  _this.renderType = exports.MaterialRenderType.normal;
8630
8630
  }
8631
8631
  return _this;
@@ -9050,7 +9050,7 @@ function generateEmptyTypedArray(type) {
9050
9050
  return new Float32Array(0);
9051
9051
  }
9052
9052
 
9053
- var seed$c = 1;
9053
+ var seed$b = 1;
9054
9054
  /**
9055
9055
  * Mesh 抽象类
9056
9056
  */
@@ -9062,7 +9062,7 @@ var Mesh = /** @class */ (function (_super) {
9062
9062
  _this.visible = true;
9063
9063
  if (props) {
9064
9064
  var material = props.material, geometry = props.geometry, _a = props.name, name_1 = _a === void 0 ? '<unnamed>' : _a, _b = props.priority, priority = _b === void 0 ? 0 : _b, _c = props.worldMatrix, worldMatrix = _c === void 0 ? Matrix4$1.fromIdentity() : _c;
9065
- _this.id = 'Mesh' + seed$c++;
9065
+ _this.id = 'Mesh' + seed$b++;
9066
9066
  _this.name = name_1;
9067
9067
  _this.geometry = geometry;
9068
9068
  _this.material = material;
@@ -9070,7 +9070,7 @@ var Mesh = /** @class */ (function (_super) {
9070
9070
  _this.worldMatrix = worldMatrix;
9071
9071
  }
9072
9072
  else {
9073
- _this.id = 'Mesh' + seed$c++;
9073
+ _this.id = 'Mesh' + seed$b++;
9074
9074
  _this.name = '<unnamed>';
9075
9075
  _this.worldMatrix = Matrix4$1.fromIdentity();
9076
9076
  _this._priority = 0;
@@ -9290,7 +9290,7 @@ exports.RenderPassDestroyAttachmentType = void 0;
9290
9290
  */
9291
9291
  RenderPassDestroyAttachmentType[RenderPassDestroyAttachmentType["destroy"] = 0] = "destroy";
9292
9292
  })(exports.RenderPassDestroyAttachmentType || (exports.RenderPassDestroyAttachmentType = {}));
9293
- var seed$b = 1;
9293
+ var seed$a = 1;
9294
9294
  /**
9295
9295
  * RenderPass 抽象类
9296
9296
  */
@@ -9302,7 +9302,7 @@ var RenderPass = /** @class */ (function () {
9302
9302
  this.attachments = [];
9303
9303
  this.destroyed = false;
9304
9304
  this.initialized = false;
9305
- var _a = options.name, name = _a === void 0 ? 'RenderPass_' + seed$b++ : _a, clearAction = options.clearAction, semantics = options.semantics, depthStencilAttachment = options.depthStencilAttachment, storeAction = options.storeAction, _b = options.priority, priority = _b === void 0 ? 0 : _b, _c = options.meshOrder, meshOrder = _c === void 0 ? exports.OrderType.ascending : _c, _d = options.meshes, meshes = _d === void 0 ? [] : _d, _e = options.delegate, delegate = _e === void 0 ? {} : _e;
9305
+ var _a = options.name, name = _a === void 0 ? 'RenderPass_' + seed$a++ : _a, clearAction = options.clearAction, semantics = options.semantics, depthStencilAttachment = options.depthStencilAttachment, storeAction = options.storeAction, _b = options.priority, priority = _b === void 0 ? 0 : _b, _c = options.meshOrder, meshOrder = _c === void 0 ? exports.OrderType.ascending : _c, _d = options.meshes, meshes = _d === void 0 ? [] : _d, _e = options.delegate, delegate = _e === void 0 ? {} : _e;
9306
9306
  this.name = name;
9307
9307
  this.renderer = renderer;
9308
9308
  this.priority = priority;
@@ -9919,7 +9919,7 @@ var defaultGlobalVolume = {
9919
9919
  };
9920
9920
 
9921
9921
  var RENDER_PASS_NAME_PREFIX = '_effects_default_';
9922
- var seed$a = 1;
9922
+ var seed$9 = 1;
9923
9923
  /**
9924
9924
  * RenderFrame 抽象类
9925
9925
  */
@@ -10054,7 +10054,7 @@ var RenderFrame = /** @class */ (function () {
10054
10054
  }
10055
10055
  this.semantics = new SemanticMap(options.semantics);
10056
10056
  this.clearAction = clearAction;
10057
- this.name = "RenderFrame".concat(seed$a++);
10057
+ this.name = "RenderFrame".concat(seed$9++);
10058
10058
  var firstRP = renderPasses[0];
10059
10059
  var sourceOpts = {
10060
10060
  type: glContext.UNSIGNED_BYTE,
@@ -11277,6 +11277,12 @@ var SerializationHelper = /** @class */ (function () {
11277
11277
  value.id &&
11278
11278
  value.id.length === 32;
11279
11279
  };
11280
+ // TODO 测试函数,2.0 上线后移除
11281
+ SerializationHelper.checkGLTFNode = function (value) {
11282
+ return value instanceof Object &&
11283
+ value.nodeIndex !== undefined &&
11284
+ value.isJoint !== undefined;
11285
+ };
11280
11286
  SerializationHelper.deserializeProperty = function (property, engine, level) {
11281
11287
  var e_11, _a, e_12, _b;
11282
11288
  if (level > 10) {
@@ -11309,7 +11315,9 @@ var SerializationHelper = /** @class */ (function () {
11309
11315
  else if (SerializationHelper.checkDataPath(property)) {
11310
11316
  return engine.assetLoader.loadGUID(property.id);
11311
11317
  }
11312
- else if (property instanceof EffectsObject || SerializationHelper.checkTypedArray(property)) {
11318
+ else if (property instanceof EffectsObject ||
11319
+ SerializationHelper.checkTypedArray(property) ||
11320
+ SerializationHelper.checkGLTFNode(property)) {
11313
11321
  return property;
11314
11322
  }
11315
11323
  else if (property instanceof Object) {
@@ -11384,7 +11392,9 @@ var SerializationHelper = /** @class */ (function () {
11384
11392
  res = _j.sent();
11385
11393
  return [2 /*return*/, res];
11386
11394
  case 12:
11387
- if (!(property instanceof EffectsObject || SerializationHelper.checkTypedArray(property))) return [3 /*break*/, 13];
11395
+ if (!(property instanceof EffectsObject ||
11396
+ SerializationHelper.checkTypedArray(property) ||
11397
+ SerializationHelper.checkGLTFNode(property))) return [3 /*break*/, 13];
11388
11398
  return [2 /*return*/, property];
11389
11399
  case 13:
11390
11400
  if (!(property instanceof Object)) return [3 /*break*/, 22];
@@ -11872,20 +11882,6 @@ var particleOriginTranslateMap = (_a$7 = {},
11872
11882
  _a$7[ParticleOrigin$1.PARTICLE_ORIGIN_RIGHT_BOTTOM] = [0.5, -0.5],
11873
11883
  _a$7[ParticleOrigin$1.PARTICLE_ORIGIN_RIGHT_TOP] = [0.5, 0.5],
11874
11884
  _a$7);
11875
- /**
11876
- * 提取并转换 JSON 数据中的 anchor 值
11877
- */
11878
- function convertAnchor(anchor, particleOrigin) {
11879
- if (anchor) {
11880
- return [anchor[0] - 0.5, 0.5 - anchor[1]];
11881
- }
11882
- else if (particleOrigin) {
11883
- return particleOriginTranslateMap[particleOrigin];
11884
- }
11885
- else {
11886
- return [0, 0];
11887
- }
11888
- }
11889
11885
  function nearestPowerOfTwo(value) {
11890
11886
  return Math.pow(2, Math.round(Math.log(value) / Math.LN2));
11891
11887
  }
@@ -12581,7 +12577,7 @@ function createKeyFrameMeta() {
12581
12577
  }
12582
12578
 
12583
12579
  var tempQuat$1 = new Quaternion();
12584
- var seed$9 = 1;
12580
+ var seed$8 = 1;
12585
12581
  // TODO 继承 Component
12586
12582
  var Transform = /** @class */ (function () {
12587
12583
  function Transform(props, parent) {
@@ -12644,7 +12640,7 @@ var Transform = /** @class */ (function () {
12644
12640
  * 最终模型矩阵对应变换的缓存,当自身矩阵或父矩阵有修改时需要更新
12645
12641
  */
12646
12642
  this.worldTRSCache = { position: new Vector3(0, 0, 0), quat: new Quaternion(0, 0, 0, 1), scale: new Vector3(1, 1, 1) };
12647
- this.name = "transform_".concat(seed$9++);
12643
+ this.name = "transform_".concat(seed$8++);
12648
12644
  if (props) {
12649
12645
  this.setTransform(props);
12650
12646
  }
@@ -12824,13 +12820,11 @@ var Transform = /** @class */ (function () {
12824
12820
  * 设置锚点
12825
12821
  * @param x
12826
12822
  * @param y
12827
- * @param z
12828
12823
  */
12829
- Transform.prototype.setAnchor = function (x, y, z) {
12830
- if (this.anchor.x !== x || this.anchor.y !== y || this.anchor.z !== z) {
12824
+ Transform.prototype.setAnchor = function (x, y) {
12825
+ if (this.anchor.x !== x || this.anchor.y !== y) {
12831
12826
  this.anchor.x = x;
12832
12827
  this.anchor.y = y;
12833
- this.anchor.z = z;
12834
12828
  this.dirtyFlags.localData = true;
12835
12829
  this.dispatchValueChange();
12836
12830
  }
@@ -12841,8 +12835,7 @@ var Transform = /** @class */ (function () {
12841
12835
  * @param reverseEuler - 设置 rotation时,欧拉角是否需要取负值
12842
12836
  */
12843
12837
  Transform.prototype.setTransform = function (props, reverseEuler) {
12844
- var _a;
12845
- var position = props.position, rotation = props.rotation, scale = props.scale, quat = props.quat, name = props.name, anchor = props.anchor;
12838
+ var position = props.position, rotation = props.rotation, scale = props.scale, size = props.size, quat = props.quat, name = props.name, anchor = props.anchor;
12846
12839
  if (name) {
12847
12840
  this.name = name;
12848
12841
  }
@@ -12879,12 +12872,15 @@ var Transform = /** @class */ (function () {
12879
12872
  this.setScale(scale[0], scale[1], scale[2]);
12880
12873
  }
12881
12874
  }
12875
+ if (size) {
12876
+ this.setSize(size.x, size.y);
12877
+ }
12882
12878
  if (anchor) {
12883
- if (anchor instanceof Vector3) {
12884
- this.setAnchor(anchor.x, anchor.y, anchor.z);
12879
+ if (anchor instanceof Vector2) {
12880
+ this.setAnchor(anchor.x, anchor.y);
12885
12881
  }
12886
12882
  else {
12887
- this.setAnchor(anchor[0], anchor[1], (_a = anchor[2]) !== null && _a !== void 0 ? _a : 0);
12883
+ this.setAnchor(anchor[0], anchor[1]);
12888
12884
  }
12889
12885
  }
12890
12886
  };
@@ -13378,7 +13374,7 @@ var HELP_LINK$1 = {
13378
13374
 
13379
13375
  var vertex = "\nprecision highp float;\n\nattribute vec2 aPoint;\nuniform vec4 uPos;\nuniform vec2 uSize;\nuniform vec4 uQuat;\nuniform vec4 uColor;\nuniform mat4 effects_ObjectToWorld;\nuniform mat4 effects_MatrixInvV;\nuniform mat4 effects_MatrixVP;\nvarying vec4 vColor;\n#ifdef ENV_EDITOR\n uniform vec4 uEditorTransform;\n#endif\n\nvec3 rotateByQuat(vec3 a, vec4 quat){\n vec3 qvec = quat.xyz;\n vec3 uv = cross(qvec, a);\n vec3 uuv = cross(qvec, uv) * 2.;\n return a +(uv * 2. * quat.w + uuv);\n}\n\nvoid main() {\n vec4 _pos = uPos;\n vec3 point = rotateByQuat(vec3(aPoint.xy * uSize, 0.),uQuat);\n vec4 pos = vec4(_pos.xyz, 1.0);\n pos = effects_ObjectToWorld * pos;\n pos.xyz += effects_MatrixInvV[0].xyz * point.x+ effects_MatrixInvV[1].xyz * point.y;\n gl_Position = effects_MatrixVP * pos;\n vColor = uColor;\n #ifdef ENV_EDITOR\n gl_Position = vec4(gl_Position.xy * uEditorTransform.xy + uEditorTransform.zw * gl_Position.w, gl_Position.zw);\n #endif\n}\n";
13380
13376
  var fragment = "\nprecision highp float;\n\n#define fragColor gl_FragColor\n\nvarying vec4 vColor;\nvoid main() {\n gl_FragColor = vColor;\n}\n";
13381
- var seed$8 = 1;
13377
+ var seed$7 = 1;
13382
13378
  var InteractMesh = /** @class */ (function () {
13383
13379
  function InteractMesh(props, rendererOptions, transform, engine) {
13384
13380
  this.transform = transform;
@@ -13456,7 +13452,7 @@ var InteractMesh = /** @class */ (function () {
13456
13452
  };
13457
13453
  InteractMesh.prototype.createMesh = function (geometry, material) {
13458
13454
  return Mesh.create(this.engine, {
13459
- name: 'Interact_preview' + seed$8++,
13455
+ name: 'Interact_preview' + seed$7++,
13460
13456
  priority: 0,
13461
13457
  worldMatrix: Matrix4$1.fromIdentity(),
13462
13458
  geometry: geometry,
@@ -13941,783 +13937,1019 @@ var PlayableOutput = /** @class */ (function () {
13941
13937
  * @since 2.0.0
13942
13938
  * @internal
13943
13939
  */
13944
- var TimelineComponent = /** @class */ (function (_super) {
13945
- __extends(TimelineComponent, _super);
13946
- function TimelineComponent(engine) {
13947
- var _this = _super.call(this, engine) || this;
13948
- _this.reusable = false;
13949
- _this.timelineStarted = false;
13950
- _this.playableGraph = new PlayableGraph();
13951
- /**
13952
- * 元素动画已经播放的时间
13953
- */
13954
- _this.time = 0;
13955
- _this.tracks = [];
13956
- _this.trackSeed = 0;
13957
- return _this;
13940
+ var Track = /** @class */ (function () {
13941
+ function Track() {
13942
+ this.clips = [];
13943
+ this.clipSeed = 0;
13958
13944
  }
13959
- TimelineComponent.prototype.start = function () {
13960
- var e_1, _a, e_2, _b;
13945
+ Track.prototype.createOutput = function () {
13946
+ var output = new PlayableOutput();
13947
+ return output;
13948
+ };
13949
+ /**
13950
+ * 重写该方法以创建自定义混合器
13951
+ */
13952
+ Track.prototype.createMixerPlayable = function () {
13953
+ return new Playable();
13954
+ };
13955
+ Track.prototype.createPlayebleTree = function () {
13956
+ var e_1, _a;
13957
+ var defaultMixPlayable = this.createMixerPlayable();
13961
13958
  try {
13962
- // TODO TimelineClip 需要传入 start duration 数据
13963
- for (var _c = __values$1(this.tracks), _d = _c.next(); !_d.done; _d = _c.next()) {
13964
- var track = _d.value;
13965
- try {
13966
- for (var _e = (e_2 = void 0, __values$1(track.getClips())), _f = _e.next(); !_f.done; _f = _e.next()) {
13967
- var clip = _f.value;
13968
- clip.start = this.item.start;
13969
- clip.duration = this.item.duration;
13970
- }
13971
- }
13972
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
13973
- finally {
13974
- try {
13975
- if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
13976
- }
13977
- finally { if (e_2) throw e_2.error; }
13978
- }
13959
+ for (var _b = __values$1(this.clips), _c = _b.next(); !_c.done; _c = _b.next()) {
13960
+ var clip = _c.value;
13961
+ defaultMixPlayable.connect(clip.playable);
13979
13962
  }
13980
13963
  }
13981
13964
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
13982
13965
  finally {
13983
13966
  try {
13984
- if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
13967
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
13985
13968
  }
13986
13969
  finally { if (e_1) throw e_1.error; }
13987
13970
  }
13988
- this.compileTracks(this.playableGraph);
13971
+ return defaultMixPlayable;
13989
13972
  };
13990
- // TODO: [1.31] @十弦 vfx-item onUpdate 的改动验证
13991
- TimelineComponent.prototype.update = function (dt) {
13992
- var e_3, _a, e_4, _b, e_5, _c, e_6, _d, e_7, _e, e_8, _f, e_9, _g, e_10, _h;
13993
- if (this.item.stopped || !this.item.composition) {
13994
- return;
13995
- }
13996
- if (!this.timelineStarted) {
13997
- try {
13998
- for (var _j = __values$1(this.tracks), _k = _j.next(); !_k.done; _k = _j.next()) {
13999
- var track = _k.value;
14000
- try {
14001
- for (var _l = (e_4 = void 0, __values$1(track.getClips())), _m = _l.next(); !_m.done; _m = _l.next()) {
14002
- var clip = _m.value;
14003
- clip.playable.onGraphStart();
14004
- }
14005
- }
14006
- catch (e_4_1) { e_4 = { error: e_4_1 }; }
14007
- finally {
14008
- try {
14009
- if (_m && !_m.done && (_b = _l.return)) _b.call(_l);
14010
- }
14011
- finally { if (e_4) throw e_4.error; }
14012
- }
14013
- }
14014
- }
14015
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
14016
- finally {
14017
- try {
14018
- if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
13973
+ Track.prototype.createClip = function (classConstructor, name) {
13974
+ var newClip = new TimelineClip();
13975
+ newClip.playable = new classConstructor();
13976
+ newClip.name = name ? name : 'TimelineClip' + newClip.id;
13977
+ this.addClip(newClip);
13978
+ return newClip;
13979
+ };
13980
+ Track.prototype.getClips = function () {
13981
+ return this.clips;
13982
+ };
13983
+ Track.prototype.findClip = function (name) {
13984
+ var e_2, _a;
13985
+ try {
13986
+ for (var _b = __values$1(this.clips), _c = _b.next(); !_c.done; _c = _b.next()) {
13987
+ var clip = _c.value;
13988
+ if (clip.name === name) {
13989
+ return clip;
14019
13990
  }
14020
- finally { if (e_3) throw e_3.error; }
14021
13991
  }
14022
- this.timelineStarted = true;
14023
13992
  }
14024
- var now = this.time;
14025
- // 判断动画是否开始
14026
- if (this.item.delaying && now >= 0 && now <= this.item.duration) {
14027
- this.item.delaying = false;
13993
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
13994
+ finally {
14028
13995
  try {
14029
- for (var _o = __values$1(this.tracks), _p = _o.next(); !_p.done; _p = _o.next()) {
14030
- var track = _p.value;
14031
- try {
14032
- for (var _q = (e_6 = void 0, __values$1(track.getClips())), _r = _q.next(); !_r.done; _r = _q.next()) {
14033
- var clip = _r.value;
14034
- clip.playable.onPlayablePlay();
14035
- }
14036
- }
14037
- catch (e_6_1) { e_6 = { error: e_6_1 }; }
14038
- finally {
14039
- try {
14040
- if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
14041
- }
14042
- finally { if (e_6) throw e_6.error; }
14043
- }
14044
- }
14045
- }
14046
- catch (e_5_1) { e_5 = { error: e_5_1 }; }
14047
- finally {
14048
- try {
14049
- if (_p && !_p.done && (_c = _o.return)) _c.call(_o);
14050
- }
14051
- finally { if (e_5) throw e_5.error; }
13996
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14052
13997
  }
13998
+ finally { if (e_2) throw e_2.error; }
14053
13999
  }
14054
- // 判断动画是否结束
14055
- var ended;
14056
- if (VFXItem.isParticle(this.item)) {
14057
- ended = this.item.isEnded(now) && this.item.content.destoryed;
14000
+ };
14001
+ Track.prototype.addClip = function (clip) {
14002
+ clip.playable.bindingItem = this.bindingItem;
14003
+ clip.id = (this.clipSeed++).toString();
14004
+ this.clips.push(clip);
14005
+ };
14006
+ return Track;
14007
+ }());
14008
+ /**
14009
+ * @since 2.0.0
14010
+ * @internal
14011
+ */
14012
+ var TimelineClip = /** @class */ (function () {
14013
+ function TimelineClip() {
14014
+ this.start = 0;
14015
+ this.duration = 0;
14016
+ }
14017
+ return TimelineClip;
14018
+ }());
14019
+
14020
+ var AnimationStream = /** @class */ (function () {
14021
+ function AnimationStream(playable) {
14022
+ this.curveValues = {};
14023
+ this.playable = playable;
14024
+ }
14025
+ AnimationStream.prototype.setCurveValue = function (componentType, propertyName, value) {
14026
+ if (!this.findCurveValue(componentType, propertyName)) {
14027
+ this.curveValues[componentType + propertyName] = { componentType: componentType, propertyName: propertyName, value: value };
14058
14028
  }
14059
14029
  else {
14060
- ended = this.item.isEnded(now);
14030
+ this.curveValues[componentType + propertyName].value = value;
14061
14031
  }
14062
- if (ended) {
14063
- var endBehavior = this.item.endBehavior;
14064
- if (!this.item.ended) {
14065
- this.item.ended = true;
14066
- this.item.onEnd();
14067
- if (endBehavior === END_BEHAVIOR_DESTROY$1) {
14068
- try {
14069
- for (var _s = __values$1(this.tracks), _t = _s.next(); !_t.done; _t = _s.next()) {
14070
- var track = _t.value;
14071
- try {
14072
- for (var _u = (e_8 = void 0, __values$1(track.getClips())), _v = _u.next(); !_v.done; _v = _u.next()) {
14073
- var clip = _v.value;
14074
- clip.playable.onPlayableDestroy();
14075
- }
14076
- }
14077
- catch (e_8_1) { e_8 = { error: e_8_1 }; }
14078
- finally {
14079
- try {
14080
- if (_v && !_v.done && (_f = _u.return)) _f.call(_u);
14081
- }
14082
- finally { if (e_8) throw e_8.error; }
14083
- }
14084
- }
14085
- }
14086
- catch (e_7_1) { e_7 = { error: e_7_1 }; }
14087
- finally {
14088
- try {
14089
- if (_t && !_t.done && (_e = _s.return)) _e.call(_s);
14090
- }
14091
- finally { if (e_7) throw e_7.error; }
14092
- }
14093
- this.item.delaying = true;
14094
- if (!this.item.reusable && !this.reusable) {
14095
- this.item.dispose();
14096
- return;
14097
- }
14098
- }
14099
- }
14032
+ return this.curveValues[componentType + propertyName];
14033
+ };
14034
+ AnimationStream.prototype.findCurveValue = function (componentType, propertyName) {
14035
+ return this.curveValues[componentType + propertyName];
14036
+ };
14037
+ AnimationStream.prototype.getInputStream = function (index) {
14038
+ var inputPlayable = this.playable.getInput(index);
14039
+ if (inputPlayable instanceof AnimationPlayable) {
14040
+ return inputPlayable.animationStream;
14100
14041
  }
14101
- // TODO: [1.31] @茂安 验证 https://github.com/galacean/effects-runtime/commits/main/packages/effects-core/src/vfx-item.ts
14102
- // 在生命周期内更新动画
14103
- if (!this.item.delaying) {
14104
- var lifetime = this.time / this.item.duration;
14105
- this.item.lifetime = lifetime;
14106
- try {
14107
- for (var _w = __values$1(this.tracks), _x = _w.next(); !_x.done; _x = _w.next()) {
14108
- var track = _x.value;
14109
- try {
14110
- for (var _y = (e_10 = void 0, __values$1(track.getClips())), _z = _y.next(); !_z.done; _z = _y.next()) {
14111
- var clip = _z.value;
14112
- clip.playable.setTime(this.time);
14113
- }
14114
- }
14115
- catch (e_10_1) { e_10 = { error: e_10_1 }; }
14116
- finally {
14117
- try {
14118
- if (_z && !_z.done && (_h = _y.return)) _h.call(_y);
14119
- }
14120
- finally { if (e_10) throw e_10.error; }
14121
- }
14122
- }
14042
+ };
14043
+ return AnimationStream;
14044
+ }());
14045
+
14046
+ var AnimationPlayable = /** @class */ (function (_super) {
14047
+ __extends(AnimationPlayable, _super);
14048
+ function AnimationPlayable() {
14049
+ var _this = _super.call(this) || this;
14050
+ _this.animationStream = new AnimationStream(_this);
14051
+ return _this;
14052
+ }
14053
+ return AnimationPlayable;
14054
+ }(Playable));
14055
+
14056
+ var tempRot$1 = new Euler();
14057
+ var tempSize$1 = new Vector3(1, 1, 1);
14058
+ var tempPos = new Vector3();
14059
+ /**
14060
+ * @since 2.0.0
14061
+ * @internal
14062
+ */
14063
+ var AnimationClipPlayable = /** @class */ (function (_super) {
14064
+ __extends(AnimationClipPlayable, _super);
14065
+ function AnimationClipPlayable() {
14066
+ return _super !== null && _super.apply(this, arguments) || this;
14067
+ }
14068
+ AnimationClipPlayable.prototype.processFrame = function (dt) {
14069
+ if (this.bindingItem.composition) {
14070
+ this.sampleAnimation();
14071
+ }
14072
+ };
14073
+ /**
14074
+ * 应用时间轴K帧数据到对象
14075
+ */
14076
+ AnimationClipPlayable.prototype.sampleAnimation = function () {
14077
+ var _this = this;
14078
+ var duration = this.bindingItem.duration;
14079
+ var life = this.time / duration;
14080
+ life = life < 0 ? 0 : (life > 1 ? 1 : life);
14081
+ if (this.sizeXOverLifetime) {
14082
+ tempSize$1.x = this.sizeXOverLifetime.getValue(life);
14083
+ if (this.sizeSeparateAxes) {
14084
+ tempSize$1.y = this.sizeYOverLifetime.getValue(life);
14085
+ tempSize$1.z = this.sizeZOverLifetime.getValue(life);
14123
14086
  }
14124
- catch (e_9_1) { e_9 = { error: e_9_1 }; }
14125
- finally {
14126
- try {
14127
- if (_x && !_x.done && (_g = _w.return)) _g.call(_w);
14128
- }
14129
- finally { if (e_9) throw e_9.error; }
14087
+ else {
14088
+ tempSize$1.z = tempSize$1.y = tempSize$1.x;
14130
14089
  }
14131
- this.playableGraph.evaluate(dt);
14090
+ var startSize = this.originalTransform.scale;
14091
+ this.bindingItem.transform.setScale(tempSize$1.x * startSize.x, tempSize$1.y * startSize.y, tempSize$1.z * startSize.z);
14092
+ // this.animationStream.setCurveValue('transform', 'scale.x', tempSize.x * startSize.x);
14093
+ // this.animationStream.setCurveValue('transform', 'scale.y', tempSize.y * startSize.y);
14094
+ // this.animationStream.setCurveValue('transform', 'scale.z', tempSize.z * startSize.z);
14095
+ }
14096
+ if (this.rotationOverLifetime) {
14097
+ var func = function (v) { return _this.rotationOverLifetime.asRotation ? v.getValue(life) : v.getIntegrateValue(0, life, duration); };
14098
+ var incZ = func(this.rotationOverLifetime.z);
14099
+ var separateAxes = this.rotationOverLifetime.separateAxes;
14100
+ tempRot$1.x = separateAxes ? func(this.rotationOverLifetime.x) : 0;
14101
+ tempRot$1.y = separateAxes ? func(this.rotationOverLifetime.y) : 0;
14102
+ tempRot$1.z = incZ;
14103
+ var rot = tempRot$1.addEulers(this.originalTransform.rotation, tempRot$1);
14104
+ this.bindingItem.transform.setRotation(rot.x, rot.y, rot.z);
14105
+ // this.animationStream.setCurveValue('transform', 'rotation.x', rot.x);
14106
+ // this.animationStream.setCurveValue('transform', 'rotation.y', rot.y);
14107
+ // this.animationStream.setCurveValue('transform', 'rotation.z', rot.z);
14108
+ }
14109
+ if (this.positionOverLifetime) {
14110
+ var pos = tempPos;
14111
+ calculateTranslation(pos, this, this.gravity, this.time, duration, this.originalTransform.position, this.velocity);
14112
+ if (this.originalTransform.path) {
14113
+ pos.add(this.originalTransform.path.getValue(life));
14114
+ }
14115
+ this.bindingItem.transform.setPosition(pos.x, pos.y, pos.z);
14116
+ // this.animationStream.setCurveValue('transform', 'position.x', pos.x);
14117
+ // this.animationStream.setCurveValue('transform', 'position.y', pos.y);
14118
+ // this.animationStream.setCurveValue('transform', 'position.z', pos.z);
14132
14119
  }
14133
14120
  };
14134
- // time 单位秒
14135
- TimelineComponent.prototype.setTime = function (time) {
14136
- this.time = time;
14137
- };
14138
- TimelineComponent.prototype.getTime = function () {
14139
- return this.time;
14140
- };
14141
- TimelineComponent.prototype.toLocalTime = function (time) {
14142
- var localTime = time - this.options.start;
14143
- var duration = this.options.duration;
14144
- if (localTime - duration > 0.001) {
14145
- if (this.options.endBehavior === END_BEHAVIOR_RESTART$1) {
14146
- localTime = localTime % duration;
14121
+ AnimationClipPlayable.prototype.fromData = function (data) {
14122
+ var _a;
14123
+ var scale = this.bindingItem.transform.scale;
14124
+ this.originalTransform = {
14125
+ position: this.bindingItem.transform.position.clone(),
14126
+ rotation: this.bindingItem.transform.getRotation().clone(),
14127
+ // TODO 编辑器 scale 没有z轴控制
14128
+ scale: new Vector3(scale.x, scale.y, scale.x),
14129
+ };
14130
+ var positionOverLifetime = data.positionOverLifetime;
14131
+ var rotationOverLifetime = data.rotationOverLifetime;
14132
+ var sizeOverLifetime = data.sizeOverLifetime;
14133
+ // TODO: 没有 K 帧数据的不需要传 positionOverLifetime 空对象
14134
+ if (positionOverLifetime && Object.keys(positionOverLifetime).length !== 0) {
14135
+ this.positionOverLifetime = positionOverLifetime;
14136
+ if (positionOverLifetime.path) {
14137
+ this.originalTransform.path = createValueGetter(positionOverLifetime.path);
14147
14138
  }
14148
- else if (this.options.endBehavior === END_BEHAVIOR_FREEZE$1) {
14149
- localTime = Math.min(duration, localTime);
14139
+ var linearVelEnable = positionOverLifetime.linearX || positionOverLifetime.linearY || positionOverLifetime.linearZ;
14140
+ if (linearVelEnable) {
14141
+ this.linearVelOverLifetime = {
14142
+ x: positionOverLifetime.linearX && createValueGetter(positionOverLifetime.linearX),
14143
+ y: positionOverLifetime.linearY && createValueGetter(positionOverLifetime.linearY),
14144
+ z: positionOverLifetime.linearZ && createValueGetter(positionOverLifetime.linearZ),
14145
+ asMovement: positionOverLifetime.asMovement,
14146
+ enabled: !!linearVelEnable,
14147
+ };
14148
+ }
14149
+ var orbitalVelEnable = positionOverLifetime.orbitalX || positionOverLifetime.orbitalY || positionOverLifetime.orbitalZ;
14150
+ if (orbitalVelEnable) {
14151
+ this.orbitalVelOverLifetime = {
14152
+ x: positionOverLifetime.orbitalX && createValueGetter(positionOverLifetime.orbitalX),
14153
+ y: positionOverLifetime.orbitalY && createValueGetter(positionOverLifetime.orbitalY),
14154
+ z: positionOverLifetime.orbitalZ && createValueGetter(positionOverLifetime.orbitalZ),
14155
+ center: ensureVec3(positionOverLifetime.orbCenter),
14156
+ asRotation: positionOverLifetime.asRotation,
14157
+ enabled: !!orbitalVelEnable,
14158
+ };
14150
14159
  }
14160
+ this.speedOverLifetime = positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime);
14151
14161
  }
14152
- return localTime;
14162
+ if (sizeOverLifetime) {
14163
+ if (sizeOverLifetime.separateAxes) {
14164
+ this.sizeSeparateAxes = true;
14165
+ this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.x || 1);
14166
+ this.sizeYOverLifetime = createValueGetter(sizeOverLifetime.y || 1);
14167
+ this.sizeZOverLifetime = createValueGetter(sizeOverLifetime.z || 1);
14168
+ }
14169
+ else {
14170
+ this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.size || 1);
14171
+ }
14172
+ }
14173
+ if (rotationOverLifetime) {
14174
+ this.rotationOverLifetime = {
14175
+ asRotation: rotationOverLifetime.asRotation,
14176
+ separateAxes: rotationOverLifetime.separateAxes,
14177
+ z: createValueGetter(rotationOverLifetime.z || 0),
14178
+ };
14179
+ if (rotationOverLifetime.separateAxes) {
14180
+ var rotLt = this.rotationOverLifetime;
14181
+ rotLt.x = createValueGetter(rotationOverLifetime.x || 0);
14182
+ rotLt.y = createValueGetter(rotationOverLifetime.y || 0);
14183
+ }
14184
+ }
14185
+ this.gravity = Vector3.fromArray((positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravity) || []);
14186
+ this.gravityModifier = createValueGetter((_a = positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravityOverLifetime) !== null && _a !== void 0 ? _a : 0);
14187
+ this.direction = (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.direction) ? Vector3.fromArray(positionOverLifetime.direction).normalize() : new Vector3();
14188
+ this.startSpeed = (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.startSpeed) || 0;
14189
+ this.velocity = this.direction.clone();
14190
+ this.velocity.multiply(this.startSpeed);
14153
14191
  };
14154
- TimelineComponent.prototype.createTrack = function (classConstructor, name) {
14155
- var newTrack = new classConstructor();
14156
- newTrack.bindingItem = this.item;
14157
- newTrack.id = (this.trackSeed++).toString();
14158
- newTrack.name = name ? name : 'Track' + newTrack.id;
14159
- this.tracks.push(newTrack);
14160
- return newTrack;
14192
+ return AnimationClipPlayable;
14193
+ }(AnimationPlayable));
14194
+ /**
14195
+ * @since 2.0.0
14196
+ * @internal
14197
+ */
14198
+ var ActivationClipPlayable = /** @class */ (function (_super) {
14199
+ __extends(ActivationClipPlayable, _super);
14200
+ function ActivationClipPlayable() {
14201
+ return _super !== null && _super.apply(this, arguments) || this;
14202
+ }
14203
+ ActivationClipPlayable.prototype.onGraphStart = function () {
14204
+ this.bindingItem.transform.setValid(false);
14205
+ this.hideRendererComponents();
14161
14206
  };
14162
- TimelineComponent.prototype.getTracks = function () {
14163
- return this.tracks;
14207
+ ActivationClipPlayable.prototype.onPlayablePlay = function () {
14208
+ this.bindingItem.transform.setValid(true);
14209
+ this.showRendererComponents();
14164
14210
  };
14165
- TimelineComponent.prototype.findTrack = function (name) {
14166
- var e_11, _a;
14211
+ ActivationClipPlayable.prototype.onPlayableDestroy = function () {
14212
+ this.bindingItem.transform.setValid(false);
14213
+ this.hideRendererComponents();
14214
+ };
14215
+ ActivationClipPlayable.prototype.hideRendererComponents = function () {
14216
+ var e_1, _a;
14167
14217
  try {
14168
- for (var _b = __values$1(this.tracks), _c = _b.next(); !_c.done; _c = _b.next()) {
14169
- var track = _c.value;
14170
- if (track.name === name) {
14171
- return track;
14218
+ for (var _b = __values$1(this.bindingItem.rendererComponents), _c = _b.next(); !_c.done; _c = _b.next()) {
14219
+ var rendererComponent = _c.value;
14220
+ if (rendererComponent.enabled) {
14221
+ rendererComponent.enabled = false;
14172
14222
  }
14173
14223
  }
14174
14224
  }
14175
- catch (e_11_1) { e_11 = { error: e_11_1 }; }
14225
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
14176
14226
  finally {
14177
14227
  try {
14178
14228
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14179
14229
  }
14180
- finally { if (e_11) throw e_11.error; }
14230
+ finally { if (e_1) throw e_1.error; }
14181
14231
  }
14182
14232
  };
14183
- TimelineComponent.prototype.rebuildGraph = function () {
14184
- this.playableGraph = new PlayableGraph();
14185
- this.compileTracks(this.playableGraph);
14186
- };
14187
- TimelineComponent.prototype.compileTracks = function (graph) {
14188
- var e_12, _a;
14233
+ ActivationClipPlayable.prototype.showRendererComponents = function () {
14234
+ var e_2, _a;
14189
14235
  try {
14190
- for (var _b = __values$1(this.tracks), _c = _b.next(); !_c.done; _c = _b.next()) {
14191
- var track = _c.value;
14192
- var trackMixPlayable = track.createPlayebleTree();
14193
- var trackOutput = track.createOutput();
14194
- graph.addOutput(trackOutput);
14195
- trackOutput.setSourcePlayeble(trackMixPlayable);
14236
+ for (var _b = __values$1(this.bindingItem.rendererComponents), _c = _b.next(); !_c.done; _c = _b.next()) {
14237
+ var rendererComponent = _c.value;
14238
+ if (!rendererComponent.enabled) {
14239
+ rendererComponent.enabled = true;
14240
+ }
14196
14241
  }
14197
14242
  }
14198
- catch (e_12_1) { e_12 = { error: e_12_1 }; }
14243
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
14199
14244
  finally {
14200
14245
  try {
14201
14246
  if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14202
14247
  }
14203
- finally { if (e_12) throw e_12.error; }
14248
+ finally { if (e_2) throw e_2.error; }
14204
14249
  }
14205
14250
  };
14206
- TimelineComponent.prototype.fromData = function (data) {
14207
- _super.prototype.fromData.call(this, data);
14208
- this.options = {
14209
- start: this.item.start,
14210
- duration: this.item.duration,
14211
- looping: this.item.endBehavior === END_BEHAVIOR_RESTART$1,
14212
- endBehavior: this.item.endBehavior || END_BEHAVIOR_DESTROY$1,
14213
- };
14214
- this.id = this.item.id;
14215
- this.name = this.item.name;
14216
- };
14217
- TimelineComponent.prototype.toData = function () {
14218
- _super.prototype.toData.call(this);
14219
- };
14220
- __decorate([
14221
- serialize()
14222
- ], TimelineComponent.prototype, "time", void 0);
14223
- return TimelineComponent;
14224
- }(ItemBehaviour));
14251
+ return ActivationClipPlayable;
14252
+ }(Playable));
14225
14253
 
14226
14254
  /**
14227
14255
  * @since 2.0.0
14228
14256
  * @internal
14229
14257
  */
14230
- var Track = /** @class */ (function () {
14231
- function Track() {
14232
- this.clips = [];
14233
- this.clipSeed = 0;
14258
+ var TimelineComponent = /** @class */ (function (_super) {
14259
+ __extends(TimelineComponent, _super);
14260
+ function TimelineComponent(engine) {
14261
+ var _this = _super.call(this, engine) || this;
14262
+ _this.reusable = false;
14263
+ _this.timelineStarted = false;
14264
+ _this.playableGraph = new PlayableGraph();
14265
+ /**
14266
+ * 元素动画已经播放的时间
14267
+ */
14268
+ _this.time = 0;
14269
+ _this.tracks = [];
14270
+ _this.trackSeed = 0;
14271
+ return _this;
14234
14272
  }
14235
- Track.prototype.createOutput = function () {
14236
- var output = new PlayableOutput();
14237
- return output;
14238
- };
14239
- /**
14240
- * 重写该方法以创建自定义混合器
14241
- */
14242
- Track.prototype.createMixerPlayable = function () {
14243
- return new Playable();
14244
- };
14245
- Track.prototype.createPlayebleTree = function () {
14246
- var e_1, _a;
14247
- var defaultMixPlayable = this.createMixerPlayable();
14273
+ TimelineComponent.prototype.start = function () {
14274
+ var e_1, _a, e_2, _b;
14248
14275
  try {
14249
- for (var _b = __values$1(this.clips), _c = _b.next(); !_c.done; _c = _b.next()) {
14250
- var clip = _c.value;
14251
- defaultMixPlayable.connect(clip.playable);
14276
+ // TODO TimelineClip 需要传入 start duration 数据
14277
+ for (var _c = __values$1(this.tracks), _d = _c.next(); !_d.done; _d = _c.next()) {
14278
+ var track = _d.value;
14279
+ try {
14280
+ for (var _e = (e_2 = void 0, __values$1(track.getClips())), _f = _e.next(); !_f.done; _f = _e.next()) {
14281
+ var clip = _f.value;
14282
+ clip.start = this.item.start;
14283
+ clip.duration = this.item.duration;
14284
+ }
14285
+ }
14286
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
14287
+ finally {
14288
+ try {
14289
+ if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
14290
+ }
14291
+ finally { if (e_2) throw e_2.error; }
14292
+ }
14252
14293
  }
14253
14294
  }
14254
14295
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
14255
14296
  finally {
14256
14297
  try {
14257
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14298
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
14258
14299
  }
14259
14300
  finally { if (e_1) throw e_1.error; }
14260
14301
  }
14261
- return defaultMixPlayable;
14262
- };
14263
- Track.prototype.createClip = function (classConstructor, name) {
14264
- var newClip = new TimelineClip();
14265
- newClip.playable = new classConstructor();
14266
- newClip.name = name ? name : 'TimelineClip' + newClip.id;
14267
- this.addClip(newClip);
14268
- return newClip;
14269
- };
14270
- Track.prototype.getClips = function () {
14271
- return this.clips;
14302
+ this.compileTracks(this.playableGraph);
14272
14303
  };
14273
- Track.prototype.findClip = function (name) {
14274
- var e_2, _a;
14275
- try {
14276
- for (var _b = __values$1(this.clips), _c = _b.next(); !_c.done; _c = _b.next()) {
14277
- var clip = _c.value;
14278
- if (clip.name === name) {
14279
- return clip;
14280
- }
14281
- }
14304
+ // TODO: [1.31] @十弦 vfx-item onUpdate 的改动验证
14305
+ TimelineComponent.prototype.update = function (dt) {
14306
+ var e_3, _a, e_4, _b, e_5, _c, e_6, _d, e_7, _e, e_8, _f, e_9, _g, e_10, _h;
14307
+ if (this.item.stopped || !this.item.composition) {
14308
+ return;
14282
14309
  }
14283
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
14284
- finally {
14310
+ if (!this.timelineStarted) {
14285
14311
  try {
14286
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14312
+ for (var _j = __values$1(this.tracks), _k = _j.next(); !_k.done; _k = _j.next()) {
14313
+ var track = _k.value;
14314
+ try {
14315
+ for (var _l = (e_4 = void 0, __values$1(track.getClips())), _m = _l.next(); !_m.done; _m = _l.next()) {
14316
+ var clip = _m.value;
14317
+ clip.playable.onGraphStart();
14318
+ }
14319
+ }
14320
+ catch (e_4_1) { e_4 = { error: e_4_1 }; }
14321
+ finally {
14322
+ try {
14323
+ if (_m && !_m.done && (_b = _l.return)) _b.call(_l);
14324
+ }
14325
+ finally { if (e_4) throw e_4.error; }
14326
+ }
14327
+ }
14287
14328
  }
14288
- finally { if (e_2) throw e_2.error; }
14289
- }
14290
- };
14291
- Track.prototype.addClip = function (clip) {
14292
- clip.playable.bindingItem = this.bindingItem;
14293
- clip.id = (this.clipSeed++).toString();
14294
- this.clips.push(clip);
14295
- };
14296
- return Track;
14297
- }());
14298
- /**
14299
- * @since 2.0.0
14300
- * @internal
14301
- */
14302
- var TimelineClip = /** @class */ (function () {
14303
- function TimelineClip() {
14304
- this.start = 0;
14305
- this.duration = 0;
14306
- }
14307
- return TimelineClip;
14308
- }());
14309
-
14310
- var singleSplits = [[0, 0, 1, 1, undefined]];
14311
- var tempColor = [1, 1, 1, 1];
14312
- var seed$7 = 0;
14313
- var SpriteColorPlayable = /** @class */ (function (_super) {
14314
- __extends(SpriteColorPlayable, _super);
14315
- function SpriteColorPlayable() {
14316
- var _this = _super !== null && _super.apply(this, arguments) || this;
14317
- _this.renderColor = [1, 1, 1, 1];
14318
- return _this;
14319
- }
14320
- SpriteColorPlayable.prototype.onPlayablePlay = function () {
14321
- this.spriteMaterial = this.bindingItem.getComponent(SpriteComponent).material;
14322
- };
14323
- SpriteColorPlayable.prototype.processFrame = function (dt) {
14324
- var colorInc = vecFill(tempColor, 1);
14325
- var colorChanged;
14326
- var life = this.time / this.bindingItem.duration;
14327
- var opacityOverLifetime = this.opacityOverLifetime;
14328
- var colorOverLifetime = this.colorOverLifetime;
14329
- if (colorOverLifetime) {
14330
- colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
14331
- colorChanged = true;
14332
- }
14333
- if (opacityOverLifetime) {
14334
- colorInc[3] *= opacityOverLifetime.getValue(life);
14335
- colorChanged = true;
14336
- }
14337
- if (colorChanged) {
14338
- vecMulCombine(this.renderColor, colorInc, this.startColor);
14339
- this.spriteMaterial.getVector4('_Color').setFromArray(this.renderColor);
14340
- }
14341
- };
14342
- SpriteColorPlayable.prototype.fromData = function (clipData) {
14343
- var _a;
14344
- this.clipData = clipData;
14345
- var colorOverLifetime = clipData.colorOverLifetime;
14346
- if (colorOverLifetime) {
14347
- this.opacityOverLifetime = createValueGetter((_a = colorOverLifetime.opacity) !== null && _a !== void 0 ? _a : 1);
14348
- if (colorOverLifetime.color && colorOverLifetime.color[0] === ValueType$1.GRADIENT_COLOR) {
14349
- this.colorOverLifetime = colorStopsFromGradient(colorOverLifetime.color[1]);
14329
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
14330
+ finally {
14331
+ try {
14332
+ if (_k && !_k.done && (_a = _j.return)) _a.call(_j);
14333
+ }
14334
+ finally { if (e_3) throw e_3.error; }
14350
14335
  }
14336
+ this.timelineStarted = true;
14351
14337
  }
14352
- this.startColor = clipData.startColor || [1, 1, 1, 1];
14353
- return this;
14354
- };
14355
- return SpriteColorPlayable;
14356
- }(Playable));
14357
- var SpriteComponent = /** @class */ (function (_super) {
14358
- __extends(SpriteComponent, _super);
14359
- function SpriteComponent(engine, props) {
14360
- var _this = _super.call(this, engine) || this;
14361
- _this.color = [1, 1, 1, 1];
14362
- _this.visible = true;
14363
- _this.getHitTestParams = function (force) {
14364
- var _a;
14365
- var ui = _this.interaction;
14366
- if ((force || ui)) {
14367
- var area = _this.getBoundingBox();
14368
- if (area) {
14369
- return {
14370
- behavior: ((_a = _this.interaction) === null || _a === void 0 ? void 0 : _a.behavior) || 0,
14371
- type: area.type,
14372
- triangles: area.area,
14373
- backfaceCulling: _this.renderer.side === SideMode$1.FRONT,
14374
- };
14338
+ var now = this.time;
14339
+ // 判断动画是否开始
14340
+ if (this.item.delaying && now >= 0 && now <= this.item.duration) {
14341
+ this.item.delaying = false;
14342
+ try {
14343
+ for (var _o = __values$1(this.tracks), _p = _o.next(); !_p.done; _p = _o.next()) {
14344
+ var track = _p.value;
14345
+ try {
14346
+ for (var _q = (e_6 = void 0, __values$1(track.getClips())), _r = _q.next(); !_r.done; _r = _q.next()) {
14347
+ var clip = _r.value;
14348
+ clip.playable.onPlayablePlay();
14349
+ }
14350
+ }
14351
+ catch (e_6_1) { e_6 = { error: e_6_1 }; }
14352
+ finally {
14353
+ try {
14354
+ if (_r && !_r.done && (_d = _q.return)) _d.call(_q);
14355
+ }
14356
+ finally { if (e_6) throw e_6.error; }
14357
+ }
14375
14358
  }
14376
14359
  }
14377
- };
14378
- if (props) {
14379
- _this.fromData(props);
14360
+ catch (e_5_1) { e_5 = { error: e_5_1 }; }
14361
+ finally {
14362
+ try {
14363
+ if (_p && !_p.done && (_c = _o.return)) _c.call(_o);
14364
+ }
14365
+ finally { if (e_5) throw e_5.error; }
14366
+ }
14380
14367
  }
14381
- return _this;
14382
- }
14383
- /**
14384
- * 设置当前 Mesh 的可见性。
14385
- * @param visible - true:可见,false:不可见
14386
- */
14387
- SpriteComponent.prototype.setVisible = function (visible) {
14388
- this.visible = visible;
14389
- };
14390
- /**
14391
- * 获取当前 Mesh 的可见性。
14392
- */
14393
- SpriteComponent.prototype.getVisible = function () {
14394
- return this.visible;
14395
- };
14396
- SpriteComponent.prototype.render = function (renderer) {
14397
- if (!this.getVisible()) {
14398
- return;
14368
+ // 判断动画是否结束
14369
+ var ended;
14370
+ if (VFXItem.isParticle(this.item)) {
14371
+ ended = this.item.isEnded(now) && this.item.content.destoryed;
14399
14372
  }
14400
- var material = this.material;
14401
- var geo = this.geometry;
14402
- if (renderer.renderingData.currentFrame.globalUniforms) {
14403
- renderer.setGlobalMatrix('effects_ObjectToWorld', this.transform.getWorldMatrix());
14373
+ else {
14374
+ ended = this.item.isEnded(now);
14404
14375
  }
14405
- this.material.setVector2('_Size', this.transform.size);
14406
- // 执行 Geometry 的数据刷新
14407
- geo.flush();
14408
- renderer.drawGeometry(geo, material);
14409
- };
14410
- SpriteComponent.prototype.start = function () {
14411
- this.priority = this.item.listIndex;
14412
- this.timelineComponent = this.item.getComponent(TimelineComponent);
14413
- this.item.getHitTestParams = this.getHitTestParams;
14414
- };
14415
- SpriteComponent.prototype.update = function (dt) {
14416
- var time = this.timelineComponent.getTime();
14417
- var duration = this.item.duration;
14418
- var life = Math.min(Math.max(time / duration, 0.0), 1.0);
14419
- var ta = this.textureSheetAnimation;
14420
- if (ta) {
14421
- var total = ta.total || (ta.row * ta.col);
14422
- var texRectX = 0;
14423
- var texRectY = 0;
14424
- var texRectW = 1;
14425
- var texRectH = 1;
14426
- var flip = void 0;
14427
- if (this.splits) {
14428
- var sp = this.splits[0];
14429
- flip = sp[4];
14430
- texRectX = sp[0];
14431
- texRectY = sp[1];
14432
- if (flip) {
14433
- texRectW = sp[3];
14434
- texRectH = sp[2];
14435
- }
14436
- else {
14437
- texRectW = sp[2];
14438
- texRectH = sp[3];
14376
+ if (ended) {
14377
+ var endBehavior = this.item.endBehavior;
14378
+ if (!this.item.ended) {
14379
+ this.item.ended = true;
14380
+ this.item.onEnd();
14381
+ if (endBehavior === END_BEHAVIOR_DESTROY$1) {
14382
+ try {
14383
+ for (var _s = __values$1(this.tracks), _t = _s.next(); !_t.done; _t = _s.next()) {
14384
+ var track = _t.value;
14385
+ try {
14386
+ for (var _u = (e_8 = void 0, __values$1(track.getClips())), _v = _u.next(); !_v.done; _v = _u.next()) {
14387
+ var clip = _v.value;
14388
+ clip.playable.onPlayableDestroy();
14389
+ }
14390
+ }
14391
+ catch (e_8_1) { e_8 = { error: e_8_1 }; }
14392
+ finally {
14393
+ try {
14394
+ if (_v && !_v.done && (_f = _u.return)) _f.call(_u);
14395
+ }
14396
+ finally { if (e_8) throw e_8.error; }
14397
+ }
14398
+ }
14399
+ }
14400
+ catch (e_7_1) { e_7 = { error: e_7_1 }; }
14401
+ finally {
14402
+ try {
14403
+ if (_t && !_t.done && (_e = _s.return)) _e.call(_s);
14404
+ }
14405
+ finally { if (e_7) throw e_7.error; }
14406
+ }
14407
+ this.item.delaying = true;
14408
+ if (!this.item.reusable && !this.reusable) {
14409
+ this.item.dispose();
14410
+ return;
14411
+ }
14439
14412
  }
14440
14413
  }
14441
- var dx = void 0, dy = void 0;
14442
- if (flip) {
14443
- dx = 1 / ta.row * texRectW;
14444
- dy = 1 / ta.col * texRectH;
14414
+ }
14415
+ // TODO: [1.31] @茂安 验证 https://github.com/galacean/effects-runtime/commits/main/packages/effects-core/src/vfx-item.ts
14416
+ // 在生命周期内更新动画
14417
+ if (!this.item.delaying) {
14418
+ var lifetime = this.time / this.item.duration;
14419
+ this.item.lifetime = lifetime;
14420
+ try {
14421
+ for (var _w = __values$1(this.tracks), _x = _w.next(); !_x.done; _x = _w.next()) {
14422
+ var track = _x.value;
14423
+ try {
14424
+ for (var _y = (e_10 = void 0, __values$1(track.getClips())), _z = _y.next(); !_z.done; _z = _y.next()) {
14425
+ var clip = _z.value;
14426
+ clip.playable.setTime(this.time);
14427
+ }
14428
+ }
14429
+ catch (e_10_1) { e_10 = { error: e_10_1 }; }
14430
+ finally {
14431
+ try {
14432
+ if (_z && !_z.done && (_h = _y.return)) _h.call(_y);
14433
+ }
14434
+ finally { if (e_10) throw e_10.error; }
14435
+ }
14436
+ }
14445
14437
  }
14446
- else {
14447
- dx = 1 / ta.col * texRectW;
14448
- dy = 1 / ta.row * texRectH;
14438
+ catch (e_9_1) { e_9 = { error: e_9_1 }; }
14439
+ finally {
14440
+ try {
14441
+ if (_x && !_x.done && (_g = _w.return)) _g.call(_w);
14442
+ }
14443
+ finally { if (e_9) throw e_9.error; }
14449
14444
  }
14450
- var texOffset = void 0;
14451
- if (ta.animate) {
14452
- var frameIndex = Math.round(life * (total - 1));
14453
- var yIndex = Math.floor(frameIndex / ta.col);
14454
- var xIndex = frameIndex - yIndex * ta.col;
14455
- texOffset = flip ? [dx * yIndex, dy * (ta.col - xIndex)] : [dx * xIndex, dy * (1 + yIndex)];
14445
+ this.playableGraph.evaluate(dt);
14446
+ }
14447
+ };
14448
+ // time 单位秒
14449
+ TimelineComponent.prototype.setTime = function (time) {
14450
+ this.time = time;
14451
+ };
14452
+ TimelineComponent.prototype.getTime = function () {
14453
+ return this.time;
14454
+ };
14455
+ TimelineComponent.prototype.toLocalTime = function (time) {
14456
+ var localTime = time - this.options.start;
14457
+ var duration = this.options.duration;
14458
+ if (localTime - duration > 0.001) {
14459
+ if (this.options.endBehavior === END_BEHAVIOR_RESTART$1) {
14460
+ localTime = localTime % duration;
14456
14461
  }
14457
- else {
14458
- texOffset = [0, dy];
14462
+ else if (this.options.endBehavior === END_BEHAVIOR_FREEZE$1) {
14463
+ localTime = Math.min(duration, localTime);
14459
14464
  }
14460
- this.material.getVector4('_TexOffset').setFromArray([
14461
- texRectX + texOffset[0],
14462
- texRectH + texRectY - texOffset[1],
14463
- dx, dy,
14464
- ]);
14465
14465
  }
14466
+ return localTime;
14466
14467
  };
14467
- SpriteComponent.prototype.onDestroy = function () {
14468
- if (this.item && this.item.composition) {
14469
- this.item.composition.destroyTextures(this.getTextures());
14470
- }
14468
+ TimelineComponent.prototype.createTrack = function (classConstructor, name) {
14469
+ var newTrack = new classConstructor();
14470
+ newTrack.bindingItem = this.item;
14471
+ newTrack.id = (this.trackSeed++).toString();
14472
+ newTrack.name = name ? name : 'Track' + newTrack.id;
14473
+ this.tracks.push(newTrack);
14474
+ return newTrack;
14471
14475
  };
14472
- SpriteComponent.prototype.getItemInitData = function (item, idx, pointStartIndex, textureIndex) {
14473
- var geoData = item.geoData;
14474
- if (!geoData) {
14475
- geoData = item.geoData = this.getItemGeometryData(item, idx);
14476
+ TimelineComponent.prototype.getTracks = function () {
14477
+ return this.tracks;
14478
+ };
14479
+ TimelineComponent.prototype.findTrack = function (name) {
14480
+ var e_11, _a;
14481
+ try {
14482
+ for (var _b = __values$1(this.tracks), _c = _b.next(); !_c.done; _c = _b.next()) {
14483
+ var track = _c.value;
14484
+ if (track.name === name) {
14485
+ return track;
14486
+ }
14487
+ }
14476
14488
  }
14477
- var index = geoData.index;
14478
- var idxCount = index.length;
14479
- // @ts-expect-error
14480
- var indexData = this.wireframe ? new Uint8Array([0, 1, 1, 3, 2, 3, 2, 0]) : new index.constructor(idxCount);
14481
- if (!this.wireframe) {
14482
- for (var i = 0; i < idxCount; i++) {
14483
- indexData[i] = pointStartIndex + index[i];
14489
+ catch (e_11_1) { e_11 = { error: e_11_1 }; }
14490
+ finally {
14491
+ try {
14492
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14484
14493
  }
14494
+ finally { if (e_11) throw e_11.error; }
14485
14495
  }
14486
- return {
14487
- atlasOffset: geoData.atlasOffset,
14488
- index: indexData,
14489
- };
14490
14496
  };
14491
- SpriteComponent.prototype.setItem = function () {
14492
- var textures = [];
14493
- var texture = this.renderer.texture;
14494
- if (texture) {
14495
- addItem(textures, texture);
14496
- }
14497
- texture = this.renderer.texture;
14498
- var textureIndex = texture ? textures.indexOf(texture) : -1;
14499
- var data = this.getItemInitData(this, 0, 0, textureIndex);
14500
- var renderer = this.renderer;
14501
- var texParams = this.material.getVector4('_TexParams');
14502
- texParams.x = renderer.occlusion ? +(renderer.transparentOcclusion) : 1;
14503
- texParams.y = +this.preMultiAlpha;
14504
- texParams.z = renderer.renderMode;
14505
- var attributes = {
14506
- atlasOffset: new Float32Array(data.atlasOffset.length),
14507
- index: new Uint16Array(data.index.length),
14508
- };
14509
- attributes.atlasOffset.set(data.atlasOffset);
14510
- attributes.index.set(data.index);
14511
- var _a = this, material = _a.material, geometry = _a.geometry;
14512
- var indexData = attributes.index;
14513
- geometry.setIndexData(indexData);
14514
- geometry.setAttributeData('atlasOffset', attributes.atlasOffset);
14515
- geometry.setDrawCount(data.index.length);
14516
- for (var i = 0; i < textures.length; i++) {
14517
- var texture_1 = textures[i];
14518
- material.setTexture('uSampler' + i, texture_1);
14497
+ TimelineComponent.prototype.rebuildGraph = function () {
14498
+ this.playableGraph = new PlayableGraph();
14499
+ this.compileTracks(this.playableGraph);
14500
+ };
14501
+ TimelineComponent.prototype.compileTracks = function (graph) {
14502
+ var e_12, _a;
14503
+ try {
14504
+ for (var _b = __values$1(this.tracks), _c = _b.next(); !_c.done; _c = _b.next()) {
14505
+ var track = _c.value;
14506
+ var trackMixPlayable = track.createPlayebleTree();
14507
+ var trackOutput = track.createOutput();
14508
+ graph.addOutput(trackOutput);
14509
+ trackOutput.setSourcePlayeble(trackMixPlayable);
14510
+ }
14519
14511
  }
14520
- // FIXME: 内存泄漏的临时方案,后面再调整
14521
- var emptyTexture = this.emptyTexture;
14522
- for (var k = textures.length; k < exports.maxSpriteMeshItemCount; k++) {
14523
- material.setTexture('uSampler' + k, emptyTexture);
14512
+ catch (e_12_1) { e_12 = { error: e_12_1 }; }
14513
+ finally {
14514
+ try {
14515
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
14516
+ }
14517
+ finally { if (e_12) throw e_12.error; }
14524
14518
  }
14525
14519
  };
14526
- SpriteComponent.prototype.createGeometry = function (mode) {
14527
- var maxVertex = 12 * this.splits.length;
14528
- return Geometry.create(this.engine, {
14529
- attributes: {
14530
- aPos: {
14531
- type: glContext.FLOAT,
14532
- size: 3,
14533
- data: new Float32Array([
14534
- -0.5, 0.5, 0,
14535
- -0.5, -0.5, 0,
14536
- 0.5, 0.5, 0,
14537
- 0.5, -0.5, 0, //右下
14538
- ]),
14539
- },
14540
- atlasOffset: {
14541
- size: 2,
14542
- offset: 0,
14543
- releasable: true,
14544
- type: glContext.FLOAT,
14545
- data: new Float32Array(0),
14546
- },
14547
- },
14548
- indices: { data: new Uint16Array(0), releasable: true },
14549
- mode: mode,
14550
- maxVertex: maxVertex,
14551
- });
14552
- };
14553
- SpriteComponent.prototype.createMaterial = function (renderInfo, count) {
14554
- var side = renderInfo.side, occlusion = renderInfo.occlusion, blending = renderInfo.blending, maskMode = renderInfo.maskMode, mask = renderInfo.mask;
14555
- var materialProps = {
14556
- shader: spriteMeshShaderFromRenderInfo(renderInfo, count, 1),
14557
- };
14558
- this.preMultiAlpha = getPreMultiAlpha(blending);
14559
- var material = Material.create(this.engine, materialProps);
14560
- var states = {
14561
- side: side,
14562
- blending: true,
14563
- blendMode: blending,
14564
- mask: mask,
14565
- maskMode: maskMode,
14566
- depthTest: true,
14567
- depthMask: occlusion,
14520
+ TimelineComponent.prototype.fromData = function (data) {
14521
+ _super.prototype.fromData.call(this, data);
14522
+ this.options = {
14523
+ start: this.item.start,
14524
+ duration: this.item.duration,
14525
+ looping: this.item.endBehavior === END_BEHAVIOR_RESTART$1,
14526
+ endBehavior: this.item.endBehavior || END_BEHAVIOR_DESTROY$1,
14568
14527
  };
14569
- material.blending = states.blending;
14570
- material.stencilRef = states.mask !== undefined ? [states.mask, states.mask] : undefined;
14571
- material.depthTest = states.depthTest;
14572
- material.depthMask = states.depthMask;
14573
- setBlendMode(material, states.blendMode);
14574
- setMaskMode(material, states.maskMode);
14575
- setSideMode(material, states.side);
14576
- if (!material.hasUniform('_Color')) {
14577
- material.setVector4('_Color', new Vector4$1(0, 0, 0, 1));
14528
+ this.id = this.item.id;
14529
+ this.name = this.item.name;
14530
+ var activationTrack = this.createTrack(Track, 'ActivationTrack');
14531
+ activationTrack.createClip(ActivationClipPlayable, 'ActivationTimelineClip');
14532
+ };
14533
+ TimelineComponent.prototype.toData = function () {
14534
+ _super.prototype.toData.call(this);
14535
+ };
14536
+ __decorate([
14537
+ serialize()
14538
+ ], TimelineComponent.prototype, "time", void 0);
14539
+ return TimelineComponent;
14540
+ }(ItemBehaviour));
14541
+
14542
+ var singleSplits = [[0, 0, 1, 1, undefined]];
14543
+ var tempColor = [1, 1, 1, 1];
14544
+ var seed$6 = 0;
14545
+ var SpriteColorPlayable = /** @class */ (function (_super) {
14546
+ __extends(SpriteColorPlayable, _super);
14547
+ function SpriteColorPlayable() {
14548
+ var _this = _super !== null && _super.apply(this, arguments) || this;
14549
+ _this.renderColor = [1, 1, 1, 1];
14550
+ return _this;
14551
+ }
14552
+ SpriteColorPlayable.prototype.onPlayablePlay = function () {
14553
+ this.spriteMaterial = this.bindingItem.getComponent(SpriteComponent).material;
14554
+ };
14555
+ SpriteColorPlayable.prototype.processFrame = function (dt) {
14556
+ var colorInc = vecFill(tempColor, 1);
14557
+ var colorChanged;
14558
+ var life = this.time / this.bindingItem.duration;
14559
+ var opacityOverLifetime = this.opacityOverLifetime;
14560
+ var colorOverLifetime = this.colorOverLifetime;
14561
+ if (colorOverLifetime) {
14562
+ colorInc = getColorFromGradientStops(colorOverLifetime, life, true);
14563
+ colorChanged = true;
14578
14564
  }
14579
- if (!material.hasUniform('_TexOffset')) {
14580
- material.setVector4('_TexOffset', new Vector4$1());
14565
+ if (opacityOverLifetime) {
14566
+ colorInc[3] *= opacityOverLifetime.getValue(life);
14567
+ colorChanged = true;
14581
14568
  }
14582
- if (!material.hasUniform('_TexParams')) {
14583
- material.setVector4('_TexParams', new Vector4$1());
14569
+ if (colorChanged) {
14570
+ vecMulCombine(this.renderColor, colorInc, this.startColor);
14571
+ this.spriteMaterial.getVector4('_Color').setFromArray(this.renderColor);
14584
14572
  }
14585
- return material;
14586
14573
  };
14587
- SpriteComponent.prototype.getItemGeometryData = function (item, aIndex) {
14588
- var splits = item.splits, renderer = item.renderer, textureSheetAnimation = item.textureSheetAnimation;
14589
- var sx = 1, sy = 1;
14590
- if (renderer.shape) {
14591
- var _a = renderer.shape, index_1 = _a.index, aPoint = _a.aPoint;
14592
- var point = new Float32Array(aPoint);
14593
- var position_1 = [];
14594
- var atlasOffset_1 = [];
14595
- for (var i = 0; i < point.length; i += 6) {
14596
- point[i] *= sx;
14597
- point[i + 1] *= sy;
14598
- atlasOffset_1.push(aPoint[i + 2], aPoint[i + 3]);
14599
- position_1.push(point[i], point[i + 1], 0.0);
14600
- }
14601
- this.geometry.setAttributeData('aPos', new Float32Array(position_1));
14602
- return {
14603
- index: index_1,
14604
- atlasOffset: atlasOffset_1,
14605
- };
14606
- }
14607
- var originData = [-.5, .5, -.5, -.5, .5, .5, .5, -.5];
14608
- var atlasOffset = [];
14609
- var index = [];
14610
- var col = 2;
14611
- var row = 2;
14612
- if (splits.length === 1) {
14613
- col = 1;
14614
- row = 1;
14615
- }
14616
- var position = [];
14617
- for (var x = 0; x < col; x++) {
14618
- for (var y = 0; y < row; y++) {
14619
- var base = (y * 2 + x) * 4;
14620
- // @ts-expect-error
14621
- var split = textureSheetAnimation ? [0, 0, 1, 1, splits[0][4]] : splits[y * 2 + x];
14622
- var texOffset = split[4] ? [0, 0, 1, 0, 0, 1, 1, 1] : [0, 1, 0, 0, 1, 1, 1, 0];
14623
- var dw = ((x + x + 1) / col - 1) / 2;
14624
- var dh = ((y + y + 1) / row - 1) / 2;
14625
- var tox = split[0];
14626
- var toy = split[1];
14627
- var tsx = split[4] ? split[3] : split[2];
14628
- var tsy = split[4] ? split[2] : split[3];
14629
- var origin_1 = [
14630
- originData[0] / col + dw,
14631
- originData[1] / row + dh,
14632
- originData[2] / col + dw,
14633
- originData[3] / row + dh,
14634
- originData[4] / col + dw,
14635
- originData[5] / row + dh,
14636
- originData[6] / col + dw,
14637
- originData[7] / row + dh,
14638
- ];
14639
- atlasOffset.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);
14640
- position.push((origin_1[0]) * sx, (origin_1[1]) * sy, 0.0, (origin_1[2]) * sx, (origin_1[3]) * sy, 0.0, (origin_1[4]) * sx, (origin_1[5]) * sy, 0.0, (origin_1[6]) * sx, (origin_1[7]) * sy, 0.0);
14641
- index.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
14574
+ SpriteColorPlayable.prototype.fromData = function (clipData) {
14575
+ var _a;
14576
+ this.clipData = clipData;
14577
+ var colorOverLifetime = clipData.colorOverLifetime;
14578
+ if (colorOverLifetime) {
14579
+ this.opacityOverLifetime = createValueGetter((_a = colorOverLifetime.opacity) !== null && _a !== void 0 ? _a : 1);
14580
+ if (colorOverLifetime.color && colorOverLifetime.color[0] === ValueType$1.GRADIENT_COLOR) {
14581
+ this.colorOverLifetime = colorStopsFromGradient(colorOverLifetime.color[1]);
14642
14582
  }
14643
14583
  }
14644
- this.geometry.setAttributeData('aPos', new Float32Array(position));
14645
- return { index: index, atlasOffset: atlasOffset };
14584
+ this.startColor = clipData.startColor || [1, 1, 1, 1];
14585
+ return this;
14646
14586
  };
14647
- SpriteComponent.prototype.getTextures = function () {
14648
- var ret = [];
14649
- var tex = this.renderer.texture;
14650
- if (tex) {
14651
- ret.push(tex);
14587
+ return SpriteColorPlayable;
14588
+ }(Playable));
14589
+ var SpriteComponent = /** @class */ (function (_super) {
14590
+ __extends(SpriteComponent, _super);
14591
+ function SpriteComponent(engine, props) {
14592
+ var _this = _super.call(this, engine) || this;
14593
+ _this.color = [1, 1, 1, 1];
14594
+ _this.visible = true;
14595
+ _this.getHitTestParams = function (force) {
14596
+ var _a;
14597
+ var ui = _this.interaction;
14598
+ if ((force || ui)) {
14599
+ var area = _this.getBoundingBox();
14600
+ if (area) {
14601
+ return {
14602
+ behavior: ((_a = _this.interaction) === null || _a === void 0 ? void 0 : _a.behavior) || 0,
14603
+ type: area.type,
14604
+ triangles: area.area,
14605
+ backfaceCulling: _this.renderer.side === SideMode$1.FRONT,
14606
+ };
14607
+ }
14608
+ }
14609
+ };
14610
+ if (props) {
14611
+ _this.fromData(props);
14652
14612
  }
14653
- return ret;
14613
+ return _this;
14614
+ }
14615
+ /**
14616
+ * 设置当前 Mesh 的可见性。
14617
+ * @param visible - true:可见,false:不可见
14618
+ */
14619
+ SpriteComponent.prototype.setVisible = function (visible) {
14620
+ this.visible = visible;
14654
14621
  };
14655
14622
  /**
14656
- * 获取图层包围盒的类型和世界坐标
14657
- * @returns
14623
+ * 获取当前 Mesh 的可见性。
14658
14624
  */
14659
- SpriteComponent.prototype.getBoundingBox = function () {
14660
- if (!this.item) {
14625
+ SpriteComponent.prototype.getVisible = function () {
14626
+ return this.visible;
14627
+ };
14628
+ SpriteComponent.prototype.render = function (renderer) {
14629
+ if (!this.getVisible()) {
14661
14630
  return;
14662
14631
  }
14663
- var worldMatrix = this.transform.getWorldMatrix();
14664
- var triangles = trianglesFromRect(Vector3.ZERO, 1 / 2, 1 / 2);
14665
- triangles.forEach(function (triangle) {
14666
- worldMatrix.transformPoint(triangle.p0);
14667
- worldMatrix.transformPoint(triangle.p1);
14668
- worldMatrix.transformPoint(triangle.p2);
14669
- });
14670
- return {
14671
- type: exports.HitTestType.triangle,
14672
- area: triangles,
14673
- };
14674
- };
14675
- // TODO: [1.31] @十弦 https://github.com/galacean/effects-runtime/commit/fe8736540b9a461d8e96658f4d755ff8089a263b#diff-a3618f4527c5fe6e842f20d67d5c82984568502c6bf6fdfcbd24f69e2894ca90
14676
- SpriteComponent.prototype.fromData = function (data) {
14677
- var _a, _b, _c, _d, _e, _f;
14678
- _super.prototype.fromData.call(this, data);
14679
- var interaction = data.interaction, options = data.options, _g = data.listIndex, listIndex = _g === void 0 ? 0 : _g;
14680
- var renderer = data.renderer;
14681
- if (!renderer) {
14682
- //@ts-expect-error
14683
- renderer = {};
14632
+ var material = this.material;
14633
+ var geo = this.geometry;
14634
+ if (renderer.renderingData.currentFrame.globalUniforms) {
14635
+ renderer.setGlobalMatrix('effects_ObjectToWorld', this.transform.getWorldMatrix());
14684
14636
  }
14685
- this.interaction = interaction;
14686
- this.renderer = {
14687
- renderMode: (_a = renderer.renderMode) !== null && _a !== void 0 ? _a : RenderMode$1.BILLBOARD,
14688
- blending: (_b = renderer.blending) !== null && _b !== void 0 ? _b : BlendingMode$1.ALPHA,
14689
- texture: (_c = renderer.texture) !== null && _c !== void 0 ? _c : this.engine.emptyTexture,
14690
- occlusion: !!(renderer.occlusion),
14691
- transparentOcclusion: !!(renderer.transparentOcclusion) || (renderer.maskMode === MaskMode$1.MASK),
14692
- side: (_d = renderer.side) !== null && _d !== void 0 ? _d : SideMode$1.DOUBLE,
14693
- shape: renderer.shape,
14694
- mask: (_e = renderer.mask) !== null && _e !== void 0 ? _e : 0,
14695
- maskMode: (_f = renderer.maskMode) !== null && _f !== void 0 ? _f : MaskMode$1.NONE,
14696
- order: listIndex,
14697
- };
14698
- this.emptyTexture = this.engine.emptyTexture;
14699
- this.splits = data.splits || singleSplits;
14700
- this.textureSheetAnimation = data.textureSheetAnimation;
14701
- this.cachePrefix = '-';
14702
- this.renderInfo = getImageItemRenderInfo(this);
14703
- var geometry = this.createGeometry(glContext.TRIANGLES);
14704
- var material = this.createMaterial(this.renderInfo, 2);
14705
- this.worldMatrix = Matrix4$1.fromIdentity();
14706
- this.material = material;
14707
- this.geometry = geometry;
14708
- this.name = 'MSprite' + seed$7++;
14709
- var startColor = options.startColor || [1, 1, 1, 1];
14710
- this.material.setVector4('_Color', new Vector4$1().setFromArray(startColor));
14711
- this.material.setVector4('_TexOffset', new Vector4$1().setFromArray([0, 0, 1, 1]));
14712
- this.setItem();
14713
- // 添加K帧动画
14714
- var colorTrack = this.item.getComponent(TimelineComponent).createTrack(Track, 'SpriteColorTrack');
14715
- colorTrack.createClip(SpriteColorPlayable, 'SpriteColorClip').playable.fromData({ colorOverLifetime: data.colorOverLifetime, startColor: data.options.startColor });
14716
- };
14717
- SpriteComponent.prototype.toData = function () {
14718
- _super.prototype.toData.call(this);
14637
+ this.material.setVector2('_Size', this.transform.size);
14638
+ // 执行 Geometry 的数据刷新
14639
+ geo.flush();
14640
+ renderer.drawGeometry(geo, material);
14719
14641
  };
14720
- SpriteComponent = __decorate([
14642
+ SpriteComponent.prototype.start = function () {
14643
+ this.priority = this.item.listIndex;
14644
+ this.timelineComponent = this.item.getComponent(TimelineComponent);
14645
+ this.item.getHitTestParams = this.getHitTestParams;
14646
+ };
14647
+ SpriteComponent.prototype.update = function (dt) {
14648
+ var time = this.timelineComponent.getTime();
14649
+ var duration = this.item.duration;
14650
+ var life = Math.min(Math.max(time / duration, 0.0), 1.0);
14651
+ var ta = this.textureSheetAnimation;
14652
+ if (ta) {
14653
+ var total = ta.total || (ta.row * ta.col);
14654
+ var texRectX = 0;
14655
+ var texRectY = 0;
14656
+ var texRectW = 1;
14657
+ var texRectH = 1;
14658
+ var flip = void 0;
14659
+ if (this.splits) {
14660
+ var sp = this.splits[0];
14661
+ flip = sp[4];
14662
+ texRectX = sp[0];
14663
+ texRectY = sp[1];
14664
+ if (flip) {
14665
+ texRectW = sp[3];
14666
+ texRectH = sp[2];
14667
+ }
14668
+ else {
14669
+ texRectW = sp[2];
14670
+ texRectH = sp[3];
14671
+ }
14672
+ }
14673
+ var dx = void 0, dy = void 0;
14674
+ if (flip) {
14675
+ dx = 1 / ta.row * texRectW;
14676
+ dy = 1 / ta.col * texRectH;
14677
+ }
14678
+ else {
14679
+ dx = 1 / ta.col * texRectW;
14680
+ dy = 1 / ta.row * texRectH;
14681
+ }
14682
+ var texOffset = void 0;
14683
+ if (ta.animate) {
14684
+ var frameIndex = Math.round(life * (total - 1));
14685
+ var yIndex = Math.floor(frameIndex / ta.col);
14686
+ var xIndex = frameIndex - yIndex * ta.col;
14687
+ texOffset = flip ? [dx * yIndex, dy * (ta.col - xIndex)] : [dx * xIndex, dy * (1 + yIndex)];
14688
+ }
14689
+ else {
14690
+ texOffset = [0, dy];
14691
+ }
14692
+ this.material.getVector4('_TexOffset').setFromArray([
14693
+ texRectX + texOffset[0],
14694
+ texRectH + texRectY - texOffset[1],
14695
+ dx, dy,
14696
+ ]);
14697
+ }
14698
+ };
14699
+ SpriteComponent.prototype.onDestroy = function () {
14700
+ if (this.item && this.item.composition) {
14701
+ this.item.composition.destroyTextures(this.getTextures());
14702
+ }
14703
+ };
14704
+ SpriteComponent.prototype.getItemInitData = function (item, idx, pointStartIndex, textureIndex) {
14705
+ var geoData = item.geoData;
14706
+ if (!geoData) {
14707
+ geoData = item.geoData = this.getItemGeometryData(item, idx);
14708
+ }
14709
+ var index = geoData.index;
14710
+ var idxCount = index.length;
14711
+ // @ts-expect-error
14712
+ var indexData = this.wireframe ? new Uint8Array([0, 1, 1, 3, 2, 3, 2, 0]) : new index.constructor(idxCount);
14713
+ if (!this.wireframe) {
14714
+ for (var i = 0; i < idxCount; i++) {
14715
+ indexData[i] = pointStartIndex + index[i];
14716
+ }
14717
+ }
14718
+ return {
14719
+ atlasOffset: geoData.atlasOffset,
14720
+ index: indexData,
14721
+ };
14722
+ };
14723
+ SpriteComponent.prototype.setItem = function () {
14724
+ var textures = [];
14725
+ var texture = this.renderer.texture;
14726
+ if (texture) {
14727
+ addItem(textures, texture);
14728
+ }
14729
+ texture = this.renderer.texture;
14730
+ var textureIndex = texture ? textures.indexOf(texture) : -1;
14731
+ var data = this.getItemInitData(this, 0, 0, textureIndex);
14732
+ var renderer = this.renderer;
14733
+ var texParams = this.material.getVector4('_TexParams');
14734
+ texParams.x = renderer.occlusion ? +(renderer.transparentOcclusion) : 1;
14735
+ texParams.y = +this.preMultiAlpha;
14736
+ texParams.z = renderer.renderMode;
14737
+ var attributes = {
14738
+ atlasOffset: new Float32Array(data.atlasOffset.length),
14739
+ index: new Uint16Array(data.index.length),
14740
+ };
14741
+ attributes.atlasOffset.set(data.atlasOffset);
14742
+ attributes.index.set(data.index);
14743
+ var _a = this, material = _a.material, geometry = _a.geometry;
14744
+ var indexData = attributes.index;
14745
+ geometry.setIndexData(indexData);
14746
+ geometry.setAttributeData('atlasOffset', attributes.atlasOffset);
14747
+ geometry.setDrawCount(data.index.length);
14748
+ for (var i = 0; i < textures.length; i++) {
14749
+ var texture_1 = textures[i];
14750
+ material.setTexture('uSampler' + i, texture_1);
14751
+ }
14752
+ // FIXME: 内存泄漏的临时方案,后面再调整
14753
+ var emptyTexture = this.emptyTexture;
14754
+ for (var k = textures.length; k < exports.maxSpriteMeshItemCount; k++) {
14755
+ material.setTexture('uSampler' + k, emptyTexture);
14756
+ }
14757
+ };
14758
+ SpriteComponent.prototype.createGeometry = function (mode) {
14759
+ var maxVertex = 12 * this.splits.length;
14760
+ return Geometry.create(this.engine, {
14761
+ attributes: {
14762
+ aPos: {
14763
+ type: glContext.FLOAT,
14764
+ size: 3,
14765
+ data: new Float32Array([
14766
+ -0.5, 0.5, 0,
14767
+ -0.5, -0.5, 0,
14768
+ 0.5, 0.5, 0,
14769
+ 0.5, -0.5, 0, //右下
14770
+ ]),
14771
+ },
14772
+ atlasOffset: {
14773
+ size: 2,
14774
+ offset: 0,
14775
+ releasable: true,
14776
+ type: glContext.FLOAT,
14777
+ data: new Float32Array(0),
14778
+ },
14779
+ },
14780
+ indices: { data: new Uint16Array(0), releasable: true },
14781
+ mode: mode,
14782
+ maxVertex: maxVertex,
14783
+ });
14784
+ };
14785
+ SpriteComponent.prototype.createMaterial = function (renderInfo, count) {
14786
+ var side = renderInfo.side, occlusion = renderInfo.occlusion, blending = renderInfo.blending, maskMode = renderInfo.maskMode, mask = renderInfo.mask;
14787
+ var materialProps = {
14788
+ shader: spriteMeshShaderFromRenderInfo(renderInfo, count, 1),
14789
+ };
14790
+ this.preMultiAlpha = getPreMultiAlpha(blending);
14791
+ var material = Material.create(this.engine, materialProps);
14792
+ var states = {
14793
+ side: side,
14794
+ blending: true,
14795
+ blendMode: blending,
14796
+ mask: mask,
14797
+ maskMode: maskMode,
14798
+ depthTest: true,
14799
+ depthMask: occlusion,
14800
+ };
14801
+ material.blending = states.blending;
14802
+ material.stencilRef = states.mask !== undefined ? [states.mask, states.mask] : undefined;
14803
+ material.depthTest = states.depthTest;
14804
+ material.depthMask = states.depthMask;
14805
+ setBlendMode(material, states.blendMode);
14806
+ setMaskMode(material, states.maskMode);
14807
+ setSideMode(material, states.side);
14808
+ if (!material.hasUniform('_Color')) {
14809
+ material.setVector4('_Color', new Vector4$1(0, 0, 0, 1));
14810
+ }
14811
+ if (!material.hasUniform('_TexOffset')) {
14812
+ material.setVector4('_TexOffset', new Vector4$1());
14813
+ }
14814
+ if (!material.hasUniform('_TexParams')) {
14815
+ material.setVector4('_TexParams', new Vector4$1());
14816
+ }
14817
+ return material;
14818
+ };
14819
+ SpriteComponent.prototype.getItemGeometryData = function (item, aIndex) {
14820
+ var splits = item.splits, renderer = item.renderer, textureSheetAnimation = item.textureSheetAnimation;
14821
+ var sx = 1, sy = 1;
14822
+ if (renderer.shape) {
14823
+ var _a = renderer.shape, index_1 = _a.index, aPoint = _a.aPoint;
14824
+ var point = new Float32Array(aPoint);
14825
+ var position_1 = [];
14826
+ var atlasOffset_1 = [];
14827
+ for (var i = 0; i < point.length; i += 6) {
14828
+ point[i] *= sx;
14829
+ point[i + 1] *= sy;
14830
+ atlasOffset_1.push(aPoint[i + 2], aPoint[i + 3]);
14831
+ position_1.push(point[i], point[i + 1], 0.0);
14832
+ }
14833
+ this.geometry.setAttributeData('aPos', new Float32Array(position_1));
14834
+ return {
14835
+ index: index_1,
14836
+ atlasOffset: atlasOffset_1,
14837
+ };
14838
+ }
14839
+ var originData = [-.5, .5, -.5, -.5, .5, .5, .5, -.5];
14840
+ var atlasOffset = [];
14841
+ var index = [];
14842
+ var col = 2;
14843
+ var row = 2;
14844
+ if (splits.length === 1) {
14845
+ col = 1;
14846
+ row = 1;
14847
+ }
14848
+ var position = [];
14849
+ for (var x = 0; x < col; x++) {
14850
+ for (var y = 0; y < row; y++) {
14851
+ var base = (y * 2 + x) * 4;
14852
+ // @ts-expect-error
14853
+ var split = textureSheetAnimation ? [0, 0, 1, 1, splits[0][4]] : splits[y * 2 + x];
14854
+ var texOffset = split[4] ? [0, 0, 1, 0, 0, 1, 1, 1] : [0, 1, 0, 0, 1, 1, 1, 0];
14855
+ var dw = ((x + x + 1) / col - 1) / 2;
14856
+ var dh = ((y + y + 1) / row - 1) / 2;
14857
+ var tox = split[0];
14858
+ var toy = split[1];
14859
+ var tsx = split[4] ? split[3] : split[2];
14860
+ var tsy = split[4] ? split[2] : split[3];
14861
+ var origin_1 = [
14862
+ originData[0] / col + dw,
14863
+ originData[1] / row + dh,
14864
+ originData[2] / col + dw,
14865
+ originData[3] / row + dh,
14866
+ originData[4] / col + dw,
14867
+ originData[5] / row + dh,
14868
+ originData[6] / col + dw,
14869
+ originData[7] / row + dh,
14870
+ ];
14871
+ atlasOffset.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);
14872
+ position.push((origin_1[0]) * sx, (origin_1[1]) * sy, 0.0, (origin_1[2]) * sx, (origin_1[3]) * sy, 0.0, (origin_1[4]) * sx, (origin_1[5]) * sy, 0.0, (origin_1[6]) * sx, (origin_1[7]) * sy, 0.0);
14873
+ index.push(base, 1 + base, 2 + base, 2 + base, 1 + base, 3 + base);
14874
+ }
14875
+ }
14876
+ this.geometry.setAttributeData('aPos', new Float32Array(position));
14877
+ return { index: index, atlasOffset: atlasOffset };
14878
+ };
14879
+ SpriteComponent.prototype.getTextures = function () {
14880
+ var ret = [];
14881
+ var tex = this.renderer.texture;
14882
+ if (tex) {
14883
+ ret.push(tex);
14884
+ }
14885
+ return ret;
14886
+ };
14887
+ /**
14888
+ * 获取图层包围盒的类型和世界坐标
14889
+ * @returns
14890
+ */
14891
+ SpriteComponent.prototype.getBoundingBox = function () {
14892
+ if (!this.item) {
14893
+ return;
14894
+ }
14895
+ var worldMatrix = this.transform.getWorldMatrix();
14896
+ var triangles = trianglesFromRect(Vector3.ZERO, 1 / 2, 1 / 2);
14897
+ triangles.forEach(function (triangle) {
14898
+ worldMatrix.transformPoint(triangle.p0);
14899
+ worldMatrix.transformPoint(triangle.p1);
14900
+ worldMatrix.transformPoint(triangle.p2);
14901
+ });
14902
+ return {
14903
+ type: exports.HitTestType.triangle,
14904
+ area: triangles,
14905
+ };
14906
+ };
14907
+ // TODO: [1.31] @十弦 https://github.com/galacean/effects-runtime/commit/fe8736540b9a461d8e96658f4d755ff8089a263b#diff-a3618f4527c5fe6e842f20d67d5c82984568502c6bf6fdfcbd24f69e2894ca90
14908
+ SpriteComponent.prototype.fromData = function (data) {
14909
+ var _a, _b, _c, _d, _e, _f;
14910
+ _super.prototype.fromData.call(this, data);
14911
+ var interaction = data.interaction, options = data.options, _g = data.listIndex, listIndex = _g === void 0 ? 0 : _g;
14912
+ var renderer = data.renderer;
14913
+ if (!renderer) {
14914
+ //@ts-expect-error
14915
+ renderer = {};
14916
+ }
14917
+ this.interaction = interaction;
14918
+ this.renderer = {
14919
+ renderMode: (_a = renderer.renderMode) !== null && _a !== void 0 ? _a : RenderMode$1.BILLBOARD,
14920
+ blending: (_b = renderer.blending) !== null && _b !== void 0 ? _b : BlendingMode$1.ALPHA,
14921
+ texture: (_c = renderer.texture) !== null && _c !== void 0 ? _c : this.engine.emptyTexture,
14922
+ occlusion: !!(renderer.occlusion),
14923
+ transparentOcclusion: !!(renderer.transparentOcclusion) || (renderer.maskMode === MaskMode$1.MASK),
14924
+ side: (_d = renderer.side) !== null && _d !== void 0 ? _d : SideMode$1.DOUBLE,
14925
+ shape: renderer.shape,
14926
+ mask: (_e = renderer.mask) !== null && _e !== void 0 ? _e : 0,
14927
+ maskMode: (_f = renderer.maskMode) !== null && _f !== void 0 ? _f : MaskMode$1.NONE,
14928
+ order: listIndex,
14929
+ };
14930
+ this.emptyTexture = this.engine.emptyTexture;
14931
+ this.splits = data.splits || singleSplits;
14932
+ this.textureSheetAnimation = data.textureSheetAnimation;
14933
+ this.cachePrefix = '-';
14934
+ this.renderInfo = getImageItemRenderInfo(this);
14935
+ var geometry = this.createGeometry(glContext.TRIANGLES);
14936
+ var material = this.createMaterial(this.renderInfo, 2);
14937
+ this.worldMatrix = Matrix4$1.fromIdentity();
14938
+ this.material = material;
14939
+ this.geometry = geometry;
14940
+ this.name = 'MSprite' + seed$6++;
14941
+ var startColor = options.startColor || [1, 1, 1, 1];
14942
+ this.material.setVector4('_Color', new Vector4$1().setFromArray(startColor));
14943
+ this.material.setVector4('_TexOffset', new Vector4$1().setFromArray([0, 0, 1, 1]));
14944
+ this.setItem();
14945
+ // 添加K帧动画
14946
+ var colorTrack = this.item.getComponent(TimelineComponent).createTrack(Track, 'SpriteColorTrack');
14947
+ colorTrack.createClip(SpriteColorPlayable, 'SpriteColorClip').playable.fromData({ colorOverLifetime: data.colorOverLifetime, startColor: data.options.startColor });
14948
+ };
14949
+ SpriteComponent.prototype.toData = function () {
14950
+ _super.prototype.toData.call(this);
14951
+ };
14952
+ SpriteComponent = __decorate([
14721
14953
  effectsClass(exports.DataType.SpriteComponent)
14722
14954
  ], SpriteComponent);
14723
14955
  return SpriteComponent;
@@ -17710,7 +17942,7 @@ var ParticleSystem = /** @class */ (function (_super) {
17710
17942
  sprite[1] = tsa.animationDuration.getValue(lifetime);
17711
17943
  sprite[2] = tsa.cycles.getValue(lifetime);
17712
17944
  }
17713
- var rot = tempRot$1;
17945
+ var rot = tempRot;
17714
17946
  if (options.start3DRotation) {
17715
17947
  // @ts-expect-error
17716
17948
  rot.set(options.startRotationX.getValue(lifetime), options.startRotationY.getValue(lifetime), options.startRotationZ.getValue(lifetime));
@@ -17726,7 +17958,7 @@ var ParticleSystem = /** @class */ (function (_super) {
17726
17958
  if (color.length === 3) {
17727
17959
  color[3] = 1;
17728
17960
  }
17729
- var size = tempSize$1;
17961
+ var size = tempSize;
17730
17962
  if (options.start3DSize) {
17731
17963
  size.x = options.startSizeX.getValue(lifetime);
17732
17964
  size.y = options.startSizeY.getValue(lifetime);
@@ -17888,7 +18120,8 @@ var ParticleSystem = /** @class */ (function (_super) {
17888
18120
  separateAxes: false,
17889
18121
  x: createValueGetter(('size' in sizeOverLifetime ? sizeOverLifetime.size : sizeOverLifetime.x) || 1),
17890
18122
  };
17891
- var anchor = Vector2.fromArray(convertAnchor(renderer.anchor, renderer.particleOrigin));
18123
+ renderer.anchor = renderer.anchor || [0, 0];
18124
+ var anchor = Vector2.fromArray(renderer.anchor);
17892
18125
  this.options = {
17893
18126
  particleFollowParent: !!options.particleFollowParent,
17894
18127
  startLifetime: createValueGetter(options.startLifetime),
@@ -17900,484 +18133,250 @@ var ParticleSystem = /** @class */ (function (_super) {
17900
18133
  maxCount: (_e = options.maxCount) !== null && _e !== void 0 ? _e : 0,
17901
18134
  gravityModifier: createValueGetter(gravityModifier || 0),
17902
18135
  gravity: gravity,
17903
- start3DSize: !!options.start3DSize,
17904
- startTurbulence: startTurbulence,
17905
- turbulence: turbulence,
17906
- speedOverLifetime: positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime),
17907
- linearVelOverLifetime: linearVelOverLifetime,
17908
- orbitalVelOverLifetime: orbitalVelOverLifetime,
17909
- forceTarget: forceTarget,
17910
- };
17911
- if (options.startRotationZ) {
17912
- this.options.startRotation = createValueGetter(options.startRotationZ || 0);
17913
- }
17914
- if (options.startRotationX || options.startRotationY) {
17915
- this.options.start3DRotation = true;
17916
- this.options.startRotationX = createValueGetter(options.startRotationX || 0);
17917
- this.options.startRotationY = createValueGetter(options.startRotationY || 0);
17918
- this.options.startRotationZ = createValueGetter(options.startRotationZ || 0);
17919
- }
17920
- if (options.start3DSize) {
17921
- this.options.startSizeX = createValueGetter(options.startSizeX);
17922
- this.options.startSizeY = createValueGetter(options.startSizeY);
17923
- }
17924
- else {
17925
- this.options.startSize = createValueGetter(options.startSize);
17926
- this.options.sizeAspect = createValueGetter(options.sizeAspect || 1);
17927
- }
17928
- var particleMeshProps = {
17929
- // listIndex: vfxItem.listIndex,
17930
- meshSlots: options.meshSlots,
17931
- name: this.name,
17932
- matrix: Matrix4$1.IDENTITY,
17933
- filter: props.filter,
17934
- shaderCachePrefix: shaderCachePrefix,
17935
- renderMode: renderer.renderMode || RenderMode$1.BILLBOARD,
17936
- side: renderer.side || SideMode$1.DOUBLE,
17937
- gravity: gravity,
17938
- // duration: vfxItem.duration,
17939
- blending: renderer.blending || BlendingMode$1.ALPHA,
17940
- rotationOverLifetime: rotationOverLifetime,
17941
- gravityModifier: this.options.gravityModifier,
17942
- linearVelOverLifetime: this.options.linearVelOverLifetime,
17943
- orbitalVelOverLifetime: this.options.orbitalVelOverLifetime,
17944
- speedOverLifetime: this.options.speedOverLifetime,
17945
- sprite: textureSheetAnimation,
17946
- occlusion: !!renderer.occlusion,
17947
- transparentOcclusion: !!renderer.transparentOcclusion,
17948
- maxCount: options.maxCount,
17949
- mask: renderer.mask,
17950
- maskMode: (_f = renderer.maskMode) !== null && _f !== void 0 ? _f : MaskMode$1.NONE,
17951
- forceTarget: forceTarget,
17952
- diffuse: renderer.texture,
17953
- sizeOverLifetime: sizeOverLifetimeGetter,
17954
- anchor: anchor,
17955
- };
17956
- if (colorOverLifetime) {
17957
- var color = colorOverLifetime.color, opacity = colorOverLifetime.opacity;
17958
- particleMeshProps.colorOverLifetime = {};
17959
- if (opacity) {
17960
- particleMeshProps.colorOverLifetime.opacity = createValueGetter(colorOverLifetime.opacity);
17961
- }
17962
- if (color) {
17963
- if (color[0] === ValueType$1.GRADIENT_COLOR) {
17964
- particleMeshProps.colorOverLifetime.color = colorOverLifetime.color[1];
17965
- }
17966
- else if (color[0] === ValueType$1.RGBA_COLOR) {
17967
- particleMeshProps.colorOverLifetime.color = Texture.createWithData(this.engine, {
17968
- data: new Uint8Array(color[1]),
17969
- width: 1,
17970
- height: 1,
17971
- });
17972
- }
17973
- else if (color instanceof Texture) {
17974
- particleMeshProps.colorOverLifetime.color = color;
17975
- }
17976
- }
17977
- }
17978
- var uvs = [];
17979
- var textureMap = [0, 0, 1, 1];
17980
- var flip;
17981
- if (props.splits) {
17982
- var s = props.splits[0];
17983
- flip = s[4];
17984
- textureMap = flip ? [s[0], s[1], s[3], s[2]] : [s[0], s[1], s[2], s[3]];
17985
- }
17986
- if (textureSheetAnimation && !textureSheetAnimation.animate) {
17987
- var col = flip ? textureSheetAnimation.row : textureSheetAnimation.col;
17988
- var row = flip ? textureSheetAnimation.col : textureSheetAnimation.row;
17989
- var total = textureSheetAnimation.total || col * row;
17990
- var index$1 = 0;
17991
- for (var x = 0; x < col; x++) {
17992
- for (var y = 0; y < row && index$1 < total; y++, index$1++) {
17993
- uvs.push([
17994
- x * textureMap[2] / col + textureMap[0],
17995
- y * textureMap[3] / row + textureMap[1],
17996
- textureMap[2] / col,
17997
- textureMap[3] / row
17998
- ]);
17999
- }
18000
- }
18001
- }
18002
- else {
18003
- uvs.push(textureMap);
18004
- }
18005
- this.uvs = uvs;
18006
- // @ts-expect-error
18007
- particleMeshProps.textureFlip = flip;
18008
- var trails = props.trails;
18009
- var trailMeshProps;
18010
- if (trails) {
18011
- this.trails = {
18012
- lifetime: createValueGetter(trails.lifetime),
18013
- dieWithParticles: trails.dieWithParticles !== false,
18014
- sizeAffectsWidth: !!trails.sizeAffectsWidth,
18015
- sizeAffectsLifetime: !!trails.sizeAffectsLifetime,
18016
- inheritParticleColor: !!trails.inheritParticleColor,
18017
- parentAffectsPosition: !!trails.parentAffectsPosition,
18018
- };
18019
- trailMeshProps = {
18020
- name: 'Trail',
18021
- matrix: Matrix4$1.IDENTITY,
18022
- minimumVertexDistance: trails.minimumVertexDistance || 0.02,
18023
- maxTrailCount: options.maxCount,
18024
- pointCountPerTrail: Math.round(trails.maxPointPerTrail) || 32,
18025
- blending: trails.blending,
18026
- texture: trails.texture,
18027
- opacityOverLifetime: createValueGetter(trails.opacityOverLifetime || 1),
18028
- widthOverTrail: createValueGetter(trails.widthOverTrail || 1),
18029
- // order: vfxItem.listIndex + (trails.orderOffset || 0),
18030
- shaderCachePrefix: shaderCachePrefix,
18031
- lifetime: this.trails.lifetime,
18032
- occlusion: !!trails.occlusion,
18033
- transparentOcclusion: !!trails.transparentOcclusion,
18034
- textureMap: trails.textureMap,
18035
- mask: renderer.mask,
18036
- maskMode: renderer.maskMode,
18037
- };
18038
- if (trails.colorOverLifetime && trails.colorOverLifetime[0] === ValueType$1.GRADIENT_COLOR) {
18039
- trailMeshProps.colorOverLifetime = trails.colorOverLifetime[1];
18040
- }
18041
- if (trails.colorOverTrail && trails.colorOverTrail[0] === ValueType$1.GRADIENT_COLOR) {
18042
- trailMeshProps.colorOverTrail = trails.colorOverTrail[1];
18043
- }
18044
- }
18045
- this.renderer = new ParticleSystemRenderer(this.engine, particleMeshProps, trailMeshProps);
18046
- this.meshes = this.renderer.meshes;
18047
- // this.item = vfxItem;
18048
- var interaction = props.interaction;
18049
- if (interaction) {
18050
- this.interaction = {
18051
- multiple: interaction.multiple,
18052
- radius: interaction.radius,
18053
- behavior: interaction.behavior,
18054
- };
18055
- }
18056
- this.item.getHitTestParams = this.getHitTestParams;
18057
- this.item._content = this;
18058
- this.renderer.item = this.item;
18059
- this.item.components.push(this.renderer);
18060
- this.item.rendererComponents.push(this.renderer);
18061
- // 添加粒子动画 clip
18062
- var timeline = this.item.getComponent(TimelineComponent);
18063
- timeline.createTrack(Track).createClip(ParticleBehaviourPlayable);
18064
- };
18065
- ParticleSystem = __decorate([
18066
- effectsClass(exports.DataType.ParticleSystem)
18067
- ], ParticleSystem);
18068
- return ParticleSystem;
18069
- }(Component));
18070
- // array performance better for small memory than Float32Array
18071
- var tempDir = new Vector3();
18072
- var tempSize$1 = new Vector2();
18073
- var tempRot$1 = new Euler();
18074
- var tmpDirX = new Vector3();
18075
- var tmpDirY = new Vector3();
18076
- var tempVec3 = new Vector3();
18077
- var tempEuler = new Euler();
18078
- var tempSprite = [0, 0, 0];
18079
- var tempMat4 = new Matrix4$1();
18080
- function getBurstOffsets(burstOffsets) {
18081
- var ret = {};
18082
- if (Array.isArray(burstOffsets)) {
18083
- burstOffsets.forEach(function (arr) {
18084
- var isArr = arr instanceof Array;
18085
- var index = isArr ? arr[0] : arr.index;
18086
- var offsets = ret[index];
18087
- if (!offsets) {
18088
- offsets = ret[index] = [];
18089
- }
18090
- if (isArr) {
18091
- offsets.push(arr.slice(1, 4));
18092
- }
18093
- else {
18094
- offsets.push([+arr.x, +arr.y, +arr.z]);
18095
- }
18096
- });
18097
- }
18098
- return ret;
18099
- }
18100
- function randomArrItem(arr, keepArr) {
18101
- var index = Math.floor(Math.random() * arr.length);
18102
- var item = arr[index];
18103
- if (!keepArr) {
18104
- arr.splice(index, 1);
18105
- }
18106
- return item;
18107
- }
18108
-
18109
- /**
18110
- * @since 2.0.0
18111
- * @internal
18112
- */
18113
- var ParticleBehaviourPlayable = /** @class */ (function (_super) {
18114
- __extends(ParticleBehaviourPlayable, _super);
18115
- function ParticleBehaviourPlayable() {
18116
- return _super !== null && _super.apply(this, arguments) || this;
18117
- }
18118
- ParticleBehaviourPlayable.prototype.onPlayablePlay = function () {
18119
- this.particleSystem = this.bindingItem.getComponent(ParticleSystem);
18120
- if (this.particleSystem) {
18121
- this.particleSystem.name = this.bindingItem.name;
18122
- this.particleSystem.start();
18123
- this.particleSystem.initEmitterTransform();
18136
+ start3DSize: !!options.start3DSize,
18137
+ startTurbulence: startTurbulence,
18138
+ turbulence: turbulence,
18139
+ speedOverLifetime: positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime),
18140
+ linearVelOverLifetime: linearVelOverLifetime,
18141
+ orbitalVelOverLifetime: orbitalVelOverLifetime,
18142
+ forceTarget: forceTarget,
18143
+ };
18144
+ if (options.startRotationZ) {
18145
+ this.options.startRotation = createValueGetter(options.startRotationZ || 0);
18124
18146
  }
18125
- };
18126
- ParticleBehaviourPlayable.prototype.processFrame = function (dt) {
18127
- var particleSystem = this.particleSystem;
18128
- if (particleSystem) {
18129
- this.bindingItem.parent;
18130
- // TODO: [1.31] @十弦 验证 https://github.com/galacean/effects-runtime/commit/3e7d73d37b7d98c2a25e4544e80e928b17801ccd#diff-fae062f28caf3771cfedd3a20dc22f9749bd054c7541bf2fd50a9a5e413153d4
18131
- // particleSystem.setParentTransform(parentItem.transform);
18132
- particleSystem.setVisible(true);
18133
- particleSystem.onUpdate(dt);
18147
+ if (options.startRotationX || options.startRotationY) {
18148
+ this.options.start3DRotation = true;
18149
+ this.options.startRotationX = createValueGetter(options.startRotationX || 0);
18150
+ this.options.startRotationY = createValueGetter(options.startRotationY || 0);
18151
+ this.options.startRotationZ = createValueGetter(options.startRotationZ || 0);
18134
18152
  }
18135
- };
18136
- return ParticleBehaviourPlayable;
18137
- }(Playable));
18138
-
18139
- var CalculateLoader = /** @class */ (function (_super) {
18140
- __extends(CalculateLoader, _super);
18141
- function CalculateLoader() {
18142
- return _super !== null && _super.apply(this, arguments) || this;
18143
- }
18144
- return CalculateLoader;
18145
- }(AbstractPlugin));
18146
-
18147
- var AnimationStream = /** @class */ (function () {
18148
- function AnimationStream(playable) {
18149
- this.curveValues = {};
18150
- this.playable = playable;
18151
- }
18152
- AnimationStream.prototype.setCurveValue = function (componentType, propertyName, value) {
18153
- if (!this.findCurveValue(componentType, propertyName)) {
18154
- this.curveValues[componentType + propertyName] = { componentType: componentType, propertyName: propertyName, value: value };
18153
+ if (options.start3DSize) {
18154
+ this.options.startSizeX = createValueGetter(options.startSizeX);
18155
+ this.options.startSizeY = createValueGetter(options.startSizeY);
18155
18156
  }
18156
18157
  else {
18157
- this.curveValues[componentType + propertyName].value = value;
18158
- }
18159
- return this.curveValues[componentType + propertyName];
18160
- };
18161
- AnimationStream.prototype.findCurveValue = function (componentType, propertyName) {
18162
- return this.curveValues[componentType + propertyName];
18163
- };
18164
- AnimationStream.prototype.getInputStream = function (index) {
18165
- var inputPlayable = this.playable.getInput(index);
18166
- if (inputPlayable instanceof AnimationPlayable) {
18167
- return inputPlayable.animationStream;
18168
- }
18169
- };
18170
- return AnimationStream;
18171
- }());
18172
-
18173
- var AnimationPlayable = /** @class */ (function (_super) {
18174
- __extends(AnimationPlayable, _super);
18175
- function AnimationPlayable() {
18176
- var _this = _super.call(this) || this;
18177
- _this.animationStream = new AnimationStream(_this);
18178
- return _this;
18179
- }
18180
- return AnimationPlayable;
18181
- }(Playable));
18182
-
18183
- var tempRot = new Euler();
18184
- var tempSize = new Vector3(1, 1, 1);
18185
- var tempPos = new Vector3();
18186
- /**
18187
- * @since 2.0.0
18188
- * @internal
18189
- */
18190
- var AnimationClipPlayable = /** @class */ (function (_super) {
18191
- __extends(AnimationClipPlayable, _super);
18192
- function AnimationClipPlayable() {
18193
- return _super !== null && _super.apply(this, arguments) || this;
18194
- }
18195
- AnimationClipPlayable.prototype.processFrame = function (dt) {
18196
- if (this.bindingItem.composition) {
18197
- this.sampleAnimation();
18158
+ this.options.startSize = createValueGetter(options.startSize);
18159
+ this.options.sizeAspect = createValueGetter(options.sizeAspect || 1);
18198
18160
  }
18199
- };
18200
- /**
18201
- * 应用时间轴K帧数据到对象
18202
- */
18203
- AnimationClipPlayable.prototype.sampleAnimation = function () {
18204
- var _this = this;
18205
- var duration = this.bindingItem.duration;
18206
- var life = this.time / duration;
18207
- life = life < 0 ? 0 : (life > 1 ? 1 : life);
18208
- if (this.sizeXOverLifetime) {
18209
- tempSize.x = this.sizeXOverLifetime.getValue(life);
18210
- if (this.sizeSeparateAxes) {
18211
- tempSize.y = this.sizeYOverLifetime.getValue(life);
18212
- tempSize.z = this.sizeZOverLifetime.getValue(life);
18161
+ var particleMeshProps = {
18162
+ // listIndex: vfxItem.listIndex,
18163
+ meshSlots: options.meshSlots,
18164
+ name: this.name,
18165
+ matrix: Matrix4$1.IDENTITY,
18166
+ filter: props.filter,
18167
+ shaderCachePrefix: shaderCachePrefix,
18168
+ renderMode: renderer.renderMode || RenderMode$1.BILLBOARD,
18169
+ side: renderer.side || SideMode$1.DOUBLE,
18170
+ gravity: gravity,
18171
+ // duration: vfxItem.duration,
18172
+ blending: renderer.blending || BlendingMode$1.ALPHA,
18173
+ rotationOverLifetime: rotationOverLifetime,
18174
+ gravityModifier: this.options.gravityModifier,
18175
+ linearVelOverLifetime: this.options.linearVelOverLifetime,
18176
+ orbitalVelOverLifetime: this.options.orbitalVelOverLifetime,
18177
+ speedOverLifetime: this.options.speedOverLifetime,
18178
+ sprite: textureSheetAnimation,
18179
+ occlusion: !!renderer.occlusion,
18180
+ transparentOcclusion: !!renderer.transparentOcclusion,
18181
+ maxCount: options.maxCount,
18182
+ mask: renderer.mask,
18183
+ maskMode: (_f = renderer.maskMode) !== null && _f !== void 0 ? _f : MaskMode$1.NONE,
18184
+ forceTarget: forceTarget,
18185
+ diffuse: renderer.texture,
18186
+ sizeOverLifetime: sizeOverLifetimeGetter,
18187
+ anchor: anchor,
18188
+ };
18189
+ if (colorOverLifetime) {
18190
+ var color = colorOverLifetime.color, opacity = colorOverLifetime.opacity;
18191
+ particleMeshProps.colorOverLifetime = {};
18192
+ if (opacity) {
18193
+ particleMeshProps.colorOverLifetime.opacity = createValueGetter(colorOverLifetime.opacity);
18213
18194
  }
18214
- else {
18215
- tempSize.z = tempSize.y = tempSize.x;
18195
+ if (color) {
18196
+ if (color[0] === ValueType$1.GRADIENT_COLOR) {
18197
+ particleMeshProps.colorOverLifetime.color = colorOverLifetime.color[1];
18198
+ }
18199
+ else if (color[0] === ValueType$1.RGBA_COLOR) {
18200
+ particleMeshProps.colorOverLifetime.color = Texture.createWithData(this.engine, {
18201
+ data: new Uint8Array(color[1]),
18202
+ width: 1,
18203
+ height: 1,
18204
+ });
18205
+ }
18206
+ else if (color instanceof Texture) {
18207
+ particleMeshProps.colorOverLifetime.color = color;
18208
+ }
18216
18209
  }
18217
- var startSize = this.originalTransform.scale;
18218
- this.bindingItem.transform.setScale(tempSize.x * startSize.x, tempSize.y * startSize.y, tempSize.z * startSize.z);
18219
- // this.animationStream.setCurveValue('transform', 'scale.x', tempSize.x * startSize.x);
18220
- // this.animationStream.setCurveValue('transform', 'scale.y', tempSize.y * startSize.y);
18221
- // this.animationStream.setCurveValue('transform', 'scale.z', tempSize.z * startSize.z);
18222
18210
  }
18223
- if (this.rotationOverLifetime) {
18224
- var func = function (v) { return _this.rotationOverLifetime.asRotation ? v.getValue(life) : v.getIntegrateValue(0, life, duration); };
18225
- var incZ = func(this.rotationOverLifetime.z);
18226
- var separateAxes = this.rotationOverLifetime.separateAxes;
18227
- tempRot.x = separateAxes ? func(this.rotationOverLifetime.x) : 0;
18228
- tempRot.y = separateAxes ? func(this.rotationOverLifetime.y) : 0;
18229
- tempRot.z = incZ;
18230
- var rot = tempRot.addEulers(this.originalTransform.rotation, tempRot);
18231
- this.bindingItem.transform.setRotation(rot.x, rot.y, rot.z);
18232
- // this.animationStream.setCurveValue('transform', 'rotation.x', rot.x);
18233
- // this.animationStream.setCurveValue('transform', 'rotation.y', rot.y);
18234
- // this.animationStream.setCurveValue('transform', 'rotation.z', rot.z);
18211
+ var uvs = [];
18212
+ var textureMap = [0, 0, 1, 1];
18213
+ var flip;
18214
+ if (props.splits) {
18215
+ var s = props.splits[0];
18216
+ flip = s[4];
18217
+ textureMap = flip ? [s[0], s[1], s[3], s[2]] : [s[0], s[1], s[2], s[3]];
18235
18218
  }
18236
- if (this.positionOverLifetime) {
18237
- var pos = tempPos;
18238
- calculateTranslation(pos, this, this.gravity, this.time, duration, this.originalTransform.position, this.velocity);
18239
- if (this.originalTransform.path) {
18240
- pos.add(this.originalTransform.path.getValue(life));
18219
+ if (textureSheetAnimation && !textureSheetAnimation.animate) {
18220
+ var col = flip ? textureSheetAnimation.row : textureSheetAnimation.col;
18221
+ var row = flip ? textureSheetAnimation.col : textureSheetAnimation.row;
18222
+ var total = textureSheetAnimation.total || col * row;
18223
+ var index$1 = 0;
18224
+ for (var x = 0; x < col; x++) {
18225
+ for (var y = 0; y < row && index$1 < total; y++, index$1++) {
18226
+ uvs.push([
18227
+ x * textureMap[2] / col + textureMap[0],
18228
+ y * textureMap[3] / row + textureMap[1],
18229
+ textureMap[2] / col,
18230
+ textureMap[3] / row
18231
+ ]);
18232
+ }
18241
18233
  }
18242
- this.bindingItem.transform.setPosition(pos.x, pos.y, pos.z);
18243
- // this.animationStream.setCurveValue('transform', 'position.x', pos.x);
18244
- // this.animationStream.setCurveValue('transform', 'position.y', pos.y);
18245
- // this.animationStream.setCurveValue('transform', 'position.z', pos.z);
18246
18234
  }
18247
- };
18248
- AnimationClipPlayable.prototype.fromData = function (data) {
18249
- var _a;
18250
- var scale = this.bindingItem.transform.scale;
18251
- this.originalTransform = {
18252
- position: this.bindingItem.transform.position.clone(),
18253
- rotation: this.bindingItem.transform.getRotation().clone(),
18254
- // TODO 编辑器 scale 没有z轴控制
18255
- scale: new Vector3(scale.x, scale.y, scale.x),
18256
- };
18257
- var positionOverLifetime = data.positionOverLifetime;
18258
- var rotationOverLifetime = data.rotationOverLifetime;
18259
- var sizeOverLifetime = data.sizeOverLifetime;
18260
- // TODO: 没有 K 帧数据的不需要传 positionOverLifetime 空对象
18261
- if (positionOverLifetime && Object.keys(positionOverLifetime).length !== 0) {
18262
- this.positionOverLifetime = positionOverLifetime;
18263
- if (positionOverLifetime.path) {
18264
- this.originalTransform.path = createValueGetter(positionOverLifetime.path);
18265
- }
18266
- var linearVelEnable = positionOverLifetime.linearX || positionOverLifetime.linearY || positionOverLifetime.linearZ;
18267
- if (linearVelEnable) {
18268
- this.linearVelOverLifetime = {
18269
- x: positionOverLifetime.linearX && createValueGetter(positionOverLifetime.linearX),
18270
- y: positionOverLifetime.linearY && createValueGetter(positionOverLifetime.linearY),
18271
- z: positionOverLifetime.linearZ && createValueGetter(positionOverLifetime.linearZ),
18272
- asMovement: positionOverLifetime.asMovement,
18273
- enabled: !!linearVelEnable,
18274
- };
18275
- }
18276
- var orbitalVelEnable = positionOverLifetime.orbitalX || positionOverLifetime.orbitalY || positionOverLifetime.orbitalZ;
18277
- if (orbitalVelEnable) {
18278
- this.orbitalVelOverLifetime = {
18279
- x: positionOverLifetime.orbitalX && createValueGetter(positionOverLifetime.orbitalX),
18280
- y: positionOverLifetime.orbitalY && createValueGetter(positionOverLifetime.orbitalY),
18281
- z: positionOverLifetime.orbitalZ && createValueGetter(positionOverLifetime.orbitalZ),
18282
- center: ensureVec3(positionOverLifetime.orbCenter),
18283
- asRotation: positionOverLifetime.asRotation,
18284
- enabled: !!orbitalVelEnable,
18285
- };
18286
- }
18287
- this.speedOverLifetime = positionOverLifetime.speedOverLifetime && createValueGetter(positionOverLifetime.speedOverLifetime);
18235
+ else {
18236
+ uvs.push(textureMap);
18288
18237
  }
18289
- if (sizeOverLifetime) {
18290
- if (sizeOverLifetime.separateAxes) {
18291
- this.sizeSeparateAxes = true;
18292
- this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.x || 1);
18293
- this.sizeYOverLifetime = createValueGetter(sizeOverLifetime.y || 1);
18294
- this.sizeZOverLifetime = createValueGetter(sizeOverLifetime.z || 1);
18238
+ this.uvs = uvs;
18239
+ // @ts-expect-error
18240
+ particleMeshProps.textureFlip = flip;
18241
+ var trails = props.trails;
18242
+ var trailMeshProps;
18243
+ if (trails) {
18244
+ this.trails = {
18245
+ lifetime: createValueGetter(trails.lifetime),
18246
+ dieWithParticles: trails.dieWithParticles !== false,
18247
+ sizeAffectsWidth: !!trails.sizeAffectsWidth,
18248
+ sizeAffectsLifetime: !!trails.sizeAffectsLifetime,
18249
+ inheritParticleColor: !!trails.inheritParticleColor,
18250
+ parentAffectsPosition: !!trails.parentAffectsPosition,
18251
+ };
18252
+ trailMeshProps = {
18253
+ name: 'Trail',
18254
+ matrix: Matrix4$1.IDENTITY,
18255
+ minimumVertexDistance: trails.minimumVertexDistance || 0.02,
18256
+ maxTrailCount: options.maxCount,
18257
+ pointCountPerTrail: Math.round(trails.maxPointPerTrail) || 32,
18258
+ blending: trails.blending,
18259
+ texture: trails.texture,
18260
+ opacityOverLifetime: createValueGetter(trails.opacityOverLifetime || 1),
18261
+ widthOverTrail: createValueGetter(trails.widthOverTrail || 1),
18262
+ // order: vfxItem.listIndex + (trails.orderOffset || 0),
18263
+ shaderCachePrefix: shaderCachePrefix,
18264
+ lifetime: this.trails.lifetime,
18265
+ occlusion: !!trails.occlusion,
18266
+ transparentOcclusion: !!trails.transparentOcclusion,
18267
+ textureMap: trails.textureMap,
18268
+ mask: renderer.mask,
18269
+ maskMode: renderer.maskMode,
18270
+ };
18271
+ if (trails.colorOverLifetime && trails.colorOverLifetime[0] === ValueType$1.GRADIENT_COLOR) {
18272
+ trailMeshProps.colorOverLifetime = trails.colorOverLifetime[1];
18295
18273
  }
18296
- else {
18297
- this.sizeXOverLifetime = createValueGetter(sizeOverLifetime.size || 1);
18274
+ if (trails.colorOverTrail && trails.colorOverTrail[0] === ValueType$1.GRADIENT_COLOR) {
18275
+ trailMeshProps.colorOverTrail = trails.colorOverTrail[1];
18298
18276
  }
18299
18277
  }
18300
- if (rotationOverLifetime) {
18301
- this.rotationOverLifetime = {
18302
- asRotation: rotationOverLifetime.asRotation,
18303
- separateAxes: rotationOverLifetime.separateAxes,
18304
- z: createValueGetter(rotationOverLifetime.z || 0),
18278
+ this.renderer = new ParticleSystemRenderer(this.engine, particleMeshProps, trailMeshProps);
18279
+ this.meshes = this.renderer.meshes;
18280
+ // this.item = vfxItem;
18281
+ var interaction = props.interaction;
18282
+ if (interaction) {
18283
+ this.interaction = {
18284
+ multiple: interaction.multiple,
18285
+ radius: interaction.radius,
18286
+ behavior: interaction.behavior,
18305
18287
  };
18306
- if (rotationOverLifetime.separateAxes) {
18307
- var rotLt = this.rotationOverLifetime;
18308
- rotLt.x = createValueGetter(rotationOverLifetime.x || 0);
18309
- rotLt.y = createValueGetter(rotationOverLifetime.y || 0);
18310
- }
18311
18288
  }
18312
- this.gravity = Vector3.fromArray((positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravity) || []);
18313
- this.gravityModifier = createValueGetter((_a = positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.gravityOverLifetime) !== null && _a !== void 0 ? _a : 0);
18314
- this.direction = (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.direction) ? Vector3.fromArray(positionOverLifetime.direction).normalize() : new Vector3();
18315
- this.startSpeed = (positionOverLifetime === null || positionOverLifetime === void 0 ? void 0 : positionOverLifetime.startSpeed) || 0;
18316
- this.velocity = this.direction.clone();
18317
- this.velocity.multiply(this.startSpeed);
18289
+ this.item.getHitTestParams = this.getHitTestParams;
18290
+ this.item._content = this;
18291
+ this.renderer.item = this.item;
18292
+ this.item.components.push(this.renderer);
18293
+ this.item.rendererComponents.push(this.renderer);
18294
+ // 添加粒子动画 clip
18295
+ var timeline = this.item.getComponent(TimelineComponent);
18296
+ timeline.createTrack(Track).createClip(ParticleBehaviourPlayable);
18318
18297
  };
18319
- return AnimationClipPlayable;
18320
- }(AnimationPlayable));
18298
+ ParticleSystem = __decorate([
18299
+ effectsClass(exports.DataType.ParticleSystem)
18300
+ ], ParticleSystem);
18301
+ return ParticleSystem;
18302
+ }(Component));
18303
+ // array performance better for small memory than Float32Array
18304
+ var tempDir = new Vector3();
18305
+ var tempSize = new Vector2();
18306
+ var tempRot = new Euler();
18307
+ var tmpDirX = new Vector3();
18308
+ var tmpDirY = new Vector3();
18309
+ var tempVec3 = new Vector3();
18310
+ var tempEuler = new Euler();
18311
+ var tempSprite = [0, 0, 0];
18312
+ var tempMat4 = new Matrix4$1();
18313
+ function getBurstOffsets(burstOffsets) {
18314
+ var ret = {};
18315
+ if (Array.isArray(burstOffsets)) {
18316
+ burstOffsets.forEach(function (arr) {
18317
+ var isArr = arr instanceof Array;
18318
+ var index = isArr ? arr[0] : arr.index;
18319
+ var offsets = ret[index];
18320
+ if (!offsets) {
18321
+ offsets = ret[index] = [];
18322
+ }
18323
+ if (isArr) {
18324
+ offsets.push(arr.slice(1, 4));
18325
+ }
18326
+ else {
18327
+ offsets.push([+arr.x, +arr.y, +arr.z]);
18328
+ }
18329
+ });
18330
+ }
18331
+ return ret;
18332
+ }
18333
+ function randomArrItem(arr, keepArr) {
18334
+ var index = Math.floor(Math.random() * arr.length);
18335
+ var item = arr[index];
18336
+ if (!keepArr) {
18337
+ arr.splice(index, 1);
18338
+ }
18339
+ return item;
18340
+ }
18341
+
18321
18342
  /**
18322
18343
  * @since 2.0.0
18323
18344
  * @internal
18324
18345
  */
18325
- var ActivationClipPlayable = /** @class */ (function (_super) {
18326
- __extends(ActivationClipPlayable, _super);
18327
- function ActivationClipPlayable() {
18346
+ var ParticleBehaviourPlayable = /** @class */ (function (_super) {
18347
+ __extends(ParticleBehaviourPlayable, _super);
18348
+ function ParticleBehaviourPlayable() {
18328
18349
  return _super !== null && _super.apply(this, arguments) || this;
18329
18350
  }
18330
- ActivationClipPlayable.prototype.onGraphStart = function () {
18331
- this.bindingItem.transform.setValid(false);
18332
- this.hideRendererComponents();
18333
- };
18334
- ActivationClipPlayable.prototype.onPlayablePlay = function () {
18335
- this.bindingItem.transform.setValid(true);
18336
- this.showRendererComponents();
18337
- };
18338
- ActivationClipPlayable.prototype.onPlayableDestroy = function () {
18339
- this.bindingItem.transform.setValid(false);
18340
- this.hideRendererComponents();
18341
- };
18342
- ActivationClipPlayable.prototype.hideRendererComponents = function () {
18343
- var e_1, _a;
18344
- try {
18345
- for (var _b = __values$1(this.bindingItem.rendererComponents), _c = _b.next(); !_c.done; _c = _b.next()) {
18346
- var rendererComponent = _c.value;
18347
- if (rendererComponent.enabled) {
18348
- rendererComponent.enabled = false;
18349
- }
18350
- }
18351
- }
18352
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
18353
- finally {
18354
- try {
18355
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
18356
- }
18357
- finally { if (e_1) throw e_1.error; }
18351
+ ParticleBehaviourPlayable.prototype.onPlayablePlay = function () {
18352
+ this.particleSystem = this.bindingItem.getComponent(ParticleSystem);
18353
+ if (this.particleSystem) {
18354
+ this.particleSystem.name = this.bindingItem.name;
18355
+ this.particleSystem.start();
18356
+ this.particleSystem.initEmitterTransform();
18358
18357
  }
18359
18358
  };
18360
- ActivationClipPlayable.prototype.showRendererComponents = function () {
18361
- var e_2, _a;
18362
- try {
18363
- for (var _b = __values$1(this.bindingItem.rendererComponents), _c = _b.next(); !_c.done; _c = _b.next()) {
18364
- var rendererComponent = _c.value;
18365
- if (!rendererComponent.enabled) {
18366
- rendererComponent.enabled = true;
18367
- }
18368
- }
18369
- }
18370
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
18371
- finally {
18372
- try {
18373
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
18374
- }
18375
- finally { if (e_2) throw e_2.error; }
18359
+ ParticleBehaviourPlayable.prototype.processFrame = function (dt) {
18360
+ var particleSystem = this.particleSystem;
18361
+ if (particleSystem) {
18362
+ this.bindingItem.parent;
18363
+ // TODO: [1.31] @十弦 验证 https://github.com/galacean/effects-runtime/commit/3e7d73d37b7d98c2a25e4544e80e928b17801ccd#diff-fae062f28caf3771cfedd3a20dc22f9749bd054c7541bf2fd50a9a5e413153d4
18364
+ // particleSystem.setParentTransform(parentItem.transform);
18365
+ particleSystem.setVisible(true);
18366
+ particleSystem.onUpdate(dt);
18376
18367
  }
18377
18368
  };
18378
- return ActivationClipPlayable;
18369
+ return ParticleBehaviourPlayable;
18379
18370
  }(Playable));
18380
18371
 
18372
+ var CalculateLoader = /** @class */ (function (_super) {
18373
+ __extends(CalculateLoader, _super);
18374
+ function CalculateLoader() {
18375
+ return _super !== null && _super.apply(this, arguments) || this;
18376
+ }
18377
+ return CalculateLoader;
18378
+ }(AbstractPlugin));
18379
+
18381
18380
  var TextLayout = /** @class */ (function () {
18382
18381
  function TextLayout(options) {
18383
18382
  this.width = 0;
@@ -19675,9 +19674,10 @@ var TextComponent = /** @class */ (function (_super) {
19675
19674
  if (this.textStyle.fontSize === value) {
19676
19675
  return;
19677
19676
  }
19677
+ // 保证字号变化后位置正常
19678
+ var diff = this.textStyle.fontSize - value;
19679
+ this.textLayout.lineHeight += diff;
19678
19680
  this.textStyle.fontSize = value;
19679
- // 1.5175 = 31.43 / 20
19680
- this.textLayout.lineHeight = this.textStyle.fontSize * 1.5175;
19681
19681
  this.isDirty = true;
19682
19682
  };
19683
19683
  /**
@@ -20003,7 +20003,7 @@ var TextLoader = /** @class */ (function (_super) {
20003
20003
  return TextLoader;
20004
20004
  }(AbstractPlugin));
20005
20005
 
20006
- var seed$6 = 1;
20006
+ var seed$5 = 1;
20007
20007
  /**
20008
20008
  * @since 2.0.0
20009
20009
  * @internal
@@ -20029,24 +20029,9 @@ var EffectComponent = /** @class */ (function (_super) {
20029
20029
  };
20030
20030
  }
20031
20031
  };
20032
- _this.id = 'Mesh' + seed$6++;
20032
+ _this.id = 'Mesh' + seed$5++;
20033
20033
  _this.name = '<unnamed>';
20034
20034
  _this._priority = 0;
20035
- _this.geometry = Geometry.create(_this.engine);
20036
- var geometryData = {
20037
- vertices: [
20038
- -1, 1, 0,
20039
- -1, -1, 0,
20040
- 1, 1, 0,
20041
- 1, -1, 0, //右下
20042
- ],
20043
- uvs: [0, 1, 0, 0, 1, 1, 1, 0],
20044
- indices: [0, 1, 2, 2, 1, 3],
20045
- dataType: exports.DataType.Geometry,
20046
- id: generateGUID(),
20047
- };
20048
- _this.geometry.fromData(geometryData);
20049
- _this.triangles = geometryToTriangles(_this.geometry);
20050
20035
  return _this;
20051
20036
  }
20052
20037
  Object.defineProperty(EffectComponent.prototype, "isDestroyed", {
@@ -20583,11 +20568,6 @@ var VFXItem = /** @class */ (function (_super) {
20583
20568
  this.id = id.toString(); // TODO 老数据 id 是 number,需要转换
20584
20569
  this.name = name;
20585
20570
  this.start = delay ? delay : this.start;
20586
- // TODO spec 数据需要区分 scale 和 size
20587
- if (transform && transform.scale && data.type !== 'ECS') {
20588
- //@ts-expect-error TODO 数据改造后移除 expect-error
20589
- transform.scale.z = transform.scale.x;
20590
- }
20591
20571
  if (transform) {
20592
20572
  //@ts-expect-error TODO 数据改造后移除 expect-error
20593
20573
  transform.position = new Vector3().copyFrom(transform.position);
@@ -20595,51 +20575,36 @@ var VFXItem = /** @class */ (function (_super) {
20595
20575
  transform.rotation = new Euler().copyFrom(transform.rotation);
20596
20576
  //@ts-expect-error
20597
20577
  transform.scale = new Vector3().copyFrom(transform.scale);
20578
+ //@ts-expect-error
20579
+ if (transform.size) {
20580
+ //@ts-expect-error
20581
+ transform.size = new Vector2().copyFrom(transform.size);
20582
+ }
20583
+ //@ts-expect-error
20584
+ if (transform.anchor) {
20585
+ //@ts-expect-error
20586
+ transform.anchor = new Vector2().copyFrom(transform.anchor);
20587
+ }
20598
20588
  this.transform.setTransform(transform);
20599
20589
  }
20600
20590
  this.transform.name = this.name;
20601
20591
  this.transform.engine = this.engine;
20602
- // TODO spec 数据需要区分 scale 和 size
20603
- if (data.type === ItemType$1.sprite && transform) {
20604
- this.transform.setSize(this.transform.scale.x, this.transform.scale.y);
20605
- this.transform.setScale(1, 1, 1);
20606
- }
20607
20592
  this.parentId = parentId;
20608
20593
  this.duration = duration;
20609
20594
  this.endBehavior = endBehavior;
20610
- // TODO: 放到 Spec 处理
20611
- if (this.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 || this.endBehavior === END_BEHAVIOR_PAUSE$1) {
20612
- this.endBehavior = END_BEHAVIOR_FREEZE$1;
20613
- }
20614
20595
  this.lifetime = -(this.start / this.duration);
20615
20596
  this.listIndex = listIndex;
20597
+ //@ts-expect-error
20598
+ this.oldId = data.oldId;
20616
20599
  if (!data.content) {
20617
20600
  data.content = { options: {} };
20618
20601
  }
20619
20602
  var timelineComponent = this.getComponent(TimelineComponent);
20620
20603
  timelineComponent.fromData(data.content);
20621
- // TODO anchor 应该放在 transform data
20622
- if (data.type === ItemType$1.sprite) {
20623
- var content = data.content;
20624
- if (!content.renderer) {
20625
- //@ts-expect-error
20626
- content.renderer = {};
20627
- }
20628
- var realAnchor = convertAnchor(content.renderer.anchor, content.renderer.particleOrigin);
20629
- var startSize = this.transform.size;
20630
- // 兼容旧JSON(anchor和particleOrigin可能同时存在)
20631
- if (!content.renderer.anchor && content.renderer.particleOrigin !== undefined) {
20632
- this.transform.position.add([-realAnchor[0] * startSize.x, -realAnchor[1] * startSize.y, 0]);
20633
- }
20634
- this.transform.setAnchor(realAnchor[0] * startSize.x, realAnchor[1] * startSize.y, 0);
20635
- }
20636
- // TODO 要放在上面的 if 后面添加,否则会 position 初始化错误
20637
20604
  if (this.type !== ItemType$1.particle) {
20638
20605
  var track = timelineComponent.createTrack(Track, 'AnimationTrack');
20639
20606
  track.createClip(AnimationClipPlayable, 'AnimationTimelineClip').playable.fromData(data.content);
20640
20607
  }
20641
- var activationTrack = timelineComponent.createTrack(Track, 'ActivationTrack');
20642
- activationTrack.createClip(ActivationClipPlayable, 'ActivationTimelineClip');
20643
20608
  if (duration <= 0) {
20644
20609
  throw Error("Item duration can't be less than 0, see ".concat(HELP_LINK$1['Item duration can\'t be less than 0']));
20645
20610
  }
@@ -22654,7 +22619,7 @@ function isScene(scene) {
22654
22619
 
22655
22620
  function version3Migration(scene) {
22656
22621
  var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e, e_6, _f;
22657
- scene.jsonScene.version = 3.0;
22622
+ scene.jsonScene.version = '3.0';
22658
22623
  var ecScene = scene.jsonScene;
22659
22624
  if (!ecScene.items) {
22660
22625
  ecScene.items = [];
@@ -22666,6 +22631,10 @@ function version3Migration(scene) {
22666
22631
  for (var i = 0; i < composition.items.length; i++) {
22667
22632
  ecScene.items.push(composition.items[i]);
22668
22633
  }
22634
+ // composition 的 endbehaviour 兼容
22635
+ if (composition.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 || composition.endBehavior === END_BEHAVIOR_PAUSE$1) {
22636
+ composition.endBehavior = END_BEHAVIOR_FREEZE$1;
22637
+ }
22669
22638
  }
22670
22639
  }
22671
22640
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
@@ -22681,6 +22650,9 @@ function version3Migration(scene) {
22681
22650
  for (var _j = __values$1(ecScene.items), _k = _j.next(); !_k.done; _k = _j.next()) {
22682
22651
  var item = _k.value;
22683
22652
  itemGuidMap[item.id] = generateGUID();
22653
+ // TODO: 编辑器测试用,上线后删除
22654
+ //@ts-expect-error
22655
+ item.oldId = item.id;
22684
22656
  item.id = itemGuidMap[item.id];
22685
22657
  }
22686
22658
  }
@@ -22788,12 +22760,61 @@ function version3Migration(scene) {
22788
22760
  if (!scale) {
22789
22761
  scale = [1, 1, 1];
22790
22762
  }
22763
+ item.transform = {
22764
+ //@ts-expect-error
22765
+ position: { x: position[0], y: position[1], z: position[2] },
22766
+ //@ts-expect-error
22767
+ rotation: { x: rotation[0], y: rotation[1], z: rotation[2] },
22768
+ //@ts-expect-error
22769
+ scale: { x: scale[0], y: scale[1], z: scale[0] },
22770
+ };
22771
+ // sprite 的 scale 转为 size
22772
+ if (item.type === ItemType$1.sprite) {
22773
+ //@ts-expect-error
22774
+ item.transform.size = { x: scale[0], y: scale[1] };
22775
+ //@ts-expect-error
22776
+ item.transform.scale = { x: 1, y: 1, z: 1 };
22777
+ }
22778
+ // sprite 的 anchor 修正
22779
+ if (item.type === ItemType$1.sprite) {
22780
+ var content = item.content;
22781
+ //@ts-expect-error
22782
+ if (!content.renderer) {
22783
+ //@ts-expect-error
22784
+ content.renderer = {};
22785
+ }
22786
+ //@ts-expect-error
22787
+ var renderer = content.renderer;
22788
+ var realAnchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
22789
+ //@ts-expect-error
22790
+ var startSize = item.transform.size;
22791
+ // 兼容旧JSON(anchor和particleOrigin可能同时存在)
22792
+ if (!renderer.anchor && renderer.particleOrigin !== undefined) {
22793
+ //@ts-expect-error
22794
+ item.transform.position.x += -realAnchor[0] * startSize.x;
22795
+ //@ts-expect-error
22796
+ item.transform.position.y += -realAnchor[1] * startSize.y;
22797
+ }
22798
+ //@ts-expect-error
22799
+ item.transform.anchor = { x: realAnchor[0] * startSize.x, y: realAnchor[1] * startSize.y };
22800
+ }
22801
+ }
22802
+ if (item.type === ItemType$1.particle) {
22803
+ var content = item.content;
22791
22804
  //@ts-expect-error
22792
- item.transform.position = { x: position[0], y: position[1], z: position[2] };
22805
+ if (!content.renderer) {
22806
+ //@ts-expect-error
22807
+ content.renderer = {};
22808
+ }
22793
22809
  //@ts-expect-error
22794
- item.transform.rotation = { x: rotation[0], y: rotation[1], z: rotation[2] };
22810
+ var renderer = content.renderer;
22795
22811
  //@ts-expect-error
22796
- item.transform.scale = { x: scale[0], y: scale[1], z: scale[2] };
22812
+ content.renderer.anchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
22813
+ }
22814
+ // item 的 endbehaviour 兼容
22815
+ // @ts-expect-error
22816
+ if (item.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY$1 || item.endBehavior === END_BEHAVIOR_PAUSE$1) {
22817
+ item.endBehavior = END_BEHAVIOR_FREEZE$1;
22797
22818
  }
22798
22819
  // item 的 content 转为 component data 加入 JSONScene.components
22799
22820
  var uuid = v4().replace(/-/g, '');
@@ -22968,8 +22989,22 @@ function version3Migration(scene) {
22968
22989
  }
22969
22990
  return scene;
22970
22991
  }
22992
+ /**
22993
+ * 提取并转换 JSON 数据中的 anchor 值
22994
+ */
22995
+ function convertAnchor(anchor, particleOrigin) {
22996
+ if (anchor) {
22997
+ return [anchor[0] - 0.5, 0.5 - anchor[1]];
22998
+ }
22999
+ else if (particleOrigin) {
23000
+ return particleOriginTranslateMap[particleOrigin];
23001
+ }
23002
+ else {
23003
+ return [0, 0];
23004
+ }
23005
+ }
22971
23006
 
22972
- var seed$5 = 1;
23007
+ var seed$4 = 1;
22973
23008
  /**
22974
23009
  * 资源管理器
22975
23010
  * 用于加载和动效中所有的资源文件,包括图片、插件、图层粒子数据等
@@ -22989,7 +23024,7 @@ var AssetManager = /** @class */ (function () {
22989
23024
  * 图像资源,用于创建和释放GPU纹理资源
22990
23025
  */
22991
23026
  this.assets = {};
22992
- this.id = seed$5++;
23027
+ this.id = seed$4++;
22993
23028
  /**
22994
23029
  * 场景加载的超时定时器
22995
23030
  */
@@ -23005,6 +23040,26 @@ var AssetManager = /** @class */ (function () {
23005
23040
  var _a = options.timeout, timeout = _a === void 0 ? 10 : _a;
23006
23041
  this.timeout = timeout;
23007
23042
  };
23043
+ /**
23044
+ * 根据用户传入的参数修改场景数据
23045
+ */
23046
+ AssetManager.prototype.updateSceneData = function (compositions) {
23047
+ var variables = this.options.variables;
23048
+ if (!variables || Object.keys(variables).length <= 0) {
23049
+ return compositions;
23050
+ }
23051
+ compositions.forEach(function (composition) {
23052
+ composition.items.forEach(function (item) {
23053
+ if (item.type === ItemType$1.text) {
23054
+ var textVariable = variables[item.name];
23055
+ if (textVariable) {
23056
+ item.content.options.text = textVariable;
23057
+ }
23058
+ }
23059
+ });
23060
+ });
23061
+ return compositions;
23062
+ };
23008
23063
  /**
23009
23064
  * 场景创建,通过 json 创建出场景对象,并进行提前编译等工作
23010
23065
  * @param url - json 的 URL 链接或者 json 对象
@@ -23096,6 +23151,7 @@ var AssetManager = /** @class */ (function () {
23096
23151
  for (i = 0; i < scene.images.length; i++) {
23097
23152
  scene.textureOptions[i].image = scene.images[i];
23098
23153
  }
23154
+ scene.jsonScene.compositions = this.updateSceneData(scene.jsonScene.compositions);
23099
23155
  _e.label = 5;
23100
23156
  case 5: return [3 /*break*/, 12];
23101
23157
  case 6: return [4 /*yield*/, hookTimeInfo('processJSON', function () { return _this.processJSON(rawJSON); })];
@@ -23115,6 +23171,7 @@ var AssetManager = /** @class */ (function () {
23115
23171
  return [4 /*yield*/, hookTimeInfo('processTextures', function () { return _this.processTextures(loadedImages_1, loadedBins_1, jsonScene_1); })];
23116
23172
  case 10:
23117
23173
  loadedTextures = _e.sent();
23174
+ jsonScene_1.compositions = this.updateSceneData(jsonScene_1.compositions);
23118
23175
  scene = {
23119
23176
  url: url,
23120
23177
  renderLevel: this.options.renderLevel,
@@ -23961,7 +24018,9 @@ var CompositionComponent = /** @class */ (function (_super) {
23961
24018
  }
23962
24019
  // endBehaviour 类型需优化
23963
24020
  props.content = itemData.content;
23964
- item = new VFXItem(this.engine, __assign$1(__assign$1({}, props), { id: itemData.id, name: itemData.name, delay: itemData.delay, duration: itemData.duration, endBehavior: itemData.endBehavior, parentId: itemData.parentId, transform: itemData.transform }));
24021
+ item = new VFXItem(this.engine, __assign$1(__assign$1({}, props), { id: itemData.id, name: itemData.name, delay: itemData.delay, duration: itemData.duration, endBehavior: itemData.endBehavior, parentId: itemData.parentId, transform: itemData.transform,
24022
+ // @ts-expect-error TODO: 2.0 编辑器测试代码,后续移除
24023
+ oldId: itemData.oldId }));
23965
24024
  // TODO 编辑器数据传入 composition type 后移除
23966
24025
  item.type = ItemType$1.composition;
23967
24026
  item.composition = this.item.composition;
@@ -24096,7 +24155,6 @@ var CompositionComponent = /** @class */ (function (_super) {
24096
24155
  return CompositionComponent;
24097
24156
  }(ItemBehaviour));
24098
24157
 
24099
- var seed$4 = 1;
24100
24158
  /**
24101
24159
  * 合成抽象类:核心对象,通常一个场景只包含一个合成,可能会有多个合成。
24102
24160
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
@@ -24169,7 +24227,7 @@ var Composition = /** @class */ (function () {
24169
24227
  this.width = width;
24170
24228
  this.height = height;
24171
24229
  this.renderOrder = baseRenderOrder;
24172
- this.id = seed$4++;
24230
+ this.id = sourceContent.id;
24173
24231
  this.renderer = renderer;
24174
24232
  this.texInfo = imageUsage !== null && imageUsage !== void 0 ? imageUsage : {};
24175
24233
  this.event = event;
@@ -24196,7 +24254,7 @@ var Composition = /** @class */ (function () {
24196
24254
  this.rootItem.onEnd = function () {
24197
24255
  weapp.window.setTimeout(function () {
24198
24256
  var _a;
24199
- (_a = _this.handleEnd) === null || _a === void 0 ? void 0 : _a.call(_this, _this);
24257
+ (_a = _this.onEnd) === null || _a === void 0 ? void 0 : _a.call(_this, _this);
24200
24258
  }, 0);
24201
24259
  };
24202
24260
  this.pluginSystem.resetComposition(this, this.renderFrame);
@@ -24275,9 +24333,9 @@ var Composition = /** @class */ (function () {
24275
24333
  * 重新开始合成
24276
24334
  */
24277
24335
  Composition.prototype.restart = function () {
24278
- var contentItems = this.rootComposition.items;
24279
- contentItems.forEach(function (item) { return item.dispose(); });
24280
- contentItems.length = 0;
24336
+ this.rootComposition.items;
24337
+ // contentItems.forEach(item => item.dispose());
24338
+ // contentItems.length = 0;
24281
24339
  this.prepareRender();
24282
24340
  this.reset();
24283
24341
  this.transform.setValid(true);
@@ -24560,7 +24618,8 @@ var Composition = /** @class */ (function () {
24560
24618
  var time = this.getUpdateTime(deltaTime * this.speed);
24561
24619
  this.globalTime += time;
24562
24620
  if (this.rootTimeline.isActiveAndEnabled) {
24563
- this.rootTimeline.setTime(this.globalTime / 1000);
24621
+ var localTime = this.rootTimeline.toLocalTime(this.globalTime / 1000);
24622
+ this.rootTimeline.setTime(localTime);
24564
24623
  }
24565
24624
  this.updateVideo();
24566
24625
  // 更新 model-tree-plugin
@@ -25025,6 +25084,9 @@ var Composition = /** @class */ (function () {
25025
25084
  }
25026
25085
  this.compositionSourceManager.dispose();
25027
25086
  this.refCompositionProps.clear();
25087
+ if (this.renderer.env === PLAYER_OPTIONS_ENV_EDITOR) {
25088
+ return;
25089
+ }
25028
25090
  this.renderer.clear({
25029
25091
  stencilAction: exports.TextureLoadAction.clear,
25030
25092
  clearStencil: 0,
@@ -25695,9 +25757,20 @@ var Ticker = /** @class */ (function () {
25695
25757
  if (fps === void 0) { fps = 60; }
25696
25758
  this.paused = true;
25697
25759
  this.lastTime = 0;
25760
+ this._deltaTime = 0;
25698
25761
  this.setFPS(fps);
25699
25762
  this.tickers = [];
25700
25763
  }
25764
+ Object.defineProperty(Ticker.prototype, "deltaTime", {
25765
+ /**
25766
+ * 获取定时器当前帧更新的时间
25767
+ */
25768
+ get: function () {
25769
+ return this._deltaTime;
25770
+ },
25771
+ enumerable: false,
25772
+ configurable: true
25773
+ });
25701
25774
  /**
25702
25775
  * FPS 帧率设置
25703
25776
  */
@@ -25724,6 +25797,7 @@ var Ticker = /** @class */ (function () {
25724
25797
  Ticker.prototype.start = function () {
25725
25798
  var _this = this;
25726
25799
  this.paused = false;
25800
+ this._deltaTime = 0;
25727
25801
  if (!this.intervalId) {
25728
25802
  this.lastTime = weapp.performance.now();
25729
25803
  var raf_1 = weapp.requestAnimationFrame || function (func) {
@@ -25746,6 +25820,7 @@ var Ticker = /** @class */ (function () {
25746
25820
  this.intervalId = 0;
25747
25821
  this.lastTime = 0;
25748
25822
  this.paused = true;
25823
+ this._deltaTime = 0;
25749
25824
  this.tickers = [];
25750
25825
  };
25751
25826
  /**
@@ -25753,12 +25828,14 @@ var Ticker = /** @class */ (function () {
25753
25828
  */
25754
25829
  Ticker.prototype.pause = function () {
25755
25830
  this.paused = true;
25831
+ this._deltaTime = 0;
25756
25832
  };
25757
25833
  /**
25758
25834
  * 定时器恢复方法
25759
25835
  */
25760
25836
  Ticker.prototype.resume = function () {
25761
25837
  this.paused = false;
25838
+ this._deltaTime = 0;
25762
25839
  };
25763
25840
  /**
25764
25841
  * 定时器 tick 方法
@@ -25768,8 +25845,8 @@ var Ticker = /** @class */ (function () {
25768
25845
  return;
25769
25846
  }
25770
25847
  var startTime = weapp.performance.now();
25771
- var deltaTime = startTime - this.lastTime;
25772
- if (deltaTime >= this.interval) {
25848
+ this._deltaTime = startTime - this.lastTime;
25849
+ if (this._deltaTime >= this.interval) {
25773
25850
  this.lastTime = startTime;
25774
25851
  if (this.resetTickers) {
25775
25852
  this.tickers = this.tickers.filter(function (tick) { return tick; });
@@ -25777,7 +25854,7 @@ var Ticker = /** @class */ (function () {
25777
25854
  }
25778
25855
  for (var i = 0, len = this.tickers.length; i < len; i++) {
25779
25856
  var tick = this.tickers[i];
25780
- tick(deltaTime);
25857
+ tick(this._deltaTime);
25781
25858
  }
25782
25859
  }
25783
25860
  };
@@ -26974,35 +27051,39 @@ var GLGeometry = /** @class */ (function (_super) {
26974
27051
  };
26975
27052
  GLGeometry.prototype.fromData = function (data) {
26976
27053
  _super.prototype.fromData.call(this, data);
26977
- var geometryData = data;
26978
- var fullGeometryData = __assign$1({ vertices: [], uvs: [], normals: [], indices: [] }, geometryData);
27054
+ var buffer = decodeBase64ToArrays(data.buffer);
27055
+ var vertexCount = data.vertexData.vertexCount;
27056
+ var positionChannel = data.vertexData.channels[0];
27057
+ var uvChannel = data.vertexData.channels[1];
27058
+ var normalChannel = data.vertexData.channels[2];
27059
+ // 根据提供的长度信息创建 Float32Array
27060
+ var positionBuffer = new Float32Array(buffer, positionChannel.offset, positionChannel.dimension * vertexCount);
27061
+ var uvBuffer = new Float32Array(buffer, uvChannel.offset, uvChannel.dimension * vertexCount);
27062
+ var normalBuffer = new Float32Array(buffer, normalChannel.offset, normalChannel.dimension * vertexCount);
27063
+ // 根据提供的长度信息创建 Uint16Array,它紧随 Float32Array 数据之后
27064
+ var indexBuffer = new Uint16Array(buffer, data.indexOffset);
26979
27065
  var geometryProps = {
26980
27066
  mode: glContext.TRIANGLES,
26981
27067
  attributes: {
26982
27068
  aPos: {
26983
27069
  type: glContext.FLOAT,
26984
27070
  size: 3,
26985
- data: new Float32Array(fullGeometryData.vertices),
27071
+ data: positionBuffer,
26986
27072
  },
26987
27073
  aUV: {
26988
27074
  type: glContext.FLOAT,
26989
27075
  size: 2,
26990
- data: new Float32Array(fullGeometryData.uvs),
27076
+ data: uvBuffer,
26991
27077
  },
26992
27078
  aNormal: {
26993
27079
  type: glContext.FLOAT,
26994
27080
  size: 3,
26995
- data: new Float32Array(fullGeometryData.normals),
27081
+ data: normalBuffer,
26996
27082
  },
26997
27083
  },
26998
27084
  };
26999
- if (fullGeometryData.indices.length !== 0) {
27000
- geometryProps.indices = { data: new Uint32Array(fullGeometryData.indices) };
27001
- geometryProps.drawCount = fullGeometryData.indices.length;
27002
- }
27003
- else {
27004
- geometryProps.drawCount = fullGeometryData.vertices.length / 3;
27005
- }
27085
+ geometryProps.indices = { data: indexBuffer };
27086
+ geometryProps.drawCount = indexBuffer.length;
27006
27087
  this.processProps(geometryProps);
27007
27088
  };
27008
27089
  GLGeometry.prototype.dispose = function () {
@@ -27037,6 +27118,19 @@ var GLGeometry = /** @class */ (function (_super) {
27037
27118
  };
27038
27119
  return GLGeometry;
27039
27120
  }(Geometry));
27121
+ function decodeBase64ToArrays(base64String) {
27122
+ // 将 Base64 编码的字符串转换为二进制字符串
27123
+ var binaryString = atob(base64String);
27124
+ // 将二进制字符串转换为字节数组
27125
+ var bytes = new Uint8Array(binaryString.length);
27126
+ for (var i = 0; i < binaryString.length; i++) {
27127
+ bytes[i] = binaryString.charCodeAt(i);
27128
+ }
27129
+ // 创建 ArrayBuffer 并为其创建视图
27130
+ var buffer = bytes.buffer;
27131
+ // 返回解码后的数组
27132
+ return buffer;
27133
+ }
27040
27134
 
27041
27135
  var GLMaterialState = /** @class */ (function () {
27042
27136
  function GLMaterialState() {
@@ -30888,7 +30982,7 @@ var Player = /** @class */ (function () {
30888
30982
  }());
30889
30983
  function isSceneWithOptions(scene) {
30890
30984
  // TODO: 判断不太优雅,后期试情况优化
30891
- return isObject(scene) && 'scene' in scene;
30985
+ return isObject(scene) && 'scene' in scene && 'options' in scene;
30892
30986
  }
30893
30987
  /**
30894
30988
  * 禁止/允许创建新的播放器,已创建的不受影响
@@ -31018,7 +31112,7 @@ Renderer.create = function (canvas, framework, renderOptions) {
31018
31112
  Engine.create = function (gl) {
31019
31113
  return new GLEngine(gl);
31020
31114
  };
31021
- var version = "2.0.0-alpha.0";
31115
+ var version = "2.0.0-alpha.2";
31022
31116
  logger.info('player version: ' + version);
31023
31117
 
31024
31118
  exports.AbstractPlugin = AbstractPlugin;
@@ -31153,7 +31247,6 @@ exports.combineImageTemplate2Async = combineImageTemplate2Async;
31153
31247
  exports.combineImageTemplateAsync = combineImageTemplateAsync;
31154
31248
  exports.compatibleFrag = compatible_frag;
31155
31249
  exports.compatibleVert = compatible_vert;
31156
- exports.convertAnchor = convertAnchor;
31157
31250
  exports.copyFrag = copy;
31158
31251
  exports.createCopyShader = createCopyShader;
31159
31252
  exports.createGLContext = createGLContext;