hi there,
i am working on a script for automatic rigging of characters
i have devised it in such a way that it creates guides at the particular points where joints are to be created and the guides are connected through curves, and the user can use the guides to adjust the position of joints according to the character....
but i am facing a problem that how can i tell maya to create joints between these two points ar along a curve
..
any help would be gratly accepted
waiting for reply
Well in order to create a joint hierarchy along a curve what you can do is the following:
- Create a curve CV of degree 1 with two cv points, connecting your two guides.
- Then rebuild the curve using "Edit Curves > Rebuild Curve" and within the options menu, set "Rebuild Type" to Uniform, and set the "Number of Spans" parameter to the number of bones you want. This will add cv points evenly spaced throughout your curve.
- Now using a for loop go through the above curve quering the XYZ position of each CV on the curve and use it to create each bone of the hierarchy.
Here's a bit of code that I wrote in order to achieve this exact task in the past.
In my case I was using two markers called mark_body_start and mark_body_mid to define the start and end points of the joint hierarchy.
CODE
{
int $bodyBones = 10; // Number of bones
// Finding the positions of the markers
float $x, $y, $z;
$x = getAttr mark\_body\_start.translateX;
$y = getAttr mark\_body\_start.translateY;
$z = getAttr mark\_body\_start.translateZ;
vector $markBodyStart = <>;
$x = getAttr mark\_body\_mid.translateX;
$y = getAttr mark\_body\_mid.translateY;
$z = getAttr mark\_body\_mid.translateZ;
vector $markBodyMid = <>;
// Creating a curve between them
curve -d 1 -name "curve_body"
-p ($markBodyStart.x) ($markBodyStart.y) ($markBodyStart.z)
-p ($markBodyMid.x) ($markBodyMid.y) ($markBodyMid.z);
rebuildCurve -ch 1 -rpo 1 -rt 0 -end 1 -kr 1
-kcp 0 -kep 1 -kt 0 -s $bodyBones -d 1 -tol 0.01 "curve_body";
// Evenly spacing joints according to the curve
vector $cvPos = 0;
for ($k = 0; $k <= $bodyBones; $k++)
{
$cvPos = `pointPosition -w ("curve\_body.cv[" + $k + "]")`;
joint -name ("joint_body_" + ($k+1)) -p ($cvPos.x) ($cvPos.y) ($cvPos.z);
}
select -cl;
delete "curve_body";
}
Hope it helps!
1 Like
Hey Segmoria, I know you posted this years ago but I wanted to say a huge thanks. Im learning rigging and python and needed a way of creating a specified number of joints in a chain that would work with squash and strecth etc. I had a more complicated way that worked but not with the scaling for squash... i looked for ages all over the net for alternatives, then saw yours and it works so well, its less code and clean. I reproduced this in Python here:
import maya.cmds as mc
side = "center"
limb = "spine"
startPos = mc.xform('startPositioner', q=1, ws=0, t=1)
endPos = mc.xform('endPositioner', q=1, ws=0, t=1)#define the end position
numJoints = 4
print startPos
#Creating a curve between them
mc.curve (d=1, n= 'curve_body', p=[(startPos[0],startPos[1],startPos[2]),(endPos[0],endPos[1],endPos[2])])
mc.rebuildCurve(ch=1, rpo=1, rt=0, end=1, kr=1, kcp=0, kep=1, kt=0, s=numJoints, d=1, tol=0.01, n='curve_body')
#Evenly spacing joints according to the curve
cvPos = 0
k=0
while k <= (numJoints):
cvPos = mc.pointPosition( 'curve_body.cv[' + str(k) + ']', w=1)
getJoints = mc.joint(n=('center_spine_0' + str(k+1)+'_jnt'), p=cvPos)
k=k+1
print cvPos
#Set the rotation order
r=0
while r < (numJoints):
mc.joint(('center_spine_0' + str(r+1)+'_jnt'), e=True, oj='xyz' , sao='yup' )
r=r+1
mc.select(cl=1)
mc.delete ('curve_body')
HUGE thanks again !!!!