From 65759fc51c92a4a07ffb72d9f8fb7f73e5ef241d Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:23:49 +0100 Subject: [PATCH 1/8] Use BabylonNative WindowT type --- Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm | 2 +- Modules/@babylonjs/react-native/shared/BabylonNative.cpp | 6 +----- Modules/@babylonjs/react-native/shared/BabylonNative.h | 2 +- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm b/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm index 2ba27605a..043783734 100644 --- a/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm +++ b/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm @@ -59,7 +59,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(mtkView.layer, width, height); } } diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp index f81936d25..8ce3fa606 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(); diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.h b/Modules/@babylonjs/react-native/shared/BabylonNative.h index 3e1539709..671e1bf25 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.h +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.h @@ -27,7 +27,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(Babylon::Graphics::WindowT window, size_t width, size_t height); void UpdateMSAA(uint8_t value); void UpdateAlphaPremultiplied(bool enabled); From 8f064d8fd00531fbf21a1c6d66a70c34fbc7eeb0 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Wed, 18 Mar 2026 17:47:30 +0100 Subject: [PATCH 2/8] missed one def --- Modules/@babylonjs/react-native/shared/BabylonNative.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp index 8ce3fa606..ddf553e6e 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.cpp +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.cpp @@ -309,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() }) { From d32fd42fccc8df0d09b7a64c26c4346c055e6dcd Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 15:31:19 +0200 Subject: [PATCH 3/8] Fix Xcode 26 build: suppress deprecated-declarations for Clang targets wstring_convert is deprecated in C++17 and the BabylonNative cmakeextensions build helper adds -Werror to all Clang targets, turning this deprecation into a hard build error on Xcode 26+ / Clang 20+. Add -Wno-deprecated-declarations via add_compile_options for Clang/ AppleClang builds so the project compiles cleanly while all other -Werror checks remain enforced. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Modules/@babylonjs/react-native/ios/CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) 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}) From b6ad45fce23482b7d6d5bfd65c69c61caf473f83 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 16:27:24 +0200 Subject: [PATCH 4/8] WindowType update --- Modules/@babylonjs/react-native/shared/BabylonNative.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.h b/Modules/@babylonjs/react-native/shared/BabylonNative.h index 671e1bf25..6d03cbdb8 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.h +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.h @@ -13,11 +13,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 +31,7 @@ namespace BabylonNative void Initialize(facebook::jsi::Runtime& jsiRuntime, Dispatcher jsDispatcher); void Deinitialize(); - void UpdateView(Babylon::Graphics::WindowT 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); From 0a4d9b6e9cba236935cc02bf384e039bba1a436f Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 16:32:31 +0200 Subject: [PATCH 5/8] Add BABYLON_USE_SYSTEM_CMAKE env var and update version table - postinstall.js: add BABYLON_USE_SYSTEM_CMAKE=1 env variable that bypasses the npm-bundled cmake-runtime package and uses whatever cmake is found on PATH (Homebrew, system install, etc.) - README: document the new BABYLON_USE_SYSTEM_CMAKE variable in the iOS CMake configuration section - README: add BabylonReactNative 2.0.2 entry to the Platform Native Packages version table (requires Babylon.js 9.0.0, BabylonNative 887a044) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Modules/@babylonjs/react-native/README.md | 6 ++++++ Modules/@babylonjs/react-native/postinstall.js | 5 +++++ 2 files changed, 11 insertions(+) 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/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. From 8721561807eedeb27572b4a7e1896cd7e244eef2 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 16:48:16 +0200 Subject: [PATCH 6/8] Fix missing CA::MetalLayer declaration in BabylonNative.h Include QuartzCore/CAMetalLayer.h explicitly so that CA::MetalLayer is declared when BabylonNative.h is compiled. MTKView.h alone does not guarantee the CA namespace is available in all build contexts (e.g. the CI runner with Xcode 26). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Modules/@babylonjs/react-native/shared/BabylonNative.h | 1 + 1 file changed, 1 insertion(+) diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.h b/Modules/@babylonjs/react-native/shared/BabylonNative.h index 6d03cbdb8..888811db9 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.h +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.h @@ -4,6 +4,7 @@ #if defined(__APPLE__) #include +#include #elif defined(ANDROID) #include #elif WINAPI_FAMILY == WINAPI_FAMILY_APP From 267fb63774c2a601ad129e6e27c7f8145218f60b Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 17:01:26 +0200 Subject: [PATCH 7/8] Fix CA::MetalLayer undeclared in C++ TUs via forward declaration only defines an Objective-C @interface, not the C++ CA::MetalLayer class from Metal-cpp. BabylonNative.cpp is compiled as a pure C++ translation unit, so including that header does not make the CA:: namespace visible. Replace the include with a C++ forward declaration: namespace CA { class MetalLayer; } This is sufficient for the pointer type alias in the header. The full definition is provided by the Metal-cpp headers that BabylonNative itself brings in when the implementation files are compiled. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Modules/@babylonjs/react-native/shared/BabylonNative.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Modules/@babylonjs/react-native/shared/BabylonNative.h b/Modules/@babylonjs/react-native/shared/BabylonNative.h index 888811db9..1609fdf76 100644 --- a/Modules/@babylonjs/react-native/shared/BabylonNative.h +++ b/Modules/@babylonjs/react-native/shared/BabylonNative.h @@ -4,7 +4,10 @@ #if defined(__APPLE__) #include -#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 From b2e1538a568c1f5c26335414914e7831ac364613 Mon Sep 17 00:00:00 2001 From: Cedric Guillemet <1312968+CedricGuillemet@users.noreply.github.com> Date: Tue, 14 Apr 2026 17:38:52 +0200 Subject: [PATCH 8/8] Fix ObjC CALayer* to C++ CA::MetalLayer* cast in BabylonNativeInterop.mm mtkView.layer returns CALayer* (ObjC), but UpdateView expects CA::MetalLayer* (C++ Metal-cpp type). These are ABI-compatible since MTKView always uses CAMetalLayer as its backing layer, but in ObjC++ we must bridge explicitly: 1. Cast CALayer* -> CAMetalLayer* (safe ObjC downcast) 2. __bridge void* (ARC-safe ObjC -> C pointer) 3. reinterpret_cast (void* -> CA::MetalLayer*) Also import to declare CAMetalLayer in the ObjC++ TU. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm b/Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm index 043783734..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.layer, width, height); + BabylonNative::UpdateView(reinterpret_cast((__bridge void*)(CAMetalLayer*)mtkView.layer), width, height); } }