5

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.

Hari
  • 144
  • 9

1 Answers1

3

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

double-beep
  • 5,031
  • 17
  • 33
  • 41
Kenneth
  • 3,957
  • 8
  • 39
  • 62
  • I was stuck on this for weeks. Your answer to this answer works! The other answer shows you what to do but I was trying to keep my code compact and was doing everything all in one line which was in correct: material.diffuse.contents = MyViewController.view .isOpaque = false. The key to the other answer is to set the viewController.isOpaque = false **BEFORE** you set it to the materials contents: **1.** MyViewController.isOpaque = false **then 2.** material.diffuse.contents = MyViewController.view. – Lance Samaria Dec 22 '19 at 04:43