检查SCNNodes是否在视图中重叠

问题描述 投票:0回答:1

如何检测两个SCNNodes是否在SCNView重叠?它们被添加到different x an z axis位置,但是从相机的位置看起来它们重叠在一起。我想检测到这个,然后向上或向下移动其中一个。 enter image description here

swift scenekit arkit scnnode
1个回答
0
投票

对于那些以后会遇到这个问题的人...我用SCNNode的simdWorldPosition属性修复了这个问题。这是代码:

let overlapping = wayNamedLocationNode.infoTextNodes.filter { overlappingTextNode in
                    let x = abs(overlappingTextNode.simdWorldPosition.x - textNode.simdWorldPosition.x)
                    let z = abs(overlappingTextNode.simdWorldPosition.z - textNode.simdWorldPosition.z)
                    if ((x < 4 && x > 0) || (z < 4 && z > 0)) {
                        return true
                    } else {
                        return false
                    }
                }
if overlapping.count > 0 {
     overlapping.forEach { $0.removeFromParentNode() }
}

首先,我找到了所有重叠的节点,然后我只是从父节点中删除它们。

© www.soinside.com 2019 - 2024. All rights reserved.