Visibility query

Is it possible to hide objects from specific camera’s whilst being visible on other camera’s? I’m using viewports.

Are you using this method:
https://www.blender.org/api/blender_python_api_2_76_2/bge.types.KX_Camera.html?highlight=setviewport#bge.types.KX_Camera.setViewport

That’s a bit of an old one and not very flexible.

There is a work around, but it’s pretty difficult and doesn’t have good performance.
The best way would be to add 2 planes in front of the main camera, render from two other cameras and assign the rendered images to the texture of the two planes.

You should use this method:
https://www.blender.org/api/blender_python_api_2_76_2/bge.texture.html?highlight=texture#bge.texture.ImageRender

and you can time the refresh() call until after you’ve hidden the items you don’t want seen.

Something like:



# make a list of things that are exclusive to one camera, by marking them with a property

if "ini" not in own:
    own['cam_1_visible'] = [ob for ob in own.scene.objects if ob.get("visible_1")]
    own['cam_2.visible'] = [ob for ob in own.scene.objects if ob.get("visible_2")]
    own['ini'] = True

# render things only visible to camera 1

for ob in own['cam_1_visible']:
    ob.visible = True

cam_1['render'].refresh()

# hide them again

for ob in own['cam_1_visible']:
    ob.visible = False

# render things only visible to camera 2

for ob in own['cam_2.visible']:
    ob.visible = True

cam_2['render'].refresh()

for ob in own['cam_2.visible']:
    ob.visible = False

# hide them again


Though I’m sure you could make a better script with better performance with work.