diff --git a/Modules/@babylonjs/react-native/README.md b/Modules/@babylonjs/react-native/README.md index 2c4339348..113614d77 100644 --- a/Modules/@babylonjs/react-native/README.md +++ b/Modules/@babylonjs/react-native/README.md @@ -34,6 +34,11 @@ To disable post install CMake generation, set this variable before running `npm export BABYLON_NO_CMAKE_POSTINSTALL=1 ``` +To use the system cmake (e.g. a Homebrew or system install) instead of the cmake bundled in the npm package, set this variable before running `npm install`: +``` +export BABYLON_USE_SYSTEM_CMAKE=1 +``` + ### Plugins selection Plugins can be disabled at build time. They are all enabled by default and disabling is done with environment variables: @@ -56,6 +61,7 @@ Babylon.js minimal version: |BabylonReactNative version | Babylon.js version | BabylonNative commit | | ----------- | ------------------------ | --- | +|2.0.2 | 9.0.0 | 887a044 |2.0.0 | 8.3.0 | 6c25966e8f8c0f3a0c13fdf77064f1bde790391f diff --git a/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm b/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm index 2ba27605a..617b2a667 100644 --- a/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm +++ b/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm @@ -6,6 +6,7 @@ #include #import +#import #import @@ -59,7 +60,7 @@ + (void)updateView:(MTKView*)mtkView { const int width = static_cast(mtkView.bounds.size.width * scale); const int height = static_cast(mtkView.bounds.size.height * scale); if (width != 0 && height != 0) { - BabylonNative::UpdateView(mtkView, width, height); + BabylonNative::UpdateView(reinterpret_cast((__bridge void*)(CAMetalLayer*)mtkView.layer), width, height); } } diff --git a/Modules/@babylonjs/react-native/ios/CMakeLists.txt b/Modules/@babylonjs/react-native/ios/CMakeLists.txt index 9aaafc417..f23cc4068 100644 --- a/Modules/@babylonjs/react-native/ios/CMakeLists.txt +++ b/Modules/@babylonjs/react-native/ios/CMakeLists.txt @@ -19,6 +19,12 @@ set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall") set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -x objective-c++") +# wstring_convert and codecvt_utf8_utf16 are deprecated in C++17; prevent this from +# being treated as a hard error so the build succeeds on Xcode 26+ / Clang 20+. +if(CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_compile_options(-Wno-deprecated-declarations) +endif() + set(BABYLON_NATIVE_PLUGIN_NATIVEXR 1) if(DEFINED ENV{BABYLON_NATIVE_PLUGIN_NATIVEXR}) set(BABYLON_NATIVE_PLUGIN_NATIVEXR $ENV{BABYLON_NATIVE_PLUGIN_NATIVEXR}) diff --git a/Modules/@babylonjs/react-native/postinstall.js b/Modules/@babylonjs/react-native/postinstall.js index 0e3cd7030..a7da65d08 100644 --- a/Modules/@babylonjs/react-native/postinstall.js +++ b/Modules/@babylonjs/react-native/postinstall.js @@ -2,6 +2,11 @@ const os = require("os"); const path = require("path"); function getCmakeExecutable() { + // When BABYLON_USE_SYSTEM_CMAKE=1, skip the npm cmake package and use whatever + // cmake is found on PATH (e.g. a Homebrew or system install). + if (process.env.BABYLON_USE_SYSTEM_CMAKE === '1') { + return 'cmake'; + } try { // cmake-runtime ships the cmake binary; resolve it directly to avoid // relying on npx or PATH. diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp index f81936d25..ddf553e6e 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp @@ -81,13 +81,9 @@ namespace BabylonNative Napi::Detach(m_env); } - void UpdateView(WindowType window, size_t width, size_t height) + void UpdateView(Babylon::Graphics::WindowT window, size_t width, size_t height) { -#if defined(__APPLE__) - m_graphicsConfig.Window = (Babylon::Graphics::WindowT)window.layer; -#else m_graphicsConfig.Window = window; -#endif m_graphicsConfig.Width = width; m_graphicsConfig.Height = height; UpdateGraphicsConfiguration(); @@ -313,7 +309,7 @@ namespace BabylonNative g_nativeModule.reset(); } - void UpdateView(WindowType window, size_t width, size_t height) + void UpdateView(Babylon::Graphics::WindowT window, size_t width, size_t height) { if (auto nativeModule{ g_nativeModule.lock() }) { diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.h b/Modules/@babylonjs/react-native/shared/BabylonNative.h index 3e1539709..1609fdf76 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.h +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.h @@ -4,6 +4,10 @@ #if defined(__APPLE__) #include +// Forward-declare CA::MetalLayer so BabylonNative.h is usable from pure C++ +// translation units. The ObjC header only defines +// the @interface, not the C++ CA:: namespace class from Metal-cpp. +namespace CA { class MetalLayer; } #elif defined(ANDROID) #include #elif WINAPI_FAMILY == WINAPI_FAMILY_APP @@ -13,11 +17,15 @@ namespace BabylonNative { #if defined(__APPLE__) + // this needs to be updated in BabylonNative XR impl to use WindowType and not an opaque type using WindowType = MTKView*; + using WindowTypeUpdate = CA::MetalLayer*; #elif defined(ANDROID) using WindowType = ANativeWindow*; + using WindowTypeUpdate = ANativeWindow*; #elif WINAPI_FAMILY == WINAPI_FAMILY_APP using WindowType = winrt::Windows::UI::Xaml::Controls::SwapChainPanel; + using WindowTypeUpdate = winrt::Windows::UI::Xaml::Controls::SwapChainPanel; #else #error Unsupported platform #endif @@ -27,7 +35,7 @@ namespace BabylonNative void Initialize(facebook::jsi::Runtime& jsiRuntime, Dispatcher jsDispatcher); void Deinitialize(); - void UpdateView(WindowType window, size_t width, size_t height); + void UpdateView(WindowTypeUpdate window, size_t width, size_t height); void UpdateMSAA(uint8_t value); void UpdateAlphaPremultiplied(bool enabled);