跳到主要內容

Blender Mcp

通過套接字連接至 blender-mcp 插件,從 Hermes 直接控制 Blender。創建 3D 對象、材質、動畫,並運行任意 Blender Python (bpy) 代碼。當用戶希望在 Blender 中創建或修改任何內容時使用。

技能元數據

來源可選 — 使用 hermes skills install official/creative/blender-mcp 安裝
路徑optional-skills/creative/blender-mcp
版本1.0.0
作者alireza78a

參考:完整 SKILL.md

信息

以下是 Hermes 在觸發此技能時加載的完整技能定義。這是技能激活時代理所看到的指令。

Blender MCP

通過 TCP 端口 9876 上的套接字,從 Hermes 控制正在運行的 Blender 實例。

設置(一次性)

1. 安裝 Blender 插件

curl -sL https://raw.githubusercontent.com/ahujasid/blender-mcp/main/addon.py -o ~/Desktop/blender_mcp_addon.py

在 Blender 中: 編輯 > 偏好設置 > 插件 > 安裝 > 選擇 blender_mcp_addon.py 啟用 "Interface: Blender MCP"

2. 在 Blender 中啟動套接字服務器

在 Blender 視口中按 N 鍵打開側邊欄。 找到 "BlenderMCP" 選項卡並點擊 "Start Server"(啟動服務器)。

3. 驗證連接

nc -z -w2 localhost 9876 && echo "OPEN" || echo "CLOSED"

協議

基於 TCP 的純 UTF-8 JSON -- 無長度前綴。

發送: {"type": "<command>", "params": {<kwargs>}} 接收: {"status": "success", "result": <value>} {"status": "error", "message": "<reason>"}

可用命令

typeparamsdescription
execute_codecode (str)運行任意 bpy Python 代碼
get_scene_info(none)列出場景中的所有對象
get_object_infoobject_name (str)獲取特定對象的詳細信息
get_viewport_screenshot(none)當前視口的截圖

Python 輔助函數

在 execute_code 工具調用中使用此函數:

import socket, json

def blender_exec(code: str, host="localhost", port=9876, timeout=15): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.settimeout(timeout) payload = json.dumps({"type": "execute_code", "params": {"code": code}}) s.sendall(payload.encode("utf-8")) buf = b"" while True: try: chunk = s.recv(4096) if not chunk: break buf += chunk try: json.loads(buf.decode("utf-8")) break except json.JSONDecodeError: continue except socket.timeout: break s.close() return json.loads(buf.decode("utf-8"))

常見 bpy 模式

清空場景

bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete()

添加網格對象

bpy.ops.mesh.primitive_uv_sphere_add(radius=1, location=(0, 0, 0)) bpy.ops.mesh.primitive_cube_add(size=2, location=(3, 0, 0)) bpy.ops.mesh.primitive_cylinder_add(radius=0.5, depth=2, location=(-3, 0, 0))

創建並分配材質

mat = bpy.data.materials.new(name="MyMat") mat.use_nodes = True bsdf = mat.node_tree.nodes.get("Principled BSDF") bsdf.inputs["Base Color"].default_value = (R, G, B, 1.0) bsdf.inputs["Roughness"].default_value = 0.3 bsdf.inputs["Metallic"].default_value = 0.0 obj.data.materials.append(mat)

關鍵幀動畫

obj.location = (0, 0, 0) obj.keyframe_insert(data_path="location", frame=1) obj.location = (0, 0, 3) obj.keyframe_insert(data_path="location", frame=60)

渲染到文件

bpy.context.scene.render.filepath = "/tmp/render.png" bpy.context.scene.render.engine = 'CYCLES' bpy.ops.render.render(write_still=True)

注意事項

  • 運行前必須檢查套接字是否已打開 (nc -z localhost 9876)
  • 每次會話都必須在 Blender 內部啟動插件服務器(N 面板 > BlenderMCP > Connect)
  • 將複雜場景分解為多個較小的 execute_code 調用,以避免超時
  • 渲染輸出路徑必須是絕對路徑 (/tmp/...),而非相對路徑
  • shade_smooth() 要求對象處於選中狀態且位於物體模式