ARKit – Rendering a 3D object under an invisible plane

后端 未结 1 1802
自闭症患者
自闭症患者 2021-01-25 14:50

I have an ARKit scene with an invisible SCNPlane:

plane.geometry?.firstMaterial?.colorBufferWriteMask = []

This plane is placed on

相关标签:
1条回答
  • 2021-01-25 15:12

    You can achieve it using the following lines of code:

    shadowsPlane.geometry?.materials.first?.writesToDepthBuffer = true
    shadowsPlane.geometry?.materials.first?.readsFromDepthBuffer = true
    

    Choose one of two instance properties for .colorBufferWriteMask:

    shadowsPlane.geometry?.materials.first?.colorBufferWriteMask = []
    

    Set a rendering order for your objects like:

    shadowsPlane.renderingOrder = -1   // the nearest layer
    

    And, of course, use an appropriate .lightingModel instance property:

    shadowsPlane.geometry?.materials.first?.lightingModel = .constant 
    

    Remember, there will be some tiny air gap between two planes:

    shadowsPlane.position = SCNVector3(x: 0, y: 0, z: 0)
    floorPlane.position = SCNVector3(x: 0, y: -0.01, z: 0)
    
    0 讨论(0)
提交回复
热议问题