Skip to content

Commit fd7f7e6

Browse files
authored
Integrate the new Babylon Native Graphics object (#86)
The main change here is to use the new Graphics object from Babylon Native: - Update Babylon Native to the latest, and Babylon.js to 4.2.0-beta.6. - Bump up the min version of @babylonjs/core to 4.2.0-beta.6 (it has changes tied to changes made to Babylon Native). - Add dependencies on the Graphics lib (CMakeLists.txt and podspec). - Update gulp package build script to expect to include libGraphics.a (iOS). Also included a couple other minor changes: - Explicitly specify the architecture when building the simulator libs for iOS (XCode 12 seems to default to arm64 instead of x86_64). - Add a note to the readme about requiring a custom metro.config.js if you want to install a local version of the package.
1 parent e588a71 commit fd7f7e6

File tree

15 files changed

+43
-30
lines changed

15 files changed

+43
-30
lines changed

Apps/PackageTest/package-lock.json

+4-4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/PackageTest/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
1111
},
1212
"dependencies": {
13-
"@babylonjs/core": "^4.2.0-beta.2",
13+
"@babylonjs/core": "^4.2.0-beta.6",
1414
"@babylonjs/react-native": "file:../../Package/Assembled/babylonjs-react-native-0.0.1.tgz",
1515
"react": "16.13.1",
1616
"react-native": "0.63.1",

Apps/Playground/ios/Podfile.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ SPEC CHECKSUMS:
466466
React-jsi: b32a31da32e030f30bbf9a8d3a9c8325df9e793f
467467
React-jsiexecutor: 7ab9cdcdd18d57652fb041f8a147fe9658d4e00a
468468
React-jsinspector: 2e28bb487e42dda6c94dbfa0c648d1343767a0fb
469-
react-native-babylon: 004630b2838450727c093bfcc30e05d5b08206c1
469+
react-native-babylon: 704a0f409074182d47b917877c3ef70512a18ac5
470470
react-native-slider: b34d943dc60deb96d952ba6b6b249aa8091e86da
471471
React-RCTActionSheet: 1702a1a85e550b5c36e2e03cb2bd3adea053de95
472472
React-RCTAnimation: ddda576010a878865a4eab83a78acd92176ef6a1

Apps/Playground/package-lock.json

+11-11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Apps/Playground/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"lint": "eslint . --ext .js,.jsx,.ts,.tsx"
1111
},
1212
"dependencies": {
13-
"@babylonjs/core": "^4.2.0-beta.2",
14-
"@babylonjs/loaders": "^4.2.0-beta.2",
13+
"@babylonjs/core": "^4.2.0-beta.6",
14+
"@babylonjs/loaders": "^4.2.0-beta.6",
1515
"@babylonjs/react-native": "file:../../Modules/@babylonjs/react-native",
1616
"@react-native-community/slider": "^2.0.9",
1717
"logkitty": "^0.7.1",

Modules/@babylonjs/react-native/android/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ target_link_libraries(BabylonNative
4646
arcana
4747
jsi
4848
AndroidExtensions
49+
Graphics
4950
JsRuntime
5051
NativeWindow
5152
NativeEngine

Modules/@babylonjs/react-native/android/src/main/cpp/BabylonNativeInterop.cpp

+7-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include <jni.h>
22

3+
#include <Babylon/Graphics.h>
34
#include <Babylon/JsRuntime.h>
45
#include <Babylon/Plugins/NativeWindow.h>
56
#include <Babylon/Plugins/NativeEngine.h>
@@ -52,7 +53,9 @@ namespace Babylon
5253
auto width = static_cast<size_t>(ANativeWindow_getWidth(windowPtr));
5354
auto height = static_cast<size_t>(ANativeWindow_getHeight(windowPtr));
5455

55-
Plugins::NativeEngine::InitializeGraphics(windowPtr, width, height);
56+
m_graphics = Graphics::InitializeFromWindow<void*>(windowPtr, width, height);
57+
m_graphics->AddToJavaScript(m_env);
58+
5659
Plugins::NativeEngine::Initialize(m_env);
5760
Plugins::NativeWindow::Initialize(m_env, windowPtr, width, height);
5861
Plugins::NativeXr::Initialize(m_env);
@@ -62,12 +65,11 @@ namespace Babylon
6265
m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(m_env);
6366

6467
// TODO: This shouldn't be necessary, but for some reason results in a significant increase in frame rate. Need to figure this out.
65-
Plugins::NativeEngine::Reinitialize(m_env, windowPtr, width, height);
68+
m_graphics->ReinitializeFromWindow<void*>(windowPtr, width, height);
6669
}
6770

6871
~Native()
6972
{
70-
Plugins::NativeEngine::DeinitializeGraphics();
7173
// TODO: Figure out why this causes the app to crash
7274
//Napi::Detach(m_env);
7375
}
@@ -76,7 +78,7 @@ namespace Babylon
7678
{
7779
auto width = static_cast<size_t>(ANativeWindow_getWidth(windowPtr));
7880
auto height = static_cast<size_t>(ANativeWindow_getHeight(windowPtr));
79-
Plugins::NativeEngine::Reinitialize(m_env, windowPtr, width, height);
81+
m_graphics->ReinitializeFromWindow<void*>(windowPtr, width, height);
8082
}
8183

8284
void SetPointerButtonState(uint32_t pointerId, uint32_t buttonId, bool isDown, uint32_t x, uint32_t y)
@@ -99,6 +101,7 @@ namespace Babylon
99101
private:
100102
using looper_scheduler_t = arcana::looper_scheduler<sizeof(std::weak_ptr<Napi::Env>) + sizeof(std::function<void(Napi::Env)>)>;
101103

104+
std::unique_ptr<Graphics> m_graphics{};
102105
Napi::Env m_env;
103106
JsRuntime* m_runtime;
104107
Plugins::NativeInput* m_nativeInput;

Modules/@babylonjs/react-native/ios/BabylonNative.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "BabylonNative.h"
22

3+
#include <Babylon/Graphics.h>
34
#include <Babylon/JsRuntime.h>
45
#include <Babylon/Plugins/NativeWindow.h>
56
#include <Babylon/Plugins/NativeEngine.h>
@@ -29,6 +30,7 @@ namespace Babylon
2930
{
3031
}
3132

33+
std::unique_ptr<Graphics> m_graphics{};
3234
Napi::Env env;
3335
JsRuntime* runtime{};
3436
Plugins::NativeInput* nativeInput{};
@@ -38,7 +40,7 @@ namespace Babylon
3840
: m_impl{ std::make_unique<Native::Impl>(jsiRuntime) }
3941
{
4042
dispatch_sync(dispatch_get_main_queue(), ^{
41-
Plugins::NativeEngine::InitializeGraphics(windowPtr, width, height);
43+
m_impl->m_graphics = Graphics::InitializeFromWindow<void*>(windowPtr, width, height);
4244
});
4345

4446
auto run_loop_scheduler = std::make_shared<arcana::run_loop_scheduler>(arcana::run_loop_scheduler::get_for_current_thread());
@@ -52,6 +54,8 @@ namespace Babylon
5254
}};
5355

