Community影像github.com

m4bwav/polywright-blender

用於 Blender 腳本化、自動化或除錯時,在撰寫任何 bpy 程式碼之前使用:無頭執行、回報錯誤、bpy API 陷阱、測試過的食譜、MCP 伺服器風險及其他作業系統的 3D 工具。

polywright-blender 是什麼?

此技能為 AI 代理提供一個完整的 Blender 自動化框架,涵蓋從環境檢測、無頭腳本執行、API 陷阱處理到常見工作流程(如修改器、布林運算、重網格、UV、烘焙、旋轉台、深度通道、批量匯出)的完整解決方案。它強烈建議在副本上進行無頭執行,並透過簡短文字報告而非即時螢幕截圖來驅動 Blender。技能支援 Blender 5.x(特別是 LTS 5.2),並內建 bpy 腳本規範、錯誤處理與重試機制,以及兩個 Blender MCP 伺服器的風險評估與使用指南。此外,它還涵蓋了其他 3D 工具的跨平台版本說明,確保代理能在 Windows、macOS 和 Linux 上正確運作。透過 pw.py 輔助腳本,它可以統一管理 Blender 的發現、執行、渲染、轉換、LOD 生成等任務,並提供豐富的食譜參考檔案,適用於場景、物理、動作與道具設計等進階需求。

相容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/m4bwav/polywright/tree/HEAD/skills/polywright-blender

Installed? Explore more 影像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

polywright-blender 是做什麼的?

Blender 是主力工具:免費、支援所有作業系統、可腳本化到每個按鈕。代理最好以無頭模式驅動它,在副本上執行,並產生簡短的文字報告,而非透過即時畫面的螢幕截圖。 返回中心:../polywright/SKILL.md。 深度參考:references/bpy-api-traps.md、references/bpy-recipes.md、 references/bpy-recipes-scenes.md 和 references/bpy-recipes-physics.md (每個食譜都由測試套件執行)、 references/mcp-bridges.md、 references/tools-by-os.md。

步驟 1:找到 Blender

執行 python ../polywright/scripts/pw.py doctor 即可找到它(POLYWRIGHT_BLENDER、PATH、Windows、macOS 和 Linux 的安裝資料夾)並顯示版本。目標為最新的 LTS 版本(5.2,支援至 2028 年 7 月)。將版本號寫入腳本的第一個註解中;以下 API 資訊皆針對 5.2 版。

步驟 2:無頭執行腳本

python ../polywright/scripts/pw.py bpy build.py [--blend in.blend] [--timeout 1800] -- <script args>

pw.py 自己的選項可以放在腳本名稱之前或之後;-- 之後的所有參數都會傳遞給腳本。 它會執行 blender --background --factory-startup --python-exit-code 3 --python build.py -- args,去除 Blender 的日誌雜訊,並回傳 ok、腳本自己的輸出行和回溯追蹤。如果沒有 --python-exit-code,Blender 內部的 Python 錯誤仍會以 exit 0 結束:切勿僅靠結束碼判斷成功與否。請印出您自己需要的 [pw] 行(大小、計數、檢查)。

腳本規則:

  • 從 bpy.ops.wm.read_factory_settings(use_empty=True) 或明確的 .blend 檔案開始;切勿依賴使用者的啟動檔案。
  • 優先使用 bpy.data 和 bmesh 而非 bpy.ops。當需要使用運算子時,請先設定活動物件和選取範圍,或使用 with bpy.context.temp_override(...)。
  • 視口運算子在無頭模式下會失敗(view3d.*、screen.screenshot、render.opengl):請自行根據邊界框設定攝影機(就像 pw.py render 所做的那樣)。
  • 讀取 enum 項目而非猜測名稱:m.bl_rna.properties["solver"].enum_items。
  • 真實尺寸以公尺為單位;在測量前套用變換;glTF 匯入時會以四元數模式導入,並在一個父物體上進行軸向修正:先清除父物體並保留變換,然後套用,最後再測量。
  • 將每個輸出路徑寫成絕對路徑(os.path.abspath),並在之後列印檔案是否存在:相對路徑的 render.filepath 可能會回報成功但實際卻未寫入任何可見內容(L-004)。
  • 在 work/ 中為每個里程碑儲存一個帶編號的 .blend 檔案;從該檔案重新啟動,而非維持一個長時間執行的即時工作階段。
  • 在渲染之前先烘焙模擬,並將快取資料夾放在 .blend 檔案旁邊(預設為暫存目錄,關閉後會遺失)。烘焙進度會大量輸出到標準輸出,而 pw.py bpy 會截斷中間部分:請將結果寫入一個 JSON 檔案。
  • 如果發生回溯錯誤,最多重試兩次;然後查詢 API(陷阱檔案、內省、官方 MCP 的文件搜尋),而不是第三次盲目猜測。

步驟 3:陷阱(簡短列表;完整列表請見陷阱檔案)

寫法(舊版)5.x 版使用
bpy.ops.import_scene.obj、import_mesh.stl、import_mesh.ply、wm.collada_*wm.obj_import、wm.stl_import、wm.ply_import;Collada 已移除
BLENDER_EEVEE_NEXTBLENDER_EEVEE
import bglgpu 模組
Principled Specular、Subsurface、Transmission、Emission、ClearcoatSpecular IOR Level、Subsurface Weight、Transmission Weight、Emission Color、Coat Weight
action.fcurves插槽動作:圖層、片段、通道包
幾何節點上的 mod["Socket_2"] = xmod.properties.inputs.Socket_2.value = x
import_image.to_planeimage.import_as_mesh_planes
Workbench shading.show_shadowshading.show_shadows
obj.select = True、scene.objects.active、mesh.use_auto_smooth、scene.node_tree(2.7x 書籍)select_set、view_layer.objects.active、shade_auto_smooth 或 set_sharp_from_angle、scene.compositing_node_group
transform_apply(scale=True) 單獨使用也會套用位置和旋轉:請傳入 location=False, rotation=False

