Multiple Cameras and DisplayRegions Working

I finally got my multiple cameras and display regions working, after going through some codes on the forum.
I wanted to share it with those who like me may be green, and looking for an easy way to do this.

Models

land = loader.loadModel(“models/environment”)
land.reparentTo( render )
land.setPos(0,0,0)

model1 = Actor.Actor(“models/ralph”)
model1.reparentTo(render)
model1.setScale(.2)
model1.setPos(10, 12, 0)

model2 = Actor.Actor(“models/panda”)
model2.reparentTo(render)
model2.setScale(.2)
model2.setPos(0, 0, 0)

Camera 1

my_cam1 = Camera(“cam1”)

my_cam1.setScene(land)

my_camera1 = render.attachNewNode(my_cam1)
my_camera1.setName(“camera1”)
my_camera1.setPos(0,20,0)
my_camera1.lookAt(model2)

Camera 2

my_cam2 = Camera(“cam2”)
my_camera2 = render.attachNewNode(my_cam2)
my_camera2.setName(“camera2”)
my_camera2.setPos(0,20,0)
my_camera2.lookAt(model1)

Camera 3

my_cam3 = Camera(“cam3”)
my_camera3 = render.attachNewNode(my_cam3)
my_camera3.setName(“camera3”)
my_camera3.setPos(0,10,0)
my_camera3.lookAt(land)

Disable the default DisplayRegion, which covers the whole screen.

dr = base.camNode.getDisplayRegion(0)
dr.setActive(0) # Or leave it (dr.setActive(1))

Now, make a new pair of side-by-side DisplayRegions.

window = dr.getWindow()
dr1 = window.makeDisplayRegion(0, 0.5, 0, 1)
dr1.setSort(dr.getSort())
dr2 = window.makeDisplayRegion(0.5, 1, 0, 1)
dr2.setSort(dr.getSort())

A smaller window

dr3 = window.makeDisplayRegion(0.8, 0.9, 0.2, 0.4)
dr3.setSort(dr.getSort())

Setup each camera.

dr1.setCamera(my_camera1)
dr2.setCamera(my_camera2)
dr3.setCamera(my_camera3)

1 Like

Thanks for sharing, but

  1. please use

[code]
tags
2. next time, post it in Code Snipplets. (can some admin move this?)

EDIT: You can still edit your post using the edit button and add code tags anyway.

Thanks for the corrections. I didn’t realize.

Yeah - thanks for the post. I find the Python API to be totally bewildering! Your post got me past a (yet another) hurdle.

\d