Make a new scene graph.

On the road to grokking cameras, I am trying to make a fresh SG, attach a Camera and see a box. Could anyone help repair the code below, which just shows nothing at all right now. I guess there’s some voodoo I need to make ‘render2’ an actual visible SG.

import direct.directbase.DirectStart
from pandac.PandaModules import *

camNode = Camera('cam')
camNP = NodePath(camNode)

render2 = NodePath('render2')
camNP.reparentTo(render2)
camNP.setPos(0,-10,2)

box = loader.loadModel('box.egg')
box.reparentTo(render2)
box.setPos(0,0,0)

camNP.lookAt(box)

box.place()
run()

\d

Python is not my thing, but I think this is what going on:

You are loading the box, wich will be placed in its local space ( I guess centered in your model )
Then you reparent it to the camera node.

So in ‘world’ space, the box is now at 0,-10,2 wich is the position of your camera.
So the camera must be inside the box, and it will be fairly hard for the camera to look at its own position :wink:

Try this: (parent the box after positioning)

box = loader.loadModel(‘box.egg’)
box.setPos(0,0,0)
box.reparentTo(render2)

First of all, you need to tell the Camera what it should render. Do:

camNode.setScene(render2d)

Secondly, you need to tell the Camera where it should render into. A buffer, a window, or a part of the window, …?
So, you need to create a DisplayRegion by calling makeMonoDisplayRegion() on the buffer or window. Then call setCamera and pass it your camera NodePath.

Or you could just attach an existing display region to the camera.

Thanks rdb. I will stick to ‘render’ for now. I was only looking for an example of making a new Camera() for use in the diagrams. I got it working now.

\d

For the record, note that camNode.setScene() is no longer the preferred way to tell a camera what it should be rendering. The preferred way is simply the parent the camera into the scene graph you desire.

But, yeah, a camera requires a DisplayRegion in order to render anything. It’s really the DisplayRegion that’s doing the rendering; the camera just sets up the view properties for the DisplayRegion.

David