当模式为AREnvironmentProbeAnchor
时,我不知道automatic
的工作方式。我假设ARKit为我创建了具有纹理的一系列锚点,但是我看不到它们。
我已添加到配置:
session.configuration.environmentTexturing = AREnvironmentTexturingAutomatic;
现在我正在循环遍历框架中的所有锚点并寻找AREnvironmentProbeAnchor
:
for (ARAnchor* anchor in frame.anchors) {
if ([anchor isKindOfClass:[AREnvironmentProbeAnchor class]]) {
NSLog(@"found");
}
}
怎么了?
谢谢!
答案 0 :(得分:1)
例如,您应该在实例方法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
希望这会有所帮助。