Confirm ARHit Ready
Confirm ARHit Ready
I am using Unity with Apples's ARKitHitTest script. I have created a prompt on the UI that asks the user to point at the ground and scan.
What I am trying to do is determine when the ARKit has enough points scanned to place target. Once I figured out how this is done I can then update the user Prompt to say ready to place. Can anyone please advise how I determine when ARKit is ready to place? Thanks!
1 Answer
1
ARKit has a number of methods which you can utilise to determine whether tracking is available, and whether for example conditions are not ideal for tracking.
These can be obtained in Unity by registering for the following callbacks:
Unity
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
UnityARSessionNativeInterface.ARSessionFailedEvent += ARSessionFailedEvent;
These can help you to determine whether tracking is available or limited for example.
Essentially when a Session has good conditions e.g the delegate informs us that:
ARTrackingStateReason.ARTrackingStateReasonNone
We know that conditions are suitable for placing an object, as enough featurePoints are available etc.
As such a Class to handle this might look like so:
public class ARTrackingStatusController : MonoBehaviour {
//1. Get Reference To The Session
private UnityARSessionNativeInterface augmentedRealitySession;
private string arTrackingStatus = "Preparing Device...";
//------------------
//MARK: - LifeCycle
//------------------
void Start () {
//1. Register For The ARFrame Updated Event Which In IOS = (func renderer(_ renderer: SCNSceneRenderer, updateAtTime time: TimeInterval))
UnityARSessionNativeInterface.ARFrameUpdatedEvent += ARFrameUpdated;
UnityARSessionNativeInterface.ARSessionFailedEvent += ARSessionFailedEvent;
}
void Update () {
//1. Update The Status Of The Session
print(arTrackingStatus);
}
//-------------------------
//MARK: - ARSCNViewDelegate
//-------------------------
/// <summary>
/// Called Each Time The ARCamera Is Updated
/// </summary>
/// <param name="camera">Camera.</param>
public void ARFrameUpdated (UnityARCamera camera)
{
//1. Track The ARSession
if (camera.trackingState == ARTrackingState.ARTrackingStateLimited) {
logTrackingStateReason (camera.trackingReason);
} else {
logTrackingState (camera.trackingState);
}
logLighting (camera.lightData.arLightEstimate.ambientIntensity);
}
/// <summary>
/// Logs The ARSession Failed Event
/// </summary>
/// <param name="error">Error.</param>
public void ARSessionFailedEvent (string error)
{
print (error);
}
//----------------------
//MARK: - Status Updates
//----------------------
/// <summary>
/// Informs The User About The Current Tracking State
/// </summary>
/// <param name="trackingState">Tracking state.</param>
public void logTrackingState (ARTrackingState trackingState)
{
switch (trackingState) {
case ARTrackingState.ARTrackingStateNormal:
arTrackingStatus = "Tracking Ready";
break;
case ARTrackingState.ARTrackingStateNotAvailable:
arTrackingStatus = "Tracking Unavailable";
break;
}
}
/// <summary>
/// Informs The User About The Current Tracking Status
/// </summary>
/// <param name="reason">Reason.</param>
public void logTrackingStateReason (ARTrackingStateReason reason)
{
switch (reason) {
case ARTrackingStateReason.ARTrackingStateReasonExcessiveMotion:
arTrackingStatus = "Please Slow Your Movement";
break;
case ARTrackingStateReason.ARTrackingStateReasonInsufficientFeatures:
arTrackingStatus = "Try To Point At A Flat Surface";
break;
case ARTrackingStateReason.ARTrackingStateReasonInitializing:
arTrackingStatus = "Initializing";
break;
case ARTrackingStateReason.ARTrackingStateReasonRelocalizing:
arTrackingStatus = "Relocalizing";
break;
case ARTrackingStateReason.ARTrackingStateReasonNone:
arTrackingStatus = "";
break;
}
}
/// <summary>
/// Determines If The Current Lighting Conditions Are Appropriate For The ARSession
/// </summary>
/// <param name="lightEstimate">Light estimate.</param>
public void logLighting (float lightEstimate)
{
if (lightEstimate < 100) {
arTrackingStatus = "Lighting Is To Dark";
}
}
Hope it helps...
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.