我正在尝试将平面检测添加到一个简单的ARKit应用程序中。我想把图片放在垂直平面上。
因此,首先需要检测平面,然后才能添加我在RealityKit中创建的物体锚点。
然而,问题是我不确定使用ARKit 3和Xcode 11检测平面并将其添加到我的场景中的正确方法。
应该很简单:
尝试创建 AnchorEntity 时,我收到以下错误:
Expression type 'AnchorEntity' is ambiguous without more context
因此,首先需要检测平面,然后才能添加我在RealityKit中创建的物体锚点。
然而,问题是我不确定使用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)
}
但我收到了以下错误:
类型 'ARView' 的值没有成员 'session'
我甚至尝试了苹果在他们的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)
}
}