@galacean/effects-core 2.0.0-alpha.16 → 2.0.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * Description: Galacean Effects runtime core for the web
4
4
  * Author: Ant Group CO., Ltd.
5
5
  * Contributors: 燃然,飂兮,十弦,云垣,茂安,意绮
6
- * Version: v2.0.0-alpha.16
6
+ * Version: v2.0.0-alpha.17
7
7
  */
8
8
 
9
9
  'use strict';
@@ -328,7 +328,6 @@ function isSimulatorCellPhone() {
328
328
  }
329
329
  function isAlipayMiniApp() {
330
330
  var _my;
331
- // @ts-expect-error
332
331
  return typeof my !== 'undefined' && ((_my = my) == null ? void 0 : _my.renderTarget) === 'web';
333
332
  }
334
333
 
@@ -562,8 +561,8 @@ function noop() {}
562
561
  *
563
562
  * @static
564
563
  * @function isString
565
- * @param {object} obj - 要判断的对象
566
- * @return {boolean}
564
+ * @param obj - 要判断的对象
565
+ * @return
567
566
  */ function isString(obj) {
568
567
  return typeof obj === 'string';
569
568
  }
@@ -572,8 +571,8 @@ function noop() {}
572
571
  *
573
572
  * @static
574
573
  * @function isArray
575
- * @param {object} obj - 要判断的对象
576
- * @return {boolean}
574
+ * @param obj - 要判断的对象
575
+ * @return
577
576
  */ const isArray = Array.isArray || function(obj) {
578
577
  return Object.prototype.toString.call(obj) === '[object Array]';
579
578
  };
@@ -582,8 +581,8 @@ function noop() {}
582
581
  *
583
582
  * @static
584
583
  * @function isFunction
585
- * @param {object} obj - 要判断的对象
586
- * @return {boolean}
584
+ * @param obj - 要判断的对象
585
+ * @return
587
586
  */ function isFunction(obj) {
588
587
  return Object.prototype.toString.call(obj) === '[object Function]';
589
588
  }
@@ -592,8 +591,8 @@ function noop() {}
592
591
  *
593
592
  * @static
594
593
  * @function isObject
595
- * @param {object} obj - 要判断的对象
596
- * @return {boolean}
594
+ * @param obj - 要判断的对象
595
+ * @return
597
596
  */ function isObject(obj) {
598
597
  return Object.prototype.toString.call(obj) === '[object Object]';
599
598
  }
@@ -602,25 +601,12 @@ function isCanvas(canvas) {
602
601
  // 小程序 Canvas 无法使用 instanceof HTMLCanvasElement 判断
603
602
  return typeof canvas === 'object' && canvas !== null && ((_canvas_tagName = canvas.tagName) == null ? void 0 : _canvas_tagName.toUpperCase()) === 'CANVAS';
604
603
  }
605
- function deepClone(obj) {
606
- if (isArray(obj)) {
607
- return obj.map(deepClone);
608
- } else if (obj && typeof obj === 'object') {
609
- if (ArrayBuffer.isView(obj)) {
610
- return obj.slice();
611
- }
612
- const ret = {};
613
- const kas = Object.keys(obj);
614
- for(let i = 0; i < kas.length; i++){
615
- const key = kas[i];
616
- ret[key] = deepClone(obj[key]);
617
- }
618
- return ret;
619
- }
620
- return obj;
621
- }
622
- // TODO: 改名
623
- function random(min, max) {
604
+ /**
605
+ * 生成一个位于 min 和 max 之间的随机数
606
+ * @param min
607
+ * @param max
608
+ * @returns
609
+ */ function randomInRange(min, max) {
624
610
  return min + Math.random() * (max - min);
625
611
  }
626
612
  function throwDestroyedError() {
@@ -3860,7 +3846,7 @@ var CameraClipMode;
3860
3846
  * 蒙版形状切分
3861
3847
  */ ValueType[ValueType["SHAPE_SPLITS"] = 11] = "SHAPE_SPLITS";
3862
3848
  /**
3863
- *直线路径
3849
+ * 直线路径
3864
3850
  */ ValueType[ValueType["LINEAR_PATH"] = 12] = "LINEAR_PATH";
3865
3851
  /**
3866
3852
  * 多色
@@ -4036,7 +4022,7 @@ var TextAlignment;
4036
4022
  (function(TextAlignment) {
4037
4023
  /**
4038
4024
  * text alignment starts from(x,y) to right direction
4039
- * 从(x,y)开始第一个字符,向右边延伸
4025
+ * 从 (x,y) 开始第一个字符,向右边延伸
4040
4026
  */ TextAlignment[TextAlignment["left"] = 0] = "left";
4041
4027
  /**
4042
4028
  * (x,y) is middle position of text, where (left + right)/2 =(x,y)
@@ -4044,7 +4030,7 @@ var TextAlignment;
4044
4030
  */ TextAlignment[TextAlignment["middle"] = 1] = "middle";
4045
4031
  /**
4046
4032
  * text alignment ends with(x,y) from left direction
4047
- * 从(x,y)结束最后一个字符,向左边延伸
4033
+ * 从 (x,y) 结束最后一个字符,向左边延伸
4048
4034
  */ TextAlignment[TextAlignment["right"] = 2] = "right";
4049
4035
  })(TextAlignment || (TextAlignment = {}));
