SpatialLens
Parses USD/USDZ/USDA files into structured JSON for AI agents, enabling scene graph hierarchy, material shader graphs, spatial positions, and entity relationship analysis via CLI and MCP tools.
README
SpatialLens
USD/USDZ/USDA scene graph parser and spatial analysis tool for AI agents.
SpatialLens gives AI coding agents (Claude, Codex, Gemini, etc.) structured access to 3D scene data from Apple's USD ecosystem. It parses binary .usdz and text .usda files into structured JSON that any AI can reason about — entity hierarchies, material shader graphs, spatial positions, transforms, and relationships between objects.
Status: Work in Progress. Actively developed and tested against real visionOS game assets. Core parsing and spatial analysis are functional. Contributions and feedback welcome.
Why This Exists
AI agents working on visionOS, RealityKit, or any USD-based 3D project are blind to what's actually in the asset files. They can read Swift code that references entity names and positions, but they can't see the USDZ contents — the hierarchy, the materials, the transforms, the shader graphs. This creates a gap where the AI guesses instead of knowing.
SpatialLens closes that gap by translating binary 3D assets into structured text that AI agents natively understand.
Two Ways to Use It
1. CLI (any AI agent, any environment)
python cli.py <command> <file> [options]
No MCP required. Runs anywhere with Python 3.12+ and Apple's USD tools. Output is JSON to stdout — pipe it, save it, paste it into a prompt.
2. MCP Server (Claude Desktop, or any MCP-compatible client)
python server.py
Exposes all tools over MCP for real-time use during coding sessions.
Prerequisites
- macOS (required for Apple USD tools)
- Python 3.12+
- Apple USD CLI tools —
usdcatandusdtreeat/usr/bin/(ships with Xcode Command Line Tools)
Verify your setup:
usdcat --version # Should print "Apple USD Tools (x.x.x)"
usdtree --version # Same
python3 --version # 3.12+
Setup
git clone https://github.com/RevivrStudios/spatiallens-mcp.git
cd spatiallens-mcp
python3 -m venv venv
source venv/bin/activate
pip install -r requirements.txt
CLI Commands
All commands output structured JSON to stdout unless noted.
scene — Full Scene Graph
python cli.py scene Player_Ships.usdz
Returns the complete prim hierarchy with types, paths, properties, and children. Use this for deep analysis.
tree — Quick Hierarchy (text output)
python cli.py tree Player_Ships.usdz
Returns an indented text tree. Fast overview of what's in a file.
materials — Materials and Shader Graphs
python cli.py materials TerrainGlass.usda
Returns all materials with shader node IDs, input parameters, output connections, and the full shader graph. Use this for debugging visual issues.
transforms — Positioned Entities
python cli.py transforms Player_Ships.usdz
Returns every entity that has translate, rotate, or scale data.
entities — List All Entities
python cli.py entities Enemy_Ships.usdz
python cli.py entities Enemy_Ships.usdz --type Mesh
Flat list of all entities. Filter by type: Mesh, Material, Shader, Xform, Sphere, Scope.
details — Single Entity Deep Dive
python cli.py details Player_Ships.usdz --path "/__spaceships_set/Meshes"
Full properties and children for one specific entity. If the path doesn't exist, returns all available paths.
layout — Spatial Layout Analysis
python cli.py layout Player_Ships.usdz
Returns:
- All positioned entities with coordinates
- Bounding box (min, max, center, size in meters)
- 5 nearest entity pairs with distances
- Plain English spread description (compact / room-scale / large-scale)
- Coordinate convention reference
diff — Compare Two Files
python cli.py diff Player_Ships.usdz Enemy_Ships.usdz
Structural diff: added prims, removed prims, changed properties. Use after editing a USDZ in Reality Composer Pro.
overlaps — Find Overlapping Entities
python cli.py overlaps Player_Ships.usdz --threshold 0.05
Flags entity pairs closer than the threshold (default 1cm). Catches z-fighting, stacked geometry, accidental overlaps.
relationship — Spatial Relationship Between Two Entities
python cli.py relationship Player_Ships.usdz \
--a "/__spaceships_set/.../SpaceShip1_" \
--b "/__spaceships_set/.../SpaceShip2_"
Returns distance and plain English description: "SpaceShip2_ is 1.665m to the right and 0.022m toward viewer from SpaceShip1_"
move — Compute New Position
python cli.py move Player_Ships.usdz \
--path "/__spaceships_set/.../SpaceShip1_" \
--direction right \
--meters 0.5
Returns current position, direction, and computed new position. Directions: left, right, up, down, forward, back, toward viewer, away from viewer.
Coordinate Convention
SpatialLens uses the RealityKit / visionOS coordinate system:
| Direction | Axis | Sign |
|---|---|---|
| Right | X | + |
| Left | X | - |
| Up | Y | + |
| Down | Y | - |
| Toward viewer | Z | + |
| Away from viewer | Z | - |
Units: 1 unit = metersPerUnit meters (read from the USD file metadata). Common values:
metersPerUnit = 1— units are meters (RealityKit default)metersPerUnit = 0.01— units are centimeters (common in Sketchfab/Blender exports)
SpatialLens reads metersPerUnit from each file and converts all spatial output to meters automatically.
MCP Server Setup
For Claude Desktop, add to your claude_desktop_config.json:
{
"mcpServers": {
"spatiallens": {
"command": "/path/to/spatiallens-mcp/venv/bin/python",
"args": ["/path/to/spatiallens-mcp/server.py"]
}
}
}
The MCP server exposes 11 tools:
parse_scene_graph— full scene graphhierarchy_tree— quick text treeget_materials— materials and shadersget_transforms— positioned entitieslist_entities— flat entity list with type filterget_entity_details— single entity deep divediff_scenes— structural diffspatial_layout— spatial analysis with bounding boxspatial_relationship— relationship between two entitiescheck_spatial_overlaps— overlap detectionmove_suggestion— compute new position from direction
Project Structure
spatiallens-mcp/
├── cli.py # Standalone CLI (no MCP needed)
├── server.py # MCP server entry point
├── usda_parser.py # USDA text → structured dict parser
├── spatial_math.py # Coordinate geometry and spatial analysis
├── requirements.txt # Python dependencies (fastmcp, mcp)
└── tests/
├── test_parser.py # Unit tests for USDA parser
└── test_tools.py # Integration tests against real USDZ files
Core modules:
-
usda_parser.py— Line-by-line state machine that parses the text output ofusdcat --flatten. Extracts prim hierarchy, types, properties, material bindings, shader connections. Handles nested metadata blocks and customData annotations. -
spatial_math.py— Pure math operations on parsed prim data. Position extraction (fromxformOp:translateor 4x4 transform matrices), distance calculation, relative position descriptions, bounding box analysis, overlap detection, move suggestions. No app-specific logic. -
server.py— FastMCP wrapper that shells out tousdcat/usdtree, passes results through the parser and spatial math modules, and returns structured JSON. -
cli.py— Argparse-based CLI that uses the same parser and spatial math modules. Identical output, no MCP dependency.
For AI Agents: How to Use This
If you're an AI agent reading this README, here's how to get value from SpatialLens:
- Clone and set up the repo (see Setup above)
- Run
python cli.py tree <file>first to see what's in a USDZ file - Run
python cli.py layout <file>to understand spatial positioning - Run
python cli.py materials <file>when debugging visual issues - Run
python cli.py entities <file> --type Meshto find specific geometry - Run
python cli.py diff <old> <new>after editing a scene to verify changes
The JSON output is designed to be parsed programmatically. Every command returns valid JSON to stdout (except tree which returns text).
Key insight: When the human says "move it to the right" or "the ships are too close together," you can now quantify that with real coordinates instead of guessing. Use layout to see where things are, relationship to measure distances, and move to compute exact position changes.
Tested Against
- Player_Ships.usdz — 5 spaceship models, 25 entities, centimeter-scale (metersPerUnit=0.01)
- Enemy_Ships.usdz — 12 enemy ship models, 46 entities, centimeter-scale
- TerrainGlass.usda — Glass material with 14-node shader graph (RealityKit MaterialX)
All from a real visionOS game project. 17/17 tests passing.
Limitations
- macOS only — requires Apple's
usdcatandusdtreeCLI tools - Local transforms only — positions are local to the prim, not accumulated world-space (parent transforms not yet composed)
- No mesh geometry — parses hierarchy, properties, and materials, but does not read vertex/face data
- No texture content — identifies texture file references but cannot read image data
- Parser handles common USDA patterns — exotic USD features (variants, payloads, instancing) may not be fully parsed
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。