blender-scripting
安装方式
先用 Prompt 核对来源与依赖。也可下载安装包。
用 AI 助手安装
复制提示词,让助手先核对固定版本和依赖。
查看 Prompt收起 Prompt
先检查当前 Agent 是否已安装 SkillPI Skill Finder。如果尚未安装,请按官方仓库的说明安装并启用:https://github.com/Findskills/skillpi。然后使用 Skill Finder 打开此 SkillPI 详情页并定位 "blender-scripting":https://skillpi.com/zh/skills/deepskill-6442185c07c2490e609b8b258382d2027840da8e287ee54937f287f0b7f413d7。安装前核对上游来源和版本:https://github.com/TerminalSkills/skills。来源不一致时停止并说明差异。核对通过后,用 Skill Finder 安装目标 Skill,并报告安装路径和来源版本。
来源与配置
github.com
配置方式待核实
请查看原始来源中的适用工具、依赖和权限要求。
安装实测待补充
用于编写并运行 Blender Python 脚本以实现 3D 自动化和程序化建模。适用于需要用代码自动化 Blender 任务、创建 3D 模型、运行无头脚本、操作场景、批量处理 .blend 文件、使用 bmesh 构建几何体、应用修改器、生成程序化形状或通过 bpy API 导入/导出 3D 模型的场景。
介绍来源: third_party · TerminalSkills · 1.1.0 参考来源
SkillPi 解读
- 实测状态
- 未测试
文件浏览
Frontmatter
name: blender-scripting
description: >-
Write and run Blender Python scripts for 3D automation and procedural
modeling. Use when the user wants to automate Blender tasks, create 3D models
from code, run headless scripts, manipulate scenes, batch process .blend
files, build geometry with bmesh, apply modifiers, generate procedural
shapes, or import/export 3D models using the bpy API.
license: Apache-2.0
compatibility: >-
Requires Blender 3.0+ installed and accessible from the command line.
Linux: sudo apt install blender or snap install blender.
macOS: brew install --cask blender.
metadata:
author: terminal-skills
version: "1.1.0"
category: automation
tags: ["blender", "3d", "python", "automation", "procedural"]Blender Scripting
Overview
Automate Blender tasks and create 3D models procedurally using Python and the bpy API. Run scripts headlessly from the terminal to manipulate scenes, build geometry with bmesh, apply modifiers, batch process files, and import/export models.
Instructions
1. Run scripts from the terminal
blender --background --python script.py
blender myfile.blend --background --python script.py
blender --background --python script.py -- --output /tmp/result.png --scale 2.0
2. Scene setup and cleanup
import bpy
def clear_scene():
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete(use_global=False)
for block in bpy.data.meshes:
if block.users == 0:
bpy.data.meshes.remove(block)
3. Create and transform objects
import bpy, math
from mathutils import Vector
bpy.ops.mesh.primitive_cube_add(size=2, location=(0, 0, 0))
cube = bpy.context.active_object
cube.location = (3, 0, 1)
cube.rotation_euler = (0, 0, math.radians(45))
cube.scale = (1, 2, 0.5)
4. Build meshes from raw data
vertices = [(-1,-1,0), (1,-1,0), (1,1,0), (-1,1,0),
(-1,-1,2), (1,-1,2), (1,1,2), (-1,1,2)]
faces = [(0,1,2,3), (4,5,6,7), (0,1,5,4), (2,3,7,6), (0,3,7,4), (1,2,6,5)]
mesh = bpy.data.meshes.new("CustomBox")
mesh.from_pydata(vertices, [], faces)
mesh.update()
obj = bpy.data.objects.new("CustomBox", mesh)
bpy.context.collection.objects.link(obj)
5. Use bmesh for advanced mesh editing
import bmesh
bm = bmesh.new()
v1 = bm.verts.new((0, 0, 0))
v2 = bm.verts.new((1, 0, 0))
v3 = bm.verts.new((1, 1, 0))
v4 = bm.verts.new((0, 1, 0))
bm.faces.new((v1, v2, v3, v4))
bmesh.ops.extrude_face_region(bm, geom=bm.faces[:])
bmesh.ops.subdivide_edges(bm, edges=bm.edges[:], cuts=2)
mesh = bpy.data.meshes.new("Result")
bm.to_mesh(mesh)
bm.free()
obj = bpy.data.objects.new("Result", mesh)
bpy.context.collection.objects.link(obj)
6. Apply modifiers
obj = bpy.context.active_object
sub = obj.modifiers.new("Subdivision", 'SUBSURF')
sub.levels = 2
mirror = obj.modifiers.new("Mirror", 'MIRROR')
mirror.use_axis = (True, False, False)
array = obj.modifiers.new("Array", 'ARRAY')
array.count = 5
array.relative_offset_displace = (1.1, 0, 0)
solid = obj.modifiers.new("Solidify", 'SOLIDIFY')
solid.thickness = 0.1
bevel = obj.modifiers.new("Bevel", 'BEVEL')
bevel.width = 0.05
bevel.segments = 3
# Apply permanently
bpy.context.view_layer.objects.active = obj
bpy.ops.object.modifier_apply(modifier="Subdivision")
7. Create curves
curve_data = bpy.data.curves.new("MyCurve", type='CURVE')
curve_data.dimensions = '3D'
spline = curve_data.splines.new('BEZIER')
spline.bezier_points.add(3)
for i, (x, y, z) in enumerate([(0,0,0), (1,1,0), (2,0,1), (3,1,1)]):
pt = spline.bezier_points[i]
pt.co = (x, y, z)
pt.handle_type_left = pt.handle_type_right = 'AUTO'
curve_data.bevel_depth = 0.1
obj = bpy.data.objects.new("MyCurve", curve_data)
bpy.context.collection.objects.link(obj)
8. Import and export
bpy.ops.wm.obj_import(filepath="/path/model.obj")
bpy.ops.import_scene.fbx(filepath="/path/model.fbx")
bpy.ops.import_scene.gltf(filepath="/path/model.glb")
bpy.ops.wm.obj_export(filepath="/path/output.obj")
bpy.ops.export_scene.gltf(filepath="/path/output.glb", export_format='GLB')
9. Assign materials
mat_red = bpy.data.materials.new("Red")
mat_red.diffuse_color = (1, 0, 0, 1)
obj.data.materials.append(mat_red)
for i, poly in enumerate(obj.data.polygons):
poly.material_index = 0 if i % 2 == 0 else 1
10. Batch process files
import glob
for filepath in glob.glob("/path/to/*.blend"):
bpy.ops.wm.open_mainfile(filepath=filepath)
for obj in bpy.data.objects:
if obj.type == 'MESH':
print(f" {obj.name}: {len(obj.data.vertices)} verts")
bpy.ops.wm.save_as_mainfile(filepath=filepath.replace(".blend", "_processed.blend"))
Examples
Example 1: Procedural spiral staircase
User request: "Generate a spiral staircase with 20 steps"
import bpy, math
def create_spiral_staircase(steps=20, radius=3, height=6):
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()
step_height = height / steps
for i in range(steps):
angle = (2 * math.pi * i) / steps
x, y = radius * math.cos(angle), radius * math.sin(angle)
bpy.ops.mesh.primitive_cube_add(size=1, location=(x, y, i * step_height),
scale=(1.5, 0.4, step_height * 0.8))
bpy.context.active_object.rotation_euler.z = angle
bpy.ops.mesh.primitive_cylinder_add(radius=0.2, depth=height, location=(0, 0, height/2))
create_spiral_staircase()
bpy.ops.wm.save_as_mainfile(filepath="/tmp/staircase.blend")
Example 2: Export all mesh objects as separate OBJ files
User request: "Export every mesh in my .blend as a separate OBJ"
import bpy, os
output_dir = "/tmp/exports"
os.makedirs(output_dir, exist_ok=True)
for obj in bpy.data.objects:
if obj.type == 'MESH':
bpy.ops.object.select_all(action='DESELECT')
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.wm.obj_export(filepath=os.path.join(output_dir, f"{obj.name}.obj"),
export_selected_objects=True)
Run: blender scene.blend --background --python export_all.py
Example 3: Procedural terrain from heightmap
User request: "Generate a terrain mesh using sine waves"
import bpy, bmesh, math, random
bm = bmesh.new()
res, size = 50, 20
verts = []
for i in range(res):
row = []
for j in range(res):
x, y = (i/res - 0.5) * size, (j/res - 0.5) * size
z = math.sin(x*0.5) * math.cos(y*0.5) * 2 + random.uniform(-0.2, 0.2)
row.append(bm.verts.new((x, y, z)))
verts.append(row)
for i in range(res-1):
for j in range(res-1):
bm.faces.new((verts[i][j], verts[i+1][j], verts[i+1][j+1], verts[i][j+1]))
mesh = bpy.data.meshes.new("Terrain")
bm.to_mesh(mesh)
bm.free()
obj = bpy.data.objects.new("Terrain", mesh)
bpy.context.collection.objects.link(obj)
Guidelines
- Always use
--backgroundwhen running from the terminal to skip the GUI - Use
from_pydata()for simple static meshes; usebmeshfor advanced operations - Always call
mesh.update()afterfrom_pydata()andbm.free()after bmesh - Use
bpy.datafor direct data access (fast); usebpy.opsfor complex operations - Ensure correct object is active and selected before using operators
- For batch processing, save to new files (not overwrite originals) unless requested
- For large meshes (10k+ faces), prefer bmesh over repeated
bpy.opscalls - Link objects to a collection — unlinked objects won't appear in the scene
- Blender uses Z-up coordinates; account for this when importing from Y-up systems
- Use
mathutilsfor vector math and matrix operations (bundled with Blender Python) - Import/export operator names vary by Blender version; listed ones work for 3.6+
当前收录版本
1.1.0
质量评测
满分100 · 来自 SkillPi LAB 实验室的评测报告。
亮点
- 提供 Blender Python 自动化脚本编写能力,覆盖 3D 建模、程序化生成、批量处理等高频刚需场景
- 包含完整端到端示例(螺旋楼梯、批量导出、程序化地形),显著提升用户效率
亮点
- 触发描述清晰完整,涵盖自动化任务、代码建模、无头脚本、批量处理等多种变体
- 边界明确,不易与其他 Skill 重叠
亮点
- 结构清晰,分 10 个核心操作模块,步骤完整
- frontmatter 完整,包含兼容性说明与元数据
- 提供 3 个高质量端到端示例,便于用户理解与复用
待提升项
-
未显式处理文件路径不存在等 IO 异常 原报告严重程度:轻微
在导入/导出和批量处理示例中,未对文件路径有效性进行校验或异常捕获
改进建议:建议在文件操作前后添加 try-except 块或路径存在性检查,提升脚本健壮性
亮点
- 工具来源明确(bpy/bmesh API),参数使用正确
- 对关键操作(如对象选择、mesh.update)有明确说明
- 提供了 Blender 命令行调用方式,便于无头执行
取前四项原始分值的算术平均,四舍五入取整。可通过收录报告核对各项评分与说明,运行记录需单独查证。
正文静态检测
100 / 100 · skillpi-20261123-no-r3-v1
正文未命中当前规则。
分数仅反映正文中的规则命中,供使用前参考。附件与运行行为不在此评分范围内。
权限与使用前检查
根据当前主文档自动整理,命中内容可能是示例或防护说明;不是实际权限声明,也未覆盖附件、外部依赖或运行行为。
-
安装或获取外部依赖
使用官方来源并锁定版本,在隔离环境检查安装脚本。当前文档检查不覆盖后续下载的代码。
主文档提及 · 第 12, 13 行 -
管理员或提升权限
确认确有必要再提升权限;不要关闭防护、绕过证书验证或扩大整个系统的访问权限。
主文档提及 · 第 12 行
安全评级与访问范围
safe · 静态证据核验,不代表运行安全保证。
使用前请由宿主核对并授权实际文件读写、外部服务和联网目的地;本站的核验不会授予任何运行权限。
用户讨论
还没有已核实的点评。