AR Session concepts and flow in the Mega WeChat Mini Program plugin
This document introduces the concepts and flow of AR Session in the Mega WeChat Mini Program plugin.
What AR Session is
The AR Session provided by the Mega WeChat Mini Program plugin is the entry point for all AR features. It manages the runtime process and state, including obtaining data from VisionKit and the sensor APIs provided by WeChat, fusing cloud localization and local AR tracker results, and driving the movement and rendering of the camera and other objects in the scene.
flowchart LR
Pose(VisionKit camera pose) -- Sync every frame --> Session[Session]
Image(Camera image used to calculate the camera pose of this frame) -. Sent only during Mega localization .-> Session
Sensor(WeChat sensor data) -. Async .-> Session
Session -- Transform --> Camera(xr-frame camera)
AR Session flow
flowchart LR
Start((" "))
End((" "))
Init[Initializing]
Run[Running]
Check{Success?}
Start -->|Call start| Init
Init --> Check
Check -->|Yes| Run
Check -->|No / retry count exceeds the limit| End
Run -->|Call stop| End
Start: the session state changes to Initializing. This includes environment checks, resource loading, and waiting for the AR system of WeChat xr-frame to become ready.
Run: the session state changes to Running. At this stage, the session outputs tracking results every frame and updates the Transform of the xr-frame camera.
Stop: the session state changes to None. This includes releasing resources, resetting state, and destroying MegaTracker.
Warning
AR features can be used only after the session starts successfully.
AR Session states:
| State | Description |
|---|---|
| None | Initial state; the session has not started or initialization failed |
| Initializing | Initialization in progress |
| Running | Running state; the session has started and initialization is complete |
[Optional] AR Session in the WeChat Mini Program plugin and AR Session in Unity
Note
Only for developers migrating Unity projects.
The AR Session in the Mega WeChat Mini Program plugin is a simplified version of AR Session in Unity. Because concurrent use of other algorithm components is not supported, the AR Session in WeChat Mini Program uses pre-integrated data source components and algorithm components. Users cannot select data sources and/or assemble algorithm components.
In addition, the Mega WeChat Mini Program plugin can be considered to support only targets of type Block and center mode centered on the target.