From 3e07453b9e384e95c5ba80d84509811428a2da13 Mon Sep 17 00:00:00 2001 From: Ryan Tremblay Date: Wed, 3 Feb 2021 09:00:40 -0800 Subject: [PATCH 01/16] Add NativeCapture to init and test it --- Apps/Playground/App.tsx | 26 +++++++++++++++---- .../react-native/shared/BabylonNative.cpp | 3 +++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/Apps/Playground/App.tsx b/Apps/Playground/App.tsx index 12ad93df5..aa0b8ef95 100644 --- a/Apps/Playground/App.tsx +++ b/Apps/Playground/App.tsx @@ -13,9 +13,15 @@ import { Scene, Vector3, ArcRotateCamera, Camera, WebXRSessionManager, SceneLoad import '@babylonjs/loaders'; import Slider from '@react-native-community/slider'; +declare class NativeCapture { + public constructor(); + public addOnCaptureCallback(onCaptureCallback: (ext: any) => void): void; + public dispose(): void; +}; + const EngineScreen: FunctionComponent = (props: ViewProps) => { const defaultScale = 1; - const enableSnapshots = false; + const enableSnapshots = true; const engine = useEngine(); const [toggleView, setToggleView] = useState(false); @@ -27,6 +33,7 @@ const EngineScreen: FunctionComponent = (props: ViewProps) => { const [snapshotData, setSnapshotData] = useState(); const [engineViewCallbacks, setEngineViewCallbacks] = useState(); const [trackingState, setTrackingState] = useState(); + const [nativeCapture, setNativeCapture] = useState(); useEffect(() => { if (engine) { @@ -49,9 +56,9 @@ const EngineScreen: FunctionComponent = (props: ViewProps) => { rootNode.rotate(Vector3.Down(), (touchEvent.currentState - touchEvent.previousState) * 0.005); } } - }) + }); } - }) + }); const transformContainer = new TransformNode("Transform Container", scene); transformContainer.parent = rootNode; @@ -110,6 +117,15 @@ const EngineScreen: FunctionComponent = (props: ViewProps) => { setEngineViewCallbacks(engineViewCallbacks); }, [engine]); + const toggleCapture = useCallback(async () => { + if (nativeCapture) { + nativeCapture.dispose(); + setNativeCapture(undefined); + } else { + setNativeCapture(new NativeCapture()); + } + }, [nativeCapture]); + const onSnapshot = useCallback(async () => { if (engineViewCallbacks) { setSnapshotData("data:image/jpeg;base64," + await engineViewCallbacks.takeSnapshot()); @@ -125,11 +141,11 @@ const EngineScreen: FunctionComponent = (props: ViewProps) => { { enableSnapshots && -