Skip to content

Commit 2e54459

Browse files
fix: separate semantics initialisation from cloud anchors
1 parent 4a4fbc0 commit 2e54459

4 files changed

Lines changed: 47 additions & 3 deletions

File tree

ios/ViroKit/VROARFrameiOS.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,4 +364,14 @@ VROMatrix4f VROARFrameiOS::getDepthTextureTransform() const {
364364
return matrix;
365365
}
366366

367+
float VROARFrameiOS::getSemanticLabelFraction(VROSemanticLabel label) {
368+
// Scene Semantics on iOS is provided through the ARCore SDK
369+
// Delegate to the session which has access to the ARCore provider
370+
std::shared_ptr<VROARSessioniOS> session = _session.lock();
371+
if (session) {
372+
return session->getSemanticLabelFraction(label);
373+
}
374+
return 0.0f;
375+
}
376+
367377
#endif

ios/ViroKit/VROARFrameiOS.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ class API_AVAILABLE(ios(12.0)) VROARFrameiOS : public VROARFrame {
8585
*/
8686
VROMatrix4f getDepthTextureTransform() const;
8787

88+
// Scene Semantics support (requires ARCore SDK with Semantics extension)
89+
float getSemanticLabelFraction(VROSemanticLabel label) override;
90+
8891
private:
8992

9093
ARFrame *_frame;

ios/ViroKit/VROARSessioniOS.cpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,18 @@ void VROARSessioniOS::removeGeospatialAnchor(std::shared_ptr<VROGeospatialAnchor
12551255
#pragma mark - Scene Semantics API
12561256

12571257
bool VROARSessioniOS::isSemanticModeSupported() const {
1258-
// Scene Semantics on iOS requires ARCore Geospatial SDK with Semantics extension
1259-
// Check if the cloud anchor provider with semantics support is available
1258+
// Scene Semantics on iOS requires ARCore SDK with Semantics extension
1259+
// Initialize the provider if needed to check support
1260+
if (_cloudAnchorProviderARCore == nil) {
1261+
// Try to create provider temporarily to check support
1262+
// Note: This is a const method, so we need a mutable cast
1263+
VROARSessioniOS *mutableSelf = const_cast<VROARSessioniOS *>(this);
1264+
mutableSelf->_cloudAnchorProviderARCore = [[VROCloudAnchorProviderARCore alloc] init];
1265+
if (mutableSelf->_cloudAnchorProviderARCore) {
1266+
pinfo("ARCore provider initialized for Scene Semantics support check");
1267+
}
1268+
}
1269+
12601270
if (_cloudAnchorProviderARCore != nil) {
12611271
return [_cloudAnchorProviderARCore isSemanticModeSupported];
12621272
}
@@ -1266,6 +1276,19 @@ bool VROARSessioniOS::isSemanticModeSupported() const {
12661276
void VROARSessioniOS::setSemanticModeEnabled(bool enabled) {
12671277
_semanticModeEnabled = enabled;
12681278

1279+
// Initialize ARCore provider if needed for semantics
1280+
if (_cloudAnchorProviderARCore == nil && enabled) {
1281+
_cloudAnchorProviderARCore = [[VROCloudAnchorProviderARCore alloc] init];
1282+
if (_cloudAnchorProviderARCore) {
1283+
pinfo("ARCore provider initialized for Scene Semantics");
1284+
} else {
1285+
pwarn("⚠️ Failed to initialize ARCore provider for Scene Semantics");
1286+
pwarn("⚠️ Make sure GARAPIKey is set in Info.plist");
1287+
_semanticModeEnabled = false;
1288+
return;
1289+
}
1290+
}
1291+
12691292
if (_cloudAnchorProviderARCore != nil) {
12701293
// Check if semantic mode is supported before enabling
12711294
if (enabled && !isSemanticModeSupported()) {
@@ -1277,11 +1300,18 @@ void VROARSessioniOS::setSemanticModeEnabled(bool enabled) {
12771300
[_cloudAnchorProviderARCore setSemanticModeEnabled:enabled];
12781301
pinfo("Scene Semantics mode set to %s", enabled ? "ENABLED" : "DISABLED");
12791302
} else if (enabled) {
1280-
pwarn("⚠️ Scene Semantics requires ARCore Geospatial provider to be configured");
1303+
pwarn("⚠️ Scene Semantics requires ARCore SDK. Add ARCore/Semantics pod to your Podfile.");
12811304
_semanticModeEnabled = false;
12821305
}
12831306
}
12841307

1308+
float VROARSessioniOS::getSemanticLabelFraction(VROSemanticLabel label) const {
1309+
if (_cloudAnchorProviderARCore != nil) {
1310+
return [_cloudAnchorProviderARCore getSemanticLabelFraction:(NSInteger)label];
1311+
}
1312+
return 0.0f;
1313+
}
1314+
12851315
#pragma mark - VROARKitSessionDelegate
12861316

12871317
@interface VROARKitSessionDelegate ()

ios/ViroKit/VROARSessioniOS.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ class API_AVAILABLE(ios(12.0)) VROARSessioniOS : public VROARSession, public std
131131
// Scene Semantics API
132132
bool isSemanticModeSupported() const override;
133133
void setSemanticModeEnabled(bool enabled) override;
134+
float getSemanticLabelFraction(VROSemanticLabel label) const;
134135

135136
/*
136137
Internal methods.

0 commit comments

Comments
 (0)