我正在尝试将平面检测添加到一个简单的 ARKit 应用程序中。我想将图片放在垂直平面上。
所以首先我需要检测平面,然后我可以添加我在 RealityKit 中创建的对象 anchor 。
但是问题是我不确定使用 ARKit 3 和 Xcode 11 检测飞机并将其添加到我的场景的正确方法。
它应该像这样简单:
import ARKit
import RealityKit
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
let arConfiguration = ARWorldTrackingConfiguration()
arConfiguration.planeDetection = .horizontal
arView.session.run(arConfiguration)
}
但是我得到以下错误:
Value of type 'ARView' has no member 'session'
我什至尝试了以下 Apple 从他们的 WWDC 演示 (4:27) 中用作示例的内容,
let anchor = AnchorEntity(plane: .verticle, minimumBounds: [0.2, 0.2])
arView.scene.addAnchor(anchor)
但我在尝试创建 AnchorEntity 时遇到以下错误
Expression type 'AnchorEntity' is ambiguous without more context
import UIKit
import RealityKit
import ARKit
class ViewController: UIViewController {
@IBOutlet var arView: ARView!
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
}
override func viewDidLoad() {
super.viewDidLoad()
}
func addFrame() {
// Load the "Box" scene from the "Experience" Reality File
let boxAnchor = try! Experience.loadBox()
// Add the box anchor to the scene
arView.scene.anchors.append(boxAnchor)
}
}
最佳答案
如果您的构建目的地设置为模拟器,您会收到此错误。您需要选择实际设备或通用 iOS 设备。
我已经在这上面撞了好几次了,现在添加以下评论
// If the following line fails to compile "Value of type 'ARView' has no member 'session'"
// You need to select a Real Device or Generic iOS Device and not a simulator
arView.session.run(configuration)
关于ios - ARKit 平面检测 - 类型 'ARView' 的值没有成员 'session',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56973063/