sceneview-android
sceneview-android copied to clipboard
OnGestureListener always receiving the same Node
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?
Do you happen to have any updates on this?
Sadly, no. I put this on pause since I couldn't find a solution.
I spoke with @grassydragon on Discord recently and he said that he will try to reproduce it
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.
Fixed in v2.2.0