File size: 5,884 Bytes
baa8e90 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
from impact.utils import any_typ
import comfy_extras.nodes_mask
from nodes import MAX_RESOLUTION
class GeneralSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"sel_mode": ("BOOLEAN", {"default": True, "label_on": "select_on_prompt", "label_off": "select_on_execution", "forceInput": False}),
},
"optional": {
"input1": (any_typ,),
},
"hidden": {"unique_id": "UNIQUE_ID", "extra_pnginfo": "EXTRA_PNGINFO"}
}
RETURN_TYPES = (any_typ, "STRING", "INT")
RETURN_NAMES = ("selected_value", "selected_label", "selected_index")
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, *args, **kwargs):
selected_index = int(kwargs['select'])
input_name = f"input{selected_index}"
selected_label = input_name
node_id = kwargs['unique_id']
nodelist = kwargs['extra_pnginfo']['workflow']['nodes']
for node in nodelist:
if str(node['id']) == node_id:
inputs = node['inputs']
for slot in inputs:
if slot['name'] == input_name and 'label' in slot:
selected_label = slot['label']
break
if input_name in kwargs:
return (kwargs[input_name], selected_label, selected_index)
else:
print(f"ImpactSwitch: invalid select index (ignored)")
return (None, "", selected_index)
class GeneralInversedSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 999999, "step": 1}),
"input": (any_typ,),
},
"hidden": {"unique_id": "UNIQUE_ID"},
}
RETURN_TYPES = tuple([any_typ] * 100)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, input, unique_id):
res = []
for i in range(0, select):
if select == i+1:
res.append(input)
else:
res.append(None)
return res
class ImageMaskSwitch:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"select": ("INT", {"default": 1, "min": 1, "max": 4, "step": 1}),
"images1": ("IMAGE",),
},
"optional": {
"mask1_opt": ("MASK",),
"images2_opt": ("IMAGE",),
"mask2_opt": ("MASK",),
"images3_opt": ("IMAGE",),
"mask3_opt": ("MASK",),
"images4_opt": ("IMAGE",),
"mask4_opt": ("MASK",),
},
}
RETURN_TYPES = ("IMAGE", "MASK",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, select, images1, mask1_opt=None, images2_opt=None, mask2_opt=None, images3_opt=None, mask3_opt=None,
images4_opt=None, mask4_opt=None):
if select == 1:
return images1, mask1_opt,
elif select == 2:
return images2_opt, mask2_opt,
elif select == 3:
return images3_opt, mask3_opt,
else:
return images4_opt, mask4_opt,
class RemoveNoiseMask:
@classmethod
def INPUT_TYPES(s):
return {"required": {"samples": ("LATENT",)}}
RETURN_TYPES = ("LATENT",)
FUNCTION = "doit"
CATEGORY = "ImpactPack/Util"
def doit(self, samples):
res = {key: value for key, value in samples.items() if key != 'noise_mask'}
return (res, )
class ImagePasteMasked:
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"destination": ("IMAGE",),
"source": ("IMAGE",),
"x": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
"y": ("INT", {"default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1}),
"resize_source": ("BOOLEAN", {"default": False}),
},
"optional": {
"mask": ("MASK",),
}
}
RETURN_TYPES = ("IMAGE",)
FUNCTION = "composite"
CATEGORY = "image"
def composite(self, destination, source, x, y, resize_source, mask = None):
destination = destination.clone().movedim(-1, 1)
output = comfy_extras.nodes_mask.composite(destination, source.movedim(-1, 1), x, y, mask, 1, resize_source).movedim(1, -1)
return (output,)
from impact.utils import any_typ
class ImpactLogger:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"data": (any_typ, ""),
},
"hidden": {"prompt": "PROMPT", "extra_pnginfo": "EXTRA_PNGINFO"},
}
CATEGORY = "ImpactPack/Debug"
OUTPUT_NODE = True
RETURN_TYPES = ()
FUNCTION = "doit"
def doit(self, data, prompt, extra_pnginfo):
shape = ""
if hasattr(data, "shape"):
shape = f"{data.shape} / "
print(f"[IMPACT LOGGER]: {shape}{data}")
print(f" PROMPT: {prompt}")
# for x in prompt:
# if 'inputs' in x and 'populated_text' in x['inputs']:
# print(f"PROMP: {x['10']['inputs']['populated_text']}")
#
# for x in extra_pnginfo['workflow']['nodes']:
# if x['type'] == 'ImpactWildcardProcessor':
# print(f" WV : {x['widgets_values'][1]}\n")
return {}
class ImpactDummyInput:
@classmethod
def INPUT_TYPES(s):
return {"required": {}}
CATEGORY = "ImpactPack/Debug"
RETURN_TYPES = (any_typ,)
FUNCTION = "doit"
def doit(self):
return ("DUMMY",)
|