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

Tap event is called multiple times and outside the node area

Open JeromeCHA opened this issue 1 year ago • 2 comments

Currently, with the version 2.2.0, I am facing the issue where hitTest result is returned even if we tapped outside the node.

The behavior can be reproduced with the following simple code.

val engine = rememberEngine()
val modelLoader = rememberModelLoader(engine)
val testNode = SphereNode(
    engine = engine,
    radius = 1f,
).apply {
    position = Position(z = -5f)
}
Scene(
    modifier = Modifier.fillMaxSize(),
    engine = engine,
    modelLoader = modelLoader,
    childNodes = rememberNodes {
        add(testNode)
    },
    onTouchEvent = { _, result ->
        // check if the tapped node is our testNode
        if (result?.node == testNode) {
            Toast.makeText(this, "Tapped on the node", Toast.LENGTH_SHORT).show()
        }
        false
    }
)

or with the gesture listener

onGestureListener = rememberOnGestureListener(
    onSingleTapConfirmed = { _, node ->
        if (node == testNode) {
            Toast.makeText(this, "Tapped on the node", Toast.LENGTH_SHORT)
                .show()
        }
    }
),

Here is the result

tap_bug

Is there something I am doing wrong? or anything I can do to avoid this?

Edit : Still occurs in 2.2.1

JeromeCHA avatar Jun 11 '24 02:06 JeromeCHA

This is not a solution, but an idea why it happens. My guess is that the SphereNode is using a bounding box for the collision test.

SceneView_SphereNode_Issue

A quick rundown revealed, that a box must be used:

  • https://github.com/SceneView/sceneview-android/blob/main/sceneview/src/main/java/io/github/sceneview/node/SphereNode.kt#L36
  • https://github.com/SceneView/sceneview-android/blob/main/sceneview/src/main/java/io/github/sceneview/geometries/Sphere.kt#L51
  • https://github.com/SceneView/sceneview-android/blob/main/sceneview/src/main/java/io/github/sceneview/geometries/Geometry.kt#L212

In the collision package there is a class called Sphere.java. Probably a remnant of SceneForm, but you can give it a try.

RGregat avatar Jun 11 '24 12:06 RGregat

@RGregat Ohh I see, thank you for the explanation. I hope it can be fixed 🤔 For a SphereNode, I guess you can check if the tap is outside the sphere area, but for some models (using ModelNode for example) it will be tough to avoid that behavior

Shape Result
T

JeromeCHA avatar Jun 12 '24 01:06 JeromeCHA

Hey there, it looks like there has been no activity on this issue recently. Has the issue been fixed, or does it still require the community's attention? This issue may be closed if no further activity occurs. Thank you for your contributions.

github-actions[bot] avatar Sep 10 '24 05:09 github-actions[bot]

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please feel free to create a new issue with up-to-date information.

github-actions[bot] avatar Sep 18 '24 05:09 github-actions[bot]