@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,135 +0,0 @@
|
|
|
1
|
-
import type { AnimationSource, ParsedAnimation } from '@haiyue/animation-spec';
|
|
2
|
-
import { parseAnimation } from '@haiyue/animation-spec';
|
|
3
|
-
import { Component, type Entity, type World } from '@haiyue/engine';
|
|
4
|
-
import { ComponentLifecycleFlags, UniqueCheckType } from '@haiyue/engine/ecs';
|
|
5
|
-
import type { Animation2DRuntime } from './Animation2DRuntime';
|
|
6
|
-
import type { Animation2DExtensionRegistry } from './Animation2DExtensionRegistry';
|
|
7
|
-
|
|
8
|
-
export interface Animation2DComponentOptions {
|
|
9
|
-
autoplay?: boolean;
|
|
10
|
-
loop?: boolean;
|
|
11
|
-
speed?: number;
|
|
12
|
-
startTime?: number;
|
|
13
|
-
runtimeExtensions?: Animation2DExtensionRegistry;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Animation2DRuntimeStats {
|
|
17
|
-
readonly nodeCount: number;
|
|
18
|
-
readonly visualCount: number;
|
|
19
|
-
readonly unsupportedComponentCount: number;
|
|
20
|
-
readonly pendingResourceCount: number;
|
|
21
|
-
readonly failedResourceCount: number;
|
|
22
|
-
readonly textCount: number;
|
|
23
|
-
readonly particleCount: number;
|
|
24
|
-
readonly audioCount: number;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export class Animation2DComponent extends Component {
|
|
28
|
-
static override UniqueCheckType = UniqueCheckType.SYMBOL | UniqueCheckType.REPLACE;
|
|
29
|
-
static override UniqueSymbol = Symbol.for('Animation2DComponent');
|
|
30
|
-
static override Lifecycle = ComponentLifecycleFlags.EntityRemoveComponent | ComponentLifecycleFlags.EntityRemoveFromWorld;
|
|
31
|
-
|
|
32
|
-
readonly animation: ParsedAnimation;
|
|
33
|
-
playing: boolean;
|
|
34
|
-
loop: boolean;
|
|
35
|
-
speed: number;
|
|
36
|
-
currentTime: number;
|
|
37
|
-
completed = false;
|
|
38
|
-
readonly runtimeExtensions: Animation2DExtensionRegistry | undefined;
|
|
39
|
-
_runtime: Animation2DRuntime | null = null;
|
|
40
|
-
_needsApply = true;
|
|
41
|
-
_forceParticleSeek = false;
|
|
42
|
-
|
|
43
|
-
constructor(source: AnimationSource | ParsedAnimation, options: Animation2DComponentOptions = {}) {
|
|
44
|
-
super('Animation2DComponent');
|
|
45
|
-
this.animation = isParsed(source) ? source : parseAnimation(source);
|
|
46
|
-
this.playing = options.autoplay ?? true;
|
|
47
|
-
this.loop = options.loop ?? this.animation.endBehavior === 'loop';
|
|
48
|
-
this.speed = finiteSpeed(options.speed ?? 1);
|
|
49
|
-
this.currentTime = clampTime(options.startTime ?? 0, this.animation.duration);
|
|
50
|
-
this.runtimeExtensions = options.runtimeExtensions;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
get runtimeStats(): Animation2DRuntimeStats {
|
|
54
|
-
return this._runtime?.stats ?? {
|
|
55
|
-
nodeCount: 0,
|
|
56
|
-
visualCount: 0,
|
|
57
|
-
unsupportedComponentCount: 0,
|
|
58
|
-
pendingResourceCount: 0,
|
|
59
|
-
failedResourceCount: 0,
|
|
60
|
-
textCount: 0,
|
|
61
|
-
particleCount: 0,
|
|
62
|
-
audioCount: 0,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
play(): this {
|
|
67
|
-
if (this.completed) {
|
|
68
|
-
this.currentTime = 0;
|
|
69
|
-
this._needsApply = true;
|
|
70
|
-
this._forceParticleSeek = true;
|
|
71
|
-
}
|
|
72
|
-
this.playing = true;
|
|
73
|
-
this.completed = false;
|
|
74
|
-
this._runtime?.setPlaying(true);
|
|
75
|
-
return this;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
pause(): this {
|
|
79
|
-
this.playing = false;
|
|
80
|
-
this._runtime?.setPlaying(false);
|
|
81
|
-
return this;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
seek(seconds: number): this {
|
|
85
|
-
this.currentTime = clampTime(seconds, this.animation.duration);
|
|
86
|
-
this.completed = false;
|
|
87
|
-
this._needsApply = true;
|
|
88
|
-
this._forceParticleSeek = true;
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
setSpeed(speed: number): this {
|
|
93
|
-
this.speed = finiteSpeed(speed);
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
onEntityRemoveComponent(_entity: Entity, component: Component): void {
|
|
98
|
-
if (component === this) this._disposeRuntime();
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
onEntityRemoveFromWorld(_entity: Entity, _world: World): void {
|
|
102
|
-
this._disposeRuntime();
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
override clone(): Animation2DComponent {
|
|
106
|
-
const clone = new Animation2DComponent(this.animation, {
|
|
107
|
-
autoplay: this.playing,
|
|
108
|
-
loop: this.loop,
|
|
109
|
-
speed: this.speed,
|
|
110
|
-
startTime: this.currentTime,
|
|
111
|
-
...(this.runtimeExtensions ? { runtimeExtensions: this.runtimeExtensions } : {}),
|
|
112
|
-
});
|
|
113
|
-
clone.disabled = this.disabled;
|
|
114
|
-
return clone;
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
_disposeRuntime(): void {
|
|
118
|
-
this._runtime?.destroy();
|
|
119
|
-
this._runtime = null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function isParsed(source: AnimationSource | ParsedAnimation): source is ParsedAnimation {
|
|
124
|
-
return typeof source === 'object' && source !== null && 'source' in source;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function finiteSpeed(value: number): number {
|
|
128
|
-
if (!Number.isFinite(value) || value < 0) throw new RangeError('Animation2DComponent speed must be finite and non-negative.');
|
|
129
|
-
return value;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
function clampTime(value: number, duration: number): number {
|
|
133
|
-
if (!Number.isFinite(value)) throw new RangeError('Animation2DComponent time must be finite.');
|
|
134
|
-
return Math.max(0, Math.min(duration, value));
|
|
135
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AnimationComponent,
|
|
3
|
-
AnimationNode,
|
|
4
|
-
ParsedAnimation,
|
|
5
|
-
} from '@haiyue/animation-spec';
|
|
6
|
-
import type { Entity } from '@haiyue/engine';
|
|
7
|
-
|
|
8
|
-
export interface Animation2DExtensionContext {
|
|
9
|
-
readonly animation: ParsedAnimation;
|
|
10
|
-
readonly node: Readonly<AnimationNode>;
|
|
11
|
-
readonly component: Readonly<AnimationComponent>;
|
|
12
|
-
/** Anchor-adjusted parent for entities created by the extension. */
|
|
13
|
-
readonly parent: Entity;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface Animation2DExtensionInstance {
|
|
17
|
-
/** Deterministic composition-time update; implementations must tolerate seeks and loop wrap. */
|
|
18
|
-
apply?(timeSeconds: number, opacity: number): void;
|
|
19
|
-
setOpacity?(opacity: number): void;
|
|
20
|
-
destroy?(): void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export interface Animation2DExtensionHandler {
|
|
24
|
-
/** Component type or namespaced extension id implemented by this handler. */
|
|
25
|
-
readonly id: string;
|
|
26
|
-
create(context: Animation2DExtensionContext): Animation2DExtensionInstance | void;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/** Instance-owned registry; unregister tokens only remove the handler that created them. */
|
|
30
|
-
export class Animation2DExtensionRegistry {
|
|
31
|
-
private readonly _handlers = new Map<string, Animation2DExtensionHandler>();
|
|
32
|
-
|
|
33
|
-
register(handler: Animation2DExtensionHandler): () => void {
|
|
34
|
-
if (!handler.id.trim()) throw new TypeError('Animation runtime extension id must not be empty.');
|
|
35
|
-
if (this._handlers.has(handler.id)) throw new Error(`Animation runtime extension "${handler.id}" is already registered.`);
|
|
36
|
-
this._handlers.set(handler.id, handler);
|
|
37
|
-
let active = true;
|
|
38
|
-
return () => {
|
|
39
|
-
if (!active) return;
|
|
40
|
-
active = false;
|
|
41
|
-
if (this._handlers.get(handler.id) === handler) this._handlers.delete(handler.id);
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
get(id: string): Animation2DExtensionHandler | undefined {
|
|
46
|
-
return this._handlers.get(id);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
has(id: string): boolean {
|
|
50
|
-
return this._handlers.has(id);
|
|
51
|
-
}
|
|
52
|
-
}
|