Skip to content

Commit 7077d58

Browse files
C. M. Barthryantrem
andauthored
Add helper header to obtain native anchor pointer from xr anchor (#195)
* update babylonnative * change branch reference for now * add native anchor access * fix helper header to compile * update babylonnative * move back to correct repo reference * Update Modules/@babylonjs/react-native-windows/windows/include/XrAnchorHelperOpenXR.h Co-authored-by: Ryan Tremblay <[email protected]> * expose ability to get native anchor Co-authored-by: Ryan Tremblay <[email protected]>
1 parent 222cb55 commit 7077d58

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#pragma once
2+
3+
#if __has_include("jsi/jsi.h")
4+
#include "jsi/jsi.h"
5+
#include <openxr/openxr.h>
6+
7+
namespace BabylonReactNative
8+
{
9+
bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, XrSpatialAnchorMSFT& nativeAnchor)
10+
{
11+
nativeAnchor = nullptr;
12+
if (!jsAnchor.isObject())
13+
{
14+
return false;
15+
}
16+
17+
if (!jsiRuntime.global().hasProperty(jsiRuntime, "navigator"))
18+
{
19+
return false;
20+
}
21+
22+
auto navigator{ jsiRuntime.global().getProperty(jsiRuntime, "navigator").asObject(jsiRuntime) };
23+
if (!navigator.hasProperty(jsiRuntime, "xr"))
24+
{
25+
return false;
26+
}
27+
28+
auto nativeXr{ navigator.getProperty(jsiRuntime, "xr").asObject(jsiRuntime) };
29+
if (!nativeXr.hasProperty(jsiRuntime, "getNativeAnchor"))
30+
{
31+
return false;
32+
}
33+
34+
auto getNativeAnchor{nativeXr.getPropertyAsFunction(jsiRuntime, "getNativeAnchor")};
35+
auto nativeAnchorPtr{static_cast<uintptr_t>(getNativeAnchor.call(jsiRuntime, { jsAnchor.asObject(jsiRuntime) }).asNumber())};
36+
37+
nativeAnchor = reinterpret_cast<XrSpatialAnchorMSFT>(nativeAnchorPtr);
38+
return true;
39+
}
40+
}
41+
#endif

0 commit comments

Comments
 (0)