Skip to content

Commit 0572e64

Browse files
authored
Update to latest BabylonNative with tracking states exposed (#122)
Adding debug targets for VSCode and displaying the tracking state from BabylonNative in the Playground app
1 parent 50736ce commit 0572e64

File tree

6 files changed

+63
-6
lines changed

6 files changed

+63
-6
lines changed

.gitignore

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
#
33
.DS_Store
44

5-
# Visual Studio Code
6-
#
7-
.vscode
8-
95
# Android Studio
106
.project
117
.classpath

.vscode/extensions.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
// See http://go.microsoft.com/fwlink/?LinkId=827846
3+
// for the documentation about the extensions.json format
4+
"recommendations": [
5+
"msjsdiag.vscode-react-native",
6+
]
7+
}

.vscode/launch.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "Build & Debug Android",
9+
"cwd": "${workspaceFolder}/Apps/Playground",
10+
"type": "reactnativedirect",
11+
"request": "launch",
12+
"platform": "android"
13+
},
14+
{
15+
"name": "Build & Debug iOS on Device",
16+
"cwd": "${workspaceFolder}/Apps/Playground",
17+
"type": "reactnativedirect",
18+
"request": "launch",
19+
"platform": "ios",
20+
"port": 9221,
21+
"target": "device"
22+
},
23+
{
24+
"name": "Attach to Android",
25+
"cwd": "${workspaceFolder}/Apps/Playground",
26+
"type": "reactnativedirect",
27+
"request": "attach"
28+
},
29+
{
30+
"name": "Attach to iOS on Device",
31+
"cwd": "${workspaceFolder}/Apps/Playground",
32+
"type": "reactnativedirect",
33+
"request": "attach",
34+
"platform": "ios",
35+
"port": 9221
36+
},
37+
]
38+
}

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"react-native-tools.projectRoot": "./Apps/Playground"
3+
}

Apps/Playground/App.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import React, { useState, FunctionComponent, useEffect, useCallback } from 'reac
99
import { SafeAreaView, StatusBar, Button, View, Text, ViewProps, Image } from 'react-native';
1010

1111
import { EngineView, useEngine, EngineViewCallbacks } from '@babylonjs/react-native';
12-
import { Scene, Vector3, ArcRotateCamera, Camera, WebXRSessionManager, SceneLoader, TransformNode, DeviceSourceManager, DeviceType, DeviceSource, PointerInput } from '@babylonjs/core';
12+
import { Scene, Vector3, ArcRotateCamera, Camera, WebXRSessionManager, SceneLoader, TransformNode, DeviceSourceManager, DeviceType, DeviceSource, PointerInput, WebXRTrackingState } from '@babylonjs/core';
1313
import '@babylonjs/loaders';
1414
import Slider from '@react-native-community/slider';
1515

@@ -26,6 +26,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
2626
const [scale, setScale] = useState<number>(defaultScale);
2727
const [snapshotData, setSnapshotData] = useState<string>();
2828
const [engineViewCallbacks, setEngineViewCallbacks] = useState<EngineViewCallbacks>();
29+
const [trackingState, setTrackingState] = useState<WebXRTrackingState>();
2930

3031
useEffect(() => {
3132
if (engine) {
@@ -74,16 +75,27 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
7475
}
7576
}, [rootNode, scale]);
7677

78+
const trackingStateToString = (trackingState: WebXRTrackingState | undefined) : string => {
79+
return trackingState === undefined ? "" : WebXRTrackingState[trackingState];
80+
};
81+
7782
const onToggleXr = useCallback(() => {
7883
(async () => {
7984
if (xrSession) {
8085
await xrSession.exitXRAsync();
8186
setXrSession(undefined);
87+
setTrackingState(undefined);
8288
} else {
8389
if (rootNode !== undefined && scene !== undefined) {
8490
const xr = await scene.createDefaultXRExperienceAsync({ disableDefaultUI: true, disableTeleportation: true })
8591
const session = await xr.baseExperience.enterXRAsync("immersive-ar", "unbounded", xr.renderTarget);
8692
setXrSession(session);
93+
94+
setTrackingState(xr.baseExperience.camera.trackingState);
95+
xr.baseExperience.camera.onTrackingStateChanged.add((newTrackingState) => {
96+
setTrackingState(newTrackingState);
97+
});
98+
8799
// TODO: Figure out why getFrontPosition stopped working
88100
//box.position = (scene.activeCamera as TargetCamera).getFrontPosition(2);
89101
const cameraRay = scene.activeCamera!.getForwardRay(1);
@@ -119,6 +131,7 @@ const EngineScreen: FunctionComponent<ViewProps> = (props: ViewProps) => {
119131
}
120132
<EngineView style={props.style} camera={camera} onInitialized={onInitialized} />
121133
<Slider style={{position: 'absolute', minHeight: 50, margin: 10, left: 0, right: 0, bottom: 0}} minimumValue={0.2} maximumValue={2} value={defaultScale} onValueChange={setScale} />
134+
<Text style={{fontSize: 12, color: 'yellow', position: 'absolute', margin: 10}}>{trackingStateToString(trackingState)}</Text>
122135
</View>
123136
}
124137
{ toggleView &&

Apps/Playground/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ SPEC CHECKSUMS:
466466
React-jsi: b32a31da32e030f30bbf9a8d3a9c8325df9e793f
467467
React-jsiexecutor: 7ab9cdcdd18d57652fb041f8a147fe9658d4e00a
468468
React-jsinspector: 2e28bb487e42dda6c94dbfa0c648d1343767a0fb
469-
react-native-babylon: cbcec38c3e3d9fc1aee538508a1f751619bb335b
469+
react-native-babylon: 05685525bfa89aae82b2fccd0a56351e954df545
470470
react-native-slider: b34d943dc60deb96d952ba6b6b249aa8091e86da
471471
React-RCTActionSheet: 1702a1a85e550b5c36e2e03cb2bd3adea053de95
472472
React-RCTAnimation: ddda576010a878865a4eab83a78acd92176ef6a1

0 commit comments

Comments
 (0)