@galacean/effects-plugin-spine 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/README.md CHANGED
@@ -12,10 +12,11 @@ import '@galacean/effects-plugin-spine';
12
12
  ### Get Spine Resource List
13
13
 
14
14
  ``` ts
15
- import type { SpineResource } from '@galacean/effects-plugin-spine';
15
+ import type { SpineDataCache } from '@galacean/effects-plugin-spine';
16
16
 
17
17
  const comp = await player.play(scene);
18
- const spineData: SpineResource[] = comp.loaderData.spineDatas;
18
+ const item = comp.getItemByName('itemName');
19
+ const spineData: SpineDataCache = item.spineDataCache;
19
20
  ```
20
21
 
21
22
  ### Get Animation List / Skin List
@@ -24,17 +25,18 @@ const spineData: SpineResource[] = comp.loaderData.spineDatas;
24
25
 
25
26
  ``` ts
26
27
  const comp = await new Player().loadScene(scene);
27
- const item = comp.getItemByName(name)
28
+ const item = comp.getItemByName('itemName');
28
29
  const { skeletonData } = item.spineDataCache;
29
30
  const animationList = getAnimationList(skeletonData);
30
31
  const skinList = getSkinList(skeletonData);
31
32
  ```
32
33
 
33
- 2. Get from the `spineDatas` array
34
+ 2. After starting, you can access it in the `spineDataCache`.
34
35
 
35
36
  ``` ts
36
37
  const comp = await new Player().loadScene(scene);
37
- const { skinList, animationList } = comp.loaderData.spineDatas[index];
38
+ const item = comp.getItemByName('itemName')
39
+ const { skinList, animationList } = item.spineDataCache;
38
40
  ```
39
41
 
40
42
  ### Get Duration of a Specific Animation
package/dist/alipay.js CHANGED
@@ -26,12 +26,6 @@ function _inherits(subClass, superClass) {
26
26
  if (superClass) _set_prototype_of(subClass, superClass);
27
27
  }
28
28
 
29
- function _instanceof1(left, right) {
30
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
31
- return !!right[Symbol.hasInstance](left);
32
- } else return _instanceof1(left, right);
33
- }
34
-
35
29
  function _array_like_to_array(arr, len) {
36
30
  if (len == null || len > arr.length) len = arr.length;
37
31
  for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
@@ -67,6 +61,12 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
67
61
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
68
62
  }
69
63
 
