title: LiDAR and RealityKit – Capture a Real World Texture for a Scanned Model
body: <h2>Task</h2>
  <p>I would like to <strong><code>capture</code></strong> a real-world texture and apply it to a reconstructed mesh produced with a help of LiDAR scanner. I suppose that Projection-View-Model matrices should be used for that. A texture must be made from fixed Point-of-View, for example, from center of a room. However, it would be an ideal solution if we could apply an <code>environmentTexturing</code> data, collected as a <code>cube-map</code> texture in a scene.</p>
  <p><a href="https://i.stack.imgur.com/3JyxW.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/3JyxW.jpg" alt="enter image description here" /></a></p>
  <p>Look at <a href="https://apps.apple.com/ru/app/3d-scanner-app/id1419913995?l=en" rel="nofollow noreferrer">3D Scanner App</a>. It's a reference app allowing us to export a model with its texture.</p>
  <p>I need to capture a texture with one iteration. I do not need to update it in a realtime. I realize that changing PoV leads to a wrong texture's perception, in other words, distortion of a texture. Also I realize that there's a dynamic tesselation in RealityKit and there's an automatic texture mipmapping (texture's resolution depends on a distance it captured from).</p>
  <pre class="lang-swift prettyprint-override"><code>import RealityKit
  import ARKit
  import Metal
  import ModelIO
  
  class ViewController: UIViewController, ARSessionDelegate {
      
      @IBOutlet var arView: ARView!
  
      override func viewDidLoad() {
          super.viewDidLoad()
  
          arView.session.delegate = self
          arView.debugOptions.insert(.showSceneUnderstanding)
  
          let config = ARWorldTrackingConfiguration()
          config.sceneReconstruction = .mesh
          config.environmentTexturing = .automatic
          arView.session.run(config)
      }
  }
  </code></pre>
  <h2>Question</h2>
  <ul>
  <li>How to capture and apply a real world texture to a reconstructed 3D mesh?</li>
  </ul>
  <p><br></p>