Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Modules/@babylonjs/react-native/BabylonModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,27 @@ import { NativeEngine } from '@babylonjs/core';

// This global object is part of Babylon Native.
declare const _native: {
graphicsInitializationPromise: Promise<void>;
whenGraphicsReady: () => Promise<void>;
engineInstance: NativeEngine;
}

const NativeBabylonModule: {
initialize(): Promise<boolean>;
whenInitialized(): Promise<boolean>;
reset(): Promise<boolean>;
} = NativeModules.BabylonModule;

export const BabylonModule = {
initialize: async () => {
const initialized = await NativeBabylonModule.initialize();
if (initialized) {
await _native.graphicsInitializationPromise;
await _native.whenGraphicsReady();
}
return initialized;
},

whenInitialized: NativeBabylonModule.whenInitialized,
reset: NativeBabylonModule.reset,

createEngine: () => {
const engine = new NativeEngine();
Expand Down
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/EngineHook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export function useEngine(): Engine | undefined {
if (engine) {
DisposeEngine(engine);
}
BabylonModule.reset();
setEngine(undefined);
};
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ namespace Babylon
auto height = static_cast<size_t>(ANativeWindow_getHeight(windowPtr));
m_graphics->UpdateWindow<void*>(windowPtr);
m_graphics->UpdateSize(width, height);
m_graphics->EnableRendering();
}

void Reset()
{
m_graphics->DisableRendering();
}

void SetPointerButtonState(uint32_t pointerId, uint32_t buttonId, bool isDown, uint32_t x, uint32_t y)
Expand Down Expand Up @@ -166,6 +172,12 @@ extern "C" JNIEXPORT void JNICALL Java_com_babylonreactnative_BabylonNativeInter
native->SetPointerPosition(static_cast<uint32_t>(pointerId), static_cast<uint32_t>(x), static_cast<uint32_t>(y));
}

extern "C" JNIEXPORT void JNICALL Java_com_babylonreactnative_BabylonNativeInterop_reset(JNIEnv* env, jclass obj, jlong instanceRef)
{
auto native = reinterpret_cast<Babylon::Native*>(instanceRef);
native->Reset();
}

