Importing shapekeys from Blender

hi, I have some issues with importing shapekeys from Blender. I tried MetaMorph by folishFrost and it worked, but I would like to export the shapekeys in C# so that I can use them directly, because loading dozens of image files and extracting shapekey information from them can take quite some time. I am also avoiding using UV because it looks like in Blender the uv values are associated with faces, while in Unity they are associated with vertices. I am hoping to map the vertices directly between Blender and Unity.

Like always, I ran into a few problems.

  1. The order of the vertices are changed when a mesh is imported from blender into unity. Online searching told me that this is because the coordinate systems are different. Is there a simple way to restore the vertex order?
  2. I tried to look up the vertices one by one by coordinates. I mapped the coordinates like this: Xu = -Xb; Yu = Zb; Zu = -Yb (u for unity and b for blender). I found no match :frowning: There was no scaling or translation of the mesh (would that have mattered?).
  3. It seems to me that in order to update the mesh, one must reassign the vertices property of the mesh.vertices. Modifying individual vertices (e.g. mesh.vertices[0].x += 1.0 ) doesn’t work. Is that supposed to be?

Please help me out. And if I am mistaken in anything, please point them out as well. Thank you!

Perhaps you’re fighting the wrong fight.

How about taking the pair of arrays metamorph makes from the images (the index of verts effected, and the shift of those verts) and just save them to a text file. Then have the game look for that text files and read it on gamestart?

also, if you can preload characters in the background, you can just have it yield every 10-100 lines of textfile read to stop lagging as well.

Good luck!

Thank you, Foolish Frost! I did not expect a direct answer from you. I learned a lot from your script. It led me into the door of mesh scripting.

I figured out how Unity imports vertices from Blender: it inverts the X coordinates then rotate around the X axis by 270 degrees without changing the local coordinates further. I was able to find the vertices in my C# script. Still, I could use a few advices:

  1. I had some spikes when using MetaMorph – singular vertices moving along their normals creating long spikes. Do you know what could have cause this problem? Could it be caused by the UV unwrapping process? Is there a recommended UV unwrapping method for MetaMorph?

  2. I do not know how to preload characters in the background. Can you give a few pointers on that?

Many thanks and happy holiday!

Well, some hings to keep in mind:

Well, first things to check:

  • Did you set the texture to 24 bit color compression import in unity?
  • Is the mip-map turned off in unity for that texture?
  • Did you make sure the UV map never overlapped on he model?

Most of the issues are due to the image being processed like a texture, instead of as pure data.

As to preloading, that about programming: I don’t offer that as a part of the free scripts since it was a tech demo. It’s expected to be handed t a coder for tweaking for specific cases, more than as a final solution.

Preloadings is taking the data arrays made from the textures, and saving them as files that can be loaded again later without processing every vert in the mesh again.

The problem with that is, if you reimport the mesh, then you may need to re-process the vert movement data for metamorph. Again, I wish I could be more specific, but I’m currently on some projects with tight deadlines breathing down my neck.

Thank you, Foolish Frost! I will look into those issue. Good luck on your project.