我有一个应用程序,可以渲染增强现实场景和一个您可以走进场景的门户。该场景被平面遮挡,无法看到,但如果您走过该平面,您就会“闯入”虚拟环境。
我不是在寻找代码,而是在寻找如何解决此问题的帮助。我想让你进入虚拟场景的唯一方法就是穿过我创建的门口。我首先考虑跟踪相机的位置,并确保在越过阈值以启用渲染之前您非常接近入口,但似乎如果我这样做,用户将无法看穿在接近/进入虚拟场景之前的门口。
最佳答案
首先看How to create a Portal effect in ARKit just using the SceneKit editor? Stack Overflow 发布了如何制作门户本身的文章。
The robust way to prevent users from passing through virtual walls is to have the same configuration of virtual walls like real walls have (where physical wall is – the virtual wall exists too).
您还需要对象检测工具。为了将虚拟墙精确定位在真实的物理墙上,只需使用 Core ML具有预先训练的小型 mlmodel
的框架以及 ARKit 框架的类,如 ARImageTrackingConfiguration()或ARWorldTrackingConfiguration() .
In case you have no opportunity to build the same configuration of virtual walls like real walls were built, you can make a user's iPhone vibrate when a user has collided with a virtual wall. Here's a code:
import AudioToolbox.AudioServices
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate)
AudioServicesPlayAlertSound(kSystemSoundID_Vibrate)
希望这有帮助。
关于swift - 我怎样才能只允许从门户进入我的虚拟场景?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55210060/