This module provides APIs related to arViewController (AR scene management capabilities) of AR Engine.
The basic core capabilities include AR session management, spatial object management, and scene-based management.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Since: 5.1.0(18)
Facial keypoint type.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Since: 6.1.0(23)
| Name | Value | Description |
|---|---|---|
| LEFT_EYE | 0 | Left eye. |
| LEFT_SIDE_OF_MOUTH | 1 | Left side of the mouth. |
| RIGHT_EYE | 2 | Right eye. |
| RIGHT_SIDE_OF_MOUTH | 3 | Right side of the mouth. |
| TIP_OF_NOSE | 4 | Nose tip. |
| CENTER_OF_FACE | 5 | Center of the face. |
ARView context, which is used to manage AR scenes, including initialization, suspension, resumption, and destruction.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
init(): Promise<void>
Initializes ARViewContext to initialize the AR session and configure the AR rendering scene, among other tasks. This API uses a promise to return the result.
Required permissions: ohos.permission.CAMERA, ohos.permission.GYROSCOPE, and ohos.permission.ACCELEROMETER
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but returns error code 801 on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to Universal Error Codes and AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 201 | Permissions not granted, such as the camera permission. |
| 801 | Device not compatible. |
| 1009200001 | Failure. |
| 1009200007 | Configuration not supported. |
| 1009200008 | Resource exhausted. |
| 1009200009 | Service unavailable. |
| 1009200010 | Camera unavailable. |
| 1009200201 | ARView invalid operation. |
| 1009200202 | Graphics3D AR scene required. |
| 1009200203 | AREngine config required. |
| 1009200204 | AR session setup failed. |
| 1009200205 | AR scene camera setup failed. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
await context.init(); pause(): void
Pauses camera tracking and AR scene rendering.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200001 | Failure. |
| 1009200201 | ARView invalid operation. |
| 1009200204 | AR session setup failed. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.pause(); destroy(): Promise<void>
Destroys ARViewContext to release the resources used by ARView, including terminating the AR session and dismantling the presented scene. This should be used when exiting ARView. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200001 | Failure. |
| 1009200201 | ARView invalid operation. |
| 1009200204 | AR session setup failed. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.destroy(); resume(): void
Resumes paused camera tracking and AR scene rendering.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200001 | Failure. |
| 1009200010 | Camera unavailable. |
| 1009200201 | ARView invalid operation. |
| 1009200204 | AR session setup failed. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.resume(); set scene(scene: Scene)
Sets the AR scene of ARView.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| scene | Scene | Yes | AR scene, which is used to manage spatial nodes. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { Scene } from '@kit.ArkGraphics3D';
import { arViewController } from '@kit.AREngine';
Scene.load().then((scene: Scene) => {
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.scene = scene;
}).catch((err: BusinessError) => {
console.error(`Failed to load scene. Code is ${err.code}, message is ${err.message}.`);
}); get scene(): Scene
Obtains the AR scene for managing spatial nodes.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Returns:
| Type | Description |
|---|---|
| Scene | AR scene, which is used to manage spatial nodes. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { Scene } from '@kit.ArkGraphics3D';
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.scene; get session(): arEngine.ARSession | undefined
Obtains AR sessions, which are used to obtain AR environment tracking, camera tracking, hit testing, and other capabilities, such as camera pose, plane information, and anchor creation.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Returns:
| Type | Description |
|---|---|
| arEngine.ARSession | undefined | AR session content obtained. If the AR session is set successfully, arEngine.ARSession is returned. If ARViewContext fails to be initialized due to an abnormal setting or operation, undefined is returned. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.session; set config(conf: arEngine.ARConfig)
Sets the AR session configuration files, including north-facing coordinates, performance modes, and more.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| conf | arEngine.ARConfig | Yes | Function configuration parameters of ARSession. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.config = {
type: arEngine.ARType.WORLD,
poseMode: arEngine.ARPoseMode.GRAVITY_AND_HEADING,
powerMode: arEngine.ARPowerMode.POWER_SAVING,
depthMode: arEngine.ARDepthMode.AUTOMATIC
}; loadAsset(resourcePath: ResourceStr, landmark: LandmarkType): Promise<void>
Places a model at a specified keypoint. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| resourcePath | ResourceStr | Yes | Path for storing the model. |
| landmark | LandmarkType | Yes | Keypoint where the model is to be placed. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
// Local path for storing the model.
let resourcePath:ResourceStr = $rawfile('xxxx/xxxx');
context.loadAsset(resourcePath, arViewController.LandmarkType.LEFT_EYE); removeAsset(landmark: LandmarkType):Promise<void>
Removes a placed model from a specified keypoint. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| landmark | LandmarkType | Yes | Keypoint where the model is to be removed. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.removeAsset(arViewController.LandmarkType.LEFT_EYE); clearResource():Promise<void>
Clears all placed models. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Returns:
| Type | Description |
|---|---|
| Promise<void> | Promise that returns no value. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.clearResource(); setBlendShapeWeight(node: Node, type: arEngine.ARBlendShapeType, weight: number): boolean
Sets the weight of a specific micro-expression in a specified node for rendering the expression.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| node | Node | Yes | AR scene node corresponding to the new anchor. Note: Nodes belong to the Ark Graphics Platform (AGP) rendering engine and use the AGP-aligned world coordinate system, which is different from the gravity-aligned world coordinate system used by AR Engine. You need to distinguish between the two when using the anchor parameter. For details, please refer to Coordinate System. |
| type | arEngine.ARBlendShapeType | Yes | Micro-expression type. |
| weight | number | Yes | Micro-expression weight. The value ranges from 0 to 1. |
Returns:
| Type | Description |
|---|---|
| boolean | Micro-expression weight setting result. The value true indicates that the operation is successful, and the value false indicates the opposite. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Node } from '@kit.ArkGraphics3D';
onAnchorUpdate(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
ctx.setBlendShapeWeight(node, arEngine.ARBlendShapeType.EYE_BLINK_LEFT, 0.1);
} getBlendShapeWeight(node: Node, type: arEngine.ARBlendShapeType): number | null
Obtains the weight of a specific micro-expression in a specified node.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| node | Node | Yes | AR scene node corresponding to the new anchor. Note: Nodes belong to the Ark Graphics Platform (AGP) rendering engine and use the AGP-aligned world coordinate system, which is different from the gravity-aligned world coordinate system used by AR Engine. You need to distinguish between the two when using the anchor parameter. For details, please refer to Coordinate System. |
| type | arEngine.ARBlendShapeType | Yes | Micro-expression type. |
Returns:
| Type | Description |
|---|---|
| number | null | Weight of the current micro-expression. If the passed node or type is incorrect, null is returned. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Node } from '@kit.ArkGraphics3D';
onAnchorUpdate(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
ctx.getBlendShapeWeight(node, arEngine.ARBlendShapeType.EYE_BLINK_LEFT);
} transformPose(position: Vec3, rotation: Quaternion): arEngine.ARPose | null
Converts the pose information from the AR coordinate system to the AGP rendering engine coordinate system and returns the converted pose information.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| position | Vec3 | Yes | Pose coordinate information. |
| rotation | Quaternion | Yes | Pose orientation information. |
Returns:
| Type | Description |
|---|---|
| arEngine.ARPose | null | Pose information after conversion. If the input parameter is invalid or the ARPose object fails to be created, null is returned. |
Example:
import { arViewController } from '@kit.AREngine';
import { Vec3, Quaternion } from '@kit.ArkGraphics3D';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
let pose: Vec3 = { x: 1.0, y: -1.0, z: -0.5 };
let rot: Quaternion = {
x: -0.1,
y: 0.2,
z: -0.3,
w: 0.5
};
context.transformPose(pose, rot); loadGSModel(resourcePath: spatialRender.GSImportSettings, location: arEngine.ARPose): Promise<number>
Loads a 3DGS model. Only one model can be loaded in each session. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| resourcePath | spatialRender.GSImportSettings | Yes | Path for storing the model. |
| location | arEngine.ARPose | Yes | Placement pose of the model. |
Returns:
| Type | Description |
|---|---|
| Promise<number> | Promise used to return the ID of the 3DGS model. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Vec3, Quaternion } from '@kit.ArkGraphics3D';
import { spatialRender } from '@kit.SpatialReconKit';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
// Local path for storing the model.
let resourcePath: spatialRender.GSImportSettings = { uri: 'OhosRawFile://assets/gltf/model.glb', offset: 0 };
let r: Quaternion = {
x: 0,
y: 0,
z: 0,
w: 0
};
let t: Vec3 = { x: 0, y: 0, z: 0 };
let location: arEngine.ARPose = arEngine.createARPose(r, t);
await context.loadGSModel(resourcePath, location); removeGSModel(modelID: number):Promise<boolean>
Removes a placed model based on the model ID. This API uses a promise to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 26.0.0
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| modelID | number | Yes | ID of the model to be removed. |
Returns:
| Type | Description |
|---|---|
| Promise<boolean> | Promise used to return the model removal result. The value true indicates that the model is removed successfully, and the value false indicates that the model fails to be removed. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arViewController } from '@kit.AREngine';
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
await context.removeGSModel(1); set callback(callback: ARViewCallback)
Sets callback function to implement corresponding service logic via callback. This API uses an asynchronous callback to return the result.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| callback | ARViewCallback | Yes | Abstract class of ARViewCallback, which declares the callback API of ARView. This API uses an asynchronous callback to return the result. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200201 | ARView invalid operation. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Node } from '@kit.ArkGraphics3D';
class ARViewCallbackImpl extends arViewController.ARViewCallback {
onAnchorAdd(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
console.info('onAnchorAdd');
console.info(`add anchor id = ${String(anchor.id)}`);
console.info(`add anchor translation = ${anchor.getPose().translation}`);
console.info(`add node pose = ${node.position}`);
}
onAnchorUpdate(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
console.info('onAnchorUpdate');
console.info(`update anchor id = ${String(anchor.id)}`);
console.info(`update anchor translation = ${anchor.getPose().translation}`);
console.info(`update node pose = ${node.position}`);
}
async onFrameUpdate(ctx: arViewController.ARViewContext, sysBootTs: number): Promise<void> {
let arSession: arEngine.ARSession | undefined = ctx.session;
if (arSession) {
let frame: arEngine.ARFrame = arSession.getFrame();
if (!frame) {
console.error('Failed to get arSession.frame, it is undefined or null');
} else {
console.info(`Succeeded in getting arSession.frame = ${frame.timestamp}`);
await frame.release();
}
} else {
console.error('Failed to get arSession, arSession is undefined');
}
}
}
let context: arViewController.ARViewContext = new arViewController.ARViewContext();
context.callback = new ARViewCallbackImpl(); Abstract class of ARViewCallback, which declares the callback API of ARView. This API uses an asynchronous callback to return the result.
You need to inherit this class and implement the callback child class based on the service logic.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
abstract onAnchorAdd(ctx: ARViewContext, node: Node, anchor: arEngine.ARAnchor): void
When a new plane is detected in an AR session, an anchor and a corresponding scene node are automatically created for the plane, and this callback function is automatically triggered in the frame refresh logic.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| ctx | ARViewContext | Yes | Context information (ARViewContext) of ARView. |
| node | Node | Yes | AR scene node corresponding to the new anchor. Note: Nodes belong to the Ark Graphics Platform (AGP) rendering engine and use the AGP-aligned world coordinate system, which is different from the gravity-aligned world coordinate system used by AR Engine. You need to distinguish between the two when using the anchor parameter. For details, please refer to Coordinate System. |
| anchor | arEngine.ARAnchor | Yes | Anchor created for the new plane. Note: The pose of ARAnchor uses the gravity-aligned world coordinate system of AR Engine. For details, please refer to Coordinate System. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Node } from '@kit.ArkGraphics3D';
// Create a callback class by referring to the sample code of the ARViewContext.callback API and then implement this API.
onAnchorAdd(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
// Other operations.
} abstract onAnchorUpdate(ctx: ARViewContext, node: Node, anchor: arEngine.ARAnchor): void
Called when ARView automatically detects the scene node corresponding to the anchor and calls the callback function after the anchor in the AR session is updated.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| ctx | ARViewContext | Yes | Context information (ARViewContext) of ARView. |
| node | Node | Yes | AR scene node corresponding to the new anchor. Note: Nodes belong to the Ark Graphics Platform (AGP) rendering engine and use the AGP-aligned world coordinate system, which is different from the gravity-aligned world coordinate system used by AR Engine. You need to distinguish between the two when using the anchor parameter. For details, please refer to Coordinate System. |
| anchor | arEngine.ARAnchor | Yes | Anchor to be updated. Note: The pose of ARAnchor uses the gravity-aligned world coordinate system of AR Engine. For details, please refer to Coordinate System. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
import { Node } from '@kit.ArkGraphics3D';
// Create a callback class by referring to the sample code of the ARViewContext.callback API and then implement this API.
onAnchorUpdate(ctx: arViewController.ARViewContext, node: Node, anchor: arEngine.ARAnchor): void {
// Other operations.
} abstract onFrameUpdate(ctx: ARViewContext, sysBootTs: number): void
Automatically triggered before each frame is refreshed in an AR scene. You can adjust the placement pose of AR entities, animations, and camera pose based on this callback.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Device behavior differences: This API can be properly called on some phones, tablets, and TVs, but cannot be called on devices that do not support this API. You can use the arViewController.isARTypeSupported API to check whether the capability is supported.
Since: 5.1.0(18)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| ctx | ARViewContext | Yes | Context information of ARView. |
| sysBootTs | number | Yes | Timestamp, in microseconds. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
// Create a callback class by referring to the sample code of the ARViewContext.callback API and then implement this API.
onFrameUpdate(ctx: arViewController.ARViewContext, sysBootTs: number): void {
let arSession: arEngine.ARSession | undefined = ctx.session;
if (arSession) {
let frame: arEngine.ARFrame = arSession.getFrame();
if (!frame){
console.error('Failed to get arSession.frame, it is undefined or null');
} else {
console.info(`Succeeded in getting arSession.frame = ${frame.timestamp}`);
await frame.release();
}
} else {
console.error('Failed to get arSession, arSession is undefined');
}
} isARTypeSupported(type: arEngine.ARFeatureType): boolean
Called in ARViewController to check whether the AR feature can run on the current device.
Model restriction: This API can be used only in the stage model.
System capability: SystemCapability.AREngine.Core
Since: 6.1.0(23)
Parameters:
| Parameter | Type | Mandatory | Description |
|---|---|---|---|
| type | arEngine.ARFeatureType | Yes | AR feature to be checked. |
Returns:
| Type | Description |
|---|---|
| boolean | AR feature check result. The value true indicates that the device supports the feature, and false indicates that the device does not support the feature. |
Error codes:
For details about the error codes, please refer to AR Engine Error Codes.
| ID | Error Message |
|---|---|
| 1009200001 | Failure. |
Example:
import { arEngine, arViewController } from '@kit.AREngine';
arViewController.isARTypeSupported(arEngine.ARFeatureType.ARENGINE_FEATURE_TYPE_FACE);