PyArchInit 3D Viewer Guide
Interactive 3D visualization of stratigraphic models in your browser
This guide explains how to use the PyArchInit 3D Viewer - a web-based tool that lets you visualize archaeological stratigraphic units in three dimensions, with real-time updates and natural language commands.
Table of Contents
What is the 3D Viewer?
The PyArchInit 3D Viewer is a web-based 3D visualization tool that:
Displays stratigraphic units (US) as 3D objects in your browser
Uses archaeological data from your database (dimensions, relationships, periods)
Supports natural language commands via chat interface
Updates in real-time when connected to Blender
Positions automatically based on stratigraphic relationships (Harris Matrix)
Color-codes by period or other criteria
Runs entirely in your browser using Three.js (WebGL)
What You Can Do
Create 3D models from US data
Filter by period, area, or type
Position objects based on Harris Matrix
Export to various formats
Watch real-time construction when connected to Blender
Interact with objects (click for info)
Orbit, zoom, pan the view
Quick Start
Step 1: Start the Web Interface
# Navigate to your project directory
cd /path/to/pyarchinit-mini
# Start the Flask server
DATABASE_URL="sqlite:///data/pyarchinit_tutorial.db" python3 -m pyarchinit_mini.web_interface.app
You should see:
[INFO] PyArchInit-Mini Web Interface starting...
[INFO] Running on http://127.0.0.1:5001
[INFO] Press CTRL+C to quit
Step 2: Open the 3D Builder
Open your browser (Chrome, Firefox, Safari, Edge)
Navigate to:
http://localhost:5001/3d-builder/You should see:
Left side: Site selector and form
Center: 3D viewer canvas (black background)
Right side: Chat interface
Step 3: Select a Site
Click the “Site” dropdown in the left panel
Select a site from your database (e.g., “Tempio Fortuna”)
Click “Auto-Populate US” to load all US for that site
The US list will appear below
Step 4: Build Your First Model
Type in the chat:
Build all
The viewer will:
Query all US for the selected site
Generate a GraphML file with relationships
Calculate 3D positions
Create proxy objects (colored boxes)
Display them in the viewer
Interface Overview
Layout
┌─────────────────┬──────────────────────────┬─────────────────┐
│ │ │ │
│ Left Panel │ Center Viewer │ Right Panel │
│ │ │ │
│ - Site Select │ - 3D Canvas │ - Chat │
│ - US List │ - Camera Controls │ - Messages │
│ - Options │ - Object Info │ - Input │
│ │ │ │
└─────────────────┴──────────────────────────┴─────────────────┘
Left Panel: Site & US Selection
Site Dropdown: Select which archaeological site to work with
Auto-Populate US Button: Load all US for selected site
US List: Shows all US with checkboxes
Build Options:
Positioning mode (GraphML, Simple, Grid)
Layer spacing (vertical distance between layers)
Color mode (by period, by type, custom)
Center Panel: 3D Viewer
Canvas: WebGL 3D rendering area
Camera: Orbits around the center, can zoom and pan
Grid: Optional grid floor for reference
Axes Helper: X (red), Y (green), Z (blue) axes
Overlay: Shows current view info (camera position, object count)
Controls: Bottom-left buttons for view presets
Right Panel: Chat Interface
Messages Area: Shows conversation history
Input Box: Type natural language commands
Send Button: Submit your command
Status: Shows connection status and progress
Building 3D Models
Method 1: Chat Commands (Recommended)
Simply type what you want in the chat:
Build all
Create US 1, 2, 3
Generate 3D model for selected site
Method 2: Manual Selection
Check US in the left panel
Click “Build Selected”
Wait for processing
View results in the canvas
Method 3: API Call (Advanced)
Use the MCP tools directly:
// Via MCP
build_3d({
us_ids: [1, 2, 3],
mode: "selected",
positioning: "graphml",
layer_spacing: 0.8
})
Understanding Positioning Modes
GraphML (Recommended)
Uses Harris Matrix relationships
Automatically calculates vertical positions
Respects stratigraphic sequence
Best for accurate visualization
Example:
Build with GraphML positioning
Simple
Stacks US vertically in database order
No relationship analysis
Fast but less accurate
Example:
Build with simple positioning
Grid
Arranges US in a regular grid
Ignores relationships
Good for viewing many US side-by-side
Example:
Build with grid layout
Chat Commands
The chat interface accepts natural language commands in Italian or English.
Build Commands
Command |
What It Does |
Example |
|---|---|---|
|
Build all US for selected site |
Creates complete 3D model |
|
Build specific US |
Creates only listed US |
|
Use existing GraphML file |
Loads relationships from file |
Filter Commands
Command |
What It Does |
Example |
|---|---|---|
|
Filter by period |
Shows only US from Roman period |
|
Hide specific US |
Removes US from view |
|
Filter by type |
Shows only USM (structures) |
|
Filter by area |
Shows US from specific area |
Material Commands
Command |
What It Does |
Example |
|---|---|---|
|
Change object color |
Applies red color to US 3 |
|
Use hex color |
Applies exact color code |
|
Change material type |
Makes object look like stone |
View Commands
Command |
What It Does |
Example |
|---|---|---|
|
Return to default view |
Centers and resets zoom |
|
Camera looks down |
Bird’s eye view |
|
Camera looks from front |
Elevation view |
|
Closer view |
Magnifies scene |
Export Commands
Command |
What It Does |
Example |
|---|---|---|
|
Save Harris Matrix |
Downloads .graphml file |
|
Save Blender file |
(Requires Blender connected) |
|
Save 3D model |
Downloads GLB file |
Viewer Controls
Mouse Controls
Left Click + Drag: Rotate camera (orbit)
Right Click + Drag: Pan camera (move sideways)
Scroll Wheel: Zoom in/out
Left Click on Object: Select and show info
Keyboard Shortcuts
Arrow Keys: Rotate view
+/-: Zoom in/out
H: Toggle help overlay
G: Toggle grid
R: Reset camera
View Presets
Bottom-left buttons provide quick view angles:
Top: View from above (Y-axis)
Front: View from front (Z-axis)
Side: View from side (X-axis)
Iso: Isometric 45° view
Reset: Default view
Features
Automatic Positioning
The viewer automatically positions US based on:
Stratigraphic Relationships:
“Above” relationships place US higher
“Below” relationships place US lower
“Cuts” and “Fills” affect positioning
GraphML Layout:
Hierarchical layout from Harris Matrix
Respects all relationship types
Handles cycles and paradoxes
Layer Spacing:
Adjustable vertical distance (default: 0.8m)
Prevents overlap
Maintains stratigraphic order
Color Coding
Objects are colored based on:
By Period (Default)
Romano: Red-brown
Medieval: Brown
Etrusco: Blue
Modern: Gray
Unknown: Light gray
By Unit Type
US (Strato): Earth tones
USM (Muro): Stone gray
USD (Distruzione): Dark gray
USV (Negativo): Inverted colors
Custom Colors
Set specific colors via chat:
Color US 3 #FF5733
Object Information
Click any object to see:
US ID and description
Unit type (US, USM, USD, USV)
Archaeological period
Excavation area
Dimensions
Stratigraphic relationships
Real-time Updates
When connected to Blender:
Objects appear as they’re created
Materials update live
Transformations sync instantly
Progress bar shows construction
Blender Integration
The 3D Viewer can display models created in Blender in real-time.
Setup
Install Blender MCP Addon: See BLENDER_INTEGRATION.md
Start Blender with addon enabled
Start Web Interface:
DATABASE_URL="sqlite:///data/pyarchinit_tutorial.db" \ python3 -m pyarchinit_mini.web_interface.app
Open 3D Viewer:
http://localhost:5001/3d-builder/Type in chat:
Build US 1,2,3
Watch:
Blender creates actual 3D geometry
Viewer receives real-time updates via WebSocket
Objects appear with realistic materials
What Gets Streamed
From Blender to Viewer:
Geometry creation - New objects appear
Material changes - Colors and textures update
Transformations - Position, rotation, scale changes
Progress updates - Status messages and percentages
Benefits of Blender Integration
Real geometry instead of simple boxes
Realistic materials based on archaeological data
Professional rendering quality
Export options (.blend, .glb, .fbx, .obj)
Advanced editing capabilities
Troubleshooting
Problem: Viewer shows empty canvas
Possible Causes:
No site selected
No US in database
JavaScript errors
Solutions:
# Check database has data
sqlite3 data/pyarchinit_tutorial.db "SELECT COUNT(*) FROM us_table;"
# Check browser console for errors (F12 → Console)
# Verify site selected in dropdown
# Try: "Build all" in chat
Problem: “Build all” does nothing
Possible Causes:
No US for selected site
GraphML generation failed
Server error
Solutions:
# Check server logs
# Look for errors in terminal where Flask is running
# Try manual US selection:
# 1. Check some US in left panel
# 2. Click "Build Selected"
# Check if site has US:
sqlite3 data/pyarchinit_tutorial.db \
"SELECT COUNT(*) FROM us_table WHERE sito='Site Name';"
Problem: Objects overlapping
Cause: Insufficient layer spacing or missing relationships
Solutions:
# Increase spacing:
Build with layer spacing 1.5
# Use GraphML positioning:
Build with GraphML layout
# Check relationships exist:
# Go to US management and verify "Above/Below" relationships
Problem: Chat not responding
Possible Causes:
Server not running
MCP executor not initialized
Database locked
Solutions:
# Restart Flask server
# Press CTRL+C, then restart:
DATABASE_URL="sqlite:///data/pyarchinit_tutorial.db" \
python3 -m pyarchinit_mini.web_interface.app
# Check logs for errors
# Try refreshing browser (CTRL+R)
Problem: Colors all gray
Cause: Period data missing from US
Solutions:
# Check period data:
sqlite3 data/pyarchinit_tutorial.db \
"SELECT us, periodo FROM us_table LIMIT 10;"
# Add period to US:
# Go to US edit form → Fill "Periodo iniziale" field
# Or manually color in chat:
Color US 3 blue
Problem: Blender connection failed
Cause: Blender addon not running or wrong port
Solutions:
Open Blender
Press N → PyArchInit tab
Click “Connect to PyArchInit”
Verify port 5001 matches Flask server
Check firewall allows local connections
Performance Tips
For Large Sites (50+ US)
Filter first:
Show only Roman period
Build in batches:
Create US 1-10 Create US 11-20 ...
Use simple positioning:
Build with simple positioning
Reduce layer spacing:
Build with layer spacing 0.5
Browser Performance
Use Chrome or Firefox for best WebGL performance
Close other tabs to free memory
Update graphics drivers
Reduce window size if laggy
Network Performance
If using remote server:
Use wired connection over WiFi
Close bandwidth-heavy apps
Consider local installation instead
Advanced Usage
Custom Positioning
Create custom positions via API:
position({
method: "graphml",
layer_spacing: 1.2,
horizontal_spacing: 2.0,
us_ids: [1, 2, 3, 4, 5]
})
Export for Other Software
The viewer can export to:
yEd Graph Editor: GraphML format
Blender: .blend files (via Blender integration)
Game engines: .glb/.gltf formats
CAD software: .obj/.fbx formats (planned)
Embed in Your Site
Embed the 3D viewer in your own webpage:
<iframe src="http://localhost:5001/3d-builder/"
width="100%" height="600px"
frameborder="0">
</iframe>
Next Steps
Try Blender Integration - See BLENDER_INTEGRATION.md
Setup MCP for AI Commands - See MCP_INTEGRATION.md
Explore the API - See REST API documentation in README.md
Technical Details
Stack
Frontend: HTML5, CSS3, JavaScript (ES6+)
3D Engine: Three.js r150
Real-time: Socket.IO 4.5.4
Backend: Flask + Flask-SocketIO
Database: SQLite or PostgreSQL
Browser Requirements
WebGL 2.0 support
ES6 JavaScript support
WebSocket support
Supported Browsers:
Chrome 90+
Firefox 88+
Safari 14+
Edge 90+
File Locations
pyarchinit-mini/
├── pyarchinit_mini/web_interface/
│ ├── templates/3d_builder/index.html # Main template
│ ├── static/js/three-d-viewer.js # Viewer logic
│ ├── static/js/three.min.js # Three.js library
│ ├── static/js/OrbitControls.js # Camera controls
│ └── three_d_builder_routes.py # Flask routes
├── pyarchinit_mini/services/
│ ├── command_parser.py # Chat command parsing
│ └── mcp_executor.py # MCP tool execution
└── pyarchinit_mini/mcp_server/tools/
└── build_3d_tool.py # 3D model generation
Resources
Three.js Docs: https://threejs.org/docs/
Socket.IO Docs: https://socket.io/docs/
WebGL Tutorial: https://developer.mozilla.org/en-US/docs/Web/API/WebGL_API
PyArchInit-Mini: https://github.com/enzococca/pyarchinit-mini
Support
Issues: https://github.com/enzococca/pyarchinit-mini/issues
Email: enzo.ccc@gmail.com
Documentation: https://github.com/enzococca/pyarchinit-mini/blob/main/README.md
Last Updated: November 2025 PyArchInit-Mini Version: 1.9.10+