[英]Reality Composer not importing correctly into RealityKit
我正在嘗試將 3d 模型錨定到真實世界的圖像上,在我的例子中是 QR 碼......它在 Reality Composer 中運行良好,但是,我試圖將它添加到我的 RealityKit 項目中,但我的ARView... 控制台中沒有打印任何相關內容。
這是我的代碼:
struct MainARView: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let view = ARView()
let session = view.session
let config = ARWorldTrackingConfiguration()
session.run(config)
view.debugOptions = [.showFeaturePoints,
.showAnchorOrigins,
.showAnchorGeometry]
guard let anchor = try? TestObj.loadScene() else {
print("Error loading TestObj")
return view
}
view.scene.addAnchor(anchor)
return view
}
func updateUIView(_ view: ARView, context: Context) { }
}
任何幫助將非常感激
在您的情況下,無需運行ARWorldTrackingConfig
或ARImageTrackingConfig
。
與 ARKit 不同,RealityKit 會根據 Target 的案例( .object
、 .image
、 .plane
等)自動跟蹤您的所有 AnchorEntities。 Reality Composer 已經為您創建了AnchorEntity(.image)
,因此ARImageTrackingConfig
會自動分配給會話。
import SwiftUI
import RealityKit
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let qrCodeModel = try! Experience.loadModel()
arView.scene.anchors.append(qrCodeModel)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) { }
}
除了上述之外,這里還有一種在 RealityKit 中從頭開始創建相同場景的方法。
struct ARViewContainer: UIViewRepresentable {
func makeUIView(context: Context) -> ARView {
let arView = ARView(frame: .zero)
let entity = ModelEntity(mesh: .generateBox(size: 0.125))
let anchor = AnchorEntity(.image(group: "AR Resources",
name: "QRCode.png"))
entity.setParent(anchor)
arView.scene.anchors.append(anchor)
return arView
}
func updateUIView(_ uiView: ARView, context: Context) { }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.