ARFrame 锚点中不存在 AREnvironmentProbeAnchor
Posted
技术标签:
【中文标题】ARFrame 锚点中不存在 AREnvironmentProbeAnchor【英文标题】:AREnvironmentProbeAnchor are not present in ARFrame anchors 【发布时间】:2019-08-27 15:47:51 【问题描述】:当模式为automatic
时,我无法弄清楚AREnvironmentProbeAnchor
的工作原理。我假设 ARKit 为我创建了一系列带有纹理的锚点,但我看不到它们。
我添加到配置中:
session.configuration.environmentTexturing = AREnvironmentTexturingAutomatic;
现在我正在遍历框架中的所有锚点并寻找AREnvironmentProbeAnchor
:
for (ARAnchor* anchor in frame.anchors)
if ([anchor isKindOfClass:[AREnvironmentProbeAnchor class]])
NSLog(@"found");
可能出了什么问题?
谢谢!
【问题讨论】:
你从哪里循环锚点? 【参考方案1】:例如,您应该在实例方法renderer(_:didAdd:for:)
中使用if-statement
。任何 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
希望这会有所帮助。
【讨论】:
以上是关于ARFrame 锚点中不存在 AREnvironmentProbeAnchor的主要内容,如果未能解决你的问题,请参考以下文章
由于 html 锚点中的 onclick 事件导致页面加载缓慢
JavaScript Onclik在锚点中更改文本并启用具有表单字段的div并隐藏onload默认属性