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
849 stars 161 forks source link

Tap event is called multiple times and outside the node area #522

Closed JeromeCHA closed 2 months ago

JeromeCHA commented 5 months ago

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

RGregat commented 5 months ago

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:

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

JeromeCHA commented 5 months ago

@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
github-actions[bot] commented 2 months ago

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] commented 2 months ago

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.