https://github.com/ehsanwwe/ios-webxr-slam
WebXR-grade AR for iOS Safari. SLAM-based surface detection, gyro tracking & 3D placement โ no app, no SDK, no compromise.
https://github.com/ehsanwwe/ios-webxr-slam
Last synced: 2 months ago
JSON representation
WebXR-grade AR for iOS Safari. SLAM-based surface detection, gyro tracking & 3D placement โ no app, no SDK, no compromise.
- Host: GitHub
- URL: https://github.com/ehsanwwe/ios-webxr-slam
- Owner: ehsanwwe
- License: mit
- Created: 2026-05-21T14:17:48.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2026-05-21T14:33:04.000Z (3 months ago)
- Last Synced: 2026-05-21T23:19:25.342Z (3 months ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
๐ญ WebARKit
WebXR-grade Augmented Reality for iOS Safari โ No App Required
The open-source AR engine that brings real-world surface tracking to iOS browsers.
The missing bridge between WebXR and iOS Safari.
---








**[๐ Live Demo](#demo) ยท [๐ Documentation](#getting-started) ยท [๐บ Roadmap](#roadmap) ยท [๐ค Contributing](#contributing)**
---
## The Problem
```
iOS Safari has ~25% global mobile market share.
iOS Safari does NOT support WebXR immersive-ar sessions.
Every existing Web AR solution either requires a paid SDK (8th Wall),
a native app (ARKit), or degrades silently to nothing on iOS.
```
**WebARKit solves this.** It is a standalone AR engine that runs entirely in the browser โ using the device camera, gyroscope, and a WASM-powered visual tracking layer โ to deliver surface-aware AR on iOS Safari, with no app install, no proprietary SDK, and no compromise.
---
## โจ Features
| Feature | iOS Safari | Android Chrome |
|---|---|---|
| Camera overlay | โ
| โ
|
| Gyroscope-based orientation | โ
| โ
|
| Visual feature tracking (SLAM) | โ
๐ | โ
|
| Plane / floor detection | โ
๐ | โ
via WebXR |
| 3D object placement on surface | โ
๐ | โ
|
| Drag / rotate placed object | โ
| โ
|
| 3D avatar + animation (GLB/FBX) | โ
| โ
|
| Voice AI integration | โ
| โ
|
| Works without app install | โ
| โ
|
| Works without paid SDK | โ
| โ
|
---
## ๐ Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ WebARKit Engine โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Sensor Layer โ โ Camera Layer โ โ
โ โ DeviceOrientation โ โ getUserMedia (rear cam) โ โ
โ โ alpha / beta / gammaโ โ OffscreenCanvas frames โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โผ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Orientation โ โ Visual Tracker (WASM) โ โ
โ โ computeDeviceQuat()โ โ FAST corner detection โ โ
โ โ screen-orient corr.โ โ Lucas-Kanade optical flow โ โ
โ โ quaternion slerp โ โ Essential matrix / pose est.โ โ
โ โโโโโโโโโโโโฌโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ โ
โ โ โ โ
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Sensor Fusion โ โ
โ โ Gyro (rotation) + โ โ
โ โ Optical flow (position) โ โ
โ โ โ Fused 6DOF camera pose โ โ
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Plane Detector โ โ
โ โ RANSAC homography โ โ
โ โ Floor / surface recognition โ โ
โ โ โ Reticle on real surface โ โ
โ โโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โผ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Three.js Renderer โ โ
โ โ Fused pose โ camera matrix โ โ
โ โ GLB / FBX / animated avatar โ โ
โ โ AR overlay on camera feed โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
**Dual-mode runtime โ automatic, zero config:**
```
navigator.xr?.isSessionSupported('immersive-ar')
โโโ true โ XR Mode (Android Chrome, full WebXR)
โโโ false โ WebARKit Mode (iOS Safari, this engine)
```
---
## ๐ฌ Demo
> ๐ฑ Point your iPhone camera at a flat surface. Tap to place. Drag to move. Pinch-rotate with two fingers.
| AR Avatar Placement | Surface Detection | Voice AI |
|---|---|---|
| *(GIF coming soon)* | *(GIF coming soon)* | *(GIF coming soon)* |
**[โ Try the live demo](https://your-demo-url.com)** *(iOS Safari recommended)*
---
## ๐ Getting Started
### Requirements
- Modern iOS device (iOS 13+) with Safari
- HTTPS (required for camera + sensor permissions)
- Three.js r140+
### Installation
```bash
npm install webarkit
# or use via CDN
```
```html
import { WebARKit } from './webarkit.js';
```
### Minimal Setup
```javascript
import { WebARKit } from './webarkit.js';
import * as THREE from 'three';
const scene = new THREE.Scene();
const engine = new WebARKit({ scene });
// Load your 3D model
engine.onReady(() => {
engine.loadModel('/my-model.glb').then(model => {
engine.placeOnSurface(model);
});
});
engine.start(); // auto-detects iOS vs WebXR, handles permissions
```
### How It Works on iOS
1. **Camera feed** is captured via `getUserMedia` and composited behind the Three.js canvas.
2. **Gyroscope** (`DeviceOrientationEvent`) drives camera rotation โ calibrated at session start.
3. **Visual tracker** (WASM Worker) extracts FAST corners each frame and tracks them across frames using Lucas-Kanade optical flow to estimate camera translation.
4. **Sensor fusion** merges gyro orientation with visual translation into a stable 6DOF pose.
5. **Plane detector** runs RANSAC over tracked point clouds to identify horizontal surfaces and outputs a hit-test equivalent for object placement.
6. **Three.js** renders the 3D scene using the fused camera matrix, pixel-perfectly over the camera feed.
---
## ๐ Project Structure
```
webarkit/
โโโ src/
โ โโโ core/
โ โ โโโ WebARKit.js # Main engine class
โ โ โโโ ModeRouter.js # XR vs Gyro auto-detection
โ โ โโโ SessionManager.js # Permission flow
โ โโโ tracking/
โ โ โโโ GyroTracker.js # DeviceOrientation โ quaternion
โ โ โโโ VisualTracker.js # WASM optical flow bridge
โ โ โโโ SensorFusion.js # Gyro + visual โ 6DOF pose
โ โ โโโ PlaneDetector.js # RANSAC surface detection
โ โโโ wasm/
โ โ โโโ fast_corners.cpp # FAST feature detector (C++)
โ โ โโโ lk_tracker.cpp # Lucas-Kanade tracker (C++)
โ โ โโโ build.sh # Emscripten build script
โ โโโ rendering/
โ โ โโโ CameraOverlay.js # Camera feed compositor
โ โ โโโ Reticle.js # Surface indicator
โ โ โโโ AvatarLoader.js # GLB/FBX + animation
โ โโโ ui/
โ โโโ LoadingUI.js
โ โโโ StatusUI.js
โ โโโ VoiceChat.js
โโโ demo/
โ โโโ index.html
โ โโโ avatar-demo.js
โโโ tests/
โโโ docs/
```
---
## ๐บ Roadmap
### โ
Phase 1 โ Gyro AR (Complete)
- [x] iOS camera feed via `getUserMedia`
- [x] `DeviceOrientationEvent` permission flow (iOS 13+)
- [x] `computeDeviceQuat()` โ screen-orientation-corrected quaternion
- [x] Gyro calibration & reset on session start
- [x] SLERP-smoothed camera rotation
- [x] Three.js scene over camera feed
- [x] GLB + FBX avatar loading with animation mixer
- [x] Two-finger rotate gesture
- [x] Single-finger drag (world XZ plane)
- [x] Dual-mode auto-routing (XR / Gyro)
- [x] WebXR hit-test drag (Android Chrome)
- [x] Voice-to-voice AI assistant integration
- [x] Timeline-based animation playback system
- [x] In-scene GLB UI button interaction
---
### ๐ Phase 2 โ Visual Tracking (In Progress)
- [x] Camera frame capture via OffscreenCanvas
- [ ] Web Worker pipeline for off-main-thread processing
- [ ] FAST corner detector (WASM, compiled from C++)
- [ ] Lucas-Kanade optical flow tracker (WASM)
- [ ] Camera translation estimation from tracked points
- [ ] Sensor fusion: gyro orientation + visual translation
- [ ] Drift correction using feature re-detection
- [ ] Pose smoothing & outlier rejection
---
### ๐ Phase 3 โ Plane Detection & True SLAM
- [ ] Point cloud accumulation over time
- [ ] RANSAC-based planar surface fitting
- [ ] Floor / table / wall classification
- [ ] Reticle snapping to detected surface (WebXR hit-test parity)
- [ ] Object placement on real surface (not fixed Z)
- [ ] Surface mesh visualization (optional debug overlay)
- [ ] Multi-plane tracking
---
### ๐ฎ Phase 4 โ Advanced Features
- [ ] Monocular depth estimation (TensorFlow.js / ONNX)
- [ ] Occlusion: real objects hiding virtual ones
- [ ] Light estimation from camera feed
- [ ] Image target / marker tracking
- [ ] Persistent world anchors (IndexedDB)
- [ ] Multi-object scene management
- [ ] iOS 18 WebXR support monitoring & auto-migration
---
### ๐ฆ Phase 5 โ SDK & Ecosystem
- [ ] Clean public API with TypeScript types
- [ ] npm package `webarkit`
- [ ] React wrapper (`@webarkit/react`)
- [ ] Webpack / Vite plugin
- [ ] Example templates (avatar, furniture, product viewer)
- [ ] Interactive documentation site
- [ ] Performance benchmarks vs 8th Wall / AR.js / Mind-AR
---
## ๐ Comparison
| | **WebARKit** | 8th Wall | AR.js | Mind-AR |
|---|---|---|---|---|
| iOS Safari | โ
| โ
| โ ๏ธ limited | โ ๏ธ limited |
| Surface tracking | โ
(Phase 3) | โ
| โ | โ |
| Open source | โ
| โ | โ
| โ
|
| Free | โ
| โ ($) | โ
| โ
|
| Three.js native | โ
| โ ๏ธ wrapper | โ ๏ธ wrapper | โ ๏ธ wrapper |
| No app required | โ
| โ
| โ
| โ
|
| Voice AI ready | โ
| โ | โ | โ |
---
## ๐ง Technical Notes
### Why not just use a WebXR polyfill?
Existing polyfills (Google's `webxr-polyfill`) handle controller input and basic session management, but **do not implement** `immersive-ar` hit-test or image tracking on iOS โ the hard parts. WebARKit implements exactly those missing pieces from scratch.
### Why sensor fusion instead of pure visual SLAM?
Pure visual SLAM is computationally expensive on mobile browsers. Pure gyro drifts. Fusing both gives stable orientation (gyro) with position correction (visual) โ the same strategy used in ARCore and ARKit under the hood, adapted for the browser sandbox.
### WASM for performance
Feature detection and optical flow run in a Web Worker using WebAssembly compiled from C++ via Emscripten. This keeps the main thread free for Three.js rendering and maintains 60fps on mid-range iOS hardware.
---
## ๐ค Contributing
Contributions are welcome โ especially on the WASM tracker and plane detection modules.
```bash
git clone https://github.com/ehsanwwe/ios-webxr-slam
cd ios-webxr-slam
npm install
npm run dev
```
To build the WASM module:
```bash
cd src/wasm
./build.sh # requires Emscripten SDK
```
Please open an issue before submitting large PRs. See [CONTRIBUTING.md](./CONTRIBUTING.md).
---
## ๐ค Author
**Ehsan Moradi** โ Senior Full-Stack & AI Engineer ยท CTO ยท 20+ years in production software
Specialized in: Real-time graphics ยท AR / SLAM systems ยท AI agents ยท WebGL renderers
- ๐ [LinkedIn](https://www.linkedin.com/in/ehsan-hightech/)
- ๐ [GitHub](https://github.com/ehsanwwe)
- ๐ง ehsan.hightech@gmail.com
> This project grew out of production work building [Mediuty](https://mediuty.com) โ an AR virtual makeup platform with a custom real-time rendering engine โ where iOS support was a hard requirement with no acceptable commercial solution.
---
## ๐ License
MIT ยฉ [Ehsan Moradi](https://github.com/ehsanwwe)
---
## ๐ท GitHub Topics
> Add these to your repository Settings โ Topics for maximum discoverability:
`ios` ยท `webxr` ยท `ios-ar` ยท `web-ar` ยท `slam` ยท `augmented-reality` ยท `three-js` ยท `ios-safari` ยท `webxr-ios` ยท `mobile-ar` ยท `gyroscope` ยท `computer-vision` ยท `optical-flow` ยท `wasm` ยท `arkit-web` ยท `webarkit`
---
If this saved you from buying an SDK license, consider giving it a โญ