Preserving keyframes after a mesh is separated and then recombined in Maya

So I have something of an odd process here that I am hoping to be able to perform on a mesh through a python script.

Assume you have a mesh (made of separate meshes) that has keyframes.

  1. You separate the mesh.
  2. Move the timeslider to another time.
  3. Move your separated meshes to a new place.
  4. Keyframe the new position.
  5. Recombine the meshes (and have all of the keyframes from both before and after the separation).

Separate and Combine both delete keyframes. Do you have any idea how to preserve the keyframes?

The only idea I can come up with right now is to:

  1. Copy the mesh pre-separation.
  2. Separate the copy.
  3. Match verts between the copy and original based on position.
  4. Move the copy.
  5. Copy the position data to the original and keyframe it.

It can be done, I am just afraid of it taking a lot of time if the mesh is too dense.

My answer below is possibly a little too involved for what you’re trying to do, but if you find yourself running out of options, here’s how I might approach it.

If you have a look at the graph for just two combined cubes, you’ll find that in between your original meshes and the output there is a little node called “polyUnite”
http://help.autodesk.com/cloudhelp/2015/ENU/Maya-Tech-Docs/Nodes/polyUnite.html

What this does, is it takes an array of meshes with a matrix for each and outputs exactly what you’d expect; a combined version of all meshes.

If you perform this operation yourself, instead of rely on the menu-item “Combine”, and it may provide you with some additional flexibility. What you need to do is:

  1. Get your two meshes ready
  2. cmds.createNode(“polyUnite”) will get you a “combine” node.
  3. Connect the “outMesh” attribute of both of the cubes into the “inputPoly[0]” and “inputPoly[1]” slots of the polyUnite node
  4. Connect either “matrix” or “worldMatrix” from both of the cubes into the “inputMat[0]” and “inputMat[1]” slots of the polyUnite node

At this point, the meshes are combined, but are not being outputted just yet.

  1. cmds.createNode(“mesh”) will get you a new mesh to store the result in
  2. Connect “output” of polyUnite into “inMesh” of the new mesh.

And viola, you have a new combined mesh being driven by your original meshes. Their keyframed animation will dynamically update the resulting combination and all is well.

Making the connections

If you haven’t worked with connecting nodes before, it can get a little tricky. I typically use Hypershade for these matters, but it’s likely that the newer Node Editor is equally apt. One thing you might encounter however is having trouble connecting to the second slot of inputMat and inputPoly as Maya only creates slots when they are needed. To make Maya allocate these slots for you, you can ask for it.

cmds.getAttr(“polyUnite1.inputMat[1]”)

At that point, the slot will be available for you to connect with.

After some thought, keyframe animation will only affect the transformation of a node, and not it’s shape. So for step 4, make sure you connect “worldMatrix”, and not “matrix” as the latter won’t take into account any animation applied onto the transform.

Unless I mis-read the OP, can’t you just separate the meshes, animate the separated pieces, and then polyUnite() them? In 2015, at least, that worked for both transform and vert animations.

If you have keys on the original mesh as well, you might try duplicating it first, animating the copies, and using the animated recombined mesh as a wrap deformer on the original

@Theodox You are absolutely right. That was totally my fault, I was deleting the history on the mesh after combining and separating (reflex since I didnt want to keep too many extra nodes in the outliner). Thanks for pointing that out!

@marcuso That is really interesting. I didnt realize you could make those types of connections manually. Learn somethin new everyday! :smiley: