Concepts

Architecture

The package's AR runtimes behind three JS API layers: the module map, the public surface, and the data flows — WebXR, native Android ARCore, and native iOS ARKit/RealityKit (since 1.2.0).

The package is a Capacitor plugin with three independent AR runtimes (two before 1.2.0, which added the iOS runtime) behind three JS API layers. There is no build step: the published entry is the raw ESM source, with hand-written TypeScript declarations (src/*.d.ts) alongside it.

Your app, React or plain JSARCore facadesrc/index.js · registerPlugin('ARCore')ARView · useARCore · gesturessrc/ar-view.js · src/hooks.js · src/gestures.jsCapacitor bridgeARCoreWeb enginesrc/web.js · WebPluginNative Android pluginARCore session · hit test · surface eventsFilament render loop (camera background)Three.js over WebXRGLB models · planes · reticle · screenshotsimmersive-ar session in the browserLeft path: Android app only · Right path: browser, and the web platform inside CapacitorThe two runtimes do not share code below the facade, and are not at feature parity.

Diagram: the two runtimes of reticlexr 1.1.0 and the layers above them.

The three JS layers

LayerFilesSits on
ARCore facade: session/hit-test/model methods plus a local event bus (on()), bridging native events lazily, on first subscriptionsrc/index.js (13.4 KB)Capacitor plugin named ARCore
ARView / createARView + functional helpers: single active model, transform state, texture registry, gesture wiringsrc/ar-view.js (9.8 KB)WebXR engine only
useARCore hook + createARGestureControllersrc/hooks.js (27.7 KB), src/gestures.js (4.7 KB)WebXR engine only

The high-level layers never call the native plugin. If you use createARView or the hook, you are on the WebXR runtime everywhere, including inside a Capacitor app, where the WebView runs the same code.

Data flow: JS → bridge → native ARCore

App JS ─ ARCore.startSession() ─ Capacitor bridge ─► ARCorePlugin (UI thread)
  ├─ camera permission check / request
  └─ ARSessionManager.createSession(planeDetection, lightEstimation)
       ├─ ArCoreApk availability / requestInstall
       ├─ new Session + Config (plane finding, light estimation, auto focus)
       └─ onSessionReady ─► ARRenderer + ARViewManager
            (native view inserted behind the WebView; WebView made transparent)

Render loop (dedicated ARRenderThread):
  Session.update() → tracking → planes → camera matrices
  → camera-texture background → Filament render

Events: managers → AREventEmitter → notifyListeners → Capacitor
  → the facade's lazily installed bridge → ARCore.on() subscribers

Hit test: JS hitTest({x, y}) → plugin → latest frame
  → normalised coords → display pixels → frame.hitTest()

Data flow: JS → bridge → native ARKit (iOS, since 1.2.0)

App JS ─ ARCore.startSession() ─ Capacitor bridge ─► ARCorePlugin (Swift)
  ├─ camera permission (AVCaptureDevice; coded CAMERA_PERMISSION_DENIED)
  └─ ARViewManager attaches a RealityKit ARView over the web view
       └─ ARSessionManager configures ARWorldTrackingConfiguration
            (plane detection horizontal + vertical, light estimation)
  ARSessionDelegate: plane anchors → surface events;
    camera tracking state → trackingChanged; failures → error

Hit test: JS hitTest({x, y}) → normalised point → ARView.raycast
  → position + quaternion rotation [qx, qy, qz, qw] (same shape as
    Android) + a real ARAnchor registered with the session

Models (USDZ only): placeModel resolves usdzPath/usdzUrl, else the
  GLB's sibling .usdz (remote files download to Caches first)
  → Entity.load → AnchorEntity bound to a real ARAnchor
  → collision shapes + RealityKit gestures (move/rotate/scale)
  setTransform / setMaterial / moveModel / removeModel /
  getPlacedModels / clearModels operate on that registry for real

Data flow: JS → Three.js → WebXR

App ─ createARView({ overlay }) ─► ARView ─► ARCoreWeb
create() ─► setConfig() + startSession({ domOverlay })
  Three.js setup (once): WebGLRenderer, Scene, PerspectiveCamera (70°),
    lights, GLTFLoader, plane groups, reticle
  navigator.xr.requestSession('immersive-ar', {
    requiredFeatures: ['hit-test'],
    optionalFeatures: ['local-floor'?, 'plane-detection'?,
                       'light-estimation'?,
                       'camera-access'? (only with enableScreenshots),
                       'dom-overlay'? (with overlay)] })
  renderer.xr.setSession(); hit-test source from the viewer space;
  reference space: local-floor → local → viewer fallback chain

Per frame: viewer hit test → reticle pose + surface state
  (frame listeners notified on change, at most 10 Hz)
  every 8th frame: detected planes → dot/mesh visualisation
  anchor map → model + shadow transforms → render

Models: GLTFLoader.load(url) → cache → scene.clone() per placement
  → per-instance cloned materials → blob shadow plane per anchor
Gestures: Pointer Events on the overlay ─► facade callbacks ─► engine transforms

The native side at a glance

iOS: six Swift files under ios/Sources/ReticlexrPlugin/, one module mirroring the Android structure: the plugin facade (ARCorePlugin, jsName ARCore), a session manager (ARKit configuration + ARSessionDelegate), a view manager (the RealityKit ARView overlay), a model manager (the placed-model registry — real entities, not metadata), a coordinate mapper (normalised points, quaternion/euler/hex helpers) and an event emitter over notifyListeners. Distributed via Package.swift (Swift Package Manager) and Reticlexr.podspec (CocoaPods).

Android: eleven Java classes under android/src/main/java/com/capacitor/arcore/: the plugin facade, a session manager (sole owner of the ARCore Session), a Filament renderer with its own render thread, a surface manager, a coordinate mapper for hit tests, an event emitter, a view manager, plus an anchor manager that registers the real anchors created by hit tests, and a model manager that is currently a registry only (native model rendering is not implemented). What that means in practice is the subject of WebXR vs native ARCore.

Dependencies (verified from package.json)

KindPackageVersion
peerDependency@capacitor/core^8.5.2
peerDependencythree^0.180.0
peerDependencyreact>=16.8.0
Androidcom.google.ar:core1.40.0
AndroidFilament (filament-android, gltfio-android)1.52.0
Android SDKcompile / target / min36 / 36 / 24
iOSARKit + RealityKit (system frameworks)iOS 15+
iOS distributionPackage.swift (cap-swift-pm, Capacitor 8) + Reticlexr.podspec—

Lockfiles are committed for the package, the example app and this site (package-lock.json in each), so installs are reproducible with npm ci; the ranges above are what the package declares, and the lockfiles pin what actually resolves.