"""
Mesh analysis tools for topology inspection.
Provides deterministic analysis of mesh topology metrics and issue detection.
"""
from typing import Dict, Any, List, Optional
# Tool schemas for MCP registration
MESH_STATS_SCHEMA = {
"type": "object",
"properties": {
"active_only": {
"type": "boolean",
"description": "Analyze only the active object (true) or all mesh objects (false)",
"default": True
}
},
"required": []
}
DETECT_ISSUES_SCHEMA = {
"type": "object",
"properties": {
"angle_sharp": {
"type": "number",
"description": "Threshold angle in degrees for detecting sharp edges (default: 30)",
"default": 30,
"minimum": 0,
"maximum": 180
},
"distance_doubles": {
"type": "number",
"description": "Merge distance for detecting duplicate vertices (default: 0.0001)",
"default": 0.0001,
"minimum": 0
}
},
"required": []
}
def get_tool_definitions() -> List[Dict[str, Any]]:
"""Return MCP tool definitions for mesh analysis."""
return [
{
"name": "mesh_stats",
"description": (
"Get detailed topology statistics for mesh objects. "
"Returns counts of vertices/edges/faces, tri/quad/ngon breakdown, "
"non-manifold counts, sharp edges, and surface area/volume metrics."
),
"inputSchema": MESH_STATS_SCHEMA
},
{
"name": "detect_topology_issues",
"description": (
"Detect topology issues in mesh objects. "
"Reports non-manifold edges, loose geometry, duplicate vertices, "
"inverted normals, and provides suggested fixes."
),
"inputSchema": DETECT_ISSUES_SCHEMA
}
]
# Blender-side command implementations (to be called from addon.py)
def build_blender_command_mesh_stats(active_only: bool = True) -> Dict[str, Any]:
"""Build the Blender command for mesh_stats."""
return {
"type": "mesh_stats",
"params": {
"active_only": active_only
}
}
def build_blender_command_detect_issues(
angle_sharp: float = 30.0,
distance_doubles: float = 0.0001
) -> Dict[str, Any]:
"""Build the Blender command for detect_topology_issues."""
return {
"type": "detect_topology_issues",
"params": {
"angle_sharp": angle_sharp,
"distance_doubles": distance_doubles
}
}