viromedia / virocore

ViroCore cross-platform AR/VR renderer
MIT License
364 stars 108 forks source link

[QUESTION] Display camera preview as a background texture below a ViroViewScene #282

Open jpsarda opened 5 years ago

jpsarda commented 5 years ago

I want to make a very simple AR app, I don't need ARCore for it, and I couldn't use ARCore anyway becuase of the very small ratio of supported devices right now.

So my idea was to use Sceneform or Virocore. I know Sceneform can do it ( https://github.com/google-ar/sceneform-android-sdk/issues/274#issuecomment-419589970 ), but Sceneform requires android 7.0, which is better than ARCore minimum requirements, but not enough supported devices for my project.

So I know Viracore can be sued without ARCore with the ViroViewScene and the virocore-helloworld-scene example. But is there a way to display a background texture and render the camera preview on this texture ? Or add the ViroViewScene over an android view that takes care of the camera preview rendering ?

Thanks for your help.

dam00n commented 5 years ago

This is not something we have tried (or seen someone try using virocore) so we can not definitively say it is supported.

jpsarda commented 5 years ago

What about displaying a fixed background image, would it be possible (weither it is in the 2D scene or in an android imageview below the ViroViewScene) ?

dthian commented 5 years ago

If you are thinking of the background image in the 3d world, it should be possible to display your own image as the background in the scene.

Else, if you are thinking of a flat camera Android view behind the ViroViewScene, that should also be possible, as you can set the background color of the renderer so that you can see through it into the camera view.

jpsarda commented 5 years ago

So what I'm looking to achieve seems possible ? The second solution (flat camera android view) seems the easiest so I'll try with this one. My only concern is that the camera preview android view will be a open gl view, and I hope it's not a problem for the ViroViewScene which is an opengl view too I suppose.

Regarding the first solution, we use a viro Texture with this method scene.setBackgroundTexture(texture);. Camera preview in android can be captured as a SurfaceTexture (example here https://stackoverflow.com/a/12457895/612912 ). Do you know a way to transfer the content of the SurfaceTexture into a viro Texture ?

dthian commented 5 years ago

So what I'm looking to achieve seems possible ?

Again, as @dam00n has mentioned:

This is not something we have tried (or seen someone try using virocore) so we can not definitively say it is supported.

To your second question - none that i know of the top of my head. But probably not, as these textures are meant for setting images and videos, not transferring data or referencing from underlying gl textures / gl surfaces / gl views.

jpsarda commented 5 years ago

Apparently it works. I displayed a camera preview view below the ViroViewScene, and both views are showing. I extracted the camera preview code from this sample https://github.com/googlesamples/android-Camera2Basic

[edit] Well it works on my oneplus 6T android 9.X but not on my samsung S5 neo android 6.0.1

JooHyun-plask commented 3 years ago

Apparently it works. I displayed a camera preview view below the ViroViewScene, and both views are showing. I extracted the camera preview code from this sample https://github.com/googlesamples/android-Camera2Basic

[edit] Well it works on my oneplus 6T android 9.X but not on my samsung S5 neo android 6.0.1

hi jpsarda i developing show 3d model use viroviewscene but i faced blackscreen can you tell me tip about load & display viroviewscene??

i referenced https://github.com/viromedia/virocore/issues/43 this code