我正在使用类似于此的 overlaySKScene
创建注释( https://sketchfab.com/models/1144d7be20434e8387a2f0e311eca9b1# )。我关注了https://github.com/halmueller/ImmersiveInterfaces/tree/master/Tracking%20Overlay创建叠加层。
但在提供的示例中,他们仅创建一个注释,并且它是静态的。我想根据我们拥有的子节点的数量动态创建多个注释,并且还应该能够将注释放置在相应子节点的顶部。如何实现这一目标?
我正在添加如下所示的叠加层,
sceneView.overlaySKScene = InformationOverlayScene(size: sceneView.frame.size)
其中InformationOverlayScene是SKScene
,我在其中添加了两个子节点
来创建一个注释。
最佳答案
使用映射到子节点数组的注释 Sprite 创建一个数组,然后执行如下操作:
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 中)的位置。关键部分是projectPoint用于根据3D场景中的SCNNode获取SK叠加场景的2D位置。
要防止不可见节点的注释显示(例如父对象背面的子节点),请使用 SCNRenderer 的nodesInsideFrustum(of:) 方法。
关于ios - 如何在 iOS 11 中使用 scenekit - ARKit 动态创建 3D 对象的注释?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46298338/