BabylonReactNative - How to get AR camera to focus

I was wondering how I can get the camera (the real world one) in react native AR to focus, things that are far away seem in focus, but closer stuff stays blurry.

Any ideas?


Adding @ryantrem

As far as I know, there are no ARCore/ARKit apis that give control of focus, but rather they auto-focus under the hood. Babylon Native definitely does not have any code that tries to interact with focus. What device are you using? Do you have the same issue in other AR apps (e.g. AR measurement apps for example)?

1 Like

So I previously worked with Viro which has an autofocus attribute (ViroARSceneNavigator).
Looking at how they implemented that I found:
Config.FocusMode  |  ARCore  |  Google Developers

It seems like ARCore puts it to fixed automatically, if you want autofocus you have to specifically set it.

Should I make a request in the Babylon Native Github?

Interesting, I wasn’t aware of that. The doc you referenced says:

For optimal AR tracking performance, use the focus mode provided by the default session config. While capturing pictures or video, use AUTO . For optimal AR tracking, revert to the default focus mode once auto focus behavior is no longer needed.

So it sounds like what we are already doing is what is supposed to be done for “optimal AR tracking performance.” What is your scenario where you want to change the behavior?

1 Like

I’ve got my QR code solution working, even with this blurry focus, but I’m sure that it would work a whole lot better with better focus.
I also find myself wanting it to focus when looking at an AR object on my desk, with every other camera thing autofocussing you kind of expect it to do that.

I can imagine this not being a problem when you’re viewing a life sized car or something, but as soon as you’re working with small objects on desks (like viewing 3D objects on top of a magazine as an ad for example) it shows when the background is out of focus. It takes away from the experience.

Also with Viro I never noticed a performance penalty when setting it to autofocus. At least having the option somewhere would be amazing!

I see, thanks for those details! I think the challenge here will be that Babylon’s XR support has abstractions to help make the same code work across mobile/HMD (iOS, Android, Windows) and browsers (WebXR), so for the most part the current functionality is the common subset between all these platforms, and I’m not sure whether focus is supported in these other platforms. If not, we do have some other cases where we have options that are more like preferredFocusMode, where the idea is that the API consumer can indicate their preference and we respect it if it is supported on the current platform (but we don’t guarantee it since it might not be supported on a given platform, hence the “preferred” prefix). But I guess first thing would be to see if ARKit and WebXR support focus options. If you could help research that and create an issue on GitHub it would certainly help! :slight_smile:

1 Like

I’ll get on that! Which Github repo should I do this for? Native or ReactNative?

Thanks for looking into this, I’m honestly having a great time getting to know Babylon and the ReactNative implementation. :smiley:

Found the option in ARKit! Apple Developer Documentation but they enable autofocus by default.

1 Like

BabylonNative is probably the right repo for this issue since I don’t think it is specific to React Native.

1 Like