@haiyue/extensions 0.1.0 → 0.2.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.
- package/README.md +25 -0
- package/dist/animation/Animation2DComponent.d.ts +18 -0
- package/dist/animation/Animation2DExtensionRegistry.d.ts +7 -0
- package/dist/animation/Animation2DRenderSystem.d.ts +6 -0
- package/dist/animation/Animation2DRuntime.d.ts +6 -2
- package/dist/animation/AnimationTextRasterizer.d.ts +4 -0
- package/dist/animation/AnimationVisual2D.d.ts +58 -2
- package/dist/animation/interaction/InteractionRuntime.d.ts +83 -0
- package/dist/animation/interaction/runtime-types.d.ts +257 -0
- package/dist/animation.d.ts +3 -1
- package/dist/animation.js +551 -59
- package/dist/animation3d.js +1 -1
- package/dist/canvas-text.js +1 -1
- package/dist/chunks/2d-ui-animation-2d.generated-FpziAeGJ.js +4 -0
- package/dist/chunks/2d-ui-indexed-sprite.generated-DmKR0CC3.js +4 -0
- package/dist/chunks/Animation2DStateMachine-BHcA6Cu3.js +18212 -0
- package/dist/chunks/{AnimationStateMachineController-BIcAh-sT.js → AnimationStateMachineController-4sKaqh9E.js} +2 -2
- package/dist/chunks/AnimationVisual2D-8y3qp0_U.js +230 -0
- package/dist/chunks/{RenderSystem2DBase-DDT61dAu.js → RenderSystem2DBase-CF2s00vg.js} +2 -2
- package/dist/controls/VirtualJoystickControls.d.ts +46 -0
- package/dist/controls/contracts.d.ts +91 -0
- package/dist/controls.d.ts +2 -0
- package/dist/controls.js +358 -0
- package/dist/deformable-animation/runtime/DeformableMesh2DRuntimeExtension.d.ts +11 -0
- package/dist/deformable-animation/runtime/DeformableMesh2DSampler.d.ts +11 -0
- package/dist/deformable-animation.d.ts +5 -0
- package/dist/deformable-animation.js +316 -0
- package/dist/experimental-indexed-sprite.d.ts +5 -0
- package/dist/experimental-indexed-sprite.js +482 -0
- package/dist/gltf-worker-runtime.js +9 -9
- package/dist/hya-state-machine.js +3 -2
- package/dist/index.js +1 -1
- package/dist/indexed-sprite/AtlasLayout.d.ts +2 -0
- package/dist/indexed-sprite/IndexedSpriteRenderer.d.ts +23 -0
- package/dist/indexed-sprite/contracts.d.ts +89 -0
- package/dist/internal/2d-ui-shader-artifact.js +232 -23
- package/dist/ray-tracing/acceleration/bvh.d.ts +37 -0
- package/dist/ray-tracing/acceleration/index.d.ts +6 -0
- package/dist/ray-tracing/acceleration/pack.d.ts +152 -0
- package/dist/ray-tracing/acceleration/query.d.ts +4 -0
- package/dist/ray-tracing/acceleration/runtime.d.ts +30 -0
- package/dist/ray-tracing/acceleration/tlas.d.ts +4 -0
- package/dist/ray-tracing/acceleration/types.d.ts +165 -0
- package/dist/ray-tracing/denoise/index.d.ts +3 -0
- package/dist/ray-tracing/denoise/layout.d.ts +9 -0
- package/dist/ray-tracing/denoise/runtime.d.ts +23 -0
- package/dist/ray-tracing/denoise/types.d.ts +28 -0
- package/dist/ray-tracing/hybrid/contract.d.ts +2 -0
- package/dist/ray-tracing/hybrid/index.d.ts +5 -0
- package/dist/ray-tracing/hybrid/layout.d.ts +17 -0
- package/dist/ray-tracing/hybrid/plan.d.ts +2 -0
- package/dist/ray-tracing/hybrid/runtime.d.ts +31 -0
- package/dist/ray-tracing/hybrid/shaders/hybrid-artifact.generated.d.ts +625 -0
- package/dist/ray-tracing/hybrid/types.d.ts +144 -0
- package/dist/ray-tracing/lifecycle/device-recovery.d.ts +31 -0
- package/dist/ray-tracing/lifecycle/index.d.ts +2 -0
- package/dist/ray-tracing/lifecycle/types.d.ts +37 -0
- package/dist/ray-tracing/material/index.d.ts +2 -0
- package/dist/ray-tracing/material/pack.d.ts +5 -0
- package/dist/ray-tracing/material/types.d.ts +63 -0
- package/dist/ray-tracing/reference/index.d.ts +122 -0
- package/dist/ray-tracing/renderer/index.d.ts +7 -0
- package/dist/ray-tracing/renderer/layout.d.ts +20 -0
- package/dist/ray-tracing/renderer/plan.d.ts +2 -0
- package/dist/ray-tracing/renderer/reference.d.ts +17 -0
- package/dist/ray-tracing/renderer/runtime.d.ts +39 -0
- package/dist/ray-tracing/renderer/scene.d.ts +4 -0
- package/dist/ray-tracing/renderer/types.d.ts +115 -0
- package/dist/ray-tracing/sampling/index.d.ts +8 -0
- package/dist/ray-tracing/sampling/layout.d.ts +12 -0
- package/dist/ray-tracing/sampling/plan.d.ts +5 -0
- package/dist/ray-tracing/sampling/revision.d.ts +15 -0
- package/dist/ray-tracing/sampling/runtime.d.ts +44 -0
- package/dist/ray-tracing/sampling/sequence.d.ts +2 -0
- package/dist/ray-tracing/sampling/types.d.ts +96 -0
- package/dist/ray-tracing/scene/index.d.ts +41 -0
- package/dist/ray-tracing/traversal/index.d.ts +4 -0
- package/dist/ray-tracing/traversal/layout.d.ts +16 -0
- package/dist/ray-tracing/traversal/plan.d.ts +2 -0
- package/dist/ray-tracing/traversal/runtime.d.ts +25 -0
- package/dist/ray-tracing/traversal/types.d.ts +79 -0
- package/dist/ray-tracing/worker/client.d.ts +25 -0
- package/dist/ray-tracing/worker/index.d.ts +5 -0
- package/dist/ray-tracing/worker/runtime.d.ts +11 -0
- package/dist/ray-tracing/worker/serialization.d.ts +16 -0
- package/dist/ray-tracing/worker/source.d.ts +1 -0
- package/dist/ray-tracing/worker/types.d.ts +91 -0
- package/dist/ray-tracing.d.ts +17 -0
- package/dist/ray-tracing.js +7666 -0
- package/dist/spine.js +1 -1
- package/dist/tilemap.js +1 -1
- package/package.json +26 -23
- package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +0 -27
- package/dist/animation/Particle2DDescriptorAdapter.d.ts +0 -5
- package/dist/animation3d/Animation3DResource.d.ts +0 -28
- package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +0 -65
- package/dist/animation3d/hya/index.d.ts +0 -4
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +0 -81
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +0 -39
- package/dist/animation3d/runtime/integration/index.d.ts +0 -2
- package/dist/animation3d/runtime/mixer/Action.d.ts +0 -150
- package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +0 -6
- package/dist/animation3d/runtime/mixer/Mixer.d.ts +0 -59
- package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +0 -1
- package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +0 -24
- package/dist/animation3d/runtime/mixer/index.d.ts +0 -4
- package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +0 -1
- package/dist/animation3d/runtime/state-machine/index.d.ts +0 -6
- package/dist/benchmark.d.ts +0 -30
- package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +0 -4
- package/dist/chunks/Animation2DStateMachine-9IonguNa.js +0 -3245
- package/dist/gltf/GltfAccessorReader.d.ts +0 -7
- package/dist/gltf/GltfDracoDecoder.d.ts +0 -4
- package/dist/gltf/GltfLoaderErrors.d.ts +0 -4
- package/dist/gltf/GltfMaterialDescriptor.d.ts +0 -23
- package/dist/gltf/GltfMaterialLoader.d.ts +0 -6
- package/dist/gltf-worker-runtime.d.ts +0 -7
- package/dist/plugins/pluginUtils.d.ts +0 -20
- package/dist/plugins.d.ts +0 -6
- package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +0 -658
- package/dist/spine/Spine2DGpuRenderer.d.ts +0 -65
- package/dist/spine/Spine2DRuntime.d.ts +0 -103
- package/dist/spine/SpineAnimationBoneTimelines.d.ts +0 -8
- package/dist/spine/SpineFloatBuilder.d.ts +0 -15
- package/dist/spine/SpinePathConstraintSolver.d.ts +0 -32
- package/dist/spine/SpineSkeletonRuntime.d.ts +0 -185
- package/dist/spine/SpineSlotAnimation.d.ts +0 -17
- package/dist/spine/SpineTimelineRuntime.d.ts +0 -25
- package/dist/spine/SpineVertexBuilder.d.ts +0 -61
- package/dist/tilemap/Tilemap2DRenderer.d.ts +0 -24
- package/dist/utils/arrayAccess.d.ts +0 -4
- package/dist/utils/camera2d.d.ts +0 -12
- package/src/animation/Animation2DComponent.ts +0 -135
- package/src/animation/Animation2DExtensionRegistry.ts +0 -52
- package/src/animation/Animation2DRenderSystem.ts +0 -1026
- package/src/animation/Animation2DRuntime.ts +0 -1326
- package/src/animation/Animation2DStateMachine.ts +0 -39
- package/src/animation/Animation2DStateMachineComponent.ts +0 -228
- package/src/animation/Animation2DStateMachineRuntime.ts +0 -141
- package/src/animation/Animation2DStateMachineSystem.ts +0 -60
- package/src/animation/Animation2DStateMachineVisualRuntime.ts +0 -282
- package/src/animation/Animation2DSystem.ts +0 -72
- package/src/animation/AnimationAssetLoader.ts +0 -84
- package/src/animation/AnimationAudioClip.ts +0 -140
- package/src/animation/AnimationPathTessellator.ts +0 -691
- package/src/animation/AnimationTextRasterizer.ts +0 -340
- package/src/animation/AnimationVisual2D.ts +0 -153
- package/src/animation/HyaAnimation2DClipAdapter.ts +0 -845
- package/src/animation/Particle2DDescriptorAdapter.ts +0 -35
- package/src/animation/runtime/mixer/Action.ts +0 -876
- package/src/animation/runtime/mixer/Mixer.ts +0 -505
- package/src/animation/runtime/mixer/PoseBuffer.ts +0 -105
- package/src/animation/runtime/mixer/Sampler.ts +0 -252
- package/src/animation/runtime/mixer/Types.ts +0 -138
- package/src/animation/runtime/mixer/index.ts +0 -31
- package/src/animation-state-machine/AnimationStateMachine.ts +0 -146
- package/src/animation-state-machine/AnimationStateMachineChannels.ts +0 -116
- package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +0 -197
- package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +0 -503
- package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +0 -763
- package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +0 -987
- package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +0 -54
- package/src/animation-state-machine/runtime/index.ts +0 -47
- package/src/animation.ts +0 -33
- package/src/animation3d/Animation3DAction.ts +0 -73
- package/src/animation3d/Animation3DBinding.ts +0 -116
- package/src/animation3d/Animation3DClip.ts +0 -22
- package/src/animation3d/Animation3DError.ts +0 -34
- package/src/animation3d/Animation3DMixer.ts +0 -82
- package/src/animation3d/Animation3DPose.ts +0 -100
- package/src/animation3d/Animation3DPoseBuffer.ts +0 -85
- package/src/animation3d/Animation3DResource.ts +0 -49
- package/src/animation3d/Animation3DStateMachine.ts +0 -126
- package/src/animation3d/Animation3DStateMachineRuntime.ts +0 -191
- package/src/animation3d/Animation3DTrack.ts +0 -29
- package/src/animation3d/hya/HyaAnimation3DRuntime.ts +0 -756
- package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +0 -618
- package/src/animation3d/hya/HyaAnimation3DTypes.ts +0 -168
- package/src/animation3d/hya/index.ts +0 -10
- package/src/animation3d/index.ts +0 -76
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +0 -325
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +0 -158
- package/src/animation3d/runtime/integration/index.ts +0 -9
- package/src/animation3d/runtime/mixer/Action.ts +0 -833
- package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +0 -26
- package/src/animation3d/runtime/mixer/Mixer.ts +0 -562
- package/src/animation3d/runtime/mixer/PoseBuffer.ts +0 -1
- package/src/animation3d/runtime/mixer/TrackSampler.ts +0 -399
- package/src/animation3d/runtime/mixer/index.ts +0 -8
- package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +0 -4
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +0 -1
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +0 -1
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +0 -1
- package/src/animation3d/runtime/state-machine/index.ts +0 -45
- package/src/animation3d.ts +0 -5
- package/src/benchmark.ts +0 -168
- package/src/canvas-text/CanvasText2DRenderSystem.ts +0 -292
- package/src/canvas-text/CanvasTextComponent.ts +0 -47
- package/src/canvas-text.ts +0 -4
- package/src/experimental-gltf-worker.ts +0 -18
- package/src/experimental-spine-worker.ts +0 -9
- package/src/gltf/GltfAccessorReader.ts +0 -271
- package/src/gltf/GltfAnimation3DAdapter.ts +0 -680
- package/src/gltf/GltfAnimationRuntime.ts +0 -392
- package/src/gltf/GltfAssetWorkerClient.ts +0 -136
- package/src/gltf/GltfCompatibilityReport.ts +0 -214
- package/src/gltf/GltfConservativeBounds.ts +0 -219
- package/src/gltf/GltfDracoDecoder.ts +0 -251
- package/src/gltf/GltfExtensionAdapter.ts +0 -340
- package/src/gltf/GltfLoaderContract.ts +0 -333
- package/src/gltf/GltfLoaderErrors.ts +0 -59
- package/src/gltf/GltfMaterialDescriptor.ts +0 -134
- package/src/gltf/GltfMaterialEncoder.ts +0 -173
- package/src/gltf/GltfMaterialLoader.ts +0 -293
- package/src/gltf/GltfModelComponent.ts +0 -115
- package/src/gltf/GltfModelSystem.ts +0 -208
- package/src/gltf/GltfPlugin.ts +0 -84
- package/src/gltf/GltfSchema.ts +0 -229
- package/src/gltf/GltfUvSemanticPlanner.ts +0 -166
- package/src/gltf/gltfLoader.ts +0 -910
- package/src/gltf-animation3d.ts +0 -10
- package/src/gltf-worker-runtime.ts +0 -10
- package/src/gltf.ts +0 -56
- package/src/grid/Grid2DComponent.ts +0 -69
- package/src/grid.ts +0 -2
- package/src/hya-state-machine.ts +0 -19
- package/src/index.ts +0 -2
- package/src/plugins/pluginUtils.ts +0 -50
- package/src/plugins.ts +0 -6
- package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +0 -242
- package/src/shaders/generated/2d-ui-artifact.generated.ts +0 -867
- package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +0 -38
- package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +0 -41
- package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +0 -36
- package/src/spine/Spine2DComponent.ts +0 -168
- package/src/spine/Spine2DGpuRenderer.ts +0 -449
- package/src/spine/Spine2DRenderSystem.ts +0 -199
- package/src/spine/Spine2DRuntime.ts +0 -1529
- package/src/spine/SpineAnimationBoneTimelines.ts +0 -30
- package/src/spine/SpineAssetParser.ts +0 -20
- package/src/spine/SpineAssetWorkerClient.ts +0 -112
- package/src/spine/SpineAssetWorkerContract.ts +0 -4
- package/src/spine/SpineAtlasParser.ts +0 -127
- package/src/spine/SpineFloatBuilder.ts +0 -66
- package/src/spine/SpinePathConstraintSolver.ts +0 -582
- package/src/spine/SpinePlugin.ts +0 -76
- package/src/spine/SpineSkeletonRuntime.ts +0 -521
- package/src/spine/SpineSlotAnimation.ts +0 -195
- package/src/spine/SpineTimelineRuntime.ts +0 -453
- package/src/spine/SpineVertexBuilder.ts +0 -686
- package/src/spine.ts +0 -7
- package/src/tilemap/Tilemap2DComponent.ts +0 -232
- package/src/tilemap/Tilemap2DRenderSystem.ts +0 -58
- package/src/tilemap/Tilemap2DRenderer.ts +0 -289
- package/src/tilemap/TilemapPlugin.ts +0 -75
- package/src/tilemap.ts +0 -6
- package/src/tween/Tween2DComponent.ts +0 -83
- package/src/tween/Tween2DSystem.ts +0 -78
- package/src/tween.ts +0 -4
- package/src/types/earcut.d.ts +0 -7
- package/src/types/wgsl.d.ts +0 -4
- package/src/utils/RenderSystem2DBase.ts +0 -164
- package/src/utils/arrayAccess.ts +0 -17
- package/src/utils/camera2d.ts +0 -68
- package/src/utils/render2dGpu.ts +0 -132
- package/test/fixtures/gltf/animation-characterization.gltf +0 -344
|
@@ -1,505 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnimationStateMachineActionOptions,
|
|
3
|
-
AnimationStateMachineMixerPort,
|
|
4
|
-
} from '../../../animation-state-machine/runtime/AnimationStateMachineMixerPort.js';
|
|
5
|
-
import {
|
|
6
|
-
Animation2DActionRuntime,
|
|
7
|
-
type Animation2DActionOwner,
|
|
8
|
-
type Animation2DActionTrackRuntime,
|
|
9
|
-
} from './Action.js';
|
|
10
|
-
import { isNumericBinding, wrapAngle } from './Sampler.js';
|
|
11
|
-
import type {
|
|
12
|
-
Animation2DActionOptions,
|
|
13
|
-
Animation2DBinding,
|
|
14
|
-
Animation2DClip,
|
|
15
|
-
Animation2DMutablePose,
|
|
16
|
-
Animation2DPose,
|
|
17
|
-
} from './Types.js';
|
|
18
|
-
|
|
19
|
-
interface LayerAccumulator {
|
|
20
|
-
readonly layer: number;
|
|
21
|
-
readonly overrideSum: Float32Array;
|
|
22
|
-
readonly additiveSum: Float32Array;
|
|
23
|
-
overrideWeight: number;
|
|
24
|
-
rotationAnchor: number;
|
|
25
|
-
rotationAnchorSet: boolean;
|
|
26
|
-
dominantSet: boolean;
|
|
27
|
-
dominantValue: unknown;
|
|
28
|
-
dominantWeight: number;
|
|
29
|
-
dominantOrder: number;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
interface BindingAccumulator {
|
|
33
|
-
readonly binding: Animation2DBinding;
|
|
34
|
-
readonly result: Float32Array;
|
|
35
|
-
readonly base: Float32Array;
|
|
36
|
-
readonly layers: LayerAccumulator[];
|
|
37
|
-
readonly layersById: Map<number, LayerAccumulator>;
|
|
38
|
-
references: number;
|
|
39
|
-
active: boolean;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Format-independent 2D pose mixer and shared state-machine mixer port.
|
|
44
|
-
*
|
|
45
|
-
* Action/track/layer accumulators are retained across frames. Once actions
|
|
46
|
-
* and their masks/layers have been warmed, update/evaluate allocates no
|
|
47
|
-
* action- or property-proportional temporary objects.
|
|
48
|
-
*/
|
|
49
|
-
export class Animation2DMixerRuntime
|
|
50
|
-
implements Animation2DActionOwner, AnimationStateMachineMixerPort<Animation2DActionRuntime> {
|
|
51
|
-
private readonly _clips = new Map<string, Animation2DClip>();
|
|
52
|
-
private readonly _actions: Animation2DActionRuntime[] = [];
|
|
53
|
-
private readonly _actionsById = new Map<string, Animation2DActionRuntime>();
|
|
54
|
-
private readonly _accumulators = new Map<string, BindingAccumulator>();
|
|
55
|
-
private readonly _accumulatorList: BindingAccumulator[] = [];
|
|
56
|
-
private readonly _stateMachineLayers = new Map<string, number>();
|
|
57
|
-
private _destroyed = false;
|
|
58
|
-
private _time = 0;
|
|
59
|
-
private _timeScale = 1;
|
|
60
|
-
private _nextActionId = 1;
|
|
61
|
-
private _nextActionOrder = 0;
|
|
62
|
-
private _nextStateMachineLayer = 0;
|
|
63
|
-
|
|
64
|
-
constructor(clips: readonly Animation2DClip[] = []) {
|
|
65
|
-
for (let index = 0; index < clips.length; index++) this.registerClip(clips[index]!);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
get time(): number { return this._time; }
|
|
69
|
-
get timeScale(): number { return this._timeScale; }
|
|
70
|
-
set timeScale(value: number) {
|
|
71
|
-
this.assertActive();
|
|
72
|
-
if (!Number.isFinite(value)) {
|
|
73
|
-
throw new RangeError(`Animation2D mixer timeScale must be finite; received ${value}.`);
|
|
74
|
-
}
|
|
75
|
-
this._timeScale = value;
|
|
76
|
-
}
|
|
77
|
-
get actions(): readonly Animation2DActionRuntime[] { return this._actions; }
|
|
78
|
-
get liveBindingCount(): number { return this._accumulators.size; }
|
|
79
|
-
|
|
80
|
-
registerClip(clip: Animation2DClip): this {
|
|
81
|
-
this.assertActive();
|
|
82
|
-
const existing = this._clips.get(clip.id);
|
|
83
|
-
if (existing && existing !== clip) {
|
|
84
|
-
throw new RangeError(`Animation2D clip id "${clip.id}" is already registered.`);
|
|
85
|
-
}
|
|
86
|
-
this._clips.set(clip.id, clip);
|
|
87
|
-
return this;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
unregisterClip(clipId: string): boolean {
|
|
91
|
-
this.assertActive();
|
|
92
|
-
return this._clips.delete(clipId);
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
createAction(
|
|
96
|
-
clip: Animation2DClip,
|
|
97
|
-
options?: Animation2DActionOptions,
|
|
98
|
-
): Animation2DActionRuntime;
|
|
99
|
-
createAction(
|
|
100
|
-
clipId: string,
|
|
101
|
-
options: AnimationStateMachineActionOptions,
|
|
102
|
-
): Animation2DActionRuntime;
|
|
103
|
-
createAction(
|
|
104
|
-
source: Animation2DClip | string,
|
|
105
|
-
options: Animation2DActionOptions | AnimationStateMachineActionOptions = {},
|
|
106
|
-
): Animation2DActionRuntime {
|
|
107
|
-
this.assertActive();
|
|
108
|
-
const clip = typeof source === 'string' ? this._clips.get(source) : source;
|
|
109
|
-
if (!clip) throw new RangeError(`Animation2D clip "${String(source)}" is not registered.`);
|
|
110
|
-
const stateOptions = isStateMachineOptions(options) ? options : null;
|
|
111
|
-
const runtimeOptions = stateOptions ? null : options as Animation2DActionOptions;
|
|
112
|
-
const layer = stateOptions
|
|
113
|
-
? this._stateMachineLayer(stateOptions.layerId)
|
|
114
|
-
: runtimeOptions!.layer ?? 0;
|
|
115
|
-
const id = runtimeOptions?.id
|
|
116
|
-
? runtimeOptions.id
|
|
117
|
-
: `${clip.id}:${stateOptions?.stateId ?? 'action'}:${this._nextActionId++}`;
|
|
118
|
-
if (!id) throw new RangeError('Animation2D action id must not be empty.');
|
|
119
|
-
if (this._actionsById.has(id)) {
|
|
120
|
-
throw new RangeError(`Animation2D action id "${id}" already exists.`);
|
|
121
|
-
}
|
|
122
|
-
const actionOptions: Animation2DActionOptions = stateOptions
|
|
123
|
-
? {
|
|
124
|
-
id,
|
|
125
|
-
layer,
|
|
126
|
-
loop: stateOptions.loop,
|
|
127
|
-
blendMode: stateOptions.blendMode,
|
|
128
|
-
...(stateOptions.mask ? { mask: stateOptions.mask } : {}),
|
|
129
|
-
}
|
|
130
|
-
: { ...runtimeOptions!, id, layer };
|
|
131
|
-
const action = new Animation2DActionRuntime(
|
|
132
|
-
this,
|
|
133
|
-
clip,
|
|
134
|
-
id,
|
|
135
|
-
this._nextActionOrder++,
|
|
136
|
-
actionOptions,
|
|
137
|
-
);
|
|
138
|
-
for (let index = 0; index < action.runtimeTracks.length; index++) {
|
|
139
|
-
this._retainBinding(action.runtimeTracks[index]!.track.binding, layer);
|
|
140
|
-
}
|
|
141
|
-
this._actions.push(action);
|
|
142
|
-
this._actionsById.set(id, action);
|
|
143
|
-
return action;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
getAction(actionId: string): Animation2DActionRuntime | null {
|
|
147
|
-
this.assertActive();
|
|
148
|
-
return this._actionsById.get(actionId) ?? null;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
removeAction(action: Animation2DActionRuntime | string): boolean {
|
|
152
|
-
this.assertActive();
|
|
153
|
-
const runtime = typeof action === 'string' ? this._actionsById.get(action) : action;
|
|
154
|
-
if (!runtime || this._actionsById.get(runtime.id) !== runtime) return false;
|
|
155
|
-
const index = this._actions.indexOf(runtime);
|
|
156
|
-
if (index >= 0) this._actions.splice(index, 1);
|
|
157
|
-
this._actionsById.delete(runtime.id);
|
|
158
|
-
for (let trackIndex = 0; trackIndex < runtime.runtimeTracks.length; trackIndex++) {
|
|
159
|
-
this._releaseBinding(runtime.runtimeTracks[trackIndex]!.track.binding);
|
|
160
|
-
}
|
|
161
|
-
runtime.invalidate();
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
update(deltaSeconds: number, out: Animation2DMutablePose): Animation2DPose {
|
|
166
|
-
this.assertActive();
|
|
167
|
-
if (!Number.isFinite(deltaSeconds)) {
|
|
168
|
-
throw new RangeError(`Animation2D mixer delta must be finite; received ${deltaSeconds}.`);
|
|
169
|
-
}
|
|
170
|
-
const mixerDelta = deltaSeconds * this._timeScale;
|
|
171
|
-
this._time += mixerDelta;
|
|
172
|
-
out.reset(this._time);
|
|
173
|
-
this._advanceActions(mixerDelta, out);
|
|
174
|
-
this._evaluateInto(out);
|
|
175
|
-
return out.seal();
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
evaluate(out: Animation2DMutablePose): Animation2DPose {
|
|
179
|
-
this.assertActive();
|
|
180
|
-
out.reset(this._time);
|
|
181
|
-
for (let index = 0; index < this._actions.length; index++) {
|
|
182
|
-
this._actions[index]!.flushPendingEffects(out);
|
|
183
|
-
}
|
|
184
|
-
this._evaluateInto(out);
|
|
185
|
-
return out.seal();
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
setMixerTime(timeSeconds: number, out: Animation2DMutablePose): Animation2DPose {
|
|
189
|
-
this.assertActive();
|
|
190
|
-
if (!Number.isFinite(timeSeconds)) {
|
|
191
|
-
throw new RangeError(`Animation2D mixer time must be finite; received ${timeSeconds}.`);
|
|
192
|
-
}
|
|
193
|
-
const delta = timeSeconds - this._time;
|
|
194
|
-
this._time = timeSeconds;
|
|
195
|
-
out.reset(this._time);
|
|
196
|
-
this._advanceActions(delta, out);
|
|
197
|
-
this._evaluateInto(out);
|
|
198
|
-
return out.seal();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
play(action: Animation2DActionRuntime): void {
|
|
202
|
-
this._assertOwned(action);
|
|
203
|
-
action.play();
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
stop(action: Animation2DActionRuntime): void {
|
|
207
|
-
this._assertOwned(action);
|
|
208
|
-
action.stop();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
fade(action: Animation2DActionRuntime, targetWeight: number, durationSeconds: number): void {
|
|
212
|
-
this._assertOwned(action);
|
|
213
|
-
action.fadeTo(targetWeight, durationSeconds);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
setWeight(action: Animation2DActionRuntime, weight: number): void {
|
|
217
|
-
this._assertOwned(action);
|
|
218
|
-
action.weight = weight;
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
setTime(action: Animation2DActionRuntime, timeSeconds: number): void {
|
|
222
|
-
this._assertOwned(action);
|
|
223
|
-
action.synchronizeTime(timeSeconds);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
setTimeScale(action: Animation2DActionRuntime, timeScale: number): void {
|
|
227
|
-
this._assertOwned(action);
|
|
228
|
-
action.timeScale = timeScale;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
destroyAction(action: Animation2DActionRuntime): void {
|
|
232
|
-
this.removeAction(action);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
destroy(): void {
|
|
236
|
-
if (this._destroyed) return;
|
|
237
|
-
for (let index = 0; index < this._actions.length; index++) this._actions[index]!.invalidate();
|
|
238
|
-
this._actions.length = 0;
|
|
239
|
-
this._actionsById.clear();
|
|
240
|
-
this._accumulators.clear();
|
|
241
|
-
this._accumulatorList.length = 0;
|
|
242
|
-
this._clips.clear();
|
|
243
|
-
this._stateMachineLayers.clear();
|
|
244
|
-
this._destroyed = true;
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
assertActive(): void {
|
|
248
|
-
if (this._destroyed) throw new Error('Animation2D mixer has been destroyed.');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
private _advanceActions(mixerDelta: number, out: Animation2DMutablePose): void {
|
|
252
|
-
for (let index = 0; index < this._actions.length; index++) {
|
|
253
|
-
this._actions[index]!.advance(mixerDelta, out);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
private _evaluateInto(out: Animation2DMutablePose): void {
|
|
258
|
-
for (let index = 0; index < this._accumulatorList.length; index++) {
|
|
259
|
-
resetAccumulator(this._accumulatorList[index]!);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
for (let actionIndex = 0; actionIndex < this._actions.length; actionIndex++) {
|
|
263
|
-
const action = this._actions[actionIndex]!;
|
|
264
|
-
const weight = action.effectiveWeight;
|
|
265
|
-
if (weight <= 0) continue;
|
|
266
|
-
for (let trackIndex = 0; trackIndex < action.runtimeTracks.length; trackIndex++) {
|
|
267
|
-
const runtimeTrack = action.runtimeTracks[trackIndex]!;
|
|
268
|
-
const binding = runtimeTrack.track.binding;
|
|
269
|
-
if (!action.acceptsBinding(binding)) continue;
|
|
270
|
-
const accumulator = this._accumulators.get(binding.id);
|
|
271
|
-
if (!accumulator) continue;
|
|
272
|
-
let layer = accumulator.layersById.get(action.layer);
|
|
273
|
-
if (!layer) {
|
|
274
|
-
layer = createLayerAccumulator(binding, action.layer);
|
|
275
|
-
insertLayer(accumulator, layer);
|
|
276
|
-
}
|
|
277
|
-
accumulator.active = true;
|
|
278
|
-
const sampled = runtimeTrack.sampler.sample(action.time);
|
|
279
|
-
if (isNumericBinding(binding)) {
|
|
280
|
-
accumulateNumeric(
|
|
281
|
-
layer,
|
|
282
|
-
binding,
|
|
283
|
-
runtimeTrack,
|
|
284
|
-
sampled as Float32Array,
|
|
285
|
-
weight,
|
|
286
|
-
action.blendMode,
|
|
287
|
-
);
|
|
288
|
-
} else {
|
|
289
|
-
accumulateDominant(layer, sampled, weight, action.order);
|
|
290
|
-
}
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
for (let index = 0; index < this._accumulatorList.length; index++) {
|
|
295
|
-
const accumulator = this._accumulatorList[index]!;
|
|
296
|
-
if (!accumulator.active) continue;
|
|
297
|
-
if (isNumericBinding(accumulator.binding)) {
|
|
298
|
-
finalizeNumeric(accumulator);
|
|
299
|
-
out.writeNumeric(accumulator.binding, accumulator.result);
|
|
300
|
-
} else {
|
|
301
|
-
let hasValue = false;
|
|
302
|
-
let value: unknown;
|
|
303
|
-
for (let layerIndex = 0; layerIndex < accumulator.layers.length; layerIndex++) {
|
|
304
|
-
const layer = accumulator.layers[layerIndex]!;
|
|
305
|
-
if (!layer.dominantSet) continue;
|
|
306
|
-
hasValue = true;
|
|
307
|
-
value = layer.dominantValue;
|
|
308
|
-
}
|
|
309
|
-
if (hasValue) out.writeDiscrete(accumulator.binding, value);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
private _retainBinding(binding: Animation2DBinding, layer: number): void {
|
|
315
|
-
const existing = this._accumulators.get(binding.id);
|
|
316
|
-
if (existing) {
|
|
317
|
-
if (existing.binding.strategy !== binding.strategy
|
|
318
|
-
|| existing.binding.valueSize !== binding.valueSize) {
|
|
319
|
-
throw new RangeError(`Animation2D binding id "${binding.id}" has incompatible contracts.`);
|
|
320
|
-
}
|
|
321
|
-
existing.references++;
|
|
322
|
-
if (!existing.layersById.has(layer)) insertLayer(existing, createLayerAccumulator(binding, layer));
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
const size = isNumericBinding(binding) ? binding.valueSize! : 0;
|
|
326
|
-
const accumulator: BindingAccumulator = {
|
|
327
|
-
binding,
|
|
328
|
-
result: new Float32Array(size),
|
|
329
|
-
base: new Float32Array(size),
|
|
330
|
-
layers: [],
|
|
331
|
-
layersById: new Map(),
|
|
332
|
-
references: 1,
|
|
333
|
-
active: false,
|
|
334
|
-
};
|
|
335
|
-
writeDefaultBase(binding, accumulator.base);
|
|
336
|
-
insertLayer(accumulator, createLayerAccumulator(binding, layer));
|
|
337
|
-
this._accumulators.set(binding.id, accumulator);
|
|
338
|
-
this._accumulatorList.push(accumulator);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
private _releaseBinding(binding: Animation2DBinding): void {
|
|
342
|
-
const accumulator = this._accumulators.get(binding.id);
|
|
343
|
-
if (!accumulator) return;
|
|
344
|
-
accumulator.references--;
|
|
345
|
-
if (accumulator.references > 0) return;
|
|
346
|
-
this._accumulators.delete(binding.id);
|
|
347
|
-
const index = this._accumulatorList.indexOf(accumulator);
|
|
348
|
-
if (index >= 0) this._accumulatorList.splice(index, 1);
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
private _stateMachineLayer(layerId: string): number {
|
|
352
|
-
const existing = this._stateMachineLayers.get(layerId);
|
|
353
|
-
if (existing !== undefined) return existing;
|
|
354
|
-
const layer = this._nextStateMachineLayer++;
|
|
355
|
-
this._stateMachineLayers.set(layerId, layer);
|
|
356
|
-
return layer;
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
private _assertOwned(action: Animation2DActionRuntime): void {
|
|
360
|
-
this.assertActive();
|
|
361
|
-
if (this._actionsById.get(action.id) !== action) {
|
|
362
|
-
throw new RangeError('Animation2D action does not belong to this mixer.');
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
function resetAccumulator(accumulator: BindingAccumulator): void {
|
|
368
|
-
accumulator.active = false;
|
|
369
|
-
for (let index = 0; index < accumulator.layers.length; index++) {
|
|
370
|
-
const layer = accumulator.layers[index]!;
|
|
371
|
-
layer.overrideSum.fill(0);
|
|
372
|
-
layer.additiveSum.fill(0);
|
|
373
|
-
layer.overrideWeight = 0;
|
|
374
|
-
layer.rotationAnchor = 0;
|
|
375
|
-
layer.rotationAnchorSet = false;
|
|
376
|
-
layer.dominantSet = false;
|
|
377
|
-
layer.dominantValue = undefined;
|
|
378
|
-
layer.dominantWeight = -1;
|
|
379
|
-
layer.dominantOrder = Number.MAX_SAFE_INTEGER;
|
|
380
|
-
}
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
function createLayerAccumulator(binding: Animation2DBinding, layer: number): LayerAccumulator {
|
|
384
|
-
const size = isNumericBinding(binding) ? binding.valueSize! : 0;
|
|
385
|
-
return {
|
|
386
|
-
layer,
|
|
387
|
-
overrideSum: new Float32Array(size),
|
|
388
|
-
additiveSum: new Float32Array(size),
|
|
389
|
-
overrideWeight: 0,
|
|
390
|
-
rotationAnchor: 0,
|
|
391
|
-
rotationAnchorSet: false,
|
|
392
|
-
dominantSet: false,
|
|
393
|
-
dominantValue: undefined,
|
|
394
|
-
dominantWeight: -1,
|
|
395
|
-
dominantOrder: Number.MAX_SAFE_INTEGER,
|
|
396
|
-
};
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
function insertLayer(accumulator: BindingAccumulator, layer: LayerAccumulator): void {
|
|
400
|
-
let index = accumulator.layers.length;
|
|
401
|
-
while (index > 0 && accumulator.layers[index - 1]!.layer > layer.layer) index--;
|
|
402
|
-
accumulator.layers.splice(index, 0, layer);
|
|
403
|
-
accumulator.layersById.set(layer.layer, layer);
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
function accumulateNumeric(
|
|
407
|
-
layer: LayerAccumulator,
|
|
408
|
-
binding: Animation2DBinding,
|
|
409
|
-
runtimeTrack: Animation2DActionTrackRuntime,
|
|
410
|
-
sampled: Float32Array,
|
|
411
|
-
weight: number,
|
|
412
|
-
blendMode: 'override' | 'additive',
|
|
413
|
-
): void {
|
|
414
|
-
if (blendMode === 'additive') {
|
|
415
|
-
if (binding.strategy === 'rotation') {
|
|
416
|
-
layer.additiveSum[0] = layer.additiveSum[0]!
|
|
417
|
-
+ wrapAngle(sampled[0]! - runtimeTrack.reference[0]!) * weight;
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
for (let index = 0; index < sampled.length; index++) {
|
|
421
|
-
layer.additiveSum[index] = layer.additiveSum[index]!
|
|
422
|
-
+ (sampled[index]! - runtimeTrack.reference[index]!) * weight;
|
|
423
|
-
}
|
|
424
|
-
return;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
if (binding.strategy === 'rotation') {
|
|
428
|
-
if (!layer.rotationAnchorSet) {
|
|
429
|
-
layer.rotationAnchor = sampled[0]!;
|
|
430
|
-
layer.rotationAnchorSet = true;
|
|
431
|
-
}
|
|
432
|
-
const unwrapped = layer.rotationAnchor + wrapAngle(sampled[0]! - layer.rotationAnchor);
|
|
433
|
-
layer.overrideSum[0] = layer.overrideSum[0]! + unwrapped * weight;
|
|
434
|
-
} else {
|
|
435
|
-
for (let index = 0; index < sampled.length; index++) {
|
|
436
|
-
layer.overrideSum[index] = layer.overrideSum[index]! + sampled[index]! * weight;
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
layer.overrideWeight += weight;
|
|
440
|
-
}
|
|
441
|
-
|
|
442
|
-
function accumulateDominant(
|
|
443
|
-
layer: LayerAccumulator,
|
|
444
|
-
value: unknown,
|
|
445
|
-
weight: number,
|
|
446
|
-
order: number,
|
|
447
|
-
): void {
|
|
448
|
-
if (weight < layer.dominantWeight
|
|
449
|
-
|| (weight === layer.dominantWeight && order >= layer.dominantOrder)) return;
|
|
450
|
-
layer.dominantSet = true;
|
|
451
|
-
layer.dominantValue = value;
|
|
452
|
-
layer.dominantWeight = weight;
|
|
453
|
-
layer.dominantOrder = order;
|
|
454
|
-
}
|
|
455
|
-
|
|
456
|
-
function finalizeNumeric(accumulator: BindingAccumulator): void {
|
|
457
|
-
const binding = accumulator.binding;
|
|
458
|
-
const result = accumulator.result;
|
|
459
|
-
result.set(accumulator.base);
|
|
460
|
-
for (let layerIndex = 0; layerIndex < accumulator.layers.length; layerIndex++) {
|
|
461
|
-
const layer = accumulator.layers[layerIndex]!;
|
|
462
|
-
const weight = layer.overrideWeight;
|
|
463
|
-
if (weight > 0) {
|
|
464
|
-
if (binding.strategy === 'rotation') {
|
|
465
|
-
const target = layer.overrideSum[0]! / weight;
|
|
466
|
-
const current = target + wrapAngle(result[0]! - target);
|
|
467
|
-
const alpha = Math.min(1, weight);
|
|
468
|
-
result[0] = current + (target - current) * alpha;
|
|
469
|
-
} else if (weight < 1) {
|
|
470
|
-
const baseWeight = 1 - weight;
|
|
471
|
-
for (let index = 0; index < result.length; index++) {
|
|
472
|
-
result[index] = layer.overrideSum[index]! + result[index]! * baseWeight;
|
|
473
|
-
}
|
|
474
|
-
} else {
|
|
475
|
-
const inverseWeight = 1 / weight;
|
|
476
|
-
for (let index = 0; index < result.length; index++) {
|
|
477
|
-
result[index] = layer.overrideSum[index]! * inverseWeight;
|
|
478
|
-
}
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
for (let index = 0; index < result.length; index++) {
|
|
482
|
-
result[index] = result[index]! + layer.additiveSum[index]!;
|
|
483
|
-
}
|
|
484
|
-
if (binding.strategy === 'rotation') result[0] = wrapAngle(result[0]!);
|
|
485
|
-
}
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
function writeDefaultBase(binding: Animation2DBinding, out: Float32Array): void {
|
|
489
|
-
const authored = binding.defaultValue;
|
|
490
|
-
if (authored && typeof authored === 'object' && 'length' in authored) {
|
|
491
|
-
const values = authored as ArrayLike<number>;
|
|
492
|
-
for (let index = 0; index < out.length; index++) out[index] = values[index] ?? 0;
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
out.fill(0);
|
|
496
|
-
if (binding.path === 'transform.scale'
|
|
497
|
-
|| binding.path === 'opacity'
|
|
498
|
-
|| binding.path === 'color') out.fill(1);
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
function isStateMachineOptions(
|
|
502
|
-
options: Animation2DActionOptions | AnimationStateMachineActionOptions,
|
|
503
|
-
): options is AnimationStateMachineActionOptions {
|
|
504
|
-
return 'layerId' in options && 'stateId' in options;
|
|
505
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Animation2DBinding,
|
|
3
|
-
Animation2DEffectEvent,
|
|
4
|
-
Animation2DMutablePose,
|
|
5
|
-
Animation2DPose,
|
|
6
|
-
Animation2DPoseChannel,
|
|
7
|
-
} from './Types.js';
|
|
8
|
-
|
|
9
|
-
class ReusablePoseChannel implements Animation2DPoseChannel {
|
|
10
|
-
binding: Animation2DBinding;
|
|
11
|
-
value: Float32Array | unknown;
|
|
12
|
-
private _numeric = new Float32Array(0);
|
|
13
|
-
|
|
14
|
-
constructor(binding: Animation2DBinding) {
|
|
15
|
-
this.binding = binding;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
writeNumeric(binding: Animation2DBinding, source: ArrayLike<number>): void {
|
|
19
|
-
const size = numericSize(binding);
|
|
20
|
-
this.binding = binding;
|
|
21
|
-
if (this._numeric.length !== size) this._numeric = new Float32Array(size);
|
|
22
|
-
for (let index = 0; index < size; index++) this._numeric[index] = source[index] ?? 0;
|
|
23
|
-
this.value = this._numeric;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
writeDiscrete(binding: Animation2DBinding, value: unknown): void {
|
|
27
|
-
this.binding = binding;
|
|
28
|
-
this.value = value;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Caller-owned frame-transient pose. Channel records, numeric storage, and
|
|
34
|
-
* effect arrays are reused after warmup.
|
|
35
|
-
*/
|
|
36
|
-
export class Animation2DPoseBuffer implements Animation2DMutablePose, Animation2DPose {
|
|
37
|
-
private readonly _channelPool: ReusablePoseChannel[] = [];
|
|
38
|
-
private readonly _channels: ReusablePoseChannel[] = [];
|
|
39
|
-
private readonly _effects: Animation2DEffectEvent[] = [];
|
|
40
|
-
private _sequence = 0;
|
|
41
|
-
private _mixerTime = 0;
|
|
42
|
-
private _sealed = true;
|
|
43
|
-
|
|
44
|
-
get sequence(): number { return this._sequence; }
|
|
45
|
-
get mixerTime(): number { return this._mixerTime; }
|
|
46
|
-
get channels(): readonly Animation2DPoseChannel[] { return this._channels; }
|
|
47
|
-
get effects(): readonly Animation2DEffectEvent[] { return this._effects; }
|
|
48
|
-
|
|
49
|
-
reset(mixerTime: number): void {
|
|
50
|
-
if (!Number.isFinite(mixerTime)) {
|
|
51
|
-
throw new RangeError(`Animation2D pose mixerTime must be finite; received ${mixerTime}.`);
|
|
52
|
-
}
|
|
53
|
-
this._mixerTime = mixerTime;
|
|
54
|
-
this._channels.length = 0;
|
|
55
|
-
this._effects.length = 0;
|
|
56
|
-
this._sealed = false;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
writeNumeric(binding: Animation2DBinding, value: ArrayLike<number>): void {
|
|
60
|
-
const size = numericSize(binding);
|
|
61
|
-
if (value.length < size) {
|
|
62
|
-
throw new RangeError(
|
|
63
|
-
`Animation2D pose channel "${binding.id}" requires ${size} values; received ${value.length}.`,
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
const channel = this._channelAt(this._channels.length, binding);
|
|
67
|
-
channel.writeNumeric(binding, value);
|
|
68
|
-
this._channels.push(channel);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
writeDiscrete(binding: Animation2DBinding, value: unknown): void {
|
|
72
|
-
const channel = this._channelAt(this._channels.length, binding);
|
|
73
|
-
channel.writeDiscrete(binding, value);
|
|
74
|
-
this._channels.push(channel);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
emit(effect: Animation2DEffectEvent): void {
|
|
78
|
-
this._effects.push(effect);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
seal(): Animation2DPose {
|
|
82
|
-
if (!this._sealed) {
|
|
83
|
-
this._sequence++;
|
|
84
|
-
this._sealed = true;
|
|
85
|
-
}
|
|
86
|
-
return this;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
private _channelAt(index: number, binding: Animation2DBinding): ReusablePoseChannel {
|
|
90
|
-
let channel = this._channelPool[index];
|
|
91
|
-
if (!channel) {
|
|
92
|
-
channel = new ReusablePoseChannel(binding);
|
|
93
|
-
this._channelPool.push(channel);
|
|
94
|
-
}
|
|
95
|
-
return channel;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function numericSize(binding: Animation2DBinding): number {
|
|
100
|
-
const size = binding.valueSize ?? 0;
|
|
101
|
-
if (!Number.isInteger(size) || size <= 0) {
|
|
102
|
-
throw new RangeError(`Animation2D numeric binding "${binding.id}" requires a positive valueSize.`);
|
|
103
|
-
}
|
|
104
|
-
return size;
|
|
105
|
-
}
|