ARKit隐藏墙后的物体 [英] ARKit hide objects behind walls

查看:245
本文介绍了ARKit隐藏墙后的物体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用ARKit跟踪的水平和垂直平面隐藏墙后/真实物体后面的物体?当前离开房间时和/或应该在后面的物体前面时,可以通过墙看到3D添加的对象。那么是否有可能使用数据ARKit让我提供更自然的AR体验,而不会通过墙壁出现对象?

How can I use the horizontal and vertical planes tracked by ARKit to hide objects behind walls/ behind real objects? Currently the 3D added objects can be seen through walls when you leave a room and/ or in front of objects that they should be behind. So is it possible to use the data ARKit gives me to provide a more natural AR experience without the objects appearing through walls?

推荐答案

你有两个问题。

(你甚至没有使用正则表达式!)

如果您设置了SceneKit材质的 colorBufferWriteMask 到Swift中的空值( [] ),使用该材质的任何对象都不会出现在视图中,但它们仍然会写入渲染期间的z缓冲区会影响其他对象的渲染。实际上,你会得到一个形状像你的物体的洞,背景显示(摄像机输入,在 ARSCNView 的情况下),但仍然可以模糊其他SceneKit对象。

If you set a SceneKit material's colorBufferWriteMask to an empty value ([] in Swift), any objects using that material won't appear in the view, but they'll still write to the z-buffer during rendering, which affects the rendering of other objects. In effect, you'll get a "hole" shaped like your object, through which the background shows (the camera feed, in the case of ARSCNView), but which can still obscure other SceneKit objects.

你还需要确保在任何其他节点隐藏之前,遮挡渲染。你可以使用节点层次结构来做到这一点(我不记得父节点是否在他们的子节点之前呈现或反过来,但它很容易测试)。层次结构中的对等节点没有确定性顺序,但您可以使用 renderingOrder 属性。该属性默认为零,因此将其设置为-1将在所有内容之前呈现。 (或者为了更好的控制,将几个节点的 renderingOrder 设置为一系列值。)

You'll also need to make sure that an occluded renders before any other nodes it's supposed to obscure. You can do this using node hierarchy ( I can't remember offhand whether parent nodes render before their children or the other way around, but it's easy enough to test). Nodes that are peers in the hierarchy don't have a deterministic order, but you can force an order regardless of hierarchy with the renderingOrder property. That property defaults to zero, so setting it to -1 will render before everything. (Or for finer control, set the renderingOrders for several nodes to a sequence of values.)

在iOS 11.3及更高版本(又名ARKit 1.5)中,你可以打开 vertical 飞机检测。 (请注意,当您获得 vertical 飞机锚从那里回来,它们会自动旋转。所以如果你把模型附加到锚上,它们的本地向上方向与飞机垂直。)在iOS 11.3中也是新的,你可以得到每个检测到的平面的更详细的形状估计(请参阅 ARSCNPlaneGeometry ),无论其是什么定向。

In iOS 11.3 and later (aka "ARKit 1.5"), you can turn on vertical plane detection. (Note that when you get vertical plane anchors back from that, they're automatically rotated. So if you attach models to the anchor, their local "up" direction is normal to the plane.) Also new in iOS 11.3, you can get a more detailed shape estimate for each detected plane (see ARSCNPlaneGeometry), regardless of its orientation.

然而,即使您有水平和垂直,平面的外部界限也只是随时间变化的估计值。也就是说,ARKit可以快速检测墙壁的哪个部分,但是如果没有用户花费一些时间挥动设备来绘制空间,它就不知道墙壁的边缘。即使这样,映射的边缘也可能与真实墙壁的边缘没有精确对齐。

However, even if you have the horizontal and the vertical, the outer limits of a plane are just estimates that change over time. That is, ARKit can quickly detect where part of a wall is, but it doesn't know where the edges of the wall are without the user spending some time waving the device around to map out the space. And even then, the mapped edges might not line up precisely with those of the real wall.

所以...如果你使用检测到的垂直平面遮挡虚拟几何体,你可能会找到应该隐藏的虚拟对象显示的位置,或者通过不完全隐藏在墙的边缘,或者通过ARKit未映射整个真实墙的位置可见。 (后一个问题你可以通过假设比ARKit更大的程度来解决。)

So... if you use detected vertical planes to occlude virtual geometry, you might find places where virtual objects that are supposed to be hidden show through, either by being not quite hiding right at the edge of the wall, or being visible through places where ARKit hasn't mapped the entire real wall. (The latter issue you might be able to solve by assuming a larger extent than ARKit does.)

这篇关于ARKit隐藏墙后的物体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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