RealityKit –在检测到的平面上可视化网格
我想在检测到的平面上绘制网格点,如 ARCore 中所示视频链接,我不知道如何实现它。
你能帮我实现这个目标吗?提前致谢。
I want to draw the mesh point on the detected plane as shown in the ARCore video link and I don't know how to achieve it.
Can you help me out to achieve this? Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ARKit
|RealityKit
中的经典网格可视化在这篇文章中,我想向您展示如何使用 ARKit/RealityKit 框架启用平面检测过程的“经典”可视化。但在这种情况下,我不保证您能够以视觉上令人愉悦的方式可视化网格,因为它是在 Google ARCore 中实现的。
但是,为了可视化检测水平和垂直平面的过程(类似于您在 ARCore 中看到的行为),您应该使用场景重建方法,即使用 LiDAR 扫描仪。但这是一个不同的故事,因为您必须使用金属来实现程序纹理,并为前缘设置软蒙版。
这是代码:
ViewController.swift
ARSessionDelegate
仅可以更新共面检测到的平面。
PS
如果您有兴趣在 RealityKit 中可视化
Canonical Face Mask
,看看这篇文章。Classic grid visualization in
ARKit
|RealityKit
In this post, I want to show you how to enable the "classic" visualization of the plane detection process with ARKit/RealityKit frameworks. But in this case, I don't promise you to visualize a grid in such a way that is visually pleasing, as it's implemented in Google ARCore.
However, in order to visualize the process of detecting horizontal and vertical planes similar to the behavior you can see in ARCore, you should use the scene reconstruction methodology, i.e. using a LiDAR scanner. But that's a different story, because you'll have to use Metal to implement a procedural texture with a soft mask for the front edge.
Here's a code:
ViewController.swift
ARSessionDelegate
Only coplanar detected planes may be updated.
P. S.
If you're interested in visualizing the
Canonical Face Mask
in RealityKit, take a look at this post.扩展安迪的答案:
由于我真的很想使用金属纹理,而且安迪提供的答案很遗憾没有为我更新平面边界,我想出了这个解决方案:
首先,我使用自定义金属表面着色器:
然后,我创建了一个与 Andy 类似的平面,所以感谢这部分:)
值得注意的是,它对 didUpdate() 函数和平面范围的检索方式进行了一些更改,因为 Andy 的代码使用了 Apple 已弃用的函数。另外,我将其重命名为“ARGrid”,这样它就不会与 SwiftUI 的 Grid() 冲突。
最后,我在 ARView 代理函数中实现了一些更改:
我对 Metal 还很陌生,这是我的第一个项目。因此,如果我在某个地方搞砸了,我会非常高兴收到改进这一点的建议。
希望这有帮助
Expanding on Andy's answer:
As I really wanted to use a Metal texture and also the answer provided by Andy sadly didn't update the plane bounds for me, I came up with this solution:
Firstly, I used a custom Metal Surface Shader:
Then, I created a Plane similarly to Andy, so thanks for that part :)
Notably, it has some changes to the didUpdate() function and the way the plane extent is retrieved, as Andy's code is using functions that Apple has since deprecated. Also, I renamed it to "ARGrid", so it wouldn't conflict with SwiftUI's Grid().
Lastly, I implemented a few changes in my ARView Delegate Functions:
I'm still very new to Metal, this being my first project. So I'd be more than happy about suggestions for improving this, if I messed up somewhere.
Hope this helps
我改进了 Andy 的代码,以解决一些崩溃问题(当尝试接近数组上的 [0] 时),或者创建名称无效的纹理,并更新它(范围不再使用):
网格:
ARSessionDelegate:
ViewController (我没有更改)
I improved Andy's code, to solve some crashes ( when trying to approach [0] on array), or creating a texture with invalid name, and also update it (extent is no longer in use):
Grid:
ARSessionDelegate:
ViewController (which I didn't change)