@zephyr3d/scene 0.9.11 → 0.9.12

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,19 +1,19 @@
1
1
  import { Observable } from '@zephyr3d/base';
2
2
 
3
- /**
4
- * Serializable animation timeline definition.
5
- * @public
3
+ /**
4
+ * Serializable animation timeline definition.
5
+ * @public
6
6
  */ class AnimationTimeline {
7
- /**
8
- * Root step sequence executed by runners created from this timeline.
7
+ /**
8
+ * Root step sequence executed by runners created from this timeline.
9
9
  */ steps;
10
- /**
11
- * Event responses declared on this timeline.
10
+ /**
11
+ * Event responses declared on this timeline.
12
12
  */ responses;
13
- /**
14
- * Create a timeline from a definition object or a root step array.
15
- *
16
- * @param definition - Timeline definition, or a shorthand array used as the root steps.
13
+ /**
14
+ * Create a timeline from a definition object or a root step array.
15
+ *
16
+ * @param definition - Timeline definition, or a shorthand array used as the root steps.
17
17
  */ constructor(definition){
18
18
  if (Array.isArray(definition)) {
19
19
  this.steps = definition;
@@ -23,28 +23,28 @@ import { Observable } from '@zephyr3d/base';
23
23
  this.responses = definition.responses ?? [];
24
24
  }
25
25
  }
26
- /**
27
- * Create a runtime runner for this timeline.
28
- *
29
- * @param animationSet - Animation set used to create and update playbacks.
30
- * @returns A new stopped runner bound to this timeline and animation set.
26
+ /**
27
+ * Create a runtime runner for this timeline.
28
+ *
29
+ * @param animationSet - Animation set used to create and update playbacks.
30
+ * @returns A new stopped runner bound to this timeline and animation set.
31
31
  */ createRunner(animationSet) {
32
32
  return new AnimationTimelineRunner(animationSet, this);
33
33
  }
34
34
  }
