1

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?

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51
Kummmar
  • 11
  • 1
  • i edited your question, because you shouldn't use bold font because it might be considered as rude or shouting. thx. – Chris Apr 05 '23 at 12:36
  • have a look to https://blender.stackexchange.com/questions/45146/how-to-find-all-objects-in-the-cameras-view-with-python – lemon Apr 05 '23 at 14:27

1 Answers1

0

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)

Harry McKenzie
  • 10,995
  • 8
  • 23
  • 51