Check if an object is occluded by another object from camera?

Is there a way to check using a python script to check whether an object is occluded from camera by any other mesh/object in the scene?

For example, in this scene setup, how can I find out whether if the cube-looking mesh is fully/partly visible from camera?
I can do by hand using the camera-view but is this possible with the Python API?

Any help would be really appreciated!


(I am using blender v2.83.1)

1 Like

It’s certainly possible, but there is a lot of math involved. You can use a projection matrix or ray trace. You should look into how the WeightLifter addon does it (I think that is its name. There is an addon that sets weights based on whether something is in view of the camera or not).

I think you could use: https://docs.blender.org/api/current/bpy.types.Scene.html?highlight=cast%20ray#bpy.types.Scene.ray_cast

If the object returned is not the one you want it is occluded