Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Bake cloth simulation from Blender to Unity?

Discussion in 'Animation' started by Olipool, Jan 28, 2020.

  1. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Hi all,

    I am trying to implement an opening curtain in Unity. It covers a window and when the player clicks on it, it will move to one side. Since it doesn't need to be dynamic I made the simulation in Blender (because navigating the space and setting things up feels easier for me than using Unity for that task.
    Now I got 200 frames of curtain animation but don't know how to get this mesh animation to Unity. Most tutorials deal with armatures or bones and the importer in Unity does not recognize the baked animation in the FBX file. I tried a recommended way to export and import as .mdd file in Blender that creates shape keys for every frame but those aren't recognized as well.

    Any ideas for me?

    Thanks! :)
    curtainExportProblem.JPG
     
    Palmi1120 likes this.
  2. Olmi

    Olmi

    Joined:
    Nov 29, 2012
    Posts:
    1,553
    One idea that might work is that you could tween between meshes that you import so that they have same point order.
    This would also allow you to only have the amount of keyframes (meshes) you need. I'm not sure how fast this might perform and if it's good idea for your use-case, but certainly doable. But you would need to write / or get some code for this.
     
    Olipool likes this.
  3. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Thanks, this is a nice idea but more suited to a handful of meshes, I guess I would need a lot of meshes because the simulation is not very "linear" to tween. It would surely work, I could even switch the whole mesh every frame, but it sounds like a "hack" :)
     
  4. IlisanVlad

    IlisanVlad

    Joined:
    Dec 3, 2017
    Posts:
    30
    Have you figured it out? Thank you
     
  5. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Thanks to a video tutorial I was able to bring a shape key animation to Unity:

    But it is not complete for dealing with cloth, I learned how to make shape keys from cloth simulation using mdd exporter: https://blender.stackexchange.com/q...-use-shape-keys-to-bake-a-soft-body-animation

    So it worked, now I am putting everything together and simulate and export a real curtain with wall fixtures etc., import it in Unity, check if I can trigger the animations with an animator controller and if that works, I will try to post the solution here again. :)
     
  6. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320


    So that is the final result so far. It has way too many polys but I don't care right now :D
    I hope I will find the time to make a small video tutorial about that at the weekend. The key to success was to delete the cloth modifier before exporting (but of course have the shape keyframes from the mdd import) and in the fbx export settings UNCHECK NLS strips and All actions.
     
    Batuhan13, kjelyazkov and Olmi like this.
  7. Batuhan13

    Batuhan13

    Joined:
    Apr 9, 2017
    Posts:
    117
    Hello Olipool this curtain is really looking great I am wondering have you found a time to make a small tutorial video about that =) If you could you share it with me :D
     
  8. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Hi Batuhan, thanks for the compliment :) I had to solve so many problems in that game that I had no time to make one tutorial so far. But thanks for the reminder, I hope I can make it this week, won't be very polished but will show the steps needed ;)
     
    Batuhan13 likes this.
  9. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Batuhan, apologies for the delay. I prepared the steps of the tutorial and will record it tomorrow :)
     
    Batuhan13 likes this.
  10. Batuhan13

    Batuhan13

    Joined:
    Apr 9, 2017
    Posts:
    117
    Alright mate I am waiting excitingly :D
     
  11. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Finally, it is finished, hadn't thought it would take that long to make, cut and upload for such a short tutorial ;)
    Some right-click menus in Unity are not shown, I don't know why, must be an issue with the capturing software. But if anything is unclear feel free to ask :)
     
  12. edbjorgen

    edbjorgen

    Joined:
    Oct 20, 2019
    Posts:
    1
    Wow, amazing! I was googling for the EXACT same answer, and here it is, I mean, you even made a vid tutorial about the solution! Holy crap, it's fantastic!
     
    Olipool likes this.
  13. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Haha nice, thanks for the feedback, then the work was worth it ;)
     
  14. krisventure

    krisventure

    Joined:
    Mar 24, 2016
    Posts:
    118
    Works like a charm thank you for sharing!
     
    Olipool likes this.
  15. lucet

    lucet

    Joined:
    Sep 14, 2019
    Posts:
    4
    Bonjour est ce que ça marche avec une armature sur un maillage personnage et plusieurs animations idl et marche par exemple?
     
  16. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Il "devrait" fonctionner avec tout ce qui déforme un maillage. Mais si vous l'utilisez pour des vêtements par exemple, il n'interagira pas avec le personnage et autres.
     
  17. neetikumar21

    neetikumar21

    Joined:
    Nov 23, 2022
    Posts:
    1
    Hi Olipool! I followed your tutorial (thanks for making it btw), but when I go to remove the cloth modifier or subdivide modifier, the fabric doesn't keep its shape anymore. I'm not sure what I've done wrong, I exported and imported the mdd as in the video, and the shape keyframes all show up....
     
  18. Olipool

    Olipool

    Joined:
    Feb 8, 2015
    Posts:
    320
    Hi neetikumar21,
    I haven't tried to make a curtain since then so maybe the new Blender version or plugin of the export may have changed. It sounds to me like the keyframes are not containing the right things. I am just guessing but maybe on exporting, the curtain was not selected or something like that or some setting needs to be turned on. Maybe you need to apply the modifiers now before exporting. Maybe you can try that. If the shape key contains data for the curtain I don't know why it wouldn't "deform" the curtain each frame.
    And did you bake the animation before exporting?
     
    Last edited: Oct 15, 2023