Friday, 24 February 2023

python way of making the bones based on cvs

from cgtalk forum poster - Darksuit

CGTalk | Auto-create joint chain along spline? (cgsociety.org)

just in case - 

changing the orientation on the joints should be easy enough look to the script for

this line

cmds.joint(currentJoint,e=True,zso=True,oj="xyz")

change the oj=“xyz” to the orientation you need… more than likely you are looking for “xzy”.

The import maya.cmds as cmds line imports the MEL script commands to python. There are some differences, but there is a lot of good documentation, and a number of references out there.

as for reorienting the joints. change the following line i=1 in the last block to i=0 that will start the orientation at the base joint instead of the second joint. A lot of times I leave the base joint aligned to world for my own uses.




 import maya.cmds as cmds


# array of selected objects

sel = cmds.ls( selection=True )


# name of the curve to convert

lastSelect = int(len(sel)) -1

curveSel = sel[lastSelect]


# print lastSelect

#print curveSel


#find the number of CVs (Degree + Spans)

numCVs = int(cmds.getAttr (curveSel+'.degree'))+ (cmds.getAttr (curveSel+'.spans'))

#print numCVs


# selection must be clear

cmds.select(clear=True)


#For each CV in the Curve create a joint.


i=0

while 1:

    if not ( i < numCVs ):

        break

    cvPosition = (cmds.getAttr (curveSel+'.cv['+(str(i))+']'))

    if (i == 0):

    cmds.joint(n=curveSel+'_jointRoot',p = cvPosition[0])

    if (i == (numCVs-1)):

    cmds.joint(n=curveSel+'_jointEnd', p = cvPosition[0])

    if(i>0)and(i != numCVs-1):

    cmds.joint(n=curveSel+'_joint_'+(str(i)),p = cvPosition[0])

    i+=1

 

# reorient the joints    

i=1

while 1:

if not (i < numCVs-1):

break

#find the name of the current Joint

currentJoint = (curveSel+'_joint_'+(str(i)))

cmds.joint(currentJoint,e=True,zso=True,oj="xyz")

i+=1


joints along curve script mel

 nnJointsOnCurve for Maya - Free Character Scripts / Plugins Downloads for Maya (highend3d.com)

JUST in case this vanishes... puts joints on a curve. v useful and simple

/////////////////////////////// nnJointsOnCurve /////////////////////////////////


//                              Scripted by -Nilesh Jadhav

//                                                         27-07-2010

/////////////////////////////////////////////////////////////////////////////////////

// -------------- This script generates joint chain on selected Curve ---------------

//////////////////////////////////////////////////////////////////////////////////////

//

////////////////////////// UI Designing for nnJointOnCurve /////////////////////////


if (`window -exists curveJoint`)

deleteUI "curveJoint";

    

    window -t "nnJointsOnCurve" -w 200 -h 200 -mnb 1 -mxb 0 -s 1 curveJoint;


columnLayout -adj 1 -columnAttach "both" 1 -rowSpacing 10 -columnWidth 250;


    intFieldGrp -l"Number of Joints" numberInt;

    checkBoxGrp -l"Rebuild the Curve" rebuildCheck;

    text -l "Select the Curve and press the Button" -fn "smallBoldLabelFont" ;

    button -l"<< Add Joint Chain on Curve >>" -h 30 -c ("nnJointsOnCurve()") goButton;

    text -l"Scripted by - Nilesh Jadhav" -bgc 1 1 1;


showWindow curveJoint;




/////////////////////////////////////  Procedure ////////////////////////////////////////////////


global proc nnJointsOnCurve()

{


    string $sel []=`ls -sl`;

    string $curve =$sel [0];

    string $check =`checkBoxGrp -q -v1 rebuildCheck`;

if ($check==1 )

{

rebuildCurve -rt 0 -s 25;


}

else

{

}

    string $lcr []=`spaceLocator`;

    string $loc =$lcr [0];


    string $path =`pathAnimation  -stu 1 -etu 1000 -f on  $curve $loc `; 

    int $numbers []=`intFieldGrp -q -v numberInt`;


    float $locPos []=`xform -q -ws  -t $loc`;

    int $divFacter =1000 / $numbers [0];


select -cl;

$i=`currentTime -q`;

            for ($i=1; $i<1000; $i=$i+$divFacter) //--------- Loop to make joint chain

                {




        currentTime $i;

        float $lcPos []=`xform -q  -ws -t locator1`;


        string $joints =`joint -a -p $lcPos [0] $lcPos [1] $lcPos [2]`;


}

string $selJoint []=`ls -sl`;

string $jnt =$selJoint [0]; 



    $i =1;

            for ( $i=1; $i<$numbers[0]+1; $i++) //--------- loop for getting 1st joint

                {

                    pickWalk -d up;

                }    

    

    joint -e -oj xyz -secondaryAxisOrient yup -ch -zso;



delete $path;

delete $loc;

currentTime -e 1;

}


