Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to have a SCNNode which is transparent, but which occludes any object behind it? [duplicate]

So to be clear on my goals, since I don't have any code to share... Lets say I have a SCNNode which is positioned between the camera and another SCNNode. The first SCNNode is a SCNBox, but has no texture, thus the second SCNNode can be seen behind it. I want to give the first node a transparent material, but to have it also occlude all nodes behind it, as though it was opaque. In a regular scene, this would mean that you could see the scene background color, black perhaps, but I'm planning on doing this in ARKit, which makes more sense as that means you'd simply see the real world behind it.

like image 635
Andrew Avatar asked Sep 01 '17 18:09

Andrew


1 Answers

You can use material with clear color:

extension SCNMaterial {
    convenience init(color: UIColor) {
        self.init()
        diffuse.contents = color
    }
    convenience init(image: UIImage) {
        self.init()
        diffuse.contents = image
    }
}

let clearMaterial = SCNMaterial(color: .clear)
boxNode.materials = [clearMaterial]
like image 139
Vasilii Muravev Avatar answered Oct 11 '22 10:10

Vasilii Muravev