Is there a way to spawn multiple instances of Panda3D, or at least the Bullet phyics?

I’m using Panda3D with Bullet as a 6DOF environment for Reinforcement Learning with Stable Baselines. In order to effectively train agents I want to execute multiple instances in parallel. Showbase doesn’t allow multiple instances to be spawned, but I never need to visualize more than one instance at a time.

So I’m trying to make ShowBase optional. But without Showbase, I don’t have the render nodepath to which all my phyics objects attach. Is there a way to run only bullet without Showbase? Or is there a way to get multiple Showbase instances after all? Or a different solution entirely?

Thank you.

Unless Bullet prohibits this, it seems to me that you could simply keep multiple BulletWorlds, updated in some task or other. These could be associated with separate scene-graphs disconnected from “render”, attached there only when you want to visualise one or another scene.

Something like this (in sketch):

class MySim(ShowBase):
    def __init__(self):
        # All the usual ShowBase and app-startup stuff here,
        # omitted for brevity

        self.worlds = []
        for i in range(NUM_WORLDS):
           world = BulletWorld()
           root = NodePath(PandaNode("world root"))
           self.worlds.append((world, root))

           # More initialisation here...

    # This may not be the ideal way to do the following;
    # I'm doing it this way for simplicity and example
    def addCollisionNPToWorld(self, worldIndex, nodePath):
        world, root = self.worlds[worldIndex]

    def update(self, task):
        for world, root in self.worlds:
            world.doPhysics('''<Whatever parameters you intend>''')
        return task.cont

There might be more work to be done if any sort of culling of visible geometry is required, but that may be soluble in some way, I think.

Thank you for the pitch, that helped me a great deal. I ended up implementing it a bit differently because I need the instances to be created as individual classes. If rendering is needed I create my showbase class normally and if not, I just never call showbase.init() and the bullet nodes will be attached to a root node.

Again thanks!

1 Like