The Map Editor is a visual tool for designing buildings and placing objects in your Babylon.js game world. It uses a grid-based system where each cell represents 1 unit in the 3D world.
Location: tools/map-editor.html Access: Open directly in web browser - no server needed!
Getting Started
1. Open the Map Editor
Simply open tools/map-editor.html in your web browser:
# From your project root
open tools/map-editor.html
# or
firefox tools/map-editor.html
# or copy the full path and open in browser
/home/gianfiorenzo/Documents/Vs\ Code/babylon_fp/tools/map-editor.html
2. Using the Tools
Available Tools:
🧱 Wall - Create solid walls for buildings (2 units wide × 1 unit deep × 3 units tall)
Verwandte Skills
⬜ Floor - Create floor tiles (thin, walkable)
🚪 Door - Create doorways (2 units wide × 1 unit deep × 2.2 units tall, interactive in-game)
🪟 Window - Create windows (2 units wide × 1 unit deep × 1.5 units tall)
👤 NPC Spawn - Mark NPC spawn points
🎮 Player Spawn - Mark player spawn points
❌ Erase - Remove tiles
How to Use:
Click a tool button to select it (it will highlight green)
Click on the grid to place tiles
Use the Rotation dropdown or press 'R' to rotate (0°, 90°, 180°, 270°)
Click on existing tiles with the Erase tool to remove them
Hover over the grid to see coordinates
3. Grid System
Grid Size: 100x100 by default (adjustable)
Cell Size: 1 unit per cell
World Size: 100x100 units total
Origin: Center of the grid is world position (0, 0, 0)
Coordinate Conversion:
Grid (50, 50) = World (0, 0) (center)
Grid (0, 0) = World (-50, -50) (top-left corner)
Grid (100, 100) = World (50, 50) (bottom-right corner)
4. Visual Features
Cursor Preview 👁️
Semi-transparent preview of the tile you're about to place
Shows exactly what the tile will look like before clicking
Preview follows your mouse cursor in real-time
Changes instantly when you switch tools or rotation
Orientation Indicators 🧭
All rotatable items show a bright green line on their "front" edge:
Walls, Doors, Windows:
0° (Horizontal): Green line on bottom edge (facing south)
90° (Vertical): Green line on left edge (facing west)
180°: Green line on top edge (facing north)
270°: Green line on right edge (facing east)
NPC & Player Spawns:
Default orientation facing south (down) with green line on bottom
Already-placed tiles show a darker green line (more subtle) to indicate their orientation.
Erase Tool Visual ❌
Shows a red X under cursor when erase tool is selected
Clear visual indication of what will be deleted
5. Building Types
Walls
Default height: 3 units
Blocks player movement
Used for building exteriors and interiors
Rotatable: 0°, 90°, 180°, 270°
Floors
Thin tiles (0.1 units high)
Create interior floors or platforms
Collision enabled
Walkable
Doors
Height: 2.2 units
Width: 1.0 units (can occupy 2 grid units with rotation)
Can be made interactive with the DoorSystem
Initially blocks movement in-game
Rotatable for proper wall orientation
Windows
Placed higher on walls (1.5 units from top)
Semi-transparent
Blocks movement (glass)
Rotatable for proper wall orientation
Spawn Points
Player Spawn: Where the player starts (only one per map)
NPC Spawn: Where NPCs are placed (link to NPC id in JSON)
Include npcId in the JSON to link to specific NPC data
Advanced Features
Drag Painting 🎨
Left-click and drag to paint multiple tiles quickly
Works with: Wall, Floor, Window, and Erase tools
Perfect for creating large areas without clicking repeatedly
Release mouse button to stop painting
NPC Schedule Editor 📅
Automatically opens when you select/place an NPC
Edit waypoint times, positions, and npc type
Add, edit, or remove waypoints
Time validation ensures consistent schedules
Export/import preserves all schedule data
Map Import/Export
Exporting Your Map
Once you've designed your map:
Copy JSON: Copies the map data to your clipboard
Download JSON: Downloads as a .json file
Save the file to /public/data/maps/your_map_name.json
Importing Maps
Click Import JSON button
Select a .json file from your computer
Map and all schedule data are restored
Existing data is replaced
Rotation & Building Walls
Wall Placement
Horizontal Wall (0° or 180°)
Place walls at grid positions with X-spacing of 2:
Reuse maps with position offsets for similar buildings
Example Workflow
Sketch: Draw your building layout on paper
Design: Open map editor and create the structure
Place NPCs: Click NPC Spawn, edit schedule in modal
Export: Download JSON file
Save: Move to /public/data/maps/
Test: Load in game and walk through
Iterate: Adjust and refine
Commit: Save to version control
Troubleshooting
Map doesn't load in game:
Check browser console for errors
Verify JSON syntax is valid
Ensure file path in Game.ts is correct
Check the file exists in /public/data/maps/
Walls overlap or look wrong:
Remember spacing: horizontal walls use X-spacing of 2, vertical use Y-spacing of 2
Check grid coordinates vs world coordinates
Verify rotation settings (green line should face outward)
Player gets stuck:
Add doors where needed
Check for overlapping collision geometry
Verify spawn points are in valid, open locations
Schedule editor not showing:
Make sure you've selected an NPC spawn point
Click on the NPC spawn to select it
The editor should appear automatically
Keyboard Shortcuts
R - Rotate selected tool by 90°
E - Select Erase tool
D - Select Floor tool
W - Select Wall tool
Development Commands
List all maps
ls -1 /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp/public/data/maps/*.json
Validate map JSON
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
for f in public/data/maps/*.json; do
echo "Checking $f..."
node -e "JSON.parse(require('fs').readFileSync('$f'))" && echo "✓ Valid"
done
Count buildings in a map
cd /home/gianfiorenzo/Documents/Vs\ Code/babylon_fp
cat public/data/maps/example.json | grep -c '"type"'