Using the Vuforia Fusion Platform Handle¶
Vuforia Engine provides access to ARKit and ARCore specific functionalities. This can be used to combine Vuforia functionality with functionality that only exists in ARKit and ARCore. For instance, an application can access plane boundaries or additional lighting information through this mechanism.
Detailed information on ARKit can be found here, and information on ARCore can be found here.
NOTE: The Platform Handle mechanism is only exposed in the native Vuforia Engine API.
Platform Access¶
Retrieve the platform controller to get access to platform-specific functionality by calling vuEngineGetPlatformController()
. Use then vuPlatformControllerGetFusionProviderPlatformType()
to return a VuFusionProviderPlatformType
struct with the platform provider info on the following supported types.
- VU_FUSION_PROVIDER_PLATFORM_TYPE_ARKIT
- VU_FUSION_PROVIDER_PLATFORM_TYPE_ARCORE
NOTE: Other platform fusion provider types exist but do not need handles to be provided.
The values contained within the struct are platform-specific and need to be used with platform-specific code. Please refer to the Vuforia Reference Documentation for more details on the enum types.
See also Vuforia Fusion for a more general introduction.
API Usage - Best Practices¶
Pointer ownership¶
Vuforia owns the pointers contained in this struct; developers must exercise caution while using them.
- Do not release or destroy the session or the frame.
- Do not pause the session.
- Do not reconfigure the session.
NOTE: Doing any of the above will cause Vuforia's handling of the information from the provider to fail in undefined ways.
Camera ownership¶
Vuforia owns the camera throughout this process. In order to change any camera properties such as the video mode or autofocus mode, you need to use Vuforia Engine's camera control APIs.
Pointer validity¶
- A valid value for the session will be available after the camera has been started and will remain valid until the camera is stopped.
- A valid value for the frame will be available after the camera has been started and will only be valid for the duration of one frame.
- The caller needs to request the frame information for every new frame.
Platform-Specific aspects¶
- No ARKit delegate callbacks are available on iOS.
- All information supplied through the callbacks is available via the ARSession.
- No Java-binding support on Android.
- Developer must use the ARCore C-API and if needed should use JNI to access this functionality from Kotlin or Java applications.
- Some parameters of the returned struct also have a platform-specific lifecycle.
Expected usage¶
It is expected that these calls will be most useful during the rendering phase of the application, and largely in a read-only mode from within an application's render loop.
Vuforia tracking Behavior¶
The behavior of Vuforia Engine has been modified to provide developers with more flexibility when making use of the vuPlatformControllerGetFusionProviderPlatformType()
API call.
Engine behavior on ARCore and ARKit
- In addition to horizontal planes, vertical planes will be enabled when
VuPlatformARKitInfo
orVuPlatformARCoreInfo
are populated with the relevant API calls.- Vuforia HitTest calls will continue to use only horizontal planes as specified by the
VuHitTestHint
.
- Vuforia HitTest calls will continue to use only horizontal planes as specified by the
- On Device Pose Observer reset, only Anchors that have been created by Vuforia Engine will be destroyed.
ARKit Platform-specific Pointer¶
For complete details of the ARKit API, developers should refer to the Apple documentation.
As Vuforia owns the pointers, you must use the (__bridge ARSession*)
cast in Objective-C to turn the void*
into an arSession
or arFrame
. This informs Objective-C's reference counting that the pointer should not be handled by the application.
The following code snippet in Swift is an extract from the native iOS sample; it demonstrates how to access the ARKit Session held by Vuforia.
- The
getARKitInfo()
method is declared in theVuforiaWrapper.h
to allow the ARKit Session and Frame pointers to be retrieved by the Swift code. getARKitInfo()
is implemented inVuforiaWrapper.cpp
- Employ a method such as the
accessFusionProviderPointers()
found in the native iOS sample in theVuforiaView.swift
file to get access to the ARKit session.
You can test the sample by connecting to an iOS device with a USB cable and build the project to the device with the debugging option enabled and a Vuforia license key added to the AppController.cpp
.
When running the application and clicking either the Model Target icon or the Image Target icon, a log is written in the debug console every 5 seconds displaying the tracking state.
ARCore Platform-specific Pointer¶
For complete details of the ARCore API, developers should refer to the Google documentation. As ARCore is a C-based API, it is sufficient to use a static_cast<>
to turn the pointer from a void*
into an ArSession
or ArFrame
. As this is an NDK pointer, this functionality cannot be used directly from within a Kotlin or Java Android application. If developers wish to use these APIs within a Kotlin or Java application, they will have to make the calls in a C/C++ source file invoked via JNI.
To enable ARCore in an Android project, modify the build.gradle
to include the ARCore native libraries. Please refer to the Google ARCore documentation or the Vuforia Android native sample's build.gradle
file on adding the library path. A summary of the steps to add ARCore native libraries is listed below.
- Add a path to extract the ARCore native libraries.
- Create a configuration to mark the
aars
to extract the.so
files from.
- Add dependencies for ARCore support.
- If applicable, add an argument to
externalNativeBuild
to pass ARCore to your CMake library.
- Add a task to
extractNativeLibraries
from the native configuration to allow the NDK API to access the libraries.
- Add a task
whenTaskAdded
to enable the use of ARCore APIs in the application.
- In your
CMakeLists.txt
, add the directives to include the ARCore libraries.
Include in your main application the arcore_c_api.h
available from the ARCore-Android-SDK repository. In the native samples, this is done in the VuforiaWrapper.cpp
. Employ a method to access the session pointers as demonstrated in the native Android sample's accessFusionProviderPointer()
.
You can test the sample by connecting to an Android device with a USB cable and build the project to the device with the debugging option enabled and a license key added to the AppController.cpp
.
When running the application and clicking either the Model Target icon or the Image Target icon, a log is written in the debug console every 5 seconds displaying the current tracking state.