Prashant Tukadiya
Prashant Tukadiya

Reputation: 16456

ARKit How to stop flickering or How to position node towards camera,

I have created Wall with SCNPlane. on that plane I am adding another Plane where User point the device

But because of both plane has same position newly added plane is flickering.

So How can I keep distance from wall node and plane node

how i add plane node.

let hitTestScene = self.sceneView.hitTest(self.sceneView.center, options:[SCNHitTestOption.categoryBitMask : 16])
 if let first = hitTestScene.first  {
    if first.node.name == NodeNames.wallNode {
       let value = MathHelper().getMeasurementBetween(vector1: lastNodePosition, and: first.worldCoordinates)
          let node = SCNNode(geometry: SCNPlane(width: CGFloat( value) , height:  CGFloat(value)))
           node.geometry?.firstMaterial?.isDoubleSided = true
           node.name = "Plane1"
           node.geometry?.firstMaterial?.diffuse.contents = UIColor.red.withAlphaComponent(1)
           node.eulerAngles = first.node.eulerAngles
           node.position = lastNodePosition

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

       }
 }  

Plane in red is continually flicked (appear - disappear )

enter image description here

I have tried node.position.z -= 0.2 but it is not working and node position changes completely because of node.eulerAngles

Any help would be appreciated

Upvotes: 2

Views: 1174

Answers (1)

Prashant Tukadiya
Prashant Tukadiya

Reputation: 16456

I have figure it out.

by setting rendringOrder and readsFromDepthBuffer I was able to stop that flick effect

extension SCNNode {
    func renderOnTop() {
        self.renderingOrder = 2
        if let geom = self.geometry {
            for material in geom.materials {
                material.readsFromDepthBuffer = false
            }
        }
        for child in self.childNodes {
            child.renderOnTop()
        }
    }
}

Hope some can use it if same issue

Upvotes: 1

Related Questions