目录

Data Type Conversion

When you develop AR apps, certain data types need to be converted before they can be used. Below is a summary along with examples.

ArrayBuffer

For methods that do not support receiving the ArrayBuffer data type, the data must be deserialized into the int32 or float32 type. The list of APIs requiring the conversion is as follows.

API Description
ImageComponent The buffer parameter is of the ArrayBuffer type, which can be converted to int32.
ARPlane.getPolygonXZ The return value is of the ArrayBuffer type, which can be converted to float32.
ARSceneMesh.getVertices The return value is of the ArrayBuffer type, which can be converted to float32.
ARSceneMesh.getVertexNormals The return value is of the ArrayBuffer type, which can be converted to float32.
ARSceneMesh.getTriangleIndices The return value is of the ArrayBuffer type, which can be converted to int32.
ARSemanticDensePointData The id parameter is of the ArrayBuffer type, which can be converted to int32.
ARSemanticDensePointData The position parameter is of the ArrayBuffer type, which can be converted to float32.
ARSemanticDensePointData The color parameter is of the ArrayBuffer type, which can be converted to int32.

The following are conversion examples:

export function arrayBufferFloat32ToNumber(buffer: ArrayBuffer): number[] {
  let view: Float32Array = new Float32Array(buffer);
  let numberArray: number[] = Array.from(view);
  return numberArray;
}

export function arrayBufferInt32ToNumber(buffer: ArrayBuffer): number[] {
  let view: Int32Array = new Int32Array(buffer);
  let numberArray: number[] = Array.from(view);
  return numberArray;
}