@babylonjs/react-native 0.4.0-alpha.43 → 0.4.0-alpha.47
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/EngineView.d.ts +1 -0
- package/EngineView.js +2 -1
- package/EngineView.js.map +1 -1
- package/README.md +8 -0
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/babylonreactnative/EngineView.java +118 -27
- package/android/src/main/java/com/babylonreactnative/EngineViewManager.java +8 -0
- 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/ios/BabylonNativeInterop.mm +10 -10
- package/ios/EngineViewManager.mm +16 -1
- package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +7359 -10383
- 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-msl.a +0 -0
- package/ios/libs/libtinyexr.a +0 -0
- package/ios/libs/libxr.a +0 -0
- package/package.json +3 -4
- package/shared/BabylonNative.h +27 -3
- package/ios/libs/libspirv-cross-hlsl.a +0 -0
package/EngineView.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { Camera } from '@babylonjs/core';
|
|
|
4
4
|
export interface EngineViewProps extends ViewProps {
|
|
5
5
|
camera?: Camera;
|
|
6
6
|
displayFrameRate?: boolean;
|
|
7
|
+
isTransparent?: boolean;
|
|
7
8
|
onInitialized?: (view: EngineViewCallbacks) => void;
|
|
8
9
|
}
|
|
9
10
|
export interface EngineViewCallbacks {
|
package/EngineView.js
CHANGED
|
@@ -10,6 +10,7 @@ export const EngineView = (props) => {
|
|
|
10
10
|
const [sceneStats, setSceneStats] = useState();
|
|
11
11
|
const engineViewRef = useRef(null);
|
|
12
12
|
const snapshotPromise = useRef();
|
|
13
|
+
const isTransparent = props.isTransparent || false;
|
|
13
14
|
useEffect(() => {
|
|
14
15
|
(async () => {
|
|
15
16
|
setInitialized(await ensureInitialized());
|
|
@@ -97,7 +98,7 @@ export const EngineView = (props) => {
|
|
|
97
98
|
}, []);
|
|
98
99
|
if (initialized !== false) {
|
|
99
100
|
return (React.createElement(View, { style: [{ flex: 1 }, props.style, { overflow: "hidden" }] },
|
|
100
|
-
initialized && React.createElement(NativeEngineView, { ref: engineViewRef, style: { flex: 1 }, onSnapshotDataReturned: snapshotDataReturnedHandler }),
|
|
101
|
+
initialized && React.createElement(NativeEngineView, { ref: engineViewRef, style: { flex: 1 }, onSnapshotDataReturned: snapshotDataReturnedHandler, isTransparent: isTransparent }),
|
|
101
102
|
sceneStats !== undefined &&
|
|
102
103
|
React.createElement(View, { style: { backgroundColor: '#00000040', opacity: 1, position: 'absolute', right: 0, left: 0, top: 0, flexDirection: 'row-reverse' } },
|
|
103
104
|
React.createElement(Text, { style: { color: 'yellow', alignSelf: 'flex-end', margin: 3, fontVariant: ['tabular-nums'] } },
|
package/EngineView.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngineView.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/EngineView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAgD,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,sBAAsB,EAAa,QAAQ,EAAkB,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAClI,OAAO,EAAU,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"EngineView.js","sourceRoot":"","sources":["../../Modules/@babylonjs/react-native/EngineView.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAgD,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtH,OAAO,EAAE,sBAAsB,EAAa,QAAQ,EAAkB,IAAI,EAAE,IAAI,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAClI,OAAO,EAAU,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAUpD,MAAM,gBAAgB,GAGlB,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,YAAY,CAAC,GAAG,sBAAsB,CAAC,YAAY,CAAC,CAAC,CAAC;AAkB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C,oBAAC,IAAI,IAAC,KAAK,EAAE,EAAE,QAAQ,EAAE,EAAE,EAAE,uEAAyE,CACnG,CACV,CAAC;KACL;AACL,CAAC,CAAA"}
|
package/README.md
CHANGED
|
@@ -76,4 +76,12 @@ const MyComponent: FunctionComponent<MyComponentProps> = (props: MyComponentProp
|
|
|
76
76
|
}
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
+
Also the `EngineView` has a boolean `isTransparent` flag which defines whether the background of the scene should be transparent or not.
|
|
80
|
+
|
|
81
|
+
e.g.
|
|
82
|
+
|
|
83
|
+
```tsx
|
|
84
|
+
<EngineView style={{flex: 1}} camera={camera} isTransparent={true} />
|
|
85
|
+
```
|
|
86
|
+
|
|
79
87
|
Note: Currently only one `EngineView` can be active at any given time. Multi-view will be supported in a future release.
|
package/android/build.gradle
CHANGED
|
@@ -89,7 +89,7 @@ repositories {
|
|
|
89
89
|
dependencies {
|
|
90
90
|
//noinspection GradleDynamicVersion
|
|
91
91
|
implementation 'com.facebook.react:react-native:+' // From node_modules
|
|
92
|
-
implementation 'com.google.ar:core:1.
|
|
92
|
+
implementation 'com.google.ar:core:1.22.0'
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
def configureReactNativePom(def pom) {
|
|
@@ -2,37 +2,41 @@ package com.babylonreactnative;
|
|
|
2
2
|
|
|
3
3
|
import android.annotation.TargetApi;
|
|
4
4
|
import android.graphics.Bitmap;
|
|
5
|
+
import android.graphics.SurfaceTexture;
|
|
5
6
|
import android.os.Build;
|
|
6
7
|
import android.os.Handler;
|
|
7
8
|
import android.os.HandlerThread;
|
|
8
9
|
import android.util.Base64;
|
|
9
10
|
import android.view.MotionEvent;
|
|
10
11
|
import android.view.PixelCopy;
|
|
12
|
+
import android.view.Surface;
|
|
11
13
|
import android.view.SurfaceHolder;
|
|
12
14
|
import android.view.SurfaceView;
|
|
15
|
+
import android.view.TextureView;
|
|
13
16
|
import android.view.View;
|
|
14
17
|
import android.widget.FrameLayout;
|
|
15
18
|
|
|
19
|
+
import androidx.annotation.NonNull;
|
|
20
|
+
|
|
16
21
|
import com.facebook.react.bridge.ReactContext;
|
|
17
22
|
import com.facebook.react.uimanager.UIManagerModule;
|
|
18
23
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
19
24
|
|
|
20
25
|
import java.io.ByteArrayOutputStream;
|
|
21
26
|
|
|
22
|
-
public final class EngineView extends FrameLayout implements SurfaceHolder.Callback, View.OnTouchListener {
|
|
27
|
+
public final class EngineView extends FrameLayout implements SurfaceHolder.Callback, TextureView.SurfaceTextureListener, View.OnTouchListener {
|
|
23
28
|
private static final FrameLayout.LayoutParams childViewLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
24
|
-
private
|
|
25
|
-
private
|
|
29
|
+
private TextureView transparentTextureView;
|
|
30
|
+
private Surface transparentSurface = null;
|
|
31
|
+
private SurfaceView opaqueSurfaceView = null;
|
|
32
|
+
private SurfaceView xrSurfaceView;
|
|
26
33
|
private final EventDispatcher reactEventDispatcher;
|
|
27
34
|
private Runnable renderRunnable;
|
|
28
35
|
|
|
29
36
|
public EngineView(ReactContext reactContext) {
|
|
30
37
|
super(reactContext);
|
|
31
38
|
|
|
32
|
-
this.
|
|
33
|
-
this.primarySurfaceView.setLayoutParams(EngineView.childViewLayoutParams);
|
|
34
|
-
this.primarySurfaceView.getHolder().addCallback(this);
|
|
35
|
-
this.addView(this.primarySurfaceView);
|
|
39
|
+
this.setIsTransparent(false);
|
|
36
40
|
|
|
37
41
|
this.xrSurfaceView = new SurfaceView(reactContext);
|
|
38
42
|
this.xrSurfaceView.setLayoutParams(childViewLayoutParams);
|
|
@@ -60,22 +64,43 @@ public final class EngineView extends FrameLayout implements SurfaceHolder.Callb
|
|
|
60
64
|
this.reactEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
61
65
|
}
|
|
62
66
|
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
}
|
|
67
|
+
// ------------------------------------
|
|
68
|
+
// TextureView related
|
|
73
69
|
|
|
74
|
-
|
|
75
|
-
|
|
70
|
+
public void setIsTransparent(Boolean isTransparent) {
|
|
71
|
+
if (isTransparent) {
|
|
72
|
+
if (this.opaqueSurfaceView != null) {
|
|
73
|
+
this.opaqueSurfaceView.setVisibility(View.GONE);
|
|
74
|
+
this.opaqueSurfaceView = null;
|
|
76
75
|
}
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
if (this.transparentTextureView == null) {
|
|
77
|
+
this.transparentTextureView = new TextureView(this.getContext());
|
|
78
|
+
this.transparentTextureView.setLayoutParams(EngineView.childViewLayoutParams);
|
|
79
|
+
this.transparentTextureView.setSurfaceTextureListener(this);
|
|
80
|
+
this.transparentTextureView.setOpaque(false);
|
|
81
|
+
this.addView(this.transparentTextureView);
|
|
82
|
+
}
|
|
83
|
+
} else {
|
|
84
|
+
if (this.transparentTextureView != null) {
|
|
85
|
+
this.transparentTextureView.setVisibility(View.GONE);
|
|
86
|
+
this.transparentTextureView = null;
|
|
87
|
+
}
|
|
88
|
+
if (this.opaqueSurfaceView == null) {
|
|
89
|
+
this.opaqueSurfaceView = new SurfaceView(this.getContext());
|
|
90
|
+
this.opaqueSurfaceView.setLayoutParams(EngineView.childViewLayoutParams);
|
|
91
|
+
this.opaqueSurfaceView.getHolder().addCallback(this);
|
|
92
|
+
this.addView(this.opaqueSurfaceView);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
// xr view needs to be on top of views that might be created after it.
|
|
96
|
+
if (this.xrSurfaceView != null) {
|
|
97
|
+
this.xrSurfaceView.bringToFront();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Override
|
|
102
|
+
public void surfaceCreated(SurfaceHolder surfaceHolder) {
|
|
103
|
+
this.startRenderLoop();
|
|
79
104
|
}
|
|
80
105
|
|
|
81
106
|
@Override
|
|
@@ -89,6 +114,43 @@ public final class EngineView extends FrameLayout implements SurfaceHolder.Callb
|
|
|
89
114
|
this.renderRunnable = null;
|
|
90
115
|
}
|
|
91
116
|
|
|
117
|
+
@Override
|
|
118
|
+
public void onSurfaceTextureAvailable(@NonNull SurfaceTexture surfaceTexture, int i, int i1) {
|
|
119
|
+
this.startRenderLoop();
|
|
120
|
+
this.acquireNewTransparentSurface(surfaceTexture);
|
|
121
|
+
BabylonNativeInterop.updateView(this.transparentSurface);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
@Override
|
|
125
|
+
public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surfaceTexture, int i, int i1) {
|
|
126
|
+
this.acquireNewTransparentSurface(surfaceTexture);
|
|
127
|
+
BabylonNativeInterop.updateView(this.transparentSurface);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@Override
|
|
131
|
+
public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surfaceTexture) {
|
|
132
|
+
this.stopRenderLoop();
|
|
133
|
+
this.transparentSurface.release();
|
|
134
|
+
this.transparentSurface = null;
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
@Override
|
|
139
|
+
public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surfaceTexture) {
|
|
140
|
+
this.acquireNewTransparentSurface(surfaceTexture);
|
|
141
|
+
BabylonNativeInterop.updateView(this.transparentSurface);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private void acquireNewTransparentSurface(@NonNull SurfaceTexture surfaceTexture) {
|
|
145
|
+
if (this.transparentSurface != null) {
|
|
146
|
+
this.transparentSurface.release();
|
|
147
|
+
}
|
|
148
|
+
this.transparentSurface = new Surface(surfaceTexture);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// ------------------------------------
|
|
152
|
+
// Common
|
|
153
|
+
|
|
92
154
|
@Override
|
|
93
155
|
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
94
156
|
BabylonNativeInterop.reportMotionEvent(motionEvent);
|
|
@@ -114,13 +176,20 @@ public final class EngineView extends FrameLayout implements SurfaceHolder.Callb
|
|
|
114
176
|
helperThread.start();
|
|
115
177
|
final Handler helperThreadHandler = new Handler(helperThread.getLooper());
|
|
116
178
|
|
|
117
|
-
|
|
179
|
+
Surface sourceSurface = this.transparentSurface;
|
|
118
180
|
if (BabylonNativeInterop.isXRActive()) {
|
|
119
|
-
|
|
181
|
+
sourceSurface = this.xrSurfaceView.getHolder().getSurface();
|
|
182
|
+
} else if (this.opaqueSurfaceView != null) {
|
|
183
|
+
sourceSurface = this.opaqueSurfaceView.getHolder().getSurface();
|
|
120
184
|
}
|
|
185
|
+
PixelCopy.request(sourceSurface, bitmap, getOnPixelCopyFinishedListener(bitmap, helperThread), helperThreadHandler);
|
|
186
|
+
}
|
|
121
187
|
|
|
122
|
-
|
|
123
|
-
|
|
188
|
+
// ---------------------------------------------------------------------------------------------
|
|
189
|
+
// Returns the listener for the PixelCopy.request function call
|
|
190
|
+
@NonNull
|
|
191
|
+
private PixelCopy.OnPixelCopyFinishedListener getOnPixelCopyFinishedListener(Bitmap bitmap, HandlerThread helperThread) {
|
|
192
|
+
return (copyResult) -> {
|
|
124
193
|
// If the pixel copy was a success then convert the image to a base 64 encoded jpeg and fire the event.
|
|
125
194
|
String encoded = "";
|
|
126
195
|
if (copyResult == PixelCopy.SUCCESS) {
|
|
@@ -130,10 +199,32 @@ public final class EngineView extends FrameLayout implements SurfaceHolder.Callb
|
|
|
130
199
|
bitmap.recycle();
|
|
131
200
|
encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
132
201
|
}
|
|
133
|
-
|
|
134
202
|
SnapshotDataReturnedEvent snapshotEvent = new SnapshotDataReturnedEvent(this.getId(), encoded);
|
|
135
203
|
reactEventDispatcher.dispatchEvent(snapshotEvent);
|
|
136
204
|
helperThread.quitSafely();
|
|
137
|
-
}
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private void startRenderLoop() {
|
|
209
|
+
if(this.renderRunnable == null){
|
|
210
|
+
this.renderRunnable = new Runnable() {
|
|
211
|
+
@Override
|
|
212
|
+
public void run() {
|
|
213
|
+
if (BabylonNativeInterop.isXRActive()) {
|
|
214
|
+
EngineView.this.xrSurfaceView.setVisibility(View.VISIBLE);
|
|
215
|
+
} else {
|
|
216
|
+
EngineView.this.xrSurfaceView.setVisibility(View.INVISIBLE);
|
|
217
|
+
}
|
|
218
|
+
BabylonNativeInterop.renderView();
|
|
219
|
+
EngineView.this.postOnAnimation(this);
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
this.postOnAnimation(this.renderRunnable);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
private void stopRenderLoop() {
|
|
227
|
+
this.removeCallbacks(this.renderRunnable);
|
|
228
|
+
this.renderRunnable = null;
|
|
138
229
|
}
|
|
139
230
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
package com.babylonreactnative;
|
|
2
2
|
|
|
3
|
+
import android.widget.FrameLayout;
|
|
4
|
+
|
|
3
5
|
import androidx.annotation.NonNull;
|
|
4
6
|
import androidx.annotation.Nullable;
|
|
5
7
|
|
|
@@ -7,6 +9,7 @@ import com.facebook.react.bridge.ReadableArray;
|
|
|
7
9
|
import com.facebook.react.common.MapBuilder;
|
|
8
10
|
import com.facebook.react.uimanager.SimpleViewManager;
|
|
9
11
|
import com.facebook.react.uimanager.ThemedReactContext;
|
|
12
|
+
import com.facebook.react.uimanager.annotations.ReactProp;
|
|
10
13
|
|
|
11
14
|
import java.util.Map;
|
|
12
15
|
|
|
@@ -20,6 +23,11 @@ public final class EngineViewManager extends SimpleViewManager<EngineView> {
|
|
|
20
23
|
return "EngineView";
|
|
21
24
|
}
|
|
22
25
|
|
|
26
|
+
@ReactProp(name = "isTransparent")
|
|
27
|
+
public void setIsTransparent(EngineView view, Boolean isTransparent) {
|
|
28
|
+
view.setIsTransparent(isTransparent);
|
|
29
|
+
}
|
|
30
|
+
|
|
23
31
|
@NonNull
|
|
24
32
|
@Override
|
|
25
33
|
protected EngineView createViewInstance(@NonNull ThemedReactContext reactContext) {
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -36,7 +36,7 @@ static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
|
36
36
|
});
|
|
37
37
|
} };
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
BabylonNative::Initialize(*GetJSIRuntime(bridge), std::move(jsDispatcher));
|
|
40
40
|
|
|
41
41
|
[[NSNotificationCenter defaultCenter] removeObserver:self
|
|
42
42
|
name:RCTBridgeWillInvalidateModulesNotification
|
|
@@ -51,7 +51,7 @@ static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
|
51
51
|
// NOTE: This happens during dev mode reload, when the JS engine is being shutdown and restarted.
|
|
52
52
|
+ (void)onBridgeWillInvalidate:(NSNotification*)notification
|
|
53
53
|
{
|
|
54
|
-
|
|
54
|
+
BabylonNative::Deinitialize();
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
+ (void)updateView:(MTKView*)mtkView {
|
|
@@ -59,24 +59,24 @@ static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
|
59
59
|
const int width = static_cast<int>(mtkView.bounds.size.width * scale);
|
|
60
60
|
const int height = static_cast<int>(mtkView.bounds.size.height * scale);
|
|
61
61
|
if (width != 0 && height != 0) {
|
|
62
|
-
|
|
62
|
+
BabylonNative::UpdateView(mtkView, width, height);
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
+ (void)renderView {
|
|
67
|
-
|
|
67
|
+
BabylonNative::RenderView();
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
+ (void)resetView {
|
|
71
|
-
|
|
71
|
+
BabylonNative::ResetView();
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
+ (void)updateXRView:(MTKView*)mtkView {
|
|
75
|
-
|
|
75
|
+
BabylonNative::UpdateXRView(mtkView);
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
+ (bool)isXRActive {
|
|
79
|
-
return
|
|
79
|
+
return BabylonNative::IsXRActive();
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
+ (void)reportTouchEvent:(MTKView*)mtkView touches:(NSSet<UITouch*>*)touches event:(UIEvent*)event {
|
|
@@ -98,14 +98,14 @@ static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
|
98
98
|
pointerId = [activeTouches count];
|
|
99
99
|
[activeTouches addObject:touch];
|
|
100
100
|
}
|
|
101
|
-
|
|
101
|
+
BabylonNative::SetTouchButtonState(static_cast<uint32_t>(pointerId), true, x, y);
|
|
102
102
|
break;
|
|
103
103
|
}
|
|
104
104
|
|
|
105
105
|
case UITouchPhaseMoved: {
|
|
106
106
|
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
107
107
|
if (pointerId != NSNotFound) {
|
|
108
|
-
|
|
108
|
+
BabylonNative::SetTouchPosition(static_cast<uint32_t>(pointerId), x, y);
|
|
109
109
|
}
|
|
110
110
|
break;
|
|
111
111
|
}
|
|
@@ -115,7 +115,7 @@ static NSMutableArray* activeTouches = [NSMutableArray new];
|
|
|
115
115
|
NSUInteger pointerId = [activeTouches indexOfObject:touch];
|
|
116
116
|
if (pointerId != NSNotFound) {
|
|
117
117
|
[activeTouches replaceObjectAtIndex:pointerId withObject:[NSNull null]];
|
|
118
|
-
|
|
118
|
+
BabylonNative::SetTouchButtonState(static_cast<uint32_t>(pointerId), false, x, y);
|
|
119
119
|
}
|
|
120
120
|
break;
|
|
121
121
|
}
|
package/ios/EngineViewManager.mm
CHANGED
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
@interface EngineView : MTKView
|
|
12
12
|
|
|
13
13
|
@property (nonatomic, copy) RCTDirectEventBlock onSnapshotDataReturned;
|
|
14
|
+
@property (nonatomic, assign) BOOL isTransparent;
|
|
15
|
+
|
|
14
16
|
|
|
15
17
|
@end
|
|
16
18
|
|
|
@@ -22,7 +24,6 @@
|
|
|
22
24
|
- (instancetype)init:(RCTBridge*)_bridge {
|
|
23
25
|
if (self = [super initWithFrame:CGRectZero device:MTLCreateSystemDefaultDevice()]) {
|
|
24
26
|
bridge = _bridge;
|
|
25
|
-
|
|
26
27
|
super.translatesAutoresizingMaskIntoConstraints = false;
|
|
27
28
|
super.colorPixelFormat = MTLPixelFormatBGRA8Unorm_sRGB;
|
|
28
29
|
super.depthStencilPixelFormat = MTLPixelFormatDepth32Float;
|
|
@@ -30,6 +31,16 @@
|
|
|
30
31
|
return self;
|
|
31
32
|
}
|
|
32
33
|
|
|
34
|
+
- (void)setIsTransparentFlag:(NSNumber*)isTransparentFlag {
|
|
35
|
+
BOOL isTransparent = [isTransparentFlag intValue] == 1;
|
|
36
|
+
if(isTransparent){
|
|
37
|
+
[self setOpaque:NO];
|
|
38
|
+
} else {
|
|
39
|
+
[self setOpaque:YES];
|
|
40
|
+
}
|
|
41
|
+
self.isTransparent = isTransparent;
|
|
42
|
+
}
|
|
43
|
+
|
|
33
44
|
- (void)setBounds:(CGRect)bounds {
|
|
34
45
|
[super setBounds:bounds];
|
|
35
46
|
[BabylonNativeInterop updateView:self];
|
|
@@ -103,6 +114,10 @@
|
|
|
103
114
|
|
|
104
115
|
@implementation EngineViewManager
|
|
105
116
|
|
|
117
|
+
RCT_CUSTOM_VIEW_PROPERTY(isTransparent, NSNumber*, EngineView){
|
|
118
|
+
[view setIsTransparentFlag:json];
|
|
119
|
+
}
|
|
120
|
+
|
|
106
121
|
RCT_EXPORT_MODULE(EngineViewManager)
|
|
107
122
|
|
|
108
123
|
RCT_EXPORT_VIEW_PROPERTY(onSnapshotDataReturned, RCTDirectEventBlock)
|