首页 文章

'Hide'在ARKit 2.0上触发图像下的平面节点

提问于
浏览
1

我正在使用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来复制我的触发器,但是用一只手握住触发器时看起来很奇怪 .

以下是该问题的一些图片:

Image below trigger, but showing on top

Image below trigger

2 回答

  • 2

    我通过使用遮挡找到了解决方案!基本上我在触发器上创建了一个平面,它封闭了它背后的一切,如下所示:

    //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)
    
  • 0

    您只需将UiimageView object 放在 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
        }
    

相关问题