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
816 stars 159 forks source link

Get child renderable node by onSingleTap #410

Closed vicgcode closed 7 months ago

vicgcode commented 7 months ago

Hello!

I use ArSceneView 2.0.3. I have a model that contains almost twenty child nodes. I try to get a child node when user tap on the scene, but onSingleTapUp and onSingleTapConfirmed callbacks return a parent node that contains all existing child nodes, but I don;t know how to find selected child node. How to get selected/tapped child node?

My code:

override fun onSingleTapUp(e: MotionEvent, node: Node?) {
            Log.e("oops", "onSingleTapUp")
            if (node != null) {
                val nodes = node.childNodes
                val renderableNodes = nodes.mapNotNull {
                    it as? ModelNode.RenderableNode
                }
                // here all child nodes, but I need selected one
                renderableNodes.forEach {
                    Log.e("oops", "${it.name}")
                }
            }
        }

Also I tried to use Compose, but it returns the same - all child nodes instead the one that tapped by user.

onGestureListener = rememberOnGestureListener(
                            onSingleTapConfirmed = { motionEvent, node ->
                                if (node != null) {
                                    val nodes = node.childNodes
                                    val renderableNodes = nodes.mapNotNull {
                                        it as? ModelNode.RenderableNode
                                    }
                                    val entity = node.entity
                                    val name = (node as? ModelNode.RenderableNode)?.name
                                    renderableNodes.forEach {
                                        Log.e("oops", "child name = ${it.name}")
                                    }

@ThomasGorisse @grassydragon

and All members

grassydragon commented 7 months ago

Hi! Long story short, after trying another picking method, we've returned to the original one that uses the bounding box of a model. And while the child nodes are extracted from the model, the collision shapes aren't created for them. I've wanted to see if it's even possible to do so but have forgotten about it.

vicgcode commented 7 months ago

Thank you for the answer @grassydragon! Is there an any version of SceneView in which picking works with child nodes?

grassydragon commented 7 months ago

I think you should try a version before this release: https://github.com/SceneView/sceneview-android/releases/tag/v1.2.0