Plane AR tracker exception handling
This article introduces how to handle exceptions of the WeChat plane AR tracker by registering callbacks.
Before you start
Understand the MegaTracker workflow to learn:
- The plane AR tracker in xr-frame is essentially a wrapper for VisionKit 6DoF-plane capability.
- How MegaTracker works on xr-frame.
Understand the concept and process of AR session
Why plane detection exceptions occur
In specific scenarios (such as large white walls appearing in the frame, prolonged camera occlusion, etc.), the WeChat plane AR tracker may experience abnormal states.
At this time, the plane AR tracker cannot output the camera pose (i.e., 6DoF data) for each frame normally, which will cause MegaTracker to fail.
When the scene returns to normal (rich textures, camera unobstructed) for a period of time, the plane AR tracker will resume working, and MegaTracker will also recover.
Set behavior when plane detection is abnormal
Register an exception handling callback via setPlaneDetectionErrorBehavior(behavior). When an exception is detected, this callback will be triggered, allowing developers to implement custom prompts, hide 3D content, or other processing logic.
session.setPlaneDetectionErrorBehavior(() => {
wx.showToast({
icon: 'none',
title: `WeChat plane detection result is abnormal. Please move the camera back and forth over a plane to restore tracking`,
duration: 2000,
});
});
This example uses the setPlaneDetectionErrorBehavior(behavior) interface of the session to register a callback that pops up a Toast window when a plane detection exception is triggered.