"""
Shading and UV Preparation Tools
Tools for marking seams and sharp edges automatically based on angle thresholds.
"""
from mcp.server.fastmcp import Context
import logging
logger = logging.getLogger("BlenderMCPServer")
def mark_seams_by_angle(
ctx: Context,
blender_connection,
angle: float = 60.0,
clear_existing: bool = False
) -> str:
"""
Automatically mark UV seams on edges based on angle threshold.
Useful for preparing meshes for UV unwrapping.
Parameters:
- angle: Angle threshold in degrees (default: 60). Edges with angle ≥ this become seams.
- clear_existing: Clear existing seams before marking new ones (default: False)
Returns count of edges marked as seams.
"""
try:
result = blender_connection.send_command("mark_seams_by_angle", {
"angle": angle,
"clear_existing": clear_existing
})
if "error" in result:
return f"Error: {result['error']}"
output = "UV Seams Marked!\n\n"
output += f"Angle Threshold: {result.get('angle', angle)}°\n"
output += f"Edges Marked: {result.get('edges_marked', 0)}\n"
if clear_existing:
output += "(Existing seams were cleared)\n"
return output
except Exception as e:
logger.error(f"Error marking seams: {str(e)}")
return f"Error marking seams: {str(e)}"
def mark_sharp_by_angle(
ctx: Context,
blender_connection,
angle: float = 45.0,
clear_existing: bool = False
) -> str:
"""
Automatically mark sharp edges based on angle threshold for proper shading.
Sharp edges will show crisp transitions in smooth shading.
Parameters:
- angle: Angle threshold in degrees (default: 45). Edges with angle ≥ this become sharp.
- clear_existing: Clear existing sharp edges before marking new ones (default: False)
Returns count of edges marked as sharp.
"""
try:
result = blender_connection.send_command("mark_sharp_by_angle", {
"angle": angle,
"clear_existing": clear_existing
})
if "error" in result:
return f"Error: {result['error']}"
output = "Sharp Edges Marked!\n\n"
output += f"Angle Threshold: {result.get('angle', angle)}°\n"
output += f"Edges Marked: {result.get('edges_marked', 0)}\n"
if clear_existing:
output += "(Existing sharp edges were cleared)\n"
return output
except Exception as e:
logger.error(f"Error marking sharp edges: {str(e)}")
return f"Error marking sharp edges: {str(e)}"