Xandaaah
Xandaaah

Reputation: 73

Load .egg model file from a string, not from a file

I'm making a game that'll load an egg from a server, and it has to display it. Every documentation piece says how to load an egg from a file, but not from a plaintext string, so how do I do it? I'd rather not save an egg file to a temporary directory.

My current code, if you want:

self.environment = loader.loadModel("models/world")
self.environment.reparentTo(self.workspace)

Upvotes: 0

Views: 26

Answers (1)

rdb
rdb

Reputation: 1617

You can pass in a StringStream via the EggData class and the global load_egg_data function:

from panda3d.core import StringStream
from panda3d.egg import EggData, load_egg_data

stream = StringStream(b'your egg data here')

data = EggData()
if not data.read(stream):
    print("Failed to read.")

root = load_egg_data(data)
model = render.attach_new_node(root)

Also note the existence of vfs-mount-url / VirtualFileMountHTTP, which allows you to mount your server to a directory and have Panda download the file for you.

Upvotes: 1

Related Questions