gpt4 book ai didi

objective-c - AREnvironmentProbeAnchor 不存在于 ARFrame anchor 中

转载 作者:行者123 更新时间:2023-11-28 05:44:10 24 4
gpt4 key购买 nike

当模式为自动时,我不知道AREnvironmentProbeAnchor 是如何工作的。我假设 ARKit 为我创建了一系列具有纹理的 anchor ,但我看不到它们。

我在配置中添加了:

session.configuration.environmentTexturing = AREnvironmentTexturingAutomatic;

现在我正在循环遍历框架中的所有 anchor 并寻找 AREnvironmentProbeAnchor:

for (ARAnchor* anchor in frame.anchors) {
if ([anchor isKindOfClass:[AREnvironmentProbeAnchor class]]) {
NSLog(@"found");
}
}

有什么问题吗?

谢谢!

最佳答案

例如,您应该在实例方法 renderer(_:didAdd:for:) 中使用 if 语句。任何 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))
}
}

Result:

// It's true

希望这对您有所帮助。

关于objective-c - AREnvironmentProbeAnchor 不存在于 ARFrame anchor 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55540483/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com