Skip to content

gameltb/io_comfyui

Repository files navigation

io_comfyui

Let Blender work with ComfyUI by ComfyScript.
This addon is still in development.

Installation

ComfyUI

You'll need an ComfyUI installation, which can be local or remote.
This addon currently requires ComfyUI to have the following nodes installed:

Blender

Install like other blender addon.
Download main.zip.
It requires the installation of dependencies in the requirements.txt. I'm not sure what to do in the environment you're using.

Usage

Basic usage

You need to start comfyui first.
Than set comfyui server address in addon preferences.
Find IO ComfyUI panel at 3D view, Usually click the N key to toggle Show/Hide.
Click the Init ComfyScript and select workflow.

Make your own workflow

This addon base on ComfyScript, You can refer to it documentation to make your own workflow.
example

hybrikx need ComfyUI_paper_playground.
Usage : set arm to SMPLX-neutral in smplx_model_300_20220615.blend which can be found in smplx_blender smplx_blender_addon_300_20220623.zip.

New workflow can be save to custom_workflows/ like example.

Use in blender script

import bpy

import io_comfyui
from io_comfyui.blender_utils import image_to_pil, pil_to_image
from io_comfyui.comfy_script.runtime.nodes import *
from io_comfyui.workflow import WorkFlowObject, run_workflow


class WorkFlow(WorkFlowObject):
    def __init__(self) -> None:
        super().__init__()

    def execute(self):
        model, clip, _ = CheckpointLoaderSimple("majicmixRealistic_v6.safetensors")
        conditioning = CLIPTextEncode("1girl", clip)
        conditioning2 = CLIPTextEncode("text, watermark", clip)
        latent = EmptyLatentImage(512, 768, 1)
        latent = KSampler(model, 0, 20, 5.0, "euler_ancestral", "karras", conditioning, conditioning2, latent, 1.0)
        vae = VAELoader("vae-ft-mse-840000-ema-pruned.safetensors")
        image = VAEDecode(latent, vae)
        return (PreviewImage(image),)

    def post_execute(self, results):
        out_images = results[0].wait()
        for i, out_image in enumerate(out_images):
            bpy_image = pil_to_image(out_image, f"script_{i}")


w = WorkFlow()
io_comfyui.CUSTOM_WORKFLOW_OBJECT = w
bpy.ops.io_comfyui.run_workflow(use_custom_workflow_obj=True)
"""or
w = WorkFlow()
run_workflow(w)
w.post_execute(w.results)
"""

Resources

About

Let Blender work with ComfyUI by ComfyScript.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages