google / filament

Filament is a real-time physically based rendering engine for Android, iOS, Windows, Linux, macOS, and WebGL2
https://google.github.io/filament/
Apache License 2.0
17.87k stars 1.9k forks source link

How to implement ModelViewer Scene click listener to get clicked Entity? #7744

Closed amit-iottive closed 7 months ago

amit-iottive commented 7 months ago

Hi

Currently I am working on sample-gltf-viewer repo. I have used SingleTapListener but on click of model every time I get same entity name.

inner class SingleTapListener : GestureDetector.SimpleOnGestureListener() {

   override fun onSingleTapUp(event: MotionEvent): Boolean 
   {
    modelViewer.view.pick(
        event.x.toInt(),
        surfaceView.height - event.y.toInt(),
        surfaceView.handler, {
            val name = modelViewer.asset!!.getName(it.renderable)
            Log.v("Filament", "Picked ${it.renderable}: " + name)
        },
    )
    return super.onSingleTapUp(event)
}

}

I have tried to get entity info by foreach loop and I am able to fetch all entity info.

modelViewer.scene.forEach() { Log.e("Filament","Entity>>>"+it.toString()+" Name>>>"+ modelViewer.asset!!.getName(it)) }

Is there any way to implement modelViewer.scene click listener?

OS: Android

I have attached Gltf model screenshot for your reference.

Screenshot_20240408_114614

poweifeng commented 7 months ago

Let's use the duplication discussion for follow-up: https://github.com/google/filament/discussions/7745