Skip to content

OnGestureListener always receiving the same Node #400

@dzivko1

Description

@dzivko1

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?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions