What should I use instead of “import direct.directbase.DirectStart” in imported modules? I need to use “render” to reparent nodepaths to it, and how to import it without importing the rest of the DirectStart stuff?
hmm i would say look at he source in showbase. It create render i guess you can create your won showbase but then it does just as much mess as “importing direct stuff” and that is probably the direct stuff you do not want.
If you don’t want a graphics window but just want render a solution is creating your own render.
render = NodePath(‘render’)
There is nothing special about render it just a nodepath just like everything else.
If you tell is what you are trying to do we might give you a better answer.
Not sure what you mean. If someone somewhere has already imported DirectStart, then “render” is available to you without importing anything–this is because DirectStart shoves lots of things, including render, into the builtins dictionary.
If you don’t want to import DirectStart at all, meaning you don’t even want to open a window, then what exactly do you mean by render? If you just want to use any old scene graph root, you can create your own render: render = NodePath(‘render’).
My code is separated in different files (main.py, camera.py, player.py and so on). In order to use “render” NodePath there, I have to import DirectStart. In other words, DirectStart is imported in several modules of the code, not only in the main.py. I checked it, it influences performance very negatively (if the DirectStart is imported in only two modules, the fps are cut in half).
Therefore, I am going to import DirectStart only in the main.py module, and need a way to import “render” in all other modules.
I have made a workaround for it. I have created a module that calls DirectStart, and makes an object for it:
class ApplicationWindow(): def __init__(self): import direct.directbase.DirectStart appWindow = ApplicationWindow()
and this appWindow is then imported into all other modules via “from window import appWindow”.
See my post above. You should not need to import DirectStart in order to use the symbols defined there.
And, right, you should not import DirectStart more than once. If you really wanted to import something, though, just import ShowBase. If you look at the contents of DirectStart.py, it’s only this:
from direct.showbase import ShowBase ShowBase.ShowBase()
So importing DirectStart simply constructs an instance of a ShowBase class (this is the object that becomes the global “base” object). You don’t want to create more than one of these, of course, but you can access the existing one once it has been created, even if you don’t import anything at all.