【发布时间】:2020-08-17 14:10:11
【问题描述】:
我正在尝试使用 SwiftUI、RealityKit 和 ARKit 在面部加载不同的模型。
struct AugmentedRealityView: UIViewRepresentable {
@Binding var modelName: String
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let configuration = ARFaceTrackingConfiguration()
arView.session.run(configuration, options: [.removeExistingAnchors,
.resetTracking])
loadModel(name: modelName, arView: arView)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) { }
private func loadModel(name: String, arView: ARView) {
var cancellable: AnyCancellable? = nil
cancellable = ModelEntity.loadAsync(named: name).sink(
receiveCompletion: { loadCompletion in
if case let .failure(error) = loadCompletion {
print("Unable to load model: \(error.localizedDescription)")
}
cancellable?.cancel()
},
receiveValue: { model in
let faceAnchor = AnchorEntity(.face)
arView.scene.addAnchor(faceAnchor)
faceAnchor.addChild(model)
model.scale = [1, 1, 1]
})
}
}
这是我加载它们的方式,但是当相机视图打开并加载一个模型时,其他模型将不会被加载。有人可以帮帮我吗?
【问题讨论】:
-
阅读这篇文章以了解如何操作:stackoverflow.com/questions/59618102/…
标签: swiftui augmented-reality arkit realitykit reality-composer