@babylonjs/react-native 0.4.0-alpha.4 → 0.4.0-alpha.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BabylonModule.d.ts +2 -0
- package/BabylonModule.js +21 -0
- package/BabylonModule.js.map +1 -0
- package/EngineHook.d.ts +3 -0
- package/EngineHook.js +179 -0
- package/EngineHook.js.map +1 -0
- package/EngineView.d.ts +12 -0
- package/EngineView.js +117 -0
- package/EngineView.js.map +1 -0
- package/FontFace.d.ts +12 -0
- package/FontFace.js +35 -0
- package/FontFace.js.map +1 -0
- package/NativeCapture.d.ts +14 -0
- package/NativeCapture.js +14 -0
- package/NativeCapture.js.map +1 -0
- package/README.md +2 -6
- package/ReactNativeEngine.d.ts +7 -0
- package/ReactNativeEngine.js +33 -0
- package/ReactNativeEngine.js.map +1 -0
- package/VersionValidation.d.ts +1 -0
- package/VersionValidation.js +13 -0
- package/VersionValidation.js.map +1 -0
- package/android/build.gradle +13 -1
- package/android/include/IXrContextARCore.h +10 -0
- package/android/src/main/java/com/babylonreactnative/BabylonModule.java +7 -20
- package/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java +89 -140
- package/android/src/main/java/com/babylonreactnative/EngineView.java +60 -11
- package/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libturbomodulejsijni.so +0 -0
- package/android/src/main/jniLibs/x86/libBabylonNative.so +0 -0
- package/android/src/main/jniLibs/x86/libturbomodulejsijni.so +0 -0
- package/index.d.ts +4 -0
- package/index.js +5 -0
- package/index.js.map +1 -0
- package/ios/BabylonModule.mm +7 -8
- package/ios/BabylonNativeInterop.h +7 -4
- package/ios/BabylonNativeInterop.mm +84 -124
- package/ios/EngineViewManager.mm +34 -19
- package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +9810 -8605
- package/ios/include/IXrContextARKit.h +10 -0
- package/ios/libs/libBabylonNative.a +0 -0
- package/ios/libs/libCanvas.a +0 -0
- package/ios/libs/libGenericCodeGen.a +0 -0
- package/ios/libs/libGraphics.a +0 -0
- package/ios/libs/libJsRuntime.a +0 -0
- package/ios/libs/libMachineIndependent.a +0 -0
- package/ios/libs/libNativeCapture.a +0 -0
- package/ios/libs/libNativeEngine.a +0 -0
- package/ios/libs/libNativeInput.a +0 -0
- package/ios/libs/libNativeOptimizations.a +0 -0
- package/ios/libs/libNativeTracing.a +0 -0
- package/ios/libs/libNativeXr.a +0 -0
- package/ios/libs/libOGLCompiler.a +0 -0
- package/ios/libs/libOSDependent.a +0 -0
- package/ios/libs/libSPIRV.a +0 -0
- package/ios/libs/libUrlLib.a +0 -0
- package/ios/libs/libWindow.a +0 -0
- package/ios/libs/libXMLHttpRequest.a +0 -0
- package/ios/libs/libastc-codec.a +0 -0
- package/ios/libs/libastc.a +0 -0
- package/ios/libs/libbgfx.a +0 -0
- package/ios/libs/libbimg.a +0 -0
- package/ios/libs/libbx.a +0 -0
- package/ios/libs/libglslang.a +0 -0
- package/ios/libs/libnapi.a +0 -0
- package/ios/libs/libspirv-cross-core.a +0 -0
- package/ios/libs/libspirv-cross-glsl.a +0 -0
- package/ios/libs/libspirv-cross-hlsl.a +0 -0
- package/ios/libs/libspirv-cross-msl.a +0 -0
- package/ios/libs/libxr.a +0 -0
- package/package.json +54 -42
- package/shared/BabylonNative.h +24 -0
- package/shared/XrAnchorHelper.h +229 -0
- package/shared/XrContextHelper.h +179 -0
- package/BabylonModule.ts +0 -33
- package/EngineHelpers.ts +0 -14
- package/EngineHook.ts +0 -97
- package/EngineView.tsx +0 -168
- package/index.ts +0 -2
- package/ios/BabylonNative.h +0 -24
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
#import "BabylonNativeInterop.h"
|
|
2
|
-
#import "BabylonNative.h"
|
|
2
|
+
#import "../shared/BabylonNative.h"
|
|
3
3
|
|
|
4
4
|
#import <React/RCTBridge+Private.h>
|
|
5
5
|
#import <jsi/jsi.h>
|
|
6
|
+
#include <ReactCommon/CallInvoker.h>
|
|
6
7
|
|
|
7
8
|
#import <Foundation/Foundation.h>
|
|
8
9
|
|
|
9
|
-
#import <functional>
|
|
10
10
|
#import <memory>
|
|
11
|
-
#import <vector>
|
|
12
|
-
#import <unordered_map>
|
|
13
|
-
#import <mutex>
|
|
14
11
|
|
|
15
12
|
using namespace facebook;
|
|
16
13
|
|
|
@@ -27,144 +24,107 @@ namespace {
|
|
|
27
24
|
|
|
28
25
|
@implementation BabylonNativeInterop
|
|
29
26
|
|
|
30
|
-
static
|
|
31
|
-
static MTKView* currentView;
|
|
32
|
-
static std::unique_ptr<Babylon::Native> currentNativeInstance;
|
|
33
|
-
static std::unordered_map<void*, std::vector<RCTPromiseResolveBlock>> initializationPromises;
|
|
34
|
-
static std::mutex mapMutex;
|
|
35
|
-
static NSMutableArray* activeTouches;
|
|
27
|
+
static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
36
28
|
|
|
37
|
-
+ (void)
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
// For now, be sure to disable Metal API Validation under Product->Scheme->Edit Scheme.
|
|
58
|
-
currentNativeInstance->Resize(width, height);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}];
|
|
62
|
-
}
|
|
29
|
+
+ (void)initialize:(RCTBridge*)bridge {
|
|
30
|
+
auto jsCallInvoker{ bridge.jsCallInvoker };
|
|
31
|
+
auto jsDispatcher{ [jsCallInvoker{ std::move(jsCallInvoker) }](std::function<void()> func)
|
|
32
|
+
{
|
|
33
|
+
jsCallInvoker->invokeAsync([func{ std::move(func) }]
|
|
34
|
+
{
|
|
35
|
+
func();
|
|
36
|
+
});
|
|
37
|
+
} };
|
|
38
|
+
|
|
39
|
+
Babylon::Initialize(*GetJSIRuntime(bridge), std::move(jsDispatcher));
|
|
40
|
+
|
|
41
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
42
|
+
name:RCTBridgeWillInvalidateModulesNotification
|
|
43
|
+
object:bridge.parentBridge];
|
|
44
|
+
|
|
45
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
46
|
+
selector:@selector(onBridgeWillInvalidate:)
|
|
47
|
+
name:RCTBridgeWillInvalidateModulesNotification
|
|
48
|
+
object:bridge.parentBridge];
|
|
63
49
|
}
|
|
64
50
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const CGFloat scale = UIScreen.mainScreen.scale;
|
|
70
|
-
const CGPoint pointerPosition = [touch locationInView:currentView];
|
|
71
|
-
const uint32_t x = static_cast<uint32_t>(pointerPosition.x * scale);
|
|
72
|
-
const uint32_t y = static_cast<uint32_t>(pointerPosition.y * scale);
|
|
73
|
-
|
|
74
|
-
switch (touch.phase) {
|
|
75
|
-
case UITouchPhaseBegan: {
|
|
76
|
-
NSUInteger pointerId = [activeTouches indexOfObject:[NSNull null]];
|
|
77
|
-
if (pointerId == NSNotFound) {
|
|
78
|
-
pointerId = [activeTouches count];
|
|
79
|
-
[activeTouches addObject:touch];
|
|
80
|
-
} else {
|
|
81
|
-
[activeTouches replaceObjectAtIndex:pointerId withObject:touch];
|
|
82
|
-
}
|
|
83
|
-
currentNativeInstance->SetPointerButtonState(static_cast<uint32_t>(pointerId), 0, true, x, y);
|
|
84
|
-
break;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
case UITouchPhaseMoved: {
|
|
88
|
-
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
89
|
-
currentNativeInstance->SetPointerPosition(static_cast<uint32_t>(pointerId), x, y);
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
case UITouchPhaseEnded:
|
|
94
|
-
case UITouchPhaseCancelled: {
|
|
95
|
-
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
96
|
-
[activeTouches replaceObjectAtIndex:pointerId withObject:[NSNull null]];
|
|
97
|
-
currentNativeInstance->SetPointerButtonState(static_cast<uint32_t>(pointerId), 0, false, x, y);
|
|
98
|
-
break;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
default:
|
|
102
|
-
break;
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
51
|
+
// NOTE: This happens during dev mode reload, when the JS engine is being shutdown and restarted.
|
|
52
|
+
+ (void)onBridgeWillInvalidate:(NSNotification*)notification
|
|
53
|
+
{
|
|
54
|
+
Babylon::Deinitialize();
|
|
107
55
|
}
|
|
108
56
|
|
|
109
|
-
+ (void)
|
|
110
|
-
const
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
57
|
+
+ (void)updateView:(MTKView*)mtkView {
|
|
58
|
+
const CGFloat scale = mtkView.contentScaleFactor;
|
|
59
|
+
const int width = static_cast<int>(mtkView.bounds.size.width * scale);
|
|
60
|
+
const int height = static_cast<int>(mtkView.bounds.size.height * scale);
|
|
61
|
+
if (width != 0 && height != 0) {
|
|
62
|
+
Babylon::UpdateView((__bridge void*)mtkView, width, height);
|
|
115
63
|
}
|
|
116
64
|
}
|
|
117
65
|
|
|
118
|
-
+ (void)
|
|
119
|
-
|
|
120
|
-
currentNativeInstance->Reset();
|
|
121
|
-
}
|
|
66
|
+
+ (void)renderView {
|
|
67
|
+
Babylon::RenderView();
|
|
122
68
|
}
|
|
123
69
|
|
|
124
|
-
+ (void)
|
|
125
|
-
|
|
126
|
-
activeTouches = [NSMutableArray new];
|
|
70
|
+
+ (void)resetView {
|
|
71
|
+
Babylon::ResetView();
|
|
127
72
|
}
|
|
128
73
|
|
|
129
|
-
+ (void)
|
|
130
|
-
|
|
74
|
+
+ (void)updateXRView:(MTKView*)mtkView {
|
|
75
|
+
Babylon::UpdateXRView((__bridge void*)mtkView);
|
|
76
|
+
}
|
|
131
77
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
if (bridge != currentBridge) {
|
|
136
|
-
if (currentBridge == nil || currentBridge.parentBridge != bridge.parentBridge) {
|
|
137
|
-
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
138
|
-
selector:@selector(onBridgeWillInvalidate:)
|
|
139
|
-
name:RCTBridgeWillInvalidateModulesNotification
|
|
140
|
-
object:bridge.parentBridge];
|
|
141
|
-
}
|
|
78
|
+
+ (bool)isXRActive {
|
|
79
|
+
return Babylon::IsXRActive();
|
|
80
|
+
}
|
|
142
81
|
|
|
143
|
-
|
|
144
|
-
|
|
82
|
+
+ (void)reportTouchEvent:(MTKView*)mtkView touches:(NSSet<UITouch*>*)touches event:(UIEvent*)event {
|
|
83
|
+
for (UITouch* touch in touches) {
|
|
84
|
+
if (touch.view == mtkView) {
|
|
85
|
+
const CGFloat scale = mtkView.contentScaleFactor;
|
|
86
|
+
const CGPoint pointerPosition = [touch locationInView:mtkView];
|
|
87
|
+
const uint32_t x = static_cast<uint32_t>(pointerPosition.x * scale);
|
|
88
|
+
const uint32_t y = static_cast<uint32_t>(pointerPosition.y * scale);
|
|
89
|
+
|
|
90
|
+
switch (touch.phase) {
|
|
91
|
+
case UITouchPhaseBegan: {
|
|
92
|
+
// The activeTouches array only grows, it does not shrink (to keep indices constant since they are used as pointer ids),
|
|
93
|
+
// so look for an unused (null) array element and reuse it if found. Otherwise, add a new entry to the array.
|
|
94
|
+
NSUInteger pointerId = [activeTouches indexOfObject:[NSNull null]];
|
|
95
|
+
if (pointerId != NSNotFound) {
|
|
96
|
+
[activeTouches replaceObjectAtIndex:pointerId withObject:touch];
|
|
97
|
+
} else {
|
|
98
|
+
pointerId = [activeTouches count];
|
|
99
|
+
[activeTouches addObject:touch];
|
|
100
|
+
}
|
|
101
|
+
Babylon::SetTouchButtonState(static_cast<uint32_t>(pointerId), true, x, y);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
145
104
|
|
|
146
|
-
|
|
105
|
+
case UITouchPhaseMoved: {
|
|
106
|
+
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
107
|
+
if (pointerId != NSNotFound) {
|
|
108
|
+
Babylon::SetTouchPosition(static_cast<uint32_t>(pointerId), x, y);
|
|
109
|
+
}
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
147
112
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
113
|
+
case UITouchPhaseEnded:
|
|
114
|
+
case UITouchPhaseCancelled: {
|
|
115
|
+
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
116
|
+
if (pointerId != NSNotFound) {
|
|
117
|
+
[activeTouches replaceObjectAtIndex:pointerId withObject:[NSNull null]];
|
|
118
|
+
Babylon::SetTouchButtonState(static_cast<uint32_t>(pointerId), false, x, y);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
153
122
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
resolve([NSNumber numberWithUnsignedLong:reinterpret_cast<uintptr_t>(currentNativeInstance.get())]);
|
|
123
|
+
default:
|
|
124
|
+
break;
|
|
125
|
+
}
|
|
158
126
|
}
|
|
159
|
-
|
|
160
|
-
initializationPromises.erase(initializationPromisesIterator);
|
|
161
127
|
}
|
|
162
128
|
}
|
|
163
129
|
|
|
164
|
-
// NOTE: This happens during dev mode reload, when the JS engine is being shutdown and restarted.
|
|
165
|
-
+ (void)onBridgeWillInvalidate:(NSNotification*)notification
|
|
166
|
-
{
|
|
167
|
-
currentNativeInstance.reset();
|
|
168
|
-
}
|
|
169
|
-
|
|
170
130
|
@end
|
package/ios/EngineViewManager.mm
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
#import <React/RCTViewManager.h>
|
|
4
4
|
#import <React/RCTUIManager.h>
|
|
5
|
+
#import <ReactCommon/CallInvoker.h>
|
|
5
6
|
|
|
6
7
|
#import <Foundation/Foundation.h>
|
|
7
8
|
#import <UIKit/UIKit.h>
|
|
@@ -14,14 +15,13 @@
|
|
|
14
15
|
@end
|
|
15
16
|
|
|
16
17
|
@implementation EngineView {
|
|
17
|
-
RCTBridge* bridge;
|
|
18
|
-
|
|
18
|
+
const RCTBridge* bridge;
|
|
19
|
+
MTKView* xrView;
|
|
19
20
|
}
|
|
20
21
|
|
|
21
|
-
- (instancetype)init:(RCTBridge*)_bridge
|
|
22
|
+
- (instancetype)init:(RCTBridge*)_bridge {
|
|
22
23
|
if (self = [super initWithFrame:CGRectZero device:MTLCreateSystemDefaultDevice()]) {
|
|
23
24
|
bridge = _bridge;
|
|
24
|
-
runLoop = _runLoop;
|
|
25
25
|
|
|
26
26
|
super.translatesAutoresizingMaskIntoConstraints = false;
|
|
27
27
|
super.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
|
|
@@ -32,23 +32,45 @@
|
|
|
32
32
|
|
|
33
33
|
- (void)setBounds:(CGRect)bounds {
|
|
34
34
|
[super setBounds:bounds];
|
|
35
|
-
[BabylonNativeInterop
|
|
35
|
+
[BabylonNativeInterop updateView:self];
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
- (void)touchesBegan:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
|
|
39
|
-
[BabylonNativeInterop reportTouchEvent:touches
|
|
39
|
+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
- (void)touchesMoved:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
|
|
43
|
-
[BabylonNativeInterop reportTouchEvent:touches
|
|
43
|
+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
- (void)touchesEnded:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
|
|
47
|
-
[BabylonNativeInterop reportTouchEvent:touches
|
|
47
|
+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
- (void)touchesCancelled:(NSSet<UITouch*>*)touches withEvent:(UIEvent*)event {
|
|
51
|
-
[BabylonNativeInterop reportTouchEvent:touches
|
|
51
|
+
[BabylonNativeInterop reportTouchEvent:self touches:touches event:event];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
- (void)drawRect:(CGRect)rect {
|
|
55
|
+
if ([BabylonNativeInterop isXRActive]) {
|
|
56
|
+
if (!xrView) {
|
|
57
|
+
xrView = [[MTKView alloc] initWithFrame:self.bounds device:self.device];
|
|
58
|
+
xrView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
|
|
59
|
+
xrView.userInteractionEnabled = false;
|
|
60
|
+
[self addSubview:xrView];
|
|
61
|
+
[BabylonNativeInterop updateXRView:xrView];
|
|
62
|
+
}
|
|
63
|
+
} else if (xrView) {
|
|
64
|
+
[BabylonNativeInterop updateXRView:nil];
|
|
65
|
+
[xrView removeFromSuperview];
|
|
66
|
+
xrView = nil;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[BabylonNativeInterop renderView];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
-(void)dealloc {
|
|
73
|
+
[BabylonNativeInterop updateXRView:nil];
|
|
52
74
|
}
|
|
53
75
|
|
|
54
76
|
- (void)takeSnapshot {
|
|
@@ -63,7 +85,7 @@
|
|
|
63
85
|
// Grab the image from the graphics context, and convert into a base64 encoded JPG.
|
|
64
86
|
UIImage* capturedImage = UIGraphicsGetImageFromCurrentImageContext();
|
|
65
87
|
UIGraphicsEndImageContext();
|
|
66
|
-
NSData* jpgData = UIImageJPEGRepresentation(capturedImage,
|
|
88
|
+
NSData* jpgData = UIImageJPEGRepresentation(capturedImage, .8f);
|
|
67
89
|
NSString* encodedData = [jpgData base64EncodedStringWithOptions:0];
|
|
68
90
|
|
|
69
91
|
// Fire the onSnapshotDataReturned event if hooked up.
|
|
@@ -79,9 +101,7 @@
|
|
|
79
101
|
@interface EngineViewManager : RCTViewManager
|
|
80
102
|
@end
|
|
81
103
|
|
|
82
|
-
@implementation EngineViewManager
|
|
83
|
-
NSRunLoop* runLoop;
|
|
84
|
-
}
|
|
104
|
+
@implementation EngineViewManager
|
|
85
105
|
|
|
86
106
|
RCT_EXPORT_MODULE(EngineViewManager)
|
|
87
107
|
|
|
@@ -98,13 +118,8 @@ RCT_EXPORT_METHOD(takeSnapshot:(nonnull NSNumber*) reactTag) {
|
|
|
98
118
|
}];
|
|
99
119
|
}
|
|
100
120
|
|
|
101
|
-
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(setJSThread) {
|
|
102
|
-
runLoop = [NSRunLoop currentRunLoop];
|
|
103
|
-
return nil;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
121
|
- (UIView*)view {
|
|
107
|
-
return [[EngineView alloc] init:self.bridge
|
|
122
|
+
return [[EngineView alloc] init:self.bridge];
|
|
108
123
|
}
|
|
109
124
|
|
|
110
125
|
@end
|