Author Topic: serializing object3d with textures  (Read 4088 times)

Offline influt

  • byte
  • *
  • Posts: 25
    • View Profile
serializing object3d with textures
« on: October 15, 2009, 06:35:40 pm »
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.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: serializing object3d with textures
« Reply #1 on: October 15, 2009, 09:04:18 pm »
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?

Offline influt

  • byte
  • *
  • Posts: 25
    • View Profile
Re: serializing object3d with textures
« Reply #2 on: October 16, 2009, 04:31:32 pm »
Yes, I thought about this. This new method would help!
I just have to serialize everything at once..

« Last Edit: October 16, 2009, 05:10:03 pm by influt »

Offline influt

  • byte
  • *
  • Posts: 25
    • View Profile
Re: serializing object3d with textures
« Reply #3 on: October 16, 2009, 06:36:24 pm »
Any chances to see that method soon?

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: serializing object3d with textures
« Reply #4 on: October 16, 2009, 09:01:20 pm »
Yes, i'll add it next week.

Offline EgonOlsen

  • Administrator
  • quad
  • *****
  • Posts: 12295
    • View Profile
    • http://www.jpct.net
Re: serializing object3d with textures
« Reply #5 on: October 19, 2009, 03:48:41 pm »
I've updated the current release version with that method. It's untested...i hope it works fine. If not, please let me know.

Offline influt

  • byte
  • *
  • Posts: 25
    • View Profile
Re: serializing object3d with textures
« Reply #6 on: October 19, 2009, 04:31:17 pm »
thanks a lot