RealityKit: "annotating" an object

Hello,

I want to be able to tap on a previously-placed ModelEntity box and add a dot or a text at that location on the box (kind of like I'm adding an annotation on the box)

I have something like this, but not sure how I should do it correctly:

class MyARView: ARView {
// ...
    private func didTap(_ gestureRecognizer: UITapGestureRecognizer) {
        let pos = gestureRecognizer.location(in: self)
        
        if !didPlaceCube {
            placeCube(pos)
            return
        }
        
        let hitTestResult = self.hitTest(pos)
        
        guard let firstResult = hitTestResult.first else { return}
        
        let entity = firstResult.entity
        
        let textEntity = ModelEntity(mesh: .generateText("Hello there", extrusionDepth: 0.4, font: .boldSystemFont(ofSize: 0.05), containerFrame: .zero, alignment: .center, lineBreakMode: .byWordWrapping))
        
        textEntity.setPosition(entity.position + firstResult.position, relativeTo: entity)
        entity.addChild(textEntity)
        
     }
// ...
}
RealityKit: "annotating" an object
 
 
Q