Skip to content

fix(jacket): 打包自制封面时限制尺寸,避免超大纹理导致选歌卡顿 - #81

Merged
clansty merged 3 commits into
MuNET-OSS:mainfrom
HuimanQAQ:fix/jacket-max-size
Nov 6, 2026
Merged

clansty merged 3 commits into
MuNET-OSS:mainfrom
HuimanQAQ:fix/jacket-max-size

Conversation

@HuimanQAQ

@HuimanQAQ HuimanQAQ commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

问题

导入自制曲目时,MCM 会把原图尺寸直接写进大封面 AB(jacket),并且纹理格式固定为未压缩的 RGBA32、无 mipmap。官方封面是 400×400 的 BC7。

实测某游戏数据(A5xx 包,329 首自制曲):

官方 自制
尺寸 400×400(老歌 256×256) 原图尺寸,最大 3000×3000
格式 BC7 / DXT1 RGBA32 未压缩
单文件 130~180 KB 最大 18.6 MB
显存 0.16 MB 最大 34.3 MB

共 69 个封面 ≥400 KB,合计 158 MB 文件、347 MB 显存(同样数量的官方封面只需约 11 MB)。游戏的 AssetBundleDB.load() 是同步 LoadFromFile + LoadAsset,换成这种超大纹理时会出现明显掉帧。

改动

  • AssetBundleCreator 新增 MaxJacketDimension = 400,并给 CreateTextureAssetBundle / RepackTextureAssetBundle 增加 maxDimension 参数:超过上限时按长边等比缩放(ResizeMode.Max,Lanczos3,只缩不放,不裁剪、不改变宽高比)
  • 四处写封面大图的路径统一走该上限:导入封面(CreateMusicJacketAssetBundles)、改 ID 重打包(MusicTransferController)、图片转 AB 工具(ImageToAbToolController)、mcm makeab
  • jacket_s 仍然是 200×200,不受影响

验证

  • dotnet build MaiChartManager.CLI -c Crack 通过
  • 用 mcm makeab 处理 3000×3000 与 1736×1604 的测试图,产物为 400×400 与 400×370
  • 重打包后的 bundle 结构与现有 MCM 产物一致(Texture2D pathID / AssetBundle container / preload 均不变)

注意

只影响新写入的封面。已经导入的曲目需要重新导入封面,或者用一次性脚本把现有的大封面重打包(我可以另外提供,未包含在本 PR 内)。

View guided diff

Sourcery 摘要

在创建资源包时限制大型夹克纹理的尺寸,以降低内存使用量并提升加载性能。

错误修复:

  • 将新打包的大型夹克纹理的最大尺寸限制为 400 像素,以缩小过大的资源包,并防止选择界面出现卡顿。

功能增强:

  • 在夹克导入、重新打包、图像转换和 CLI 资源包创建过程中,统一按比例缩小纹理尺寸,同时保持小型夹克不变。
Original summary in English

Sourcery 总结

将新生成的封面纹理最长边限制为 400 像素,以减少加载开销并防止游戏界面卡顿。

错误修复:

  • 将新打包的大尺寸封面纹理的最大尺寸限制为 400 像素,减少可能导致歌曲选择界面卡顿的过量资源包和内存占用。

增强功能:

  • 在封面导入、重新打包、图像转换和命令行资源包创建过程中统一应用保持宽高比的缩放处理,同时保持小尺寸封面不变。
Original summary in English

Sourcery 总结

将生成的封面纹理最长边限制为 400 像素,以减小资源体积并提升加载性能。

错误修复:

  • 将新打包的大尺寸封面纹理的最大尺寸限制为 400 像素,以减少内存使用,并避免过大的纹理导致歌曲选择界面卡顿。

功能增强:

  • 在音乐导入、纹理重新打包、图像转换和 makeab CLI 中统一按比例缩放封面,同时保持小尺寸封面不变。
Original summary in English

Summary by Sourcery

Limit generated jacket textures to a maximum 400-pixel edge to reduce asset size and improve loading performance.

Bug Fixes:

  • Limit newly packaged large jacket textures to a 400-pixel maximum dimension to reduce memory usage and prevent song-selection stuttering from oversized textures.

Enhancements:

  • Apply proportional jacket resizing consistently across music imports, texture repacking, image conversion, and the makeab CLI while leaving small jackets unchanged.

