如何将SCNPlane颜色更改为清晰的颜色

时间:2018-05-16 10:09:27

标签: ios swift scenekit arkit scnnode

我正在开发一个ARKit项目,当在水平平面上点击时需要Ripple动画效果。为此,我已经获取了UIView对象并将其作为SCNPlane对象的材料的内容传递。我已经为UIView对象添加了Ripple动画。一切正常。但我不能改变SCNPlane颜色来清除颜色。我可以使用材质的透明属性。但它也隐藏了Ripple动画。所以,我需要的是,SCNPlane对象的背景颜色应该是透明的,并且只有Ripple动画应该出现给用户。有人可以帮我这个。

这是我的代码。

    let location = tapGesture.location(in: self.sceneView)
    let results = self.sceneView.hitTest(location, types: .existingPlane)
    if !results.isEmpty{

        guard let result = results.first else{ return }
        let myUIView = UIView(frame: CGRect(origin: .zero, size: CGSize(width: 300, height: 300)))
        myUIView.backgroundColor = .red
        let plane = SCNPlane(width: 1.0, height: 1.0)
        plane.firstMaterial?.diffuse.contents = myUIView
        let planeViewNode = SCNNode(geometry: plane)
        planeViewNode.eulerAngles.x = Float(-Double.pi / 2)
        planeViewNode.position = SCNVector3(result.worldTransform.columns.3.x, result.worldTransform.columns.3.y, result.worldTransform.columns.3.z)

        self.sceneView.scene.rootNode.addChildNode(planeViewNode)

        //Ripple animation code goes here 
    }

I took screenshot from Civilisations AR app from BBC. Please refer the screenshot by clicking this link. This is how exactly I need.

1 个答案:

答案 0 :(得分:1)

查看this答案。将UiView isOpaque设置为false对我有用。