【发布时间】:2018-12-15 20:02:48
【问题描述】:
我的应用有一个 ARSCNView 并通过图像检测识别图像 我们的目标是寻找一张图片,一旦它被识别出来,就改变世界位置到它的中心
有些东西不工作。任何帮助将不胜感激!
func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) {
guard let imageAnchor = anchor as? ARImageAnchor else {return}
if let imageName = imageAnchor.referenceImage.name {
switch imageName {
case "myImage":
//OK, the image gets recognized
let refSphere = SCNSphere(radius: 0.02)
let refNode = SCNNode(geometry: refSphere)
refSphere.firstMaterial?.diffuse.contents = UIColor.red.withAlphaComponent(0.8)
node.addChildNode(refNode) // OK, there's a sphere representation on top of the recognized image
sceneView.session.pause()
self.sceneView.session.setWorldOrigin(relativeTransform: node.simdTransform) // Trying to move the world Origin to the center of recognized image
sceneView.session.run(configuration, options: [.resetTracking])
let box = SCNBox(width: 0.05, height: 0.05, length: 0.05, chamferRadius: 0.01)
let boxNode = SCNNode(geometry: box)
box.firstMaterial?.diffuse.contents = UIColor.green.withAlphaComponent(0.9)
boxNode.position = SCNVector3(0,0,0)
sceneView.scene.rootNode.addChildNode(boxNode) // Not OK - I was expecting to have world Origin in the center of the recognized image and a green box on top of it
default:
print("other")
}
}
}
【问题讨论】: