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

How to show a Label(or text ) over Node #572

Open mudasirmukhtar-abyte opened 1 month ago

mudasirmukhtar-abyte commented 1 month ago

I need to display labels or text annotations above specific nodes. I've successfully added child nodes to my AnchorNode, but I'm unable to find a straightforward way to attach labels to these nodes.

fun addChildNodeToAnchor(parentNode: Node, position: Position) { Node(binding.arSceneView.engine).apply { isEditable = false name = "child node" lifecycleScope.launch { withContext(Dispatchers.Main) { val modelNode = buildModelNode("child", position, "myModel.glb", 0.25f) modelNode?.let { addChildNode(it) it.position = Position(x = position[0], y = position[1], z = position[2]) } parent = parentNode } } } }

fun buildModelNode(
    nodeName: String,
    position: Position,
    modelToLoad: String,
    scaleToUnits: Float
): ModelNode? {
    binding.arSceneView.modelLoader.loadModelInstance(
        modelToLoad
    )?.let { modelInstance ->
        return ModelNode(
            modelInstance = modelInstance,
            autoAnimate = false,
            scaleToUnits = scaleToUnits,
            centerOrigin = position
        ).apply {
            name = nodeName
            isEditable = true
        }
    }
    return null
}

`