SceneView / sceneform-android

Sceneform Maintained is an ARCore Android SDK with Google Filament as 3D engine. This is the continuation of the archived Sceneform
https://sceneview.github.io/sceneform-android/
Apache License 2.0
626 stars 146 forks source link

hitTest doesn't work #220

Closed agGitHub closed 2 years ago

agGitHub commented 2 years ago

Hi,

In the following sample:

https://github.com/SceneView/sceneform-android/blob/master/samples/3d-model-viewer/src/main/java/com/google/ar/sceneform/samples/sceneviewbackground/MainActivity.java (3D viewer without ARCore)

I removed the backgroundSceneView in order to keep only the transparentSceneView in full screen.

Then, I do (in a onFrameUpdate loop):

Scene scene = transparentSceneView.getScene();
Camera camera = scene.getCamera();
Ray ray0 = camera.screenPointToRay(halfScreenWidth, halfScreenHeight); 
 ArrayList<HitTestResult> list =  scene.hitTestAll(ray0);

ray0 equals: [Origin:[x=0.0, y=4.543066E-6, z=-0.01], Direction:[x=0.0, y=4.5430654E-4, z=-0.9999999]] => seems correct

hitTestAll gives the following point: [x=0.0, y=4.543066E-6, z=-0.01] => seems not correct as the model backdrop.glb is located at position (0,0,-1).

Is there any bug with hitTest? Or am I missing something?

Thanks.

ThomasGorisse commented 2 years ago

The HitTest in a 3D only context will return something only if it hit something (a Node). What are you trying to achieve?

ThomasGorisse commented 2 years ago

Sorry. I didn't read your question fully. I will have a look at it since it's one of the next goal for SceneView. You should give a try to Filament Pick API which you should be able to use within Sceneform and which will replace 3D (non AR) actual hitTest in SceneView

ThomasGorisse commented 2 years ago

While speaking about hitTest, just to let you and others know, in SceneView, we have made the choice to use the ARCore depth hitTest instead of the DepthLab way: own hitTest system based on the Depth Image. So the Filament Pick API will be the only one available for 3D only usage.

@agGitHub Please let us know your results if you give a try with the Filament Pick API and link question you could ask them here.

agGitHub commented 2 years ago

Thanks for your answers. Actually, it seems that the problem was due to the backdrop.glb model. For some reasons, it doesn't respond to raycast/hittest. Perhaps because it seems to have no texture or a transparent texture (it is covered with the typical 'checkerboard' texture of the 'alpha color'). Or perhaps another bug on this glb model. I imported a GLTF model and it works. Will tell you if I have new info.

agGitHub commented 2 years ago

I confirm that it is a bug due to backdrop.glb (probably because it has a kind of transparent texture), not due to the glb format. Indeed, I just tested hittest with the other glb model present in your sample (dragon.glb) ; it has a texture, and it receives hittests correctly.