How to change SCNPlane color as clear color

ε祈祈猫儿з 提交于 2019-12-22 08:12:51

问题


I am working on a ARKit project which needs Ripple animation effect when tapped on Horizontal Plane. For that I have took UIView object and pass that as contents for material of SCNPlane object. I have added Ripple animation to UIView object. Everything works fine. But I can't change the SCNPlane colour to clear color. I can use transparency property for the material. But it is hiding Ripple animation too. So, what I need here is, the background colour of SCNPlane object should be transparent and only Ripple animation should appear to user. Can someone help me on this.

This is my code.

    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:


Check out this answer. Setting the UiView isOpaque to false worked for me.



来源:https://stackoverflow.com/questions/50368057/how-to-change-scnplane-color-as-clear-color

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!