Skip to content

feat: 将Atlas的scale参数处理移动至skel中,实现无损4→3降级#29

Draft
Agent-0808 wants to merge 7 commits into
wang606:mainfrom
Agent-0808:main
Draft

feat: 将Atlas的scale参数处理移动至skel中,实现无损4→3降级#29
Agent-0808 wants to merge 7 commits into
wang606:mainfrom
Agent-0808:main

Conversation

@Agent-0808

Copy link
Copy Markdown
Contributor

功能:--atlas-scale 参数实现

相关issue: #20 #28

声明:代码是我vibe出来的,我确实不太懂spine内部格式,但是我用手头的素材测试了一下可以正常使用。
至于有没有更好的实现方法我就不清楚了233

保留了原方案为默认方案,新实现的无损转换功能通过--atlas-scale参数开启。

下方的报告也是AI代写

背景

Spine 4.x Atlas 支持 scale 参数(如 scale: 0.6 或 1.27),Spine 3.x 不支持。
传统降级方案通过缩放 PNG 图像处理,导致像素精度损失。

方案

将 Atlas scale 操作转移到 Skel 文件的浮点数据转换中,实现无损转换。

实现细节

applyAtlasScale(SkeletonData& data, double scale) 函数处理以下数据:

  1. 骨骼位置bone.x, bone.y, bone.length × scale
  2. 根骨骼反向缩放root.scaleX, root.scaleY × (1/scale),恢复设计尺寸
  3. Region Attachmentx, y, width, height × scale
  4. Mesh Attachment
    • width, height × scale
    • vertices 处理:
      • 加权网格:[boneCount, boneIdx, weight, x, y, ...] 循环格式,只缩放 x, y 坐标
      • 非加权网格:[x, y, x, y, ...] 直接缩放所有坐标
  5. Linked Mesh / Bounding Box / Path:相应数据 × scale
  6. Skeleton 尺寸width, height × (1/scale)

使用方式

方式一:Python 脚本

# 无损模式:保留原图,scale 应用到 skel 浮点数据
python Spine4xTo38Converter.py input.skel output_dir --converter converter.exe --lossless

# 默认模式:缩放 PNG,scale 应用到 atlas 整数坐标(有损)
python Spine4xTo38Converter.py input.skel output_dir --converter converter.exe

方式二:手动调用

# C++ 程序
SpineSkeletonDataConverter input.skel output.skel --atlas-scale 0.75

# Atlas 降级(移除 scale 参数,保持坐标不变)
python SpineAtlasDowngrade.py input.atlas output_dir --ignore-scale

文件更新

  • src/main.cpp:添加 applyAtlasScale() 函数和 --atlas-scale 参数
  • tools/Spine4xTo38Converter.py:添加 --lossless 模式,集成 atlas scale 处理逻辑
  • tools/SpineAtlasDowngrade.py:添加 --ignore-scale 参数

此前处理加权网格时错误地缩放了 vertices 中的所有元素,导致 vector 越界。

修复:只缩放 x, y 坐标,跳过 boneCount、bone index 和 weight。
调整 applyAtlasScale 函数,区分加权和非加权网格的缩放逻辑,对非加权网格直接缩放全部顶点坐标
@Agent-0808
Agent-0808 marked this pull request as draft June 24, 2026 06:33
@Agent-0808

Copy link
Copy Markdown
Contributor Author

发现还是有不对的地方

yCENzh added a commit to yCENzh/SpineSkeletonDataConverter that referenced this pull request Jul 14, 2026
- curve: 增加 epsilon 阈值保护贝塞尔曲线归一化除零 (PR #33)
- curve: 4.x→3.x 转换时截断多分量曲线残留数据 (PR #33)
- writer(42): 加权网格判断 `>` 改为 `!=` 更精确 (PR #31)
- cmake: 输出目录改为 bin/ (exe) 和 lib/ (静态库) (PR #26)
- common: 添加 <sstream> 头文件包含 (PR #26)
- gitignore: 忽略更多构建产物 (PR #26)
- converter: SpineConverter.py 跨平台搜索可执行文件 (PR #26)
- atlas: SpineAtlasDowngrade.py 新增 --ignore-scale 无损模式 (PR #29)

Refs:
  wang606/SpineSkeletonDataConverter#33
  wang606/SpineSkeletonDataConverter#31
  wang606/SpineSkeletonDataConverter#29
  wang606/SpineSkeletonDataConverter#26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant