Class 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)));
}
});
}
-
Method Summary
Modifier and TypeMethodDescriptionstatic ARCapabilitiesReturns which AR features this device supports.static booleanTrue when the running platform has a working AR implementation.static ARSessionopen(ARSessionOptions opts) Opens an AR session.static voidrequestPermissions(SuccessCallback<Boolean> callback) Requests the camera permission needed for AR.
-
Method Details
-
isSupported
public static boolean isSupported()True when the running platform has a working AR implementation. False on platforms and devices without AR support. -
getCapabilities
Returns which AR features this device supports. On unsupported platforms every capability reads false. -
open
Opens an AR session. Throws
IllegalStateExceptionwhen AR is unsupported or a session is already open; close the old session first.Parameters
opts: the session configuration; null uses the defaults
Returns
the running session
-
requestPermissions
Requests the camera permission needed for AR. The callback receives true when granted; it is invoked on the EDT.
Parameters
callback: receives the grant result; may be null
-