Files
Derfuu-Derfuu_ComfyUI_Modde…/pyscripts/Nodes/Functions/Tuples.py
T
Derfuu 665c3f10b1 Debug node get additional output to be able for use in-line with other nodes;
Removed(commented) "Tuples" nodes;
Removed "TUPLES" type from "Get size" nodes; (DON'T FORGET TO REPLACE THEM IF THEY'RE PERSISTS IN YOUR WORKFLOW)
Types moved into their own class with class methods and default parameters instead of just tuples with strings and dicts;
Added "Logic node" (>, <, =, AND, OR, XOR); (idk why i did this one, but got an idea that with object recognition models to count objects and correct them in next iterations would be not so bad idea as i think. Or something like this)
changed README.md to current state of this repo
2024-04-03 03:07:33 +03:00

155 lines
3.4 KiB
Python

from custom_nodes.Derfuu_ComfyUI_ModdedNodes.pyscripts.components.fields import Field
import math
from custom_nodes.Derfuu_ComfyUI_ModdedNodes.pyscripts.components.tree import TREE_TUPLES
class Tuple:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Value_A": Field.float(),
"Value_B": Field.float(),
"round_": (["No", "Yes", "Ceil", "Floor"],),
}
}
RETURN_TYPES = ("TUPLE",)
CATEGORY = TREE_TUPLES
FUNCTION = 'get_tuple'
def get_tuple(self, Value_A: float = 0, Value_B: float = 0, round_: str = "No"):
if round_ == "No":
return ((Value_A, Value_B),)
elif round_ == "Yes":
return ((round(Value_A), round(Value_B)),)
elif round_ == "Ceil":
return ((math.ceil(Value_A), math.ceil(Value_B)),)
elif round_ == "Floor":
return ((math.floor(Value_A), math.floor(Value_B)),)
# py 3.10+
# match round:
# case "No":
# return ((Value_A, Value_B),)
# case "Yes":
# return ((int(Value_A), int(Value_B)),)
# case "Ceil":
# return ((math.ceil(Value_A), math.ceil(Value_B)),)
# case "Floor":
# return ((math.floor(Value_A), math.floor(Value_B)),)
class Int2Tuple:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Value_A": Field.int(),
"Value_B": Field.int(),
}
}
RETURN_TYPES = ("TUPLE",)
CATEGORY = TREE_TUPLES
FUNCTION = 'get_tuple'
def get_tuple(self, Value_A=0, Value_B=0):
return ((Value_A, Value_B),)
class Tuple2Float:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Tuple": ("TUPLE",),
}
}
RETURN_TYPES = ("FLOAT", "FLOAT",)
CATEGORY = TREE_TUPLES
FUNCTION = 'get_tuple'
def get_tuple(self, Tuple):
return (Tuple[0], Tuple[1],)
class Tuple2Int:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Tuple": ("TUPLE",),
}
}
RETURN_TYPES = ("INT", "INT",)
CATEGORY = TREE_TUPLES
FUNCTION = 'get_tuple'
def get_tuple(self, Tuple):
return (int(Tuple[0]), int(Tuple[1]),)
class FlipTuple:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Tuple": ("TUPLE",)
}
}
RETURN_TYPES = ("TUPLE",)
FUNCTION = "flip"
CATEGORY = TREE_TUPLES
def flip(self, Tuple):
return ((Tuple[1], Tuple[0]),)
class MultiplyTupleBy:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"Tuple": ("TUPLE",),
"Value": Field.float(),
}
}
RETURN_TYPES = ("TUPLE",)
FUNCTION = "MultiplyTuples"
CATEGORY = TREE_TUPLES
def MultiplyTuples(self, Tuple: tuple, Value: float):
Tuple = (
Tuple[0] * Value,
Tuple[1] * Value
)
return (Tuple,)