我想要
capture
一个真实世界的纹理,并将其应用到在 LiDAR 扫描仪的帮助下生成的重建网格。我认为应该使用投影视图模型矩阵。纹理必须从固定的视点(例如,从房间的中心)制作。然而,如果我们可以应用 environmentTexturing
数据(在场景中作为 cube-map
纹理收集),这将是一个理想的解决方案。
查看 3D 扫描仪应用程序。这是一个参考应用程序,允许我们导出带有纹理的模型。
我需要通过一次迭代捕获纹理。我不需要实时更新它。我意识到改变 PoV 会导致错误的纹理感知,换句话说,纹理的扭曲。我还意识到 RealityKit 中有一个动态细分,并且有一个自动纹理 mipmap(纹理的分辨率取决于它捕获的距离)。
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)
}
}
2023 年 10 月 10 日,Apple 发布了 iOS Reality Composer 1.6 应用程序,该应用程序能够使用 LiDAR 扫描过程实时捕获带有纹理的现实世界模型的网格。但目前还没有原生的编程 API(但我们都期待着它)。
此外,还有一种方法允许开发人员从一系列镜头创建纹理模型。
Object Capture API 为开发人员提供了期待已久的
photogrammetry
工具。在输出中,我们得到带有 UV 映射高分辨率纹理的 USDZ 模型。要实现 Object Capture API
,您需要 macOS 12+ 和 Xcode 13+。
要从一系列镜头创建 USDZ 模型,请将所有拍摄的图像提交到 RealityKit 的
PhotogrammetrySession
。
这里有一个代码片段,可以让您了解这个过程:
import RealityKit
import Combine
let pathToImages = URL(fileURLWithPath: "/path/to/my/images/")
let url = URL(fileURLWithPath: "model.usdz")
var request = PhotogrammetrySession.Request.modelFile(url: url,
detail: .medium)
var configuration = PhotogrammetrySession.Configuration()
configuration.sampleOverlap = .normal
configuration.sampleOrdering = .unordered
configuration.featureSensitivity = .normal
configuration.isObjectMaskingEnabled = false
guard let session = try PhotogrammetrySession(input: pathToImages,
configuration: configuration)
else { return
}
var subscriptions = Set<AnyCancellable>()
session.output.receive(on: DispatchQueue.global())
.sink(receiveCompletion: { _ in
// errors
}, receiveValue: { _ in
// output
})
.store(in: &subscriptions)
session.process(requests: [request])
您可以使用相应的 UV 映射纹理重建 USD 和 OBJ 模型。
如何在Unity中完成
我想分享一些关于 Unity 的 AR Foundation 与来自 LiDAR 的网格的工作的有趣信息。目前——2020 年 11 月 1 日——出现了一个荒谬的情况。这与原生 ARKit 开发人员无法使用标准高级 RealityKit 工具捕获扫描对象的纹理这一事实相关,但 Unity 的 AR Foundation 用户(创建 ARKit 应用程序)可以使用
ARMeshManager
脚本来做到这一点。我不知道这个脚本是由 AR 基金会团队开发的,还是由一家小型创意初创公司的开发人员开发的(然后随后被购买),但事实是这样的。
要将 ARKit 网格与 AR Foundation 结合使用,您只需将 ARMeshManager 组件添加到场景中。正如您在图片中看到的,有
Texture Coordinates
、Color
和 Mesh Density
等功能。
如果有人有关于如何在 Unity 中配置或编写脚本的更多详细信息,请在此线程中发布。