"""
Shading Validation Tools
MCP tools for quick viewport shading setup to validate surface quality.
"""
from mcp.server.fastmcp import Context
import logging
logger = logging.getLogger("BlenderMCPServer")
def set_matcap_shading(
ctx: Context,
blender_connection,
matcap_name: str = None
) -> str:
"""
Set matcap shading for surface validation.
Matcap shading reveals shading artifacts, harsh lines, and surface issues.
Optimal for checking retopology quality before final approval.
Parameters:
- matcap_name: Optional specific matcap name (default: use current)
"""
try:
params = {}
if matcap_name:
params["matcap_name"] = matcap_name
result = blender_connection.send_command("set_matcap_shading", params)
if "error" in result:
return f"Error: {result['error']}"
output = "Matcap Shading Setup\n"
output += "=" * 50 + "\n\n"
output += f"Shading type: {result.get('shading_type', 'SOLID')}\n"
output += f"Light mode: {result.get('light_mode', 'MATCAP')}\n"
output += f"Matcap: {result.get('matcap', 'default')}\n"
output += f"Wireframe overlay: {'enabled' if result.get('wireframe_overlay') else 'disabled'}\n"
output += "\nViewport is now configured for shading validation.\n"
output += "Look for harsh lines, bright spots, and pinching.\n"
return output
except Exception as e:
logger.error(f"Error setting matcap shading: {str(e)}")
return f"Error setting matcap shading: {str(e)}"
def toggle_wireframe_overlay(
ctx: Context,
blender_connection,
enabled: bool = None
) -> str:
"""
Toggle or set wireframe overlay visibility.
Parameters:
- enabled: True to show, False to hide, None to toggle
"""
try:
params = {}
if enabled is not None:
params["enabled"] = enabled
result = blender_connection.send_command("toggle_wireframe_overlay", params)
if "error" in result:
return f"Error: {result['error']}"
state = "enabled" if result.get('wireframe_enabled') else "disabled"
output = f"Wireframe overlay is now {state}.\n"
if result.get('wireframe_enabled'):
output += "Topology is visible on mesh surface.\n"
else:
output += "Clean shading view without topology lines.\n"
return output
except Exception as e:
logger.error(f"Error toggling wireframe overlay: {str(e)}")
return f"Error toggling wireframe overlay: {str(e)}"
def toggle_smooth_shading(
ctx: Context,
blender_connection,
object_name: str = None,
smooth: bool = True
) -> str:
"""
Set smooth or flat shading on mesh object.
Parameters:
- object_name: Name of object (default: active object)
- smooth: True for smooth shading, False for flat
"""
try:
params = {"smooth": smooth}
if object_name:
params["object_name"] = object_name
result = blender_connection.send_command("toggle_smooth_shading", params)
if "error" in result:
return f"Error: {result['error']}"
shading_type = "smooth" if result.get('smooth_shading') else "flat"
output = f"Shading Mode: {result.get('object_name', 'Unknown')}\n"
output += "=" * 50 + "\n\n"
output += f"Shading set to: {shading_type}\n"
if result.get('smooth_shading'):
output += "\nSmooth shading applied - surfaces appear smooth.\n"
else:
output += "\nFlat shading applied - individual face angles visible.\n"
output += "Useful for identifying problem faces.\n"
return output
except Exception as e:
logger.error(f"Error setting shading: {str(e)}")
return f"Error setting shading: {str(e)}"