我正在使用ARKit 2.0来检测触发图像并将平面和对象放置在其上方。我希望特定的物体从触发图像下方逐渐出现,并将其自身放置在侧面。为此,我运行动画来移动位置:
//Original Position
self.planeNode?.position = SCNVector3(0, -0.02, 0)
//New position
self.planeNode?.runAction(SCNAction.move(to: SCNVector3(0.08, -0.05, 0), duration: 0.5))
但是,触发图像并没有隐藏planeNode,即使从技术上讲,它仍然可以在它上面看到。
我想到了将扳机复制到具有相同图像的planeNode上,但是当用手或类似物握住扳机时,看起来会很奇怪。
以下是该问题的一些图片:
答案 0 :(得分:3)
我通过使用遮挡找到了解决方案!本质上,我在触发器的顶部创建了一个平面,该平面将其后面的所有东西都遮挡了,如下所示:
//Set occlusion material
let cardOcclusion = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
let holdout = SCNMaterial()
holdout.isDoubleSided = true
holdout.diffuse.contents = CIColor.black
holdout.colorBufferWriteMask = SCNColorMask(rawValue: 0)
cardOcclusion.firstMaterial? = holdout
let cardOcclusionNode = SCNNode()
cardOcclusionNode.eulerAngles.x = -.pi / 2
cardOcclusionNode.geometry = cardOcclusion
node.addChildNode(cardOcclusionNode)
答案 1 :(得分:0)
您只需将UiimageView 对象放在下面代码的 viewObj 中即可。
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let imageAnchor = anchor as? ARImageAnchor {
let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)
plane.firstMaterial?.diffuse.contents = UIColor(white: 1, alpha: 0.8)
let material = SCNMaterial()
material.diffuse.contents = viewObj
plane.materials = [material]
let planeNode = SCNNode(geometry: plane)
planeNode.eulerAngles.x = -.pi / 2
node.addChildNode(planeNode)
}
return node
}