How to know if node is visible in screen or not in SceneKit?

佐手、 提交于 2019-12-10 19:38:53

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/47828491/how-to-know-if-node-is-visible-in-screen-or-not-in-scenekit

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!