Search Unity

How to serialize mesh visibility ?

Discussion in 'Multiplayer' started by martinf35, Aug 13, 2009.

  1. martinf35

    martinf35

    Joined:
    Jun 4, 2009
    Posts:
    6
    Hi everyone,
    I am working on an application where clients can customize their avatar by changing its clothes, eyes color etc...
    In my program I have an avatar composed of bodyparts categories (Leg, Torso, Head etc...). For a specific categorie, Legs for exemple, several mesh can be displayed (baggie, jeans, nude, etc...) which means that clothes are represented by mesh. So in order to have an avatar that is wearing pants I have to hide all other mesh in "Legs categorie" by setting the "Skinned Mesh Renderer" property to false which works well.
    But my problem is the following : when a client connects, a "customization" scene is loaded and it can modify the apparence of his avatar. When it's done, the main scene is loaded and a RPC is launched through the network to tell other players to instantiate the avatar with its skin data. Others do create the new player but it appears with all the mesh of each categorie as if they just instanciated the avatar prefab without modifying it.

    So to conclude I think that the "skinned mesh Renderer" property is not serialized so that if I hide a mesh of my avatar on the client side for instance, this won't be sent to the server and it won't be able to do the same locally on its side.

    Any idea to deal with that ?
    Thanks
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    as the costumization always is controlled by parameters that recreate the same state again if they are used again in the same situation, you can and actually would just serialize those parameters.

    Sending a mesh or at worst even textures would be a total overkill if XX numerics do the job too.


    Also those parameters are needed anyway as other clients can not refer to the mesh as mesh. You need a way to find it in the database somehow. Optimally you do that through an int identifier, not through its path as the path is significantly longer than 4 letters (what an int id would be) and I doubt you will need more than 4 billion different objects :)


    So what you need to implement is a resource manager as well as clear parametrization.
     
  3. martinf35

    martinf35

    Joined:
    Jun 4, 2009
    Posts:
    6
    Thanks for replying dreamora.

    Actually I can get the skin data on each player by sending it as a string parameter in my RPC function (but you are right the next step is to reduce its size by replacing path by ids).

    I think I didn't give details enough in the last post. To be more precise I use two NetworkViews : the first one for the animation the second one for the position. in the second one the "observed" property does not contain anything at the beginning : it's filled in the RPC function.
    Here is the basic scenario of my application that will help to understand my problem :

    - The first player loads the customization scene then the skin data are stored.
    - He connects to the masterserver. If everything's ok, the RPC function is called and buffered so that it's executed every time a new player connects
    - What is done in this RPC function is :

    1 - allocating two networkview ids (one for the animation the other one for the position)
    2 - instantiating the avatar prefab and applying the skin data.
    3 - setting up the "observed" property with my newly instantiated and customized prefab.

    I think that the problem is in the 3rd step because the network view is observing an instance of my avatar prefab with all its mesh and not the customized avatar.

    I also tested something. Having two players connected I tryed to hide a mesh of the client. On client side the mesh is hidden but not on server side. So as I instantiate a prefab with all the mesh I have to find a way to send a message like hide this !

    Even if I (hopefully) don't have 4 billion objects :) I really don't want to create a prefab for each "skin possibility".

    Don't hesitate to ask me for details if I wasn't clear enough.
    Thanks
     
  4. cj-currie

    cj-currie

    Joined:
    Nov 27, 2008
    Posts:
    337
    It seems to me that you could simply have a single RPC give the name/id/whatever of which mesh is shown and have the other clients run a script that hides all the meshes except the one identified in the RPC. The same script could even delete the other meshes to conserve space.

    It would look something like this:

    Code (csharp):
    1. function HideMeshes(notHidden : int){
    2.   for (x in meshes){
    3.     if (x.id != notHidden)
    4.       HideMesh(x);
    5.   }
    6. }
    Where meshes[] is an array of meshes on the character, and HideMesh() is a function that changes alpha/destroys the object.


    You have to remember that what the client sees and what the server sees is not the same object.