Skip to content

Commit db7609e

Browse files
author
C. M. Barth
authored
Add helper header for declaring native anchors created outside the babylonnative xr session (#244)
* add ability to declare xr anchor created externally * update babylonnative repo to pick up changes in master for declare anchor
1 parent 8cd481f commit db7609e

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

Modules/@babylonjs/react-native/shared/XrAnchorHelper.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,36 @@ namespace Babylon::Plugins::NativeXr
6969
nativeAnchorPtr = static_cast<uintptr_t>(getNativeAnchor.Call({ anchor }).As<Napi::Number>().DoubleValue());
7070
return true;
7171
}
72+
73+
bool TryDeclareNativeAnchor(Napi::Env env, const Napi::Value& session, uintptr_t nativeAnchorPtr, Napi::Value& xrAnchor)
74+
{
75+
xrAnchor = env.Undefined();
76+
if (!session.IsObject())
77+
{
78+
return false;
79+
}
80+
81+
if (!env.Global().Has("navigator"))
82+
{
83+
return false;
84+
}
85+
86+
auto navigator{ env.Global().Get("navigator").ToObject() };
87+
if (!navigator.Has("xr"))
88+
{
89+
return false;
90+
}
91+
92+
auto nativeXr{ navigator.Get("xr").ToObject() };
93+
if (!nativeXr.Has("declareNativeAnchor"))
94+
{
95+
return false;
96+
}
97+
98+
auto declareNativeAnchor{nativeXr.Get("declareNativeAnchor").As<Napi::Function>()};
99+
xrAnchor = declareNativeAnchor.Call({ session, Napi::Number::From(env, nativeAnchorPtr) });
100+
return true;
101+
}
72102
}
73103
#endif
74104

@@ -144,6 +174,12 @@ namespace Babylon::Plugins::NativeXr
144174

145175
return false;
146176
}
177+
178+
bool TryDeclareNativeAnchor(Napi::Env env, const Napi::Value& session, ArAnchor* nativeAnchor, Napi::Value& xrAnchor)
179+
{
180+
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nativeAnchor)};
181+
return TryDeclareNativeAnchor(env, session, nativeAnchorPtr, xrAnchor);
182+
}
147183
}
148184
#endif
149185
#endif

0 commit comments

Comments
 (0)