显示调整

This commit is contained in:
tianmo committed 2026-08-29 12:32:11 +08:00
1 parent 178a7d8412
commit b5ac9552a1
9 files changed
+1064 -81

No files matched your search

+39 -2
View File
@@ -10,11 +10,19 @@ interface RuntimeEntry {
animation: string
}
export interface SpineBoneWorldTransform {
x: number
y: number
rotation: number
scaleX: number
scaleY: number
}
export class SpineRuntimeLayer {
readonly container = new Container()
private entries = new Map<number, RuntimeEntry>()
sync(objects: SpineSceneObject[], frame: number, fps: number, showResources = true) {
sync(objects: SpineSceneObject[], frame: number, fps: number) {
for (const [id, entry] of this.entries) {
if (objects.some((object) => object.id === id)) continue
this.container.removeChild(entry.root)
@@ -47,7 +55,7 @@ export class SpineRuntimeLayer {
const root = entry.root
const spine = entry.spine
const visible = showResources && object.enabled
const visible = object.visible !== false && object.enabled
root.visible = visible
root.renderable = visible
root.position.set(object.x, -object.y)
@@ -71,6 +79,35 @@ export class SpineRuntimeLayer {
}
}
getBoneWorldTransform(objectId: number, boneName: string): SpineBoneWorldTransform | null {
const entry = this.entries.get(objectId)
const bone = entry?.spine.skeleton.findBone(boneName)
if (!entry || !bone || !bone.active) return null
// Spine 骨骼矩阵位于 Spine 对象局部空间;与外层 Pixi 容器矩阵组合后,
// 再把屏幕 Y 向下坐标转换为编辑器使用的数学坐标(Y 向上)。
const root = entry.root
const cos = Math.cos(root.rotation)
const sin = Math.sin(root.rotation)
const ra = cos * root.scale.x
const rb = -sin * root.scale.y
const rc = sin * root.scale.x
const rd = cos * root.scale.y
const a = ra * bone.a + rb * bone.c
const b = ra * bone.b + rb * bone.d
const c = rc * bone.a + rd * bone.c
const d = rc * bone.b + rd * bone.d
const screenX = root.position.x + ra * bone.worldX + rb * bone.worldY
const screenY = root.position.y + rc * bone.worldX + rd * bone.worldY
return {
x: screenX,
y: -screenY,
rotation: -Math.atan2(c, a) * 180 / Math.PI,
scaleX: Math.max(0.0001, Math.hypot(a, c)),
scaleY: Math.max(0.0001, Math.hypot(b, d)),
}
}
destroy() {
for (const entry of this.entries.values()) {
entry.root.removeFromParent()