Thursday, April 24, 2008

Command-Line Panda3D

Here's a neat tip worth pointing out: because Panda3D works in Python, and Python has a relatively robust command-line mode, you have a powerful realtime debugging tool in the form of command-line Panda. It's not really hard, you just may not realize it's possible. Open up a Python prompt, then run these lines:

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

That should be enough to get a window up and running. As you test more and more things out, remember you'll probably have to call the run() function every now and then to get tasks to run, do some extended interaction or that sort of thing. While Panda3D is actually "running," you won't have the command-line available.

When you want to pause the system and do more debugging, simply raise a KeyboardInterrupt exception, and Panda3D will freeze and return control to the command-line. You may want to write a module that does all of this for you, like, say:

from pandac.PandaModules import *
from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
class debugObj(DirectObject):
 def __init__(self):
  self.accept("space",self.interruptPanda) #any unused event, really
 def interruptPanda(self):
  raise KeyboardInterrupt()


Woohoo, now you can load modules and run Panda3D stuff to your heart's content, with the ability to freeze execution and evaluate variables at any moment.