35
- /**
36
- * Runtime interpreter for an AnimationTimeline.
37
- *
38
- * The interpreter is a synchronous frame-stack state machine advanced by {@link AnimationTimelineRunner.tick}, which is
39
- * driven by `AnimationSet.update(dt)` on the same logical clock as the animations. There is no
40
- * `async`/`await` in the control flow, so the runtime state can be serialized and replayed.
41
- * @public
35
+ /**
36
+ * Runtime interpreter for an AnimationTimeline.
37
+ *
38
+ * The interpreter is a synchronous frame-stack state machine advanced by {@link AnimationTimelineRunner.tick}, which is
39
+ * driven by `AnimationSet.update(dt)` on the same logical clock as the animations. There is no
40
+ * `async`/`await` in the control flow, so the runtime state can be serialized and replayed.
41
+ * @public
42
42
  */ class AnimationTimelineRunner extends Observable {
43
- /**
44
- * Animation set used to start, stop, and query animation playbacks.
43
+ /**
44
+ * Animation set used to start, stop, and query animation playbacks.
45
45
  */ animationSet;
46
- /**
47
- * Timeline definition interpreted by this runner.
46
+ /**
47
+ * Timeline definition interpreted by this runner.
48
48
  */ timeline;
49
49
  _stack;
50
50
  _concurrent;
@@ -59,11 +59,11 @@ import { Observable } from '@zephyr3d/base';
59
59
  /** Ids of playbacks owned by concurrent (keep-active) branches; preserved across main-flow stops. */ _concurrentPlaybackIds;
60
60
  /** Marker/frame crossings observed since the last tick, keyed by playback id. */ _crossedMarkers;
61
61
  _crossedFrames;
62
- /**
63
- * Create a stopped runner for a timeline.
64
- *
65
- * @param animationSet - Animation set that owns clips and playbacks referenced by the timeline.
66
- * @param timeline - Timeline definition to interpret.
62
+ /**
63
+ * Create a stopped runner for a timeline.
64
+ *
65
+ * @param animationSet - Animation set that owns clips and playbacks referenced by the timeline.
66
+ * @param timeline - Timeline definition to interpret.
67
67
  */ constructor(animationSet, timeline){
68
68
  super();
69
69
  this.animationSet = animationSet;
@@ -82,10 +82,10 @@ import { Observable } from '@zephyr3d/base';
82
82
  this._crossedMarkers = new Map();
83
83
  this._crossedFrames = new Map();
84
84
  }
85
- /**
86
- * Playback currently referenced by the active main-flow scope.
87
- *
88
- * @returns The current playback, or null when the main flow has no active playback reference.
85
+ /**
86
+ * Playback currently referenced by the active main-flow scope.
87
+ *
88
+ * @returns The current playback, or null when the main flow has no active playback reference.
89
89
  */ get currentPlayback() {
90
90
  const scope = this.activeScope();
91
91
  if (!scope?.currentPlaybackId) {
@@ -93,24 +93,24 @@ import { Observable } from '@zephyr3d/base';
93
93
  }
94
94
  return this._ownedPlaybacks.get(scope.currentPlaybackId) ?? null;
95
95
  }
96
- /**
97
- * Whether this runner is stopped.
98
- *
99
- * @returns True when the runner is stopped; otherwise false.
96
+ /**
97
+ * Whether this runner is stopped.
98
+ *
99
+ * @returns True when the runner is stopped; otherwise false.
100
100
  */ get stopped() {
101
101
  return this._stopped;
102
102
  }
103
- /**
104
- * Playback id for the most recent playback that completed naturally.
105
- *
106
- * @returns The playback id, or null when no owned playback has completed.
103
+ /**
104
+ * Playback id for the most recent playback that completed naturally.
105
+ *
106
+ * @returns The playback id, or null when no owned playback has completed.
107
107
  */ get lastCompletedPlaybackId() {
108
108
  return this._lastCompletedPlaybackId;
109
109
  }
110
- /**
111
- * Start or restart the runner from the beginning of the timeline.
112
- *
113
- * @returns This runner for chaining.
110
+ /**
111
+ * Start or restart the runner from the beginning of the timeline.
112
+ *
113
+ * @returns This runner for chaining.
114
114
  */ start() {
115
115
  this._stopped = false;
116
116
  this._stack = [
@@ -126,11 +126,11 @@ import { Observable } from '@zephyr3d/base';
126
126
  this.flush();
127
127
  return this;
128
128
  }
129
- /**
130
- * Stop the runner and all playbacks it owns.
131
- *
132
- * @param options - Optional stop behavior applied to owned playbacks.
133
- * @returns This runner for chaining.
129
+ /**
130
+ * Stop the runner and all playbacks it owns.
131
+ *
132
+ * @param options - Optional stop behavior applied to owned playbacks.
133
+ * @returns This runner for chaining.
134
134
  */ stop(options) {
135
135
  const wasStopped = this._stopped;
136
136
  this._stopped = true;
@@ -159,13 +159,13 @@ import { Observable } from '@zephyr3d/base';
159
159
  }
160
160
  return this;
161
161
  }
162
- /**
163
- * Append a batch of steps to run after the main stack drains.
164
- *
165
- * If the runner has already completed, enqueueing steps revives it and registers it for ticking.
166
- *
167
- * @param steps - Steps to run as the next queued batch.
168
- * @returns void
162
+ /**
163
+ * Append a batch of steps to run after the main stack drains.
164
+ *
165
+ * If the runner has already completed, enqueueing steps revives it and registers it for ticking.
166
+ *
167
+ * @param steps - Steps to run as the next queued batch.
168
+ * @returns void
169
169
  */ enqueue(steps) {
170
170
  if (steps.length === 0) {
171
171
  return;
@@ -179,13 +179,13 @@ import { Observable } from '@zephyr3d/base';
179
179
  }
180
180
  this.flush();
181
181
  }
182
- /**
183
- * Run `steps` concurrently with the current control flow (a true parallel branch). Unlike
184
- * {@link AnimationTimelineRunner.enqueue}, these do not wait for the main stack to drain.
185
- *
186
- * @param steps - Steps to run immediately in an independent concurrent branch.
187
- * @returns void
188
- * @public
182
+ /**
183
+ * Run `steps` concurrently with the current control flow (a true parallel branch). Unlike
184
+ * {@link AnimationTimelineRunner.enqueue}, these do not wait for the main stack to drain.
185
+ *
186
+ * @param steps - Steps to run immediately in an independent concurrent branch.
187
+ * @returns void
188
+ * @public
189
189
  */ runConcurrent(steps) {
190
190
  if (steps.length === 0) {
191
191
  return;
@@ -199,15 +199,15 @@ import { Observable } from '@zephyr3d/base';
199
199
  }
200
200
  this.flush();
201
201
  }
202
- /**
203
- * Dispatch an event to this runner.
204
- *
205
- * Waiting `waitEvent` frames consume matching events first. If no waiter consumes the event,
206
- * the timeline response table is evaluated.
207
- *
208
- * @param event - Event name to dispatch.
209
- * @param payload - Optional payload returned in the result.
210
- * @returns The resolved handling result for the event.
202
+ /**
203
+ * Dispatch an event to this runner.
204
+ *
205
+ * Waiting `waitEvent` frames consume matching events first. If no waiter consumes the event,
206
+ * the timeline response table is evaluated.
207
+ *
208
+ * @param event - Event name to dispatch.
209
+ * @param payload - Optional payload returned in the result.
210
+ * @returns The resolved handling result for the event.
211
211
  */ dispatch(event, payload) {
212
212
  // A waiting `waitEvent` frame consumes the event; flush advances past it synchronously.
213
213
  if (this.hasWaiterFor(event)) {
@@ -288,13 +288,13 @@ import { Observable } from '@zephyr3d/base';
288
288
  payload
289
289
  };
290
290
  }
291
- /**
292
- * Run pending non-blocking work synchronously (a zero-delta tick), without advancing any
293
- * time-based waits. Lets `start()`/`dispatch()` take effect immediately while keeping all
294
- * runtime state in the serializable frame stack.
295
- *
296
- * @returns This runner for chaining.
297
- * @public
291
+ /**
292
+ * Run pending non-blocking work synchronously (a zero-delta tick), without advancing any
293
+ * time-based waits. Lets `start()`/`dispatch()` take effect immediately while keeping all
294
+ * runtime state in the serializable frame stack.
295
+ *
296
+ * @returns This runner for chaining.
297
+ * @public
298
298
  */ flush() {
299
299
  // Guard against re-entrancy: an `emit` listener firing during a tick may dispatch again.
300
300
  if (!this._ticking) {
@@ -302,12 +302,12 @@ import { Observable } from '@zephyr3d/base';
302
302
  }
303
303
  return this;
304
304
  }
305
- /**
306
- * Advance the timeline by `deltaInSeconds`. Called by `AnimationSet.update`.
307
- *
308
- * @param deltaInSeconds - Elapsed time in seconds for this tick.
309
- * @returns void
310
- * @public
305
+ /**
306
+ * Advance the timeline by `deltaInSeconds`. Called by `AnimationSet.update`.
307
+ *
308
+ * @param deltaInSeconds - Elapsed time in seconds for this tick.
309
+ * @returns void
310
+ * @public
311
311
  */ tick(deltaInSeconds) {
312
312
  if (this._stopped && this._queued.length === 0) {
313
313
  return;
@@ -352,11 +352,11 @@ import { Observable } from '@zephyr3d/base';
352
352
  this.dispatchEvent('complete', this);
353
353
  }
354
354
  }
355
- /**
356
- * Export the runtime state as plain data.
357
- *
358
- * @returns A serializable snapshot of the runner state.
359
- * @public
355
+ /**
356
+ * Export the runtime state as plain data.
357
+ *
358
+ * @returns A serializable snapshot of the runner state.
359
+ * @public
360
360
  */ serialize() {
361
361
  return {
362
362
  stack: this._stack.map((frame)=>this.cloneFrame(frame)),
@@ -369,17 +369,17 @@ import { Observable } from '@zephyr3d/base';
369
369
  stopped: this._stopped
370
370
  };
371
371
  }
372
- /**
373
- * Restore runtime state previously produced by {@link AnimationTimelineRunner.serialize}.
374
- *
375
- * Re-create the relevant active playbacks on the AnimationSet before calling this so that
376
- * playback-bound frames (play-wait, waitMarker, waitFrame) can re-attach by id.
377
- *
378
- * @param animationSet - Animation set containing any live playbacks referenced by the state.
379
- * @param timeline - Timeline definition to bind to the restored runner.
380
- * @param state - Serialized state previously returned by {@link AnimationTimelineRunner.serialize}.
381
- * @returns A runner restored to the supplied runtime state.
382
- * @public
372
+ /**
373
+ * Restore runtime state previously produced by {@link AnimationTimelineRunner.serialize}.
374
+ *
375
+ * Re-create the relevant active playbacks on the AnimationSet before calling this so that
376
+ * playback-bound frames (play-wait, waitMarker, waitFrame) can re-attach by id.
377
+ *
378
+ * @param animationSet - Animation set containing any live playbacks referenced by the state.
379
+ * @param timeline - Timeline definition to bind to the restored runner.
380
+ * @param state - Serialized state previously returned by {@link AnimationTimelineRunner.serialize}.
381
+ * @returns A runner restored to the supplied runtime state.
382
+ * @public
383
383
  */ static deserialize(animationSet, timeline, state) {
384
384
  const runner = new AnimationTimelineRunner(animationSet, timeline);
385
385
  runner._stack = state.stack.map((frame)=>runner.cloneFrame(frame));
@@ -449,15 +449,15 @@ import { Observable } from '@zephyr3d/base';
449
449
  }
450
450
  return null;
451
451
  }
