Website Youtube GitHub

mGear Framework Forum

RBFManager - Add/remove attributes after creation

Hi!

I am using RBFManager to drive the position/rotation/scale for several joints on the face rig I’m working on. Right now I’m authoring the main structure, so we can have a template that can be imported at a later time when assembling the rigs.

Sometimes I find myself wanting to add driven attributes ones the RBF system is created and have set several poses. Is it possible doing it from the manager itself or through the API?

Thanks a lot, and once again, thanks for all the effort that you guys are putting into mGear!

Hola @iker.mozos

I think it is not possible. But I will ask @Rafael, he is the main developer of the tool

@iker.mozos Hey!

Sorry, could you clarify a little on what you would like to add once the RBF node(s) are created?

1 Like

Once I create a RBF node to drive several attributes on an object through poses, what I was trying to do was to add more attributes. The example I was working with: I’m driving the cheek joints’ position using the rotation of my jaw. But after setting the whole thing up with a couple of poses, I realize I could use some scale. As far as I know the only way I can do this is to remove the RBF and recreating it again but this time picking the scale attribute as well.

Essentially I wanted to know if adding attributes to a RBF setup was possible once it’s created.

Thanks!

1 Like

Hey @iker.mozos

Sorry for the delayed response on my part. I looked over the code and there does not seem to be any way to add driven attrs after a RBF node has been made. So I made you this little work around. I tested it a little bit and worked well. Let me know if it gives you what you need.

Remember when adding attrs like scale to an existing setup to pass in a default value of 1.0 to avoid issues.

Swap out the node names and desired attrs of course!

from mgear import rigbits


driven_node = "capeFront_L3_driven"
wd_node = "capeFront_L3_driven_WD"


def addDrivenAttributes(rbf_node, driven_node, attrs, default_value=0):
    existing_attrs = rigbits.weightNode_io.getDrivenNodeAttributes(rbf_node)
    non_existing_attrs = [x for x in attrs if x not in existing_attrs]
    number_of_driven = len(existing_attrs)
    attrs_added = []
    for index, dAttr in enumerate(non_existing_attrs):
        starting_index = number_of_driven + index
        nodePlug = "{}.output[{}]".format(rbf_node, starting_index)
        drivenPlug = "{}.{}".format(driven_node, dAttr)
        attrs_added.append(dAttr)
        attrs_added.append(mc.getAttr(drivenPlug))
        mc.connectAttr(nodePlug, drivenPlug, f=True)
    num_of_poses = cmds.getAttr("{}.poses".format(rbf_node), mi=True)


    for pose_index in range(len(num_of_poses)):
        for index, dAttr in enumerate(non_existing_attrs):
            starting_index = number_of_driven + index
            cmds.setAttr("{}.poses[{}].poseValue[{}]".format(rbf_node, pose_index, starting_index), default_value)
    rigbits.weightNode_io.forceEvaluation(rbf_node)
    return attrs_added

addDrivenAttributes(wd_node, driven_node, ["scaleX", "scaleY", "scaleZ"], default_value=1)
3 Likes

Thanks a lot, Rafael! Definitely will make use of those lines of code.