Idea for rPins Options// Zero out transformation

Hey @marcus ,
some idea for rPins, to kind of be able to create Control Rigs for rPins

“what if” we have the option to create controls for rPins, or at least have the option to Zero out its transformation values


rPin_On off control

Thanks for sharing this here @Andrei_da_02, looks like you’ve already got this under control, what you’re looking for is an option in the Pin Constraint option dialog for this to be automatic?

Here’s how you can solve this with scripting, to potentially be put in a Shelf button.

Zero Out Transforms

  1. Select one or more Markers
  2. Run script
from ragdoll import interactive as ri
from ragdoll.vendor import cmdx

# Same as menu item
ri.create_pin_constraint()

# Make undoable
with cmdx.DagModifier() as mod:
    
    # Apply to all newly created pin constraints
    for pin in cmdx.selection():

        # Zero out transformations
        mtx = pin["worldMatrix"][0].as_matrix()
        mod.set_attr(pin["translate"], (0, 0, 0))
        mod.set_attr(pin["rotate"], (0, 0, 0))
        mod.set_attr(pin["offsetParentMatrix"], mtx)

This will do what the Pin Constraint menu item does, and create a new pin constraint for each newly selected Marker.

To also generate the kind of control you’ve got there, that wraps around your geometry, we need to get a little more advanced.

Automatic NURBS Control

  1. Select one or more Markers
  2. Run script
from ragdoll import interactive as ri
from ragdoll.vendor import cmdx

# Same as menu item
ri.create_pin_constraint()

# Make undoable
with cmdx.DagModifier() as mod:
    
    # Apply to all newly created pin constraints
    for pin in cmdx.selection():

        # Zero out transformations
        mtx = pin["worldMatrix"][0].as_matrix()
        mod.set_attr(pin["translate"], (0, 0, 0))
        mod.set_attr(pin["rotate"], (0, 0, 0))
        mod.set_attr(pin["offsetParentMatrix"], mtx)
        
        # Make shape
        shape = pin.shape(type="rdPinConstraint")
        marker = shape["childMarker"].input()

        # A box with 1 unit for each side
        vertices = [
            cmdx.Point(-0.5, -0.5,  0.5),
            cmdx.Point( 0.5, -0.5,  0.5),
            cmdx.Point( 0.5,  0.5,  0.5),
            cmdx.Point(-0.5,  0.5,  0.5),
            cmdx.Point(-0.5, -0.5, -0.5),
            cmdx.Point( 0.5, -0.5, -0.5),
            cmdx.Point( 0.5,  0.5, -0.5),
            cmdx.Point(-0.5,  0.5, -0.5) 
        ]

        # Indices of the above `vertices` list,
        # with 15 lines in total, 2 points per line.
        # They are laid out in such a way that a box
        # is drawn using 1 continuous line.
        indices = [
            0, 1,
            1, 2,
            2, 3,
            3, 0,
            0, 4,
            4, 5,
            5, 1,
            1, 5,
            5, 6,
            6, 2,
            2, 6,
            6, 7,
            7, 3,
            3, 7,
            7, 4 
        ]

        # Use the shape estimation already done by Ragdoll
        # to reshape this unit box into one that wraps around
        # the original geometry.
        translate = marker["shapeOffset"].as_vector()
        rotate = marker["shapeRotation"].as_quaternion()
        scale = marker["shapeExtents"].as_vector()

        mtx = cmdx.Tm(
            translate=translate,
            rotate=rotate,
            scale=scale
        ).as_matrix()

        # Finally, sample the `vertices` list and apply the transformation
        points = []
        for index in indices:
            vertex = vertices[index]
            vertex = vertex * mtx
            points.append(cmdx.Vector(vertex))

        curve = cmdx.curve(
            parent=pin,
            points=points,
            form=cmdx.kClosed
        )

        # Associate `Enabled` with the visibility of this control
        mod.connect(shape["enabled"], curve["visibility"])

        # Keep Pin Constraint visible in Channel Box, rather than the curve
        mod.set_attr(curve["ihi"], 0)

Use it like before, and it will produce this.

The last two lines are responsible for visibility when Enabled is edited, and to keep the NURBS curve from interfering with visibility in the Channel Box.

Pretty awesome !!!..thanks!!! @alanjfs

Would it be too much work/ code to keep the hierarchy order? Kind of FK, in the order we select the markers?

the idea behind this, is to be able to build a quick Control Rig of for the Markers , using rPins,

this is the new “project” I am developing on my end

Thanks man !

Do you mean for the newly created Pin Constraints to be parented to each other, like the FK controls? The Pin Constraint associated with the lower leg would be parented to the Pin Constraint of the upper leg?

Long ago, there was a feature like that built-in.

https://learn.ragdolldynamics.com/releases/2021.05.10/#mimic

It’s possible this could be brought back, it’s a relatively simple script for the Pin Constraint.

1 Like