452
- /**
453
- * Advance a frame stack in place. The top frame runs until it blocks or completes; completed
454
- * frames pop and the parent sequence advances. Returns when the stack blocks or empties.
452
+ /**
453
+ * Advance a frame stack in place. The top frame runs until it blocks or completes; completed
454
+ * frames pop and the parent sequence advances. Returns when the stack blocks or empties.
455
455
  */ tickFrames(stack, deltaInSeconds) {
456
456
  this.tickFramesWithLeftover(stack, deltaInSeconds);
457
457
  }
458
- /**
459
- * Same as {@link AnimationTimelineRunner.tickFrames} but returns the time left unconsumed when the stack drains
460
- * completely (so a parent sequence can hand it to its next step).
458
+ /**
459
+ * Same as {@link AnimationTimelineRunner.tickFrames} but returns the time left unconsumed when the stack drains
460
+ * completely (so a parent sequence can hand it to its next step).
461
461
  */ tickFramesWithLeftover(stack, deltaInSeconds) {
462
462
  let guard = 0;
463
463
  while(stack.length > 0){
@@ -568,8 +568,8 @@ import { Observable } from '@zephyr3d/base';
568
568
  status: 'pop'
569
569
  };
570
570
  }
571
- /**
572
- * Execute a non-blocking step immediately and return null, or return a frame to block on.
571
+ /**
572
+ * Execute a non-blocking step immediately and return null, or return a frame to block on.
573
573
  */ beginStep(step, scopeFrame) {
574
574
  const scope = scopeFrame.scope;
575
575
  switch(step.type){
@@ -776,10 +776,10 @@ import { Observable } from '@zephyr3d/base';
776
776
  this._concurrentPlaybackIds.delete(playback.id);
777
777
  this.forgetPlaybackRefs(playback.id);
778
778
  }
779
- /**
780
- * Cleanup when an owned playback ends (externally or naturally). Only touches runner-local
781
- * bookkeeping, so it is safe to run inside `AnimationSet.update`'s playback loop. Frames blocked
782
- * on this playback observe its absence on the next tick and unblock.
779
+ /**
780
+ * Cleanup when an owned playback ends (externally or naturally). Only touches runner-local
781
+ * bookkeeping, so it is safe to run inside `AnimationSet.update`'s playback loop. Frames blocked
782
+ * on this playback observe its absence on the next tick and unblock.
783
783
  */ onPlaybackEnd = (event)=>{
784
784
  const playback = this._ownedPlaybacks.get(event.playback.id);
785
785
  if (playback) {