支持spine4.3

This commit is contained in:
tianmo committed 2026-09-02 13:53:12 +08:00
1 parent 63e4f61631
commit 0656684a92
206 files changed
+100597 -1320

No files matched your search

+52 -18
View File
@@ -1,25 +1,58 @@
import {
BoundingBoxAttachment,
ClippingAttachment,
MeshAttachment,
PathAttachment,
PointAttachment,
RegionAttachment,
SkeletonJson,
type AttachmentLoader,
type Skin,
BoundingBoxAttachment as BoundingBoxAttachment43,
ClippingAttachment as ClippingAttachment43,
MeshAttachment as MeshAttachment43,
PathAttachment as PathAttachment43,
PointAttachment as PointAttachment43,
RegionAttachment as RegionAttachment43,
SkeletonJson as SkeletonJson43,
TextureRegion as TextureRegion43,
type AttachmentLoader as AttachmentLoader43,
type Sequence as Sequence43,
type Skin as Skin43,
} from '@spine-particle/spine-core-4.3'
import {
BoundingBoxAttachment as BoundingBoxAttachment42,
ClippingAttachment as ClippingAttachment42,
MeshAttachment as MeshAttachment42,
PathAttachment as PathAttachment42,
PointAttachment as PointAttachment42,
RegionAttachment as RegionAttachment42,
SkeletonJson as SkeletonJson42,
type AttachmentLoader as AttachmentLoader42,
type Skin as Skin42,
} from '@esotericsoftware/spine-core'
import { normalizeSpine38JsonFor42 } from '../spine/spine38Compatibility'
import { normalizeSpineVersion, supportedSpineVersionsText, type SupportedSpineVersion } from '../spine/spineVersion'
import type { SpineJsonMap } from './spineJsonTypes'
class ExportValidationAttachmentLoader implements AttachmentLoader {
newRegionAttachment(_skin: Skin, name: string, path: string, _sequence: any) { return new RegionAttachment(name, path) }
newMeshAttachment(_skin: Skin, name: string, path: string, _sequence: any) { return new MeshAttachment(name, path) }
newBoundingBoxAttachment(_skin: Skin, name: string) { return new BoundingBoxAttachment(name) }
newPathAttachment(_skin: Skin, name: string) { return new PathAttachment(name) }
newPointAttachment(_skin: Skin, name: string) { return new PointAttachment(name) }
newClippingAttachment(_skin: Skin, name: string) { return new ClippingAttachment(name) }
class ExportValidationAttachmentLoader42 implements AttachmentLoader42 {
newRegionAttachment(_skin: Skin42, name: string, path: string, _sequence: any) { return new RegionAttachment42(name, path) }
newMeshAttachment(_skin: Skin42, name: string, path: string, _sequence: any) { return new MeshAttachment42(name, path) }
newBoundingBoxAttachment(_skin: Skin42, name: string) { return new BoundingBoxAttachment42(name) }
newPathAttachment(_skin: Skin42, name: string) { return new PathAttachment42(name) }
newPointAttachment(_skin: Skin42, name: string) { return new PointAttachment42(name) }
newClippingAttachment(_skin: Skin42, name: string) { return new ClippingAttachment42(name) }
}
class ExportValidationAttachmentLoader43 implements AttachmentLoader43 {
private sequence(sequence: Sequence43) {
for (let index = 0; index < sequence.regions.length; index++) {
if (sequence.regions[index]) continue
const region = new TextureRegion43()
region.u = 0; region.v = 0; region.u2 = 1; region.v2 = 1
region.width = 1; region.height = 1; region.originalWidth = 1; region.originalHeight = 1
region.offsetX = 0; region.offsetY = 0; region.degrees = 0
sequence.regions[index] = region
}
return sequence
}
newRegionAttachment(_skin: Skin43, _placeholder: string, name: string, _path: string, sequence: Sequence43) { return new RegionAttachment43(name, this.sequence(sequence)) }
newMeshAttachment(_skin: Skin43, _placeholder: string, name: string, _path: string, sequence: Sequence43) { return new MeshAttachment43(name, this.sequence(sequence)) }
newBoundingBoxAttachment(_skin: Skin43, _placeholder: string, name: string) { return new BoundingBoxAttachment43(name) }
newPathAttachment(_skin: Skin43, _placeholder: string, name: string) { return new PathAttachment43(name) }
newPointAttachment(_skin: Skin43, _placeholder: string, name: string) { return new PointAttachment43(name) }
newClippingAttachment(_skin: Skin43, _placeholder: string, name: string) { return new ClippingAttachment43(name) }
}
const VALID_INHERIT = new Set(['normal', 'onlyTranslation', 'noRotationOrReflection', 'noScale', 'noScaleOrReflection'])
@@ -136,8 +169,9 @@ export function validateSpineJson(text: string, expectedVersion?: SupportedSpine
validateEditorImportStructure(root, version)
if (version === '3.8') validateSpine38Structure(root)
const runtimeRoot = version === '3.8' ? normalizeSpine38JsonFor42(JSON.parse(JSON.stringify(root))) : root
const reader = new SkeletonJson(new ExportValidationAttachmentLoader())
const data = reader.readSkeletonData(runtimeRoot)
const data = version === '4.3'
? new SkeletonJson43(new ExportValidationAttachmentLoader43()).readSkeletonData(runtimeRoot)
: new SkeletonJson42(new ExportValidationAttachmentLoader42()).readSkeletonData(runtimeRoot)
if (!data.bones.length) throw new Error('导出结果缺少骨骼')
return { version, bones: data.bones.length, slots: data.slots.length, animations: data.animations.length }
}