• Stars
    star
    350
  • Rank 116,854 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created about 4 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Build React Native applications with the power of Babylon Native

npm version

Babylon React Native

Babylon React Native brings the power and flexibility of Babylon.js into a React Native environment via Babylon Native.

Current Status

Limitations

  1. Android and iOS only - support for Windows is experimental.
  2. Touch input only - mouse, keyboard, and controllers are not yet supported.
  3. Single view only - multiple views are not yet supported (only a single view can be displayed).

What is Supported from Babylon.js

See this from the Babylon Native repo.

Performance

React Native applications targeting JavaScriptCore on iOS or Hermes will not have JIT enabled. This may cause performance issues for JavaScript heavy scenarios.

Other

Babylon React Native relies heavily on newer React Native constructs including JSI to get the performance characteristics required for real time rendering. JSI allows for direct synchronous communication between native code and JavaScript code, but is incompatible with "remote debugging." If you need to debug your JavaScript code that uses Babylon React Native, you should enable Hermes and use "direct debugging" (e.g. chrome://inspect or edge://inspect). See the React Native documentation for more info.

Usage

See the package usage for installation instructions and/or the Playground app's App.tsx for example usage. You can also clone this sample repo to quickly get started.

Contributing

This quick overview will help you get started developing in the Babylon React Native repository. We support development on Windows and MacOS, but assume the use of PowerShell in the instructions below (unless otherwise noted).

If you are interested in making contributions, be sure to also review CONTRIBUTING.md.

Preparing a new Repo

Required Tools: git, Node.js (16.13.0+)

Step 1 for all development environments and targets is to clone the repo. Use a git-enabled terminal to follow the steps below.

git clone https://github.com/BabylonJS/BabylonReactNative

Then, a React Native target must be chosen. For a React-Native 0.64 build:

cd Apps/Playground
npm ci
npm run select 0.64

Selecting the React Native install will also install all NPM packages and its dependencies for the Playground sample/test app.

⚠️ When setting up the Playground app for UWP, the npm run select command must be run with Administrator rights, because of the symbolic links. Not doing so will result in this build error will popup when trying to run the Playground:

 The path cannot be traversed because it contains an untrusted mount point.

This will also automatically do the following to prepare your repo for development:

  • Update git submodules to fetch Babylon Native and its dependencies
  • [MacOS only] Run CMake to generate the iOS XCode project for Babylon React Native
  • [MacOS only] Run pod install to install cocoa pod depdendencies

After merging upstream changes in the future, you will need to either run npm install again, or run individual commands for the above operations (e.g. git submodule update --init --submodule / npm run iosCMake / pod install).

Configuring a Mac Dev Environment

Required Tools: Android Studio (including NDK 21.4.7075529), CMake, Ninja, JDK 13

  • The PATH environment variable must include the path to adb (typically ~/Library/Android/sdk/platform-tools/).
  • The PATH environment variable must include the path to Ninja, or Ninja must be installed via a package manager.
  • The ANDROID_HOME environment variable must be defined (typically ~/Library/Android/sdk).
  • The ANDROID_SDK_ROOT environment variable must be defined (typically ~/Library/Android/sdk).
  • The ANDROID_AVD_HOME environment variable must be defined if you plan to use Android emulators (typically ~/.android/avd).
  • The JAVA_HOME environment variable must be defined to point to the correct version of the JDK (typically /usr/libexec/java_home -v 13).

You can typically configure your environment by editing ~/.zshrc and adding the following:

export PATH=$PATH:~/Library/Android/sdk/platform-tools/
export PATH=$PATH:~/path_to_ninja_binary/ # Only for manual installations of Ninja (not package manager-based installations).
export ANDROID_HOME=~/Library/Android/sdk
export ANDROID_SDK_ROOT=~/Library/Android/sdk
export ANDROID_AVD_HOME=~/.android/avd
export JAVA_HOME=$(/usr/libexec/java_home -v 13)

Configuring a Windows Dev Environment

Required Tools: Android Studio (including NDK 21.4.7075529), CMake, Ninja, Visual Studio 2019

  • The PATH environment variable must include the path to adb (typically %LOCALAPPDATA%/Android/sdk/platform-tools/).
  • The PATH environment variable must include the path to Ninja, or Ninja must be installed via a package manager.
  • The ANDROID_HOME environment variable must be defined (typically %LOCALAPPDATA%/Android/sdk).
  • The JAVA_HOME environment variable must be defined (typically %ProgramFiles%/Android/Android Studio/jre).

Configuring a Linux Dev Environment

Required Tools: Android Studio (including NDK 21.4.7075529)

With Ubuntu, you can install needed packages by this command:

sudo apt-get install adb ninja-build openjdk-14-jdk android-sdk

Update PATH with this commands:

export ANDROID_HOME=$HOME/Android/Sdk
export PATH=$PATH:$ANDROID_HOME/emulator
export PATH=$PATH:$ANDROID_HOME/tools
export PATH=$PATH:$ANDROID_HOME/tools/bin
export PATH=$PATH:$ANDROID_HOME/platform-tools

Troubleshooting

  • If the Metro server is not started with npm run android , you can start it manually by running npm run start in a terminal.
  • Android Studio is the tool of choice for downloading the various versions of NDK.
  • If something goes wrong with the build npm run android --verbose can give some hints.
  • If the emulator is not launched by the build, you can run ~/Android/Sdk/emulator/emulator @name_of_your_image.
  • For other emulator issues, follow the instructions from Babylon Native documentation.
  • Refer to the Babylon Native documentation for additional information that may help troubleshoot issues.

Building and Running the Playground App

On either Mac or Windows, NPM is used to build and run the Playground sample/test app from the command line. Open a command prompt at the root of the BabylonReactNative repo if you don't have one already open.

Android

cd Apps/Playground/Playground
npm run android

After having run the above commands, you can also open Apps/Playground/android in Android Studio and run the app from there.

iOS

iOS can only be built on a Mac.

cd Apps/Playground/Playground
npm run ios

After having run the above commands, you can also open Apps/Playground/ios/Playground.xcworkspace in XCode and run the app from there.

Universal Windows Platform (UWP)

UWP can only be built on a PC. CMake must be manually run to generate project definitions for BabylonNative dependencies.

  1. Run npm ci in Apps\Playground\Playground.
  2. Run npm ci in Package.
  3. Run npx gulp buildUWP in Package. This command will run cmake and build BabylonNative dependencies. It may take a while to complete.
  4. In Apps\Playground\Playground, run npm run windows.

Note: if you experience build issues for Apps\Playground related to autolinking, try running npx react-native autolink-windows in the Apps\Playground\Playground folder. You can also run npm run windows-verbose to view logging.

Testing in the Playground App

When making local changes, the following manual test steps should be performed within the Playground app to prevent regressions. These should be checked on Android and iOS, and ideally in both debug and release, but minimally in release.

  1. Basic rendering - launch the Playground app and make sure the model loaded and is rendering at 60fps.
  2. Animation - make sure the loaded model is animating.
  3. Input handling - swipe across the display and make sure the model rotates around the y-axis.
  4. Display rotation - rotate the device 90 degrees and make sure the view rotates and renders correctly.
  5. View replacement - tap the Toggle EngineView button twice to replace the render target view.
  6. Engine dispose - tap the Toggle EngineScreen button twice to dispose and re-instantiate the Babylon engine.
  7. Suspend/resume - switch to a different app and then back to the Playground and make sure it is still rendering correctly.
  8. Fast refresh (debug only) - save the App.tsx file to trigger a fast refresh.
  9. Dev mode reload (debug only) - in the Metro server console window, press the R key on the keyboard to reload the JS engine and make sure rendering restarts successfully.
  10. XR mode - tap the Start XR button and make sure XR mode is working.
  11. XR display rotation - rotate the device 90 degrees and make sure the view rotates and renders correctly.
  12. XR view replacement - tap the Toggle EngineView button twice to replace the render target view.
  13. XR suspend/resume - switch to a different app and then back to the Playground and make sure it is still rendering correctly.

Building the NPM Package

If you want to test using a local build of the NPM package with your own React Native app, you can do so with a gulp command on a Mac (this requires a Mac as it builds binaries for both iOS and Android).

cd Package
npm install
gulp pack

The NPM package will be built into the Package directory where the gulp command was run. Once the local NPM package has been built, it can be installed into a project using npm.

cd <directory of your React Native app>
npm install <root directory of your BabylonReactNative clone>/Package/Assembled/babylonjs-react-native-0.0.1.tgz

If you wish to test the locally-built NPM packages with the apps in the PackageTest directory, before running npm install be sure to run:

cd Apps\PackageTest\<package test app version>

npm uninstall @babylon/react-native

# If you're also updating the react-native-windows package:
npm uninstall @bablyon/react-native-windows

This will allow the local package dependencies to update without the package-lock.json file worrying about new content without a new version number. You can then run the above command to install the locally-built NPM modules located in Package/Assembled.

Debugging in Context

If you want to consume @babylonjs/react-native as source in your React Native app (for debugging or for iterating on the code when making a contribution), you can install the package source directory as an npm package.

cd <directory of your React Native app>
npm install <root directory of your BabylonReactNative clone>/Modules/@babylonjs/react-native
cd ios
pod install

This will create a symbolic link in your node_modules directory to the @babylonjs/react-native source directory. However, this also requires a custom metro.config.js as the Metro bundler does not support symbolic links by default. See the GitHub issue on this for a solution.

For iOS the XCode project needs to be generated with CMake as described above and added to your xcworkspace.

Supported Versions

React Native Babylon React Native
0.64 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.3
0.65 -> 0.68 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.3
0.69 1.4.0, 1.4.1, 1.4.2, 1.4.3, 1.4.4, 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.3
0.70 1.5.0, 1.5.1, 1.6.0, 1.6.1, 1.6.3
0.71 -> 0.72 1.6.0, 1.6.1, 1.6.3

Here are the package names for Android/iOS and Windows:

React Native Android/iOS Package Windows Package
0.64 @babylonjs/react-native-iosandroid-0-64 @babylonjs/react-native-windows-0-64
0.65 -> 0.68 @babylonjs/react-native-iosandroid-0-65 @babylonjs/react-native-windows-0-65
0.69 @babylonjs/react-native-iosandroid-0-69 @babylonjs/react-native-windows-0-69
0.70 @babylonjs/react-native-iosandroid-0-70 @babylonjs/react-native-windows-0-70
0.71 -> 0.72 @babylonjs/react-native-iosandroid-0-71 @babylonjs/react-native-windows-0-71

Also, @babylonjs/react-native is a needed dependency for all platforms.

Supported Babylon.js Versions

Depending on the Babylon React Native NPM package version, some Babylon.js NPM dependency versions may or may not be compatible. Here is a compatibility list that has been tested:

Babylon React Native Babylon.js (@babylonjs/core, @babylonjs/loaders, ...)
1.4.0 5.27.1
1.4.1 5.32.2, 5.33.0, 5.33.1, 5.33.2, 5.34.0, 5.35.0
1.4.2 5.35.1, 5.36.0, 5.37.0, 5.38.0, 5.39.0, 5.42.0, 5.42.1
1.4.3 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.47.1, 5.48.0, 5.48.1, 5.49.0, 5.49.1, 5.49.2, 5.50.0, 5.50.1, 5.51.0, 5.52.0, 5.53.0, 5.54.0, 5.55.0, 5.56.0, 5.57.0, 5.57.1, 6.0.0, 6.1.0, 6.2.0, 6.3.1, 6.4.0, 6.4.1
1.4.4 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.47.1, 5.48.0, 5.48.1, 5.49.0, 5.49.1, 5.49.2, 5.50.0, 5.50.1, 5.51.0, 5.52.0, 5.53.0, 5.54.0, 5.55.0, 5.56.0, 5.57.0, 5.57.1, 6.0.0, 6.1.0, 6.2.0, 6.3.0, 6.3.1, 6.4.0, 6.4.1
1.5.0 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.47.1, 5.48.0, 5.48.1, 5.49.0, 5.49.1, 5.49.2, 5.50.0, 5.50.1, 5.51.0, 5.52.0, 5.53.0, 5.54.0, 5.55.0, 5.56.0, 5.57.0, 5.57.1, 6.0.0, 6.1.0, 6.2.0, 6.3.0, 6.3.1, 6.4.0, 6.4.1
1.5.1 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.47.1, 5.48.0, 5.48.1, 5.49.0, 5.49.1, 5.49.2, 5.50.0, 5.50.1, 5.51.0, 5.52.0, 5.53.0, 5.54.0, 5.55.0, 5.56.0, 5.57.0, 5.57.1, 6.0.0, 6.1.0, 6.2.0, 6.3.0, 6.3.1, 6.4.0, 6.4.1
1.6.0 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.48.0, 5.48.1, 5.49.1
1.6.1 5.42.2, 5.43.0, 5.43.1, 5.43.2, 5.44.0, 5.45.0, 5.45.1, 5.45.2, 5.46.0, 5.47.0, 5.48.0, 5.48.1, 5.49.1
1.6.3 5.53.1, 5.54.0, 5.55.0, 5.56.0, 5.57.0, 5.57.1, 6.0.0, 6.1.0, 6.2.0, 6.3.0, 6.3.1, 6.4.0, 6.4.1, 6.5.0, 6.5.1, 6.6.0, 6.6.1, 6.7.0, 6.8.1, 6.9.0, 6.11.2, 6.12.0, 6.12.1,6.12.2, 6.12.3, 6.14.0

Security

If you believe you have found a security vulnerability in this repository, please see SECURITY.md.

More Repositories

1

Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
TypeScript
22,116
star
2

Spector.js

Explore and Troubleshoot your WebGL scenes with ease.
TypeScript
1,215
star
3

Editor

Community managed visual editor for Babylon.js
TypeScript
804
star
4

BabylonNative

Build cross-platform native applications with the power of the Babylon.js JavaScript framework
C++
729
star
5

Exporters

Exporters for Babylon.js and gltf file formats
Mathematica
577
star
6

BlenderExporter

Exports From Blender to Babylon.JS in JSON / .babylon format
Python
280
star
7

Website

Main babylon.js website
JavaScript
197
star
8

Extensions

Extensions for Babylon.js
JavaScript
169
star
9

UnityExporter

Home of the community maintained Unity exporter for Babylon.js
159
star
10

Assets

A place for public domain digital assets to use.
JavaScript
142
star
11

SpacePirates

The Space Pirates game is a demo made to celebrate the Babylon.js 5.0 Release.
TypeScript
142
star
12

SummerFestival

Source code for game tutorial written by capucat
TypeScript
127
star
13

BabylonAR

Home of the Babylon.AR project
TypeScript
72
star
14

Documentation

Babylon.js's documentation website
TypeScript
71
star
15

OldDocumentationSite

Babylon.js documentation page
JavaScript
66
star
16

MeshesLibrary

Use this repo as a place to share your scenes and meshes
JavaScript
47
star
17

BabylonReactNativeSample

Java
33
star
18

CYOS

Create Your Own Shader
JavaScript
23
star
19

BabylonPolymorph

C++
22
star
20

SpacePiratesAR

Space Pirates Demo with Babylon React-Native and AR.
TypeScript
19
star
21

npm-package-template

JavaScript
16
star
22

Controls

Set of web controls using babylon.js and the GPU to render their content in a hardware accelerated way
TypeScript
15
star
23

JsRuntimeHost

The JsRuntimeHost is a library that provides cross-platform C++ JavaScript hosting for any JavaScript engines with Node-API support such as Chakra, V8, or JavaScriptCore.
C++
12
star
24

Brand-Toolkit

11
star
25

twgsl

C++
9
star
26

BabylonNativeExamples

A collection of sample code projects using Babylon Native to illustrate various scenarios
C++
8
star
27

UrlLib

UrlLib is a cross-platform C++ library that utilizes platform-specific implementations for URL-related functionality
C++
7
star
28

Demos

A repository of Babylon.js Demos
TypeScript
5
star
29

asset-host-template

5
star
30

havok

The Havok Physics plugin runtime files (wasm and js)
TypeScript
5
star
31

Documentation-search-engine

Website used to store documentation search engine
JavaScript
3
star
32

SpectorJSWebsite

Website for https://github.com/BabylonJS/Spector.js
JavaScript
3
star
33

CMakeExtensions

Helper functions for CMake
CMake
2
star
34

SnippetServerReference

JavaScript
1
star
35

AndroidExtensions

AndroidExtensions is a C++ utility library for Android development
C++
1
star