64
+ function _instanceof1(left, right) {
65
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
66
+ return !!right[Symbol.hasInstance](left);
67
+ } else return _instanceof1(left, right);
68
+ }
69
+
70
70
  function _assert_this_initialized(self) {
71
71
  if (self === void 0) throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
72
72
  return self;
@@ -10616,9 +10616,10 @@ function setBlending(material, mode, pma) {
10616
10616
  /**
10617
10617
  * 从二进制数据中解析 atlas 数据
10618
10618
  * @param buffer - atlas 文件对应的二进制数据
10619
+ * @param start - buffer 中的起始索引
10620
+ * @param length - buffer 的长度
10619
10621
  */ function getAtlasFromBuffer(buffer) {
10620
- var atlasText = decodeText(new Uint8Array(buffer));
10621
- return new TextureAtlas(atlasText);
10622
+ return new TextureAtlas(decodeText(buffer));
10622
10623
  }
10623
10624
  /**
10624
10625
  * 从二进制数据中解析用于创建 skeletonData 的数据
@@ -10634,80 +10635,29 @@ function setBlending(material, mode, pma) {
10634
10635
  }
10635
10636
  return skeletonFile;
10636
10637
  }
10637
-
10638
- /**
10639
- *
10640
- */ var SpineLoader = /*#__PURE__*/ function(AbstractPlugin) {
10641
- _inherits(SpineLoader, AbstractPlugin);
10642
- function SpineLoader() {
10643
- return AbstractPlugin.apply(this, arguments);
10644
- }
10645
- var _proto = SpineLoader.prototype;
10646
- _proto.onCompositionConstructed = function onCompositionConstructed(composition, scene) {
10647
- if (!scene.jsonScene.spines) {
10648
- return;
10649
- }
10650
- composition.loaderData.spineDatas = scene.jsonScene.spines.map(function(resource, index) {
10651
- return readSpineData(resource, scene.bins, composition.textures, composition);
10652
- });
10653
- };
10654
- _proto.onCompositionDestroyed = function onCompositionDestroyed(composition) {
10655
- if (composition.loaderData.spineDatas) {
10656
- delete composition.loaderData.spineDatas;
10657
- }
10658
- };
10659
- return SpineLoader;
10660
- }(effects.AbstractPlugin);
10661
- function readSpineData(resource, bins, textures, composition) {
10662
- var atlasPointer = resource.atlas, skeletonPointer = resource.skeleton, images = resource.images, skeletonType = resource.skeletonType;
10663
- var _atlasPointer_ = atlasPointer[1], index = _atlasPointer_[0], tmp = _atlasPointer_[1], start = tmp === void 0 ? 0 : tmp, bufferLength = _atlasPointer_[2];
10664
- var atlasBuffer = bins[index];
10665
- var atlasText = bufferLength ? decodeText(new Uint8Array(atlasBuffer, start, bufferLength)) : decodeText(new Uint8Array(atlasBuffer, start));
10666
- var atlas = new TextureAtlas(atlasText);
10638
+ function readAtlasData(atlasBuffer, textures) {
10639
+ var atlas = getAtlasFromBuffer(atlasBuffer);
10667
10640
  var pageCount = atlas.pages.length;
10668
- var engine = composition.getEngine();
10669
- if (images.length !== pageCount) {
10670
- throw new Error("atlas.page's length not equal spine.textures' length");
10671
- }
10672
10641
  for(var i = 0; i < pageCount; i++){
10673
10642
  var page = atlas.pages[i];
10674
- // 直接获取Texture
10675
- var tex = images[i];
10676
- // @ts-expect-error
10677
- if (images[i].id) {
10678
- var textureId = images[i].id;
10679
- tex = engine.assetLoader.loadGUID(textureId);
10680
- } else if (typeof images[i] === "number") {
10681
- // TODO 老JSON的兼容逻辑
10682
- tex = textures[images[i]];
10683
- }
10684
- if (!tex) {
10643
+ var texture = textures[i];
10644
+ if (!texture) {
10685
10645
  throw new Error("Can not find page " + page.name + "'s texture, check the texture name");
10686
10646
  }
10687
- page.texture = tex;
10647
+ page.texture = texture;
10688
10648
  }
10689
- var _skeletonPointer_ = skeletonPointer[1], skelIndex = _skeletonPointer_[0], tmp1 = _skeletonPointer_[1], skelStart = tmp1 === void 0 ? 0 : tmp1, skelBufferLength = _skeletonPointer_[2];
10690
- var skeletonBuffer = skelBufferLength ? bins[skelIndex].slice(skelStart, skelStart + skelBufferLength) : bins[skelIndex].slice(skelStart);
10691
- var skeletonFile = getSkeletonFromBuffer(skeletonBuffer, skeletonType);
10692
- var skeletonData = createSkeletonData(atlas, skeletonFile, skeletonType); //VFXItem用此skeletonData新建skeleton实例会造成纹理丢失
10693
- var skinList = getSkinList(skeletonData);
10694
- var animationList = getAnimationList(skeletonData);
10695
- return {
10696
- atlas: atlas,
10697
- skeletonFile: skeletonFile,
10698
- skeletonData: skeletonData,
10699
- images: images,
10700
- skeletonType: skeletonType,
10701
- skeletonInstance: new Skeleton(skeletonData),
10702
- skinList: skinList,
10703
- animationList: animationList,
10704
- // @ts-expect-error
10705
- texturesOptions: images.map(function(texturePointer) {
10706
- return textures[texturePointer];
10707
- }),
10708
- // @ts-expect-error
10709
- id: resource.id
10649
+ return atlas;
10650
+ }
10651
+
10652
+ function _extends() {
10653
+ _extends = Object.assign || function assign(target) {
10654
+ for(var i = 1; i < arguments.length; i++){
10655
+ var source = arguments[i];
10656
+ for(var key in source)if (Object.prototype.hasOwnProperty.call(source, key)) target[key] = source[key];
10657
+ }
10658
+ return target;
10710
10659
  };
10660
+ return _extends.apply(this, arguments);
10711
10661
  }
10712
10662
 
10713
10663
  function __decorate(decorators, target, key, desc) {
@@ -11061,8 +11011,8 @@ var SlotGroup = /*#__PURE__*/ function() {
11061
11011
  }
11062
11012
  clipper.clipEnd();
11063
11013
  this.wm = this.transform.getWorldMatrix();
11064
- this.meshGroups.map(function(sp) {
11065
- return sp.endUpdate(_this.wm);
11014
+ this.meshGroups.map(function(sp, index) {
11015
+ sp.endUpdate(_this.wm);
11066
11016
  });
11067
11017
  };
11068
11018
  /**
@@ -11083,7 +11033,7 @@ var SlotGroup = /*#__PURE__*/ function() {
11083
11033
  var res = -1;
11084
11034
  for(var i = startIndex; i < this.meshGroups.length; i++){
11085
11035
  var mesh = this.meshGroups[i];
11086
- if (mesh && mesh.blending === blendMode && mesh.texture.name === texture.name && vertexNum + mesh.indicesNum < SlotGroup.MAX_VERTICES) {
11036
+ if (mesh && mesh.blending === blendMode && mesh.texture === texture && vertexNum + mesh.indicesNum < SlotGroup.MAX_VERTICES) {
11087
11037
  res = i;
11088
11038
  break;
11089
11039
  }
@@ -11112,9 +11062,9 @@ var SlotGroup = /*#__PURE__*/ function() {
11112
11062
  var Vector2 = effects.math.Vector2, Vector3 = effects.math.Vector3;
11113
11063
  exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11114
11064
  _inherits(SpineComponent, RendererComponent);
11115
- function SpineComponent(engine, options) {
11065
+ function SpineComponent() {
11116
11066
  var _this;
11117
- _this = RendererComponent.call(this, engine) || this;
11067
+ _this = RendererComponent.apply(this, arguments) || this;
11118
11068
  /**
11119
11069
  * aabb 包围盒与 skeleton 原点的距离
11120
11070
  */ _this.offset = new Vector2();
@@ -11124,24 +11074,31 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11124
11074
  return _this;
11125
11075
  }
11126
11076
  var _proto = SpineComponent.prototype;
11127
- _proto.fromData = function fromData(options) {
11128
- RendererComponent.prototype.fromData.call(this, options);
11129
- this.options = options;
11077
+ _proto.fromData = function fromData(data) {
11078
+ RendererComponent.prototype.fromData.call(this, data);
11079
+ var _this_resource = this.resource, textures = _this_resource.images, skeletonType = _this_resource.skeletonType, atlasOptions = _this_resource.atlas, skeletonOptions = _this_resource.skeleton;
11080
+ var _atlasOptions_source = atlasOptions.source, start = _atlasOptions_source[0], bufferLength = _atlasOptions_source[1];
11081
+ var atlasBuffer = bufferLength ? new Uint8Array(atlasOptions.bins.buffer, start, bufferLength) : new Uint8Array(atlasOptions.bins.buffer, start);
11082
+ var atlas = readAtlasData(atlasBuffer, textures);
11083
+ var skBuffer = skeletonOptions.bins.buffer;
11084
+ var _skeletonOptions_source = skeletonOptions.source, skelStart = _skeletonOptions_source[0], skelBufferLength = _skeletonOptions_source[1];
11085
+ var skeletonBuffer = skelBufferLength ? skBuffer.slice(skelStart, skelStart + skelBufferLength) : skBuffer.slice(skelStart);
11086
+ var skeletonFile = getSkeletonFromBuffer(skeletonBuffer, skeletonType);
11087
+ var skeletonData = createSkeletonData(atlas, skeletonFile, skeletonType);
11088
+ this.spineDataCache = {
11089
+ atlas: atlas,
11090
+ skeletonData: skeletonData
11091
+ };
11092
+ this.options = data.options;
11130
11093
  this.item.getHitTestParams = this.getHitTestParams.bind(this);
11131
11094
  };
11132
11095
  _proto.start = function start() {
11133
- var _this_item_composition;
11134
11096
  RendererComponent.prototype.start.call(this);
11135
- var content = this.options;
11136
- if (!content) {
11137
- console.error("options used to create SpineComponent is undefined");
11138
- return;
11139
- }
11140
- this.initContent(content.options, (_this_item_composition = this.item.composition) == null ? void 0 : _this_item_composition.loaderData.spineDatas);
11097
+ this.initContent(this.spineDataCache.atlas, this.spineDataCache.skeletonData, this.options);
11141
11098
  // @ts-expect-error
11142
- this.startSize = content.options.startSize;
11099
+ this.startSize = this.options.startSize;
11143
11100
  // @ts-expect-error
11144
- this.renderer = content.renderer;
11101
+ this.renderer = this.options.renderer;
11145
11102
  if (!this.state) {
11146
11103
  return;
11147
11104
  }
@@ -11150,7 +11107,6 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11150
11107
  this.resize();
11151
11108
  };
11152
11109
  _proto.update = function update(dt) {
11153
- var _this_content;
11154
11110
  if (!(this.state && this.skeleton)) {
11155
11111
  return;
11156
11112
  }
@@ -11158,7 +11114,9 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11158
11114
  this.state.apply(this.skeleton);
11159
11115
  this.skeleton.update(dt / 1000);
11160
11116
  this.skeleton.updateWorldTransform(exports.Physics.update);
11161
- (_this_content = this.content) == null ? void 0 : _this_content.update();
11117
+ if (this.content) {
11118
+ this.content.update();
11119
+ }
11162
11120
  };
11163
11121
  _proto.render = function render(renderer) {
11164
11122
  var _this_content;
@@ -11170,24 +11128,18 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11170
11128
  this.state.clearTracks();
11171
11129
  }
11172
11130
  };
11173
- _proto.initContent = function initContent(spineOptions, spineDatas) {
11174
- var index = spineOptions.spine;
11175
- if (isNaN(index)) {
11176
- return;
11177
- }
11178
- var _spineDatas_index = spineDatas[index], atlas = _spineDatas_index.atlas, skeletonData = _spineDatas_index.skeletonData, skeletonInstance = _spineDatas_index.skeletonInstance, skinList = _spineDatas_index.skinList, animationList = _spineDatas_index.animationList;
11131
+ _proto.initContent = function initContent(atlas, skeletonData, spineOptions) {
11179
11132
  var activeAnimation = typeof spineOptions.activeAnimation === "string" ? [
11180
11133
  spineOptions.activeAnimation
11181
11134
  ] : spineOptions.activeAnimation;
11182
- this.skeleton = skeletonInstance;
11135
+ this.skeleton = new Skeleton(skeletonData);
11183
11136
  this.skeletonData = skeletonData;
11184
11137
  this.animationStateData = new AnimationStateData(this.skeletonData);
11185
11138
  this.animationStateData.defaultMix = spineOptions.mixDuration || 0;
11186
- this.spineDataCache = spineDatas[index];
11187
- this.skinList = skinList.slice();
11188
- this.animationList = animationList.slice();
11139
+ this.skinList = getSkinList(skeletonData);
11140
+ this.animationList = getAnimationList(skeletonData);
11189
11141
  this.resizeRule = spineOptions.resizeRule;
11190
- this.setSkin(spineOptions.activeSkin || (skinList.length ? skinList[0] : "default"));
11142
+ this.setSkin(spineOptions.activeSkin || (this.skinList.length ? this.skinList[0] : "default"));
11191
11143
  this.state = new AnimationState(this.animationStateData);
11192
11144
  if (activeAnimation.length === 1) {
11193
11145
  // 兼容旧JSON,根据时长计算速度
@@ -11200,6 +11152,11 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11200
11152
  } else {
11201
11153
  this.setAnimationList(activeAnimation, spineOptions.speed);
11202
11154
  }
11155
+ this.spineDataCache = _extends({}, this.spineDataCache, {
11156
+ skeletonInstance: this.skeleton,
11157
+ skinList: this.skinList,
11158
+ animationList: this.animationList
11159
+ });
11203
11160
  this.pma = atlas.pages[0].pma;
11204
11161
  this._priority = this.item.renderOrder;
11205
11162
  this.content = new SlotGroup(this.skeleton.drawOrder, {
@@ -11432,12 +11389,21 @@ exports.SpineComponent = /*#__PURE__*/ function(RendererComponent) {
11432
11389
  };
11433
11390
  return SpineComponent;
11434
11391
  }(effects.RendererComponent);
11392
+ __decorate([
11393
+ effects.serialize()
11394
+ ], exports.SpineComponent.prototype, "resource", void 0);
11435
11395
  exports.SpineComponent = __decorate([
11436
11396
  effects.effectsClass("SpineComponent")
11437
11397
  ], exports.SpineComponent);
11438
11398
 
11439
- effects.registerPlugin("spine", SpineLoader, effects.VFXItem);
11440
- var version = "2.0.0-alpha.16";
11399
+ effects.registerPlugin("spine", /*#__PURE__*/ function(AbstractPlugin) {
11400
+ _inherits(SpineLoader, AbstractPlugin);
11401
+ function SpineLoader() {
11402
+ return AbstractPlugin.apply(this, arguments);
11403
+ }
11404
+ return SpineLoader;
11405
+ }(effects.AbstractPlugin), effects.VFXItem);
11406
+ var version = "2.0.0-alpha.17";
11441
11407
  effects.logger.info("plugin spine version: " + version);
11442
11408
  if (version !== effects.version) {
11443
11409
  console.error("注意:请统一 Spine 插件与 Player 版本,不统一的版本混用会有不可预知的后果!", "\nAttention: Please ensure the Spine plugin is synchronized with the Player version. Mixing and matching incompatible versions may result in unpredictable consequences!");
@@ -11528,7 +11494,6 @@ exports.Skin = Skin;
11528
11494
  exports.SkinEntry = SkinEntry;
11529
11495
  exports.Slot = Slot;
11530
11496
  exports.SlotData = SlotData;
11531
- exports.SpineLoader = SpineLoader;
11532
11497
  exports.StringSet = StringSet;
11533
11498
  exports.Texture = Texture;
11534
11499
  exports.TextureAtlas = TextureAtlas;