@galacean/effects-core 2.0.0-alpha.31 → 2.0.0-alpha.33

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,6 +1,7 @@
1
1
  import * as spec from '@galacean/effects-specification';
2
2
  import type { Ray } from '@galacean/effects-math/es/core/ray';
3
3
  import type { Vector3 } from '@galacean/effects-math/es/core/vector3';
4
+ import type { Matrix4 } from '@galacean/effects-math/es/core/matrix4';
4
5
  import { Camera } from './camera';
5
6
  import { CompositionComponent } from './comp-vfx-item';
6
7
  import { CompositionSourceManager } from './composition-source-manager';
@@ -13,7 +14,8 @@ import type { Texture } from './texture';
13
14
  import type { Disposable, LostHandler } from './utils';
14
15
  import type { VFXItemProps } from './vfx-item';
15
16
  import { VFXItem } from './vfx-item';
16
- import { type Matrix4 } from '@galacean/effects-math/es/core';
17
+ import type { CompositionEvent } from './events';
18
+ import { EventEmitter } from './events';
17
19
  import type { PostProcessVolume } from './components/post-process-volume';
18
20
  export interface CompositionStatistic {
19
21
  loadTime: number;
@@ -45,10 +47,7 @@ export interface CompositionProps {
45
47
  reusable?: boolean;
46
48
  baseRenderOrder?: number;
47
49
  renderer: Renderer;
48
- onPlayerPause?: (item: VFXItem) => void;
49
- onItemClicked?: (item: VFXItem) => void;
50
- onMessageItem?: (item: MessageItem) => void;
51
- onEnd?: (composition: Composition) => void;
50
+ handleItemMessage: (message: MessageItem) => void;
52
51
  event?: EventSystem;
53
52
  width: number;
54
53
  height: number;
@@ -59,7 +58,7 @@ export interface CompositionProps {
59
58
  * 合成中包含了相关的 Item 元素,支持对 Item 元素的创建、更新和销毁。
60
59
  * 也负责 Item 相关的动画播放控制,和持有渲染帧数据。
61
60
  */
62
- export declare class Composition implements Disposable, LostHandler {
61
+ export declare class Composition extends EventEmitter<CompositionEvent<Composition>> implements Disposable, LostHandler {
63
62
  renderer: Renderer;
64
63
  /**
65
64
  * 当前帧的渲染数据对象
@@ -93,27 +92,6 @@ export declare class Composition implements Disposable, LostHandler {
93
92
  */
94
93
  interactive: boolean;
95
94
  compositionSourceManager: CompositionSourceManager;
96
- /**
97
- * 合成结束行为是 spec.END_BEHAVIOR_PAUSE 或 spec.END_BEHAVIOR_PAUSE_AND_DESTROY 时执行的回调
98
- * @internal
99
- */
100
- onPlayerPause?: (item: VFXItem) => void;
101
- /**
102
- * 单个合成结束时的回调
103
- */
104
- onEnd?: (composition: Composition) => void;
105
- /**
106
- * 合成中消息元素创建/销毁时触发的回调
107
- */
108
- onMessageItem?: (item: MessageItem) => void;
109
- /**
110
- * 合成中元素点击时触发的回调
111
- * 注意:此接口随时可能下线,请务使用!
112
- * @since 1.6.0
113
- * @ignore
114
- * @deprecated
115
- */
116
- onItemClicked?: (data: CompItemClickedData) => void;
117
95
  /**
118
96
  * 合成id
119
97
  */
@@ -196,6 +174,10 @@ export declare class Composition implements Disposable, LostHandler {
196
174
  private paused;
197
175
  private lastVideoUpdateTime;
198
176
  private readonly texInfo;
177
+ /**
178
+ * 合成中消息元素创建/销毁时触发的回调
179
+ */
180
+ private handleItemMessage;
199
181
  /**
200
182
  * Composition 构造函数
201
183
  * @param props - composition 的创建参数
@@ -305,23 +287,14 @@ export declare class Composition implements Disposable, LostHandler {
305
287
  protected reset(): void;
306
288
  prepareRender(): void;
307
289
  protected gatherRendererComponent(vfxItem: VFXItem, renderFrame: RenderFrame): void;
308
- /**
309
- * 是否合成需要重新播放
310
- * @returns 重新播放合成标志位
311
- */
312
- private shouldRestart;
313
- /**
314
- * 是否合成需要销毁
315
- * @returns 销毁合成标志位
316
- */
317
- private shouldDispose;
318
290
  /**
319
291
  * 合成更新,针对所有 item 的更新
320
292
  * @param deltaTime - 更新的时间步长
321
293
  * @param skipRender - 是否需要渲染
322
294
  */
323
- update(deltaTime: number, skipRender?: boolean): void;
295
+ update(deltaTime: number): void;
324
296
  private toLocalTime;
297
+ private shouldDispose;
325
298
  private getUpdateTime;
326
299
  private callStart;
327
300
  private callUpdate;
@@ -340,12 +313,16 @@ export declare class Composition implements Disposable, LostHandler {
340
313
  * 更新相机
341
314
  * @override
342
315
  */
343
- updateCamera(): void;
316
+ private updateCamera;
344
317
  /**
345
318
  * 插件更新,来自 CompVFXItem 的更新调用
346
319
  * @param deltaTime - 更新的时间步长
347
320
  */
348
- updatePluginLoaders(deltaTime: number): void;
321
+ private updatePluginLoaders;
322
+ /**
323
+ * 更新主合成组件
324
+ */
325
+ private updateRootComposition;
349
326
  /**
350
327
  * 通过名称获取元素
351
328
  * @param name - 元素名称
@@ -1,10 +1,12 @@
1
1
  import type * as spec from '@galacean/effects-specification';
2
2
  import type { Engine } from './engine';
3
+ import type { ItemEvent } from './events';
4
+ import { EventEmitter } from './events';
3
5
  /**
4
6
  * @since 2.0.0
5
7
  * @internal
6
8
  */
7
- export declare abstract class EffectsObject {
9
+ export declare abstract class EffectsObject extends EventEmitter<ItemEvent> {
8
10
  engine: Engine;
9
11
  static is(obj: unknown): obj is EffectsObject;
10
12
  protected guid: string;
@@ -0,0 +1,46 @@
1
+ export type EventEmitterListener<P extends any[]> = (...callbackArgs: P) => void;
2
+ /**
3
+ * 事件监听器选项
4
+ */
5
+ export type EventEmitterOptions = {
6
+ /**
7
+ * 是否只监听一次
8
+ */
9
+ once?: boolean;
10
+ };
11
+ export declare class EventEmitter<T extends Record<string, any[]>> {
12
+ private listeners;
13
+ /**
14
+ * 移除事件监听器
15
+ * @param eventName - 事件名称
16
+ * @param listener - 事件监听器
17
+ * @returns
18
+ */
19
+ off: <E extends keyof T & string>(eventName: E, listener: EventEmitterListener<T[E]>) => void;
20
+ /**
21
+ * 监听事件
22
+ * @param eventName - 事件名称
23
+ * @param listener - 事件监听器
24
+ * @param options - 事件监听器选项
25
+ * @returns
26
+ */
27
+ on: <E extends keyof T & string>(eventName: E, listener: EventEmitterListener<T[E]>, options?: EventEmitterOptions) => () => void;
28
+ /**
29
+ * 一次性监听事件
30
+ * @param eventName - 事件名称
31
+ * @param listener - 事件监听器
32
+ */
33
+ once: <E extends keyof T & string>(eventName: E, listener: EventEmitterListener<T[E]>) => void;
34
+ /**
35
+ * 触发事件
36
+ * @param eventName - 事件名称
37
+ * @param args - 事件参数
38
+ */
39
+ emit: <E extends keyof T & string>(eventName: E, ...args: T[E]) => void;
40
+ /**
41
+ * 获取事件名称对应的所有监听器
42
+ * @param eventName - 事件名称
43
+ * @returns - 返回事件名称对应的所有监听器
44
+ */
45
+ getListeners: <E extends keyof T & string>(eventName: E) => EventEmitterListener<T[E]>[];
46
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './event-emitter';
@@ -0,0 +1,37 @@
1
+ import type { MessageItem } from '../composition';
2
+ import type { Region } from '../plugins';
3
+ /**
4
+ * Item 可以绑定的事件
5
+ */
6
+ export type ItemEvent = {
7
+ /**
8
+ * 元素点击事件
9
+ */
10
+ ['click']: [region: Region];
11
+ /**
12
+ * 元素消息事件(元素创建/销毁时触发)
13
+ */
14
+ ['message']: [message: Omit<MessageItem, 'compositionId'>];
15
+ };
16
+ /**
17
+ * Compositio 可以绑定的事件
18
+ */
19
+ export type CompositionEvent<C> = {
20
+ /**
21
+ * 合成点击事件
22
+ */
23
+ ['click']: [
24
+ clickInfo: Region & {
25
+ compositionName: string;
26
+ compositionId: string;
27
+ }
28
+ ];
29
+ /**
30
+ * 合成结束事件
31
+ * 合成行为为循环时每次循环结束都会触发
32
+ * 合成行为为销毁/冻结时只会触发一次
33
+ */
34
+ ['end']: [endInfo: {
35
+ composition: C;
36
+ }];
37
+ };
package/dist/index.d.ts CHANGED
@@ -14,7 +14,7 @@ export * from './decorators';
14
14
  export * from './downloader';
15
15
  export * from './effects-object';
16
16
  export * from './engine';
17
- export { ensureFixedNumber, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, normalizeColor } from './fallback';
17
+ export { ensureFixedNumber, getStandardComposition, getStandardImage, getStandardItem, getStandardJSON, normalizeColor, } from './fallback';
18
18
  export * from './gl';
19
19
  export * from './material';
20
20
  export * from './math';
@@ -35,4 +35,5 @@ export * from './vfx-item';
35
35
  export * from './binary-asset';
36
36
  export * from './effects-object';
37
37
  export * from './effects-package';
38
+ export * from './events';
38
39
  export declare const version: string;