What is the function to run simulation in MEL?

969 views Asked by At

I would like to create a MEL script that creates a scene, setting up ncloth and passive collider objects and run the simulation up to a certain frame.

In the script editor, I can see the scene set-up but there is no function starting the simulation.

3

There are 3 answers

7
kartikg3 On BEST ANSWER

The technique that @Andreas suggests is sometimes called "command harvesting". It is a great way to learn what and how Maya is doing things. But to answer your specific question:

You can use cmds.play() to start playing back on Maya. See the docs for options.

You might want to set the start frame and end frame of the playback range using the cmds.playbackOptions() command. See the docs for options.

So you would do: (relevant explanatory comments added)

# egs. to play from frame 1 to 120
# also note that the playbackSpeed flag is used
# we need to set this to 0 to "play every frame".
# setting maxPlaybackSpeed to 0 will result in free playback, so the playback isn't clamped.
# At this point, playback wouldn't be realtime, but it will be accurate.
# Dynamics and simulations must be played back like this or the nucleus will not evaluate properly.

cmds.playbackOptions(animationStartTime=1, animationEndTime=120, playbackSpeed=0, maxPlaybackSpeed=0)

# now start playback
cmds.play(forward=True)

EDIT: I just noticed that you had asked for MEL commands. Just take the above commands and MEL-ify them, like so:

playbackOptions -e animationStartTime 1 animationEndTime 120 playbackSpeed 0;
play -f 1;

Suggestion: It is best to playblast this playback to watch it in proper fps and playback speed.

Hope that was useful.

0
Andreas Haferburg On

In the Script Editor you can tell Maya to "Echo all commands". If you enable that, then do something in the UI, it will output all the MEL commands in the Script Editor.

7
theodox On

I'd try using bakeSimulation to convert the sim to ordinary vertex animations. You can then advance time to the desired time and export your OBJ that way.

This will disable the simulation once executed - it's good for getting the results but not editing them.