自制封面会把原图尺寸直接写进 AB,且固定为未压缩的 RGBA32。实测游戏数据里
存在 3000x3000 的封面(34 MB 显存 / 18.6 MB 文件),而官方封面是 400x400
BC7(0.16 MB / 130 KB),游戏同步加载时会造成明显掉帧。

- AssetBundleCreator 新增 MaxJacketDimension = 400,大封面按长边等比缩放
  (只缩不放,保持原宽高比,Lanczos3)
- 导入封面、改 ID 重打包、图片转 AB 工具、mcm makeab 统一应用该上限
- jacket_s 仍然是 200x200,不受影响
@sourcery-ai

sourcery-ai Bot commented Nov 2, 2026 •

Copy link
Copy Markdown
Contributor

审查者指南

API

公开 400 像素的封面尺寸上限,以及纹理创建和重新打包时可选的 maxDimension 参数,并说明它们如何与显式调整尺寸的参数交互。

  • MaiChartManager/Utils/AssetBundleCreator.cs L15-22、L42-50(+3 处小改动)

API 的使用场景

在导入、传输、图像转换和 CLI 打包流程中创建大封面时,应用封面尺寸限制。

  • MaiChartManager.CLI/Commands/MakeAbCommand.cs L95-96
  • MaiChartManager/Controllers/Music/MusicTransferController.cs L529-530
  • MaiChartManager/Controllers/Tools/ImageToAbToolController.cs L111-112
  • MaiChartManager/Utils/AssetBundleCreator.cs L210-211

实现

先执行显式拉伸,再独立检查最大尺寸并保持宽高比;同时将尺寸限制传递给创建和重新打包辅助方法。

  • MaiChartManager/Utils/AssetBundleCreator.cs L38-39、L62-80、L243

提示和命令

与 Sourcery 互动

  • 触发新一轮审查: 在拉取请求中评论 @sourcery-ai review。
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 根据审查评论创建 GitHub issue: 回复审查评论,请 Sourcery 根据该评论创建 issue。也可以在审查评论下回复 @sourcery-ai issue 来创建 issue。
  • 生成拉取请求标题: 在拉取请求标题中的任意位置写入 @sourcery-ai,即可随时生成标题。也可以在拉取请求中评论 @sourcery-ai title,随时重新生成标题。
  • 生成拉取请求摘要: 在拉取请求正文中的任意位置写入 @sourcery-ai summary,即可在指定位置随时生成 PR 摘要。也可以在拉取请求中评论 @sourcery-ai summary,随时重新生成摘要。
  • 生成审查者指南: 在拉取请求中评论 @sourcery-ai guide,即可随时重新生成审查者指南。
  • 解决所有 Sourcery 评论: 在拉取请求中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。如果你已处理完所有评论且不想再看到它们,这个命令会很有用。
  • 忽略所有 Sourcery 审查: 在拉取请求中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。尤其适用于你想重新开始新一轮审查的情况——别忘了评论 @sourcery-ai review 来触发新一轮审查!

自定义体验

访问你的控制面板,即可:

  • 启用或停用审查功能,例如 Sourcery 生成的拉取请求摘要、审查者指南等。
  • 更改审查语言。
  • 添加、删除或编辑自定义审查说明。
  • 调整其他审查设置。

获取帮助

Original review guide in English

Reviewer's Guide

API

Expose the 400-pixel jacket limit and optional maxDimension parameters on texture creation and repacking, documenting how they interact with explicit resize dimensions.

  • MaiChartManager/Utils/AssetBundleCreator.cs L15-22, L42-50 (+3 small edits)

Uses of the API

Apply the jacket dimension limit to large-cover creation in import, transfer, image conversion, and CLI packaging paths.

  • MaiChartManager.CLI/Commands/MakeAbCommand.cs L95-96
  • MaiChartManager/Controllers/Music/MusicTransferController.cs L529-530
  • MaiChartManager/Controllers/Tools/ImageToAbToolController.cs L111-112
  • MaiChartManager/Utils/AssetBundleCreator.cs L210-211

Implementation

Implement explicit stretching followed by an independent, aspect-ratio-preserving maximum-dimension check, and forward the limit through the creation and repacking helpers.

  • MaiChartManager/Utils/AssetBundleCreator.cs L38-39, L62-80, L243

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

嘿——我发现了 1 个问题

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="MaiChartManager/Utils/AssetBundleCreator.cs" line_range="34" />
<code_context>
         int? resizeWidth = null,
