diff --git a/blender_generic_node.py b/blender_generic_node.py index d1b8b1b..97eb0d5 100644 --- a/blender_generic_node.py +++ b/blender_generic_node.py @@ -1,6 +1,7 @@ import os import json import subprocess +import tempfile CONFIG_PATH = os.path.join(os.path.dirname(__file__), "blender_tools_config.json") WRAPPER_PATH = os.path.join(os.path.dirname(__file__), "wrapper.py") @@ -25,7 +26,8 @@ class BlenderGenericNode: } } - RETURN_TYPES = ("STRING",) + RETURN_TYPES = ("STRING", "DICT") + RETURN_NAMES = ("fbx_path", "output_json") FUNCTION = "run_blender_task" CATEGORY = "Blender" @@ -35,20 +37,34 @@ class BlenderGenericNode: if not blender_exe or not os.path.exists(blender_exe): return ("Blender path not set or invalid in blender_tools_config.json",) + # Create temporary output file + tmp_output = tempfile.NamedTemporaryFile(delete=False, suffix=".json") + tmp_output_path = tmp_output.name + tmp_output.close() + + env = os.environ.copy() env["BLEND_FILE"] = blend_file env["INPUT_MODEL"] = input_model env["CONFIG_FILE"] = config_file + env["OUTPUT_JSON"] = tmp_output_path cmd = [blender_exe, "--background", "--python", WRAPPER_PATH] result = subprocess.run(cmd, env=env, capture_output=True, text=True) print(result.stdout) - if result.returncode != 0: - print(result.stderr) - return ("Blender run failed",) + output_data = {} + fbx_path = "No FBX Exported or not set" - return ("Blender task complete",) + if os.path.exists(tmp_output_path): + try: + with open(tmp_output_path, "r") as f: + output_data = json.load(f) + fbx_path = output_data.get("fbx_export", "") + except Exception as e: + print(f"Failed to parse output JSON: {e}") + + return (fbx_path, output_data) NODE_CLASS_MAPPINGS = { "BlenderGenericNode": BlenderGenericNode diff --git a/exampleBlendFiles/MeshCleanUp.blend b/exampleBlendFiles/MeshCleanUp.blend index 6720b57..fbdb11a 100644 Binary files a/exampleBlendFiles/MeshCleanUp.blend and b/exampleBlendFiles/MeshCleanUp.blend differ diff --git a/exampleBlendFiles/SimpleRig.blend b/exampleBlendFiles/SimpleRig.blend new file mode 100644 index 0000000..ad1e109 Binary files /dev/null and b/exampleBlendFiles/SimpleRig.blend differ diff --git a/exampleBlendFiles/meshCleanUpExampleConfig.config b/exampleBlendFiles/meshCleanUpExampleConfig.config index 8aebb3e..efd6fe9 100644 --- a/exampleBlendFiles/meshCleanUpExampleConfig.config +++ b/exampleBlendFiles/meshCleanUpExampleConfig.config @@ -2,5 +2,6 @@ "decimate_ratio": 0.05, "image_size": 1024, "bake_margin": 8, - "final_height": 1.8 + "final_height": 1.8, + "center_x": True } \ No newline at end of file