菜鸟教程小白 发表于 2022-12-13 02:37:28

ios - 如何在 iOS 11 中使用 scenekit - ARKit 为 3D 对象动态创建注释?


                                            <p><p>我正在使用 <code>overlaySKScene</code> 类似的东西(<a href="https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1#" rel="noreferrer noopener nofollow">https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1#</a>)创建注释。我关注了<a href="https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay" rel="noreferrer noopener nofollow">https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay</a>创建叠加层。</p>

<p>但在提供的示例中,他们只创建了一个注释,并且它是静态的。我想根据我们拥有的子节点的数量动态创建多个注释,并且还应该能够将注释定位在各个子节点的顶部。如何做到这一点? </p>

<p>我正在添加如下叠加层,</p>

<pre><code>    sceneView.overlaySKScene = InformationOverlayScene(size: sceneView.frame.size)
</code></pre>

<p>其中 InformationOverlayScene 是 <code>SKScene</code>,我在其中添加了两个 <code>childnodes</code> 以创建一个注释。</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>使用映射到子节点数组的注释 Sprite 创建一个数组,然后执行以下操作:</p>

<pre><code>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.position)

      battleSKO.healthbars.position = CGPoint(x: CGFloat(healthbarpos.x), y: (scnView.bounds.size.height-10)-CGFloat(healthbarpos.y))
    }
}
</code></pre>

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

<p>为了防止不可见节点的注释出现(例如父对象背面的子节点),请使用 SCNRenderer 的 nodesInsideFrustum(of:) 方法。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - 如何在 iOS 11 中使用 scenekit - ARKit 为 3D 对象动态创建注释?,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/46298338/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/46298338/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - 如何在 iOS 11 中使用 scenekit - ARKit 为 3D 对象动态创建注释?