Export multiple MDD at once for further use in other Blender scene ? (animation & cloth sim)

Hey guys,

I hope I’m in the right category. As I didn’t found any solution in the Blender interface, I guess my question implies a little bit of Python.

I have a character, animated thanks to a kinect sensor, and a linked armature. It also have a lot of cloth simulations : a long coat, pants, earrings, and a lot of hairs made from curves. Anyway, I have 1 project per Animation (let’s say walk.blend, run.blend, dodge.blend etc). If I need to create action combos, I guess I can create a new project, append my character in rest position, and use the NLA to combine the desired action, then bake the cloth simulations (please correct me if I’m wrong !).

I’m trying to find a way to import one of those animations in another Blender scene.

My thought was to export every cloth simulation and mesh deformations to .MDD, then create a new project with only Mesh Cache Modifier on every mesh, linked to the proper mdd. Then I’ve read that I just have to export it as an .FBX for further use.
That way, I use less GPU/CPU ressources, and I can safely append this to the other scene without risking any cheesy deformations (Again, correct me if I’m wrong please !)

I have two questions :

  1. Is this a “okay” workflow ? It seems a little clanky to me but I’m a beginner.

  2. As I have 97 .mdd to create, is there a way to select multiple meshes and export a .mdd for each of them, separately ?
    I guess it takes some Python scripting skills because I didn’t found anything in the Blender’s interface, aaaand I don’t know how Python’s work (any written tutorial for Blender btw?) :frowning:

I hope someone can help me.

Thanks guys :smiley:

PS : There’s a “multiple FBX creator script” on blenderstack (on which I’ve already posted) : https://blender.stackexchange.com/questions/169537/exporting-multiple-meshes-individually-at-once?noredirect=1&lq=1

No one ? :frowning:

Hmmm…Make sure to Place each character file in its own collection with everything connected with it…

Then you can use the standard FBX export and turn on Batch Mode with Collections Selected…send to its own directory and click on the Folder + icon and it will send each file to its own directory in the main folder…

Oh nice ! :smiley:
I thought cloth simulation were not handled by fbx exportation ? :hushed:
I found weird that no one ever asked this question, it would make sense then…
I’ll try this and let you know if everything is good!

I believe you have to Bake the simulation to the mesh before export But I am not certain as I have never exported them…

OK…Found a tutorial…important part starts at 12:00 into it…exporting the simulation as a Point Cache ( Lightwave .mmd file ) the mesh as an FBX…

EDIT: I just realized I tagged the wrong Video I was looking at…
I found out that alembic will recursively export consecutively numbered files, oooo>ooo2, etc…and this add on will export Alembic Point Cache files…so perhaps it will work for you to get all this exported…

Yeah, as stated in my first post, FBX can be used to export deformation of a mesh, but it can’t handle cloth simulation cache. So I need to export my cloth simulation in .MDD, then import the .MDD file thanks to a Mesh Cache Modifier, and THEN export everything in .FBX. :roll_eyes:

It seems that the add-on linked in your last answer can’t handle cloth sim :frowning:

Seems that .MDD is the way to go, but I don’t know how to write this in Python…

Here are my clues so far :

  1. There is a “Batch Export” template in the scripting area of Blender. But it is meant to export a .fbx file.
  2. Here is a Python command for .mdd exporting : bpy.ops.export_shape.mdd(fps=24, frame_start=1, frame_end=250)

Is it possible to mix those two so that the Batch Export template runs a .mdd exporting script instead of .fbx ?

The last addon will export the Point Cache Files…as alembic Point Cache and Alembic are recursive…

Hi !

You want to batch export each selected objects to .mdd ?
You need to activate the addon shipped by default,

I’ve written some code that should do the batch export, it looks quite simple…
Haven’t tested it so finger crossed…

I’ve tried to comment everything that is appending so you can follow along and may change some stuff.

Basically, it will take all the objects selected, de-selected them and export them one by one
.mdd file get the same name as the object, and is located next to the .blend file.

good luck !

import bpy # blender python module
import os  # python module to handle files and directory

objs        = bpy.context.selected_objects # take all the selected objets 
current_dir = os.path.split(bpy.data.filepath)[0] # get the folder where current blend file is located
start       = bpy.context.scene.frame_start # start frame of the scene
end         = bpy.context.scene.frame_end   # end frame

for ob in objs : # for each objects
    ob.select_set(False) # deselect object


for ob in objs : # for each objects 
    filepath    = os.path.join(current_dir, ob.name+".mdd") # where to save the file ? ->  next to current .blend
    ob.select_set(True) # select the object
    bpy.context.view_layer.objects.active=ob # make the object active
    bpy.ops.export_shape.mdd(filepath=filepath, fps=25, frame_start=start, frame_end=end ) # mdd export
    ob.select_set(False) # deselect the object

for ob in objs : # for each objects
    ob.select_set(True) # select object

Hey, thanks for your help ! :smiley:

Just tested this code, and I got a syntax error “Invalid Syntax” pointing out line 14 :

filepath = os.path.join(current_dir, ob.name+".mdd")) # where to save the file ? -> next to current .blend

ok !
It’s because of the double parenthesis after “.mdd”)) , should be “.mdd”)

I’ve changed it in the post, you can copy-paste it and try if it works now !

How, very sorry I should have seen that haha
I’ll try and come back here asap ! Thanks :slight_smile: