From 1cbf8e5499ef1042491963b9ba0c916190c8fbed Mon Sep 17 00:00:00 2001 From: kijai Date: Thu, 2 Nov 2023 16:14:15 +0200 Subject: [PATCH] Add FloatConstant, new INT color and bugfixes --- nodes.py | 32 +++++++++++++++++++++++--------- web/js/appearance.js | 5 +++++ web/js/setgetnodes.js | 6 ++++-- 3 files changed, 32 insertions(+), 11 deletions(-) diff --git a/nodes.py b/nodes.py index e4599ac..e8fc2eb 100644 --- a/nodes.py +++ b/nodes.py @@ -13,6 +13,7 @@ import math from nodes import MAX_RESOLUTION script_dir = os.path.dirname(os.path.abspath(__file__)) + class INTConstant: @classmethod def INPUT_TYPES(s): @@ -29,7 +30,24 @@ class INTConstant: def get_value(self, value): return (value,) - + +class FloatConstant: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "value": ("FLOAT", {"default": 0.0, "min": -0xffffffffffffffff, "max": 0xffffffffffffffff, "step": 0.01}), + }, + } + + RETURN_TYPES = ("FLOAT",) + RETURN_NAMES = ("value",) + FUNCTION = "get_value" + + CATEGORY = "KJNodes" + + def get_value(self, value): + return (value,) + def gaussian_kernel(kernel_size: int, sigma: float, device=None): x, y = torch.meshgrid(torch.linspace(-1, 1, kernel_size, device=device), torch.linspace(-1, 1, kernel_size, device=device), indexing="ij") d = torch.sqrt(x * x + y * y) @@ -62,7 +80,6 @@ class CreateFluidMask: def createfluidmask(self, frames, width, height, invert, inflow_count, inflow_velocity, inflow_radius, inflow_padding, inflow_duration): out = [] masks = [] - print(frames) RESOLUTION = width, height DURATION = frames @@ -321,11 +338,11 @@ class CrossFadeImages: } crossfade_images = [] - + alphas = torch.linspace(start_level, end_level, transitioning_frames) for i in range(transitioning_frames): alpha = alphas[i] - image1 = images_1[i - transition_start_index] + image1 = images_1[i + transition_start_index] image2 = images_2[i + transition_start_index] easing_function = easing_functions.get(interpolation) alpha = easing_function(alpha) # Apply the easing function to the alpha value @@ -342,14 +359,9 @@ class CrossFadeImages: # Append the last frame result duplicated to crossfade_images remaining_frames_images = last_frame.unsqueeze(0).repeat(remaining_frames, 1, 1, 1) crossfade_images = torch.cat([crossfade_images, remaining_frames_images], dim=0) - # # Append the remaining frames from images_2 - # remaining_images_2 = images_2[transition_start_index + transitioning_frames:] - # crossfade_images = torch.cat([crossfade_images, remaining_images_2], dim=0) - # Append the beginning of images_1 beginning_images_1 = images_1[:transition_start_index] crossfade_images = torch.cat([beginning_images_1, crossfade_images], dim=0) - return (crossfade_images,) class CreateTextMask: @@ -963,6 +975,7 @@ class ColorMatch: NODE_CLASS_MAPPINGS = { "INTConstant": INTConstant, + "FloatConstant": FloatConstant, "ConditioningMultiCombine": ConditioningMultiCombine, "ConditioningSetMaskAndCombine": ConditioningSetMaskAndCombine, "ConditioningSetMaskAndCombine3": ConditioningSetMaskAndCombine3, @@ -983,6 +996,7 @@ NODE_CLASS_MAPPINGS = { } NODE_DISPLAY_NAME_MAPPINGS = { "INTConstant": "INT Constant", + "FloatConstant": "Float Constant", "ConditioningMultiCombine": "Conditioning Multi Combine", "ConditioningSetMaskAndCombine": "ConditioningSetMaskAndCombine", "ConditioningSetMaskAndCombine3": "ConditioningSetMaskAndCombine3", diff --git a/web/js/appearance.js b/web/js/appearance.js index 305c58a..843a5b5 100644 --- a/web/js/appearance.js +++ b/web/js/appearance.js @@ -7,6 +7,11 @@ app.registerExtension({ const title = node.getTitle(); switch (title) { case "INT Constant": + node.setSize([200, 58]); + node.color = "#1b4669"; + node.bgcolor = "#29699c"; + break; + case "Float Constant": node.setSize([200, 58]); node.color = LGraphCanvas.node_colors.green.color; node.bgcolor = LGraphCanvas.node_colors.green.bgcolor; diff --git a/web/js/setgetnodes.js b/web/js/setgetnodes.js index 4b6c5bf..d62379d 100644 --- a/web/js/setgetnodes.js +++ b/web/js/setgetnodes.js @@ -11,8 +11,10 @@ function setColorAndBgColor(type) { "CONDITIONING": LGraphCanvas.node_colors.brown, "IMAGE": LGraphCanvas.node_colors.pale_blue, "CLIP": LGraphCanvas.node_colors.yellow, - "INT": LGraphCanvas.node_colors.green, - "MASK": LGraphCanvas.node_colors.cyan + "FLOAT": LGraphCanvas.node_colors.green, + "MASK": LGraphCanvas.node_colors.cyan, + "INT": { color: "#1b4669", bgcolor: "#29699c"}, + }; const colors = colorMap[type];