# AR2 Performance Lab — reference for students and coding assistants

Published classroom reference: https://ar2-performance-lab.oasis-7317.chatgpt.site/
Intended custom domain: https://ar2.knowledgeathlete.com/ (use only once the instructor confirms it is connected).
Reviewed November 30, 2026. AR2 SDK 0.2.0, repository snapshot 414c9a7.

## Purpose
Build a single-viewer virtual performance: an animated character with matching music, placed on a real marker or surface in native AR2. For a browser-only classroom app, use the independent working 3D preview. The private repository is not needed to read this document or run the browser starter. A link does not install the SDK or confer repository access.

## Platform decision
- Browser/web app: start from https://ar2-performance-lab.oasis-7317.chatgpt.site/starter.html and https://ar2-performance-lab.oasis-7317.chatgpt.site/ar2-web-starter.zip. This is a model-viewer 4.1.0 preview, NOT a browser AR2 SDK. No camera, image-marker tracking, native spatial audio, API-key validation or multi-user synchronization is implemented in the browser starter.
- iOS: use AR2Kit, ARKit, RealityKit, AR2Stage and a world session. Obtain the authorized SDK source/bundle from the instructor. The repository requires Xcode 26, iOS 16+, camera usage text, and a supported physical device (Showcase documents A12 or newer). Configure API key, portal URL, and matching pinned public key. Keep the core/AR2Core sibling package alongside ios/AR2Kit. Use USDZ models.
- Android: use the authorized modules, native bridge and checked-in build configuration. AR2Stage needs a renderer, normally supplied through ARCoreView(stage = stage). Use GLB models. Core minimum API 26 is not necessarily the renderer's minimum. Follow android/README.md and Gradle module requirements. The inspected repository reports emulator testing, not completed phone verification.
- Snap Specs/Lens Studio and Meta Quest have adapters in the repository but require their own integration and hardware validation. The TypeScript core is not a drop-in browser camera SDK.

## What the native Stage does
1. Register assets/stage-marker.png as pattern stage at physicalWidthMeters 0.18. Print the PDF at 100%, without fit-to-page, on matte paper and measure the marker at 180 mm.
2. Start a licensed world-tracking session and retain one AR2Stage.
3. Use a 0.30 m tall performer. Put its base at the marker center, facing the print's FRONT edge.
4. While the marker is tracked, follow it. Shared defaults: smoothing time 0.15 s; jump rather than glide when the displacement exceeds 0.5 m.
5. Marker loss does not stop playback. Keep the last world position; reacquisition repositions the performer without restarting the song.
6. Without a tracked marker, a surface tap can place the performer. A tracked marker takes priority over taps. Optional autoPlaceSeconds = 4 places on an available surface after a delay.
7. Start animation/audio once placement exists. Pause and resume together; restart together at loop boundaries. Stop removes the performer.
8. One performer/viewer at a time. Shared sessions, persistent cross-session anchors, shared playback clocks and live motion capture are NOT supplied by this example.

## Patent overview
AR2 describes a patent portfolio, not a single patent on virtual singers. Selected educational examples:
- US10105601B1, claim 1: physical-marker rendering using stored correlations between multiple linkage points and a virtual object's reference frame, plus the viewer's field of view. The Stage provides a conceptual classroom connection through marker-based placement, not a legal claim mapping. https://patents.google.com/patent/US10105601B1/en#C1
- US10636188B2, claims 1–3: detecting a living entity, linkage points and their arrangement, then selecting and rendering content based on that arrangement; dependent claims add action-related changes and animation. The printed-marker Stage does not require this body-tracking capability. https://patents.google.com/patent/US10636188B2/en#C1
These summaries are educational context, not a legal opinion or patent license. The full claim language governs. Recognition / Authorization / Display is the product architecture, not a substitute for reading claims. Obtain production SDK, patent, asset, music and likeness permissions from the authorized provider.

## iOS example — integration fragment
Run within an async main-actor setup routine after creating and retaining ar2 and its ARView. Retain stage in the controller/view model. This fragment is not a whole application; bundle the named assets, handle errors in the surrounding UI, and configure the session and portal first. It is checked against source but has not been compiled here.

