Hello!!
We have a babylonjs app that requires swapping between the front and back camera.
We cant get it to work properly so asking here in case someone has encountered the same issues before and are able to help. Many thanks in advance.
We have a babylonjs scene, we load 8th wall library and initialise the camera with no issues.
When we want to do the camera swap we either have errors, or the 3d model dissapears.
We init the camera code like this
this.cameraBehavior = XR8().Babylonjs.xrCameraBehavior({
cameraConfig: { direction: XR8().XrConfig.camera().BACK },
});
this.camera.addBehavior(this.cameraBehavior, true);
We have this function for camera swap
private set8thWallCamera(facingMode: 'front' | 'back'): void {
if (facingMode === 'back') {
XR8().stop();
this.camera.removeBehavior(this.cameraBehavior);
XR8().XrController.configure({
disableWorldTracking: false,
mirroredDisplay: false,
});
XR8().FaceController.configure({
coordinates: {
mirroredDisplay: false,
},
});
this.cameraBehavior = XR8().Babylonjs.xrCameraBehavior({
cameraConfig: {
direction: XR8().XrConfig.camera().BACK,
},
});
this.camera.addBehavior(this.cameraBehavior);
XR8().run();
XR8().XrController.recenter();
} else {
XR8().stop();
this.camera.removeBehavior(this.cameraBehavior);
XR8().XrController.configure({
disableWorldTracking: true,
mirroredDisplay: true,
});
XR8().FaceController.configure({
coordinates: {
mirroredDisplay: true,
},
});
this.cameraBehavior = XR8().Babylonjs.xrCameraBehavior({
cameraConfig: {
direction: XR8().XrConfig.camera().FRONT,
},
});
this.camera.addBehavior(this.cameraBehavior);
XR8().run();
}
}
X8.run() errors with
ERROR TypeError: Cannot destructure property 'canvas' of 'undefined' as it is undefined.
So we changed the run function call to have these params
from this:
XR8().run();
to this:
XR8().run({ canvas: canvas, cameraConfig: { direction: XR8().XrConfig.camera().FRONT } });
This makes the errors go away.However, these two function calls donβt do the same. this seems to change the rendering order?
I cannot see my 3d model, I can only see the camera feed.
The 3d model seems to be rendering behind the camera feed? (I can see it when i do a screengrab)
Any suggestions? Dont know what we are doing wrong.
Many thanks in advance
Update: the code above, on a different device generates this error: