Skip to content
Draft
6 changes: 6 additions & 0 deletions Modules/@babylonjs/react-native/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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


Expand Down
3 changes: 2 additions & 1 deletion Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <ReactCommon/CallInvoker.h>

#import <Foundation/Foundation.h>
#import <QuartzCore/CAMetalLayer.h>

#import <memory>

Expand Down Expand Up @@ -59,7 +60,7 @@ + (void)updateView:(MTKView*)mtkView {
const int width = static_cast<int>(mtkView.bounds.size.width * scale);
const int height = static_cast<int>(mtkView.bounds.size.height * scale);
if (width != 0 && height != 0) {
BabylonNative::UpdateView(mtkView, width, height);
BabylonNative::UpdateView(reinterpret_cast<BabylonNative::WindowTypeUpdate>((__bridge void*)(CAMetalLayer*)mtkView.layer), width, height);
}
}

Expand Down
6 changes: 6 additions & 0 deletions Modules/@babylonjs/react-native/ios/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
5 changes: 5 additions & 0 deletions Modules/@babylonjs/react-native/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 2 additions & 6 deletions Modules/@babylonjs/react-native/shared/BabylonNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Comment thread
CedricGuillemet marked this conversation as resolved.
Expand Down Expand Up @@ -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() })
{
Expand Down
10 changes: 9 additions & 1 deletion Modules/@babylonjs/react-native/shared/BabylonNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

#if defined(__APPLE__)
#include <MetalKit/MTKView.h>
// Forward-declare CA::MetalLayer so BabylonNative.h is usable from pure C++
// translation units. The ObjC header <QuartzCore/CAMetalLayer.h> only defines
// the @interface, not the C++ CA:: namespace class from Metal-cpp.
namespace CA { class MetalLayer; }
#elif defined(ANDROID)
#include <android/native_window.h>
#elif WINAPI_FAMILY == WINAPI_FAMILY_APP
Expand All @@ -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
Expand All @@ -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);

Expand Down
Loading