x


Is it possible to serialize a skinned mesh?

I'm quite familiar with c#'s serialization mechanism and I'm looking for information on how to properly serialize/deserialize a skinned mesh. I looked at the MeshSerializer2 class but that doesn't seem to work on skinned meshes. I presume that saving/restoring bone data will work, but I'm not sure what's involved. Does anyone have experience in this area?

more ▼

asked Jul 26 '11 at 05:37 PM

Diablo gravatar image

Diablo
1 1 1 1

I have exactly the same problem. Does anyone have a solution for this ?

Sep 19 '11 at 09:25 AM demicercle
(comments are locked)
10|3000 characters needed characters left

4 answers: sort voted first

Do you need to serialize a mesh at runtime? If not, then using AssetDatabase.CreateAsset to write the mesh to disk is by far the most efficient way to do it, since it works directly on the internal representation of mesh data and does not need to go through the C# properties.

more ▼

answered Sep 19 '11 at 01:11 PM

jonas echterhoff gravatar image

jonas echterhoff ♦♦
9.8k 7 23 104

(comments are locked)
10|3000 characters needed characters left

,Hi, thanks for your answer. I know how to use AssetDatabase.CreateAsset, and I wanted to use AssetBundles, but I don't have the choice, my client don't want to use Unity Pro. In fact I have to code some kind of framework that can read 3D files and display them. So I wrote a custom editor script that serialize a scene into and xml, and serialize all the meshes and animations into binary files.

In fact, today I managed to serialize skinned mesh by serializing boneWeights and bindposes informations (by adding some functions in the original MeshSerializer2 class), so I didn't have this problem anymore :-) Thanks anyway, I know it's a bit stupid and it will be more efficient to use Unity's asset management, but like I said, I don't have the choice. My client have to understand that the better way to keep graphics optimized in his application is to build directly into Unity, and not by parsing some xml files... But it's not the subject of this topic !

(sorry for my poor english, I'm french...)

more ▼

answered Sep 20 '11 at 08:44 AM

demicercle gravatar image

demicercle
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

Hi, thanks you for your answer.

In fact I have to load serialized meshes and animations for several platforms (iPad, iOs, Web Player...) and I know it will be better to use AssetDatabase.CreateAsset and AssetBundles, but I don't have the choice, my client doesn't want to use Unity Pro.

Today I managed to serialize skinned mesh, so I don't have this problem anymore :-) I use a csharp version of MeshSerializer2 and I add some functions to serialize boneWeights and bindposes info. I paste an exemple below for those who are interested.

static void ReadBoneWeightArrayBytes (BoneWeight [] arr , BinaryReader buf )
{
    int n = arr.Length;
    for (int i = 0; i < n; ++i) 
    {
       float weight0 = buf.ReadSingle();
       float weight1 = buf.ReadSingle();
       float weight2 = buf.ReadSingle();
       float weight3 = buf.ReadSingle();
       System.UInt16 boneIndex0 = buf.ReadUInt16();
       System.UInt16 boneIndex1 = buf.ReadUInt16();
       System.UInt16 boneIndex2 = buf.ReadUInt16();
       System.UInt16 boneIndex3 = buf.ReadUInt16();

        arr[i].weight0 = weight0;
       arr[i].weight1 = weight1;
       arr[i].weight2 = weight2;
       arr[i].weight3 = weight3;
       arr[i].boneIndex0 = (int)boneIndex0;
       arr[i].boneIndex1 = (int)boneIndex1;
       arr[i].boneIndex2 = (int)boneIndex2;
       arr[i].boneIndex3 = (int)boneIndex3;
    }
}

static void WriteBoneWeightArrayBytes (BoneWeight [] arr , BinaryWriter buf )
{
    foreach (BoneWeight bone in arr) 
    {
       float weight0 = bone.weight0;
       float weight1 = bone.weight1;
       float weight2 = bone.weight2;
       float weight3 = bone.weight3;
        System.UInt16 boneIndex0 = (System.UInt16)bone.boneIndex0;
        System.UInt16 boneIndex1 = (System.UInt16)bone.boneIndex1;
        System.UInt16 boneIndex2 = (System.UInt16)bone.boneIndex2;
        System.UInt16 boneIndex3 = (System.UInt16)bone.boneIndex3;

        buf.Write (weight0);
        buf.Write (weight1);
        buf.Write (weight2);
       buf.Write (weight3);
       buf.Write (boneIndex0);
        buf.Write (boneIndex1);
        buf.Write (boneIndex2);
       buf.Write (boneIndex3);
    }
}

(sorry for my poor english, I'm french...)

more ▼

answered Sep 20 '11 at 08:44 AM

demicercle gravatar image

demicercle
1 1 1 1

(comments are locked)
10|3000 characters needed characters left

Unity Serializer will serialize meshes as part of a level serialisation or for an individual object. It will also save materials.

http://whydoidoit.com

more ▼

answered Mar 05 at 10:55 AM

whydoidoit gravatar image

whydoidoit
33.1k 12 23 101

extremely strongly recommend Unity Serializer.

used it on many huge projects. "everyone" uses it. bizarrely it is free.

literally saved is $5000- on a project

Mar 05 at 11:56 AM Fattie
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x48
x31
x2

asked: Jul 26 '11 at 05:37 PM

Seen: 952 times

Last Updated: Mar 05 at 11:56 AM