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

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

问题描述

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

解决方案

这里有两个问题.

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

如何为 ARKit/SceneKit 创建遮挡几何体?

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

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

如何检测墙壁等,以便知道将遮挡几何体放在哪里?

在 iOS 11.3 及更高版本(又名ARKit 1.5")中,您可以打开 vertical 平面检测.(请注意,当您获得 vertical 平面锚从那里返回,它们会自动旋转.因此,如果您将模型附加到锚上,它们的局部向上"方向与平面垂直.)也是 iOS 11.3 中的新功能,您可以获得更详细的形状估计每个检测到的平面(参见 ARSCNPlaneGeometry),无论其方向如何.

然而,即使你有水平和垂直,平面的外部界限也只是随着时间变化的估计.也就是说,ARKit 可以快速检测墙的一部分在哪里,但它不知道墙的边缘在哪里,而无需用户花一些时间挥动设备来绘制空间图.即便如此,映射的边缘也可能无法与真实墙壁的边缘精确对齐.

所以...如果您使用检测到的垂直平面来遮挡虚拟几何体,您可能会发现应该隐藏的虚拟对象显示出来的地方,要么没有完全隐藏在墙的边缘,要么被通过 ARKit 未映射整个真实墙的地方可见.(后一个问题您可以通过假设比 ARKit 更大的范围来解决.)

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?

解决方案

You have two issues here.

(And you didn't even use regular expressions!)

How to create occlusion geometry for ARKit/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.

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.)

How to detect walls/etc so you know where to put occlusion geometry?

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.

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.

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天全站免登陆