新增模型补全空洞
This commit is contained in:
@@ -1869,6 +1869,69 @@ bool ProjectWorkspace::resolveBlackholeByCopyBackground(const QString& id, const
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectWorkspace::resolveBlackholeByModelInpaint(const QString& id, const QImage& patchedBackground,
|
||||
bool hideBlackholeAfterFill) {
|
||||
if (m_projectDir.isEmpty() || id.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
const QString bgAbs = backgroundAbsolutePath();
|
||||
if (bgAbs.isEmpty() || !QFileInfo::exists(bgAbs)) {
|
||||
return false;
|
||||
}
|
||||
if (patchedBackground.isNull()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// 写回背景文件
|
||||
{
|
||||
QImage bg = patchedBackground;
|
||||
if (bg.format() != QImage::Format_ARGB32_Premultiplied) {
|
||||
bg = bg.convertToFormat(QImage::Format_ARGB32_Premultiplied);
|
||||
}
|
||||
QImageWriter writer(bgAbs);
|
||||
writer.setFormat("png");
|
||||
writer.setCompression(1);
|
||||
if (!writer.write(bg)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// 更新实体黑洞状态 + 记录历史
|
||||
const auto before = m_project.entities();
|
||||
auto ents = before;
|
||||
int hit = -1;
|
||||
for (int i = 0; i < ents.size(); ++i) {
|
||||
if (ents[i].id == id) {
|
||||
hit = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hit < 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ents[hit].blackholeVisible = hideBlackholeAfterFill ? false : ents[hit].blackholeVisible;
|
||||
if (ents[hit].blackholeId.isEmpty()) {
|
||||
ents[hit].blackholeId = QStringLiteral("blackhole-%1").arg(ents[hit].id);
|
||||
}
|
||||
ents[hit].blackholeResolvedBy = QStringLiteral("model_inpaint");
|
||||
|
||||
m_project.setEntities(ents);
|
||||
if (!saveSingleEntityPayload(ents[hit]) || !writeIndexJsonWithoutPayloadSync()) {
|
||||
m_project.setEntities(before);
|
||||
return false;
|
||||
}
|
||||
|
||||
Operation op;
|
||||
op.type = Operation::Type::SetEntities;
|
||||
op.label = QStringLiteral("黑洞模型补全");
|
||||
op.beforeEntities = before;
|
||||
op.afterEntities = ents;
|
||||
pushOperation(op);
|
||||
m_redoStack.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ProjectWorkspace::setEntityVisibilityKey(const QString& id, int frame, bool visible) {
|
||||
if (m_projectDir.isEmpty() || id.isEmpty() || frame < 0) {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user