From 3b39086263bae125783c6b1395b4afde8f32d35a Mon Sep 17 00:00:00 2001 From: Jan Herling Date: Wed, 8 Jan 2025 20:44:12 -0800 Subject: [PATCH] Added event handling to AKDevice Summary: Just allowing to determine tracking states. Reviewed By: enpe Differential Revision: D67949270 fbshipit-source-id: 6824119c793c6d96491c83f2277a3d40bb328601 --- impl/ocean/devices/arkit/AKDevice.h | 9 ++++++- impl/ocean/devices/arkit/AKDevice.mm | 40 ++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) diff --git a/impl/ocean/devices/arkit/AKDevice.h b/impl/ocean/devices/arkit/AKDevice.h index 16313099..956827ac 100644 --- a/impl/ocean/devices/arkit/AKDevice.h +++ b/impl/ocean/devices/arkit/AKDevice.h @@ -19,7 +19,7 @@ #include -@interface AKTracker6DOFDelegate : NSObject +@interface AKTracker6DOFDelegate : NSObject @end namespace Ocean @@ -192,6 +192,13 @@ class OCEAN_DEVICES_ARKIT_EXPORT AKDevice : virtual public Device */ bool parameter(const std::string& parameter, Value& value) override; + /** + * Translates the value of an ARTrackingState to a readable string. + * @param state The state to translate + * @return The readable string + */ + static std::string translateTrackingState(const ARTrackingState& state); + /** * Translates the value of an ARGeoTrackingState to a readable string. * @param state The state to translate diff --git a/impl/ocean/devices/arkit/AKDevice.mm b/impl/ocean/devices/arkit/AKDevice.mm index b5c2b8cc..6a97e1ba 100644 --- a/impl/ocean/devices/arkit/AKDevice.mm +++ b/impl/ocean/devices/arkit/AKDevice.mm @@ -736,6 +736,28 @@ - (void)session:(ARSession *)session didRemoveAnchors:(NSArray<__kindof ARAnchor } } +- (void)session:(ARSession*)session cameraDidChangeTrackingState:(ARCamera*)camera +{ + Log::debug() << "ARKit camera tracking state changed: " << AKDevice::translateTrackingState(camera.trackingState); +} + +- (void)sessionWasInterrupted:(ARSession*)session +{ + Log::warning() << "ARKit session was interrupted"; +} + +- (void)sessionInterruptionEnded:(ARSession*)session +{ + Log::debug() << "ARKit session interruption ended"; +} + +- (BOOL)sessionShouldAttemptRelocalization:(ARSession*)session +{ + Log::debug() << "ARKit session should attempt relocalization"; + + return YES; +} + + (ARVideoFormat*)determinePreferredVideoFormat:(NSArray*)supportedVideoFormats withWidth:(unsigned int)preferredWidth withHeight:(unsigned int)preferredHeight withFps:(float)preferredFps withHDR:(int)preferredHDR { #ifdef OCEAN_DEBUG @@ -1025,6 +1047,24 @@ + (ARVideoFormat*)determinePreferredVideoFormat:(NSArray*)suppor return true; } +std::string AKDevice::translateTrackingState(const ARTrackingState& state) +{ + switch (state) + { + case ARTrackingStateNotAvailable: + return std::string("ARTrackingStateNotAvailable"); + + case ARTrackingStateLimited: + return std::string("ARTrackingStateLimited"); + + case ARTrackingStateNormal: + return std::string("ARTrackingStateNormal"); + } + + ocean_assert(false && "Unknown"); + return std::string("Unknown"); +} + API_AVAILABLE(ios(14.0)) std::string AKDevice::translateGeoTrackingState(const ARGeoTrackingState& state) {