-
- All Known Implementing Classes:
DefaultAugmentedRealityService
,DummyAugmentedRealityService
,IOSAugmentedRealityService
public interface AugmentedRealityService
The Augmented Reality Service allows accesing the native AR kit, if it is available. The developer can check if the device has Augmented Reality support.Example
Services.get(AugmentedRealityService.class).ifPresent(service -> { Availability availability = service.checkAR(() -> { // perform action after ARCore is installed }); System.out.println("AR availabity: " + availability.name()); });
/src/main/resources/
folder or subfolders.Example
The following example includes two files:
DukeKing.obj
andDukeKing.mtl
under theassets/models
folder on iOS and AndroidServices.get(AugmentedRealityService.class).ifPresent(service -> { ARModel model = new ARModel(); model.setName("DukeKing"); model.setObjFilename("models/DukeKing.obj"); model.setScale(0.9); service.setModel(model); service.cancelled().addListener((obs, ov, nv) -> { if (nv) { System.out.println("AR was cancelled"); } }); service.showAR(); });
Android Configuration
Add the following to the manifest
<manifest ...> <uses-permission android:name="android.permission.CAMERA" /> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26"/> <!--<uses-feature android:name="android.hardware.camera.ar" android:required="true"/>--> <application ...> <meta-data android:name="com.google.ar.core" android:value="optional" /> <!--<meta-data android:name="com.google.ar.core" android:value="required" />--> <meta-data android:name="com.google.ar.core.min_apk_version" android:value="180815000" /> ... <activity android:name="com.google.ar.core.InstallActivity"/> </application> </manifest>
Note: Uncomment the above commented lines if ARCore is strictly required.
The 3D model files (.obj, .mtl, .png, ...) have to be placed directly or within a folder under
/src/ios/assets/
iOS Configuration
The following frameworks have to be added to the iOS configuration in the build file:
ios { infoPList = file('src/ios/Default-Info.plist') frameworks = ['ARKit', 'SceneKit', 'CoreImage', 'CoreVideo'] ... }
The following keys are required:
<key>UIRequiredDeviceCapabilities</key> <array> <string>arm64</string> <!--<string>arkit</string>--> </array> <key>MinimumOSVersion</key> <string>11.0</string> <key>NSCameraUsageDescription</key> <string>This application will use the camera for Augmented Reality.</string>
Note: Uncomment the above commented line if ARKit is strictly required.
The 3D model files (.obj, .mtl, .png, ...) have to be placed directly or within a folder under under
/src/android/assets/
or/src/main/resources/assets/
- Since:
- 3.9.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
AugmentedRealityService.Availability
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Modifier and Type Method Description javafx.beans.property.ReadOnlyBooleanProperty
cancelled()
Boolean property that can be used to listen if the AR session was cancelledAugmentedRealityService.Availability
checkAR(java.lang.Runnable afterInstall)
Checks if device supports ARstatic java.util.Optional<AugmentedRealityService>
create()
Returns an instance ofAugmentedRealityService
.void
debugAR(boolean enable)
Shows debug informationvoid
setModel(ARModel model)
Sets the 3D model that is going to be used by the AR session.void
showAR()
Opens AR
-
-
-
Method Detail
-
create
static java.util.Optional<AugmentedRealityService> create()
Returns an instance ofAugmentedRealityService
.- Returns:
- An instance of
AugmentedRealityService
.
-
checkAR
AugmentedRealityService.Availability checkAR(java.lang.Runnable afterInstall)
Checks if device supports AR- Parameters:
afterInstall
- action that can be performed if AR is installed successfully- Returns:
- the availability of AR on the device
-
setModel
void setModel(ARModel model)
Sets the 3D model that is going to be used by the AR session. The .obj 3D model can be displayed during the AR session when the user taps on the screen after the camera recognizes a feature plane or point The model files have to be placed directly or within a folder under/src/ios/assets/
for iOS, while for Android these can be placed under/src/android/assets/
or/src/main/resources/assets/
.- Parameters:
model
- the entity model
-
showAR
void showAR()
Opens AR
-
debugAR
void debugAR(boolean enable)
Shows debug information- Parameters:
enable
- set to true to get verbose output
-
cancelled
javafx.beans.property.ReadOnlyBooleanProperty cancelled()
Boolean property that can be used to listen if the AR session was cancelled- Returns:
- a
ReadOnlyBooleanProperty
-
-