@babylonjs/react-native 0.4.0-alpha.7 → 0.64.0-alpha.47

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/BabylonModule.d.ts +2 -0
  2. package/{BabylonModule.ts → BabylonModule.js} +9 -12
  3. package/BabylonModule.js.map +1 -0
  4. package/EngineHook.d.ts +3 -0
  5. package/EngineHook.js +179 -0
  6. package/EngineHook.js.map +1 -0
  7. package/EngineView.d.ts +13 -0
  8. package/EngineView.js +118 -0
  9. package/EngineView.js.map +1 -0
  10. package/FontFace.d.ts +12 -0
  11. package/FontFace.js +35 -0
  12. package/FontFace.js.map +1 -0
  13. package/NativeCapture.d.ts +14 -0
  14. package/NativeCapture.js +14 -0
  15. package/NativeCapture.js.map +1 -0
  16. package/README.md +8 -8
  17. package/ReactNativeEngine.d.ts +7 -0
  18. package/ReactNativeEngine.js +33 -0
  19. package/ReactNativeEngine.js.map +1 -0
  20. package/VersionValidation.d.ts +1 -0
  21. package/{VersionValidation.ts → VersionValidation.js} +3 -3
  22. package/VersionValidation.js.map +1 -0
  23. package/android/build.gradle +13 -1
  24. package/android/include/IXrContextARCore.h +10 -0
  25. package/android/src/main/java/com/babylonreactnative/BabylonModule.java +6 -4
  26. package/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java +20 -6
  27. package/android/src/main/java/com/babylonreactnative/EngineView.java +151 -8
  28. package/android/src/main/java/com/babylonreactnative/EngineViewManager.java +8 -0
  29. package/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so +0 -0
  30. package/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so +0 -0
  31. package/android/src/main/jniLibs/armeabi-v7a/libBabylonNative.so +0 -0
  32. package/android/src/main/jniLibs/armeabi-v7a/libturbomodulejsijni.so +0 -0
  33. package/android/src/main/jniLibs/x86/libBabylonNative.so +0 -0
  34. package/android/src/main/jniLibs/x86/libturbomodulejsijni.so +0 -0
  35. package/index.d.ts +4 -0
  36. package/index.js +5 -0
  37. package/index.js.map +1 -0
  38. package/ios/BabylonModule.mm +7 -0
  39. package/ios/BabylonNativeInterop.h +4 -0
  40. package/ios/BabylonNativeInterop.mm +37 -14
  41. package/ios/EngineViewManager.mm +41 -3
  42. package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +7609 -9451
  43. package/ios/include/IXrContextARKit.h +10 -0
  44. package/ios/libs/libBabylonNative.a +0 -0
  45. package/ios/libs/libCanvas.a +0 -0
  46. package/ios/libs/libGenericCodeGen.a +0 -0
  47. package/ios/libs/libGraphics.a +0 -0
  48. package/ios/libs/libJsRuntime.a +0 -0
  49. package/ios/libs/libMachineIndependent.a +0 -0
  50. package/ios/libs/libNativeCapture.a +0 -0
  51. package/ios/libs/libNativeEngine.a +0 -0
  52. package/ios/libs/libNativeInput.a +0 -0
  53. package/ios/libs/libNativeOptimizations.a +0 -0
  54. package/ios/libs/libNativeTracing.a +0 -0
  55. package/ios/libs/libNativeXr.a +0 -0
  56. package/ios/libs/libOGLCompiler.a +0 -0
  57. package/ios/libs/libOSDependent.a +0 -0
  58. package/ios/libs/libSPIRV.a +0 -0
  59. package/ios/libs/libUrlLib.a +0 -0
  60. package/ios/libs/libWindow.a +0 -0
  61. package/ios/libs/libXMLHttpRequest.a +0 -0
  62. package/ios/libs/libastc-codec.a +0 -0
  63. package/ios/libs/libastc.a +0 -0
  64. package/ios/libs/libbgfx.a +0 -0
  65. package/ios/libs/libbimg.a +0 -0
  66. package/ios/libs/libbx.a +0 -0
  67. package/ios/libs/libglslang.a +0 -0
  68. package/ios/libs/libnapi.a +0 -0
  69. package/ios/libs/libspirv-cross-core.a +0 -0
  70. package/ios/libs/libspirv-cross-glsl.a +0 -0
  71. package/ios/libs/libspirv-cross-msl.a +0 -0
  72. package/ios/libs/libtinyexr.a +0 -0
  73. package/ios/libs/libxr.a +0 -0
  74. package/package.json +53 -52
  75. package/shared/BabylonNative.h +30 -3
  76. package/shared/XrAnchorHelper.h +229 -0
  77. package/shared/XrContextHelper.h +179 -0
  78. package/EngineHook.ts +0 -103
  79. package/EngineView.tsx +0 -156
  80. package/ReactNativeEngine.ts +0 -69
  81. package/index.ts +0 -2
  82. package/ios/libs/libspirv-cross-hlsl.a +0 -0
