@haiyue/extensions 0.1.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/LICENSE +21 -0
- package/README.md +30 -0
- package/dist/animation/Animation2DComponent.d.ts +46 -0
- package/dist/animation/Animation2DExtensionRegistry.d.ts +27 -0
- package/dist/animation/Animation2DRenderSystem.d.ts +89 -0
- package/dist/animation/Animation2DRuntime.d.ts +99 -0
- package/dist/animation/Animation2DStateMachine.d.ts +13 -0
- package/dist/animation/Animation2DStateMachineComponent.d.ts +54 -0
- package/dist/animation/Animation2DStateMachineRuntime.d.ts +30 -0
- package/dist/animation/Animation2DStateMachineSystem.d.ts +14 -0
- package/dist/animation/Animation2DStateMachineVisualRuntime.d.ts +27 -0
- package/dist/animation/Animation2DSystem.d.ts +14 -0
- package/dist/animation/AnimationAssetLoader.d.ts +9 -0
- package/dist/animation/AnimationAudioClip.d.ts +26 -0
- package/dist/animation/AnimationPathTessellator.d.ts +52 -0
- package/dist/animation/AnimationTextRasterizer.d.ts +21 -0
- package/dist/animation/AnimationVisual2D.d.ts +68 -0
- package/dist/animation/HyaAnimation2DClipAdapter.d.ts +16 -0
- package/dist/animation/Particle2DDescriptorAdapter.d.ts +5 -0
- package/dist/animation/runtime/mixer/Action.d.ts +150 -0
- package/dist/animation/runtime/mixer/Mixer.d.ts +54 -0
- package/dist/animation/runtime/mixer/PoseBuffer.d.ts +23 -0
- package/dist/animation/runtime/mixer/Sampler.d.ts +17 -0
- package/dist/animation/runtime/mixer/Types.d.ts +101 -0
- package/dist/animation/runtime/mixer/index.d.ts +6 -0
- package/dist/animation-state-machine/AnimationStateMachine.d.ts +111 -0
- package/dist/animation-state-machine/AnimationStateMachineChannels.d.ts +23 -0
- package/dist/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.d.ts +51 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.d.ts +14 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineCompiler.d.ts +109 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineController.d.ts +103 -0
- package/dist/animation-state-machine/runtime/AnimationStateMachineMixerPort.d.ts +35 -0
- package/dist/animation-state-machine/runtime/index.d.ts +7 -0
- package/dist/animation.d.ts +15 -0
- package/dist/animation.js +1171 -0
- package/dist/animation3d/Animation3DAction.d.ts +46 -0
- package/dist/animation3d/Animation3DBinding.d.ts +85 -0
- package/dist/animation3d/Animation3DClip.d.ts +20 -0
- package/dist/animation3d/Animation3DError.d.ts +13 -0
- package/dist/animation3d/Animation3DMixer.d.ts +27 -0
- package/dist/animation3d/Animation3DPose.d.ts +40 -0
- package/dist/animation3d/Animation3DPoseBuffer.d.ts +24 -0
- package/dist/animation3d/Animation3DResource.d.ts +28 -0
- package/dist/animation3d/Animation3DStateMachine.d.ts +95 -0
- package/dist/animation3d/Animation3DStateMachineRuntime.d.ts +70 -0
- package/dist/animation3d/Animation3DTrack.d.ts +19 -0
- package/dist/animation3d/hya/HyaAnimation3DRuntime.d.ts +73 -0
- package/dist/animation3d/hya/HyaAnimation3DStateMachineRuntime.d.ts +65 -0
- package/dist/animation3d/hya/HyaAnimation3DTypes.d.ts +170 -0
- package/dist/animation3d/hya/index.d.ts +4 -0
- package/dist/animation3d/index.d.ts +14 -0
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.d.ts +81 -0
- package/dist/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.d.ts +39 -0
- package/dist/animation3d/runtime/integration/index.d.ts +2 -0
- package/dist/animation3d/runtime/mixer/Action.d.ts +150 -0
- package/dist/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.d.ts +6 -0
- package/dist/animation3d/runtime/mixer/Mixer.d.ts +59 -0
- package/dist/animation3d/runtime/mixer/PoseBuffer.d.ts +1 -0
- package/dist/animation3d/runtime/mixer/TrackSampler.d.ts +24 -0
- package/dist/animation3d/runtime/mixer/index.d.ts +4 -0
- package/dist/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineController.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.d.ts +1 -0
- package/dist/animation3d/runtime/state-machine/index.d.ts +6 -0
- package/dist/animation3d.d.ts +5 -0
- package/dist/animation3d.js +1708 -0
- package/dist/benchmark.d.ts +30 -0
- package/dist/benchmark.js +119 -0
- package/dist/canvas-text/CanvasText2DRenderSystem.d.ts +24 -0
- package/dist/canvas-text/CanvasTextComponent.d.ts +18 -0
- package/dist/canvas-text.d.ts +4 -0
- package/dist/canvas-text.js +276 -0
- package/dist/chunks/2d-ui-animation-2d.generated-D4aHzFU2.js +4 -0
- package/dist/chunks/2d-ui-canvas-text-2d.generated-C0Eaej2m.js +4 -0
- package/dist/chunks/2d-ui-spine2d.generated-CUUi8xjl.js +4 -0
- package/dist/chunks/2d-ui-tilemap2d.generated-gebw4mX7.js +4 -0
- package/dist/chunks/Animation2DStateMachine-9IonguNa.js +3245 -0
- package/dist/chunks/AnimationStateMachineController-BIcAh-sT.js +1438 -0
- package/dist/chunks/GltfAnimation3DAdapter-Cu3rQQsW.js +2240 -0
- package/dist/chunks/GltfAnimationRuntime-CRHsLycN.js +631 -0
- package/dist/chunks/RenderSystem2DBase-DDT61dAu.js +227 -0
- package/dist/chunks/Spine2DRuntime-D9M9LAQR.js +3056 -0
- package/dist/chunks/SpineAssetParser-BSDmPge1.js +378 -0
- package/dist/chunks/gltfLoader-Dm22jLYB.js +2085 -0
- package/dist/chunks/pluginUtils-CvwroRMd.js +33 -0
- package/dist/experimental-gltf-worker.d.ts +4 -0
- package/dist/experimental-gltf-worker.js +138 -0
- package/dist/experimental-spine-worker.d.ts +4 -0
- package/dist/experimental-spine-worker.js +110 -0
- package/dist/gltf/GltfAccessorReader.d.ts +7 -0
- package/dist/gltf/GltfAnimation3DAdapter.d.ts +47 -0
- package/dist/gltf/GltfAnimationRuntime.d.ts +10 -0
- package/dist/gltf/GltfAssetWorkerClient.d.ts +20 -0
- package/dist/gltf/GltfCompatibilityReport.d.ts +70 -0
- package/dist/gltf/GltfConservativeBounds.d.ts +18 -0
- package/dist/gltf/GltfDracoDecoder.d.ts +4 -0
- package/dist/gltf/GltfExtensionAdapter.d.ts +54 -0
- package/dist/gltf/GltfLoaderContract.d.ts +249 -0
- package/dist/gltf/GltfLoaderErrors.d.ts +4 -0
- package/dist/gltf/GltfMaterialDescriptor.d.ts +23 -0
- package/dist/gltf/GltfMaterialEncoder.d.ts +20 -0
- package/dist/gltf/GltfMaterialLoader.d.ts +6 -0
- package/dist/gltf/GltfModelComponent.d.ts +72 -0
- package/dist/gltf/GltfModelSystem.d.ts +37 -0
- package/dist/gltf/GltfPlugin.d.ts +6 -0
- package/dist/gltf/GltfSchema.d.ts +225 -0
- package/dist/gltf/GltfUvSemanticPlanner.d.ts +33 -0
- package/dist/gltf/gltfLoader.d.ts +9 -0
- package/dist/gltf-animation3d.d.ts +3 -0
- package/dist/gltf-animation3d.js +8 -0
- package/dist/gltf-worker-runtime.d.ts +7 -0
- package/dist/gltf-worker-runtime.js +6981 -0
- package/dist/gltf.d.ts +12 -0
- package/dist/gltf.js +517 -0
- package/dist/grid/Grid2DComponent.d.ts +25 -0
- package/dist/grid.d.ts +2 -0
- package/dist/grid.js +56 -0
- package/dist/hya-state-machine.d.ts +7 -0
- package/dist/hya-state-machine.js +2934 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +7 -0
- package/dist/internal/2d-ui-shader-artifact.js +870 -0
- package/dist/plugins/pluginUtils.d.ts +20 -0
- package/dist/plugins.d.ts +6 -0
- package/dist/shaders/generated/2d-ui-artifact.generated.d.ts +658 -0
- package/dist/spine/Spine2DComponent.d.ts +116 -0
- package/dist/spine/Spine2DGpuRenderer.d.ts +65 -0
- package/dist/spine/Spine2DRenderSystem.d.ts +27 -0
- package/dist/spine/Spine2DRuntime.d.ts +103 -0
- package/dist/spine/SpineAnimationBoneTimelines.d.ts +8 -0
- package/dist/spine/SpineAssetParser.d.ts +18 -0
- package/dist/spine/SpineAssetWorkerClient.d.ts +19 -0
- package/dist/spine/SpineAssetWorkerContract.d.ts +6 -0
- package/dist/spine/SpineAtlasParser.d.ts +21 -0
- package/dist/spine/SpineFloatBuilder.d.ts +15 -0
- package/dist/spine/SpinePathConstraintSolver.d.ts +32 -0
- package/dist/spine/SpinePlugin.d.ts +8 -0
- package/dist/spine/SpineSkeletonRuntime.d.ts +185 -0
- package/dist/spine/SpineSlotAnimation.d.ts +17 -0
- package/dist/spine/SpineTimelineRuntime.d.ts +25 -0
- package/dist/spine/SpineVertexBuilder.d.ts +61 -0
- package/dist/spine.d.ts +7 -0
- package/dist/spine.js +578 -0
- package/dist/tilemap/Tilemap2DComponent.d.ts +110 -0
- package/dist/tilemap/Tilemap2DRenderSystem.d.ts +11 -0
- package/dist/tilemap/Tilemap2DRenderer.d.ts +24 -0
- package/dist/tilemap/TilemapPlugin.d.ts +8 -0
- package/dist/tilemap.d.ts +6 -0
- package/dist/tilemap.js +535 -0
- package/dist/tween/Tween2DComponent.d.ts +70 -0
- package/dist/tween/Tween2DSystem.d.ts +12 -0
- package/dist/tween.d.ts +4 -0
- package/dist/tween.js +138 -0
- package/dist/utils/RenderSystem2DBase.d.ts +42 -0
- package/dist/utils/arrayAccess.d.ts +4 -0
- package/dist/utils/camera2d.d.ts +12 -0
- package/dist/utils/render2dGpu.d.ts +32 -0
- package/package.json +124 -0
- package/src/animation/Animation2DComponent.ts +135 -0
- package/src/animation/Animation2DExtensionRegistry.ts +52 -0
- package/src/animation/Animation2DRenderSystem.ts +1026 -0
- package/src/animation/Animation2DRuntime.ts +1326 -0
- package/src/animation/Animation2DStateMachine.ts +39 -0
- package/src/animation/Animation2DStateMachineComponent.ts +228 -0
- package/src/animation/Animation2DStateMachineRuntime.ts +141 -0
- package/src/animation/Animation2DStateMachineSystem.ts +60 -0
- package/src/animation/Animation2DStateMachineVisualRuntime.ts +282 -0
- package/src/animation/Animation2DSystem.ts +72 -0
- package/src/animation/AnimationAssetLoader.ts +84 -0
- package/src/animation/AnimationAudioClip.ts +140 -0
- package/src/animation/AnimationPathTessellator.ts +691 -0
- package/src/animation/AnimationTextRasterizer.ts +340 -0
- package/src/animation/AnimationVisual2D.ts +153 -0
- package/src/animation/HyaAnimation2DClipAdapter.ts +845 -0
- package/src/animation/Particle2DDescriptorAdapter.ts +35 -0
- package/src/animation/runtime/mixer/Action.ts +876 -0
- package/src/animation/runtime/mixer/Mixer.ts +505 -0
- package/src/animation/runtime/mixer/PoseBuffer.ts +105 -0
- package/src/animation/runtime/mixer/Sampler.ts +252 -0
- package/src/animation/runtime/mixer/Types.ts +138 -0
- package/src/animation/runtime/mixer/index.ts +31 -0
- package/src/animation-state-machine/AnimationStateMachine.ts +146 -0
- package/src/animation-state-machine/AnimationStateMachineChannels.ts +116 -0
- package/src/animation-state-machine/runtime/Animation2DStateMachineMixerAdapter.ts +197 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineBlendTreeWeights.ts +503 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineCompiler.ts +763 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineController.ts +987 -0
- package/src/animation-state-machine/runtime/AnimationStateMachineMixerPort.ts +54 -0
- package/src/animation-state-machine/runtime/index.ts +47 -0
- package/src/animation.ts +33 -0
- package/src/animation3d/Animation3DAction.ts +73 -0
- package/src/animation3d/Animation3DBinding.ts +116 -0
- package/src/animation3d/Animation3DClip.ts +22 -0
- package/src/animation3d/Animation3DError.ts +34 -0
- package/src/animation3d/Animation3DMixer.ts +82 -0
- package/src/animation3d/Animation3DPose.ts +100 -0
- package/src/animation3d/Animation3DPoseBuffer.ts +85 -0
- package/src/animation3d/Animation3DResource.ts +49 -0
- package/src/animation3d/Animation3DStateMachine.ts +126 -0
- package/src/animation3d/Animation3DStateMachineRuntime.ts +191 -0
- package/src/animation3d/Animation3DTrack.ts +29 -0
- package/src/animation3d/hya/HyaAnimation3DRuntime.ts +756 -0
- package/src/animation3d/hya/HyaAnimation3DStateMachineRuntime.ts +618 -0
- package/src/animation3d/hya/HyaAnimation3DTypes.ts +168 -0
- package/src/animation3d/hya/index.ts +10 -0
- package/src/animation3d/index.ts +76 -0
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerAdapter.ts +325 -0
- package/src/animation3d/runtime/integration/Animation3DStateMachineMixerIntegration.ts +158 -0
- package/src/animation3d/runtime/integration/index.ts +9 -0
- package/src/animation3d/runtime/mixer/Action.ts +833 -0
- package/src/animation3d/runtime/mixer/Animation3DMixerRuntimeStore.ts +26 -0
- package/src/animation3d/runtime/mixer/Mixer.ts +562 -0
- package/src/animation3d/runtime/mixer/PoseBuffer.ts +1 -0
- package/src/animation3d/runtime/mixer/TrackSampler.ts +399 -0
- package/src/animation3d/runtime/mixer/index.ts +8 -0
- package/src/animation3d/runtime/state-machine/Animation3DBlendTreeWeights.ts +4 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineCompiler.ts +1 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineController.ts +1 -0
- package/src/animation3d/runtime/state-machine/Animation3DStateMachineMixerPort.ts +1 -0
- package/src/animation3d/runtime/state-machine/index.ts +45 -0
- package/src/animation3d.ts +5 -0
- package/src/benchmark.ts +168 -0
- package/src/canvas-text/CanvasText2DRenderSystem.ts +292 -0
- package/src/canvas-text/CanvasTextComponent.ts +47 -0
- package/src/canvas-text.ts +4 -0
- package/src/experimental-gltf-worker.ts +18 -0
- package/src/experimental-spine-worker.ts +9 -0
- package/src/gltf/GltfAccessorReader.ts +271 -0
- package/src/gltf/GltfAnimation3DAdapter.ts +680 -0
- package/src/gltf/GltfAnimationRuntime.ts +392 -0
- package/src/gltf/GltfAssetWorkerClient.ts +136 -0
- package/src/gltf/GltfCompatibilityReport.ts +214 -0
- package/src/gltf/GltfConservativeBounds.ts +219 -0
- package/src/gltf/GltfDracoDecoder.ts +251 -0
- package/src/gltf/GltfExtensionAdapter.ts +340 -0
- package/src/gltf/GltfLoaderContract.ts +333 -0
- package/src/gltf/GltfLoaderErrors.ts +59 -0
- package/src/gltf/GltfMaterialDescriptor.ts +134 -0
- package/src/gltf/GltfMaterialEncoder.ts +173 -0
- package/src/gltf/GltfMaterialLoader.ts +293 -0
- package/src/gltf/GltfModelComponent.ts +115 -0
- package/src/gltf/GltfModelSystem.ts +208 -0
- package/src/gltf/GltfPlugin.ts +84 -0
- package/src/gltf/GltfSchema.ts +229 -0
- package/src/gltf/GltfUvSemanticPlanner.ts +166 -0
- package/src/gltf/gltfLoader.ts +910 -0
- package/src/gltf-animation3d.ts +10 -0
- package/src/gltf-worker-runtime.ts +10 -0
- package/src/gltf.ts +56 -0
- package/src/grid/Grid2DComponent.ts +69 -0
- package/src/grid.ts +2 -0
- package/src/hya-state-machine.ts +19 -0
- package/src/index.ts +2 -0
- package/src/plugins/pluginUtils.ts +50 -0
- package/src/plugins.ts +6 -0
- package/src/shaders/generated/2d-ui-animation-2d.generated.wgsl +242 -0
- package/src/shaders/generated/2d-ui-artifact.generated.ts +867 -0
- package/src/shaders/generated/2d-ui-canvas-text-2d.generated.wgsl +38 -0
- package/src/shaders/generated/2d-ui-spine2d.generated.wgsl +41 -0
- package/src/shaders/generated/2d-ui-tilemap2d.generated.wgsl +36 -0
- package/src/spine/Spine2DComponent.ts +168 -0
- package/src/spine/Spine2DGpuRenderer.ts +449 -0
- package/src/spine/Spine2DRenderSystem.ts +199 -0
- package/src/spine/Spine2DRuntime.ts +1529 -0
- package/src/spine/SpineAnimationBoneTimelines.ts +30 -0
- package/src/spine/SpineAssetParser.ts +20 -0
- package/src/spine/SpineAssetWorkerClient.ts +112 -0
- package/src/spine/SpineAssetWorkerContract.ts +4 -0
- package/src/spine/SpineAtlasParser.ts +127 -0
- package/src/spine/SpineFloatBuilder.ts +66 -0
- package/src/spine/SpinePathConstraintSolver.ts +582 -0
- package/src/spine/SpinePlugin.ts +76 -0
- package/src/spine/SpineSkeletonRuntime.ts +521 -0
- package/src/spine/SpineSlotAnimation.ts +195 -0
- package/src/spine/SpineTimelineRuntime.ts +453 -0
- package/src/spine/SpineVertexBuilder.ts +686 -0
- package/src/spine.ts +7 -0
- package/src/tilemap/Tilemap2DComponent.ts +232 -0
- package/src/tilemap/Tilemap2DRenderSystem.ts +58 -0
- package/src/tilemap/Tilemap2DRenderer.ts +289 -0
- package/src/tilemap/TilemapPlugin.ts +75 -0
- package/src/tilemap.ts +6 -0
- package/src/tween/Tween2DComponent.ts +83 -0
- package/src/tween/Tween2DSystem.ts +78 -0
- package/src/tween.ts +4 -0
- package/src/types/earcut.d.ts +7 -0
- package/src/types/wgsl.d.ts +4 -0
- package/src/utils/RenderSystem2DBase.ts +164 -0
- package/src/utils/arrayAccess.ts +17 -0
- package/src/utils/camera2d.ts +68 -0
- package/src/utils/render2dGpu.ts +132 -0
- package/test/fixtures/gltf/animation-characterization.gltf +344 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
import { EngineError, EngineErrorCode } from '@haiyue/engine';
|
|
2
|
+
import { ErrorRecovery, ErrorDomain } from '@haiyue/engine/core';
|
|
3
|
+
|
|
4
|
+
function parseAtlas(text) {
|
|
5
|
+
const regions = new Map();
|
|
6
|
+
const lines = text.split(/\r?\n/);
|
|
7
|
+
let page = '';
|
|
8
|
+
for (let i = 0; i < lines.length; i++) {
|
|
9
|
+
const sourceLine = lines[i];
|
|
10
|
+
if (sourceLine === undefined)
|
|
11
|
+
continue;
|
|
12
|
+
const line = sourceLine.trim();
|
|
13
|
+
if (!line)
|
|
14
|
+
continue;
|
|
15
|
+
if (!line.includes(':')) {
|
|
16
|
+
const next = lines[i + 1]?.trim() ?? '';
|
|
17
|
+
if (next.startsWith('size:') || next.startsWith('format:') || next.startsWith('filter:') || next.startsWith('repeat:')) {
|
|
18
|
+
page = line;
|
|
19
|
+
continue;
|
|
20
|
+
}
|
|
21
|
+
const name = line;
|
|
22
|
+
const region = {
|
|
23
|
+
name,
|
|
24
|
+
page,
|
|
25
|
+
x: 0,
|
|
26
|
+
y: 0,
|
|
27
|
+
width: 1,
|
|
28
|
+
height: 1,
|
|
29
|
+
originalWidth: 0,
|
|
30
|
+
originalHeight: 0,
|
|
31
|
+
offsetX: 0,
|
|
32
|
+
offsetY: 0,
|
|
33
|
+
rotate: 0,
|
|
34
|
+
};
|
|
35
|
+
while (i + 1 < lines.length) {
|
|
36
|
+
const propertyLine = lines[i + 1];
|
|
37
|
+
if (propertyLine === undefined || !propertyLine.includes(':'))
|
|
38
|
+
break;
|
|
39
|
+
i++;
|
|
40
|
+
const separator = propertyLine.indexOf(':');
|
|
41
|
+
const key = propertyLine.slice(0, separator).trim();
|
|
42
|
+
const raw = propertyLine.slice(separator + 1).trim();
|
|
43
|
+
const nums = raw.split(',').map(Number);
|
|
44
|
+
const numberAt = (index, fallback) => {
|
|
45
|
+
const value = nums[index];
|
|
46
|
+
return value !== undefined && Number.isFinite(value) ? value : fallback;
|
|
47
|
+
};
|
|
48
|
+
if (key === 'rotate')
|
|
49
|
+
region.rotate = raw === 'true' ? 90 : raw === 'false' ? 0 : Number(raw) || 0;
|
|
50
|
+
if (key === 'bounds') {
|
|
51
|
+
region.x = numberAt(0, region.x);
|
|
52
|
+
region.y = numberAt(1, region.y);
|
|
53
|
+
region.width = numberAt(2, region.width);
|
|
54
|
+
region.height = numberAt(3, region.height);
|
|
55
|
+
}
|
|
56
|
+
if (key === 'xy') {
|
|
57
|
+
region.x = numberAt(0, region.x);
|
|
58
|
+
region.y = numberAt(1, region.y);
|
|
59
|
+
}
|
|
60
|
+
if (key === 'size') {
|
|
61
|
+
region.width = numberAt(0, region.width);
|
|
62
|
+
region.height = numberAt(1, region.height);
|
|
63
|
+
}
|
|
64
|
+
if (key === 'orig') {
|
|
65
|
+
region.originalWidth = numberAt(0, region.originalWidth);
|
|
66
|
+
region.originalHeight = numberAt(1, region.originalHeight);
|
|
67
|
+
}
|
|
68
|
+
if (key === 'offsets') {
|
|
69
|
+
region.offsetX = numberAt(0, region.offsetX);
|
|
70
|
+
region.offsetY = numberAt(1, region.offsetY);
|
|
71
|
+
region.originalWidth = numberAt(2, region.originalWidth);
|
|
72
|
+
region.originalHeight = numberAt(3, region.originalHeight);
|
|
73
|
+
}
|
|
74
|
+
if (key === 'offset') {
|
|
75
|
+
region.offsetX = numberAt(0, region.offsetX);
|
|
76
|
+
region.offsetY = numberAt(1, region.offsetY);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if (!region.originalWidth && !region.originalHeight) {
|
|
80
|
+
region.originalWidth = region.width;
|
|
81
|
+
region.originalHeight = region.height;
|
|
82
|
+
}
|
|
83
|
+
regions.set(name, region);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return regions;
|
|
87
|
+
}
|
|
88
|
+
function resolveAtlasPageImageUrl(options, atlas, page) {
|
|
89
|
+
const mapped = options.imageUrls[page] ?? options.imageUrls[page.split('/').pop() ?? page];
|
|
90
|
+
if (mapped)
|
|
91
|
+
return mapped;
|
|
92
|
+
if (options.imageUrl && (!page || atlasPageCount(atlas) <= 1))
|
|
93
|
+
return options.imageUrl;
|
|
94
|
+
if (!page) {
|
|
95
|
+
if (options.imageUrl)
|
|
96
|
+
return options.imageUrl;
|
|
97
|
+
throw new EngineError(EngineErrorCode.AssetInvalidData, 'Spine imageUrl is required when atlas has no page.', {
|
|
98
|
+
domain: ErrorDomain.Component,
|
|
99
|
+
recovery: ErrorRecovery.ReleaseResource,
|
|
100
|
+
context: { atlasUrl: options.atlasUrl, resourceType: 'skeleton/spine-atlas' },
|
|
101
|
+
path: 'spine.atlas.pages',
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return new URL(page, options.atlasUrl || window.location.href).href;
|
|
105
|
+
}
|
|
106
|
+
function atlasPageCount(atlas) {
|
|
107
|
+
return new Set(Array.from(atlas.values()).map(region => region.page).filter(Boolean)).size;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
function normalizeSpineData(input) {
|
|
111
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input)) {
|
|
112
|
+
throw invalidSpineData('Spine JSON root must be an object.', 'spine');
|
|
113
|
+
}
|
|
114
|
+
const record = input;
|
|
115
|
+
if (!Array.isArray(record.bones))
|
|
116
|
+
throw invalidSpineData('Spine JSON bones must be an array.', 'spine.bones');
|
|
117
|
+
if (!Array.isArray(record.slots))
|
|
118
|
+
throw invalidSpineData('Spine JSON slots must be an array.', 'spine.slots');
|
|
119
|
+
for (const [index, bone] of record.bones.entries()) {
|
|
120
|
+
if (typeof bone !== 'object' || bone === null || typeof bone.name !== 'string') {
|
|
121
|
+
throw invalidSpineData(`Spine bone ${index} must include a string name.`, `spine.bones[${index}].name`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
for (const [index, slot] of record.slots.entries()) {
|
|
125
|
+
if (typeof slot !== 'object' || slot === null || typeof slot.name !== 'string') {
|
|
126
|
+
throw invalidSpineData(`Spine slot ${index} must include a string name.`, `spine.slots[${index}].name`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return normalizeValidatedSpineData(record);
|
|
130
|
+
}
|
|
131
|
+
// Spine JSON is an open, version-dependent third-party schema. Dynamic access is
|
|
132
|
+
// intentionally confined to this normalization adapter; domain code consumes SpineData.
|
|
133
|
+
function normalizeValidatedSpineData(input) {
|
|
134
|
+
const skins = {};
|
|
135
|
+
const skinConstraints = {};
|
|
136
|
+
if (Array.isArray(input.skins)) {
|
|
137
|
+
for (const skin of input.skins) {
|
|
138
|
+
const name = skin.name || 'default';
|
|
139
|
+
skins[name] = normalizeSkinAttachments(skin.attachments);
|
|
140
|
+
skinConstraints[name] = {
|
|
141
|
+
ik: skin.ik ?? [],
|
|
142
|
+
transform: skin.transform ?? [],
|
|
143
|
+
path: skin.path ?? [],
|
|
144
|
+
slider: skin.slider ?? skin.sliders ?? [],
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
for (const [name, attachments] of Object.entries(input.skins ?? {})) {
|
|
150
|
+
skins[name] = normalizeSkinAttachments(attachments);
|
|
151
|
+
}
|
|
152
|
+
for (const name of Object.keys(skins))
|
|
153
|
+
skinConstraints[name] = { ik: [], transform: [], path: [], slider: [] };
|
|
154
|
+
}
|
|
155
|
+
resolveLinkedMeshes(skins);
|
|
156
|
+
const constraints = Array.isArray(input.constraints)
|
|
157
|
+
? input.constraints.map((constraint, index) => ({ ...constraint, __order: index }))
|
|
158
|
+
: null;
|
|
159
|
+
const ikConstraints = constraints
|
|
160
|
+
? constraints.filter(constraint => constraint.type === 'ik')
|
|
161
|
+
: (input.ik ?? []);
|
|
162
|
+
const transformConstraints = constraints
|
|
163
|
+
? constraints.filter(constraint => constraint.type === 'transform')
|
|
164
|
+
: (input.transform ?? []);
|
|
165
|
+
const pathConstraints = constraints
|
|
166
|
+
? constraints.filter(constraint => constraint.type === 'path')
|
|
167
|
+
: (input.path ?? []);
|
|
168
|
+
const sliderConstraints = constraints
|
|
169
|
+
? constraints.filter(constraint => constraint.type === 'slider')
|
|
170
|
+
: (input.sliders ?? input.slider ?? []);
|
|
171
|
+
return {
|
|
172
|
+
bones: (input.bones ?? []).map(bone => ({
|
|
173
|
+
name: bone.name,
|
|
174
|
+
...(bone.parent === undefined ? {} : { parent: bone.parent }),
|
|
175
|
+
...(bone.inherit === undefined ? {} : { inherit: bone.inherit }),
|
|
176
|
+
x: bone.x ?? 0,
|
|
177
|
+
y: bone.y ?? 0,
|
|
178
|
+
rotation: bone.rotation ?? 0,
|
|
179
|
+
shearX: bone.shearX ?? 0,
|
|
180
|
+
shearY: bone.shearY ?? 0,
|
|
181
|
+
scaleX: bone.scaleX ?? 1,
|
|
182
|
+
scaleY: bone.scaleY ?? 1,
|
|
183
|
+
length: bone.length ?? 0,
|
|
184
|
+
})),
|
|
185
|
+
ik: ikConstraints.map((constraint, index) => ({
|
|
186
|
+
name: constraint.name,
|
|
187
|
+
order: constraint.order ?? constraint.__order ?? index,
|
|
188
|
+
skin: constraint.skin ?? false,
|
|
189
|
+
bones: constraint.bones ?? [],
|
|
190
|
+
target: constraint.target ?? constraint.source ?? '',
|
|
191
|
+
mix: constraint.mix ?? 1,
|
|
192
|
+
softness: constraint.softness ?? 0,
|
|
193
|
+
bendPositive: constraint.bendPositive ?? true,
|
|
194
|
+
})),
|
|
195
|
+
transform: transformConstraints.map((constraint, index) => ({
|
|
196
|
+
name: constraint.name,
|
|
197
|
+
order: constraint.order ?? constraint.__order ?? index,
|
|
198
|
+
skin: constraint.skin ?? false,
|
|
199
|
+
bones: constraint.bones ?? [],
|
|
200
|
+
target: constraint.target ?? constraint.source ?? '',
|
|
201
|
+
rotation: constraint.rotation ?? 0,
|
|
202
|
+
x: constraint.x ?? 0,
|
|
203
|
+
y: constraint.y ?? 0,
|
|
204
|
+
scaleX: constraint.scaleX ?? 0,
|
|
205
|
+
scaleY: constraint.scaleY ?? 0,
|
|
206
|
+
shearY: constraint.shearY ?? 0,
|
|
207
|
+
...normalizeTransformMixes(constraint),
|
|
208
|
+
localSource: constraint.localSource ?? false,
|
|
209
|
+
localTarget: constraint.localTarget ?? false,
|
|
210
|
+
additive: constraint.additive ?? false,
|
|
211
|
+
})),
|
|
212
|
+
path: pathConstraints.map((constraint, index) => ({
|
|
213
|
+
name: constraint.name,
|
|
214
|
+
order: constraint.order ?? constraint.__order ?? index,
|
|
215
|
+
skin: constraint.skin ?? false,
|
|
216
|
+
bones: constraint.bones ?? [],
|
|
217
|
+
slot: constraint.slot ?? '',
|
|
218
|
+
position: constraint.position ?? 0,
|
|
219
|
+
spacing: constraint.spacing ?? 0,
|
|
220
|
+
mixRotate: constraint.mixRotate ?? 1,
|
|
221
|
+
mixX: constraint.mixX ?? 1,
|
|
222
|
+
mixY: constraint.mixY ?? constraint.mixX ?? 1,
|
|
223
|
+
positionMode: constraint.positionMode ?? 'percent',
|
|
224
|
+
spacingMode: constraint.spacingMode ?? 'length',
|
|
225
|
+
rotateMode: constraint.rotateMode ?? 'tangent',
|
|
226
|
+
offsetRotation: constraint.rotation ?? 0,
|
|
227
|
+
})),
|
|
228
|
+
sliders: sliderConstraints.map((constraint, index) => ({
|
|
229
|
+
name: constraint.name,
|
|
230
|
+
order: constraint.order ?? constraint.__order ?? index,
|
|
231
|
+
skin: constraint.skin ?? false,
|
|
232
|
+
animation: constraint.animation ?? '',
|
|
233
|
+
...(constraint.bone === undefined ? {} : { bone: constraint.bone }),
|
|
234
|
+
property: constraint.property ?? 'rotate',
|
|
235
|
+
scale: constraint.scale ?? 1,
|
|
236
|
+
offset: constraint.offset ?? 0,
|
|
237
|
+
loop: constraint.loop ?? false,
|
|
238
|
+
local: constraint.local ?? false,
|
|
239
|
+
mix: constraint.mix ?? 1,
|
|
240
|
+
})),
|
|
241
|
+
slots: (input.slots ?? []).map(slot => {
|
|
242
|
+
const color = parseColor(slot.color);
|
|
243
|
+
return {
|
|
244
|
+
name: slot.name,
|
|
245
|
+
bone: slot.bone,
|
|
246
|
+
...(slot.attachment === undefined ? {} : { attachment: slot.attachment }),
|
|
247
|
+
...(color === undefined ? {} : { color }),
|
|
248
|
+
blend: slot.blend ?? 'normal',
|
|
249
|
+
};
|
|
250
|
+
}),
|
|
251
|
+
skins,
|
|
252
|
+
skinConstraints,
|
|
253
|
+
animations: input.animations ?? {},
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
function invalidSpineData(message, path) {
|
|
257
|
+
return new EngineError(EngineErrorCode.AssetInvalidData, message, {
|
|
258
|
+
domain: ErrorDomain.Component,
|
|
259
|
+
recovery: ErrorRecovery.ReleaseResource,
|
|
260
|
+
context: { resourceType: 'skeleton/spine' },
|
|
261
|
+
path,
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
function parseColor(value) {
|
|
265
|
+
if (!value || value.length < 8)
|
|
266
|
+
return undefined;
|
|
267
|
+
return [
|
|
268
|
+
parseInt(value.slice(0, 2), 16) / 255,
|
|
269
|
+
parseInt(value.slice(2, 4), 16) / 255,
|
|
270
|
+
parseInt(value.slice(4, 6), 16) / 255,
|
|
271
|
+
parseInt(value.slice(6, 8), 16) / 255,
|
|
272
|
+
];
|
|
273
|
+
}
|
|
274
|
+
function resolveLinkedMeshes(skins) {
|
|
275
|
+
for (const [skinName, skin] of Object.entries(skins)) {
|
|
276
|
+
for (const [slotName, attachments] of Object.entries(skin)) {
|
|
277
|
+
for (const [attachmentName, attachment] of Object.entries(attachments)) {
|
|
278
|
+
if (attachment.type !== 'linkedmesh')
|
|
279
|
+
continue;
|
|
280
|
+
const sourceSkinName = attachment.skin ?? skinName;
|
|
281
|
+
const sourceName = attachment.source ?? attachmentName;
|
|
282
|
+
const source = skins[sourceSkinName]?.[slotName]?.[sourceName] ?? skins.default?.[slotName]?.[sourceName];
|
|
283
|
+
if (!source)
|
|
284
|
+
continue;
|
|
285
|
+
attachments[attachmentName] = {
|
|
286
|
+
...source,
|
|
287
|
+
...attachment,
|
|
288
|
+
type: source.type ?? 'mesh',
|
|
289
|
+
...(source.uvs === undefined ? {} : { uvs: source.uvs }),
|
|
290
|
+
...(source.triangles === undefined ? {} : { triangles: source.triangles }),
|
|
291
|
+
...(source.vertices === undefined ? {} : { vertices: source.vertices }),
|
|
292
|
+
...(source.vertexCount === undefined ? {} : { vertexCount: source.vertexCount }),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
function normalizeSkinAttachments(attachments) {
|
|
299
|
+
const normalized = {};
|
|
300
|
+
for (const [slotName, slotAttachments] of Object.entries(attachments ?? {})) {
|
|
301
|
+
normalized[slotName] = {};
|
|
302
|
+
for (const [attachmentName, attachment] of Object.entries(slotAttachments ?? {})) {
|
|
303
|
+
const { color: rawColor, ...attachmentFields } = attachment;
|
|
304
|
+
const color = typeof rawColor === 'string' ? parseColor(rawColor) : rawColor;
|
|
305
|
+
normalized[slotName][attachmentName] = {
|
|
306
|
+
...attachmentFields,
|
|
307
|
+
name: attachment.name ?? attachmentName,
|
|
308
|
+
path: attachment.path ?? attachment.name ?? attachmentName,
|
|
309
|
+
x: attachment.x ?? 0,
|
|
310
|
+
y: attachment.y ?? 0,
|
|
311
|
+
rotation: attachment.rotation ?? 0,
|
|
312
|
+
scaleX: attachment.scaleX ?? 1,
|
|
313
|
+
scaleY: attachment.scaleY ?? 1,
|
|
314
|
+
width: attachment.width ?? 0,
|
|
315
|
+
height: attachment.height ?? 0,
|
|
316
|
+
...(color === undefined ? {} : { color }),
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return normalized;
|
|
321
|
+
}
|
|
322
|
+
function normalizeTransformMixes(constraint) {
|
|
323
|
+
const targets = getTransformPropertyTargets(constraint.properties);
|
|
324
|
+
if (!targets) {
|
|
325
|
+
return {
|
|
326
|
+
mixRotate: constraint.mixRotate ?? 1,
|
|
327
|
+
mixX: constraint.mixX ?? 1,
|
|
328
|
+
mixY: constraint.mixY ?? constraint.mixX ?? 1,
|
|
329
|
+
mixScaleX: constraint.mixScaleX ?? 1,
|
|
330
|
+
mixScaleY: constraint.mixScaleY ?? constraint.mixScaleX ?? 1,
|
|
331
|
+
mixShearY: constraint.mixShearY ?? 1,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
return {
|
|
335
|
+
mixRotate: targets.rotate ? constraint.mixRotate ?? 1 : 0,
|
|
336
|
+
mixX: targets.x ? constraint.mixX ?? 1 : 0,
|
|
337
|
+
mixY: targets.y ? constraint.mixY ?? constraint.mixX ?? 1 : 0,
|
|
338
|
+
mixScaleX: targets.scaleX ? constraint.mixScaleX ?? 1 : 0,
|
|
339
|
+
mixScaleY: targets.scaleY ? constraint.mixScaleY ?? constraint.mixScaleX ?? 1 : 0,
|
|
340
|
+
mixShearY: targets.shearY ? constraint.mixShearY ?? 1 : 0,
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function getTransformPropertyTargets(properties) {
|
|
344
|
+
if (!properties || typeof properties !== 'object')
|
|
345
|
+
return null;
|
|
346
|
+
const targets = { rotate: false, x: false, y: false, scaleX: false, scaleY: false, shearY: false };
|
|
347
|
+
let hasTarget = false;
|
|
348
|
+
for (const from of Object.values(properties)) {
|
|
349
|
+
if (!from || typeof from !== 'object')
|
|
350
|
+
continue;
|
|
351
|
+
const to = from.to;
|
|
352
|
+
if (!to || typeof to !== 'object')
|
|
353
|
+
continue;
|
|
354
|
+
for (const name of Object.keys(to)) {
|
|
355
|
+
if (name in targets) {
|
|
356
|
+
targets[name] = true;
|
|
357
|
+
hasTarget = true;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
return hasTarget ? targets : null;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
const SPINE_ASSET_PARSER = Object.freeze({
|
|
365
|
+
type: 'skeleton/spine',
|
|
366
|
+
parse(input, _context) {
|
|
367
|
+
return {
|
|
368
|
+
data: normalizeSpineData(input.json),
|
|
369
|
+
regions: [...parseAtlas(input.atlasText).entries()],
|
|
370
|
+
};
|
|
371
|
+
},
|
|
372
|
+
});
|
|
373
|
+
function parseSpineAssetPayload(input) {
|
|
374
|
+
return SPINE_ASSET_PARSER.parse(input, { source: 'spine' });
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
export { SPINE_ASSET_PARSER as S, parseSpineAssetPayload as a, normalizeSpineData as n, parseAtlas as p, resolveAtlasPageImageUrl as r };
|
|
378
|
+
//# sourceMappingURL=SpineAssetParser-BSDmPge1.js.map
|