fix: 修复选区坐标同步到后端的问题
- 在 onNodeCreated 和 configure 中创建 region_coords hidden widget - 确保节点从工作流加载时 widget 也存在 - 修复蒙版边界检测:alpha < 255 都计入边界
This commit is contained in:
@@ -1250,6 +1250,16 @@ app.registerExtension({
|
||||
|
||||
const node = this;
|
||||
|
||||
// 确保 region_coords hidden widget 存在
|
||||
let coordsWidget = node.widgets?.find(w => w.name === "region_coords");
|
||||
if (!coordsWidget) {
|
||||
// ComfyUI hidden widget 需要手动创建
|
||||
coordsWidget = node.addWidget("STRING", "region_coords", "{}", () => {}, {
|
||||
serialize: true,
|
||||
hidden: true
|
||||
});
|
||||
}
|
||||
|
||||
// 监听图像变化
|
||||
const imgW = node.widgets?.find(w => w.name === "image");
|
||||
if (imgW) {
|
||||
@@ -1276,6 +1286,21 @@ app.registerExtension({
|
||||
}
|
||||
};
|
||||
|
||||
// 从工作流加载时确保 widget 存在
|
||||
const origConfigure = nodeType.prototype.configure;
|
||||
nodeType.prototype.configure = function(info) {
|
||||
if (origConfigure) origConfigure.apply(this, arguments);
|
||||
|
||||
const node = this;
|
||||
// 确保 region_coords widget 存在
|
||||
let coordsWidget = node.widgets?.find(w => w.name === "region_coords");
|
||||
if (!coordsWidget) {
|
||||
coordsWidget = node.addWidget("STRING", "region_coords", "{}", () => {}, {
|
||||
serialize: true
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
// 鼠标事件
|
||||
const origMouseDown = nodeType.prototype.onMouseDown;
|
||||
nodeType.prototype.onMouseDown = function(e, pos, canvas) {
|
||||
|
||||
Reference in New Issue
Block a user