serializing object3d with textures

Started by influt, October 15, 2009, 06:35:40 PM

Previous topic - Next topic

influt

Hello.

I am working on a game and there are several levels and player models. To my mind, the whole size of these resources is quite big for the game. So what I am trying to do is to make game client to load resources (models / textures / sounds) from the server only when they are needed. I can serialize models and levels when building a release, but the problem I am facing with is that a PolygonManager stores texture ids, not the names. Look at the following example:

I have to download one level, 3 common models and textures for all of them. A serialized object's PolygonManager knows the id of the texture for each polygon. The TextureManager has to have textures accessible by these ids. And here is the problem: when serializing, textures are read from the local disk and have their assigned ids. But these ids are different from those that are assigned when reading serialized textures (after they are downloaded) into the TextureManager. As the result, we have a model, where each polygon has a texture that was not meant to be there!
This can be solved if we will serialize the dump of the TextureManager, and then load it on a client. But that means we will have to download all textures, not just those that we need for a level.
Personally, I dont like this solution. I think that it would be great to have a model as a serialized object with all textures needed for this model in one package. Having one package for a model would be very convenient to download..
So i came to a conclusion that if jPCT had a possibility to store not just ids of textures in a PolygonManager, but texture names, that would allow me to achieve the desired effect .

Maybe I just cant see a neater solution? Maybe you can point me how can this be achieved better?

Thanks.

EgonOlsen

Storing the names instead of the ids isn't an option. It's too slow and consumes too much memory. The getState()-method in the manager was meant fot this, but as you say: This requires all textures to be loaded at once. Maybe this will work:

Before serializing the manager's state, replace all textures with a very small one (like 8*8 pixels all white or something). Use the same texture for all the entries of the manager. Dump this and load this dump at once at startup. It should be pretty lean.. Then, when loading the objects and the corresponding textures, replace the dummy textures with the correct ones. Of course, this requires that you know which object uses which textures/names. Is that a possibility? Would a new method replaceTexture(id, texture) help to ease this?

influt

#2
Yes, I thought about this. This new method would help!
I just have to serialize everything at once..


influt


EgonOlsen


EgonOlsen

I've updated the current release version with that method. It's untested...i hope it works fine. If not, please let me know.

influt