Interface AugmentedRealityService
-
- All Known Implementing Classes:
AndroidAugmentedRealityService
,DefaultAugmentedRealityService
,DummyAugmentedRealityService
,IOSAugmentedRealityService
public interface AugmentedRealityService
The Augmented Reality Service allows accessing the native AR kit, if it is available. The developer can check if the device has Augmented Reality support.Example
AugmentedRealityService.create().ifPresent(service -> { Availability availability = service.checkAR(() -> { // perform action after ARCore is installed }); System.out.println("AR availability: " + availability.name()); });
/src/main/resources/
folder or subfolders.Example
The following example includes two files:
DukeKing.obj
andDukeKing.mtl
under thesrc/main/resources/models
folderAugmentedRealityService.create().ifPresent(service -> { ARModel model = new ARModel(); model.setName("DukeKing"); model.setObjFilename("models/DukeKing.obj"); model.setScale(0.8); 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
Note: these modifications are handled automatically by GluonFX plugin if it is used.<manifest ...> <uses-permission android:name="android.permission.CAMERA" /> <!--<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" />--> </application> </manifest>
Note: Uncomment the above commented lines if ARCore is strictly required.
Note: All these modifications are handled automatically by the GluonFX plugin during the package goal.iOS Configuration
None- 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.ReadOnlyObjectProperty<AugmentedRealityService.Availability>
availabilityProperty()
Property that can be used to listen if the AR availability has changedjavafx.beans.property.ReadOnlyBooleanProperty
cancelled()
Boolean property that can be used to listen if the AR session was cancelledstatic java.util.Optional<AugmentedRealityService>
create()
Returns an instance ofAugmentedRealityService
.void
debugAR(boolean enable)
Shows debug informationAugmentedRealityService.Availability
getAvailability()
Checks if device supports ARvoid
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
.
-
getAvailability
AugmentedRealityService.Availability getAvailability()
Checks if device supports AR- Returns:
- the availability of AR on the device
-
availabilityProperty
javafx.beans.property.ReadOnlyObjectProperty<AugmentedRealityService.Availability> availabilityProperty()
Property that can be used to listen if the AR availability has changed- Returns:
- a
ReadOnlyObjectProperty
-
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
-
-