With python, I search to select objects in the field of view of the main camera. I found this great script by ideasman42.

It's half perfect. I don't understand why the script also selects objects behind the main camera. I need help please: How to not select objects behind main camera?


Add a plane on perspective camera looking forward.

As a quick work around is to add a plane looking forward on a perspective camera, by adding this else clause circa line 32 of original code.

if not is_persp:
    # add a 5th plane to ignore objects behind the view
    n = normal(frame[0], frame[1], frame[2])
    d = -n.dot(origin)
    planes.append((n, d))
    n = (matrix * Vector((0, 0, -1)) - origin).normalized()
    d = 0
    planes.append((n, d))

A cameras line of view is its negative local Z axis. All above does is adds a plane that has a global normal looking in the same direction.

enter image description here Image shows plane with normal, the Z axis pointing in direction of camera's -Z axis.

| improve this answer | |
  • $\begingroup$ Thanks for feedback and clear captures ! I added this else condition but the result is not change. Why objects behind main camera are select ? $\endgroup$ – LukeNukem Mar 28 '18 at 9:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.