loadmodel() from StringIO

I have a few images and models stored in a SQLite database that I would like to load into my scene. Nothing seems to be written on the subject online, but maybe someone here can help :slight_smile:

Input: raw bytes, buffer object, or StringIO
Output: Panda scene node


Have you seen Loading resources from nonstandard sources?


Yes I read that and tried using both snippets on that page. Neither a texture nor a PNMImage can be reparented, and no matter what I try I can’t seem to have the image show on the screen.

In fact, even just inefficiently writing the data to a temporary file then sending that to loadModel or OnscreenImage should work…not for me though.

You will need an understanding of the fundamental graphics primitives of Panda. To display an image, you need to load the image as a texture, then apply that texture to a card, then attach that card to a node, and attach that node into the scene graph.

OnscreenImage generally does all of this for you, but it’s primarily designed for a file on disk. However, it can also accept a Texture object as its image parameter.

In any case, it’s certainly true that writing the image data to a temporary file, then reading it via OnscreenImage (but not loadModel, which is designed for model files, not image files) would work. Note that the filename extension may be a useful hint to the image loader.

Of course, if you are loading model files instead of textures, then loadModel() should work instead, and here preserving the filename extension is crucial.