objective-c - ARFrame 锚点中不存在 AREnvironmentProbeAnchor
问题描述
我无法弄清楚AREnvironmentProbeAnchor
模式是如何工作的automatic
。我假设 ARKit 为我创建了一系列带有纹理的锚点,但我看不到它们。
我添加到配置中:
session.configuration.environmentTexturing = AREnvironmentTexturingAutomatic;
现在我正在遍历框架中的所有锚点并寻找AREnvironmentProbeAnchor
:
for (ARAnchor* anchor in frame.anchors) {
if ([anchor isKindOfClass:[AREnvironmentProbeAnchor class]]) {
NSLog(@"found");
}
}
有什么问题?
谢谢!
解决方案
例如,您应该if-statement
在实例方法renderer(_:didAdd:for:)
中使用。任何 ARAnchor 都必须属于 SCNNode。试试这段代码,看看它是如何工作的(对不起,它是在 Swift 中而不是在 Objective-C 中):
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
override func viewDidLoad() {
super.viewDidLoad()
sceneView.delegate = self
let scene = SCNScene(named: "art.scnassets/yourScene.scn")!
let sphereNode = SCNNode(geometry: SCNSphere(radius: 0.05))
sphereNode.position = SCNVector3(x: 0, y: -0.5, z: -1)
let reflectiveMaterial = SCNMaterial()
reflectiveMaterial.lightingModel = .physicallyBased
reflectiveMaterial.metalness.contents = 1.0
reflectiveMaterial.roughness.contents = 0
sphereNode.geometry?.firstMaterial = reflectiveMaterial
let moveLeft = SCNAction.moveBy(x: 0.25, y: 0, z: 0.25, duration: 2)
moveLeft.timingMode = .easeInEaseOut;
let moveRight = SCNAction.moveBy(x: -0.25, y: 0, z: -0.25, duration: 2)
moveRight.timingMode = .easeInEaseOut;
let moveSequence = SCNAction.sequence([moveLeft, moveRight])
let moveLoop = SCNAction.repeatForever(moveSequence)
sphereNode.runAction(moveLoop)
sceneView.scene = scene
sceneView.scene.rootNode.addChildNode(sphereNode)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
let configuration = ARWorldTrackingConfiguration()
configuration.environmentTexturing = .automatic
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
sceneView.session.pause()
}
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard anchor is AREnvironmentProbeAnchor else {
print("Environment anchor is NOT FOUND")
return
}
print("It's", anchor.isKind(of: AREnvironmentProbeAnchor.self))
}
}
结果:
// It's true
希望这可以帮助。
推荐阅读
- python - Python 提取数据
- unity3d - 如何消除 3D 统一运动中的滑行?
- android - 如何在用户与活动交互时连续获取 GPS 位置并基于此更改 UI?
- c# - 带有用户凭据提示的 MVC Windows 身份验证
- c++ - 模板模板参数中的 C++ 未声明标识符
- ios - 如何在 Xcode 11 iOS 13 上查看 NSLog?
- python - 如何转换数据数组以显示易于理解的结果
- node.js - 如何为选择选项列表设置猫鼬模式并在选定选项上设置属性
- unity3d - 在协程中使用 lerp 面对其他对象
- ruby-on-rails - 使用 RSpec 测试更新请求失败