From 0c8bd63aa9f832726d1f49bbf311019b149c714d Mon Sep 17 00:00:00 2001 From: "kosinkadink1@gmail.com" Date: Fri, 27 Sep 2024 14:42:50 +0900 Subject: [PATCH] Added Combine versions of Cond/Cond Pair Set Props nodes, renamed Pair Cond to Cond Pair, fixed default conds never applying hooks (due to hooks key typo) --- comfy/hooks.py | 6 +++ comfy/samplers.py | 2 +- comfy_extras/nodes_hooks.py | 75 +++++++++++++++++++++++++++++++++++-- 3 files changed, 79 insertions(+), 4 deletions(-) diff --git a/comfy/hooks.py b/comfy/hooks.py index 96b37282c..145b55819 100644 --- a/comfy/hooks.py +++ b/comfy/hooks.py @@ -619,6 +619,12 @@ def combine_conditioning(conds: list): combined_conds.extend(cond) return combined_conds +def combine_with_new_conds(conds: list, new_conds: list): + combined_conds = [] + for c, new_c in zip(conds, new_conds): + combined_conds.append(combine_conditioning([c, new_c])) + return combined_conds + def set_mask_conds(conds: list, strength: float, set_cond_area: str, opt_mask: torch.Tensor=None, opt_hooks: HookGroup=None, opt_timestep_range: tuple[float,float]=None): masked_conds = [] diff --git a/comfy/samplers.py b/comfy/samplers.py index 99cfff2b3..9b33f86d9 100644 --- a/comfy/samplers.py +++ b/comfy/samplers.py @@ -178,7 +178,7 @@ def finalize_default_conds(hooked_to_run: dict[comfy.hooks.HookGroup,list[tuple[ continue # replace p's mult with calculated mult p = p._replace(mult=mult) - hook: comfy.hooks.HookGroup = x.get('hook', None) + hook: comfy.hooks.HookGroup = x.get('hooks', None) hooked_to_run.setdefault(hook, list()) hooked_to_run[hook] += [(p, i)] diff --git a/comfy_extras/nodes_hooks.py b/comfy_extras/nodes_hooks.py index 4ef639f34..700eb63cf 100644 --- a/comfy_extras/nodes_hooks.py +++ b/comfy_extras/nodes_hooks.py @@ -17,7 +17,7 @@ import folder_paths #------------------------------------------ class PairConditioningSetProperties: NodeId = 'PairConditioningSetProperties' - NodeName = 'Pair Cond Set Props' + NodeName = 'Cond Pair Set Props' @classmethod def INPUT_TYPES(s): return { @@ -46,6 +46,41 @@ class PairConditioningSetProperties: strength=strength, set_cond_area=set_cond_area, opt_mask=opt_mask, opt_hooks=opt_hooks, opt_timestep_range=opt_timesteps) return (final_positive, final_negative) + +class PairConditioningSetPropertiesAndCombine: + NodeId = 'PairConditioningSetPropertiesAndCombine' + NodeName = 'Cond Pair Set Props Combine' + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "positive": ("CONDITIONING", ), + "negative": ("CONDITIONING", ), + "positive_NEW": ("CONDITIONING", ), + "negative_NEW": ("CONDITIONING", ), + "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), + "set_cond_area": (["default", "mask bounds"],), + }, + "optional": { + "opt_mask": ("MASK", ), + "opt_hooks": ("HOOKS",), + "opt_timesteps": ("TIMESTEPS_RANGE",), + } + } + + RETURN_TYPES = ("CONDITIONING", "CONDITIONING") + RETURN_NAMES = ("positive", "negative") + CATEGORY = "advanced/hooks/cond pair" + FUNCTION = "set_properties" + + def set_properties(self, positive, negative, positive_NEW, negative_NEW, + strength: float, set_cond_area: str, + opt_mask: torch.Tensor=None, opt_hooks: comfy.hooks.HookGroup=None, opt_timesteps: tuple=None): + positive_NEW, negative_NEW = comfy.hooks.set_mask_conds(conds=[positive_NEW, negative_NEW], + strength=strength, set_cond_area=set_cond_area, + opt_mask=opt_mask, opt_hooks=opt_hooks, opt_timestep_range=opt_timesteps) + final_positive, final_negative = comfy.hooks.combine_with_new_conds(conds=[positive, negative], new_conds=[positive_NEW, negative_NEW]) + return (final_positive, final_negative) class ConditioningSetProperties: NodeId = 'ConditioningSetProperties' @@ -77,9 +112,41 @@ class ConditioningSetProperties: opt_mask=opt_mask, opt_hooks=opt_hooks, opt_timestep_range=opt_timesteps) return (final_cond,) +class ConditioningSetPropertiesAndCombine: + NodeId = 'ConditioningSetPropertiesAndCombine' + NodeName = 'Cond Set Props Combine' + @classmethod + def INPUT_TYPES(s): + return { + "required": { + "cond": ("CONDITIONING", ), + "cond_NEW": ("CONDITIONING", ), + "strength": ("FLOAT", {"default": 1.0, "min": 0.0, "max": 10.0, "step": 0.01}), + "set_cond_area": (["default", "mask bounds"],), + }, + "optional": { + "opt_mask": ("MASK", ), + "opt_hooks": ("HOOKS",), + "opt_timesteps": ("TIMESTEPS_RANGE",), + } + } + + RETURN_TYPES = ("CONDITIONING",) + CATEGORY = "advanced/hooks/cond single" + FUNCTION = "set_properties" + + def set_properties(self, cond, cond_NEW, + strength: float, set_cond_area: str, + opt_mask: torch.Tensor=None, opt_hooks: comfy.hooks.HookGroup=None, opt_timesteps: tuple=None): + (cond_NEW,) = comfy.hooks.set_mask_conds(conds=[cond_NEW], + strength=strength, set_cond_area=set_cond_area, + opt_mask=opt_mask, opt_hooks=opt_hooks, opt_timestep_range=opt_timesteps) + (final_cond,) = comfy.hooks.combine_with_new_conds(conds=[cond], new_conds=[cond_NEW]) + return (final_cond,) + class PairConditioningCombine: NodeId = 'PairConditioningCombine' - NodeName = 'Pair Cond Combine' + NodeName = 'Cond Pair Combine' @classmethod def INPUT_TYPES(s): return { @@ -102,7 +169,7 @@ class PairConditioningCombine: class PairConditioningSetDefaultAndCombine: NodeId = 'PairConditioningSetDefaultCombine' - NodeName = 'Pair Cond Set Default Combine' + NodeName = 'Cond Pair Set Default Combine' @classmethod def INPUT_TYPES(s): return { @@ -759,7 +826,9 @@ node_list = [ CombineHooksEight, # Attach ConditioningSetProperties, + ConditioningSetPropertiesAndCombine, PairConditioningSetProperties, + PairConditioningSetPropertiesAndCombine, ConditioningSetDefaultAndCombine, PairConditioningSetDefaultAndCombine, PairConditioningCombine,