@galacean/effects-specification 2.0.0-alpha.5 → 2.0.0-alpha.7

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/fallback.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  * Name: @galacean/effects-specification
3
3
  * Description: Galacean Effects JSON Specification
4
4
  * Author: Ant Group CO., Ltd.
5
- * Version: v2.0.0-alpha.5
5
+ * Version: v2.0.0-alpha.7
6
6
  */
7
7
 
8
8
  /******************************************************************************
@@ -374,10 +374,6 @@ var ItemType;
374
374
  * 预合成元素
375
375
  */
376
376
  ItemType["composition"] = "7";
377
- /**
378
- * 滤镜图层
379
- */
380
- ItemType["filter"] = "8";
381
377
  /**
382
378
  * Spine 元素
383
379
  */
@@ -526,7 +522,7 @@ var CompositionEndBehavior;
526
522
 
527
523
  /**
528
524
  * 动态换图类型
529
- * @since 1.3.0
525
+ * @since 1.1.0
530
526
  */
531
527
  var BackgroundType;
532
528
  (function (BackgroundType) {
@@ -1218,14 +1214,6 @@ function getStandardParticleContent(particle) {
1218
1214
  ret.options.startRotationX = ensureNumberExpression(options.startRotationX);
1219
1215
  ret.options.startRotationY = ensureNumberExpression(options.startRotationY);
1220
1216
  }
1221
- if (particle.filter) {
1222
- var filter_1 = {};
1223
- forEach(particle.filter, function (val, key) {
1224
- // @ts-expect-error
1225
- filter_1[key] = ensureValueGetter(val);
1226
- });
1227
- ret.filter = filter_1;
1228
- }
1229
1217
  if (transform && transform.path) {
1230
1218
  ret.emitterTransform = {
1231
1219
  path: ensureFixedVec3(transform.path),
@@ -1509,36 +1497,6 @@ function getStandardCameraContent(model) {
1509
1497
  return ret;
1510
1498
  }
1511
1499
 
1512
- var convertParams = [
1513
- 'strength',
1514
- 'bloomAddon',
1515
- 'colorAddon',
1516
- 'period',
1517
- 'waveMovement',
1518
- 'colorThreshold',
1519
- 'xOpacity',
1520
- 'yOpacity',
1521
- 'feather',
1522
- ];
1523
- var pathParams = [
1524
- 'path', 'position',
1525
- ];
1526
- function getStandardFilterContent(filter) {
1527
- var ret = {};
1528
- forEach(filter, function (val, key) {
1529
- if (convertParams.includes(key)) {
1530
- ret[key] = ensureFixedNumber(val);
1531
- }
1532
- else if (pathParams.includes(key)) {
1533
- ret[key] = ensureFixedVec3(val);
1534
- }
1535
- else {
1536
- ret[key] = val;
1537
- }
1538
- });
1539
- return ret;
1540
- }
1541
-
1542
1500
  /**
1543
1501
  * 2.1 以下版本数据适配(mars-player@2.4.0 及以上版本支持 2.1 以下数据的适配)
1544
1502
  */
@@ -1577,21 +1535,18 @@ function version22Migration(json) {
1577
1535
  * 3.0 以下版本数据适配(runtime 2.0及以上版本支持)
1578
1536
  */
1579
1537
  function version30Migration(json) {
1580
- var e_1, _a;
1581
- var _b, _c, _d, _e, _f, _g, _h, _j;
1538
+ var e_1, _a, e_2, _b;
1539
+ var _c, _d, _e, _f, _g, _h, _j, _k;
1582
1540
  var result = __assign(__assign({}, json), { items: [], components: [], materials: [], shaders: [], geometries: [] });
1583
1541
  // 兼容老版本数据中不存在textures的情况
1584
- (_b = result.textures) !== null && _b !== void 0 ? _b : (result.textures = []);
1542
+ (_c = result.textures) !== null && _c !== void 0 ? _c : (result.textures = []);
1585
1543
  result.textures.forEach(function (textureOptions) {
1586
- //@ts-expect-error
1587
1544
  textureOptions.id = generateGUID();
1588
- //@ts-expect-error
1589
1545
  textureOptions.dataType = DataType.Texture;
1590
1546
  });
1591
1547
  if (result.textures.length < result.images.length) {
1592
1548
  for (var i = result.textures.length; i < result.images.length; i++) {
1593
1549
  result.textures.push({
1594
- //@ts-expect-error
1595
1550
  id: generateGUID(),
1596
1551
  dataType: DataType.Texture,
1597
1552
  source: i,
@@ -1599,39 +1554,53 @@ function version30Migration(json) {
1599
1554
  });
1600
1555
  }
1601
1556
  }
1557
+ var itemGuidMap = {};
1602
1558
  var _loop_1 = function (composition) {
1603
- var e_2, _m, e_3, _o;
1559
+ var e_3, _q;
1604
1560
  // composition 的 endbehaviour 兼容
1605
1561
  if (composition.endBehavior === END_BEHAVIOR_PAUSE_AND_DESTROY || composition.endBehavior === END_BEHAVIOR_PAUSE) {
1606
1562
  composition.endBehavior = END_BEHAVIOR_FREEZE;
1607
1563
  }
1608
- var itemGuidMap = {};
1564
+ // 过滤掉滤镜元素
1565
+ composition.items = composition.items.filter(function (item) { return item.type !== '8'; });
1566
+ // 过滤掉粒子滤镜(扭曲)
1567
+ composition.items.forEach(function (item) {
1568
+ if (item.type === ItemType.particle) {
1569
+ // @ts-expect-error
1570
+ var filterData = item.content['filter'];
1571
+ if (filterData) {
1572
+ // @ts-expect-error
1573
+ delete item.content['filter'];
1574
+ }
1575
+ }
1576
+ });
1577
+ var itemGuidMap_1 = {};
1609
1578
  try {
1610
- for (var _p = (e_2 = void 0, __values(composition.items)), _q = _p.next(); !_q.done; _q = _p.next()) {
1611
- var item = _q.value;
1612
- itemGuidMap[item.id] = generateGUID();
1579
+ for (var _r = (e_3 = void 0, __values(composition.items)), _s = _r.next(); !_s.done; _s = _r.next()) {
1580
+ var item = _s.value;
1581
+ itemGuidMap_1[item.id] = generateGUID();
1613
1582
  // TODO: 编辑器测试用,上线后删除
1614
1583
  //@ts-expect-error
1615
1584
  item.oldId = item.id;
1616
- item.id = itemGuidMap[item.id];
1585
+ item.id = itemGuidMap_1[item.id];
1617
1586
  }
1618
1587
  }
1619
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
1588
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
1620
1589
  finally {
1621
1590
  try {
1622
- if (_q && !_q.done && (_m = _p.return)) _m.call(_p);
1591
+ if (_s && !_s.done && (_q = _r.return)) _q.call(_r);
1623
1592
  }
1624
- finally { if (e_2) throw e_2.error; }
1593
+ finally { if (e_3) throw e_3.error; }
1625
1594
  }
1626
1595
  composition.items.forEach(function (item, index) {
1627
1596
  if (item.parentId) {
1628
1597
  if (item.parentId.includes('^')) {
1629
1598
  var parentId = (item.parentId).split('^')[0];
1630
1599
  var nodeId = (item.parentId).split('^')[1];
1631
- item.parentId = itemGuidMap[parentId] + '^' + nodeId;
1600
+ item.parentId = itemGuidMap_1[parentId] + '^' + nodeId;
1632
1601
  }
1633
1602
  else {
1634
- item.parentId = itemGuidMap[item.parentId];
1603
+ item.parentId = itemGuidMap_1[item.parentId];
1635
1604
  }
1636
1605
  }
1637
1606
  // @ts-expect-error fix item type
@@ -1639,179 +1608,177 @@ function version30Migration(json) {
1639
1608
  // @ts-expect-error fix item type
1640
1609
  composition.items[index] = { id: item.id };
1641
1610
  });
1611
+ };
1612
+ try {
1613
+ // 更正Composition.endBehavior
1614
+ for (var _l = __values(json.compositions), _m = _l.next(); !_m.done; _m = _l.next()) {
1615
+ var composition = _m.value;
1616
+ _loop_1(composition);
1617
+ }
1618
+ }
1619
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
1620
+ finally {
1642
1621
  try {
1643
- for (var _r = (e_3 = void 0, __values(result.items)), _s = _r.next(); !_s.done; _s = _r.next()) {
1644
- var item = _s.value;
1645
- // texture 索引转为统一 guid 索引
1646
- if (item.content) {
1647
- if (item.content.renderer) {
1648
- if (item.content.renderer.texture !== undefined) {
1649
- var oldTextureId = item.content.renderer.texture;
1650
- //@ts-expect-error
1651
- item.content.renderer.texture = { id: result.textures[oldTextureId].id };
1652
- }
1653
- }
1654
- if (item.content.trails) {
1655
- if (item.content.trails.texture !== undefined) {
1656
- var oldTextureId = item.content.trails.texture;
1657
- //@ts-expect-error
1658
- item.content.trails.texture = { id: result.textures[oldTextureId].id };
1659
- }
1622
+ if (_m && !_m.done && (_a = _l.return)) _a.call(_l);
1623
+ }
1624
+ finally { if (e_1) throw e_1.error; }
1625
+ }
1626
+ try {
1627
+ for (var _o = __values(result.items), _p = _o.next(); !_p.done; _p = _o.next()) {
1628
+ var item = _p.value;
1629
+ // 原 texture 索引转为统一 guid 索引
1630
+ if (item.content) {
1631
+ if (item.content.renderer) {
1632
+ if (item.content.renderer.texture !== undefined) {
1633
+ var oldTextureId = item.content.renderer.texture;
1634
+ item.content.renderer.texture = { id: result.textures[oldTextureId].id };
1660
1635
  }
1661
1636
  }
1662
- // item 的 transform 属性由数组转为 {x:n, y:n, z:n}
1663
- if (item.transform) {
1664
- //@ts-expect-error
1665
- var position = __spreadArray([], __read((_c = item.transform.position) !== null && _c !== void 0 ? _c : [0, 0, 0]), false);
1666
- //@ts-expect-error
1667
- var rotation = __spreadArray([], __read((_d = item.transform.rotation) !== null && _d !== void 0 ? _d : [0, 0, 0]), false);
1668
- //@ts-expect-error
1669
- var scale = __spreadArray([], __read((_e = item.transform.scale) !== null && _e !== void 0 ? _e : [1, 1, 1]), false);
1670
- Object.assign(item, {
1671
- transform: {
1672
- position: { x: position[0], y: position[1], z: position[2] },
1673
- eulerHint: { x: rotation[0], y: rotation[1], z: rotation[2] },
1674
- scale: { x: scale[0], y: scale[1], z: scale[0] },
1675
- },
1676
- });
1677
- // sprite 的 scale 转为 size
1678
- if (item.type === ItemType.sprite) {
1679
- item.transform.size = { x: scale[0], y: scale[1] };
1680
- item.transform.scale = { x: 1, y: 1, z: 1 };
1681
- }
1682
- // sprite 的 anchor 修正
1683
- if (item.type === ItemType.sprite) {
1684
- var content = item.content;
1685
- if (!content.renderer) {
1686
- content.renderer = {};
1687
- }
1688
- var renderer = content.renderer;
1689
- var realAnchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
1690
- var startSize = item.transform.size;
1691
- // 兼容旧JSON(anchor和particleOrigin可能同时存在)
1692
- if (!renderer.anchor && renderer.particleOrigin !== undefined) {
1693
- item.transform.position.x += -realAnchor[0] * ((_f = startSize === null || startSize === void 0 ? void 0 : startSize.x) !== null && _f !== void 0 ? _f : 1);
1694
- item.transform.position.y += -realAnchor[1] * ((_g = startSize === null || startSize === void 0 ? void 0 : startSize.y) !== null && _g !== void 0 ? _g : 1);
1695
- }
1696
- item.transform.anchor = { x: realAnchor[0] * ((_h = startSize === null || startSize === void 0 ? void 0 : startSize.x) !== null && _h !== void 0 ? _h : 1), y: realAnchor[1] * ((_j = startSize === null || startSize === void 0 ? void 0 : startSize.y) !== null && _j !== void 0 ? _j : 1) };
1637
+ if (item.content.trails) {
1638
+ if (item.content.trails.texture !== undefined) {
1639
+ var oldTextureId = item.content.trails.texture;
1640
+ item.content.trails.texture = { id: result.textures[oldTextureId].id };
1697
1641
  }
1698
1642
  }
1699
- if (item.type === ItemType.particle) {
1643
+ }
1644
+ // item 的 transform 属性由数组转为 {x:n, y:n, z:n}
1645
+ if (item.transform) {
1646
+ //@ts-expect-error
1647
+ var position = __spreadArray([], __read((_d = item.transform.position) !== null && _d !== void 0 ? _d : [0, 0, 0]), false);
1648
+ //@ts-expect-error
1649
+ var rotation = __spreadArray([], __read((_e = item.transform.rotation) !== null && _e !== void 0 ? _e : [0, 0, 0]), false);
1650
+ //@ts-expect-error
1651
+ var scale = __spreadArray([], __read((_f = item.transform.scale) !== null && _f !== void 0 ? _f : [1, 1, 1]), false);
1652
+ Object.assign(item, {
1653
+ transform: {
1654
+ position: { x: position[0], y: position[1], z: position[2] },
1655
+ eulerHint: { x: rotation[0], y: rotation[1], z: rotation[2] },
1656
+ scale: { x: scale[0], y: scale[1], z: scale[0] },
1657
+ },
1658
+ });
1659
+ // sprite 的 scale 转为 size
1660
+ if (item.type === ItemType.sprite) {
1661
+ item.transform.size = { x: scale[0], y: scale[1] };
1662
+ item.transform.scale = { x: 1, y: 1, z: 1 };
1663
+ }
1664
+ // sprite 的 anchor 修正
1665
+ if (item.type === ItemType.sprite) {
1700
1666
  var content = item.content;
1701
1667
  if (!content.renderer) {
1702
1668
  content.renderer = {};
1703
1669
  }
1704
1670
  var renderer = content.renderer;
1705
- content.renderer.anchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
1671
+ var realAnchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
1672
+ var startSize = item.transform.size;
1673
+ // 兼容旧JSON(anchor和particleOrigin可能同时存在)
1674
+ if (!renderer.anchor && renderer.particleOrigin !== undefined) {
1675
+ item.transform.position.x += -realAnchor[0] * ((_g = startSize === null || startSize === void 0 ? void 0 : startSize.x) !== null && _g !== void 0 ? _g : 1);
1676
+ item.transform.position.y += -realAnchor[1] * ((_h = startSize === null || startSize === void 0 ? void 0 : startSize.y) !== null && _h !== void 0 ? _h : 1);
1677
+ }
1678
+ item.transform.anchor = { x: realAnchor[0] * ((_j = startSize === null || startSize === void 0 ? void 0 : startSize.x) !== null && _j !== void 0 ? _j : 1), y: realAnchor[1] * ((_k = startSize === null || startSize === void 0 ? void 0 : startSize.y) !== null && _k !== void 0 ? _k : 1) };
1706
1679
  }
1707
- // 动画数据转化 TODO: 动画数据移到 TimelineComponentData
1708
- item.content.tracks = [];
1709
- var tracks = item.content.tracks;
1710
- if (item.type !== ItemType.particle) {
1711
- tracks.push({
1712
- clips: [
1713
- {
1714
- dataType: 'TransformAnimationPlayableAsset',
1715
- animationClip: {
1716
- sizeOverLifetime: item.content.sizeOverLifetime,
1717
- rotationOverLifetime: item.content.rotationOverLifetime,
1718
- positionOverLifetime: item.content.positionOverLifetime,
1719
- },
1720
- },
1721
- ],
1722
- });
1680
+ }
1681
+ if (item.type === ItemType.particle) {
1682
+ var content = item.content;
1683
+ if (!content.renderer) {
1684
+ content.renderer = {};
1723
1685
  }
1724
- if (item.type === ItemType.sprite) {
1725
- tracks.push({
1726
- clips: [
1727
- {
1728
- dataType: 'SpriteColorAnimationPlayableAsset',
1729
- animationClip: {
1730
- colorOverLifetime: item.content.colorOverLifetime,
1731
- startColor: item.content.options.startColor,
1732
- },
1686
+ var renderer = content.renderer;
1687
+ content.renderer.anchor = convertAnchor(renderer.anchor, renderer.particleOrigin);
1688
+ }
1689
+ // 动画数据转化 TODO: 动画数据移到 TimelineComponentData
1690
+ item.content.tracks = [];
1691
+ var tracks = item.content.tracks;
1692
+ if (item.type !== ItemType.particle) {
1693
+ tracks.push({
1694
+ clips: [
1695
+ {
1696
+ dataType: 'TransformAnimationPlayableAsset',
1697
+ animationClip: {
1698
+ sizeOverLifetime: item.content.sizeOverLifetime,
1699
+ rotationOverLifetime: item.content.rotationOverLifetime,
1700
+ positionOverLifetime: item.content.positionOverLifetime,
1733
1701
  },
1734
- ],
1735
- });
1736
- }
1737
- // gizmo 的 target id 转换为新的 item guid
1738
- if (item.content.options.target) {
1739
- item.content.options.target = itemGuidMap[item.content.options.target];
1740
- }
1741
- // item 的 content 转为 component data 加入 JSONScene.components
1742
- var uuid = generateGUID();
1743
- if (item.type === ItemType.sprite ||
1744
- item.type === ItemType.particle ||
1745
- item.type === ItemType.mesh ||
1746
- item.type === ItemType.skybox ||
1747
- item.type === ItemType.light ||
1748
- item.type === 'camera' ||
1749
- item.type === ItemType.tree ||
1750
- item.type === ItemType.interact ||
1751
- item.type === ItemType.camera ||
1752
- item.type === ItemType.text) {
1753
- item.components = [];
1754
- result.components.push(item.content);
1755
- item.content.id = uuid;
1756
- item.content.item = { id: item.id };
1757
- item.dataType = DataType.VFXItemData;
1758
- item.components.push({ id: item.content.id });
1759
- }
1760
- switch (item.type) {
1761
- case ItemType.sprite:
1762
- item.content.dataType = DataType.SpriteComponent;
1763
- break;
1764
- case ItemType.particle:
1765
- item.content.dataType = DataType.ParticleSystem;
1766
- break;
1767
- case ItemType.mesh:
1768
- item.content.dataType = DataType.MeshComponent;
1769
- break;
1770
- case ItemType.skybox:
1771
- item.content.dataType = DataType.SkyboxComponent;
1772
- break;
1773
- case ItemType.light:
1774
- item.content.dataType = DataType.LightComponent;
1775
- break;
1776
- case 'camera':
1777
- item.content.dataType = DataType.CameraComponent;
1778
- break;
1779
- case ItemType.tree:
1780
- item.content.dataType = DataType.TreeComponent;
1781
- break;
1782
- case ItemType.interact:
1783
- item.content.dataType = DataType.InteractComponent;
1784
- break;
1785
- case ItemType.camera:
1786
- item.content.dataType = DataType.CameraController;
1787
- break;
1788
- case ItemType.text:
1789
- item.content.dataType = DataType.TextComponent;
1790
- break;
1791
- }
1702
+ },
1703
+ ],
1704
+ });
1792
1705
  }
1793
- }
1794
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
1795
- finally {
1796
- try {
1797
- if (_s && !_s.done && (_o = _r.return)) _o.call(_r);
1706
+ if (item.type === ItemType.sprite) {
1707
+ tracks.push({
1708
+ clips: [
1709
+ {
1710
+ dataType: 'SpriteColorAnimationPlayableAsset',
1711
+ animationClip: {
1712
+ colorOverLifetime: item.content.colorOverLifetime,
1713
+ startColor: item.content.options.startColor,
1714
+ },
1715
+ },
1716
+ ],
1717
+ });
1718
+ }
1719
+ // gizmo 的 target id 转换为新的 item guid
1720
+ if (item.content.options.target) {
1721
+ item.content.options.target = itemGuidMap[item.content.options.target];
1722
+ }
1723
+ // item 的 content 转为 component data 加入 JSONScene.components
1724
+ var uuid = generateGUID();
1725
+ if (item.type === ItemType.sprite ||
1726
+ item.type === ItemType.particle ||
1727
+ item.type === ItemType.mesh ||
1728
+ item.type === ItemType.skybox ||
1729
+ item.type === ItemType.light ||
1730
+ item.type === 'camera' ||
1731
+ item.type === ItemType.tree ||
1732
+ item.type === ItemType.interact ||
1733
+ item.type === ItemType.camera ||
1734
+ item.type === ItemType.text) {
1735
+ item.components = [];
1736
+ result.components.push(item.content);
1737
+ item.content.id = uuid;
1738
+ item.content.item = { id: item.id };
1739
+ item.dataType = DataType.VFXItemData;
1740
+ item.components.push({ id: item.content.id });
1741
+ }
1742
+ switch (item.type) {
1743
+ case ItemType.sprite:
1744
+ item.content.dataType = DataType.SpriteComponent;
1745
+ break;
1746
+ case ItemType.particle:
1747
+ item.content.dataType = DataType.ParticleSystem;
1748
+ break;
1749
+ case ItemType.mesh:
1750
+ item.content.dataType = DataType.MeshComponent;
1751
+ break;
1752
+ case ItemType.skybox:
1753
+ item.content.dataType = DataType.SkyboxComponent;
1754
+ break;
1755
+ case ItemType.light:
1756
+ item.content.dataType = DataType.LightComponent;
1757
+ break;
1758
+ case 'camera':
1759
+ item.content.dataType = DataType.CameraComponent;
1760
+ break;
1761
+ case ItemType.tree:
1762
+ item.content.dataType = DataType.TreeComponent;
1763
+ break;
1764
+ case ItemType.interact:
1765
+ item.content.dataType = DataType.InteractComponent;
1766
+ break;
1767
+ case ItemType.camera:
1768
+ item.content.dataType = DataType.CameraController;
1769
+ break;
1770
+ case ItemType.text:
1771
+ item.content.dataType = DataType.TextComponent;
1772
+ break;
1798
1773
  }
1799
- finally { if (e_3) throw e_3.error; }
1800
- }
1801
- };
1802
- try {
1803
- // 更正Composition.endBehavior
1804
- for (var _k = __values(json.compositions), _l = _k.next(); !_l.done; _l = _k.next()) {
1805
- var composition = _l.value;
1806
- _loop_1(composition);
1807
1774
  }
1808
1775
  }
1809
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
1776
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
1810
1777
  finally {
1811
1778
  try {
1812
- if (_l && !_l.done && (_a = _k.return)) _a.call(_k);
1779
+ if (_p && !_p.done && (_b = _o.return)) _b.call(_o);
1813
1780
  }
1814
- finally { if (e_1) throw e_1.error; }
1781
+ finally { if (e_2) throw e_2.error; }
1815
1782
  }
1816
1783
  result.version = '3.0';
1817
1784
  return result;
@@ -1970,14 +1937,6 @@ function getStandardItem(item, opt) {
1970
1937
  duration = item.duration;
1971
1938
  }
1972
1939
  transform = item.transform || getTransform(originContent.transform);
1973
- if (type === ItemType.filter) {
1974
- if (currentVersion < '1.1') {
1975
- currentVersion = '1.1';
1976
- }
1977
- content = getStandardSpriteContent(originContent, transform);
1978
- // @ts-expect-error
1979
- content.filter = getStandardFilterContent(originContent.filter);
1980
- }
1981
1940
  }
1982
1941
  else if (item.particle) {
1983
1942
  type = ItemType.particle;