Skip to content

Commit a8ca60b

Browse files
author
C. M. Barth
authored
Support interacting with ARKit XR system in external native modules (#260)
* add ios helper functions * update bn * update babylon native dependencies * update BabylonNative dependencies * remove unneeded file * update babylonnative * update to correct commit
1 parent 5f0abf2 commit a8ca60b

File tree

3 files changed

+83
-1
lines changed

3 files changed

+83
-1
lines changed

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

+44
Original file line numberDiff line numberDiff line change
@@ -183,3 +183,47 @@ namespace Babylon::Plugins::NativeXr
183183
}
184184
#endif
185185
#endif
186+
187+
#if __has_include("IXrContextARKit.h")
188+
#include "IXrContextARKit.h"
189+
#if __has_include("jsi/jsi.h")
190+
namespace Babylon::Plugins::NativeXr
191+
{
192+
bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, ARAnchor*& nativeAnchor)
193+
{
194+
nativeAnchor = nullptr;
195+
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
196+
if (TryGetNativeAnchor(jsiRuntime, jsAnchor, nativeAnchorPtr))
197+
{
198+
nativeAnchor = reinterpret_cast<ARAnchor*>(nativeAnchorPtr);
199+
return true;
200+
}
201+
202+
return false;
203+
}
204+
}
205+
#endif
206+
#if __has_include("napi/env.h")
207+
namespace Babylon::Plugins::NativeXr
208+
{
209+
bool TryGetNativeAnchor(Napi::Env env, Napi::Value anchor, ARAnchor*& nativeAnchor)
210+
{
211+
nativeAnchor = nullptr;
212+
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
213+
if (TryGetNativeAnchor(env, anchor, nativeAnchorPtr))
214+
{
215+
nativeAnchor = reinterpret_cast<ARAnchor*>(nativeAnchorPtr);
216+
return true;
217+
}
218+
219+
return false;
220+
}
221+
222+
bool TryDeclareNativeAnchor(Napi::Env env, const Napi::Value& session, ARAnchor* nativeAnchor, Napi::Value& xrAnchor)
223+
{
224+
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nativeAnchor)};
225+
return TryDeclareNativeAnchor(env, session, nativeAnchorPtr, xrAnchor);
226+
}
227+
}
228+
#endif
229+
#endif

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

+38
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,41 @@ namespace Babylon::Plugins::NativeXr
139139
}
140140
#endif
141141
#endif
142+
143+
#if __has_include("IXrContextARKit.h")
144+
#include "IXrContextARKit.h"
145+
#if __has_include("jsi/jsi.h")
146+
namespace Babylon::Plugins::NativeXr
147+
{
148+
bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextARKit*& xrContext)
149+
{
150+
xrContext = nullptr;
151+
uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
152+
if (TryGetXrContext(jsiRuntime, "ARKit", nativePtr))
153+
{
154+
xrContext = reinterpret_cast<IXrContextARKit*>(nativePtr);
155+
return true;
156+
}
157+
158+
return false;
159+
}
160+
}
161+
#endif
162+
#if __has_include("napi/env.h")
163+
namespace Babylon::Plugins::NativeXr
164+
{
165+
bool TryGetXrContext(Napi::Env env, IXrContextARKit*& xrContext)
166+
{
167+
xrContext = nullptr;
168+
uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
169+
if (TryGetXrContext(env, "ARKit", nativePtr))
170+
{
171+
xrContext = reinterpret_cast<IXrContextARKit*>(nativePtr);
172+
return true;
173+
}
174+
175+
return false;
176+
}
177+
}
178+
#endif
179+
#endif

0 commit comments

Comments
 (0)