【修复】角色被格线切断(脚、手杖、飘起的斗篷被削掉) 新增 expand_beyond_cell(默认开启):格子只用来判定「这是哪个方向」, 角色的实际范围由它自身的连通区域决定,按质心归属确保邻居不混入。 实测 8/8 方向的裁剪框边缘 alpha 从 1.00(内容顶到边界=被切断) 降到 0.00,S 方向高度 326→356、E 方向宽度 150→188 把缺的部分找了回来。 代价是需要两遍扫描(先求全序列并集框再提取),耗时 4.7s→14.9s。 【规则】每个参数都必须有中文 tooltip,作为以后的统一约定 全仓库 26 个节点 169 个参数,此前缺 115 个,现已 100% 覆盖。 tooltip 写「怎么调」而不只是「是什么」:给取值区间的实际影响、 推荐值与踩坑提示(如 OpenAI/ZenMux 的地址栏不能带 :// , 素材拆分节点用于动画序列时顺序会漂移等)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
105 lines
4.2 KiB
Python
105 lines
4.2 KiB
Python
import re
|
|
|
|
class ShotSplitterNode:
|
|
"""
|
|
镜头分词器节点:将输入的多分镜描述脚本拆分成独立的分镜描述
|
|
"""
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(cls):
|
|
return {
|
|
"required": {
|
|
"input_text": ("STRING", {
|
|
"multiline": True,
|
|
"default": "",
|
|
"tooltip": "多分镜脚本原文。节点会识别「镜头1 / 分镜2 / Shot 3」\n"
|
|
"这类编号标记,把整段脚本拆成一条条独立的分镜描述。"
|
|
}),
|
|
},
|
|
"optional": {
|
|
"start_shot_num": ("INT", {
|
|
"default": 0,
|
|
"min": 0,
|
|
"max": 100,
|
|
"step": 1,
|
|
"tooltip": "从第几号镜头开始取,0 表示从头开始。\n"
|
|
"用于跳过前面已经出过图的镜头。"
|
|
}),
|
|
"shot_count": ("INT", {
|
|
"default": 0,
|
|
"min": 0,
|
|
"max": 100,
|
|
"step": 1,
|
|
"tooltip": "取多少个镜头,0 表示一直取到结尾。\n"
|
|
"与上面的起始号配合,可以分批处理长脚本。"
|
|
}),
|
|
},
|
|
}
|
|
|
|
RETURN_TYPES = ("LIST", "STRING")
|
|
RETURN_NAMES = ("shot_descriptions", "summary")
|
|
FUNCTION = "split_shots"
|
|
CATEGORY = "Rui-Node🐶/文本处理📝"
|
|
|
|
def split_shots(self, input_text, start_shot_num=0, shot_count=0):
|
|
"""
|
|
将输入的多分镜描述脚本拆分成独立的分镜描述
|
|
|
|
参数:
|
|
input_text: 输入的多分镜描述脚本
|
|
|
|
返回:
|
|
shot_descriptions: 拆分后的分镜描述列表(Python列表格式的字符串)
|
|
summary: 总结信息
|
|
"""
|
|
# 使用正则表达式匹配所有分镜内容
|
|
# 匹配<SHOT_XXX>和</SHOT_XXX>之间的内容,其中XXX是数字
|
|
pattern = r'<SHOT_(\d+)>([\s\S]*?)</SHOT_\1>'
|
|
matches = re.findall(pattern, input_text)
|
|
|
|
# 提取分镜描述
|
|
shot_descriptions = []
|
|
for shot_num, content in matches:
|
|
# 去除开头和结尾的空白字符,但保留内部段落结构
|
|
content = content.strip()
|
|
shot_descriptions.append(content)
|
|
|
|
# 根据开始和结束分镜编号筛选分镜
|
|
filtered_shots = []
|
|
all_shot_nums = [int(shot_num) for shot_num, _ in matches]
|
|
|
|
# 如果用户没有输入开始编号和导出数量(都为0),则导出所有分镜
|
|
if start_shot_num == 0 and shot_count == 0:
|
|
filtered_shots = shot_descriptions
|
|
else:
|
|
# 如果没有设置开始编号,则从第一个分镜开始
|
|
if start_shot_num == 0:
|
|
start_shot_num = min(all_shot_nums) if all_shot_nums else 0
|
|
|
|
# 计算结束编号
|
|
end_shot_num = start_shot_num + shot_count - 1 if shot_count > 0 else max(all_shot_nums)
|
|
|
|
# 筛选指定范围内的分镜
|
|
for i, (shot_num, content) in enumerate(matches):
|
|
if start_shot_num <= int(shot_num) <= end_shot_num:
|
|
filtered_shots.append(shot_descriptions[i])
|
|
|
|
# 生成总结信息
|
|
if start_shot_num > 0 or shot_count > 0:
|
|
end_num = start_shot_num + shot_count - 1 if shot_count > 0 else max(all_shot_nums)
|
|
summary = f"一共拆分成{len(shot_descriptions)}个分镜,导出了{len(filtered_shots)}个分镜(从{start_shot_num}开始,共{shot_count if shot_count > 0 else '全部'}个)。"
|
|
else:
|
|
summary = f"一共拆分成{len(shot_descriptions)}个分镜。"
|
|
|
|
# 直接返回Python列表,不转换为字符串
|
|
return (filtered_shots, summary)
|
|
|
|
# 节点映射字典,用于 ComfyUI 注册节点
|
|
NODE_CLASS_MAPPINGS = {
|
|
"ShotSplitter": ShotSplitterNode
|
|
}
|
|
|
|
# 节点显示名称映射,用于在 UI 中显示友好名称
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"ShotSplitter": "镜头分词器 / Shot Splitter"
|
|
} |