Loading resources from nonstandard sources

Don't mind the mess!

We're currently in the process of migrating the Panda3D Manual to a new service. This is a temporary layout in the meantime.

If you have want to load a resource from a different spot then a hard drive or inside a multifile, say for instance database or network packet you can using a StringStream.

Here is an example that reads and image into data and then uses StringStream to feed that data into the image.

data = open('my-image-file.png').read()
# send data over network or any other place and pass it on
p = PNMImage()
tex = Texture()

But, you can go one step further. Instead of just loading textures, models, sounds or other data one at a time this way, you can load an entire multifile, which as we learned in the previous section can contain any number of models, textures, sounds and other data.

data = open('my-multifile.mf').read()
stream = StringStream(data)
mf = Multifile()
vfs = VirtualFileSystem.getGlobalPtr()
vfs.mount(mf, '/mf', 0)
smiley = loader.loadModel('/mf/smiley.egg')
Previous Top Next