简体   繁体   English

iOS ARKit指向锚点的指针

[英]iOS ARKit pointer to an anchor

I have an app that has a random ARKit anchor placed in the environment. 我有一个在环境中放置了随机ARKit锚的应用程序。

I want to make a simple arrow or pointer that would point to which direction the anchor is if it is currently off the screen. 我想制作一个简单的箭头或指针,如果它当前不在屏幕上,它将指向锚点的方向。

Has anyone had to do anything similar? 有没有人必须做类似的事情? Or, do you know of any example code that I could take a look at to help me implement this feature? 或者,您是否知道任何示例代码可以帮助我实现此功能?

Thanks! 谢谢!

If you use the pointer as a UIImage you can use: self.yourSceneView.projectPoint(yourNode.worldPosition) to get the position on screen for your node and than calculate where the pointer needs to point 如果将指针用作UIImage,则可以使用:self.yourSceneView.projectPoint(yourNode.worldPosition)获取节点在屏幕上的位置,然后计算指针需要指向的位置

if the pointer is another SCNNode than use yourPointerNode.look(at: yourAnchorNode) to change the orientation of the pointer to point towards the node on the anchor 如果指针是另一个SCNNode而不是使用yourPointerNode.look(at:yourAnchorNode)更改指针的方向以指向锚点上的节点

in both cases update the locations in func session(_ session: ARSession, didUpdate frame: ARFrame) function 在两种情况下都更新func会话中的位置(_ session:ARSession,didUpdate frame:ARFrame)函数

You could create a 3D arrow, add it to your camera node so that it's always visible and give it a lookAt(your random anchor world position) constraint. 您可以创建一个3D箭头,将其添加到相机节点中,使其始终可见,并为其赋予lookAt(您的随机锚点世界位置)约束。

If your anchor is visible (use visibleNodes) then hide the arrow. 如果锚点可见(使用visibleNodes),则隐藏箭头。

Example video : https://twitter.com/londonrom/status/1060282275932372992?s=21 视频示例: https : //twitter.com/londonrom/status/1060282275932372992?s=21

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM