"""
Snapping tools for retopology workflows.
Provides safe, parameterized tools for configuring snapping behavior.
"""
from typing import Dict, Any
from mcp.server.fastmcp import Context
import logging
logger = logging.getLogger("BlenderMCPServer")
# ============================================================================
# SET SNAPPING
# ============================================================================
def set_snapping(
ctx: Context,
blender_connection,
enable: bool = True,
mode: str = "FACE_PROJECT",
align_rotation_to_target: bool = False,
project_individual_elements: bool = True,
backface_culling: bool = True
) -> str:
"""
Configure snapping settings for retopology workflow.
Sets up snapping to project new geometry onto reference surfaces.
Essential for manual retopology. Affects the active 3D viewport.
Parameters:
- enable: Enable snapping (default: true)
- mode: Snap mode - 'INCREMENT', 'VERTEX', 'EDGE', 'FACE', 'FACE_PROJECT', 'VOLUME' (default: 'FACE_PROJECT')
- align_rotation_to_target: Align rotation to target normal (default: false)
- project_individual_elements: Project each element individually (default: true)
- backface_culling: Don't snap to backfaces (default: true)
Returns status message with current snapping configuration.
"""
try:
valid_modes = ['INCREMENT', 'VERTEX', 'EDGE', 'FACE', 'FACE_PROJECT', 'VOLUME']
if mode not in valid_modes:
return f"Error: Invalid mode '{mode}'. Must be one of {valid_modes}."
result = blender_connection.send_command("set_snapping", {
"enable": enable,
"mode": mode,
"align_rotation_to_target": align_rotation_to_target,
"project_individual_elements": project_individual_elements,
"backface_culling": backface_culling
})
if "error" in result:
return f"Error: {result['error']}"
output = "Snapping Configuration Updated!\n\n"
output += f"Snapping: {'Enabled' if enable else 'Disabled'}\n"
if enable:
output += f"Mode: {mode}\n"
output += f"Align Rotation: {align_rotation_to_target}\n"
output += f"Project Individual Elements: {project_individual_elements}\n"
output += f"Backface Culling: {backface_culling}\n"
output += "\nℹ Snapping is now configured for retopology.\n"
output += "Use this to snap new geometry onto reference surfaces.\n"
return output
except Exception as e:
logger.error(f"Error setting snapping: {str(e)}")
return f"Error setting snapping: {str(e)}"