如何在 iOS 11 中使用 Scenekit - ARKit 为 3D 对象动态创建注释? [英] How to dynamically create annotations for 3D object using scenekit - ARKit in iOS 11?

查看:39
本文介绍了如何在 iOS 11 中使用 Scenekit - ARKit 为 3D 对象动态创建注释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 overlaySKScene 类似的东西创建注释(https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1#).我跟着 https://github.com/halmueller/ImmersiveInterfaces/tree/master/跟踪 %20Overlay 以创建叠加层.

I am working on creating annotations using overlaySKScene something similar to this(https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1#). I followed https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay to create the overlay.

但是在提供的示例中,他们只创建了一个注释并且它是静态的.我想根据我们拥有的子节点的数量动态创建多个注释,并且还应该能够将注释放置在各个子节点的顶部.如何实现这一目标?

But in the provided example, they are creating only one annotation and it is static. I want to create multiple annotations dynamically based on the number of child nodes we have and also should be able to position annotation on top of respective child node. How to achieve this?

我正在添加如下所示的叠加层,

I am adding overlay like below,

    sceneView.overlaySKScene = InformationOverlayScene(size: sceneView.frame.size)

其中 InformationOverlayScene 是 SKScene,我在其中添加了两个 childnodes 来创建一个注释.

where InformationOverlayScene is the SKScene in which i have added two childnodes to create one annotation.

推荐答案

使用映射到 childnodes 数组的注解精灵创建一个数组,然后执行如下操作:

Create an array with the annotation sprites that is mapped to the childnodes array, and then do something like the following:

func renderer(_ aRenderer: SCNSceneRenderer, updateAtTime time: TimeInterval) {

    let scnView = self.view as! SCNView
    //for each character
    for var i in 0...inBattleChars.count-1 {
        let healthbarpos = scnView.projectPoint(inBattleChars[i].position)

        battleSKO.healthbars[i].position = CGPoint(x: CGFloat(healthbarpos.x), y: (scnView.bounds.size.height-10)-CGFloat(healthbarpos.y))
    }
}

在渲染每一帧之前,这会更新 inBattleChars 中每个 SCNNode 的 SKSprite(在 healthBars 中)的位置.关键部分是在3D场景中根据SCNNode使用projectPoint获取SK叠加场景的2D位置.

Before every frame is rendered this updates the position of an SKSprite (in healthBars) for each SCNNode in inBattleChars. The key part is where projectPoint is used to get the SK overlay scene's 2D position based on the SCNNode in the 3D scene.

为了防止不可见节点的注释出现(例如父对象背面的子节点),请使用 SCNRenderer 的 nodesInsideFrustum(of:) 方法.

To prevent the annotations of non-visible nodes from showing up (such as childnodes on the back side of the parent object) use the SCNRenderer’s nodesInsideFrustum(of:) method.

这篇关于如何在 iOS 11 中使用 Scenekit - ARKit 为 3D 对象动态创建注释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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