@@ -0,0 +1,10 @@
1
+ #pragma once
2
+
3
+ #include <ARKit/ARKit.h>
4
+
5
+ typedef struct IXrContextARKit
6
+ {
7
+ virtual bool IsInitialized() const = 0;
8
+ virtual ARSession* XrSession() const = 0;
9
+ virtual ARFrame* XrFrame() const = 0;
10
+ } IXrContextARKit;
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/ios/libs/libbx.a CHANGED
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
package/ios/libs/libxr.a CHANGED
Binary file
package/package.json CHANGED
@@ -1,54 +1,55 @@
1
1
  {
2
- "name": "@babylonjs/react-native",
3
- "title": "React Native Babylon",
4
- "version": "0.4.0-alpha.7",
5
- "description": "Babylon Native integration into React Native",
6
- "main": "index.ts",
7
- "scripts": {
8
- "test": "echo \"Error: no test specified\" && exit 1"
9
- },
10
- "repository": {
11
- "type": "git",
12
- "url": "git+https://github.com/babylonjs/BabylonReactNative.git",
13
- "baseUrl": "https://github.com/babylonjs/BabylonReactNative"
14
- },
15
- "keywords": [
16
- "react-native"
17
- ],
18
- "author": {
19
- "name": "Your Name",
20
- "email": "yourname@email.com"
21
- },
22
- "homepage": "https://github.com/BabylonJS/BabylonReactNative#readme",
23
- "license": "MIT",
24
- "licenseFilename": "LICENSE",
25
- "readmeFilename": "README.md",
26
- "dependencies": {
27
- "base-64": "^0.1.0",
28
- "semver": "^7.3.2"
29
- },
30
- "peerDependencies": {
31
- "@babylonjs/core": "^5.0.0-alpha.9",
32
- "react": "^16.13.1",
33
- "react-native": "^0.63.1",
34
- "react-native-permissions": "^2.1.4"
35
- },
36
- "devDependencies": {
37
- "@babel/core": "^7.8.4",
38
- "@babel/runtime": "^7.8.4",
39
- "@rnw-scripts/eslint-config": "0.1.6",
40
- "@rnw-scripts/ts-config": "0.1.0",
41
- "@types/base-64": "^0.1.3",
42
- "@types/jest": "^25.2.1",
43
- "@types/react": "^16.9.32",
44
- "@types/react-native": "^0.63.1",
45
- "@types/react-native-permissions": "^2.0.0",
46
- "@types/react-test-renderer": "^16.9.2",
47
- "@types/semver": "^7.3.4",
48
- "eslint": "7.12.0",
49
- "just-scripts": "^0.44.7",
50
- "metro-react-native-babel-preset": "^0.56.0",
51
- "prettier": "1.19.1",
52
- "react-test-renderer": "17.0.1"
53
- }
2
+ "name": "@babylonjs/react-native",
3
+ "title": "React Native Babylon",
4
+ "version": "0.64.0-alpha.47",
5
+ "description": "Babylon Native integration into React Native",
6
+ "main": "index.js",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/babylonjs/BabylonReactNative.git",
13
+ "baseUrl": "https://github.com/babylonjs/BabylonReactNative"
14
+ },
15
+ "keywords": [
16
+ "react-native"
17
+ ],
18
+ "author": {
19
+ "name": "Your Name",
20
+ "email": "yourname@email.com"
21
+ },
22
+ "homepage": "https://github.com/BabylonJS/BabylonReactNative#readme",
23
+ "license": "MIT",
24
+ "licenseFilename": "LICENSE",
25
+ "readmeFilename": "README.md",
26
+ "dependencies": {
27
+ "base-64": "^0.1.0",
28
+ "semver": "^7.3.2"
29
+ },
30
+ "peerDependencies": {
31
+ "@babylonjs/core": "^5.0.0-alpha.65",
32
+ "react": ">=16.13.1",
33
+ "react-native": ">=0.63.1 <0.65.0",
34
+ "react-native-permissions": "^2.1.4"
35
+ },
36
+ "devDependencies": {
37
+ "@babel/core": "^7.8.4",
38
+ "@babel/runtime": "^7.8.4",
39
+ "@babylonjs/core": "5.0.0-alpha.65",
40
+ "@rnw-scripts/eslint-config": "0.1.6",
41
+ "@rnw-scripts/ts-config": "0.1.0",
42
+ "@types/base-64": "^0.1.3",
43
+ "@types/jest": "^25.2.1",
44
+ "@types/react": "^16.9.32",
45
+ "@types/react-native": "^0.63.1",
46
+ "@types/react-native-permissions": "^2.0.0",
47
+ "@types/react-test-renderer": "^16.9.2",
48
+ "@types/semver": "^7.3.4",
49
+ "eslint": "7.12.0",
50
+ "just-scripts": "^0.44.7",
51
+ "metro-react-native-babel-preset": "^0.56.0",
52
+ "prettier": "1.19.1",
53
+ "typescript": "^4.3.5"
54
+ }
54
55
  }
