@galacean/effects-core 1.5.0 → 1.6.0-beta.0

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.
@@ -1,5 +1,6 @@
1
1
  import * as spec from '@galacean/effects-specification';
2
- import type { Ray } from '@galacean/effects-math/es/core/index';
2
+ import type { Ray } from '@galacean/effects-math/es/core/ray';
3
+ import type { Vector3 } from '@galacean/effects-math/es/core/vector3';
3
4
  import type { SceneType } from './asset-manager';
4
5
  import type { Scene } from './scene';
5
6
  import type { Disposable, LostHandler } from './utils';
@@ -25,6 +26,12 @@ export interface MessageItem {
25
26
  phrase: number;
26
27
  compositionId: number;
27
28
  }
29
+ export interface CompItemClickedData {
30
+ name: string;
31
+ id: string;
32
+ hitPositions: Vector3[];
33
+ position: Vector3;
34
+ }
28
35
  /**
29
36
  *
30
37
  */
@@ -38,6 +45,7 @@ export interface CompositionProps {
38
45
  baseRenderOrder?: number;
39
46
  renderer: Renderer;
40
47
  onPlayerPause?: (item: VFXItem<any>) => void;
48
+ onItemClicked?: (item: VFXItem<any>) => void;
41
49
  onMessageItem?: (item: MessageItem) => void;
42
50
  onEnd?: (composition: Composition) => void;
43
51
  event?: EventSystem;
@@ -82,6 +90,11 @@ export declare class Composition implements Disposable, LostHandler {
82
90
  * 是否播放完成后销毁 texture 对象
83
91
  */
84
92
  keepResource: boolean;
93
+ /**
94
+ * 合成内的元素否允许点击、拖拽交互
95
+ * @since 1.6.0
96
+ */
97
+ interactive: boolean;
85
98
  /**
86
99
  * 合成结束行为是 spec.END_BEHAVIOR_PAUSE 或 spec.END_BEHAVIOR_PAUSE_AND_DESTROY 时执行的回调
87
100
  * @internal
@@ -95,6 +108,14 @@ export declare class Composition implements Disposable, LostHandler {
95
108
  * 合成中消息元素创建/销毁时触发的回调
96
109
  */
97
110
  onMessageItem?: (item: MessageItem) => void;
111
+ /**
112
+ * 合成中元素点击时触发的回调
113
+ * 注意:此接口随时可能下线,请务使用!
114
+ * @since 1.6.0
115
+ * @ignore
116
+ * @deprecated
117
+ */
118
+ onItemClicked?: (data: CompItemClickedData) => void;
98
119
  /**
99
120
  * 合成id
100
121
  */
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: v1.5.0
6
+ * Version: v1.6.0-beta.0
7
7
  */
8
8
 
9
9
  'use strict';
@@ -702,7 +702,7 @@ function isValidFontFamily(fontFamily) {
702
702
  * Name: @galacean/effects-specification
703
703
  * Description: Galacean Effects JSON Specification
704
704
  * Author: Ant Group CO., Ltd.
705
- * Version: v1.3.0-alpha.0
705
+ * Version: v1.3.0
706
706
  */
707
707
 
708
708
  /*********************************************/
@@ -10073,10 +10073,23 @@ var EventSystem = /** @class */ (function () {
10073
10073
  var getTouchEventValue = function (event, x, y, dx, dy) {
10074
10074
  if (dx === void 0) { dx = 0; }
10075
10075
  if (dy === void 0) { dy = 0; }
10076
- var _a = _this.target, width = _a.width, height = _a.height;
10077
- var ts = performance.now();
10078
10076
  var vx = 0;
10079
10077
  var vy = 0;
10078
+ var ts = performance.now();
10079
+ if (!_this.target) {
10080
+ logger.error('Trigger TouchEvent after EventSystem is disposed');
10081
+ return {
10082
+ x: x,
10083
+ y: y,
10084
+ vx: 0,
10085
+ vy: vy,
10086
+ dx: dx,
10087
+ dy: dy,
10088
+ ts: ts,
10089
+ width: 0, height: 0, origin: event,
10090
+ };
10091
+ }
10092
+ var _a = _this.target, width = _a.width, height = _a.height;
10080
10093
  if (lastTouch) {
10081
10094
  var dt = ts - lastTouch.ts;
10082
10095
  vx = ((dx - lastTouch.dx) / dt) || 0;
@@ -13611,10 +13624,13 @@ var InteractVFXItem = /** @class */ (function (_super) {
13611
13624
  var dragEvent;
13612
13625
  var handlerMap = {
13613
13626
  touchstart: function (event) {
13614
- var _a;
13627
+ var _a, _b;
13628
+ if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13629
+ return;
13630
+ }
13615
13631
  _this.dragEvent = null;
13616
13632
  _this.bouncingArg = null;
13617
- var camera = (_a = _this.composition) === null || _a === void 0 ? void 0 : _a.camera;
13633
+ var camera = (_b = _this.composition) === null || _b === void 0 ? void 0 : _b.camera;
13618
13634
  dragEvent = {
13619
13635
  x: event.x,
13620
13636
  y: event.y,
@@ -13629,6 +13645,10 @@ var InteractVFXItem = /** @class */ (function (_super) {
13629
13645
  _this.bouncingArg = event;
13630
13646
  },
13631
13647
  touchend: function (event) {
13648
+ var _a;
13649
+ if (!((_a = _this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13650
+ return;
13651
+ }
13632
13652
  var bouncingArg = _this.bouncingArg;
13633
13653
  if (!shouldIgnoreBouncing(bouncingArg, 3) && bouncingArg) {
13634
13654
  var speed = 5;
@@ -13653,12 +13673,12 @@ var InteractVFXItem = /** @class */ (function (_super) {
13653
13673
  // OVERRIDE
13654
13674
  };
13655
13675
  InteractVFXItem.prototype.handleDragMove = function (evt, event) {
13656
- var _a, _b;
13657
- if (!(evt && evt.cameraParam) || !this.composition) {
13676
+ var _a, _b, _c;
13677
+ if (!(evt && evt.cameraParam) || !((_a = this.composition) === null || _a === void 0 ? void 0 : _a.interactive)) {
13658
13678
  return;
13659
13679
  }
13660
13680
  var options = this.ui.options;
13661
- var _c = evt.cameraParam, position = _c.position, fov = _c.fov;
13681
+ var _d = evt.cameraParam, position = _d.position, fov = _d.fov;
13662
13682
  var dy = event.dy;
13663
13683
  var dx = event.dx * event.width / event.height;
13664
13684
  var depth = position[2];
@@ -13668,17 +13688,17 @@ var InteractVFXItem = /** @class */ (function (_super) {
13668
13688
  var nx = position[0] - width;
13669
13689
  var ny = position[1] - height;
13670
13690
  if (options.dxRange) {
13671
- var _d = __read$3(options.dxRange, 2), min = _d[0], max = _d[1];
13691
+ var _e = __read$3(options.dxRange, 2), min = _e[0], max = _e[1];
13672
13692
  nx = clamp$1(nx, min, max);
13673
13693
  if (nx !== min && nx !== max && min !== max) {
13674
- (_a = event.origin) === null || _a === void 0 ? void 0 : _a.preventDefault();
13694
+ (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13675
13695
  }
13676
13696
  }
13677
13697
  if (options.dyRange) {
13678
- var _e = __read$3(options.dyRange, 2), min = _e[0], max = _e[1];
13698
+ var _f = __read$3(options.dyRange, 2), min = _f[0], max = _f[1];
13679
13699
  ny = clamp$1(ny, min, max);
13680
13700
  if (ny !== min && ny !== max && min !== max) {
13681
- (_b = event.origin) === null || _b === void 0 ? void 0 : _b.preventDefault();
13701
+ (_c = event.origin) === null || _c === void 0 ? void 0 : _c.preventDefault();
13682
13702
  }
13683
13703
  }
13684
13704
  this.composition.camera.position = new Vector3(nx, ny, depth);
@@ -21883,7 +21903,7 @@ var filters = {
21883
21903
  * Name: @galacean/effects-specification
21884
21904
  * Description: Galacean Effects JSON Specification
21885
21905
  * Author: Ant Group CO., Ltd.
21886
- * Version: v1.3.0-alpha.0
21906
+ * Version: v1.3.0
21887
21907
  */
21888
21908
 
21889
21909
  /*********************************************/
@@ -25027,6 +25047,7 @@ var Composition = /** @class */ (function () {
25027
25047
  this.camera = new Camera(this.name, __assign$1(__assign$1({}, sourceContent === null || sourceContent === void 0 ? void 0 : sourceContent.camera), { aspect: width / height }));
25028
25048
  this.url = scene.url;
25029
25049
  this.assigned = true;
25050
+ this.interactive = true;
25030
25051
  this.onPlayerPause = onPlayerPause;
25031
25052
  this.onMessageItem = onMessageItem;
25032
25053
  this.onEnd = onEnd;
@@ -25406,7 +25427,7 @@ var Composition = /** @class */ (function () {
25406
25427
  * @param options - 最大求交数和求交时的回调
25407
25428
  */
25408
25429
  Composition.prototype.hitTest = function (x, y, force, options) {
25409
- if (this.isDestroyed) {
25430
+ if (this.isDestroyed || !this.interactive) {
25410
25431
  return [];
25411
25432
  }
25412
25433
  var regions = [];