2
$\begingroup$

Previously, I've asked this question: How can I see if an object is inside the volume rendering of the camera? and I had found the solution thanks to this post: Does Camera.view_frame() return the correct size of near clip plane?

The line code x, y, z = world_to_camera_view(sce, cam, mat * v.co) is perfect for found the objects are visible from the central camera but it excludes items that are only visible from a single camera (camera L or R). I want to find the objects visible only from the right camera and objects visible only from the left camera.

A possible solution would be:

  1. Delete stereoscopy
  2. Move the camera to the right of intercular distance / 2
  3. Incline the camera to the z-axis of angle of convergence (easy calculation)
  4. Check the visible item with world_to_camera_view
  5. Repeat for simulate the left camera (move to right and rotate z -angle)
  6. Set True the stereoscopy

But how to eliminate the stereoscopy and have a camera equal to that of the left and right?


I solved my issue by following the steps I listed. Now I have this problem:

If I place the camera on the right of a value (even higher) and then use world_to_camera_view the result I get is the same. That tells me that the camera always sees the same objects.

Code

import bpy
from bpy_extras.object_utils import world_to_camera_view

context = bpy.context
scene = bpy.context.scene
scene.update

def checkIfIsInCameraView(cam, obj):
    for v in obj.data.vertices:
        x, y, z = world_to_camera_view(context.scene, cam, obj.matrix_world * v.co)
        if (0.0 <= x <= 1.0 and 0.0 <= y <= 1.0):
            return True

    return False

#set off stereo
scene.render.use_multiview = False

#creo nuova camera per simulare camera laterale
cameraNormal = scene.camera

#change camera position
cameraNormal.location.x = cameraNormal.location.x - 50.0

for obj in scene.objects:
    if obj.type == 'MESH':
        #print if in camera view
        if checkIfIsInCameraView(cameraNormal, obj):
            print(obj)

#change camera position
cameraNormal.location.x = cameraNormal.location.x + 100.0

for obj in scene.objects:
    if obj.type == 'MESH':
        #print if in camera view
        if checkIfIsInCameraView(cameraNormal, obj):
            print(obj)

#set on stereo
scene.render.use_multiview = True
scene.update

Some tips?

$\endgroup$
  • $\begingroup$ Do you really expect the difference to be big enough that an object will only be seen in one camera? $\endgroup$ – sambler Sep 5 '15 at 6:18
  • $\begingroup$ It depends on the settings of the camera and the proximity of the object. It is a typical case of "window violation" in stereoscopy $\endgroup$ – Odino Sep 5 '15 at 7:53
  • $\begingroup$ It will depend on how accurate you want to go, using off-axis convergence gives a leaning pyramid for visible volume that increases the error if your using a plain camera as the values get larger. For best results it would mean calculating the visible volume that matches every camera setting. $\endgroup$ – sambler Sep 5 '15 at 8:14
  • $\begingroup$ Sometimes, you need to use scene.update() once you've modified some properties (location, rotation) of the objects. When the scene is updated, you can use the new values. $\endgroup$ – Jonathan Chemla Sep 7 '15 at 13:02
  • $\begingroup$ @JonathanChemla. OMG! my bad! really ... I had forgotten the () thanks for the help! $\endgroup$ – Odino Sep 7 '15 at 17:17
1
$\begingroup$

Sometimes, you need to use scene.update() once you've modified some properties (location, rotation) of the objects. When the scene is updated, you can use the new values. You forgot the parentheses after the function call :)

$\endgroup$

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.