5456
m_impl->runtime = &JsRuntime::CreateForJavaScript(m_impl->env, std::move(dispatchFunction));
57+
58+
m_impl->m_graphics->AddToJavaScript(m_impl->env);
5559

5660
Polyfills::Window::Initialize(m_impl->env);
5761

@@ -64,12 +68,11 @@ namespace Babylon
6468

6569
Native::~Native()
6670
{
67-
Plugins::NativeEngine::DeinitializeGraphics();
6871
}
6972

7073
void Native::Refresh(void* windowPtr, size_t width, size_t height)
7174
{
72-
Plugins::NativeEngine::Reinitialize(m_impl->env, windowPtr, width, height);
75+
m_impl->m_graphics->ReinitializeFromWindow<void*>(windowPtr, width, height);
7376
}
7477

7578
void Native::Resize(size_t width, size_t height)

Modules/@babylonjs/react-native/ios/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ target_include_directories(BabylonNative PUBLIC ${CMAKE_CURRENT_LIST_DIR})
3232
target_link_libraries(BabylonNative
3333
z
3434
arcana
35+
Graphics
3536
jsi
3637
JsRuntime
3738
NativeWindow

Modules/@babylonjs/react-native/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"base-64": "^0.1.0"
2828
},
2929
"peerDependencies": {
30-
"@babylonjs/core": "^4.2.0-alpha.33",
30+
"@babylonjs/core": "^4.2.0-beta.6",
3131
"react": "^16.13.1",
3232
"react-native": "^0.63.1",
3333
"react-native-permissions": "^2.1.4"

Modules/@babylonjs/react-native/react-native-babylon.podspec

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Pod::Spec.new do |s|
2525
'bx',
2626
'GenericCodeGen',
2727
'glslang',
28+
'Graphics',
2829
'jsRuntime',
2930
'OGLCompiler',
3031
'OSDependent',
Submodule BabylonNative updated 62 files

Package/gulpfile.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const buildIphoneOS = async () => {
3131
};
3232

3333
const buildIphoneSimulator = async () => {
34-
exec('xcodebuild -sdk iphonesimulator -configuration Release -project ReactNativeBabylon.xcodeproj -scheme BabylonNative build CODE_SIGNING_ALLOWED=NO', 'iOS/Build');
34+
exec('xcodebuild -sdk iphonesimulator -arch x86_64 -configuration Release -project ReactNativeBabylon.xcodeproj -scheme BabylonNative build CODE_SIGNING_ALLOWED=NO', 'iOS/Build');
3535
};
3636

3737
const buildIOS = gulp.series(makeXCodeProj, buildIphoneOS, buildIphoneSimulator);
@@ -100,6 +100,7 @@ Assembled/ios/libs/libNativeXr.a
100100
Assembled/ios/libs/libspirv-cross-glsl.a
101101
Assembled/ios/libs/libNativeInput.a
102102
Assembled/ios/libs/libJsRuntime.a
103+
Assembled/ios/libs/libGraphics.a
103104
Assembled/ios/libs/libOSDependent.a
104105
Assembled/ios/libs/libastc-codec.a
105106
Assembled/ios/libs/libGenericCodeGen.a

Package/iOS/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(PACKAGED_LIBS
1010
bx
1111
GenericCodeGen
1212
glslang
13+
Graphics
1314
JsRuntime
1415
OGLCompiler
1516
OSDependent

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ cd ios
144144
pod install
145145
```
146146

147-
This will create a symbolic link in your `node_modules` directory to the `@babylonjs/react-native` source directory. For iOS the XCode project needs to be generated with `CMake` as described [above](#ios) and added to your `xcworkspace`.
147+
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](https://github.com/react-native-community/cli/issues/1238#issue-673055870) on this for a solution.
148+
149+
For iOS the XCode project needs to be generated with `CMake` as described [above](#ios) and added to your `xcworkspace`.
148150

149151
## Security
150152

0 commit comments

Comments
 (0)