"Baking out" Segment Scale Compensation

Referring back to an old thread - [MAYA] Math behind joint scale compensation - I’ve been trying to write a tool whereby we can animate with SSC on and then on export bake it out and turn it off and get the same result for Unity. Never seems to turn out right though, has anyone managed to do any of this / shine a light on a method to do so?

As scaleSegmentCompensate is essentially pre/postTransform you’d have to cache the relative world transform of each joint for each frame. Then turn off ssc and apply/key the transform for each joint for each frame.

Roughly speaking…

import maya.cmds as cmds
import maya.api.OpenMaya as apiOM

s_time = int(cmds.playbackOptions(q=True, min=True))
e_time = int(cmds.playbackOptions(q=True, min=True))

joints = cmds.ls(type="joint")

frame_data = []

for frame in range(s_time, e_time + 1):
   
   frame_data.append([])
   cmds.currentTime(frame)


   for jnt in joints:
      
      # Not sure if SSC is inferred with parentInverse or if 
      # it gets its *true* world space.

      m0 = apiOM.MMatrix(
         cmds.getAttr("{}.parentInverseMatrix".format(jnt)
      )

      m1 = api.OpenMaya.MMatrix(
         cmds.xform(jnt, q=True, worldSpace=True, matrix=True)
      )

      frame_data[-1].append(m1 * m0.inverse())

To get the data… then to set it is just multiplying by the parents world transform.

thanks very much, I’ll try parse this! Matrix math is still something I’m struggling with!

If you haven’t seen it, then definitely watch 3 Blue 1 Brown’s “Essence of Linear Algebra” series. The visuals he put together made so much of matrix math click for me.

1 Like

You can make a persistent and non-tedious solution if you use the SSC skeleton as a middle-man. Duplicate it then turn off SSC and zero all joint orients in the new skeleton. Then connect the plain old .matrix attribute from each SSC joint to a decomposeMatrix node. Pipe the decomposed translate, rotate, scale AND SHEAR to the source’s counterpart in the non-SSC skeleton. You can use the new skeleton for exports - but you’ll want to be certain that your engine plays nicely with non-uniform scale and shear.

Thanks very much ClamDragon, looks like Unity doesn’t support those things so leaf joints it is!

Cheers