4050
4036
  /**
@@ -4094,6 +4080,7 @@ var DataType;
4094
4080
  DataType["TimelineAsset"] = "TimelineAsset";
4095
4081
  DataType["TransformPlayableAsset"] = "TransformPlayableAsset";
4096
4082
  DataType["SpriteColorPlayableAsset"] = "SpriteColorPlayableAsset";
4083
+ DataType["BinaryAsset"] = "BinaryAsset";
4097
4084
  // FIXME: 先完成ECS的场景转换,后面移到spec中
4098
4085
  DataType["MeshComponent"] = "MeshComponent";
4099
4086
  DataType["SkyboxComponent"] = "SkyboxComponent";
@@ -4102,6 +4089,7 @@ var DataType;
4102
4089
  DataType["ModelPluginComponent"] = "ModelPluginComponent";
4103
4090
  DataType["TreeComponent"] = "TreeComponent";
4104
4091
  DataType["AnimationComponent"] = "AnimationComponent";
4092
+ DataType["SpineComponent"] = "SpineComponent";
4105
4093
  // Non-EffectObject
4106
4094
  DataType["TimelineClip"] = "TimelineClip";
4107
4095
  })(DataType || (DataType = {}));
@@ -4189,11 +4177,11 @@ var VertexBufferSemantic;
4189
4177
  VertexBufferSemantic["TangentBS3"] = "TANGENT_BS3";
4190
4178
  })(VertexBufferSemantic || (VertexBufferSemantic = {}));
4191
4179
 
4192
- class BuiltinObjectGUID {
4193
- }
4194
- BuiltinObjectGUID.WhiteTexture = 'whitetexture00000000000000000000';
4195
- BuiltinObjectGUID.PBRShader = 'pbr00000000000000000000000000000';
4196
- BuiltinObjectGUID.UnlitShader = 'unlit000000000000000000000000000';
4180
+ const BuiltinObjectGUID = {
4181
+ WhiteTexture: 'whitetexture00000000000000000000',
4182
+ PBRShader: 'pbr00000000000000000000000000000',
4183
+ UnlitShader: 'unlit000000000000000000000000000'
4184
+ };
4197
4185
 
4198
4186
  var index$1 = /*#__PURE__*/Object.freeze({
4199
4187
  __proto__: null,
@@ -4249,15 +4237,20 @@ var index$1 = /*#__PURE__*/Object.freeze({
4249
4237
  BuiltinObjectGUID: BuiltinObjectGUID
4250
4238
  });
4251
4239
 
4252
- const effectsClassStore = {};
4253
4240
  const decoratorInitialStore = {};
4254
4241
  const mergedStore = {};
4255
- function getDirectStore(target) {
4256
- const classKey = target.constructor.name;
4257
- if (!decoratorInitialStore[classKey]) {
4258
- decoratorInitialStore[classKey] = {};
4259
- }
4260
- return decoratorInitialStore[classKey];
4242
+ const effectsClassStore = {};
4243
+ function effectsClass(className) {
4244
+ return (target, context)=>{
4245
+ if (effectsClassStore[className]) {
4246
+ console.warn(`Class ${className} 重复注册`);
4247
+ }
4248
+ // TODO: three修改json dataType, 这边重复注册直接 return
4249
+ effectsClassStore[className] = target;
4250
+ };
4251
+ }
4252
+ function serialize(type, sourceName) {
4253
+ return generateSerializableMember(type, sourceName); // value member
4261
4254
  }
4262
4255
  function getMergedStore(target) {
4263
4256
  const classKey = target.constructor.name;
@@ -4282,34 +4275,32 @@ function getMergedStore(target) {
4282
4275
  }
4283
4276
  return store;
4284
4277
  }
4285
- function serialize(type, sourceName) {
4286
- return generateSerializableMember(type, sourceName); // value member
4287
- }
4288
- function effectsClass(className) {
4289
- return (target, context)=>{
4290
- if (effectsClassStore[className]) {
4291
- console.warn('Class ' + className + ' 重复注册');
4292
- }
4293
- //TODO: three修改json dataType, 这边重复注册直接 return
4294
- effectsClassStore[className] = target;
4295
- };
4296
- }
4297
4278
  function generateSerializableMember(type, sourceName) {
4298
4279
  return (target, propertyKey)=>{
4299
4280
  const classStore = getDirectStore(target);
4300
4281
  if (!classStore[propertyKey]) {
4301
4282
  classStore[propertyKey] = {
4302
- type: type,
4303
- sourceName: sourceName
4283
+ type,
4284
+ sourceName
4304
4285
  };
4305
4286
  }
4306
4287
  };
4307
4288
  }
4289
+ function getDirectStore(target) {
4290
+ const classKey = target.constructor.name;
4291
+ if (!decoratorInitialStore[classKey]) {
4292
+ decoratorInitialStore[classKey] = {};
4293
+ }
4294
+ return decoratorInitialStore[classKey];
4295
+ }
4308
4296
 
4309
4297
  /**
4310
4298
  * @since 2.0.0
4311
4299
  * @internal
4312
4300
  */ class EffectsObject {
4301
+ static is(obj) {
4302
+ return obj instanceof EffectsObject && 'guid' in obj;
4303
+ }
4313
4304
  getInstanceId() {
4314
4305
  return this.guid;
4315
4306
  }
@@ -4505,6 +4496,7 @@ __decorate([
4505
4496
  super(...args);
4506
4497
  this.started = false;
4507
4498
  this.materials = [];
4499
+ this._priority = 0;
4508
4500
  this._enabled = true;
4509
4501
  }
4510
4502
  }
@@ -9213,7 +9205,7 @@ class RandomValue extends ValueGetter {
9213
9205
  this.max = props[1];
9214
9206
  }
9215
9207
  getValue(time) {
9216
- return random(this.min, this.max);
9208
+ return randomInRange(this.min, this.max);
9217
9209
  }
9218
9210
  toUniform() {
9219
9211
  return new Float32Array([
@@ -13783,7 +13775,7 @@ class Cone {
13783
13775
  // dir + [0,0,1]
13784
13776
  dir.z += 1;
13785
13777
  return {
13786
- position: position.multiply(random(0, 1)),
13778
+ position: position.multiply(randomInRange(0, 1)),
13787
13779
  direction: dir.normalize()
13788
13780
  };
13789
13781
  }
@@ -13795,7 +13787,7 @@ class Cone {
13795
13787
  }
13796
13788
  function getArcAngle(arc, arcMode, opt) {
13797
13789
  if (arcMode === ShapeArcMode.RANDOM) {
13798
- arc = random(0, arc);
13790
+ arc = randomInRange(0, arc);
13799
13791
  } else if (arcMode === ShapeArcMode.UNIDIRECTIONAL_CYCLE) {
13800
13792
  const d = opt.index % (opt.total + 1);
13801
13793
  arc = arc / opt.total * d;
@@ -13827,8 +13819,8 @@ class Circle {
13827
13819
  }
13828
13820
  class Rectangle {
13829
13821
  generate(opt) {
13830
- const x = random(-this._d, this._d);
13831
- const y = random(-this._h, this._h);
13822
+ const x = randomInRange(-this._d, this._d);
13823
+ const y = randomInRange(-this._h, this._h);
13832
13824
  return {
13833
13825
  direction: new Vector3(0, 0, 1),
13834
13826
  position: new Vector3(x, y, 0)
@@ -13873,7 +13865,7 @@ class RectangleEdge {
13873
13865
  }
13874
13866
  class Edge {
13875
13867
  generate(options) {
13876
- const x = this.arcMode === ShapeArcMode.UNIFORM_BURST ? options.burstIndex % options.burstCount / (options.burstCount - 1) : random(0, 1);
13868
+ const x = this.arcMode === ShapeArcMode.UNIFORM_BURST ? options.burstIndex % options.burstCount / (options.burstCount - 1) : randomInRange(0, 1);
13877
13869
  return {
13878
13870
  direction: new Vector3(0, 1, 0),
13879
13871
  position: new Vector3(this._d * (x - 0.5), 0, 0)
@@ -13891,7 +13883,7 @@ class Donut {
13891
13883
  generate(opt) {
13892
13884
  const dradius = this.donutRadius;
13893
13885
  const center = this.radius - dradius;
13894
- const angle = random(0, Math.PI * 2);
13886
+ const angle = randomInRange(0, Math.PI * 2);
13895
13887
  const arc = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
13896
13888
  const rot = tempMat4$2.setFromRotationZ(arc);
13897
13889
  const direction = new Vector3(Math.cos(angle), Math.sin(angle), 0);
@@ -13911,7 +13903,7 @@ class Donut {
13911
13903
  const tempMat4$1 = new Matrix4();
13912
13904
  class Sphere {
13913
13905
  getHorizontalAngle() {
13914
- return random(-90, 90);
13906
+ return randomInRange(-90, 90);
13915
13907
  }
13916
13908
  generate(opt) {
13917
13909
  const rz = getArcAngle(this.arc, this.arcMode, opt) * DEG2RAD;
@@ -13933,7 +13925,7 @@ class Sphere {
13933
13925
  }
13934
13926
  class Hemisphere extends Sphere {
13935
13927
  getHorizontalAngle() {
13936
- return random(0, 90);
13928
+ return randomInRange(0, 90);
13937
13929
  }
13938
13930
  }
13939
13931
 
@@ -15929,11 +15921,9 @@ class ParticleSystem extends Component {
15929
15921
  this.props = props;
15930
15922
  this.destroyed = false;
15931
15923
  const cachePrefix = '';
15932
- const options = props.options;
15933
- const positionOverLifetime = props.positionOverLifetime;
15934
- const shape = props.shape;
15935
- const gravityModifier = positionOverLifetime.gravityOverLifetime;
15936
- const gravity = ensureVec3(positionOverLifetime.gravity);
15924
+ const { options, positionOverLifetime = {}, shape } = props;
15925
+ const gravityModifier = positionOverLifetime == null ? void 0 : positionOverLifetime.gravityOverLifetime;
15926
+ const gravity = ensureVec3(positionOverLifetime == null ? void 0 : positionOverLifetime.gravity);
15937
15927
  const _textureSheetAnimation = props.textureSheetAnimation;
15938
15928
  const textureSheetAnimation = _textureSheetAnimation ? {
15939
15929
  animationDelay: createValueGetter(_textureSheetAnimation.animationDelay || 0),
@@ -15944,7 +15934,7 @@ class ParticleSystem extends Component {
15944
15934
  row: _textureSheetAnimation.row,
15945
15935
  total: _textureSheetAnimation.total || _textureSheetAnimation.col * _textureSheetAnimation.row
15946
15936
  } : undefined;
15947
- const startTurbulence = !!(shape && shape.turbulenceX || shape.turbulenceY || shape.turbulenceZ);
15937
+ const startTurbulence = !!(shape && shape.turbulenceX || (shape == null ? void 0 : shape.turbulenceY) || (shape == null ? void 0 : shape.turbulenceZ));
15948
15938
  let turbulence;
15949
15939
  if (startTurbulence) {
15950
15940
  var _shape_turbulenceX, _shape_turbulenceY, _shape_turbulenceZ;
@@ -15975,7 +15965,7 @@ class ParticleSystem extends Component {
15975
15965
  }
15976
15966
  }
15977
15967
  let forceTarget;
15978
- if (positionOverLifetime.forceTarget) {
15968
+ if (positionOverLifetime == null ? void 0 : positionOverLifetime.forceTarget) {
15979
15969
  forceTarget = {
15980
15970
  target: positionOverLifetime.target || [
15981
15971
  0,
@@ -17594,6 +17584,27 @@ class AnimationClipPlayable extends Playable {
17594
17584
  }
17595
17585
  }
17596
17586
 
17587
+ /**
17588
+ * @since 2.0.0
17589
+ * @internal
17590
+ */ class TimelineClip {
17591
+ toLocalTime(time) {
17592
+ let localTime = time - this.start;
17593
+ const duration = this.duration;
17594
+ if (localTime - duration > 0.001) {
17595
+ if (this.endBehaviour === ItemEndBehavior.loop) {
17596
+ localTime = localTime % duration;
17597
+ } else if (this.endBehaviour === ItemEndBehavior.freeze) {
17598
+ localTime = Math.min(duration, localTime);
17599
+ }
17600
+ }
17601
+ return localTime;
17602
+ }
17603
+ constructor(){
17604
+ this.start = 0;
17605
+ this.duration = 0;
17606
+ }
17607
+ }
17597
17608
  class TrackAsset extends PlayableAsset {
17598
17609
  /**
17599
17610
  * 重写该方法以获取自定义对象绑定
@@ -17674,7 +17685,7 @@ class TrackAsset extends PlayableAsset {
17674
17685
  }
17675
17686
  }
17676
17687
  __decorate([
17677
- serialize('TimelineClip')
17688
+ serialize(TimelineClip)
17678
17689
  ], TrackAsset.prototype, "clips", void 0);
17679
17690
  __decorate([
17680
17691
  serialize()
@@ -17687,27 +17698,6 @@ exports.TrackType = void 0;
17687
17698
  TrackType[TrackType["MasterTrack"] = 0] = "MasterTrack";
17688
17699
  TrackType[TrackType["ObjectTrack"] = 1] = "ObjectTrack";
17689
17700
  })(exports.TrackType || (exports.TrackType = {}));
17690
- class TimelineClip {
17691
- toLocalTime(time) {
17692
- let localTime = time - this.start;
17693
- const duration = this.duration;
17694
- if (localTime - duration > 0.001) {
17695
- if (this.endBehaviour === ItemEndBehavior.loop) {
17696
- localTime = localTime % duration;
17697
- } else if (this.endBehaviour === ItemEndBehavior.freeze) {
17698
- localTime = Math.min(duration, localTime);
17699
- }
17700
- }
17701
- return localTime;
17702
- }
17703
- constructor(){
17704
- this.start = 0;
17705
- this.duration = 0;
17706
- }
17707
- }
17708
- TimelineClip = __decorate([
17709
- effectsClass('TimelineClip')
17710
- ], TimelineClip);
17711
17701
  class RuntimeClip {
17712
17702
  set enable(value) {
17713
17703
  if (value) {
@@ -17782,10 +17772,6 @@ class ObjectBindingTrack extends TrackAsset {
17782
17772
  particleClip.endBehaviour = boundItem.endBehavior;
17783
17773
  }
17784
17774
  }
17785
- fromData(data) {
17786
- super.fromData(data);
17787
- this.data = data;
17788
- }
17789
17775
  }
17790
17776
  ObjectBindingTrack = __decorate([
17791
17777
  effectsClass('ObjectBindingTrack')
@@ -17971,7 +17957,6 @@ function compareTracks(a, b) {
17971
17957
  this.startTime = startTime;
17972
17958
  this.resolveBindings();
17973
17959
  this.timelinePlayable = this.timelineAsset.createPlayable(this.graph);
17974
- this.timelinePlayable.play();
17975
17960
  // 重播不销毁元素
17976
17961
  if (this.item.endBehavior !== ItemEndBehavior.destroy) {
17977
17962
  this.setReusable(true);
@@ -18355,7 +18340,6 @@ class CanvasPool {
18355
18340
  return this.elements.shift();
18356
18341
  }
18357
18342
  if (getConfig(TEMPLATE_USE_OFFSCREEN_CANVAS)) {
18358
- // @ts-expect-error
18359
18343
  return window._createOffscreenCanvas(10, 10);
18360
18344
  } else {
18361
18345
  // in hongmeng system, create too many canvas will case render error
@@ -19179,7 +19163,6 @@ class VFXItem extends EffectsObject {
19179
19163
  this.parentId = parentId;
19180
19164
  this.duration = duration;
19181
19165
  this.endBehavior = endBehavior;
19182
- this.renderOrder = listIndex;
19183
19166
  //@ts-expect-error
19184
19167
  this.oldId = data.oldId;
19185
19168
  if (!data.content) {
@@ -19190,17 +19173,11 @@ class VFXItem extends EffectsObject {
19190
19173
  if (duration <= 0) {
19191
19174
  throw Error(`Item duration can't be less than 0, see ${HELP_LINK['Item duration can\'t be less than 0']}`);
19192
19175
  }
19193
- if (data.components) {
19194
- for (const component of data.components){
19195
- const newComponent = component;
19196
- this.components.push(newComponent);
19197
- if (newComponent instanceof RendererComponent) {
19198
- this.rendererComponents.push(newComponent);
19199
- } else if (newComponent instanceof ItemBehaviour) {
19200
- this.itemBehaviours.push(newComponent);
19201
- }
19202
- }
19176
+ for (const component of this.components){
19177
+ component.onAttached();
19203
19178
  }
19179
+ // renderOrder 在 component 初始化后设置。确保能拿到 rendererComponent。
19180
+ this.renderOrder = listIndex;
19204
19181
  }
19205
19182
  toData() {
19206
19183
  var _this_parent;
@@ -19295,6 +19272,7 @@ class VFXItem extends EffectsObject {
19295
19272
  /**
19296
19273
  * 元素动画的速度
19297
19274
  */ this.speed = 1;
19275
+ this.listIndex = 0;
19298
19276
  this.name = 'VFXItem';
19299
19277
  this.transform.name = this.name;
19300
19278
  this.transform.engine = engine;
@@ -19303,6 +19281,9 @@ class VFXItem extends EffectsObject {
19303
19281
  }
19304
19282
  }
19305
19283
  }
19284
+ __decorate([
19285
+ serialize()
19286
+ ], VFXItem.prototype, "components", void 0);
19306
19287
  VFXItem = __decorate([
19307
19288
  effectsClass(DataType.VFXItemData)
19308
19289
  ], VFXItem);
@@ -19498,20 +19479,20 @@ class SerializationHelper {
19498
19479
  if (value === undefined) {
19499
19480
  value = effectsObject[key];
19500
19481
  }
19501
- if (value instanceof EffectsObject) {
19502
- this.collectSerializableObject(value, res);
19503
- } else if (value instanceof Array) {
19482
+ if (EffectsObject.is(value)) {
19483
+ SerializationHelper.collectSerializableObject(value, res);
19484
+ } else if (isArray(value)) {
19504
19485
  for (const arrayValue of value){
19505
- if (arrayValue instanceof EffectsObject) {
19506
- this.collectSerializableObject(arrayValue, res);
19486
+ if (EffectsObject.is(arrayValue)) {
19487
+ SerializationHelper.collectSerializableObject(arrayValue, res);
19507
19488
  }
19508
19489
  }
19509
- } else if (value instanceof Object) {
19490
+ } else if (isObject(value)) {
19510
19491
  // 非 EffectsObject 对象只递归一层
19511
19492
  for (const objectKey of Object.keys(value)){
19512
19493
  const objectValue = value[objectKey];
19513
- if (objectValue instanceof EffectsObject) {
19514
- this.collectSerializableObject(objectValue, res);
19494
+ if (EffectsObject.is(objectValue)) {
19495
+ SerializationHelper.collectSerializableObject(objectValue, res);
19515
19496
  }
19516
19497
  }
19517
19498
  }
@@ -19546,17 +19527,17 @@ class SerializationHelper {
19546
19527
  if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean' || SerializationHelper.checkTypedArray(value)) {
19547
19528
  // TODO json 数据避免传 typedArray
19548
19529
  serializedData[key] = value;
19549
- } else if (value instanceof Array) {
19530
+ } else if (isArray(value)) {
19550
19531
  if (!serializedData[key]) {
19551
19532
  serializedData[key] = [];
19552
19533
  }
19553
19534
  SerializationHelper.serializeArrayProperty(value, serializedData[key], 0);
19554
- } else if (value instanceof EffectsObject) {
19535
+ } else if (EffectsObject.is(value)) {
19555
19536
  // TODO 处理 EffectsObject 递归序列化
19556
19537
  serializedData[key] = {
19557
19538
  id: value.getInstanceId()
19558
19539
  };
19559
- } else if (value instanceof Object) {
19540
+ } else if (isObject(value)) {
19560
19541
  if (!serializedData[key]) {
19561
19542
  serializedData[key] = {};
19562
19543
  }
@@ -19569,17 +19550,17 @@ class SerializationHelper {
19569
19550
  if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean' || SerializationHelper.checkTypedArray(value)) {
19570
19551
  // TODO json 数据避免传 typedArray
19571
19552
  serializedData[key] = value;
19572
- } else if (value instanceof Array) {
19553
+ } else if (isArray(value)) {
19573
19554
  if (!serializedData[key]) {
19574
19555
  serializedData[key] = [];
19575
19556
  }
19576
19557
  SerializationHelper.serializeArrayProperty(value, serializedData[key], 0);
19577
- } else if (value instanceof EffectsObject) {
19558
+ } else if (EffectsObject.is(value)) {
19578
19559
  // TODO 处理 EffectsObject 递归序列化
19579
19560
  serializedData[key] = {
19580
19561
  id: value.getInstanceId()
19581
19562
  };
19582
- } else if (value instanceof Object) {
19563
+ } else if (isObject(value)) {
19583
19564
  if (!serializedData[key]) {
19584
19565
  serializedData[key] = {};
19585
19566
  }
@@ -19639,13 +19620,13 @@ class SerializationHelper {
19639
19620
  static checkTypedArray(obj) {
19640
19621
  return obj instanceof Int8Array || obj instanceof Uint8Array || obj instanceof Uint8ClampedArray || obj instanceof Int16Array || obj instanceof Uint16Array || obj instanceof Int32Array || obj instanceof Uint32Array || obj instanceof Float32Array || obj instanceof Float64Array || obj instanceof ArrayBuffer;
19641
19622
  }
19623
+ // check value is { id: 7e69662e964e4892ae8933f24562395b }
19642
19624
  static checkDataPath(value) {
19643
- // check value is { id: 7e69662e964e4892ae8933f24562395b }
19644
- return value instanceof Object && Object.keys(value).length === 1 && value.id && value.id.length === 32;
19625
+ return !!(isObject(value) && Object.keys(value).length === 1 && 'id' in value && isString(value.id) && value.id.length === 32);
19645
19626
  }
19646
19627
  // TODO 测试函数,2.0 上线后移除
19647
19628
  static checkGLTFNode(value) {
19648
- return value instanceof Object && value.nodeIndex !== undefined && value.isJoint !== undefined;
19629
+ return isObject(value) && value.nodeIndex !== undefined && value.isJoint !== undefined;
19649
19630
  }
19650
19631
  static checkImageSource(value) {
19651
19632
  return isCanvas(value) || value instanceof HTMLImageElement;
@@ -19656,7 +19637,7 @@ class SerializationHelper {
19656
19637
  return;
19657
19638
  }
19658
19639
  // 加载并链接 DataPath 字段表示的 EffectsObject 引用。Class 对象 copy [key, value] 会丢失对象信息,因此只递归数组对象和普通 js Object 结构对象。
19659
- if (property instanceof Array) {
19640
+ if (isArray(property)) {
19660
19641
  const res = [];
19661
19642
  for (const value of property){
19662
19643
  res.push(SerializationHelper.deserializeProperty(value, engine, level + 1, type));
@@ -19665,16 +19646,14 @@ class SerializationHelper {
19665
19646
  // TODO json 数据避免传 typedArray
19666
19647
  } else if (SerializationHelper.checkDataPath(property)) {
19667
19648
  return engine.assetLoader.loadGUID(property.id);
19668
- } else if (property instanceof Object && property.constructor === Object) {
19649
+ } else if (isObject(property) && property.constructor === Object) {
19669
19650
  let res;
19670
19651
  if (type) {
19671
- const classConstructor = effectsClassStore[type];
19672
- res = new classConstructor();
19652
+ res = new type();
19673
19653
  } else {
19674
19654
  res = {};
19675
19655
  }
19676
19656
  for (const key of Object.keys(property)){
19677
- // @ts-expect-error
19678
19657
  res[key] = SerializationHelper.deserializeProperty(property[key], engine, level + 1);
19679
19658
  }
19680
19659
  return res;
@@ -19688,7 +19667,7 @@ class SerializationHelper {
19688
19667
  console.error('序列化数据的内嵌对象层数大于上限');
19689
19668
  return;
19690
19669
  }
19691
- if (property instanceof Array) {
19670
+ if (isArray(property)) {
19692
19671
  const res = [];
19693
19672
  for (const value of property){
19694
19673
  res.push((yield SerializationHelper.deserializePropertyAsync(value, engine, level + 1, type)));
@@ -19698,16 +19677,14 @@ class SerializationHelper {
19698
19677
  } else if (SerializationHelper.checkDataPath(property)) {
19699
19678
  const res = yield engine.assetLoader.loadGUIDAsync(property.id);
19700
19679
  return res;
19701
- } else if (property instanceof Object && property.constructor === Object) {
19680
+ } else if (isObject(property) && property.constructor === Object) {
19702
19681
  let res;
19703
19682
  if (type) {
19704
- const classConstructor = effectsClassStore[type];
19705
- res = new classConstructor();
19683
+ res = new type();
19706
19684
  } else {
19707
19685
  res = {};
19708
19686
  }
19709
19687
  for (const key of Object.keys(property)){
19710
- // @ts-expect-error
19711
19688
  res[key] = SerializationHelper.deserializeProperty(property[key], engine, level + 1);
19712
19689
  }
19713
19690
  return res;
@@ -19729,17 +19706,17 @@ class SerializationHelper {
19729
19706
  if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean' || SerializationHelper.checkTypedArray(objectProperty)) {
19730
19707
  // TODO json 数据避免传 typedArray
19731
19708
  serializedData[key] = value;
19732
- } else if (value instanceof Array) {
19709
+ } else if (isArray(value)) {
19733
19710
  if (!serializedData[key]) {
19734
19711
  serializedData[key] = [];
19735
19712
  }
19736
19713
  SerializationHelper.serializeArrayProperty(value, serializedData[key], level + 1);
19737
- } else if (value instanceof EffectsObject) {
19714
+ } else if (EffectsObject.is(value)) {
19738
19715
  // TODO 处理 EffectsObject 递归序列化
19739
19716
  serializedData[key] = {
19740
19717
  id: value.getInstanceId()
19741
19718
  };
19742
- } else if (value instanceof Object) {
19719
+ } else if (isObject(value)) {
19743
19720
  if (!serializedData[key]) {
19744
19721
  serializedData[key] = {};
19745
19722
  }
@@ -19760,17 +19737,17 @@ class SerializationHelper {
19760
19737
  if (typeof value === 'number' || typeof value === 'string' || typeof value === 'boolean' || SerializationHelper.checkTypedArray(arrayProperty)) {
19761
19738
  // TODO json 数据避免传 typedArray
19762
19739
  serializedData[i] = value;
19763
- } else if (value instanceof Array) {
19740
+ } else if (isArray(value)) {
19764
19741
  if (!serializedData[i]) {
19765
19742
  serializedData[i] = [];
19766
19743
  }
19767
- this.serializeArrayProperty(value, serializedData[i], level + 1);
19768
- } else if (value instanceof EffectsObject) {
19744
+ SerializationHelper.serializeArrayProperty(value, serializedData[i], level + 1);
19745
+ } else if (EffectsObject.is(value)) {
19769
19746
  // TODO 处理 EffectsObject 递归序列化
19770
19747
  serializedData[i] = {
19771
19748
  id: value.getInstanceId()
19772
19749
  };
19773
- } else if (value instanceof Object) {
19750
+ } else if (isObject(value)) {
19774
19751
  if (!serializedData[i]) {
19775
19752
  serializedData[i] = {};
19776
19753
  }
@@ -20701,8 +20678,6 @@ function getStandardCameraContent(model) {
20701
20678
  /**
20702
20679
  * 3.0 以下版本数据适配(runtime 2.0及以上版本支持)
20703
20680
  */ function version30Migration(json) {
20704
- var // 更正 spine 数据中的 images 属性
20705
- _json_spines;
20706
20681
  var // 兼容老版本数据中不存在textures的情况
20707
20682
  _result;
20708
20683
  const result = _extends({}, json, {
@@ -20712,7 +20687,8 @@ function getStandardCameraContent(model) {
20712
20687
  materials: [],
20713
20688
  shaders: [],
20714
20689
  geometries: [],
20715
- animations: []
20690
+ animations: [],
20691
+ miscs: []
20716
20692
  });
20717
20693
  // image数据添加 guid
20718
20694
  for (const image of result.images){
@@ -20741,17 +20717,10 @@ function getStandardCameraContent(model) {
20741
20717
  });
20742
20718
  }
20743
20719
  }
20744
- (_json_spines = json.spines) == null ? void 0 : _json_spines.forEach((spine)=>{
20745
- for(let i = 0; i < spine.images.length; i++){
20746
- var _json_textures_spine_images_i;
20747
- //@ts-expect-error
20748
- const textureId = (_json_textures_spine_images_i = json.textures[spine.images[i]]) == null ? void 0 : _json_textures_spine_images_i.id;
20749
- //@ts-expect-error
20750
- spine.images[i] = {
20751
- id: textureId
20752
- };
20753
- }
20754
- });
20720
+ // 处理老版本数据中 bins 没有 id 的情况
20721
+ if (json.bins) {
20722
+ convertBinaryAsset(json.bins, result);
20723
+ }
20755
20724
  const itemOldIdToGuidMap = {};
20756
20725
  const guidToItemMap = {};
20757
20726
  // 更正Composition.endBehavior
@@ -20972,6 +20941,10 @@ function getStandardCameraContent(model) {
20972
20941
  //@ts-expect-error
20973
20942
  item.type = 'orientation-transformer';
20974
20943
  }
20944
+ // Spine 元素转为 guid 索引
20945
+ if (item.type === ItemType.spine && json.spines && json.spines.length !== 0) {
20946
+ convertSpineData(json.spines[item.content.options.spine], item.content, result);
20947
+ }
20975
20948
  // item 的 content 转为 component data 加入 JSONScene.components
20976
20949
  if (item.type === ItemType.sprite || item.type === ItemType.particle || item.type === ItemType.mesh || item.type === ItemType.skybox || item.type === ItemType.light || item.type === 'camera' || item.type === ItemType.tree || item.type === ItemType.interact || item.type === ItemType.camera || item.type === ItemType.text || item.type === ItemType.spine || item.type === 'editor-gizmo' || item.type === 'orientation-transformer') {
20977
20950
  item.components = [];
@@ -21215,20 +21188,48 @@ function convertTimelineAsset(composition, guidToItemMap, jsonScene) {
21215
21188
  id: timelineAssetData.id
21216
21189
  };
21217
21190
  composition.sceneBindings = sceneBindings;
21218
- if (!jsonScene.animations) {
21219
- jsonScene.animations = [];
21220
- }
21221
- // @ts-expect-error
21222
- jsonScene.animations.push(timelineAssetData);
21191
+ jsonScene.miscs.push(timelineAssetData);
21223
21192
  for (const trackData of trackDatas){
21224
21193
  //@ts-expect-error
21225
- jsonScene.animations.push(trackData);
21194
+ jsonScene.miscs.push(trackData);
21226
21195
  }
21227
21196
  for (const playableAsset of playableAssetDatas){
21228
21197
  //@ts-expect-error
21229
- jsonScene.animations.push(playableAsset);
21198
+ jsonScene.miscs.push(playableAsset);
21230
21199
  }
21231
21200
  }
21201
+ function convertBinaryAsset(bins, jsonScene) {
21202
+ //@ts-expect-error
21203
+ jsonScene.bins = bins.map((bin)=>({
21204
+ url: bin.url,
21205
+ 'dataType': 'BinaryAsset',
21206
+ id: generateGUID()
21207
+ }));
21208
+ }
21209
+ function convertSpineData(resource, content, jsonScene) {
21210
+ //@ts-expect-error
21211
+ content.resource = {
21212
+ 'atlas': {
21213
+ 'bins': {
21214
+ //@ts-expect-error
21215
+ 'id': jsonScene.bins[resource.atlas[1][0]].id
21216
+ },
21217
+ 'source': resource.atlas[1].slice(1)
21218
+ },
21219
+ 'skeleton': {
21220
+ 'bins': {
21221
+ //@ts-expect-error
21222
+ 'id': jsonScene.bins[resource.skeleton[1][0]].id
21223
+ },
21224
+ 'source': resource.skeleton[1].slice(1)
21225
+ },
21226
+ 'skeletonType': resource.skeletonType,
21227
+ 'images': resource.images.map((i)=>({
21228
+ //@ts-expect-error
21229
+ id: jsonScene.textures[i].id
21230
+ }))
21231
+ };
21232
+ }
21232
21233
 
21233
21234
  const v0 = /^(\d+)\.(\d+)\.(\d+)(-(\w+)\.\d+)?$/;
21234
21235
  const standardVersion = /^(\d+)\.(\d+)$/;
@@ -21787,7 +21788,7 @@ let seed = 1;
21787
21788
  const shaderLibrary = renderer == null ? void 0 : renderer.getShaderLibrary();
21788
21789
  yield pluginSystem == null ? void 0 : pluginSystem.precompile(compositions, renderer, options);
21789
21790
  yield new Promise((resolve)=>{
21790
- shaderLibrary.compileAllShaders(()=>{
21791
+ shaderLibrary == null ? void 0 : shaderLibrary.compileAllShaders(()=>{
21791
21792
  resolve(null);
21792
21793
  });
21793
21794
  });
@@ -23291,7 +23292,7 @@ let listOrder = 0;
23291
23292
  }
23292
23293
  addPackageDatas(scene) {
23293
23294
  const { jsonScene, textureOptions = [] } = scene;
23294
- const { items = [], materials = [], shaders = [], geometries = [], components = [], animations = [], bins = [] } = jsonScene;
23295
+ const { items = [], materials = [], shaders = [], geometries = [], components = [], animations = [], bins = [], miscs = [] } = jsonScene;
23295
23296
  for (const vfxItemData of items){
23296
23297
  this.addEffectsObjectData(vfxItemData);
23297
23298
  }
@@ -23310,6 +23311,9 @@ let listOrder = 0;
23310
23311
  for (const animationData of animations){
23311
23312
  this.addEffectsObjectData(animationData);
23312
23313
  }
23314
+ for (const miscData of miscs){
23315
+ this.addEffectsObjectData(miscData);
23316
+ }
23313
23317
  for(let i = 0; i < bins.length; i++){
23314
23318
  const binaryData = bins[i];
23315
23319
  const binaryBuffer = scene.bins[i];
@@ -23684,7 +23688,9 @@ exports.SubCompositionPlayableAsset = SubCompositionPlayableAsset;
23684
23688
  exports.SubCompositionTrack = SubCompositionTrack;
23685
23689
  exports.TEMPLATE_USE_OFFSCREEN_CANVAS = TEMPLATE_USE_OFFSCREEN_CANVAS;
23686
23690
  exports.TextComponent = TextComponent;
23691
+ exports.TextLayout = TextLayout;
23687
23692
  exports.TextLoader = TextLoader;
23693
+ exports.TextStyle = TextStyle;
23688
23694
  exports.Texture = Texture;
23689
23695
  exports.TextureFactory = TextureFactory;
23690
23696
  exports.Ticker = Ticker;
@@ -23722,7 +23728,6 @@ exports.createShape = createShape;
23722
23728
  exports.createVFXItem = createVFXItem;
23723
23729
  exports.createValueGetter = createValueGetter;
23724
23730
  exports.decimalEqual = decimalEqual;
23725
- exports.deepClone = deepClone;
23726
23731
  exports.defaultGlobalVolume = defaultGlobalVolume;
23727
23732
  exports.defaultPlugins = defaultPlugins;
23728
23733
  exports.deserializeMipmapTexture = deserializeMipmapTexture;
@@ -23809,7 +23814,7 @@ exports.particleUniformTypeMap = particleUniformTypeMap;
23809
23814
  exports.particleVert = particleVert;
23810
23815
  exports.pluginLoaderMap = pluginLoaderMap;
23811
23816
  exports.pointOnLine = pointOnLine;
23812
- exports.random = random;
23817
+ exports.randomInRange = randomInRange;
23813
23818
  exports.registerPlugin = registerPlugin;
23814
23819
  exports.removeItem = removeItem;
23815
23820
  exports.rotateVec2 = rotateVec2;