AR Session screen rotation adaptation
This article introduces how to configure AR Session when a WeChat Mini Program needs to run in landscape mode.
Before you begin
- Learn what the rotation angle of the camera image relative to the screen orientation is through AR-driven 3D rendering.
- Understand AR Session concepts and flow.
Screen orientation enum of the Mega Mini Program plugin
Note
For the definition of phone screen orientation, refer to the official definitions of systems such as IOS and Android.
Screen orientation enum of the Mega Mini Program plugin DeviceOrientation:
| Constant | Value | Description |
|---|---|---|
Portrait |
0 | Portrait |
LandscapeLeft |
90 | LandscapeLeft |
PortraitUpsideDown |
180 | PortraitUpsideDown |
LandscapeRight |
270 | LandscapeRight |
Modify screen orientation in the global WeChat Mini Program configuration
Add the window configuration in app.json. For the specific definition, see Respond to display area changes.
"window": {
"pageOrientation": "landscape"
}
Fill in "portrait" (portrait screen) or "landscape" (landscape screen) according to the actual situation.
Caution
Never use "auto" in an AR Mini Program app at any time. In some cases, it can cause severe AR image abnormalities.
Set screen orientation
Call setDeviceOrientation(deviceOrientation) and pass in the screen rotation direction. It can be called at any time and takes effect immediately.
For example, to use landscape mode where the screen is rotated 90 degrees counterclockwise relative to the natural portrait position:
let deviceOrientation = mega.DeviceOrientation.LandscapeLeft;
session.setDeviceOrientation(deviceOrientation);
The screen orientation setting provided by the mega plugin is intended to compensate for the lack of screen orientation monitoring in WeChat Mini Programs. WeChat provides only two options, portrait and landscape, in the pageOrientation setting, but these two options alone are not enough for AR applications. For example, landscape mode rotated 90 degrees counterclockwise from the natural orientation is completely different from landscape mode rotated 270 degrees counterclockwise from the natural orientation.
Therefore, when pageOrientation in app.json is set to portrait, you can omit calling setDeviceOrientation(deviceOrientation), because the natural portrait direction of a typical phone is the default orientation of session.
When pageOrientation in app.json is set to landscape, you must call setDeviceOrientation(deviceOrientation) to fix the screen orientation to LandscapeLeft or LandscapeRight