Skip to content

Commit

Permalink
Add NativeCapture (#156)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryantrem authored Feb 11, 2021
1 parent 69203e7 commit dcf25ec
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
<!-- Libraries built from repo will be autolinked -->
<AdditionalDependencies Condition="Exists('$(BabylonReactNativeDir)\submodules\BabylonNative')">WindowsApp.lib;%(AdditionalDependencies);</AdditionalDependencies>
<!-- Libraries built from npm package need to be declared-->
<AdditionalDependencies Condition="Exists('$(ProjectDir)..\libs')">arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGend.lib;glslangd.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependentd.lib;napi.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompilerd.lib;openxr_loader.lib;OSDependentd.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRVd.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies);</AdditionalDependencies>
<AdditionalDependencies Condition="Exists('$(ProjectDir)..\libs')">arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGend.lib;glslangd.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependentd.lib;napi.lib;NativeCapture.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompilerd.lib;openxr_loader.lib;OSDependentd.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRVd.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies);</AdditionalDependencies>
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
<!-- Library directories when building in repo -->
<AdditionalLibraryDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64' And Exists('$(BabylonReactNativeDir)\submodules\BabylonNative')">$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\bgfx.cmake\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\napi\napi-jsi\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\jsi\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\JsRuntime\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\Graphics\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeInput\Debug;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Debug;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Expand Down Expand Up @@ -157,7 +157,7 @@
<!-- Libraries built from repo will be autolinked -->
<AdditionalDependencies Condition="Exists('$(BabylonReactNativeDir)\submodules\BabylonNative')">WindowsApp.lib;%(AdditionalDependencies)"</AdditionalDependencies>
<!-- Libraries built from npm package need to be declared-->
<AdditionalDependencies Condition="Exists('$(ProjectDir)..\libs')">arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGen.lib;glslang.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependent.lib;napi.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompiler.lib;openxr_loader.lib;OSDependent.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRV.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies);</AdditionalDependencies>
<AdditionalDependencies Condition="Exists('$(ProjectDir)..\libs')">arcana.lib;astc.lib;astc-codec.lib;BabylonNative.lib;bgfx.lib;bimg.lib;bx.lib;edtaa3.lib;etc1.lib;etc2.lib;GenericCodeGen.lib;glslang.lib;Graphics.lib;iqa.lib;jsi.lib;JsRuntime.lib;MachineIndependent.lib;napi.lib;NativeCapture.lib;NativeEngine.lib;NativeInput.lib;NativeXr.lib;nvtt.lib;OGLCompiler.lib;openxr_loader.lib;OSDependent.lib;pvrtc.lib;spirv-cross-core.lib;spirv-cross-glsl.lib;spirv-cross-hlsl.lib;SPIRV.lib;squish.lib;UrlLib.lib;Window.lib;XMLHttpRequest.lib;xr.lib;WindowsApp.lib;%(AdditionalDependencies);</AdditionalDependencies>
<AdditionalOptions>%(AdditionalOptions)</AdditionalOptions>
<!-- Library directories when building in repo -->
<AdditionalLibraryDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64' And Exists('$(BabylonReactNativeDir)\submodules\BabylonNative')">$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\bgfx.cmake\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Dependencies\napi\napi-jsi\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\jsi\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\JsRuntime\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Core\Graphics\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeInput\Release;$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Release;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Expand Down Expand Up @@ -289,6 +289,9 @@
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\jsi\jsi.vcxproj">
<Project>{bddbd49e-873f-33e4-a99d-9d8e77b16433}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeCapture\NativeCapture.vcxproj">
<Project>{20eb2920-32bc-4aa6-9ba0-969a25d6bdb9}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x64\Plugins\NativeEngine\NativeEngine.vcxproj">
<Project>{2c18692b-80ea-335e-a473-15a19374ace0}</Project>
</ProjectReference>
Expand Down Expand Up @@ -397,6 +400,9 @@
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm64\jsi\jsi.vcxproj">
<Project>{0897d738-8022-3a3d-95b8-2b4ff7f8365e}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm64\Plugins\NativeCapture\NativeCapture.vcxproj">
<Project>{47771cab-ac3b-4673-b77e-af13a702993a}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm64\Plugins\NativeEngine\NativeEngine.vcxproj">
<Project>{d582c0e4-9a19-3024-8039-2f8ee50bc8de}</Project>
</ProjectReference>
Expand Down Expand Up @@ -505,6 +511,9 @@
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x86\jsi\jsi.vcxproj">
<Project>{1b2a5e60-84f3-34c9-9318-5cf2ac668433}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x86\Plugins\NativeCapture\NativeCapture.vcxproj">
<Project>{12221f10-00b8-45b6-8b56-c9b42bb54c6f}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_x86\Plugins\NativeEngine\NativeEngine.vcxproj">
<Project>{b9a708f6-9986-3270-b7b4-a3674ffa0053}</Project>
</ProjectReference>
Expand Down Expand Up @@ -613,6 +622,9 @@
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm\jsi\jsi.vcxproj">
<Project>{93d05ba2-59b9-3592-ab31-c441fb3d7989}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm\Plugins\NativeCapture\NativeCapture.vcxproj">
<Project>{21595e71-26ec-4dd4-85e3-59208622c21d}</Project>
</ProjectReference>
<ProjectReference Include="$(BabylonReactNativeDir)\submodules\BabylonNative\Build_uwp_arm\Plugins\NativeEngine\NativeEngine.vcxproj">
<Project>{4c5576a1-09a2-3815-8402-1fdc77ecdaf4}</Project>
</ProjectReference>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ target_link_libraries(BabylonNative
Graphics
jsi
JsRuntime
NativeCapture
NativeEngine
NativeInput
NativeXr
Expand Down
30 changes: 30 additions & 0 deletions Modules/@babylonjs/react-native/NativeCapture.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export type CapturedFrame = {
width: number;
height: number;
pitch: number;
format: "BGRA8" | undefined;
yFlip: boolean;
data: ArrayBuffer;
};

export type CaptureCallback = (capture: CapturedFrame) => void;

declare class NativeCapture {
public constructor();
public addCallback(onCaptureCallback: CaptureCallback): void;
public dispose(): void;
};

export class CaptureSession {
private readonly nativeCapture: NativeCapture;

public constructor(onCaptureCallback: CaptureCallback) {
console.warn(`CaptureSession is experimental and likely to change significantly.`);
this.nativeCapture = new NativeCapture();
this.nativeCapture.addCallback(onCaptureCallback);
}

public dispose(): void {
this.nativeCapture.dispose();
}
}
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/android/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ target_link_libraries(BabylonNative
AndroidExtensions
Graphics
JsRuntime
NativeCapture
NativeEngine
NativeInput
NativeXr
Expand Down
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './EngineView';
export * from './EngineHook';
export * from './NativeCapture';
1 change: 1 addition & 0 deletions Modules/@babylonjs/react-native/ios/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ target_link_libraries(BabylonNative
jsi
reactnative
JsRuntime
NativeCapture
NativeEngine
NativeInput
NativeXr
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ Pod::Spec.new do |s|
'OSDependent',
'MachineIndependent',
'napi',
'NativeCapture',
'NativeEngine',
'NativeInput',
'NativeXR',
Expand Down
4 changes: 3 additions & 1 deletion Modules/@babylonjs/react-native/shared/BabylonNative.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <Babylon/Graphics.h>
#include <Babylon/JsRuntime.h>
#include <Babylon/Plugins/NativeCapture.h>
#include <Babylon/Plugins/NativeEngine.h>
#include <Babylon/Plugins/NativeInput.h>
#include <Babylon/Plugins/NativeXr.h>
Expand Down Expand Up @@ -52,7 +53,8 @@ namespace Babylon

// Initialize Babylon Native plugins
Plugins::NativeXr::Initialize(m_env);
m_nativeInput = &Babylon::Plugins::NativeInput::CreateForJavaScript(m_env);
Plugins::NativeCapture::Initialize(m_env);
m_nativeInput = &Plugins::NativeInput::CreateForJavaScript(m_env);

// Initialize Babylon Native polyfills
Polyfills::Window::Initialize(m_env);
Expand Down
2 changes: 2 additions & 0 deletions Package/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ Assembled/ios/libs/libOGLCompiler.a
Assembled/ios/libs/libastc.a
Assembled/ios/libs/libNativeEngine.a
Assembled/ios/libs/libNativeXr.a
Assembled/ios/libs/libNativeCapture.a
Assembled/ios/libs/libspirv-cross-glsl.a
Assembled/ios/libs/libNativeInput.a
Assembled/ios/libs/libJsRuntime.a
Expand Down Expand Up @@ -297,6 +298,7 @@ Assembled/android/src/main/jniLibs/arm64-v8a
Assembled/android/src/main/jniLibs/arm64-v8a/libturbomodulejsijni.so
Assembled/android/src/main/jniLibs/arm64-v8a/libBabylonNative.so
Assembled/react-native-babylon.podspec
Assembled/NativeCapture.ts
Assembled/index.ts
Assembled/VersionValidation.ts
Assembled/BabylonModule.ts
Expand Down
1 change: 1 addition & 0 deletions Package/iOS/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ set(PACKAGED_LIBS
OSDependent
MachineIndependent
napi
NativeCapture
NativeEngine
NativeInput
NativeXr
Expand Down

0 comments on commit dcf25ec

Please sign in to comment.