• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by Diablo · Jul 26, 2011 at 05:37 PM · serializeskinned-mesh

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?

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image demicercle · Sep 19, 2011 at 09:25 AM 0
Share

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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by jonas-echterhoff · Sep 19, 2011 at 01:11 PM

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by demicercle · Sep 20, 2011 at 08:44 AM

,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...)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by demicercle · Sep 20, 2011 at 08:44 AM

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...)

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by whydoidoit · Mar 05, 2013 at 10:55 AM

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

http://whydoidoit.com

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Mar 05, 2013 at 11:56 AM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

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

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

10 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Can I modify a mesh via editor scripts 1 Answer

Unbind a skinned mesh in Unity 2 Answers

Type UnityEngine.GameObject is not marked as Serializable. 1 Answer

Networking color changes and other things 0 Answers

using classes in List<>'s 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges