AR session screen rotation adaptation
This article introduces how to configure AR Session when landscape mode is required for WeChat Mini Program.
Before you begin
- Understand what camera image rotation angle relative to screen orientation is through AR-powered 3D rendering.
- Understand AR Session concepts and workflow.
Screen orientation enumeration in mega mini program plugin
Note
Refer to official IOS, Android definitions for mobile screen orientation.
Mega Mini Program plugin screen orientation enumeration DeviceOrientation:
| Constant | Value | Description |
|---|---|---|
Portrait |
0 | Portrait |
LandscapeLeft |
90 | LandscapeLeft |
PortraitUpsideDown |
180 | PortraitUpsideDown |
LandscapeRight |
270 | LandscapeRight |
Modify screen orientation in WeChat Mini Program global configuration
Add window configuration in app.json, see Responsive display area changes for details.
"window": {
"pageOrientation": "landscape"
}
Fill in "portrait" or "landscape" based on actual needs.
Caution
Never use "auto" in AR mini program applications, as it may cause severe anomalies in AR display under certain circumstances.
Setting screen orientation
Call setDeviceOrientation(deviceOrientation) with screen rotation direction. Can be called anytime with immediate effect.
For example, to use in landscape mode rotated 90 degrees counterclockwise relative to natural vertical position:
let deviceOrientation = mega.DeviceOrientation.LandscapeLeft;
session.setDeviceOrientation(deviceOrientation);
The screen orientation setting provided by the mega plugin is to compensate for the lack of screen orientation monitoring in WeChat Mini Programs. WeChat only provides portrait and landscape options in pageOrientation settings, which are insufficient for AR applications. For example, landscape rotated 90 degrees counterclockwise from natural orientation is completely different from landscape rotated 270 degrees counterclockwise.
Therefore when pageOrientation in app.json is set to portrait, calling setDeviceOrientation(deviceOrientation) may be omitted since natural vertical orientation is usually the default session orientation.
When pageOrientation in app.json is set to landscape, you must call setDeviceOrientation(deviceOrientation) to fix screen orientation to either LandscapeLeft or LandscapeRight