步驟 4:常見任務

pw.py 已經可以執行檢查、渲染、轉換、LOD、可列印與聯集操作。對於其他需求,請從 references/bpy-recipes.md 選取食譜:按比例參考圖像、修改器與套用、使用 Manifold 解算器與 EXACT 備案的布林運算、體素重網格、QuadriFlow、智慧 UV 與光照貼圖 UV、從高模到低模的法線與 AO 烘焙、使用 5.x 插槽的材質、旋轉台靜態圖、用於影片的深度與法線通道、各引擎的匯出,以及根據文字描述設計的道具(車床、掃掠、鏡像;L-003)。場景:references/bpy-recipes-scenes.md:幾何節點散布、反向深度、遮罩、霧氣與法線一次渲染、透過材質覆蓋的黏土效果、線條藝術、透過 Blender 內建 FFmpeg 輸出 MP4。物理與骨架:references/bpy-recipes-physics.md:剛體與布料烘焙、為何 Rigify 骨架不是遊戲骨骼、手動綁定到骨架、體積重網格。父子關係、F-修飾器運動與驅動:references/bpy-recipes-motion.md。對於具有鏡像零件的模型圖紙:將側面攝影機抬高 10 到 15 度,否則一個零件會遮住另一個(L-005)。

步驟 5:即時工作階段(MCP)

存在兩個伺服器:Blender Lab 的官方 MCP(v1.0.3、Blender 5.1+、場景分析與 API 文件搜尋)以及社群版 mcp-for-blender(原名 blender-mcp;素材搜尋與產生器掛鉤)。兩者都會執行模型發送的任何 Python 程式碼,且沒有沙箱,使用連接埠 9876。請使用其中一個,切勿同時使用兩個;僅在使用者正在觀看 Blender 並希望進行即時編輯時使用;切勿將從下載檔案中貼上的文字貼入其程式碼中。設定與故障模式:references/mcp-bridges.md。在即時工作階段中,請將綁定編輯器的運算子包裝在 context.temp_override(window=w, area=a, region=r) 中;模態運算子和 bpy.app.timers 只能在該環境下執行,切勿在 -b 模式下執行。

其他工具

無需 Blender 的網格檢查與修復:trimesh + manifold3d(+ PyMeshLab);網頁傳遞:gltf-transform 或 gltfpack;實體建模:OpenSCAD、build123d、CadQuery、FreeCAD;切片機有 CLI。版本與各作業系統的執行情況:references/tools-by-os.md。在 macOS 上,Blender 5.x 和 bpy wheel 僅支援 Apple Silicon;bpy wheel 需要恰好是 Blender 搭載的 Python 版本(5.2 為 3.13)。

維護

常青單元,層級 moderate(Blender 每四個月發行一次;每次發行時檢查)。伴隨檔案:RESEARCH.md、CHANGELOG.md、LEARNINGS.md、TESTS.md(內含 evals/evals.json)、MAINTENANCE.md、狀態位於 evergreen.json。每次使用時請讀取 evergreen.json;到期時重新整理。

Individual skills in this repo

This repo contains 4 individual skills — each has its own dedicated page.

m4bwav/polywright

Start here whenever a task needs a 3D model and no sibling below clearly owns it: a model of a real or imagined thing for a game (Unity, Roblox, Unreal, three.js), a 3D print, AI video or AR, or another plugin asking for a mesh. Picks the route (find, capture, generate, code), scaffolds the asset folder and manifest other plugins read, and runs pw.py (inspect, render a sheet, convert, check a budget, bpy headless, match a picture's camera, army blockouts with depth and pose passes for AI...

m4bwav/polywright-finish

Use whenever a mesh must be made ready for a game engine, the web or AR: is it game-ready, too many polygons, LODs, retopology, UVs, baking, PBR and normal-map conventions, collision, rigging, and axis, unit and format export for Roblox, Unity, Unreal, Godot, three.js (meshopt, KTX2), USDZ and video blockouts. Use on 'is this game-ready', 'make this work in Roblox/Unity', 'optimise for the web', 'reduce polygons', 'add LODs', 'retopologise', 'bake normals', 'imports sideways or tiny', 'flip...

m4bwav/polywright-generate

Use whenever an imagined or hypothetical 3D model must be made from a prompt, a drawing, concept art, photos or a blockout: image-to-3D through ComfyUI (TRELLIS.2, Pixal3D, Hunyuan3D-2 via pw.py gen) or hosted (Meshy, Tripo, Rodin), or code (bpy, build123d, CadQuery, OpenSCAD) when it has dimensions; then texturing and the licence record. Use on 'make me a 3D model of a dragon', 'turn this drawing or concept art into 3D', 'image to 3D', 'text to 3D', 'TRELLIS', 'Hunyuan3D', 'Meshy', 'model a...

m4bwav/polywright-references

Use whenever reference images, views or textures for a 3D model are needed, before modelling or image-to-3D: orthographic front, side and back views with a height bar, A-pose turnarounds, multi-view sets, blockout renders repainted into consistent views, seamless textures and quick normal/height/roughness maps (pw.py texture). Use on 'what references do I need', 'reference sheet', 'front side back views', 'turnaround', 'seamless texture', 'PBR maps from this photo'. Not for flat graphic...

相關技能