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());
      });
    A 3D model with .obj format can be added, and when the user taps on the Augmented Reality world, it will be displayed. The .obj file can make reference to other .mtl files, and/or to texture files. All of these files have to be placed in the /src/main/resources/ folder or subfolders.

    Example

    The following example includes two files: DukeKing.obj and DukeKing.mtl under the src/main/resources/models folder

     AugmentedRealityService.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
    • Method Detail

      • 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