@babylonjs/react-native 0.65.0-alpha.49 → 1.0.0-preview.1
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/package.json +5 -5
- package/shared/BabylonNative.h +4 -4
- package/android/build.gradle +0 -173
- package/android/include/IXrContextARCore.h +0 -10
- package/android/src/main/AndroidManifest.xml +0 -4
- package/android/src/main/java/com/babylonreactnative/BabylonModule.java +0 -37
- package/android/src/main/java/com/babylonreactnative/BabylonNativeInterop.java +0 -125
- package/android/src/main/java/com/babylonreactnative/BabylonPackage.java +0 -21
- package/android/src/main/java/com/babylonreactnative/EngineView.java +0 -230
- package/android/src/main/java/com/babylonreactnative/EngineViewManager.java +0 -71
- package/android/src/main/java/com/babylonreactnative/SnapshotDataReturnedEvent.java +0 -28
- 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/BabylonModule.mm +0 -35
- package/ios/BabylonNativeInterop.h +0 -14
- package/ios/BabylonNativeInterop.mm +0 -130
- package/ios/EngineViewManager.mm +0 -140
- package/ios/ReactNativeBabylon.xcodeproj/project.pbxproj +0 -14885
- package/ios/ReactNativeBabylon.xcodeproj/project.xcworkspace/xcshareddata/WorkspaceSettings.xcsettings +0 -8
- package/ios/include/IXrContextARKit.h +0 -10
- 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/react-native-babylon.podspec +0 -25
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@babylonjs/react-native",
|
|
3
3
|
"title": "React Native Babylon",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "1.0.0-preview.1",
|
|
5
5
|
"description": "Babylon Native integration into React Native",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"scripts": {
|
|
@@ -28,15 +28,15 @@
|
|
|
28
28
|
"semver": "^7.3.2"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
|
-
"@babylonjs/core": "^5.0.0-rc.
|
|
31
|
+
"@babylonjs/core": "^5.0.0-rc.12",
|
|
32
32
|
"react": ">=16.13.1",
|
|
33
|
-
"react-native": ">=0.
|
|
34
|
-
"react-native-permissions": "^
|
|
33
|
+
"react-native": ">=0.63.1",
|
|
34
|
+
"react-native-permissions": "^3.0.0"
|
|
35
35
|
},
|
|
36
36
|
"devDependencies": {
|
|
37
37
|
"@babel/core": "^7.8.4",
|
|
38
38
|
"@babel/runtime": "^7.8.4",
|
|
39
|
-
"@babylonjs/core": "5.0.0-rc.
|
|
39
|
+
"@babylonjs/core": "5.0.0-rc.12",
|
|
40
40
|
"@rnw-scripts/eslint-config": "0.1.6",
|
|
41
41
|
"@rnw-scripts/ts-config": "0.1.0",
|
|
42
42
|
"@types/base-64": "^0.1.3",
|
package/shared/BabylonNative.h
CHANGED
|
@@ -31,10 +31,10 @@ namespace BabylonNative
|
|
|
31
31
|
|
|
32
32
|
void RenderView();
|
|
33
33
|
void ResetView();
|
|
34
|
-
void SetMouseButtonState(uint32_t buttonId, bool isDown,
|
|
35
|
-
void SetMousePosition(
|
|
36
|
-
void SetTouchButtonState(uint32_t pointerId, bool isDown,
|
|
37
|
-
void SetTouchPosition(uint32_t pointerId,
|
|
34
|
+
void SetMouseButtonState(uint32_t buttonId, bool isDown, int32_t x, int32_t y);
|
|
35
|
+
void SetMousePosition(int32_t x, int32_t y);
|
|
36
|
+
void SetTouchButtonState(uint32_t pointerId, bool isDown, int32_t x, int32_t y);
|
|
37
|
+
void SetTouchPosition(uint32_t pointerId, int32_t x, int32_t y);
|
|
38
38
|
|
|
39
39
|
bool IsXRActive();
|
|
40
40
|
|
package/android/build.gradle
DELETED
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
// android/build.gradle
|
|
2
|
-
|
|
3
|
-
// based on:
|
|
4
|
-
//
|
|
5
|
-
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/build.gradle
|
|
6
|
-
// original location:
|
|
7
|
-
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/build.gradle
|
|
8
|
-
//
|
|
9
|
-
// * https://github.com/facebook/react-native/blob/0.60-stable/template/android/app/build.gradle
|
|
10
|
-
// original location:
|
|
11
|
-
// - https://github.com/facebook/react-native/blob/0.58-stable/local-cli/templates/HelloWorld/android/app/build.gradle
|
|
12
|
-
|
|
13
|
-
def DEFAULT_COMPILE_SDK_VERSION = 28
|
|
14
|
-
def DEFAULT_BUILD_TOOLS_VERSION = '28.0.3'
|
|
15
|
-
def DEFAULT_MIN_SDK_VERSION = 18
|
|
16
|
-
def DEFAULT_TARGET_SDK_VERSION = 28
|
|
17
|
-
|
|
18
|
-
def safeExtGet(prop, fallback) {
|
|
19
|
-
rootProject.ext.has(prop) ? rootProject.ext.get(prop) : fallback
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
def reactProperties = new Properties()
|
|
23
|
-
file("$projectDir/../../../react-native/ReactAndroid/gradle.properties").withInputStream { reactProperties.load(it) }
|
|
24
|
-
def REACT_VERSION = reactProperties.getProperty("VERSION_NAME").split("\\.")[1].toInteger()
|
|
25
|
-
|
|
26
|
-
apply plugin: 'com.android.library'
|
|
27
|
-
apply plugin: 'maven'
|
|
28
|
-
|
|
29
|
-
buildscript {
|
|
30
|
-
// The Android Gradle plugin is only required when opening the android folder stand-alone.
|
|
31
|
-
// This avoids unnecessary downloads and potential conflicts when the library is included as a
|
|
32
|
-
// module dependency in an application project.
|
|
33
|
-
// ref: https://docs.gradle.org/current/userguide/tutorial_using_tasks.html#sec:build_script_external_dependencies
|
|
34
|
-
if (project == rootProject) {
|
|
35
|
-
repositories {
|
|
36
|
-
google()
|
|
37
|
-
jcenter()
|
|
38
|
-
}
|
|
39
|
-
dependencies {
|
|
40
|
-
classpath 'com.android.tools.build:gradle:3.4.1'
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
apply plugin: 'com.android.library'
|
|
46
|
-
apply plugin: 'maven'
|
|
47
|
-
|
|
48
|
-
android {
|
|
49
|
-
compileSdkVersion safeExtGet('compileSdkVersion', DEFAULT_COMPILE_SDK_VERSION)
|
|
50
|
-
buildToolsVersion safeExtGet('buildToolsVersion', DEFAULT_BUILD_TOOLS_VERSION)
|
|
51
|
-
defaultConfig {
|
|
52
|
-
minSdkVersion safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
|
|
53
|
-
targetSdkVersion safeExtGet('targetSdkVersion', DEFAULT_TARGET_SDK_VERSION)
|
|
54
|
-
versionCode 1
|
|
55
|
-
versionName "1.0"
|
|
56
|
-
}
|
|
57
|
-
lintOptions {
|
|
58
|
-
abortOnError false
|
|
59
|
-
}
|
|
60
|
-
compileOptions {
|
|
61
|
-
sourceCompatibility JavaVersion.VERSION_1_8
|
|
62
|
-
targetCompatibility JavaVersion.VERSION_1_8
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// The full/real version of libturbomodulejsijni.so will be built and included in apps using React Native 0.64 or newer,
|
|
67
|
-
// so exclude Babylon React Native's minimal version of these libs in this case.
|
|
68
|
-
if (REACT_VERSION >= 64) {
|
|
69
|
-
android.packagingOptions.excludes += 'lib/armeabi-v7a/libturbomodulejsijni.so'
|
|
70
|
-
android.packagingOptions.excludes += 'lib/arm64-v8a/libturbomodulejsijni.so'
|
|
71
|
-
android.packagingOptions.excludes += 'lib/x86/libturbomodulejsijni.so'
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
repositories {
|
|
75
|
-
// ref: https://www.baeldung.com/maven-local-repository
|
|
76
|
-
mavenLocal()
|
|
77
|
-
maven {
|
|
78
|
-
// All of React Native (JS, Obj-C sources, Android binaries) is installed from npm
|
|
79
|
-
url "$rootDir/../node_modules/react-native/android"
|
|
80
|
-
}
|
|
81
|
-
maven {
|
|
82
|
-
// Android JSC is installed from npm
|
|
83
|
-
url "$rootDir/../node_modules/jsc-android/dist"
|
|
84
|
-
}
|
|
85
|
-
google()
|
|
86
|
-
jcenter()
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
dependencies {
|
|
90
|
-
//noinspection GradleDynamicVersion
|
|
91
|
-
implementation 'com.facebook.react:react-native:+' // From node_modules
|
|
92
|
-
implementation 'com.google.ar:core:1.22.0'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
def configureReactNativePom(def pom) {
|
|
96
|
-
def packageJson = new groovy.json.JsonSlurper().parseText(file('../package.json').text)
|
|
97
|
-
|
|
98
|
-
pom.project {
|
|
99
|
-
name packageJson.title
|
|
100
|
-
artifactId packageJson.name
|
|
101
|
-
version = packageJson.version
|
|
102
|
-
group = "com.babylonreactnative"
|
|
103
|
-
description packageJson.description
|
|
104
|
-
url packageJson.repository.baseUrl
|
|
105
|
-
|
|
106
|
-
licenses {
|
|
107
|
-
license {
|
|
108
|
-
name packageJson.license
|
|
109
|
-
url packageJson.repository.baseUrl + '/blob/master/' + packageJson.licenseFilename
|
|
110
|
-
distribution 'repo'
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
developers {
|
|
115
|
-
developer {
|
|
116
|
-
id packageJson.author.username
|
|
117
|
-
name packageJson.author.name
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
afterEvaluate { project ->
|
|
124
|
-
// some Gradle build hooks ref:
|
|
125
|
-
// https://www.oreilly.com/library/view/gradle-beyond-the/9781449373801/ch03.html
|
|
126
|
-
task androidJavadoc(type: Javadoc) {
|
|
127
|
-
source = android.sourceSets.main.java.srcDirs
|
|
128
|
-
classpath += files(android.bootClasspath)
|
|
129
|
-
classpath += files(project.getConfigurations().getByName('compile').asList())
|
|
130
|
-
include '**/*.java'
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
task androidJavadocJar(type: Jar, dependsOn: androidJavadoc) {
|
|
134
|
-
classifier = 'javadoc'
|
|
135
|
-
from androidJavadoc.destinationDir
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
task androidSourcesJar(type: Jar) {
|
|
139
|
-
classifier = 'sources'
|
|
140
|
-
from android.sourceSets.main.java.srcDirs
|
|
141
|
-
include '**/*.java'
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
android.libraryVariants.all { variant ->
|
|
145
|
-
def name = variant.name.capitalize()
|
|
146
|
-
def javaCompileTask = variant.javaCompileProvider.get()
|
|
147
|
-
|
|
148
|
-
task "jar${name}"(type: Jar, dependsOn: javaCompileTask) {
|
|
149
|
-
from javaCompileTask.destinationDir
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
artifacts {
|
|
154
|
-
archives androidSourcesJar
|
|
155
|
-
archives androidJavadocJar
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
task installArchives(type: Upload) {
|
|
159
|
-
configuration = configurations.archives
|
|
160
|
-
repositories.mavenDeployer {
|
|
161
|
-
// Deploy to react-native-event-bridge/maven, ready to publish to npm
|
|
162
|
-
repository url: "file://${projectDir}/../android/maven"
|
|
163
|
-
configureReactNativePom pom
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
task validateSdk {
|
|
169
|
-
def minSdkVersion = safeExtGet('minSdkVersion', DEFAULT_MIN_SDK_VERSION)
|
|
170
|
-
if (minSdkVersion < DEFAULT_MIN_SDK_VERSION) {
|
|
171
|
-
throw new GradleException("minSdkVersion must be at least ${DEFAULT_MIN_SDK_VERSION} but is currently ${minSdkVersion}")
|
|
172
|
-
}
|
|
173
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
package com.babylonreactnative;
|
|
2
|
-
|
|
3
|
-
import androidx.annotation.NonNull;
|
|
4
|
-
|
|
5
|
-
import com.facebook.react.bridge.Promise;
|
|
6
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
7
|
-
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|
8
|
-
import com.facebook.react.bridge.ReactMethod;
|
|
9
|
-
|
|
10
|
-
public final class BabylonModule extends ReactContextBaseJavaModule {
|
|
11
|
-
|
|
12
|
-
BabylonModule(ReactApplicationContext reactContext) {
|
|
13
|
-
super(reactContext);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
@NonNull
|
|
17
|
-
@Override
|
|
18
|
-
public String getName() {
|
|
19
|
-
return "BabylonModule";
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@ReactMethod
|
|
23
|
-
public void initialize(Promise promise) {
|
|
24
|
-
this.getReactApplicationContext().runOnJSQueueThread(() -> {
|
|
25
|
-
BabylonNativeInterop.initialize(this.getReactApplicationContext());
|
|
26
|
-
promise.resolve(null);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
@ReactMethod
|
|
31
|
-
public void resetView(Promise promise) {
|
|
32
|
-
this.getReactApplicationContext().runOnUiQueueThread(() -> {
|
|
33
|
-
BabylonNativeInterop.resetView();
|
|
34
|
-
promise.resolve(null);
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
}
|
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
package com.babylonreactnative;
|
|
2
|
-
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.content.Intent;
|
|
6
|
-
import android.view.MotionEvent;
|
|
7
|
-
import android.view.Surface;
|
|
8
|
-
|
|
9
|
-
import com.facebook.react.bridge.ActivityEventListener;
|
|
10
|
-
import com.facebook.react.bridge.LifecycleEventListener;
|
|
11
|
-
import com.facebook.react.bridge.ReactContext;
|
|
12
|
-
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
|
|
13
|
-
|
|
14
|
-
public final class BabylonNativeInterop {
|
|
15
|
-
|
|
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);
|
|
32
|
-
}
|
|
33
|
-
|
|
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);
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
BabylonNativeInterop.lifeCycleEventListener = new LifecycleEventListener() {
|
|
47
|
-
@Override
|
|
48
|
-
public void onHostResume() {
|
|
49
|
-
BabylonNative.setCurrentActivity(reactContext.getCurrentActivity());
|
|
50
|
-
BabylonNative.resume();
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Override
|
|
54
|
-
public void onHostPause() {
|
|
55
|
-
BabylonNative.pause();
|
|
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);
|
|
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);
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
public static void updateView(Surface surface) {
|
|
85
|
-
BabylonNative.updateView(surface);
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
public static void renderView() {
|
|
89
|
-
BabylonNative.renderView();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
public static void resetView() {
|
|
93
|
-
BabylonNative.resetView();
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
public static void updateXRView(Surface surface) {
|
|
97
|
-
BabylonNative.updateXRView(surface);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
public static boolean isXRActive() {
|
|
101
|
-
return BabylonNative.isXRActive();
|
|
102
|
-
}
|
|
103
|
-
|
|
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);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
package com.babylonreactnative;
|
|
2
|
-
|
|
3
|
-
import java.util.Arrays;
|
|
4
|
-
import java.util.List;
|
|
5
|
-
|
|
6
|
-
import com.facebook.react.ReactPackage;
|
|
7
|
-
import com.facebook.react.bridge.NativeModule;
|
|
8
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
9
|
-
import com.facebook.react.uimanager.ViewManager;
|
|
10
|
-
|
|
11
|
-
public class BabylonPackage implements ReactPackage {
|
|
12
|
-
@Override
|
|
13
|
-
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
|
|
14
|
-
return Arrays.<NativeModule>asList(new BabylonModule(reactContext));
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
@Override
|
|
18
|
-
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
19
|
-
return Arrays.<ViewManager>asList(new EngineViewManager());
|
|
20
|
-
}
|
|
21
|
-
}
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
package com.babylonreactnative;
|
|
2
|
-
|
|
3
|
-
import android.annotation.TargetApi;
|
|
4
|
-
import android.graphics.Bitmap;
|
|
5
|
-
import android.graphics.SurfaceTexture;
|
|
6
|
-
import android.os.Build;
|
|
7
|
-
import android.os.Handler;
|
|
8
|
-
import android.os.HandlerThread;
|
|
9
|
-
import android.util.Base64;
|
|
10
|
-
import android.view.MotionEvent;
|
|
11
|
-
import android.view.PixelCopy;
|
|
12
|
-
import android.view.Surface;
|
|
13
|
-
import android.view.SurfaceHolder;
|
|
14
|
-
import android.view.SurfaceView;
|
|
15
|
-
import android.view.TextureView;
|
|
16
|
-
import android.view.View;
|
|
17
|
-
import android.widget.FrameLayout;
|
|
18
|
-
|
|
19
|
-
import androidx.annotation.NonNull;
|
|
20
|
-
|
|
21
|
-
import com.facebook.react.bridge.ReactContext;
|
|
22
|
-
import com.facebook.react.uimanager.UIManagerModule;
|
|
23
|
-
import com.facebook.react.uimanager.events.EventDispatcher;
|
|
24
|
-
|
|
25
|
-
import java.io.ByteArrayOutputStream;
|
|
26
|
-
|
|
27
|
-
public final class EngineView extends FrameLayout implements SurfaceHolder.Callback, TextureView.SurfaceTextureListener, View.OnTouchListener {
|
|
28
|
-
private static final FrameLayout.LayoutParams childViewLayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
29
|
-
private TextureView transparentTextureView;
|
|
30
|
-
private Surface transparentSurface = null;
|
|
31
|
-
private SurfaceView opaqueSurfaceView = null;
|
|
32
|
-
private SurfaceView xrSurfaceView;
|
|
33
|
-
private final EventDispatcher reactEventDispatcher;
|
|
34
|
-
private Runnable renderRunnable;
|
|
35
|
-
|
|
36
|
-
public EngineView(ReactContext reactContext) {
|
|
37
|
-
super(reactContext);
|
|
38
|
-
|
|
39
|
-
this.setIsTransparent(false);
|
|
40
|
-
|
|
41
|
-
this.xrSurfaceView = new SurfaceView(reactContext);
|
|
42
|
-
this.xrSurfaceView.setLayoutParams(childViewLayoutParams);
|
|
43
|
-
this.xrSurfaceView.getHolder().addCallback(new SurfaceHolder.Callback() {
|
|
44
|
-
@Override
|
|
45
|
-
public void surfaceCreated(SurfaceHolder holder) {
|
|
46
|
-
// surfaceChanged is also called when the surface is created, so just do all the handling there
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
@Override
|
|
50
|
-
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
|
|
51
|
-
BabylonNativeInterop.updateXRView(holder.getSurface());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
@Override
|
|
55
|
-
public void surfaceDestroyed(SurfaceHolder holder) {
|
|
56
|
-
BabylonNativeInterop.updateXRView(null);
|
|
57
|
-
}
|
|
58
|
-
});
|
|
59
|
-
this.xrSurfaceView.setVisibility(View.INVISIBLE);
|
|
60
|
-
this.addView(this.xrSurfaceView);
|
|
61
|
-
|
|
62
|
-
this.setOnTouchListener(this);
|
|
63
|
-
|
|
64
|
-
this.reactEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
// ------------------------------------
|
|
68
|
-
// TextureView related
|
|
69
|
-
|
|
70
|
-
public void setIsTransparent(Boolean isTransparent) {
|
|
71
|
-
if (isTransparent) {
|
|
72
|
-
if (this.opaqueSurfaceView != null) {
|
|
73
|
-
this.opaqueSurfaceView.setVisibility(View.GONE);
|
|
74
|
-
this.opaqueSurfaceView = null;
|
|
75
|
-
}
|
|
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();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
@Override
|
|
107
|
-
public void surfaceChanged(SurfaceHolder surfaceHolder, int i, int width, int height) {
|
|
108
|
-
BabylonNativeInterop.updateView(surfaceHolder.getSurface());
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
@Override
|
|
112
|
-
public void surfaceDestroyed(SurfaceHolder surfaceHolder) {
|
|
113
|
-
this.removeCallbacks(this.renderRunnable);
|
|
114
|
-
this.renderRunnable = null;
|
|
115
|
-
}
|
|
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
|
-
|
|
154
|
-
@Override
|
|
155
|
-
public boolean onTouch(View view, MotionEvent motionEvent) {
|
|
156
|
-
BabylonNativeInterop.reportMotionEvent(motionEvent);
|
|
157
|
-
return true;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
@TargetApi(24)
|
|
161
|
-
public void takeSnapshot() {
|
|
162
|
-
// Only supported on API level 24 and up, return a blank image.
|
|
163
|
-
if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
|
|
164
|
-
SnapshotDataReturnedEvent snapshotEvent = new SnapshotDataReturnedEvent(this.getId(), "");
|
|
165
|
-
reactEventDispatcher.dispatchEvent(snapshotEvent);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
// Create a bitmap that matches the width and height of the EngineView.
|
|
169
|
-
final Bitmap bitmap = Bitmap.createBitmap(
|
|
170
|
-
getWidth(),
|
|
171
|
-
getHeight(),
|
|
172
|
-
Bitmap.Config.ARGB_8888);
|
|
173
|
-
|
|
174
|
-
// Offload the snapshot worker to a helper thread.
|
|
175
|
-
final HandlerThread helperThread = new HandlerThread("ScreenCapture",-1);
|
|
176
|
-
helperThread.start();
|
|
177
|
-
final Handler helperThreadHandler = new Handler(helperThread.getLooper());
|
|
178
|
-
|
|
179
|
-
Surface sourceSurface = this.transparentSurface;
|
|
180
|
-
if (BabylonNativeInterop.isXRActive()) {
|
|
181
|
-
sourceSurface = this.xrSurfaceView.getHolder().getSurface();
|
|
182
|
-
} else if (this.opaqueSurfaceView != null) {
|
|
183
|
-
sourceSurface = this.opaqueSurfaceView.getHolder().getSurface();
|
|
184
|
-
}
|
|
185
|
-
PixelCopy.request(sourceSurface, bitmap, getOnPixelCopyFinishedListener(bitmap, helperThread), helperThreadHandler);
|
|
186
|
-
}
|
|
187
|
-
|
|
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) -> {
|
|
193
|
-
// If the pixel copy was a success then convert the image to a base 64 encoded jpeg and fire the event.
|
|
194
|
-
String encoded = "";
|
|
195
|
-
if (copyResult == PixelCopy.SUCCESS) {
|
|
196
|
-
ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream();
|
|
197
|
-
bitmap.compress(Bitmap.CompressFormat.JPEG, 80, byteArrayStream);
|
|
198
|
-
byte[] byteArray = byteArrayStream.toByteArray();
|
|
199
|
-
bitmap.recycle();
|
|
200
|
-
encoded = Base64.encodeToString(byteArray, Base64.DEFAULT);
|
|
201
|
-
}
|
|
202
|
-
SnapshotDataReturnedEvent snapshotEvent = new SnapshotDataReturnedEvent(this.getId(), encoded);
|
|
203
|
-
reactEventDispatcher.dispatchEvent(snapshotEvent);
|
|
204
|
-
helperThread.quitSafely();
|
|
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;
|
|
229
|
-
}
|
|
230
|
-
}
|