1

I am exploring lidar and its feature in ARKit. I am thinking of raycast position(x,y) on the lidar mesh. That means I want to put an anchor on the lidar mesh for the raycasted position. The goal is to keep anchor objects sticky and accurate on surface/mesh. Below image gives better understanding

enter image description here

How to get Mesh position instead of default ARWorld position in raycast. That means, How to put anchor or box upon specific position of mesh/ARMeshAnchor?

Andy Jazz
  • 49,178
  • 17
  • 136
  • 220
indrajit
  • 303
  • 1
  • 14
  • What's your question? – Andy Jazz Jul 15 '21 at 08:50
  • @AndyFedoroff On mesh/using lidar, I want to put anchor at tapped/raycasted position. another way I can say, How to raycast mesh position using the center point of screen – indrajit Jul 15 '21 at 09:33
  • If we raycast in ARKit, We get a position in the context of the plane, I want to check if there is mesh data available then put the anchor on it instead of raycasted position. – indrajit Jul 15 '21 at 09:37
  • For better result ask just one question per post.))) Insert the first question into this post and second question into another one. – Andy Jazz Jul 15 '21 at 10:07
  • https://stackoverflow.com/questions/56466773/what-is-the-real-benefit-of-using-raycast-in-arkit-and-realitykit/56467767#56467767 – Andy Jazz Jul 15 '21 at 10:13
  • I do have only one question, How to get Mesh position instead of default ARWorld position in raycast. That means, How to put anchor or box upon specific position of mesh/ARMeshAnchor. – indrajit Jul 15 '21 at 10:25
  • The same way as usually. – Andy Jazz Jul 15 '21 at 11:10

1 Answers1

2

It works with any LiDAR's reconstructed mesh, not only with planes:

@objc func tapped(_ sender: UITapGestureRecognizer) {
    
    let tapLocation = sender.location(in: arView)
    
    if let result: ARRaycastResult = arView.raycast(from: tapLocation,
                                                allowing: .estimatedPlane,
                                               alignment: .any).first {
        
        let resultAnchor = AnchorEntity(world: result.worldTransform)
        
        resultAnchor.addChild(self.sphereObject(0.05, .systemRed))
        
        arView.scene.addAnchor(resultAnchor, removerAfter: 10.0)
    }
}
Andy Jazz
  • 49,178
  • 17
  • 136
  • 220