Friday, 24 August 2018

UVs for a ribbon/pipe

1) Use the Unitize function to separate each face in the mesh and have them squarely fill the 0-1 UV space. 2) Select the edges where you want your seam. 3) Convert the selection to UV's. 4) Invert the selection. 5) Use the Move and Sew function. 6) Go in the option box for Unfold and select Vertical as your unfold constraint (horizontal if your UV's are oriented that way. 7) Enjoy your nice UV's.


https://www.youtube.com/watch?v=dahgVetfUZg

Saturday, 28 July 2018

simple sticky lips

http://www.kimonmatara.com/maya-easy-sticky-lips/
To begin, create two curves that will follow the contours of the upper and lower lips respectively as your rigged geometry deforms. These will be your ‘driver’ curves. There are various ways of doing this; in the example below, I merely drew the curves using snapping, and then wrapped them onto the original rig geometry:
Next, create a dynamic ‘averaged curve’ between them. To do this, follow these steps:
  1. Grab the curves’ shapes and graph them up in the Node Editor (or Hypershade, as you prefer).
  2. Create an ‘avgCurves’ node (in the Node Editor, you can hit tab and start typing ‘avgCurve’; alternatively, you could just issue a ‘createNode avgCurves’ in the MEL command line)
  3. Plug the ‘worldSpace’ output attribute of each curve shape into the inputCurve1 and inputCurve2 inputs of the avgCurve node:
  1. Back in the Outliner, duplicate one of the curves. This will be your ‘sticky’ curve.
  2. Add this curve’s shape to the Node Editor graph.
  3. Plug the ‘outputCurve’ output of the avgCurves node into the ‘create’ input of the curve:
  1. Select the avgCurves node and switch off ‘Automatic Weight’.
The resulting curve should fall right between the two lips, as thus:
Next, make a live, deforming copy of your rigged geometry. To do this, select your rigged geometry and issue ‘polyDuplicateAndConnect’ in the MEL command line. This will be your ‘sticky lips’ mesh. (This step is necessary to prevent dependency graph cycle problems.)
Now set the the averaged curve you created earlier as a wire deformer for this mesh. If in doubt as to how to do this, consult Maya’s documentation on the ‘wire’ deformer.
The wire deformer will have generated a ‘BaseWire’ curve. Select this curve’s shape in the Outliner and graph it in the Node Editor. Add the ‘avgCurve’ node you created originally to the graph.
Once again, plug the ‘outputCurve’ output of the avgCurve into the ‘create’ input of the BaseWire curve. We are doing this to cancel-out the wire deformer’s effects:
Paint-out the wire deformer’s influence to a narrow area along the inner lip edges:
Set ‘scale[0]’ on the wire deformer to 0.0, turn up the ‘dropoffDistance’ attribute, and overdrive ‘envelope’ to 2.0. Play with these settings until you get a good-looking result kicking in at the right range of motion.
You should now have something like the image below. If you turn up the wire dropoff, you’ll be able to zip-up the whole mouth, from the edges inwards.
  • The effect is distance-based, so some modest keying will be required in animation.

Wednesday, 18 April 2018

render layers in maya 2018

Render layers in 2018

Use groups in collections, this way you can easily swap out geo without having to update stuff each time someone changes something.

If a sub object needs changing, it could be worth putting that in a sub group too.

Use shader overrides rather than material overrides.

more UV crap

last post is a bit redundant in the age of UV-editing mode of Maya 2018, but with heavy meshes, the uv editor is dog slow.

polyEditUV -u 1 -v0 -scaleU 1.2 -scaleV 1;

Also this.

Monday, 16 April 2018

scaling UV code, around the centre of selection instead of 0,0

Original code stolen from
http://polycount.com/discussion/172364/maya-mel-scale-uv-shells-locally-script-for-anyone-that-wants-it


//store uvs into array
float $uvvalues[] =`polyEditUV -q`;
int $selSize = `size ($uvvalues)`;

//split array into U and V
float $Uarray[];
float $Varray[];

//copy U and V arrays with values
for($u = 0; $u < $selSize; $u++) {
          $Uarray[size($Uarray)] = $uvvalues[$u]; 
          $u=$u+1;
}

for($v = 1; $v < $selSize; $v++) {
          $Varray[size($Varray)] = $uvvalues[$v]; 
          $v=$v+1;
}

//sort arrays by coords and get size of array
$Uarray = `sort $Uarray`;
$Varray = `sort $Varray`;
int $UarraySize = `size ($Uarray)`;

//get max values
float $maxNuU = $Uarray[$UarraySize-1];
float $maxNuV = $Varray[$UarraySize-1];

//get min values
float $minNuU = $Uarray[0];
float $minNuV = $Varray[0];

//calculate centre values
float $middleU = ($maxNuU + $minNuU)/2;
float $middleV = ($maxNuV + $minNuV)/2;

polyEditUV -pu $middleU -pv $middleV -su .2 -sv .2;