Need help

Hi guys,
I tried creating a script to retarget animation from one skeleton to another by copying the pose and adding orient constraints, but I failed miserably… any help is very appreciated.
I’m horrible at programming, but I want to try something to use Cheetah with mixamo (rig) and cascadeur (animate) 🙃


Code:
// removed some embarrassing code…
 
Last edited:
Was thinking on making it work throughout the whole skeleton, but after testing I really like how it works now…it’s more flexible as a retargeting tool…
Code:
// Tool script ( ~/Library/Application Support/Cheetah3D/scripts/Tool to install )
//

function buildUI(tool) {
    tool.addParameterSeparator("Retarget");

    tool.addParameterLink("copy from", false);

    tool.addParameterButton("apply to selected", "ok", "copyParameters");
}

function copyParameters(tool) {
    var copyFrom = tool.getParameter("copy from");
    var copyTarget = tool.document().selectedObject();

    if (!copyFrom || !copyTarget) return;

    if (copyTarget.recordParametersForUndo) copyTarget.recordParametersForUndo();

    copyTarget.setParameter("rotation", copyFrom.getParameter("rotation"));

    // Add an ORIENTCONSTRAINTTAG to the target object and link it to the source object
    var constraintTag = copyTarget.addTagOfType(ORIENTCONSTRAINTTAG); // ORIENTCONSTRAINTTAG without double quotes
    constraintTag.setParameter("target", copyFrom);

    copyTarget.update();
}
 
Last edited:
I managed to give it an option to apply it to the children too…
Now I want to make an option to add a point constraint to just the base and maybe apply the orientations/orientconstraints based on names…
All in all, I’m starting to like this retargeting script.
Code:
//
// Tool script ( ~/Library/Application Support/Cheetah3D/scripts/Tool to install )
//

function buildUI(tool) {
    tool.addParameterSeparator("Retarget");

    tool.addParameterLink("copy from", false);

    // Add a checkbox parameter for enabling recursion
    tool.addParameterBool("Recursive", true);

    tool.addParameterButton("apply to selected", "ok", "copyParameters");
}

function copyParameters(tool) {
    var copyFrom = tool.getParameter("copy from");
    var selectedObject = tool.document().selectedObject();
    var recursive = tool.getParameter("Recursive"); // Get the value of the checkbox

    if (!copyFrom || !selectedObject) return;

    if (recursive) {
        // Copy parameters recursively and pass the tool as a parameter
        copyParametersRecursive(selectedObject, copyFrom, tool);
    } else {
        // Copy parameters for the selected object only
        selectedObject.recordParametersForUndo();
        selectedObject.setParameter("rotation", copyFrom.getParameter("rotation"));

        // Add an ORIENTCONSTRAINTTAG to the selected object
        var constraintTag = selectedObject.addTagOfType(ORIENTCONSTRAINTTAG); // Remove double quotes from ORIENTCONSTRAINTTAG
        constraintTag.setParameter("target", copyFrom);
      
        selectedObject.update();
    }
}

function copyParametersRecursive(copyTarget, copyFrom, tool) {
    if (!copyTarget || !copyFrom) return;

    if (copyTarget.recordParametersForUndo) copyTarget.recordParametersForUndo();

    // Copy the "rotation" parameter from copyFrom to copyTarget
    copyTarget.setParameter("rotation", copyFrom.getParameter("rotation"));

    // Add an ORIENTCONSTRAINTTAG to the target object and link it to the source object if recursion is enabled
    var recursive = tool.getParameter("Recursive"); // Get the value of the checkbox
    if (recursive) {
        var constraintTag = copyTarget.addTagOfType(ORIENTCONSTRAINTTAG); // Remove double quotes from ORIENTCONSTRAINTTAG
        constraintTag.setParameter("target", copyFrom);
    }

    // Recursively copy parameters and add constraint tags for child objects
    var copyTargetCount = copyTarget.childCount();
    var copyFromCount = copyFrom.childCount();

    for (var i = 0; i < Math.min(copyTargetCount, copyFromCount); i++) {
        var copyTargetChild = copyTarget.childAtIndex(i);
        var copyFromChild = copyFrom.childAtIndex(i);

        // Pass the tool as a parameter to the recursive call
        copyParametersRecursive(copyTargetChild, copyFromChild, tool);
    }

    copyTarget.update();
}
 
Back
Top