Reputation: 1611
I have an arrow in pointofview which points towards a node. I want that arrow to appear only if the node is not visible in the screen.
I have found an approach:
projectPoint 8 corners of node's boundingBox and check if:
1) Any point lies inside screen
2) Any edge from the points lie inside screen
3) Any plane lie inside screen
But it seems very big hard and messy.
So is there any simpler approach to it?
Upvotes: 5
Views: 3974
Reputation: 56625
You can use isNode(_:insideFrustumOf:)
to check if the bounding box of a given node intersects the view frustum of another node's point of view to indicate whether or not that node might be visible.
It's an instance method on SCNSceneRendered
which means that it's available on SCNView
:
if let pointOfView = sceneView.pointOfView {
let isMaybeVisible = sceneView.isNode(yourNode, insideFrustumOf: pointOfView)
// `yourNode` is in the scene's view frustum and might be visible.
}
Note, as documented, that this does not perform occlusion testing. This means that a node that appears completely behind another node (i.e. is fully occluded) may not be visible but is still inside the view frustum.
Upvotes: 17