Home Website Youtube GitHub

Blocking volume for Chain Spring

Hey guys, I’m new to MGear (and rigging in general), but I was curious, Is there a simple way to set up a blocking volume for the chain springs? For example, my character has two tassels on the front of his outfit with cloth underneath them. I want the chain spring to ideally dynamically bounce off of the cloth if they collide with it rather than clip through.

@Aerys and @soulcage discussed (and implemented) gravity and collisions. As far as I know this was a custom version of the plugins. I don’t think it has ever been added to the official mGear plugins.

A simpler (and much less accurate!) way is that you can add a clamp node to the spring, so that you can add a limit to how it can rotate. I’ve used this to get a very cheap way to prevent hair from moving inside the character’s head.

I run this script to add it to my spring component called “chainSpring”. It adds some attributes you can set to limit how much it is allowed to rotate.

If you aren’t familiar with scripting, ALL I’m doing is adding a clamp limit to the rotation of the chainSpring_C0_spring0_cns nodes and then driving the clamp value with an attribute, so you can set it easily. Those _cns nodes have a pairBlend connection input. I clamp that.


import pymel.core as pm
from mgear.core import attribute

# name this to match your own component's name!
guideName = 'chainSpring'

# Get all the related spring cns nodes
springCns = pm.ls('{}*_spring*_cns'.format(guideName), type='transform')
springCtrls = pm.ls('{}_*_ctl'.format(guideName), type='transform')

hostUI = pm.PyNode(springCtrls[0].uiHost.get())

attribute.addAttribute(hostUI, "{}_minRotX".format(guideName), "float", value=-100.0)
attribute.addAttribute(hostUI, "{}_maxRotX".format(guideName), "float", value=100.0)
attribute.addAttribute(hostUI, "{}_minRotY".format(guideName), "float", value=-100.0)
attribute.addAttribute(hostUI, "{}_maxRotY".format(guideName), "float", value=100.0)
attribute.addAttribute(hostUI, "{}_minRotZ".format(guideName), "float", value=-100.0)
attribute.addAttribute(hostUI, "{}_maxRotZ".format(guideName), "float", value=100.0)

pairBlends = [x.rotateZ.inputs()[0] for x in springCns]

for oSpring, pairBlend in zip(springCns, pairBlends):
    # Just making a clamp node to clamp the rotateZ of the character's hair
    print oSpring, pairBlend
    oClamp = pm.createNode('clamp', n=oSpring.name().replace('_cns','_clamp'))

    oClamp.outputR.connect(oSpring.rotateX, force=True)
    oClamp.outputG.connect(oSpring.rotateY, force=True)
    oClamp.outputB.connect(oSpring.rotateZ, force=True)
1 Like

@chrislesage thanks! That’s definitely helpful, however I’m not sure it will fully solve my problem as it’s less that I don’t want the chains going passed a certain threshold, and more that I want them to dynamically react to the mesh that’s animating underneath them. It makes sense for your hair as the head shape won’t change, however in my case the cloth will be skinned and react to the movement of the legs. So if the character is running for example, the tassels will bounce forward, but they need to know if they come in contact with the leg as it’s being raised up during a run and not clip through it if the leg has moved and pushed the cloth into their acceptable threshold of swinging.

1 Like

@jgiron since its possible to implement collision (and already done in a custom mgear-solver with simple spheres as colliders, but not bouncing), it is in production not so practible, because it invokes more work setting up proper collision on the rigging side…
a more practible and faster way is after animation approval to bake the springs and then modify the baked keyframes on the frames where penetration occures…
you will see that then you will have more control over the secondary animation…by modifying the rotation curves
if you really want to have proper behaviour over yor tassels then maybe going to “real” cloth simulation is better…or setting up a hair curve simulation which drives some bone chains…

real simulation will also benefit from sub-frame collisions, so if your character moves very fast berween frames…mgear spring is on a frame basis and it will not perform sub-frames…

1 Like

@jgiron if you need something more advance I would like to recommend ragdoll dynamics from @mottosso