sceneview-android icon indicating copy to clipboard operation
sceneview-android copied to clipboard

OnGestureListener always receiving the same Node

Open dzivko1 opened this issue 1 year ago • 4 comments

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?

dzivko1 avatar Jan 24 '24 13:01 dzivko1

Do you happen to have any updates on this?

KvRae avatar Mar 05 '24 09:03 KvRae

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

dzivko1 avatar Mar 05 '24 14:03 dzivko1

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

KvRae avatar Mar 05 '24 16:03 KvRae

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.

grassydragon avatar Mar 08 '24 12:03 grassydragon

Fixed in v2.2.0

ThomasGorisse avatar May 29 '24 17:05 ThomasGorisse