Reputation: 5003
I can't figure out how AREnvironmentProbeAnchor
works, when mode is automatic
. I assume that ARKit creates a range of Anchors for me with texture, but I can't see them.
I added to the configuration:
session.configuration.environmentTexturing = AREnvironmentTexturingAutomatic;
Now I am doing loop over all anchors in the frame and looking for AREnvironmentProbeAnchor
:
for (ARAnchor* anchor in frame.anchors) {
if ([anchor isKindOfClass:[AREnvironmentProbeAnchor class]]) {
NSLog(@"found");
}
}
What could be wrong?
Thanks!
Upvotes: 1
Views: 264
Reputation: 58043
You should use if-statement
inside an instance method renderer(_:didAdd:for:)
, for example. Any ARAnchor must belong to SCNNode. Try this code to find out how it works (sorry, it's in Swift not in 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
Hope this helps.
Upvotes: 2