Demo Scripts
Physics Sandbox includes 22 demo scripts that showcase different physics scenarios.
Each demo is available in both F# (.fsx) and Python, with identical behavior.
Running Demos
F# Demos
// Run a single demo:
// dotnet fsi Scripting/demos/Demo01_HelloDrop.fsx
// Run all demos automatically (10s each):
// dotnet fsi Scripting/demos/AutoRun.fsx
// Interactive runner (prompts between demos):
// dotnet fsi Scripting/demos/RunAll.fsx
Python Demos
// Prerequisites: pip install grpcio grpcio-tools protobuf
// Run a single demo:
// python Scripting/demos_py/demo01_hello_drop.py
// Run all demos automatically:
// python Scripting/demos_py/auto_run.py
// Interactive runner:
// python Scripting/demos_py/run_all.py
Demo Catalog
Note: Demos 16–18 are reserved for future use. Demos 19–24 were added in later releases
and use advanced shape types (compound, mesh, convex hull) and heightmap terrain.
Shared Prelude
Both language suites share a prelude library with 40+ helper functions:
F# Prelude (Scripting/demos/Prelude.fsx)
Key helpers:
// Session management
// let session = connect "https://localhost:7180"
// Body presets (marble, bowling ball, crate, etc.)
// let cmd = makeMarble "m-1" 0.0 5.0 0.0
// Batch commands (auto-splits at 100)
// batchAdd session commands
// Generators (stack, grid, pyramid, row)
// let cmds = makeStack "s" 5 0.0 0.0 0.0
// Simulation control
// resetSimulation session
// play session
// pause session
// Camera control with smooth transitions
// smoothCamera session (20.0, 15.0, 20.0) (0.0, 5.0, 0.0) 2.0
// Narration overlay
// narrate session "Demo Title" "Description text"
Python Prelude (Scripting/demos_py/prelude.py)
Mirrors the F# prelude with identical function names and behavior:
// # Session management
// channel, stub = connect("localhost:7180")
//
// # Body presets
// cmd = make_marble("m-1", 0.0, 5.0, 0.0)
//
// # Batch commands
// batch_add(stub, commands)
//
// # Generators
// cmds = make_stack("s", 5, 0.0, 0.0, 0.0)
//
// # Camera + narration
// smooth_camera(stub, (20, 15, 20), (0, 5, 0), 2.0)
// narrate(stub, "Demo Title", "Description")
Demo Structure
Each demo follows the same pattern:
- Reset the simulation (clear all bodies, pause, reset time)
- Create bodies using presets or generators
- Configure gravity, camera, and other settings
- Play the simulation
- Apply forces, impulses, or other interactions
- Wait for the demo duration
- Pause and clean up
Example: Demo 01 — Hello Drop
// 1. Reset simulation
// resetSimulation session
//
// 2. Add a ground plane and a sphere at height 10
// let plane = makePlane "ground" 0.0 0.0 0.0
// let sphere = makeMarble "ball-1" 0.0 10.0 0.0
// batchAdd session [plane; sphere]
//
// 3. Set gravity and camera
// setGravity session 0.0 -9.81 0.0
// setCamera session (10.0, 5.0, 10.0) (0.0, 0.0, 0.0)
//
// 4. Play and watch
// play session
// sleep 5000
Next Steps
- Getting Started — build and run the sandbox
- MCP Tools — control demos via AI assistants
- Architecture — understand the service design
PhysicsSandbox