Ios ';隐藏&x27;ARKit 2.0上触发器图像下的平面节点
我正在使用Arkit2.0检测触发图像,并将平面和对象放在上面。我希望一个特定的物体从我的触发图像下逐渐出现,并将其自身定位到它的侧面。为此,我运行动画以移动位置:Ios ';隐藏&x27;ARKit 2.0上触发器图像下的平面节点,ios,swift,arkit,ios12,Ios,Swift,Arkit,Ios12,我正在使用Arkit2.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), duratio
//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复制我的触发器,但用手拿着触发器时会显得很奇怪
以下是该问题的一些图片:
我通过使用遮挡找到了解决方案!本质上,我在我的触发器上创建了一个平面,它阻挡了它后面的一切,就像这样:
//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)
您只需将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
}