Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
JeromeCHA opened this issue Jun 11, 2024 · 2 comments
Open

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

JeromeCHA opened this issue Jun 11, 2024 · 2 comments

Comments

@JeromeCHA
Copy link

JeromeCHA commented Jun 11, 2024

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 JeromeCHA changed the title HitTest is called multiple times and outside the node area Tap event is called multiple times and outside the node area Jun 11, 2024
@RGregat
Copy link
Contributor

RGregat commented Jun 11, 2024

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
Copy link
Author

JeromeCHA commented Jun 12, 2024

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants