2017-09-05 5 views
0

주어진 SCNNode이 주어지면 노드의 좌표계에 지정된 점이 해당 노드의 형상에 포함되어 있는지 어떻게 확인할 수 있습니까?SCNNode point in tests

간단하면 포인트가 노드의 경계 상자 내에 포함되어 있는지 테스트 할 수 있습니까?

답변

0

이보다 더 좋은 대답이 없으면 놀랄 것입니다. 그러나 나는 하나를 찾지 못했고, 그래서 여기에 제가 가지고있는 것이 있습니다.

extension SCNNode { 
    func boundingBoxContains(point: SCNVector3, in node: SCNNode) -> Bool { 
    let localPoint = self.convertPosition(point, from: node) 
    return boundingBoxContains(point: localPoint) 
    } 

    func boundingBoxContains(point: SCNVector3) -> Bool { 
    return BoundingBox(self.boundingBox).contains(point) 
    } 
} 

struct BoundingBox { 
    let min: SCNVector3 
    let max: SCNVector3 

    init(_ boundTuple: (min: SCNVector3, max: SCNVector3)) { 
    min = boundTuple.min 
    max = boundTuple.max 
    } 

    func contains(_ point: SCNVector3) -> Bool { 
    let contains = 
    min.x <= point.x && 
    min.y <= point.y && 
    min.z <= point.z && 

    max.x > point.x && 
    max.y > point.y && 
    max.z > point.z 

    return contains 
    } 
}