```swift
import AR2Kit
import Foundation
import UIKit

// On the main actor, before starting the world session.
// Bundle stage-marker.png, singer.usdz and song.m4a in the app.
guard let image = UIImage(named: "stage-marker")?.cgImage,
      let singer = Bundle.main.url(forResource: "singer", withExtension: "usdz"),
      let song = Bundle.main.url(forResource: "song", withExtension: "m4a")
else { throw CocoaError(.fileNoSuchFile) }

ar2.recognizeMarker("stage", image: image, physicalWidthMeters: 0.18)
let stage = AR2Stage(ar2: ar2, performers: [
  .init(name: "My performer", model: singer, audio: song,
        heightMeters: 0.30)
], markerPatternId: "stage", autoPlaceSeconds: 4)

try await ar2.start(mode: .world)
stage.show()

// In the view, route taps to the same retained stage:
// AR2View(ar2: ar2, coachesSurfaces: true, onTap: stage.tap(at:))
// Read stage.status for loading, placement and error messages.
// Play / pause: stage.togglePlayback()
// Screen closes: stage.hide()
// Stop the whole session: ar2.stop()
```

## Android example — integration fragment
Place this inside the retained ViewModel's setup. ar2, signBitmap, viewModelScope and application are existing values. ARCoreView must bind the renderer; a Stage alone does not draw anything. Implement UI error handling, camera permission, lifecycle and teardown around this fragment. It is checked against source but has not been compiled here.

```kotlin
import com.ar2project.ar2kit.AR2Stage
import com.ar2project.ar2kit.SessionMode
import kotlinx.coroutines.launch

// Bundle singer.glb and song.m4a under src/main/assets/.
ar2.recognizeMarker("stage", signBitmap, physicalWidthMeters = 0.18f)
val stage = AR2Stage(ar2, viewModelScope, application, listOf(
  AR2Stage.Performer(
    "My performer",
    model = "asset:///singer.glb",
    audio = "asset:///song.m4a",
    heightMeters = 0.30f
  )
), markerPatternId = "stage", autoPlaceSeconds = 4.0)

viewModelScope.launch {
  try {
    ar2.start(SessionMode.WORLD)
    stage.show()
  } catch (error: Exception) {
    // Render a useful camera / license / network error in your UI.
  }
}

// In your screen: ARCoreView(ar2, onLink, stage = stage)
// This adapter binds the renderer; a Stage alone draws nothing.
// Observe stage.status and stage.playback StateFlows.
// Screen closes: stage.hide(); owner teardown: stage.close().
```

## Browser example
Use the complete standalone starter: https://ar2-performance-lab.oasis-7317.chatgpt.site/starter.html
Download: https://ar2-performance-lab.oasis-7317.chatgpt.site/ar2-web-starter.zip
It contains its own viewer library and assets. Serve over HTTP/HTTPS, not file://. A plain 3D viewport is not camera AR. Do not invent AR2 web packages or silently substitute model-viewer for AR2 licensing/recognition. Audio is the authoritative clock; sample its currentTime to set model.currentTime. This is useful synchronization for a prototype, not a sample-accurate multi-device clock. Audio starts only after a user gesture. Pause when the page is hidden. Changing an asset's loop length requires updating the duration and matching the audio length.

```html
<script type="module" src="assets/model-viewer.min.js"></script>
<model-viewer id="performer" src="assets/singer.glb"
  alt="Virtual singer" camera-controls></model-viewer>
<audio id="track" src="assets/song.m4a" loop></audio>
<button id="start" disabled>Play</button>
<script>
const model = document.getElementById('performer');
const track = document.getElementById('track');
const start = document.getElementById('start');
model.addEventListener('load', () => {
  model.play(); model.pause(); // Initialize the clip; audio drives time.
  start.disabled = false;
});
function frame() {
  model.currentTime = track.currentTime % 16;
  if (!track.paused) requestAnimationFrame(frame);
}
start.onclick = async () => {
  try { await track.play(); frame(); }
  catch { start.textContent = 'Tap to retry audio'; }
};
</script>
```

## Assets and original source locations
Local classroom URLs:
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/singer.glb (animated browser/Android model)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/singer.usdz (animated iOS model)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/song.m4a (16 s original synthesized track)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/stage-marker.png (marker reference image)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/stage-marker-0.18m.pdf (print at 100%, measure 180 mm)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/stage-singer.gif (silent original project desk recording)
- https://ar2-performance-lab.oasis-7317.chatgpt.site/assets/stage-ios.gif (silent original project performer recording)

