public final class AR
- Object
- AR
Entry point for the cross-platform augmented reality API.
AR sessions track the device’s pose in the real world through the camera,
detect surfaces, and composite virtual 3D content into the camera image.
The typical flow: check #isSupported(), #open(ARSessionOptions) a
session, add its ARSession#createView() to a form, then place content by
hit testing taps against detected planes and hanging ARNodes on the
resulting anchors.
Permissions and dependencies: simply referencing classes in this
package causes the build pipeline to inject the camera permission, the
NSCameraUsageDescription plist entry (iOS, override via the
ios.NSCameraUsageDescription build hint) and the ARCore dependency
(Android). Devices without AR support report #isSupported() false;
always guard AR functionality behind that check.
if (AR.isSupported()) {
ARSession s = AR.open(new ARSessionOptions());
Form f = new Form("AR", new BorderLayout());
f.add(BorderLayout.CENTER, s.createView());
f.show();
// on tap: hit test and place a model
s.hitTest(xNorm, yNorm).ready(hits -> {
if (hits.length > 0) {
ARAnchor a = hits[0].createAnchor();
a.setNode(new ARNode(ARModel.fromGltf(modelBytes)));
}
});
}
Methods
public static boolean isSupported() | True when the running platform has a working AR implementation. |
public static ARCapabilities getCapabilities() | Returns which AR features this device supports. |
public static ARSession open(ARSessionOptions opts) | Opens an AR session. |
public static void requestPermissions(SuccessCallback<Boolean> callback) | Requests the camera permission needed for AR. |
Inherited methods
Method details
isSupported
public static boolean isSupported()getCapabilities
public static ARCapabilities getCapabilities()open
public static ARSession open(ARSessionOptions opts)IllegalStateException when AR is
unsupported or a session is already open; close the old session first.Parameters
optsARSessionOptions- the session configuration; null uses the defaults
Returns
requestPermissions
public static void requestPermissions(SuccessCallback<Boolean> callback)Parameters
callbackSuccessCallback<Boolean>- receives the grant result; may be null