google-ar / sceneform-android-sdk

Sceneform SDK for Android
https://developers.google.com/sceneform/develop/
Apache License 2.0
1.23k stars 604 forks source link

Sceneform non ARCore mode, how to display an texture/image in background ? #678

Closed jpsarda closed 5 years ago

jpsarda commented 5 years ago

I'm trying to display camera preview as ExternalTexture below a 3D scene. I've looked into this issue https://github.com/google-ar/sceneform-android-sdk/issues/274 but I can't make it work.

I thought I would start by a less ambitious project, just displaying a fixed background image below the scene. Is there an example somewhere to help me do this ?

[edit] closing the issue because I managed to display the camera preview from the chromkey video example.

amarkovits commented 5 years ago

could you provide the code?

jpsarda commented 5 years ago

I would share, but it's a something I did for a contract, so I'm probably not authorized to share the code. Anyway, I can give you some hints. I used the chromkey video example as a base. So download the sample, and execute it. Now you know how to work with ExternalTexture. Then you have to modify the .obj file like it's said in this comment https://github.com/google-ar/sceneform-android-sdk/issues/274#issuecomment-419589970 to mak the texture fullscreen instead of in AR mode. Run the example, if the lion video is full screen, it's OK.

Then instead you need to get rid of the ARCore fragment, and replace if with an alternative fragment that will only feature a SceneView to get rid of the AR part. You will find such a fragment in this project : https://github.com/claywilkinson/poly-sample-android/tree/master/PolySampleARCore Her is the file : https://github.com/claywilkinson/poly-sample-android/blob/master/PolySampleARCore/app/src/main/java/com/google/ar/sample/polygallery/SceneformFragment.java

You can run the project you shouldn't see camera preview anymore, only the lion video fullscreen, that means you got rid of AR part.

Now, instead of rendring the video into the ExternalTexture, you need to render the camera preview. I I extracted the camera preview code from this example : https://github.com/googlesamples/android-Camera2Basic At some point the camera preview needs a SurfaceTexture to render, and you use the SurfaceTexture provided by the ExternalTexture.

amarkovits commented 5 years ago

and how do you add the new node with the camera surface? Node node = new Node(); node.setParent(scene); node.setRenderable(cameraRenderable); is not showing anything

renjithkn commented 4 years ago

Hi, It would be a great help if anyone can share sample code of this.