Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions Modules/@babylonjs/react-native/shared/XrAnchorHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,47 @@ namespace Babylon::Plugins::NativeXr
}
#endif
#endif

#if __has_include("IXrContextARKit.h")
#include "IXrContextARKit.h"
#if __has_include("jsi/jsi.h")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels like something that should be handled at the CMake level (like we do with AppRuntime* etc) instead of doing compile-time if's

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these files can be referenced by anyone independent of whether they use cmake

namespace Babylon::Plugins::NativeXr
{
bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, ARAnchor*& nativeAnchor)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer to use reference to pointer, but I feel like the pattern in OpenXR/Vulkan/D3D is usually to do pointer to pointer. Idk which is actually better, just wanted to point it out

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, without looking too hard I think the first two references could be const all the way down

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree on switching things that aren't getting set to constants. I think that a reference to a pointer is more legible than a double pointer personally.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am going to leave things as they are for now. jsiRuntime.global() isn't marked as a const operation so we can get away with handing around a const jsiRuntime here.

{
nativeAnchor = nullptr;
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use auto here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

going to leave as uintptr_t to stay consistent with rest of file/avoid editing the rest of the file.

if (TryGetNativeAnchor(jsiRuntime, jsAnchor, nativeAnchorPtr))
{
nativeAnchor = reinterpret_cast<ARAnchor*>(nativeAnchorPtr);
return true;
}

return false;
}
}
#endif
#if __has_include("napi/env.h")
namespace Babylon::Plugins::NativeXr
{
bool TryGetNativeAnchor(Napi::Env env, Napi::Value anchor, ARAnchor*& nativeAnchor)
{
nativeAnchor = nullptr;
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
if (TryGetNativeAnchor(env, anchor, nativeAnchorPtr))
{
nativeAnchor = reinterpret_cast<ARAnchor*>(nativeAnchorPtr);
return true;
}

return false;
}

bool TryDeclareNativeAnchor(Napi::Env env, const Napi::Value& session, ARAnchor* nativeAnchor, Napi::Value& xrAnchor)
{
uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nativeAnchor)};
return TryDeclareNativeAnchor(env, session, nativeAnchorPtr, xrAnchor);
}
}
#endif
#endif
38 changes: 38 additions & 0 deletions Modules/@babylonjs/react-native/shared/XrContextHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,41 @@ namespace Babylon::Plugins::NativeXr
}
#endif
#endif

#if __has_include("IXrContextARKit.h")
#include "IXrContextARKit.h"
#if __has_include("jsi/jsi.h")
namespace Babylon::Plugins::NativeXr
{
bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextARKit*& xrContext)
{
xrContext = nullptr;
uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
if (TryGetXrContext(jsiRuntime, "ARKit", nativePtr))
{
xrContext = reinterpret_cast<IXrContextARKit*>(nativePtr);
return true;
}

return false;
}
}
#endif
#if __has_include("napi/env.h")
namespace Babylon::Plugins::NativeXr
{
bool TryGetXrContext(Napi::Env env, IXrContextARKit*& xrContext)
{
xrContext = nullptr;
uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
if (TryGetXrContext(env, "ARKit", nativePtr))
{
xrContext = reinterpret_cast<IXrContextARKit*>(nativePtr);
return true;
}

return false;
}
}
#endif
#endif