extern "C" JNIEXPORT void JNICALL Java_com_babylonreactnative_BabylonNativeInterop_destroy(JNIEnv* env, jclass obj, jlong instanceRef)
{
auto native = reinterpret_cast<Babylon::Native*>(instanceRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public void initialize(Promise promise) {
public void whenInitialized(Promise promise) {
BabylonNativeInterop.whenInitialized(this.getReactApplicationContext()).thenAccept(instanceRef -> promise.resolve(instanceRef != 0));
}

@ReactMethod
public void reset(Promise promise) {
this.getReactApplicationContext().runOnJSQueueThread(() -> {
BabylonNativeInterop.reset(this.getReactApplicationContext());
promise.resolve(null);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ final class BabylonNativeInterop {
private static native void refresh(long instanceRef, Surface surface);
private static native void setPointerButtonState(long instanceRef, int pointerId, int buttonId, boolean isDown, int x, int y);
private static native void setPointerPosition(long instanceRef, int pointerId, int x, int y);
private static native void reset(long instanceRef);
private static native void destroy(long instanceRef);

// Must be called from the Android UI thread
Expand Down Expand Up @@ -137,6 +138,17 @@ static void deinitialize() {
BabylonNativeInterop.destroyOldNativeInstances(null);
}

static void reset(ReactContext reactContext) {
JavaScriptContextHolder jsContext = reactContext.getJavaScriptContextHolder();
CompletableFuture<Long> instanceRefFuture = BabylonNativeInterop.nativeInstances.get(jsContext);
if (instanceRefFuture != null) {
Long instanceRef = instanceRefFuture.getNow(null);
if (instanceRef != null) {
BabylonNativeInterop.reset(instanceRef);
}
}
}

private static CompletableFuture<Long> getOrCreateFuture(ReactContext reactContext) {
JavaScriptContextHolder jsContext = reactContext.getJavaScriptContextHolder();
CompletableFuture<Long> instanceRefFuture = BabylonNativeInterop.nativeInstances.get(jsContext);
Expand Down
12 changes: 12 additions & 0 deletions Modules/@babylonjs/react-native/ios/BabylonModule.mm
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
#import "BabylonNativeInterop.h"

#import <React/RCTBridgeModule.h>
#import <ReactCommon/CallInvoker.h>

#import <Foundation/Foundation.h>

@interface RCTBridge (RCTTurboModule)
- (std::shared_ptr<facebook::react::CallInvoker>)jsCallInvoker;
@end

@interface BabylonModule : NSObject <RCTBridgeModule>
@end

Expand All @@ -21,4 +26,11 @@ @implementation BabylonModule
[BabylonNativeInterop whenInitialized:self.bridge resolve:resolve];
}

RCT_EXPORT_METHOD(reset:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
self.bridge.jsCallInvoker->invokeAsync([resolve]() {
[BabylonNativeInterop reset];
resolve([NSNull null]);
});
}

@end
6 changes: 6 additions & 0 deletions Modules/@babylonjs/react-native/ios/BabylonNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,19 @@ namespace Babylon
{
m_impl->graphics->UpdateWindow<void*>(windowPtr);
m_impl->graphics->UpdateSize(width, height);
m_impl->graphics->EnableRendering();
}

void Native::Resize(size_t width, size_t height)
{
m_impl->graphics->UpdateSize(width, height);
}

void Native::Reset()
{
m_impl->graphics->DisableRendering();
}

void Native::SetPointerButtonState(uint32_t pointerId, uint32_t buttonId, bool isDown, uint32_t x, uint32_t y)
{
if (isDown)
Expand Down
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/ios/BabylonNative.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace Babylon
~Native();
void Refresh(void* windowPtr, size_t width, size_t height);
void Resize(size_t width, size_t height);
void Reset();
void SetPointerButtonState(uint32_t pointerId, uint32_t buttonId, bool isDown, uint32_t x, uint32_t y);
void SetPointerPosition(uint32_t pointerId, uint32_t x, uint32_t y);

Expand Down
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/ios/BabylonNativeInterop.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
+ (void)setView:(RCTBridge*)bridge jsRunLoop:(NSRunLoop*)jsRunLoop mktView:(MTKView*)mtkView;
+ (void)reportTouchEvent:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event;
+ (void)whenInitialized:(RCTBridge*)bridge resolve:(RCTPromiseResolveBlock)resolve;
+ (void)reset;
@end
6 changes: 6 additions & 0 deletions Modules/@babylonjs/react-native/ios/BabylonNativeInterop.mm
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ + (void)whenInitialized:(RCTBridge*)bridge resolve:(RCTPromiseResolveBlock)resol
}
}

+ (void)reset {
if (currentNativeInstance) {
currentNativeInstance->Reset();
}
}

+ (void)setCurrentView:(MTKView*)mtkView {
currentView = mtkView;
activeTouches = [NSMutableArray new];
Expand Down
2 changes: 1 addition & 1 deletion Modules/@babylonjs/react-native/submodules/BabylonNative
Submodule BabylonNative updated 54 files
+13 −7 .github/workflows/nightly.yml
+162 −90 Apps/BabylonScripts/babylon.glTF2FileLoader.js
+353 −164 Apps/BabylonScripts/babylon.gui.js
+5,840 −2,814 Apps/BabylonScripts/babylon.max.js
+135 −87 Apps/BabylonScripts/babylonjs.materials.js
+48 −0 Apps/BabylonScripts/draco_decoder_gltf.js
+1 −1 Apps/CMakeLists.txt
+2 −1 Apps/Playground/Android/app/CMakeLists.txt
+1 −0 Apps/Playground/Android/app/build.gradle
+11 −11 Apps/Playground/Scripts/experience.js
+0 −1 Apps/Playground/macOS/ViewController.mm
+58 −16 Apps/ValidationTests/CMakeLists.txt
+35 −0 Apps/ValidationTests/Scripts/config.json
+11 −2 Apps/ValidationTests/Scripts/validation_native.js
+28 −1 Apps/ValidationTests/Shared/TestUtils.h
+3 −0 Apps/ValidationTests/Win32/App.cpp
+2 −0 Apps/ValidationTests/X11/App.cpp
+39 −0 Apps/ValidationTests/iOS/AppDelegate.swift
+27 −0 Apps/ValidationTests/iOS/Base.lproj/LaunchScreen.storyboard
+28 −0 Apps/ValidationTests/iOS/Base.lproj/Main.storyboard
+47 −0 Apps/ValidationTests/iOS/Info.plist
+15 −0 Apps/ValidationTests/iOS/LibNativeBridge.h
+76 −0 Apps/ValidationTests/iOS/LibNativeBridge.mm
+48 −0 Apps/ValidationTests/iOS/ViewController.swift
+7 −0 Apps/ValidationTests/macOS/AppDelegate.mm
+39 −30 Apps/ValidationTests/macOS/ViewController.mm
+4 −1 Core/AppRuntime/Source/AppRuntimeChakra.cpp
+4 −0 Core/AppRuntime/Source/AppRuntimeJavaScriptCore.cpp
+5 −0 Core/Graphics/Include/Babylon/Graphics.h
+9 −0 Core/Graphics/Source/BgfxCallback.cpp
+2 −0 Core/Graphics/Source/BgfxCallback.h
+95 −35 Core/Graphics/Source/Graphics.cpp
+9 −0 Core/Graphics/Source/GraphicsImpl.h
+1 −0 Dependencies/AndroidExtensions/Include/AndroidExtensions/JavaWrappers.h
+6 −3 Dependencies/AndroidExtensions/Source/JavaWrappers.cpp
+1 −1 Dependencies/bgfx.cmake
+1 −1 Dependencies/ios-cmake
+6 −4 Dependencies/napi/napi-direct/CMakeLists.txt
+1 −1 Dependencies/napi/napi-direct/source/env_javascriptcore.cc
+6 −0 Dependencies/napi/napi-direct/source/js_native_api_chakra.cc
+16 −11 Dependencies/napi/napi-direct/source/js_native_api_chakra.h
+5 −1 Dependencies/napi/napi-direct/source/js_native_api_javascriptcore.cc
+17 −12 Dependencies/napi/napi-direct/source/js_native_api_javascriptcore.h
+0 −0 Dependencies/napi/napi-direct/source/js_native_api_javascriptcore_internals.h
+15 −10 Dependencies/napi/napi-direct/source/js_native_api_v8.h
+20 −8 Dependencies/xr/Include/XR.h
+21 −29 Dependencies/xr/Source/ARCore/XR.cpp
+31 −41 Dependencies/xr/Source/ARKit/XR.mm
+323 −12 Dependencies/xr/Source/OpenXR/XR.cpp
+34 −42 Plugins/NativeEngine/Source/NativeEngine.cpp
+59 −32 Plugins/NativeEngine/Source/NativeEngine.h
+91 −42 Plugins/NativeXr/Source/NativeXr.cpp
+1 −10 README.md
+79 −8 azure-pipelines.yml