hiding display and automatically quitting main loop

2 questions:

how do you hide the display (so that no window is displayed and visual renderings aren’t generated)?

how do you programmatically quit the main loop?

I tried using render.hide() but I am not sure what to feed it to hide my model. Ideally, I don’t want anything displayed (not even a screen). I am simply using 3D models to calculate physics of my geometries (I don’t need any visualization).

I tried quitting the main loop using either of these methods:


But, “framework” isn’t a defined variable (how do I import it? - I cant find it!). base.destroy() closes the window but the main loop continues to run.

Thanks a ton!

The main loop automatically exits when the last window is closed. So, base.closeWindow(base.win) should do the trick.

But if you don’t want a window in the first place, then you shouldn’t request one. Simply don’t import DirectStart and never create a ShowBase instance. If you do want ShowBase for some reason, you can set “window-type none” in Config.prc before instantiating ShowBase.

sorry, but if I don’t import DirectStart how do I load models? loader.loadModel() is imported from DirectStart, no?

I need to load the models to setup colliders right? How would I do collision detection without loading the models if I need the visible geometry? Just to emphasize, I do not need to visualize the geometry with my eyes, but the collision detection uses the visible geometry.

loader is part of ShowBase, which you do need to have instantiated in order to use. There are lower-level methods to load models (such as the ModelPool), although if you simply want to use the existing ShowBase interfaces, then you can follow my other suggestion, to do something like this:

from panda3d.core import loadPrcFileData
loadPrcFileData("startup", "window-type none")
import direct.directbase.DirectStart

This will start ShowBase without opening any window at all; there will be no graphics code set up whatsoever, but you will still be able to load models and use the collision system.

You don’t need any kind of rendering context in order to use the collision system, or “visible geometry”. You can use all scene graph features without a rendering context.

ok, almost there! So, everything works (no more window) except the main loop still isn’t quitting!

I am borrowing the code from the ball maze tutorial. I have a TaskMgr that calls my collision handling task or “rolltask” as is done in the tutorial.

When I am finished I call the following code:

if continue_iterating: return Task.cont
    print 'done'
    return Task.done

yet the code continues. How do I kill the mainloop so that the program finishes execution?

sys.exit(0) always works

ok, wasn’t sure if there was a cleaner way to exit the loop but this should work for now.

In the future I may be embedding this mainloop in other code that waits for it to exit (then sys.exit(0) might not be ideal).

But, till then this should do. Thanks as always!

you can control main loop on your own like this:

def main():
    global quit
    while not quit:

Then its just a matter of setting quit to True.


Thanks, I also discovered a solution that is quite simple:

taskMgr.running = False

works like a charm!