"""
Blender Snapping Handlers
This module contains handlers for configuring snapping settings in Blender.
Used primarily for retopology workflows.
"""
import bpy
def set_snapping(enable, mode, align_rotation_to_target, project_individual_elements, backface_culling):
"""Configure snapping settings for retopology"""
try:
# Get tool settings
ts = bpy.context.scene.tool_settings
# Enable/disable snapping
ts.use_snap = enable
if enable:
# Handle FACE_PROJECT mode for both Blender 3.x and 4.x
if mode == 'FACE_PROJECT':
if hasattr(ts, 'use_snap_project'):
# Blender 3.x - use FACE + use_snap_project
ts.snap_elements = {'FACE'}
ts.use_snap_project = True
else:
# Blender 4.x - FACE_PROJECT is a direct snap element
ts.snap_elements = {'FACE_PROJECT'}
else:
# Other modes (VERTEX, EDGE, FACE, etc.)
ts.snap_elements = {mode}
if hasattr(ts, 'use_snap_project'):
ts.use_snap_project = False
# Set snapping options
ts.use_snap_align_rotation = align_rotation_to_target
ts.use_snap_self = False
# Backface culling - check attribute exists for compatibility
if hasattr(ts, 'use_snap_backface_culling'):
ts.use_snap_backface_culling = backface_culling
# Project individual elements - check attribute exists
if hasattr(ts, 'use_snap_project_individual_elements'):
ts.use_snap_project_individual_elements = project_individual_elements
return {"success": True}
except Exception as e:
return {"error": f"Failed to set snapping: {str(e)}"}