@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
|
@@ -7,169 +7,118 @@ import android.view.MotionEvent;
|
|
|
7
7
|
import android.view.Surface;
|
|
8
8
|
|
|
9
9
|
import com.facebook.react.bridge.ActivityEventListener;
|
|
10
|
-
import com.facebook.react.bridge.JavaScriptContextHolder;
|
|
11
10
|
import com.facebook.react.bridge.LifecycleEventListener;
|
|
12
11
|
import com.facebook.react.bridge.ReactContext;
|
|
13
12
|
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
import java.util.Iterator;
|
|
17
|
-
import java.util.Map;
|
|
18
|
-
import java.util.concurrent.CompletableFuture;
|
|
19
|
-
import java.util.concurrent.CompletionStage;
|
|
14
|
+
public final class BabylonNativeInterop {
|
|
20
15
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
private static class BabylonNative {
|
|
17
|
+
static {
|
|
18
|
+
System.loadLibrary("BabylonNative");
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
public static native void initialize(Context context, long jsiRuntimeRef, CallInvokerHolder jsCallInvokerHolder);
|
|
22
|
+
public static native void setCurrentActivity(Activity activity);
|
|
23
|
+
public static native void pause();
|
|
24
|
+
public static native void resume();
|
|
25
|
+
public static native void updateView(Surface surface);
|
|
26
|
+
public static native void renderView();
|
|
27
|
+
public static native void resetView();
|
|
28
|
+
public static native void updateXRView(Surface surface);
|
|
29
|
+
public static native boolean isXRActive();
|
|
30
|
+
public static native void setTouchButtonState(int pointerId, boolean isDown, int x, int y);
|
|
31
|
+
public static native void setTouchPosition(int pointerId, int x, int y);
|
|
25
32
|
}
|
|
26
33
|
|
|
27
|
-
private static
|
|
28
|
-
private static
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
private static native void setPointerPosition(long instanceRef, int pointerId, int x, int y);
|
|
38
|
-
private static native void reset(long instanceRef);
|
|
39
|
-
private static native void destroy(long instanceRef);
|
|
40
|
-
|
|
41
|
-
// Must be called from the Android UI thread
|
|
42
|
-
static void setView(ReactContext reactContext, Surface surface) {
|
|
43
|
-
// This is global initialization that only needs to happen once
|
|
44
|
-
if (!BabylonNativeInterop.isInitialized) {
|
|
45
|
-
BabylonNativeInterop.initialize(reactContext);
|
|
46
|
-
BabylonNativeInterop.isInitialized = true;
|
|
34
|
+
private static LifecycleEventListener lifeCycleEventListener;
|
|
35
|
+
private static ActivityEventListener activityEventListener;
|
|
36
|
+
|
|
37
|
+
public static void initialize(ReactContext reactContext) {
|
|
38
|
+
long jsiRuntimeRef = reactContext.getJavaScriptContextHolder().get();
|
|
39
|
+
CallInvokerHolder jsCallInvokerHolder = reactContext.getCatalystInstance().getJSCallInvokerHolder();
|
|
40
|
+
BabylonNative.initialize(reactContext, jsiRuntimeRef, jsCallInvokerHolder);
|
|
41
|
+
|
|
42
|
+
if (BabylonNativeInterop.lifeCycleEventListener != null) {
|
|
43
|
+
reactContext.removeLifecycleEventListener(lifeCycleEventListener);
|
|
47
44
|
}
|
|
48
45
|
|
|
49
|
-
BabylonNativeInterop.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
Long instanceRef = instanceRefFuture.getNow(null);
|
|
55
|
-
if (instanceRef == null)
|
|
56
|
-
{
|
|
57
|
-
long jsiRuntimeRef = reactContext.getJavaScriptContextHolder().get();
|
|
58
|
-
if (jsiRuntimeRef == 0) {
|
|
59
|
-
instanceRefFuture.complete(0L);
|
|
60
|
-
} else {
|
|
61
|
-
instanceRef = BabylonNativeInterop.create(jsiRuntimeRef, reactContext.getCatalystInstance().getJSCallInvokerHolder(), surface);
|
|
62
|
-
final long finalInstanceRef = instanceRef;
|
|
63
|
-
|
|
64
|
-
reactContext.addLifecycleEventListener(new LifecycleEventListener() {
|
|
65
|
-
@Override
|
|
66
|
-
public void onHostResume() {
|
|
67
|
-
BabylonNativeInterop.setCurrentActivity(reactContext.getCurrentActivity());
|
|
68
|
-
BabylonNativeInterop.resume();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
@Override
|
|
72
|
-
public void onHostPause() {
|
|
73
|
-
BabylonNativeInterop.pause();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
@Override
|
|
77
|
-
public void onHostDestroy() {
|
|
78
|
-
BabylonNativeInterop.deinitialize();
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
reactContext.addActivityEventListener(new ActivityEventListener() {
|
|
83
|
-
@Override
|
|
84
|
-
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
85
|
-
// Nothing to do here
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
@Override
|
|
89
|
-
public void onNewIntent(Intent intent) {
|
|
90
|
-
BabylonNativeInterop.setCurrentActivity(reactContext.getCurrentActivity());
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
instanceRefFuture.complete(finalInstanceRef);
|
|
95
|
-
}
|
|
96
|
-
} else if (instanceRef != 0) {
|
|
97
|
-
BabylonNativeInterop.refresh(instanceRef, surface);
|
|
46
|
+
BabylonNativeInterop.lifeCycleEventListener = new LifecycleEventListener() {
|
|
47
|
+
@Override
|
|
48
|
+
public void onHostResume() {
|
|
49
|
+
BabylonNative.setCurrentActivity(reactContext.getCurrentActivity());
|
|
50
|
+
BabylonNative.resume();
|
|
98
51
|
}
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
52
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
Long instanceRef = instanceRefFuture.getNow(null);
|
|
106
|
-
if (instanceRef != null) {
|
|
107
|
-
int maskedAction = motionEvent.getActionMasked();
|
|
108
|
-
boolean isPointerDown = maskedAction == MotionEvent.ACTION_DOWN || maskedAction == MotionEvent.ACTION_POINTER_DOWN;
|
|
109
|
-
boolean isPointerUp = maskedAction == MotionEvent.ACTION_UP || maskedAction == MotionEvent.ACTION_POINTER_UP;
|
|
110
|
-
boolean isPointerMove = maskedAction == MotionEvent.ACTION_MOVE;
|
|
111
|
-
|
|
112
|
-
if (isPointerDown || isPointerUp) {
|
|
113
|
-
int pointerIndex = motionEvent.getActionIndex();
|
|
114
|
-
int pointerId = motionEvent.getPointerId(pointerIndex);
|
|
115
|
-
int buttonId = motionEvent.getActionButton();
|
|
116
|
-
int x = (int)motionEvent.getX(pointerIndex);
|
|
117
|
-
int y = (int)motionEvent.getY(pointerIndex);
|
|
118
|
-
BabylonNativeInterop.setPointerButtonState(instanceRef, pointerId, buttonId, isPointerDown, x, y);
|
|
119
|
-
} else if (isPointerMove) {
|
|
120
|
-
for (int pointerIndex = 0; pointerIndex < motionEvent.getPointerCount(); pointerIndex++) {
|
|
121
|
-
int pointerId = motionEvent.getPointerId(pointerIndex);
|
|
122
|
-
int x = (int)motionEvent.getX(pointerIndex);
|
|
123
|
-
int y = (int)motionEvent.getY(pointerIndex);
|
|
124
|
-
BabylonNativeInterop.setPointerPosition(instanceRef, pointerId, x, y);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
53
|
+
@Override
|
|
54
|
+
public void onHostPause() {
|
|
55
|
+
BabylonNative.pause();
|
|
127
56
|
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public void onHostDestroy() {
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
reactContext.addLifecycleEventListener(lifeCycleEventListener);
|
|
64
|
+
|
|
65
|
+
if (BabylonNativeInterop.activityEventListener != null) {
|
|
66
|
+
reactContext.removeActivityEventListener(BabylonNativeInterop.activityEventListener);
|
|
128
67
|
}
|
|
68
|
+
|
|
69
|
+
BabylonNativeInterop.activityEventListener = new ActivityEventListener() {
|
|
70
|
+
@Override
|
|
71
|
+
public void onActivityResult(Activity activity, int requestCode, int resultCode, Intent data) {
|
|
72
|
+
// Nothing to do here
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Override
|
|
76
|
+
public void onNewIntent(Intent intent) {
|
|
77
|
+
BabylonNative.setCurrentActivity(reactContext.getCurrentActivity());
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
reactContext.addActivityEventListener(BabylonNativeInterop.activityEventListener);
|
|
129
82
|
}
|
|
130
83
|
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return BabylonNativeInterop.getOrCreateFuture(reactContext);
|
|
84
|
+
public static void updateView(Surface surface) {
|
|
85
|
+
BabylonNative.updateView(surface);
|
|
134
86
|
}
|
|
135
87
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
BabylonNativeInterop.destroyOldNativeInstances(null);
|
|
88
|
+
public static void renderView() {
|
|
89
|
+
BabylonNative.renderView();
|
|
139
90
|
}
|
|
140
91
|
|
|
141
|
-
static void
|
|
142
|
-
|
|
143
|
-
CompletableFuture<Long> instanceRefFuture = BabylonNativeInterop.nativeInstances.get(jsContext);
|
|
144
|
-
if (instanceRefFuture != null) {
|
|
145
|
-
Long instanceRef = instanceRefFuture.getNow(null);
|
|
146
|
-
if (instanceRef != null) {
|
|
147
|
-
BabylonNativeInterop.reset(instanceRef);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
92
|
+
public static void resetView() {
|
|
93
|
+
BabylonNative.resetView();
|
|
150
94
|
}
|
|
151
95
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
BabylonNativeInterop.nativeInstances.put(jsContext, instanceRefFuture);
|
|
159
|
-
}
|
|
160
|
-
return instanceRefFuture;
|
|
96
|
+
public static void updateXRView(Surface surface) {
|
|
97
|
+
BabylonNative.updateXRView(surface);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
public static boolean isXRActive() {
|
|
101
|
+
return BabylonNative.isXRActive();
|
|
161
102
|
}
|
|
162
103
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
104
|
+
public static void reportMotionEvent(MotionEvent motionEvent) {
|
|
105
|
+
int maskedAction = motionEvent.getActionMasked();
|
|
106
|
+
boolean isPointerDown = maskedAction == MotionEvent.ACTION_DOWN || maskedAction == MotionEvent.ACTION_POINTER_DOWN;
|
|
107
|
+
boolean isPointerUp = maskedAction == MotionEvent.ACTION_UP || maskedAction == MotionEvent.ACTION_POINTER_UP;
|
|
108
|
+
boolean isPointerMove = maskedAction == MotionEvent.ACTION_MOVE;
|
|
109
|
+
|
|
110
|
+
if (isPointerDown || isPointerUp) {
|
|
111
|
+
int pointerIndex = motionEvent.getActionIndex();
|
|
112
|
+
int pointerId = motionEvent.getPointerId(pointerIndex);
|
|
113
|
+
int x = (int)motionEvent.getX(pointerIndex);
|
|
114
|
+
int y = (int)motionEvent.getY(pointerIndex);
|
|
115
|
+
BabylonNative.setTouchButtonState(pointerId, isPointerDown, x, y);
|
|
116
|
+
} else if (isPointerMove) {
|
|
117
|
+
for (int pointerIndex = 0; pointerIndex < motionEvent.getPointerCount(); pointerIndex++) {
|
|
118
|
+
int pointerId = motionEvent.getPointerId(pointerIndex);
|
|
119
|
+
int x = (int)motionEvent.getX(pointerIndex);
|
|
120
|
+
int y = (int)motionEvent.getY(pointerIndex);
|
|
121
|
+
BabylonNative.setTouchPosition(pointerId, x, y);
|
|
173
122
|
}
|
|
174
123
|
}
|
|
175
124
|
}
|
|
@@ -11,6 +11,7 @@ import android.view.PixelCopy;
|
|
|
11
11
|
import android.view.SurfaceHolder;
|
|
12
12
|
import android.view.SurfaceView;
|
|
13
13
|
import android.view.View;
|
|
14
|
+
import android.widget.FrameLayout;
|
|
14
15
|
|
|
15
16
|
import com.facebook.react.bridge.ReactContext;
|
|
16
17
|
import com.facebook.react.uimanager.UIManagerModule;
|
|
@@ -18,36 +19,79 @@ import com.facebook.react.uimanager.events.EventDispatcher;
|
|
|
18
19
|
|
|
19
20
|
import java.io.ByteArrayOutputStream;
|
|
20
21
|
|
|
21
|
-
public final class EngineView extends
|
|
22
|
-
private final
|
|
22
|
+
public final class EngineView extends FrameLayout implements SurfaceHolder.Callback, View.OnTouchListener {
|
|
23
|
+
private static final FrameLayout.LayoutParams childViewLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
24
|
+
private final SurfaceView primarySurfaceView;
|
|
25
|
+
private final SurfaceView xrSurfaceView;
|
|
23
26
|
private final EventDispatcher reactEventDispatcher;
|
|
27
|
+
private Runnable renderRunnable;
|
|
24
28
|
|
|
25
29
|
public EngineView(ReactContext reactContext) {
|
|
26
30
|
super(reactContext);
|
|
27
|
-
|
|
28
|
-
this.
|
|
31
|
+
|
|
32
|
+
this.primarySurfaceView = new SurfaceView(reactContext);
|
|
33
|
+
this.primarySurfaceView.setLayoutParams(EngineView.childViewLayoutParams);
|
|
34
|
+
this.primarySurfaceView.getHolder().addCallback(this);
|
|
35
|
+
this.addView(this.primarySurfaceView);
|
|
36
|
+
|
|
37
|
+
this.xrSurfaceView = new SurfaceView(reactContext);
|
|
38
|
+
this.xrSurfaceView.setLayoutParams(childViewLayoutParams);
|
|
39
|
+
this.xrSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
|
40
|
+
@Override
|
|
41
|
+
public void surfaceCreated(SurfaceHolder holder) {
|
|
42
|
+
// surfaceChanged is also called when the surface is created, so just do all the handling there
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
@Override
|
|
46
|
+
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
|
47
|
+
BabylonNativeInterop.updateXRView(holder.getSurface());
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Override
|
|
51
|
+
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
52
|
+
BabylonNativeInterop.updateXRView(null);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
this.xrSurfaceView.setVisibility(View.INVISIBLE);
|
|
56
|
+
this.addView(this.xrSurfaceView);
|
|
57
|
+
|
|
29
58
|
this.setOnTouchListener(this);
|
|
30
|
-
|
|
59
|
+
|
|
60
|
+
this.reactEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
31
61
|
}
|
|
32
62
|
|
|
33
63
|
@Override
|
|
34
64
|
public void surfaceCreated(SurfaceHolder surfaceHolder) {
|
|
35
|
-
|
|
65
|
+
this.renderRunnable = new Runnable() {
|
|
66
|
+
@Override
|
|
67
|
+
public void run() {
|
|
68
|
+
if (BabylonNativeInterop.isXRActive()) {
|
|
69
|
+
EngineView.this.xrSurfaceView.setVisibility(View.VISIBLE);
|
|
70
|
+
} else {
|
|
71
|
+
EngineView.this.xrSurfaceView.setVisibility(View.INVISIBLE);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
BabylonNativeInterop.renderView();
|
|
75
|
+
EngineView.this.postOnAnimation(this);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
this.postOnAnimation(this.renderRunnable);
|
|
36
79
|
}
|
|
37
80
|
|
|
38
81
|
@Override
|
|
39
82
|
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int width, int height) {
|
|
40
|
-
BabylonNativeInterop.
|
|
83
|
+
BabylonNativeInterop.updateView(surfaceHolder.getSurface());
|
|
41
84
|
}
|
|
42
85
|
|
|
43
86
|
@Override
|
|
44
87
|
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
|
|
45
|
-
|
|
88
|
+
this.removeCallbacks(this.renderRunnable);
|
|
89
|
+
this.renderRunnable = null;
|
|
46
90
|
}
|
|
47
91
|
|
|
48
92
|
@Override
|
|
49
93
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
50
|
-
BabylonNativeInterop.reportMotionEvent(
|
|
94
|
+
BabylonNativeInterop.reportMotionEvent(motionEvent);
|
|
51
95
|
return true;
|
|
52
96
|
}
|
|
53
97
|
|
|
@@ -70,13 +114,18 @@ public final class EngineView extends SurfaceView implements SurfaceHolder.Callb
|
|
|
70
114
|
helperThread.start();
|
|
71
115
|
final Handler helperThreadHandler = new Handler(helperThread.getLooper());
|
|
72
116
|
|
|
117
|
+
SurfaceView surfaceView = this.primarySurfaceView;
|
|
118
|
+
if (BabylonNativeInterop.isXRActive()) {
|
|
119
|
+
surfaceView = this.xrSurfaceView;
|
|
120
|
+
}
|
|
121
|
+
|
|
73
122
|
// Request the pixel copy.
|
|
74
|
-
PixelCopy.request(
|
|
123
|
+
PixelCopy.request(surfaceView, bitmap, (copyResult) -> {
|
|
75
124
|
// If the pixel copy was a success then convert the image to a base 64 encoded jpeg and fire the event.
|
|
76
125
|
String encoded = "";
|
|
77
126
|
if (copyResult == PixelCopy.SUCCESS) {
|
|
78
127
|
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
|
|
79
|
-
bitmap.compress(Bitmap.CompressFormat.JPEG,
|
|
128
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayStream);
|
|
80
129
|
byte[] byteArray = byteArrayStream.toByteArray();
|
|
81
130
|
bitmap.recycle();
|
|
82
131
|
encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/index.d.ts
ADDED
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,iBAAiB,CAAC;AAChC,cAAc,YAAY,CAAC"}
|
package/ios/BabylonModule.mm
CHANGED
|
@@ -19,16 +19,15 @@ RCT_EXPORT_MODULE();
|
|
|
19
19
|
@synthesize bridge = _bridge;
|
|
20
20
|
|
|
21
21
|
RCT_EXPORT_METHOD(initialize:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
22
|
-
[
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
[BabylonNativeInterop whenInitialized:self.bridge resolve:resolve];
|
|
22
|
+
self.bridge.jsCallInvoker->invokeAsync([bridge{ self.bridge }, resolve]() {
|
|
23
|
+
[BabylonNativeInterop initialize:bridge];
|
|
24
|
+
resolve([NSNull null]);
|
|
25
|
+
});
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
RCT_EXPORT_METHOD(
|
|
30
|
-
|
|
31
|
-
[BabylonNativeInterop
|
|
28
|
+
RCT_EXPORT_METHOD(resetView:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
|
29
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
30
|
+
[BabylonNativeInterop resetView];
|
|
32
31
|
resolve([NSNull null]);
|
|
33
32
|
});
|
|
34
33
|
}
|
|
@@ -4,8 +4,11 @@
|
|
|
4
4
|
#import <React/RCTBridge.h>
|
|
5
5
|
|
|
6
6
|
@interface BabylonNativeInterop : NSObject
|
|
7
|
-
+ (void)
|
|
8
|
-
+ (void)
|
|
9
|
-
+ (void)
|
|
10
|
-
+ (void)
|
|
7
|
+
+ (void)initialize:(RCTBridge*)bridge;
|
|
8
|
+
+ (void)updateView:(MTKView*)mtkView;
|
|
9
|
+
+ (void)renderView;
|
|
10
|
+
+ (void)resetView;
|
|
11
|
+
+ (void)updateXRView:(MTKView*)mtkView;
|
|
12
|
+
+ (bool)isXRActive;
|
|
13
|
+
+ (void)reportTouchEvent:(MTKView*)mtkView touches:(NSSet<UITouch*>*)touches event:(UIEvent*)event;
|
|
11
14
|
@end
|