-        int? resizeHeight = null)
+        int? resizeHeight = null,
+        int? maxDimension = null)
     {
         if (!File.Exists(imagePath))
</code_context>
<issue_to_address>
**Previously compiled callers fail**

When an external consumer has compiled against the previous `MaiChartManager` assembly and runs against this version, the CLR method signatures change, so an already-compiled consumer still requesting the old overload gets `MissingMethodException` when it calls `CreateTextureAssetBundle` or `RepackTextureAssetBundle`. Optional parameters only preserve source compatibility after recompilation; they do not preserve the old method entries in the assembly.

Retain the original public signatures as forwarding overloads and expose the new parameter through additional overloads.

Also at `MaiChartManager/Utils/AssetBundleCreator.cs:50`, `MaiChartManager/Utils/AssetBundleCreator.cs:217`.
</issue_to_address>

Sourcery 评估

需要人工审查。 有 1 项发现需要先处理;打包过程现在会在写入资源包之前缩小过大的夹克纹理,因此即使撤销此更改,错误的限制值也可能导致生成的资源包图像细节降低。可以使用原始图像或源资源包重新构建,因此影响范围有限且可以修复。

阻塞性发现:MaiChartManager/Utils/AssetBundleCreator.cs:34


Sourcery 对开源项目免费——如果您喜欢我们的评审,请考虑分享 ✨
Original comment in English

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="MaiChartManager/Utils/AssetBundleCreator.cs" line_range="34" />
<code_context>
         int? resizeWidth = null,
-        int? resizeHeight = null)
+        int? resizeHeight = null,
+        int? maxDimension = null)
     {
         if (!File.Exists(imagePath))
</code_context>
<issue_to_address>
**Previously compiled callers fail**

When an external consumer has compiled against the previous `MaiChartManager` assembly and runs against this version, the CLR method signatures change, so an already-compiled consumer still requesting the old overload gets `MissingMethodException` when it calls `CreateTextureAssetBundle` or `RepackTextureAssetBundle`. Optional parameters only preserve source compatibility after recompilation; they do not preserve the old method entries in the assembly.

Retain the original public signatures as forwarding overloads and expose the new parameter through additional overloads.

Also at `MaiChartManager/Utils/AssetBundleCreator.cs:50`, `MaiChartManager/Utils/AssetBundleCreator.cs:217`.
</issue_to_address>

Sourcery assessment

Needs a human reviewer. 1 finding to address first, and packaging now downsizes oversized jacket textures before writing the asset bundle, so a mistaken limit can leave generated bundles with reduced image detail even after this change is reverted. The original image or source bundle can be used to rebuild them, making the impact bounded and repairable.

Blocking findings: MaiChartManager/Utils/AssetBundleCreator.cs:34


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 4 files

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

- 显式尺寸与 maxDimension 的优先级改用 GetResizeOptions 显式表达,不再靠 else if 静默吞掉 maxDimension

- 显式尺寸分支必须指定 Mode = Stretch:ResizeOptions 默认值是 Crop,直接替换 Resize(w, h) 会变成居中裁剪

- 给 CreateTextureAssetBundle 补 XML 文档,说明 resizeWidth/resizeHeight/maxDimension 的优先级与是否保持宽高比

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Requires human review: Auto-approval blocked by 1 unresolved issue from previous reviews.
Tip: Get a Slack DM when cubic finishes reviewing your PRs. Connect Slack

View guided diff | Re-trigger cubic

- 原来写成 else if,同时给 resizeWidth/resizeHeight 和 maxDimension 时上限会被整体跳过,超大纹理照样写进 AB

- 现在显式尺寸先应用,随后独立判断长边是否超上限,任何调用组合都不会产出超限纹理

- 去掉仅为表达优先级而引入的 GetResizeOptions,逻辑回到一处,显式尺寸分支显式写 Stretch 避免 ResizeOptions 默认 Crop 造成裁剪

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

0 issues found across 1 file (changes from recent commits).

Auto-approved: 打包大封面时统一按最长边 400 等比缩小(只缩不放、不裁剪),避免超大 RGBA32 纹理同步加载导致选歌卡顿;改动只影响新写入的封面,小封面保持 200 不变,行为边界清晰且收益明确。

View guided diff | Re-trigger cubic

@clansty
clansty merged commit ce8ebff into MuNET-OSS:main Nov 6, 2026
3 checks passed
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.

2 participants