ARKit –在不可见的平面下渲染3D对象 [英] ARKit – Rendering a 3D object under an invisible plane

查看:119
本文介绍了ARKit –在不可见的平面下渲染3D对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不可见的SCNPlane的ARKit场景:

I have an ARKit scene with an invisible SCNPlane:

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

此平面放置在地面上,用于从场景中放置的其他对象渲染deferred shadows.

This plane is placed on the ground and is used to render deferred shadows from other objects placed in the scene.

我想渲染另一个SCNPlane,它应该与不可见平面处于同一水平(相同的Z-坐标).问题在于,每当新对象位于不可见平面下时,它就根本不会渲染.

I want to render another SCNPlane which should be on the same level as the invisible plane (same Z-coordinate). The problem is, that every time the new object is under the invisible plane, it is not rendered at all.

当对象处于不可见平面之下时,有什么方法可以渲染它?

Is there any way to render the object when it is under the invisible plane?

推荐答案

您可以使用以下代码行实现它:

You can achieve it using the following lines of code:

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

选择 .colorBufferWriteMask 的两个实例属性之一:

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

当然,请使用适当的 .lightingModel 实例属性:

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)

这篇关于ARKit –在不可见的平面下渲染3D对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