SceneKit Culling Plane

怎甘沉沦 提交于 2019-11-29 07:29:41

Here's a solution

  1. For the cube, use a material with constant as its lightingModel. It's the cheapest one.
  2. This material will have writesToDepthBuffer set to true and colorBufferWriteMask set to [] (empty option set). That way the cube will write in the depth buffer, but won't draw anything on screen.
  3. Set the cube's renderingOrder to -1 so that it's drawn before any other node in the scene. This will make the cube write in the depth buffer before any other object, preventing them from being drawn if they are behind the cube.

Based on @mnuages answer, you can use this class :

import SceneKit

class OccludingNode : SCNNode {
    convenience init(geometry: SCNGeometry) {
        geometry.materials = [OccludingMaterial()]

        self.init()
        self.geometry = geometry
        self.renderingOrder = -1
    }
}

class OccludingMaterial : SCNMaterial {
    override init() {
        super.init()
        isDoubleSided = true
        lightingModel = .constant
        writesToDepthBuffer = true
        colorBufferWriteMask = []
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

Create an OccludingNode from any geometry you want and anything behind it won't be rendered.

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