Skip to content

Commit 216039b

Browse files
author
C. M. Barth
authored
Update XrContextHelperOpenXR.h to obtain native extension from the global navigator object (#185)
* move to custom branch * obtain xr context off of navigator * merge master into babylonnative * address review comments * move to most recent commit * move to most recent babylonnative commit
1 parent ef7ba06 commit 216039b

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Modules/@babylonjs/react-native-windows/windows/include/XrContextHelperOpenXR.h

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,29 @@
66

77
namespace BabylonReactNative
88
{
9-
bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, const facebook::jsi::Value& xrSession, IXrContextOpenXR*& xrContext)
9+
bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextOpenXR*& xrContext)
1010
{
1111
xrContext = nullptr;
12-
if (!xrSession.isObject() ||
13-
!xrSession.asObject(jsiRuntime).hasProperty(jsiRuntime, "nativeXrContext") ||
14-
!xrSession.asObject(jsiRuntime).hasProperty(jsiRuntime, "nativeXrContextType") ||
15-
xrSession.asObject(jsiRuntime).getProperty(jsiRuntime, "nativeXrContextType").asString(jsiRuntime).utf8(jsiRuntime) != "OpenXR")
12+
if (!jsiRuntime.global().hasProperty(jsiRuntime, "navigator"))
1613
{
1714
return false;
1815
}
1916

20-
auto nativeExtensionPtr = static_cast<uintptr_t>(xrSession.asObject(jsiRuntime).getProperty(jsiRuntime, "nativeXrContext").asNumber());
17+
auto navigator{ jsiRuntime.global().getProperty(jsiRuntime, "navigator").asObject(jsiRuntime) };
18+
if (!navigator.hasProperty(jsiRuntime, "xr"))
19+
{
20+
return false;
21+
}
22+
23+
auto nativeXr{ navigator.getProperty(jsiRuntime, "xr").asObject(jsiRuntime) };
24+
if (!nativeXr.hasProperty(jsiRuntime, "nativeXrContext") ||
25+
!nativeXr.hasProperty(jsiRuntime, "nativeXrContextType") ||
26+
nativeXr.getProperty(jsiRuntime, "nativeXrContextType").asString(jsiRuntime).utf8(jsiRuntime) != "OpenXR")
27+
{
28+
return false;
29+
}
30+
31+
auto nativeExtensionPtr = static_cast<uintptr_t>(nativeXr.getProperty(jsiRuntime, "nativeXrContext").asNumber());
2132
xrContext = reinterpret_cast<IXrContextOpenXR*>(nativeExtensionPtr);
2233
return true;
2334
}

0 commit comments

Comments
 (0)