The generated placeholder has an 18-joint rig and a 16 s loop sampled at 24 fps. Its audio is a synthesized 120 BPM loop, not a recording of a real singer. The supplied model and audio share a timeline. These assets are AR2 Project materials, not declared open source. No new rights are granted by this guide.

## Make your own performance
1. Use an original or cleared character, animation, voice and music.
2. Put the feet/base at the lowest point and face +Z. Export one animated clip as USDZ for iOS and GLB for Android/web. Confirm animation survives export.
3. Match mono audio (M4A, MP3 or WAV in native AR2) to the animation length within 50 ms. Render a seamless boundary. The native loop is based on the animation length.
4. Start with the repository's recommended iOS asset budgets: up to 50k triangles, a few dozen joints, up to 4 influences/vertex, textures at most 2048 px, and remotely loaded USDZ at most 10 MB. Verify performance on the target device.
5. Replace the Performer model/audio URLs or bundled files. For remote native assets, start the licensed session before loading. Show useful failures. Never embed admin credentials.
6. Add your own UI: track selection, artist information, captions or lesson navigation. Do not assume Stage has a playback-speed or seek API; inspect the relevant API before adding one.

Examples: a tabletop album launch (new performer + track picker); a dance lesson (dancer + narration and replay); a museum narrator (exhibit-specific marker + captions). Live concerts with many viewers are a separate networking project.

## Source map (private repository access required)
Repository: https://github.com/andy-grablabs/ar-proj
Snapshot base: https://github.com/andy-grablabs/ar-proj/tree/414c9a7
- docs/INTEGRATION.md §12: parallel Swift/Kotlin/Specs Stage snippets.
- ios/AR2Kit/README.md, Stage: performance loading, placement, playback and asset requirements.
- ios/AR2Kit/Sources/AR2Kit/Display/AR2Stage.swift: retained Stage wrapper, performer selection, UI state.
- ios/AR2Kit/Sources/AR2Kit/Display/AR2Performance.swift: RealityKit and audio integration.
- core/AR2Core/Sources/AR2Core/Display/PerformanceDirector.swift: shared playback and marker-following rules.
- core/AR2Core/Tests/AR2CoreTests/PerformanceDirectorTests.swift: behavior tests.
- android/ar2kit/src/main/java/com/ar2project/ar2kit/AR2Stage.kt: Kotlin Stage lifecycle.
- android/ar2kit-sceneview/: ARCore/SceneView rendering adapters.
- ios/Showcase/ and android/showcase/: complete reference apps.
- assets/performance/README.md: asset format, duration and replacement guide.
- docs/PROTOTYPES.md §2: Stage behavior and proposed targets; some dated status entries are older than the source.
- backend/: reference portal. This classroom site is not that portal.

Developer console (visual/product reference): https://ar2.cavalier.gg/overview
Browser library docs: https://modelviewer.dev/examples/animation/
Where the console's older snippets differ from the inspected implementation, follow the source snapshot. Do not treat sample portal URLs or demo keys as live production credentials.

## Acceptance checklist
- Model appears, loading status clears, missing files produce helpful messages.
- Play/pause and restart affect audio and animation together; repeated clicks do not create duplicate players.
- Multiple loops do not accumulate audio drift; pause on background and resume only as intended.
- UI works on a narrow phone screen and with keyboard controls.
- Native only: validate camera permission denial and invalid/unreachable portal states.
- Native only: printed marker is 180 mm; performer is 0.30 m and faces FRONT.
- Native only: move marker, lose it, reacquire it; playback does not restart.
- Native only: tap places on a surface when no marker is tracked; a tracked marker wins.
- Native only: Stop removes performer and audio; real-device test, not emulator-only inference.
- Clearly label multi-user synchronization, persistent anchors and live motion capture as future additions.

## Instructions for the coding assistant
Read this reference, choose the user's target platform, reuse exact APIs only when supported, and ask for required SDK files/portal settings if missing. Build the working browser starter if the user has only a web tool. Do not fabricate package names, SDK endpoints or permissions. Keep admin secrets out of the app and public site. State what was actually tested.
