From 5b1fb8db38e4ec78df10db9ba4ff69a8f62f797c Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Wed, 4 Dec 2024 11:27:07 -0500 Subject: [PATCH 1/2] add load 3d node support --- comfy_extras/nodes_load_3d.py | 116 ++++++++++++++++++++++++++++++++++ nodes.py | 1 + 2 files changed, 117 insertions(+) create mode 100644 comfy_extras/nodes_load_3d.py diff --git a/comfy_extras/nodes_load_3d.py b/comfy_extras/nodes_load_3d.py new file mode 100644 index 000000000000..50caa01eb7b2 --- /dev/null +++ b/comfy_extras/nodes_load_3d.py @@ -0,0 +1,116 @@ +import nodes +import folder_paths +import os + +def normalize_path(path): + return path.replace('\\', '/') + +class Load3D(): + @classmethod + def INPUT_TYPES(s): + input_dir = os.path.join(folder_paths.get_input_directory(), "3d") + + os.makedirs(input_dir, exist_ok=True) + + files = [normalize_path(os.path.join("3d", f)) for f in os.listdir(input_dir) if f.endswith(('.gltf', '.glb', '.obj', '.mtl', '.fbx', '.stl'))] + + return {"required": { + "model_file": (sorted(files), {"file_upload": True}), + "image": ("LOAD_3D", {}), + "width": ("INT", {"default": 1024, "min": 1, "max": 4096, "step": 1}), + "height": ("INT", {"default": 1024, "min": 1, "max": 4096, "step": 1}), + "show_grid": ([True, False],), + "camera_type": (["perspective", "orthographic"],), + "view": (["front", "right", "top", "isometric"],), + "material": (["original", "normal", "wireframe", "depth"],), + "bg_color": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFF, "step": 1, "display": "color"}), + "light_intensity": ("INT", {"default": 10, "min": 1, "max": 20, "step": 1}), + "up_direction": (["original", "-x", "+x", "-y", "+y", "-z", "+z"],), + }} + + RETURN_TYPES = ("IMAGE", "MASK", "STRING") + RETURN_NAMES = ("image", "mask", "mesh_path") + + FUNCTION = "process" + + CATEGORY = "3d" + + def process(self, model_file, image, **kwargs): + imagepath = folder_paths.get_annotated_filepath(image) + + load_image_node = nodes.LoadImage() + + output_image, output_mask = load_image_node.load_image(image=imagepath) + + return output_image, output_mask, model_file, + +class Load3DAnimation(): + @classmethod + def INPUT_TYPES(s): + input_dir = os.path.join(folder_paths.get_input_directory(), "3d") + + os.makedirs(input_dir, exist_ok=True) + + files = [normalize_path(os.path.join("3d", f)) for f in os.listdir(input_dir) if f.endswith(('.gltf', '.glb', '.fbx'))] + + return {"required": { + "model_file": (sorted(files), {"file_upload": True}), + "image": ("LOAD_3D_ANIMATION", {}), + "width": ("INT", {"default": 1024, "min": 1, "max": 4096, "step": 1}), + "height": ("INT", {"default": 1024, "min": 1, "max": 4096, "step": 1}), + "show_grid": ([True, False],), + "camera_type": (["perspective", "orthographic"],), + "view": (["front", "right", "top", "isometric"],), + "material": (["original", "normal", "wireframe", "depth"],), + "bg_color": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFF, "step": 1, "display": "color"}), + "light_intensity": ("INT", {"default": 10, "min": 1, "max": 20, "step": 1}), + "up_direction": (["original", "-x", "+x", "-y", "+y", "-z", "+z"],), + "animation_speed": (["0.1", "0.5", "1", "1.5", "2"], {"default": "1"}), + }} + + RETURN_TYPES = ("IMAGE", "MASK", "STRING") + RETURN_NAMES = ("image", "mask", "mesh_path") + + FUNCTION = "process" + + CATEGORY = "3d" + + def process(self, model_file, image, **kwargs): + imagepath = folder_paths.get_annotated_filepath(image) + + load_image_node = nodes.LoadImage() + + output_image, output_mask = load_image_node.load_image(image=imagepath) + + return output_image, output_mask, model_file, + +class Preview3D(): + @classmethod + def INPUT_TYPES(s): + return {"required": { + "model_file": ("STRING", {"default": "", "multiline": False}), + "image": ("PREVIEW_3D", {}), + "show_grid": ([True, False],), + "camera_type": (["perspective", "orthographic"],), + "view": (["front", "right", "top", "isometric"],), + "material": (["original", "normal", "wireframe", "depth"],), + "bg_color": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFF, "step": 1, "display": "color"}), + "light_intensity": ("INT", {"default": 10, "min": 1, "max": 20, "step": 1}), + "up_direction": (["original", "-x", "+x", "-y", "+y", "-z", "+z"],), + }} + + RETURN_TYPES = () + + CATEGORY = "3d" + +NODE_CLASS_MAPPINGS = { + "Load3D": Load3D, + "Load3DAnimation": Load3DAnimation, + "Preview3D": Preview3D +} + +NODE_DISPLAY_NAME_MAPPINGS = { + "Load3D": "Load 3D", + "Load3DAnimation": "Load 3D - Animation", + "Preview3D": "Preview 3D" +} \ No newline at end of file diff --git a/nodes.py b/nodes.py index 260bb5e153fc..48686514375e 100644 --- a/nodes.py +++ b/nodes.py @@ -2149,6 +2149,7 @@ def init_builtin_extra_nodes(): "nodes_slg.py", "nodes_lt.py", "nodes_hooks.py", + "nodes_load_3d.py", ] import_failed = [] From 39fdd1f0f3c800cf66a129f380c3243540d2d073 Mon Sep 17 00:00:00 2001 From: Terry Jia Date: Thu, 12 Dec 2024 20:11:57 -0500 Subject: [PATCH 2/2] remove Preview3D from BE --- comfy_extras/nodes_load_3d.py | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) diff --git a/comfy_extras/nodes_load_3d.py b/comfy_extras/nodes_load_3d.py index 50caa01eb7b2..90da9fd6768e 100644 --- a/comfy_extras/nodes_load_3d.py +++ b/comfy_extras/nodes_load_3d.py @@ -84,33 +84,12 @@ def process(self, model_file, image, **kwargs): return output_image, output_mask, model_file, -class Preview3D(): - @classmethod - def INPUT_TYPES(s): - return {"required": { - "model_file": ("STRING", {"default": "", "multiline": False}), - "image": ("PREVIEW_3D", {}), - "show_grid": ([True, False],), - "camera_type": (["perspective", "orthographic"],), - "view": (["front", "right", "top", "isometric"],), - "material": (["original", "normal", "wireframe", "depth"],), - "bg_color": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFF, "step": 1, "display": "color"}), - "light_intensity": ("INT", {"default": 10, "min": 1, "max": 20, "step": 1}), - "up_direction": (["original", "-x", "+x", "-y", "+y", "-z", "+z"],), - }} - - RETURN_TYPES = () - - CATEGORY = "3d" - NODE_CLASS_MAPPINGS = { "Load3D": Load3D, - "Load3DAnimation": Load3DAnimation, - "Preview3D": Preview3D + "Load3DAnimation": Load3DAnimation } NODE_DISPLAY_NAME_MAPPINGS = { "Load3D": "Load 3D", - "Load3DAnimation": "Load 3D - Animation", - "Preview3D": "Preview 3D" + "Load3DAnimation": "Load 3D - Animation" } \ No newline at end of file