1
$\begingroup$

How to list all the objects in the FOV of the camera? I tried projecting the vertex with the projection matrix, but objects not in the view are still projected on the image plane. Hence is there any way to list all the objects in the FOV of the camera?

$\endgroup$
2
  • $\begingroup$ i edited your question, because you shouldn't use bold font because it might be considered as rude or shouting. thx. $\endgroup$
    – Chris
    Apr 5, 2023 at 12:36
  • $\begingroup$ have a look to blender.stackexchange.com/questions/45146/… $\endgroup$
    – lemon
    Apr 5, 2023 at 14:27

1 Answer 1

0
$\begingroup$

Try this script. It will print all the mesh objects in your camera's FOV:

import bpy
from mathutils import Vector
import math

print("Execute script ===================")

camera = bpy.context.scene.camera
fov = camera.data.angle
location = camera.location
direction = camera.matrix_world.to_quaternion() @ Vector((0.0, 0.0, -1.0))
visible_objects = [obj for obj in bpy.context.scene.objects if not obj.hide_render]

objects_in_fov = []
for obj in visible_objects:
    if obj.type != 'MESH' or not obj.visible_get():
        continue
    for v in obj.data.vertices:
        vertex_world = obj.matrix_world @ v.co
        to_vertex = vertex_world - location
        angle_to_vertex = direction.angle(to_vertex)
        if angle_to_vertex < fov / 2:
            objects_in_fov.append(obj)
            break

for obj in objects_in_fov:
    print(obj.name)
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .