showbase: Create Loader before ShowBase, importable from ShowBaseGlobal
This makes it possible to load models before opening ShowBase
This commit is contained in:
parent
5d465be01e
commit
343ec6b367
|
|
@ -126,7 +126,7 @@ class Loader(DirectObject):
|
|||
yield await req
|
||||
|
||||
# special methods
|
||||
def __init__(self, base):
|
||||
def __init__(self, base=None):
|
||||
self.base = base
|
||||
self.loader = PandaLoader.getGlobalPtr()
|
||||
|
||||
|
|
@ -136,8 +136,6 @@ class Loader(DirectObject):
|
|||
Loader.loaderIndex += 1
|
||||
self.accept(self.hook, self.__gotAsyncObject)
|
||||
|
||||
self._loadPythonFileTypes()
|
||||
|
||||
def destroy(self):
|
||||
self.ignore(self.hook)
|
||||
self.loader.stopThreads()
|
||||
|
|
@ -229,6 +227,10 @@ class Loader(DirectObject):
|
|||
"""
|
||||
|
||||
assert Loader.notify.debug("Loading model: %s" % (modelPath,))
|
||||
|
||||
if not self._loadedPythonFileTypes:
|
||||
self._loadPythonFileTypes()
|
||||
|
||||
if loaderOptions is None:
|
||||
loaderOptions = LoaderOptions()
|
||||
else:
|
||||
|
|
@ -416,6 +418,9 @@ class Loader(DirectObject):
|
|||
a callback is used, the model is saved asynchronously, and the
|
||||
true/false status is passed to the callback function. """
|
||||
|
||||
if not self._loadedPythonFileTypes:
|
||||
self._loadPythonFileTypes()
|
||||
|
||||
if loaderOptions is None:
|
||||
loaderOptions = LoaderOptions()
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -436,9 +436,9 @@ class ShowBase(DirectObject.DirectObject):
|
|||
self.useTrackball()
|
||||
|
||||
#: `.Loader.Loader` object.
|
||||
self.loader = Loader.Loader(self)
|
||||
self.loader = ShowBaseGlobal.loader
|
||||
self.loader.base = self
|
||||
self.graphicsEngine.setDefaultLoader(self.loader.loader)
|
||||
ShowBaseGlobal.loader = self.loader
|
||||
|
||||
#: The global event manager, as imported from `.EventManagerGlobal`.
|
||||
self.eventMgr = eventMgr
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ aspect2d = render2d.attachNewNode(PGTop("aspect2d"))
|
|||
#: A dummy scene graph that is not being rendered by anything.
|
||||
hidden = NodePath("hidden")
|
||||
|
||||
loader: Loader
|
||||
#: The global Loader instance for models, textures, etc.
|
||||
loader = Loader()
|
||||
|
||||
# Set direct notify categories now that we have config
|
||||
directNotify.setDconfigLevels()
|
||||
|
|
|
|||
Loading…
Reference in New Issue