Home Website Youtube GitHub

Create chain springs in post script

I am going to make a rig with 100s of chain spring components. So instead of using the guides to create it I want to put it in a post script. I have been looking for examples on how to create components with code. But couldn’t find it. Can someone please point me in the right direction?

I am guessing I should be looking here…

Hey Torben,

I’m not sure if you can create the components without guides, since a lot of logic of the components are linked to settings from the guides.
Perhaps you can look at making the guides in a pre-script? And then clean them using a post script.

For drawing guides you could have a look in the Shifter module on how it handles it.

2 Likes

Hey Jeroen,

Thank you. That makes sense to create the guides in pre and remove them in post. Probably much easier to create a guide than creating the actual component with all it’s connections.

1 Like

I think - but I’m not sure - that there might be a confusion about terms in this thread. A Shifter “component” is a guide that builds a modular part of the rig. Inside those components is a bunch of code running mGear commands or operators. And sometimes it makes sense to skip the Shifter guides and just create the nodes yourself. (For your case, with spring chains, I’m not sure.)

You do not necessarily need Shifter “guides” to use parts of mGear, especially when you are adding custom stuff to your rig in a post script. Components are just ways to conveniently package common parts of a rig, like a limb or a spine, or some other functionality you can imagine.

Shifter rigging is just one single part of mGear, the framework.

So you don’t want to just look in Shifter components code. EXCEPT, that it is a great place to find some of the commands that get run. But then you should search the documentation for those commands, so you can use them on their own.

For example http://www.mgear-framework.com/mgear_dist/mgear/core/applyop.html?highlight=spring#mgear.core.applyop.gear_spring_op

You can use a lot of these commands without even having a Shifter rig at all.

EXAMPLE:
I made 2 locators. The red “locator1” is the child of a blue locator that I am animating. Use the gear_spring_op() function on the locator, and it adds the spring. The dampness and spring parameters are found on the spring solver node. It would be your responsibility to connect those parameters to attributes on your control of choice.

There is no Shifter rig in this Maya scene.

import pymel.core as pm
import mgear.core
mgear.core.applyop.gear_spring_op(pm.PyNode('locator1'))

springyspring

In this example, the difference is that it is just driving spring on the translation. The Shifter spring guide sets up some additional stuff so that it is rotating chains. So yeah, you are missing some of that full functionality, but you can likely build it back up manually if you read the spring chain component code, like you said. That might be harder, but sometimes you can end up with a simpler setup too, if you don’t need everything that is included in the spring chain guide.

(Sorry if that was long-winded. I hope it gives you some alternative options.)

2 Likes

Thank you Chris. That is very very helpful. This is most certainly worth looking into, since the setup is only going to drive rotation on a static mesh.