Search Unity

Presenting MetaMorph Toolkit for Blender and Unity

Discussion in 'Made With Unity' started by foolish-frost, Jan 26, 2011.

  1. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169

    I've been working with Unity since the first day it was released for windows, and have always been interested in how it works with Blender. The ease of taking an animated character from Blender into unity and just having it work without a ton of tweaking amazed me.

    ...But shapekeys, the mesh morph system for Blender, didn't work.

    I came to the conclusion the current methods did not work for importing shapes, for the following reasons:
    • Importing the shapes generally took reimporting the mesh for every shape, and hoping the mesh data all read the same in regards to the number and order of verts. (They never did)
    • They tended to be slow, updating the whole mesh every frame, dropping frame rates on complex meshes regardless of what was morphed.
    • Most didn't have any API built in to easilly get started using it, and were no more than concept proofs.

    After a month of examining the possible options, I came to the conclusion I couldn't find anything that would work in a production environment.

    I'm not saying that none of them worked, Just that they did not seem to be solutions I would have paid for and used. That got me thinking about what I WOULD pay for in a tool
    • It would need to use a standard file format for storing morph shapes that can easilly be applied to a mesh regardless of how the importer organized it.
    • It would need to be fast, and only do as much work as needed to change the morphing areas of hte mesh.
    • It would need to be able to stick the UV seams of the mesh back together after all morphs are applied to the mesh. (to stop tearing from float errors on xyz position)
    • It would need to be able to export/import full animation made up of possibly dozens of shapekeys, and play them back perfectly in synch with bone animation.
    • A full API for other coders to make use of it without having to rewrite the MetaMorph script.

    Based on that laundry list of features, I started coding MetaMorph. It includes a Diff Map exporter for Blender, The MetaMorph code in UnityScript for Unity, and all needed files to test it out. The project contains the full scene, but the only file you need for your own projects is MetaMorph.py.

    Charon MoonyMetaMorph is a Unity3d and Blender3d toolkit that allows mesh animation in Unity games using Blender shapekeys. It includes an export script for Blender that converts shapekeys into Diff maps and saves the animation data as text files. The MetaMorph script for Unity can read the Diff maps and animation data in order to play back the morph animations in real time.

    You can find the kit at rezzable.com: http://rezzable.com/blogs/foolish-frost/presenting-metamorph-toolkit-blender-and-unity
     
  2. granada

    granada

    Joined:
    Oct 31, 2010
    Posts:
    135
    Ha Ha,loved the demo.My wife keeps playing it back.This looks realy cool.

    Dave
     
  3. niosop2

    niosop2

    Joined:
    Jul 23, 2009
    Posts:
    1,059
    Awesome work, I love the way you worked around vertex reordering using texture maps, great thinking.
     
  4. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Thanks. That was inspired by normal maps. Even made it so you could pick the UV layer to use for those models that had overlapping uvs for textures. Just make a second uv layer with non-overlapping uvs, and use that, and you're good to go.

    And yeah, Charon Moony is cool as a mascot. Had to make something I could give away with the kit, so I put him together in about a day or two. I think he looks pretty good for a speed model.

    The REALLY long bit of work was the speed optimization for making the morph changes. Had to make a pair of arrays: One with the vert morph vector, and the second what vert it points at in the original mesh. It only keeps track of points that moved, and so facial animation on a full body mesh only loops for the face verts morphed. The UV seam sealer works the same way, recording overlapping verts during startup, and making sure they STAY overlapping after all the morphs are applied.

    Overall, I'm very happy with the speed on this, considering what it does.
     
  5. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Does this work with 2.49b or just 2.5x? Looks pretty cool, I'm sure a bunch of Blender users will be happy with this. :)
     
  6. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Blender 2.56b. I really found no reason to support older blender versions, since the new beta is generally as stable as the original 2.49 release.

    That and the fact you can always pull your project file forward into 2.56b, while you can't really go back as easily.
     
  7. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    I wonder if it will work with the diff maps I can export in lightwave from dp vectorcast... gonna have to test it!
     
  8. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Side note. MetaMorph is now available as a free Unity asset store item. Enjoy!
     
  9. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    Can it be used with a normal mesh renderer instead of a skinned renderer?
     
    Last edited: Jan 28, 2011
  10. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    It has a checkbox allowing you to pick if the mesh is a boned mesh or not, yes. So it can be used on a building wall with damage levels, for example.
     
  11. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    Awesome, managed to export a morph from Lightwave!

    http://db.tt/GzH6KKv

    Now I just need a good way to export a script...

    I wonder if there's a way to convert papagayo scripts to work with it.

    Would it be possible to add support for floating point exr morph maps? The setup I'm using has the option, with black as zero point rather than gray, using pos/neg values.
     
    Last edited: Jan 28, 2011
  12. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Well, I think the answer to that would be: OpenSource means ANYTHING is possible. Would have to figure out if blender can save those as well.

    Generally, the function Load_Diff_Maps() has all the read calculations, so if the data we get out needs changing, we can work with that.

    Perhaps adding a checkbox for each diffmap in Diff_Map_class would allow that. How about Floating_Point : boolean?

    Might want to test more complex meshes to see if it has any problems. A facial set works wonders for testing.
     
  13. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    I used that just to be quick for testing; sadly vectorcast won't work with lightwave morphs, so I needed to create separate meshes for each shape. I've got a character set up for it now, so gonna be tweaking some settings to get it looking good.

    And a floating_point boolean would be perfect.
     
  14. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    But you CAN generate Diffmap color tgas from Lightwave you say?

    That's amazing, actually. Let me know if you want to make a note on how to export them.

    Animations are based on scalar Blender Shapekeys for each frame, so I can't say how Lightwave would do animations.

    Mind you, nothings stops you from exporting the mesh to Blender, shapekeying it there, and then just using the diffmaps and animation files from blender with your lightwave model in Unity.
     
  15. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    I used the Denis Pontonnier custom node Vector Cast. Not too much adjustment, just had to set it to normalize the output and use 24 bit instead of floating point.

    Lightwave morph animations are a separate channel for each morph, and curve based. Sorta annoying to export, so I'm not sure the best way to go about that.
     
  16. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Well, that sounds like blender. I just grab the value of how much the morph is effecting the mesh (0 means not at all, 1 means normally, -1 means reveresed, 1.1 means more than normal) for every frame and output it in a list format like a bvh. <look the demo for the formal>.
     
  17. pinkhair

    pinkhair

    Joined:
    Dec 17, 2010
    Posts:
    141
    Yeah, I managed to make a pretty simple script by hand. Automating it is the tricky part as usual^_^
     
  18. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Does anyone know if 3dmax has the option to output morphs like this?
     
  19. middleman

    middleman

    Joined:
    Mar 10, 2011
    Posts:
    4
    Has anyone attempted to use MetaMorph on a mac yet? I'm trying to export single shapekeys (not animations) from blender 2.56a (I've looked everywhere for blender 2.56b, but it appears that this may have been a typo seeing as it is not available on blender's site or anywhere else I can find). The error says that at line 201 of the "generate_diffmap_from_shape" file the local variable "path" is referenced before assigment. The 201st line reads "image.filepath = path".

    The mesh I am trying to export has a UV map and an armature- I thought the armature may have been the problem, but the error did not change after unparenting the mesh. Has this problem arisen before? I have searched several forums and found nothing about any errors at all, let alone this specific one. Does anyone have any ideas?

    -Middleman
     
  20. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    seems that being due to the fact of an error on lines 198 and 199

    Code (csharp):
    1.         elif bpy.app.build_platform.find("Mac") != -1:      
    2.             path = filepath + '/' + name + '-' + shape.name + '.tga'
    3.        
    4.         image.filepath = path
    Obviously, "Windows" and "Linux" work fine, But mac is an incorrect option for bpy.app.build_platform.find()

    I advise changing the code like this for yourself:

    Look for line 190.

    Take the following code:
    Code (csharp):
    1.         # Construct complete filepath  
    2.  
    3.         if bpy.app.build_platform.find("Windows") != -1:
    4.             path = filepath + '\\' + name + '-' + shape.name + '.tga'
    5.                    
    6.         elif bpy.app.build_platform.find("Linux") != -1:      
    7.             path = filepath + '/' + name + '-' + shape.name + '.tga'
    8.  
    9.         elif bpy.app.build_platform.find("Mac") != -1:      
    10.             path = filepath + '/' + name + '-' + shape.name + '.tga'
    11.        
    12.         image.filepath = path
    And make it:
    Code (csharp):
    1.         # Construct complete filepath
    2.        
    3.         path = filepath + '/' + name + '-' + shape.name + '.tga'
    4.        
    5.         if bpy.app.build_platform.find("Windows") != -1:
    6.             path = filepath + '\\' + name + '-' + shape.name + '.tga'
    7.                    
    8.         elif bpy.app.build_platform.find("Linux") != -1:      
    9.             path = filepath + '/' + name + '-' + shape.name + '.tga'
    10.  
    11.         elif bpy.app.build_platform.find("Mac") != -1:      
    12.             path = filepath + '/' + name + '-' + shape.name + '.tga'
    13.        
    14.         image.filepath = path
    That should allow it to work.

    Sorry about that.
     
  21. middleman

    middleman

    Joined:
    Mar 10, 2011
    Posts:
    4
    This doesn't seem to work. I tried metamorph on my windows partition and it works great, I would just prefer to not have to switch between the two constantly.

    -MiddleMan
     
  22. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
    I'm working on a MAC with OS X 10.6.6. Blender 2.56a
    In the MetaMorph Blender Manual.txt it says:
    Drop the "Diff Map Animation Exporter.py" into your addons directory.
    Activate the plugin in the Add-Ons menu under Import-Export

    There is no addons directory that I could find. I did bring up the User Preferences window and clicked on the Add Ons tab.
    At the bottom, I clicked on Install Add-On. Then navigated to Diff Map Animation Exporter.py and
    Clicked on Install Add-On in the upper left.

    It does not appear with the other addons that are there when you press the Add Ons tab at the top. Why?
    When I try and install it again, the following message appears:
    /Applications/blender-2/blender.app/Contents/MacOS/2.56/scripts/addons/Diff Map Animation Exporter.py
    is already installed.

    In Blender, when I select a mesh that has ShapeKeys and then
    in the Properties window select the Object Data Tab
    the Diff-Map Exporter does not appear.

    Maybe Diff Map Animation Exporter.py is not activated. How do you do that?
    Thanks for any and all help.
     
  23. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
    I found Diff Map Animation Exporter.py listed with the other addons under import/export and checked the box to
    activate it. One problem solved.
     
  24. ron333

    ron333

    Joined:
    Jan 3, 2009
    Posts:
    47
    Middleman,

    I changed the code to:

    # Construct complete filepath

    path = filepath + '/' + name + '-' + shape.name + '.tga'

    if bpy.app.build_platform == 'Windows' :
    path = filepath + '\\' + name + '-' + shape.name + '.tga'

    elif bpy.app.build_platform == 'Linux' :
    path = filepath + '/' + name + '-' + shape.name + '.tga'

    elif bpy.app.build_platform == 'Mac' :
    path = filepath + '/' + name + '-' + shape.name + '.tga'

    image.filepath = path

    and it generated the .tga files! On my MacBook, this took several minutes.
     
  25. middleman

    middleman

    Joined:
    Mar 10, 2011
    Posts:
    4
    I got it to work! Thank you guys so much! Apparently Blender has some interesting rules around updating/reinstalling add-ons.... But no worries. Its working just fine now.

    -Middleman
     
  26. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Glad to help!
     
  27. kilnan

    kilnan

    Joined:
    Jan 11, 2011
    Posts:
    4
    hi, i'm trying to use metamorph with blender 2.5 (2.57.1)

    I've imported and activated the .py correctly, but i cant find the export window!

    It's supposed to be in properties->object data but I can't see it!

    Thank you in advance!
     
  28. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
    Hey Frost,

    Thanks so much for this great tool! One small question though: I seem to be getting a lot of tearing - both with Charon and my own little mock-up. I read in your first post that one of the requirements was UV seam-stitching. Have you gotten around to doing so and am I just missing something?

    -Patrick

    PS: @Kilnan: A bit late, but you can find it under the Export menu, or you can just press 'space' and search for 'diff'.
     
  29. foolish-frost

    foolish-frost

    Joined:
    Mar 18, 2009
    Posts:
    169
    Anyone else getting tearing? Stitching is already installed, so we should not see it if the verts are really right on top of each other.
     
  30. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    Does this work in Blender 2.58 ?

    I can't seem to activate it in the Add-Ons list, it's grey and I can't tick it for some reason (all other add-ons in the list can be ticked as normal).

    Edit:
    Nevermind, I just found the 2.58 version of the script on the website.
     
    Last edited: Aug 1, 2011
  31. Zomby138

    Zomby138

    Joined:
    Nov 3, 2009
    Posts:
    659
    I'm getting the tearing along UV seams :\
     
  32. rambramdt

    rambramdt

    Joined:
    Jul 15, 2011
    Posts:
    14
    I have problems with the Array class in Unity. Any idea what's going on?
     
  33. parker

    parker

    Joined:
    Nov 1, 2011
    Posts:
    1
  34. rockysam888

    rockysam888

    Joined:
    Jul 28, 2009
    Posts:
    650
    (bookmarked)
     
  35. sidthekid

    sidthekid

    Joined:
    Feb 1, 2012
    Posts:
    1
    I am having the same problem on 2.56, 2.57, 2.58 on Mac OS 10.7 Intel. I have made the suggested mod from line 196 to 209 for mac compatibility. In the console I get no errors, I see the option for Export Metamorph Diff Map Animation and am able to activate it. Nothing new shows up under Properties>Object Data for a Mesh with shape keys. Any idea what I am doing wrong.

    Thanks!
     
  36. smoke

    smoke

    Joined:
    Aug 10, 2012
    Posts:
    6
    Hello,
    I've got a lot of troubles trying to make that plugin working.
    I tried Blender 2.56beta / 2.57 / 2.58 / 2.59 and for each version I tried both downloadable version of "io_export_diffmap.py".
    Sometimes I see the plugin in the addons list, sometimes I can tick it, sometimes not, and when I'm able to tick it, I don't have that "Diff-Map Exporter" window properties in Object Data..

    That's an old post and it'll be a miracle if someone give me a solution.. But let's try..

    Thanks.
     
  37. James Worth

    James Worth

    Joined:
    Aug 15, 2012
    Posts:
    16
    I have the same problem :/
     
  38. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Does not work with Blender 2.63.22 on mac.

    Keep trying! :)

    The file Charon.blend included with the download begins with the string "BLENDER_v256REND", indicating that this blend was authored with Blender 2.56. Unfortunately, http://www.blender.org/development/release-logs/blender-256-beta/ does not seem to have a working download link. The download link just redirects to http://www.blender.org/ :(
     
    Last edited: Jan 4, 2013
  39. WarpZone

    WarpZone

    Joined:
    Oct 29, 2007
    Posts:
    326
    Got it working. I used the main export script on this page: http://rezzable.com/metamorph/downloads with Blender 2.57b which I happened to have already installed.

    Also, despite the fact that release notes pages for old versions of blender exist and have "click here to download" links, the only way to actually download older versions of blender is from this page: http://download.blender.org/release/ That may not be obvious if you just Googled Blender + download + 2.56.

    It still doesn't help anyone who has content authored from a newer version of Blender, but hopefully it'll help a few people.
     
    Last edited: Jan 4, 2013
  40. Pauls

    Pauls

    Joined:
    Nov 12, 2012
    Posts:
    46
    Yep, thanks for posting the solution!
     
  41. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    @warpzone (and others) :

    The functionality of shape keys changed in 2.63 and later versions.

    BMesh in 2.63 - scroll down to "General Improvements"

    The "parker script" works in 2.61 and 2.62 - see my video HERE

    cheers, gryff :)
     
  42. ashess

    ashess

    Joined:
    May 3, 2013
    Posts:
    5
    ugh. I must be doing something wrong. can anyone help?
    I right now have Blender 2.66a, 2.60, 2.56b and 2.59 on my computer. (wondows 32 version) in 2.66a and 2.60, the file version 1.1.2 loads into the addon folder no problems, and I can select it. But when selecting a mest (even the Charon file), there is no difmap exporter to be found anywhere in the object data tab. and I looked, a lot. I can do file-> export> difx and animations, but that gives errors. presumably because I haven't fixed the settings yet? (line 464). I've tried everything I can think of by now. please help!
     
  43. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    Ashess - here are my suggestions.

    1. Install Blender 2.61 from the download archive HERE. Use the zip download NOT the .exe version. I create a directory called Blender 2.61 (for example) then unzip the file I downloaded into that directory maintaining all the same directory names. Then I create an icon on my desktop to the blender.exe file.

    I use the zip file because of this message on the blender download page:

    Provided the Blender binary is in the original extracted directory, Blender will run straight out of the box. No system libraries or system preferences are altered.

    I'm not sure quite what the executable version does - but the most common error with the Metamorph script seems to have to do with file locations.

    2. Download the "parker script" which will work in Blender 2.61 and 2.62. Download it HERE . I then just manually drop that script in the "addons" directory.

    That changed, I believe, when foolish frost upgraded his original diffmap exporter script to work with 2.58. Only the 2.56 version had an export button in the object tab.

    There is a Unity thread HERE with more details that I have posted

    cheers, gryff :)
     
  44. ashess

    ashess

    Joined:
    May 3, 2013
    Posts:
    5
    HeyHey griff, thank you for replying so soon!
    I have done as you suggested, and the addon shows well enough in the user preferences. but when I click charon, all I get for Object Data is Custom properties, Normals, Texture Space, Vertex Groups, Shape Keys, Uv maps and Vertex colors. trying to do file->Export ->Export Difmaps and Animations gets me a dialogue, but pressing theexpot Diffmaps button give me an error:

    File: (location io export script: line 474, in execute main ( ...)

    ... object has no name.
    putting in a name gives an invalid path warning though. putting in an existing folder name gives the same warning.

    Do you have any idea what is going on?
    thank you!
     
  45. ashess

    ashess

    Joined:
    May 3, 2013
    Posts:
    5
    urg. never mind!I figured it out after reading in the other thread that it took about a minute to export the examples you gave. I tried m too, and indeed, it took a minute. it worked.
    but if you don't realise it's working, and you re-click the 'export difmaps' button while the pc is working, THEN you get an error message!
     
  46. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    ashess wrote:

    That is as it should be ashess. As I said above, the "button" in the object panel went when foolish frost upgraded his script for 2.58.

    Now the creation of the DiffMaps is done with File->Export->DiffMaps and Animations - for the updated version of the script

    Can you send/post a screenshot of the export settings you are using (or trying to use) when you do this for the "moon" demo - as the screen looks JUST before you press the button that says "Export Diff v 1.1.2"?

    Ohh and what operating system are you using?

    cheers, gryff :)

    I guess I was a little slow gryff ;-)
     
    Last edited: May 6, 2013
  47. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    Glad you got it working ashess

    It actually works rather nicely I think. If you downloaded my example files - use my scripts in Unity. (Metamorph and humanshape key.js) as I fixed a little bug that could prevent them compiling properly. In fact you may want to use my example model (Male_Head) and scripts etc - as the whole thing is a lot less cluttered with moon demo..

    Let me know if you run into problems with the Unity side of things - that is where I tore out some hair ;-)

    cheers, gryff :)
     
  48. ashess

    ashess

    Joined:
    May 3, 2013
    Posts:
    5
    haha! oh dear, and im only just getting started with importing to Unity! heh. indeed, maybe I'll start with your files. I had a bit too many shape-tweens for things to hurry, and blender sorta crashed. I think I got them all though.ah, first, testing!
     
  49. gryff

    gryff

    Joined:
    Apr 17, 2012
    Posts:
    360
    ashess, I always believed in onestep at a time. The head model is simple - low vertex count (remember the script is trying to produce a map of all vertices) and if you have a lot of shape keys that is a lot of maps. Right now I can generate a basic lipsync by just using 3 shape keys. The files I posted include a pic of the Unity settings - that is where I had grief. If you use my files stick with my exact settings in the scripts.

    Anyway, I'm here if you need help.

    cheers, gryff :)
     
  50. ashess

    ashess

    Joined:
    May 3, 2013
    Posts:
    5
    thanks :D
    I *think* I have pretty close to your settings now. though when Unity opens blende files for me, i chooses Blender 2.60 instead of 2.61. ( I did take the zip files for blender 2.60, and it runs fine, but selecting 2.60 as the start-up choise doesnt seem to wok); but that version should work fin as well, right? When starting up my new project with the assats imported (map says meamoph assets), I get a warning in console:
    Assets/MetaMorph/Scripts/PlayMoon DEMO.js(262,53): BCE0017: The best overload for the method ' MetaMorph.mm_Animae_Play(String, float, int)' is not compatible with the argument list ' (String, float)'.
     
    Last edited: May 7, 2013