forked from cganimitta/ComfyUI_CGAnimittaTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlender_Bridge.py
More file actions
61 lines (52 loc) · 1.78 KB
/
Blender_Bridge.py
File metadata and controls
61 lines (52 loc) · 1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import socket
from pathlib import Path
class BlenderBridgeNode:
"""
Custom node for sending 3D models to Blender
Inputs:
model_path: Absolute path to 3D model file
port: Blender's listening port (must match)
"""
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"model_path": ("STRING", {
"default": "",
"multiline": False,
"dynamicPrompts": False,
}),
"port": ("INT", {
"default": 54321,
"min": 1024,
"max": 65535,
"step": 1,
}),
},
}
RETURN_TYPES = ()
FUNCTION = "send_model"
OUTPUT_NODE = True
CATEGORY = "CGAnimittaTools"
def send_model(self, model_path, port):
clean_path = Path(model_path.strip())
# 验证文件
if not clean_path.exists():
raise ValueError(f"File does not exist: {clean_path}")
if clean_path.suffix.lower() not in ['.obj', '.fbx', '.glb', '.gltf']:
raise ValueError(f"Unsupported format: {clean_path.suffix}")
# 发送到Blender
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(5)
s.connect(('localhost', port))
s.sendall(str(clean_path.resolve()).encode())
print(f"[Comfy->Blender] Sent: {clean_path}")
except ConnectionRefusedError:
raise RuntimeError(
f"Connection refused (port {port}). "
"Ensure Blender server is running!"
)
except Exception as e:
raise RuntimeError(f"Network error: {str(e)}")
return ()