AgentSkillsCN

Blender Mcp

Blender MCP

SKILL.md

Blender MCP Skill

Purpose: Automate 3D rendering and scene creation using Blender via Python scripting.

Setup

Ensure Blender 5.0 (or compatible 3.6+) is installed and the BLENDER_PATH environment variable is set if not in the default location.

Usage

The MCP server exposes run_blender_script(script_code: str, background: bool = True).

Example: Render a spinning card

python
# Create a simple spinning animation for a card template
import bpy
import math

# Clear existing objects
bpy.ops.object.select_all(action='SELECT')
bpy.ops.object.delete()

# Create a plane (Card)
bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0))
card = bpy.context.active_object
card.name = "Card_Template"

# Add material
mat = bpy.data.materials.new(name="Card_Mat")
card.data.materials.append(mat)
mat.use_nodes = True
bsdf = mat.node_tree.nodes["Principled BSDF"]

# Load texture (example path, adjust as needed)
# img = bpy.data.images.load("C:/path/to/card.png")
# tex_node = mat.node_tree.nodes.new('ShaderNodeTexImage')
# tex_node.image = img
# mat.node_tree.links.new(bsdf.inputs['Base Color'], tex_node.outputs['Color'])

# Animate rotation
card.rotation_mode = 'XYZ'
card.keyframe_insert(data_path="rotation_euler", frame=1)
card.rotation_euler.z = math.radians(360)
card.keyframe_insert(data_path="rotation_euler", frame=60)

# Set render settings
bpy.context.scene.render.engine = 'CYCLES'
bpy.context.scene.cycles.device = 'GPU'
bpy.context.scene.render.resolution_x = 1080
bpy.context.scene.render.resolution_y = 1080
bpy.context.scene.frame_start = 1
bpy.context.scene.frame_end = 60
bpy.context.scene.render.filepath = "//render_output/card_spin_"

# Save .blend file
bpy.ops.wm.save_as_mainfile(filepath="//card_spin.blend")

Render Frame Tool

Use render_frame(blend_file: str, output_path: str, frame: int) to render a single frame from an existing .blend file without writing a script.

Notes

  • Provide full absolute paths for textures and output files.
  • Use double backslashes \\ in paths or raw strings r"" to avoid escape sequence issues.
  • Blender uses its own bundled Python environment. External packages not included with Blender must be installed manually into Blender's python environment if needed, or stick to standard library + bpy + mathutils.