ios - ARKit 平面检测 - “ARView”类型的值没有成员“会话”
问题描述
我正在尝试将平面检测添加到一个简单的 ARKit 应用程序中。我想在垂直平面上放一张图片。
所以首先我需要检测平面然后我可以添加我在 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”类型的值没有成员“会话”
我什至尝试了以下内容,Apple 在他们的 WWDC 演示 (4:27) 中将其用作示例,
苹果演示!
let anchor = AnchorEntity(plane: .verticle, minimumBounds: [0.2, 0.2])
arView.scene.addAnchor(anchor)
但是在尝试创建 AnchorEntity 时出现以下错误
表达式类型“AnchorEntity”在没有更多上下文的情况下是模棱两可的
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)
推荐阅读
- c# - 将 NT AUTHORITY\System 添加到 SQL Server 之外的 SQL Server 中的 Sysadmin 角色
- python - SQLalchemy 空列定义模型
- python - 用逗号分割字符串,除非后跟空格或“+”
- python - 如何将 chart.y_axis 类别更改为数字
- hibernate - 在 5.4 中是否有任何选项可以控制模式验证?具体来说,序列分配大小验证
- java - 如何使用 Jib 为多模块 Spring Boot 应用程序构建 Docker 映像
- office365 - Excel 内部自定义功能的使用(一次性购买许可证)
- c++ - SplitEmptyFunction 不拆分空函数
- java - 使用 Spring Cloud Config 连接服务器时出错:`Connect: Timeout Exception on Url`
- mongodb - Pymongo $regexMatch 正则表达式选项中的无效标志:u