@@ -2,19 +2,46 @@
2
2
 
3
3
  #include <jsi/jsi.h>
4
4
 
5
- namespace Babylon
5
+ #if defined(__APPLE__)
6
+ #include <MetalKit/MTKView.h>
7
+ #elif defined(ANDROID)
8
+ #include <android/native_window.h>
9
+ #elif WINAPI_FAMILY == WINAPI_FAMILY_APP
10
+ #include <winrt/Windows.UI.Xaml.Controls.h>
11
+ #endif
12
+
13
+ namespace BabylonNative
6
14
  {
15
+ #if defined(__APPLE__)
16
+ using WindowType = MTKView*;
17
+ #elif defined(ANDROID)
18
+ using WindowType = ANativeWindow*;
19
+ #elif WINAPI_FAMILY == WINAPI_FAMILY_APP
20
+ using WindowType = winrt::Windows::UI::Xaml::Controls::SwapChainPanel;
21
+ #else
22
+ #error Unsupported platform
23
+ #endif
24
+
7
25
  using Dispatcher = std::function<void(std::function<void()>)>;
8
26
 
9
- void Initialize(facebook::jsi::Runtime& jsiRuntime, Dispatcher jsDispatcher, bool autoRender = true);
27
+ void Initialize(facebook::jsi::Runtime& jsiRuntime, Dispatcher jsDispatcher);
10
28
  void Deinitialize();
11
- void UpdateView(void* windowPtr, size_t width, size_t height, void* windowTypePtr = nullptr);
29
+
30
+ void UpdateView(WindowType window, size_t width, size_t height);
31
+
12
32
  void RenderView();
33
+ void ResetView();
13
34
  void SetMouseButtonState(uint32_t buttonId, bool isDown, uint32_t x, uint32_t y);
14
35
  void SetMousePosition(uint32_t x, uint32_t y);
15
36
  void SetTouchButtonState(uint32_t pointerId, bool isDown, uint32_t x, uint32_t y);
16
37
  void SetTouchPosition(uint32_t pointerId, uint32_t x, uint32_t y);
17
38
 
39
+ bool IsXRActive();
40
+
41
+ #if defined(__APPLE__) || defined(ANDROID)
42
+ void UpdateXRView(WindowType window);
43
+ #endif
44
+
18
45
  extern const uint32_t LEFT_MOUSE_BUTTON_ID;
19
46
  extern const uint32_t MIDDLE_MOUSE_BUTTON_ID;
20
47
  extern const uint32_t RIGHT_MOUSE_BUTTON_ID;
@@ -0,0 +1,229 @@
1
+ #pragma once
2
+
3
+ #if __has_include("jsi/jsi.h")
4
+ #include "jsi/jsi.h"
5
+ namespace Babylon::Plugins::NativeXr
6
+ {
7
+ bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, uintptr_t& nativeAnchorPtr)
8
+ {
9
+ nativeAnchorPtr = reinterpret_cast<uintptr_t>(nullptr);
10
+ if (!jsAnchor.isObject())
11
+ {
12
+ return false;
13
+ }
14
+
15
+ if (!jsiRuntime.global().hasProperty(jsiRuntime, "navigator"))
16
+ {
17
+ return false;
18
+ }
19
+
20
+ auto navigator{ jsiRuntime.global().getProperty(jsiRuntime, "navigator").asObject(jsiRuntime) };
21
+ if (!navigator.hasProperty(jsiRuntime, "xr"))
22
+ {
23
+ return false;
24
+ }
25
+
26
+ auto nativeXr{ navigator.getProperty(jsiRuntime, "xr").asObject(jsiRuntime) };
27
+ if (!nativeXr.hasProperty(jsiRuntime, "getNativeAnchor"))
28
+ {
29
+ return false;
30
+ }
31
+
32
+ auto getNativeAnchor{nativeXr.getPropertyAsFunction(jsiRuntime, "getNativeAnchor")};
33
+ nativeAnchorPtr = static_cast<uintptr_t>(getNativeAnchor.call(jsiRuntime, { jsAnchor.asObject(jsiRuntime) }).asNumber());
34
+ return true;
35
+ }
36
+ }
37
+ #endif
38
+
39
+ #if __has_include("napi/env.h")
40
+ #include "napi/env.h"
41
+ namespace Babylon::Plugins::NativeXr
42
+ {
43
+ bool TryGetNativeAnchor(Napi::Env env, Napi::Value anchor, uintptr_t& nativeAnchorPtr)
44
+ {
45
+ nativeAnchorPtr = reinterpret_cast<uintptr_t>(nullptr);
46
+ if (!anchor.IsObject())
47
+ {
48
+ return false;
49
+ }
50
+
51
+ if (!env.Global().Has("navigator"))
52
+ {
53
+ return false;
54
+ }
55
+
56
+ auto navigator{ env.Global().Get("navigator").ToObject() };
57
+ if (!navigator.Has("xr"))
58
+ {
59
+ return false;
60
+ }
61
+
62
+ auto nativeXr{ navigator.Get("xr").ToObject() };
63
+ if (!nativeXr.Has("getNativeAnchor"))
64
+ {
65
+ return false;
66
+ }
67
+
68
+ auto getNativeAnchor{nativeXr.Get("getNativeAnchor").As<Napi::Function>()};
69
+ nativeAnchorPtr = static_cast<uintptr_t>(getNativeAnchor.Call({ anchor }).As<Napi::Number>().DoubleValue());
70
+ return true;
71
+ }
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
+ }
102
+ }
103
+ #endif
104
+
105
+ #if __has_include("IXrContextOpenXR.h")
106
+ #include "IXrContextOpenXR.h"
107
+ #if __has_include("jsi/jsi.h")
108
+ namespace Babylon::Plugins::NativeXr
109
+ {
110
+ bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, XrSpatialAnchorMSFT& nativeAnchor)
111
+ {
112
+ nativeAnchor = nullptr;
113
+ uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
114
+ if (TryGetNativeAnchor(jsiRuntime, jsAnchor, nativeAnchorPtr))
115
+ {
116
+ nativeAnchor = reinterpret_cast<XrSpatialAnchorMSFT>(nativeAnchorPtr);
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+ }
123
+ #endif
124
+ #if __has_include("napi/env.h")
125
+ namespace Babylon::Plugins::NativeXr
126
+ {
127
+ bool TryGetNativeAnchor(Napi::Env env, Napi::Value anchor, XrSpatialAnchorMSFT& nativeAnchor)
128
+ {
129
+ nativeAnchor = nullptr;
130
+ uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
131
+ if (TryGetNativeAnchor(env, anchor, nativeAnchorPtr))
132
+ {
133
+ nativeAnchor = reinterpret_cast<XrSpatialAnchorMSFT>(nativeAnchorPtr);
134
+ return true;
135
+ }
136
+
137
+ return false;
138
+ }
139
+ }
140
+ #endif
141
+ #endif
142
+
143
+ #if __has_include("IXrContextARCore.h")
144
+ #include "IXrContextARCore.h"
145
+ #if __has_include("jsi/jsi.h")
146
+ namespace Babylon::Plugins::NativeXr
147
+ {
148
+ bool TryGetNativeAnchor(facebook::jsi::Runtime& jsiRuntime, facebook::jsi::Value& jsAnchor, ArAnchor*& nativeAnchor)
149
+ {
150
+ nativeAnchor = nullptr;
151
+ uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
152
+ if (TryGetNativeAnchor(jsiRuntime, jsAnchor, nativeAnchorPtr))
153
+ {
154
+ nativeAnchor = reinterpret_cast<ArAnchor*>(nativeAnchorPtr);
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 TryGetNativeAnchor(Napi::Env env, Napi::Value anchor, ArAnchor*& nativeAnchor)
166
+ {
167
+ nativeAnchor = nullptr;
168
+ uintptr_t nativeAnchorPtr{reinterpret_cast<uintptr_t>(nullptr)};
169
+ if (TryGetNativeAnchor(env, anchor, nativeAnchorPtr))
170
+ {
171
+ nativeAnchor = reinterpret_cast<ArAnchor*>(nativeAnchorPtr);
172
+ return true;
173
+ }
174
+
175
+ return false;
176
+ }
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
+ }
183
+ }
184
+ #endif
185
+ #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
@@ -0,0 +1,179 @@
1
+ #pragma once
2
+
3
+ #if __has_include("jsi/jsi.h")
4
+ #include "jsi/jsi.h"
5
+ namespace Babylon::Plugins::NativeXr
6
+ {
7
+ bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, const std::string nativeXrContextType, uintptr_t& nativeXrContext)
8
+ {
9
+ nativeXrContext = reinterpret_cast<uintptr_t>(nullptr);
10
+ if (!jsiRuntime.global().hasProperty(jsiRuntime, "navigator"))
11
+ {
12
+ return false;
13
+ }
14
+
15
+ auto navigator{ jsiRuntime.global().getProperty(jsiRuntime, "navigator").asObject(jsiRuntime) };
16
+ if (!navigator.hasProperty(jsiRuntime, "xr"))
17
+ {
18
+ return false;
19
+ }
20
+
21
+ auto nativeXr{ navigator.getProperty(jsiRuntime, "xr").asObject(jsiRuntime) };
22
+ if (!nativeXr.hasProperty(jsiRuntime, "nativeXrContext") ||
23
+ !nativeXr.hasProperty(jsiRuntime, "nativeXrContextType") ||
24
+ nativeXr.getProperty(jsiRuntime, "nativeXrContextType").asString(jsiRuntime).utf8(jsiRuntime) != nativeXrContextType)
25
+ {
26
+ return false;
27
+ }
28
+
29
+ nativeXrContext = static_cast<uintptr_t>(nativeXr.getProperty(jsiRuntime, "nativeXrContext").asNumber());
30
+ return true;
31
+ }
32
+ }
33
+ #endif
34
+
35
+ #if __has_include("napi/env.h")
36
+ #include "napi/env.h"
37
+ namespace Babylon::Plugins::NativeXr
38
+ {
39
+ bool TryGetXrContext(Napi::Env env, const std::string nativeXrContextType, uintptr_t& nativeXrContext)
40
+ {
41
+ nativeXrContext = reinterpret_cast<uintptr_t>(nullptr);
42
+ if (!env.Global().Has("navigator"))
43
+ {
44
+ return false;
45
+ }
46
+
47
+ auto navigator{ env.Global().Get("navigator").As<Napi::Object>() };
48
+ if (!navigator.Has("xr"))
49
+ {
50
+ return false;
51
+ }
52
+
53
+ auto nativeXr{ navigator.Get("xr").As<Napi::Object>() };
54
+ if (!nativeXr.Has("nativeXrContext") ||
55
+ !nativeXr.Has("nativeXrContextType") ||
56
+ nativeXr.Get("nativeXrContextType").As<Napi::String>().Utf8Value() != nativeXrContextType)
57
+ {
58
+ return false;
59
+ }
60
+
61
+ nativeXrContext = static_cast<uintptr_t>(nativeXr.Get("nativeXrContext").As<Napi::Number>().DoubleValue());
62
+ return true;
63
+ }
64
+ }
65
+ #endif
66
+
67
+ #if __has_include("IXrContextOpenXR.h")
68
+ #include "IXrContextOpenXR.h"
69
+ #if __has_include("jsi/jsi.h")
70
+ namespace Babylon::Plugins::NativeXr
71
+ {
72
+ bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextOpenXR*& xrContext)
73
+ {
74
+ xrContext = nullptr;
75
+ uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
76
+ if (TryGetXrContext(jsiRuntime, "OpenXR", nativePtr))
77
+ {
78
+ xrContext = reinterpret_cast<IXrContextOpenXR*>(nativePtr);
79
+ return true;
80
+ }
81
+
82
+ return false;
83
+ }
84
+ }
85
+ #endif
86
+ #if __has_include("napi/env.h")
87
+ namespace Babylon::Plugins::NativeXr
88
+ {
89
+ bool TryGetXrContext(Napi::Env env, IXrContextOpenXR*& xrContext)
90
+ {
91
+ xrContext = nullptr;
92
+ uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
93
+ if (TryGetXrContext(env, "OpenXR", nativePtr))
94
+ {
95
+ xrContext = reinterpret_cast<IXrContextOpenXR*>(nativePtr);
96
+ return true;
97
+ }
98
+
99
+ return false;
100
+ }
101
+ }
102
+ #endif
103
+ #endif
104
+
105
+ #if __has_include("IXrContextARCore.h")
106
+ #include "IXrContextARCore.h"
107
+ #if __has_include("jsi/jsi.h")
108
+ namespace Babylon::Plugins::NativeXr
109
+ {
110
+ bool TryGetXrContext(facebook::jsi::Runtime& jsiRuntime, IXrContextARCore*& xrContext)
111
+ {
112
+ xrContext = nullptr;
113
+ uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
114
+ if (TryGetXrContext(jsiRuntime, "ARCore", nativePtr))
115
+ {
116
+ xrContext = reinterpret_cast<IXrContextARCore*>(nativePtr);
117
+ return true;
118
+ }
119
+
120
+ return false;
121
+ }
122
+ }
123
+ #endif
124
+ #if __has_include("napi/env.h")
125
+ namespace Babylon::Plugins::NativeXr
126
+ {
127
+ bool TryGetXrContext(Napi::Env env, IXrContextARCore*& xrContext)
128
+ {
129
+ xrContext = nullptr;
130
+ uintptr_t nativePtr{reinterpret_cast<uintptr_t>(nullptr)};
131
+ if (TryGetXrContext(env, "ARCore", nativePtr))
132
+ {
133
+ xrContext = reinterpret_cast<IXrContextARCore*>(nativePtr);
134
+ return true;
135
+ }
136
+
137
+ return false;
138
+ }
139
+ }
140
+ #endif
141
+ #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