SceneView / sceneview-android

SceneView is a 3D and AR Android Composable and View with Google Filament and ARCore. This is a Sceneform replacement in Kotlin
Apache License 2.0
816 stars 159 forks source link

OnGestureListener always receiving the same Node #400

Closed dzivko1 closed 4 months ago

dzivko1 commented 8 months ago

I'm trying to detect when a certain model is tapped in a 3D model viewer. I'm using OnGestureListener.onSingleTapUp to detect taps. The taps are detected, but the Node I receive in the callback is always the first node that is added to childNodes, no matter where I tap on the screen and no matter the camera orientation.

Here is a reproducible example of what I mean.

@Composable
fun SceneViewTest() {
  val engine = rememberEngine()
  val modelLoader = rememberModelLoader(engine)
  var c by remember { mutableIntStateOf(0) }
  Scene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,
    modelLoader = modelLoader,
    childNodes = rememberNodes {
      add(ModelNode(modelLoader.createModelInstance("sofa.glb")).apply {
        position = Position(z = -4.0f)
        scale = Scale(0.25f)
      })
      add(ModelNode(modelLoader.createModelInstance("bulb.glb")).apply {
        position = Position(x = 0.5f, z = -4.0f)
        scale = Scale(0.01f)
      })
    },
    onGestureListener = rememberOnGestureListener(
      onSingleTapUp = { _, node ->
        // node is always the first added node, in this case "sofa.glb"
        node?.scale = Scale(if (c++ % 2 == 0) 0.5f else 0.25f)
      }
    )
  )
}

I would expect the received node to be the one that is tapped. Am I missing something? How can I know which node was tapped on the screen?

KvRae commented 7 months ago

Do you happen to have any updates on this?

dzivko1 commented 7 months ago

Sadly, no. I put this on pause since I couldn't find a solution.

KvRae commented 7 months ago

I spoke with @grassydragon on Discord recently and he said that he will try to reproduce it

grassydragon commented 6 months ago

It looks like the bounding box of a Node isn't updated inside the collision system with respect to its position, rotation and scale. I think I'll need some time to work on this issue.

ThomasGorisse commented 4 months ago

Fixed in v2.2.0