Labels

Sunday, 20 November 2011

Change of direction

Sorry blog for not updating you in a while. The reason for this is I've had some feedback after crit that suggested that I change a lot of my direction. I'm still moving ideas and such about for a slightly revised set of aim and objectives, but in the meantime I have been keeping myself busy. Here is a dump of some of the stuff I've done so far:

First of all, I've been learning MELscript. While I've been taking notes and learning a lot of examples from the book, I'll list the examples I've worked on here.

//Create a sphere named "mySphere", catch the return value of the nodes (creation and translate), create arrays for translate, rotate and scale, catch the data and query the values of the translate,
//rotate and scale of the current sphere. Scale cannot be caught when it is absolute.
string $name = "mySphere";
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360
-r 1 -d 3 -s 8 -nsp 4 -ch 1`;
float $trans[] = `xform -q -t $names[0]`;
float $rots[] = `xform -q -ro $names[0]`;
float $scls[] = `xform -q -s $names[0]`;
//print some of the values caught and queried
print $trans[1];
print $scls[2];
print $rots[0];


vector $vects = <<3.1,7.6,1.008>>;
print ($vects + "\n");
print (($vects.y + "\n");




string $name = "mySphere";
string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360
-r 1 -d 3 -s 8 -nsp 4 -ch 1`;
vector $tranV = `xform -q -t $names[0]`;
vector $rotV = `xform -q -ro $names[0]`;
vector $scalV = `xform -q -s $names[0]`;
string $name3 = "mySphereThree";
string $names[] = `sphere -n $name3 -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360
-r 1 -d 3 -s 8 -nsp 4 -ch 1`;
xform -ws -t ($tranV.x) ($tranV.y) ($tranV.z) -ro ($rotV.x) ($rotV.y) ($rotV.z)
-s ($scalV.x) ($scalV.y) ($scal.z) $names3[0];


proc cmMyProc ()
{
//These values will be used to translate the sphere:
int $num = 7;
float $dec = 3.267;
float $sum = $num + $dec;
//Declare variables contraining the primitive names
string $ball = "myBall";
string $box = "myBox";
//Create and translate the sphere using xform
string $sphereNodes[] = `sphere -n $ball -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360
-r 1 -d 3 -s 8 -nsp 4 -ch 1`;
xform -t $num $dec $sum $sphereNodes[0];
//Create and translate the cube by querying the sphere translations
string $cubeNodes[] = `polyCube -n $box -w 2 -h 2 -d 2 -sx 1 -sy 1 -sz 1 -ax 0 10 0 -cuv 4 -ch 1`;
vector $tranV = `xform -q -t $sphereNodes[0]`;
xform -ws -t ($tranV.x) ($tranV.y) ($tranV.z) $cubeNodes[0];
select -cl;
}
//Run the procedure
cmMyProc;


proc string[] cmMyProc (int $num,float $dec,string $ball,string $box)
{
    float $sum = $num + $dec;
   string $sphereNodes[] = `sphere -n $ball -p 0 0 0 -ax 0 1 0 -ssw 0
   -esw 360 -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
   xform -t $num $dec $sum $sphereNodes[0];
   string $cubeNodes[] = `polyCube -n $box -w 2 -h 2 -d 2 -sx 1 -sy 1
   -sz 1 -ax 0 1 0 -cuv 4 -ch 1`;
   vector $tranV = `xform -q -t $sphereNodes[0]`;
   xform -ws -t ($tranV.x)($tranV.y)($tranV.z) $cubeNodes[0];
   select -cl;
   string $names[] = {$sphereNodes[0],$sphereNodes[1],
   $cubeNodes[0],$cubeNodes[1]};
   return $names;
}
string $return[] = cmMyProc (7,3.267,"myBall","myBox");
print $return;


//Global procedure to query xforms of targetm and return xform string
global proc string cmQryXforms (string $target,string $constrain)
{
    //Query all three transforms
    float $cmQueryTrans[] = `xform -q -t $target`;
    float $cmQueryRot[] = `xform -q -ro $target`;
    float $cmQueryScale[] = `xform -q -s -r $target`;
    //Create strings that can be combined in a final xform command
    string $string1 = (" -t " +$cmQueryTrans[0]+ " " + $cmQueryTrans[1] + " " + $cmQueryTrans[2]);
    string $string2 = (" -ro " +$cmQueryRot[0]+ " " + $cmQueryRot[1] + " " + $cmQueryRot[2]);
    string $string3 = (" -s " +$cmQueryScale[0]+ " " + $cmQueryScale[1] + " " + $cmQueryScale[2] + " ");
    //Combine the strings into the final xform command, and return
    string $return = ("xform " + $string1 + $string2 + $string3 + $constrain + ";");
    return $return;
}


//Run the procedure, catch the return, and print final xform command
 string $xformGo = cmQryXforms ("myBall", "myBox");
print ($xformGo + "\n");


//Local procedure to use as xform tool to transform objects to target
proc cmXformTool ()
{
 //List the selected transforms nodes:
 string $selTrans[] = `ls -sl`;
 string $target = $selTrans[0];
 string $constrain = $selTrans[1];
    //Query all three transforms
    float $cmQueryTrans[] = `xform -q -t $target`;
    float $cmQueryRot[] = `xform -q -ro $target`;
    float $cmQueryScale[] = `xform -q -s -r $target`;
 //Create strings that can be combined in a final xform command
    string $string1 = (" -t " +$cmQueryTrans[0]+ " " + $cmQueryTrans[1] + " " + $cmQueryTrans[2]);
    string $string2 = (" -ro " +$cmQueryRot[0]+ " " + $cmQueryRot[1] + " " + $cmQueryRot[2]);
    string $string3 = (" -s " +$cmQueryScale[0]+ " " + $cmQueryScale[1] + " " + $cmQueryScale[2] + " ");
 //Combine the strings into the final xform command, and return
 string $xformGo = ("xform " + $string1 + $string2 + $string3 + $constrain + ";");
 select -cl;
 eval ($xformGo);
}
//Run the procedure
cmXformTool;


//Local procedure to use as xform tool to transform objects to target
proc cmXformTool ()
{
 //List the selected transforms nodes:
 string $selTrans[] = `ls -sl`;
 //Error check for selection
 int $sizeSelect = `size ($selTrans)`;
 if ($sizeSelect != 2)
  error "Select a target object followed by an object to constrain.";
 string $target = $selTrans[0];
 string $constrain = $selTrans[1];
    //Query all three transforms
    float $cmQueryTrans[] = `xform -q -t $target`;
    float $cmQueryRot[] = `xform -q -ro $target`;
    float $cmQueryScale[] = `xform -q -s -r $target`;
 //Create strings that can be combined in a final xform command
    string $string1 = (" -t " +$cmQueryTrans[0]+ " " + $cmQueryTrans[1] + " " + $cmQueryTrans[2]);
    string $string2 = (" -ro " +$cmQueryRot[0]+ " " + $cmQueryRot[1] + " " + $cmQueryRot[2]);
    string $string3 = (" -s " +$cmQueryScale[0]+ " " + $cmQueryScale[1] + " " + $cmQueryScale[2] + " ");
 //Combine the strings into the final xform command, and return
 string $xformGo = ("xform " + $string1 + $string2 + $string3 + $constrain + ";");
 select -cl;
 eval ($xformGo);
}
//Run the procedure
cmXformTool;


/*




BOOLEAN SCRIPTS AHEAD - USE WITH CAUTION




*/


float $A = 7.2;
float $B = 3.5;
if ($A > $B) print "A is greater than B!\n";


//randomises and checks numbers
$A = `rand 0 10`;
$B = `rand 0 10`;
 print ("A is " + $A + "\n");
 print ("B is " + $B + "\n");
if ($A > $B) print "A is greater than B!\n";
else print "A is less than B!\n";


/*Set procedure argument to 1 or 0:
 Note!: Rands #s, 0 = Both 0 */


proc string cmCondition (int $change){
//Use condition to determine values:
float $A;
float $B;
if ($change == 1) {
 $A = `rand 0 10`;
 $B = `rand 0 10`;
}
else {
 $A = 0.0;
 $B = 0.0;
}
//Print values inside variables:
 print ("A is " + $A + "\n");
 print ("B is " + $B + "\n");
//Runs three conditionals to compare values:
 string $return;
 if ($A > $B) $return = "A is greater than B!";
 else if ($A == $B) $return = "A is equal to B!";
 else $return = "A is less than B!";
return $return;


}


//Run procedure:
string $result = cmCondition (0);
print ($result + "\n");


//Change the integer value in the procedure argument:
proc string cmfindNum (int $num) { //Open Procedure...
 //Run warning if numbers are not 5, 10, 15 or 20:
  if (($num != 5) && ($num != 10) && ($num != 15) && ($num != 20));
   warning "Input a multiple of 5 under 25!";
  //Run switch statement to set string return
  string $return;
  switch ($num) {//Open switch...
   case 5:
    $return = "Your number is 5.";
    break;
   case 10:
    $return = "Your number is 10.";
    break;
   case 15:
    $return = "Your number is 15.";
    break;
   case 20:
    $return = "Your number is 20.";
    break;
  } //Close switch
 return $return;
 } //Close procedure.
//Run procedure to catch return and print:
string $result = cmfindNum (1);
print ($result + "\n");




//Change the short primitive name in the procedure argument:
proc string[] cmCreatePrim(string $primitive){ //Open procedure...
//Run warning if numbers are not 5,10,15 or 20.
 if (($primitive != "sph") &&
  ($primitive != "cub") &&
  ($primitive != "con") &&
  ($primitive != "cyl"))
  warning "Use short primitive name (sph, cub, con, or cyl).";
//Switch statement to create prim and set string array return
 string $return[];
 switch ($primitive) {//Open switch...
 case "sph":
  $return = `sphere`;
  break;
 case "cub":
  $return = `polyCube`;
  break;
 case "con":
  $return = `polyCone`;
  break;
 case "cyl":
  $return = `cylinder`;
  break;
 } //Close switch
return $return;
} //Close procedure
//Run procedure to catch return array and print:
string $names[] = cmCreatePrim ("sph");
print ("Nodes created: " + $names[0] + "," + $names[1] + "\n");


//While Loop example creating sphere;
int $i = 0;
while ($i <= 10)
{
 string $name = "mySphere";
 string $names[] = `sphere -n $name -p 0 0 0 -ax 0 1 0 -ssw 0 -esw 360
  -r 1 -d 3 -s 8 -nsp 4 -ch 1`;
 setAttr ($names[0] + ".ty") $i;
 select -cl;
 $i = $i + 2;
} //Close Loop.


//Shift select primitives to delete history and freeze:
string $selObjs[] = `ls -sl`;
for ($obj in $selObjs){ //Open Loop
 delete -ch $obj;
 makeIdentity -apply true -t1 -r 1 -s 1 -n 0 $obj;
} //Close loop.
Other than that I've been writing a bit of my own scripts. Here are two such scripts. The first was written by myself entirely, and the second I got the help from Neil McNaughton of Ruffian to help write the code and talk me through it. :)


//////////////////////////////////////////////////////////////////////////////////////////////////////////
//
//
//     This script creates a no-flip knee setup for your bipedal character.
//
//     How to run this script:
//      1.Load the script
//      2. Specify right or left side with "ikNoFlipKnee right" or ikNoFlipKnee left"
//      3. Have Fun!
//
//////////////////////////////////////////////////////////////////////////////////////////////////////////


global proc ikNoFlipKnee(string $legSideLong)
{


 //RECORD ERRORS IN THIS VARIABLE
 int $legWarning = 0;  // 0 = No Errors
       // 1 = Error Found


 // DETERMINE WHETHER LEFT OR RIGHT LEG IS CURRENTLY BEING SETUP
 // CHECK TO ENSURE ARGUMENT IS CORRECT
 string $legSide;
 if (($legSideLong != "left") && ($legSideLong != "right"))
 {
  $legWarning = 1;
  warning "Unkown argument. Please specify either left or right. ie: cgTkSetupLeg left; \n";
 } else
 {
  if ($legSideLong == "left")
  $legSide = "l";
  if ($legSideLong == "right")
  $legSide = "r";
 }


 // CHECK TO ENSURE THAT ALL REQUIRED OBJECTS EXIST IN THE CURRENT SCENE
 if ($legWarning == 0)
 {
  if (!( (`objExists ($legSide + "Hip")`)
   &&  (`objExists ($legSide + "Knee")`)
   &&  (`objExists ($legSide + "Ankle")`)
   &&  (`objExists ($legSide + "Ball")`)
   &&  (`objExists ($legSide + "Toe")`)
   &&  (`objExists ($legSideLong + "FootController")`)))
  {
   $legWarning = 1;
   warning "Unable to find all required objects to setup leg. Please ensure all objects are named properly. \n";
  }
 }


 //IF NO ERRORS ARE ENCOUNTERED, CONTINUE WITH SETUP
 if ($legWarning == 1)
 {
  warning "The leg setup has encountered an error. Check script editor for details. \n";


 } else
 {
  print "All prerequisites were found. Setup will continue. \n";


  }


  //ORIENT THE JOINTS
select -r ($legSide + "Hip");
joint -e  -oj xyz -ch -zso;


//CREATE IK HANDLE


select -r ($legSide + "Hip");
select -tgl ($legSide + "Ankle");
ikHandle -n ($legSide + "KneeIK") -sol ikRPsolver -s 0;


//ADJUST POLE VECTOR


select -r ($legSide + "KneeIK");
setAttr ($legSide + "KneeIK.poleVectorX") 0.1;
setAttr ($legSide + "KneeIK.poleVectorY") 0;
setAttr ($legSide + "KneeIK.poleVectorZ") 0;
setAttr ($legSide + "KneeIK.twist") 90;


//MOVE FOOT CONTROLLER TO POSITION


//ADD ATTRIBUTES TO FOOT CONTROLLER (including offset)
select -r {$legSideLong + "FootController"};
addAttr -ln Knee -at "float" -k 1 -r 1 -w 1;
addAttr -ln Offset -at "float" -k 1 -r 1 -w 1;


//FREEZE TRANSFORMS AND DELETE HISTORY OF FOOTCONTROL


//select -r ($legSideLong + "FootController");
FreezeTransformations;
DeleteHistory;


//CREATE PLUS MINUS AVERAGE NODE


shadingNode -asUtility plusMinusAverage -n ($legSide + "LegIKPlusMinus");


//CONNECT NODES UP


connectAttr -force ($legSideLong + "FootController.Knee") ($legSide + "LegIKPlusMinus.input1D[0]");
connectAttr -force ($legSideLong + "FootController.Offset") ($legSide + "LegIKPlusMinus.input1D[1]");
connectAttr -force ($legSide + "LegIKPlusMinus.output1D") ($legSide + "KneeIK.twist");


//SET, LOCK AND HIDE OFFSET


select -r ($legSideLong + "FootController");
setAttr ($legSideLong + "FootController.Offset") 90;
setAttr -lock true -keyable false -channelBox false ($legSideLong + "FootController.sx");
setAttr -lock true -keyable false -channelBox false ($legSideLong + "FootController.sy");
setAttr -lock true -keyable false -channelBox false ($legSideLong + "FootController.sz");
setAttr -lock true -keyable false -channelBox false ($legSideLong + "FootController.v");
setAttr -lock true -keyable false -channelBox false ($legSideLong + "FootController.Offset");


//CREATE IKS FOR REST OF FOOT


select -r ($legSide + "Ankle");
select -tgl ($legSide + "Ball");
ikHandle -n ($legSide + "AnkleIK") -sol ikSCsolver -s "sticky";


select -r ($legSide + "Ball");
select -tgl ($legSide + "Toe");
ikHandle -n ($legSide + "FootIK") -sol ikSCsolver -s "sticky";


//ATTACH FOOT CONTROLLER


parent ($legSide + "KneeIK") ($legSideLong + "FootController");
parent ($legSide +  "AnkleIK") ($legSideLong + "FootController");
parent ($legSide + "FootIK") ($legSideLong + "FootController");


select -r ($legSideLong + "FootController");


//LET USER KNOW SCRIPT HAS BEEN RUN


print ("The " + $legSideLong + " no-flip knee has been created.");

And the second script:


// generate a random set of transform data  
float $tMin = 1.0;
float $tMax = 12.0;
float $tRand[] = {rand($tMin, $tMax), rand($tMin, $tMax), rand($tMin, $tMax)};
float $rMin = 1.0;
float $rMax = 359.0;
float $rRand[] = {rand($rMin, $rMax), rand($rMin, $rMax), rand($rMin, $rMax)};
float $sMin = 0.4;
float $sMax = 2.0;
float $sRand[] = {rand($sMin, $sMax), rand($sMin, $sMax), rand($sMin, $sMax)};


// make a sphere
string $buffer[] = `sphere`;
string $randomSphere = $buffer[0];


// set the random values into the sphere's transform
xform -ws -t $tRand[0] $tRand[1] $tRand[2] -ro $rRand[0] $rRand[1] $rRand[2] -s $sRand[0] $sRand[1] $sRand[2] $randomSphere;
 
// create a new default sphere that we can use to snap to the random one
string $buffer[] = `polySphere -n "copyCatObject"`;
string $copyCatObject = $buffer[0];


// query the position/rotation/scale of the random sphere and store values
float $trans[] = `xform -q -t $randomSphere`;
float $rots[] = `xform -q -ro $randomSphere`;
float $scls[] = `xform -q -s $randomSphere`;


// set the position/rotation/scale of the copyCatSphere to match the random sphere
xform -ws -t $trans[0] $trans[1] $trans[2] -ro $rots[0] $rots[1] $rots[2] -s $scls[0] $scls[1] $scls[2] $copyCatObject;
}


I've also been doing some character stuff and rigging trials. Might record these in action and post them up later.

2 comments:

  1. Hey Sophie thought I'd return the favour.
    Its alot simpler than you'd think, all you need to do is edit a tag in CSS.
    In blogger go to -> Deign -> Template -> Customize -> Advanced -> Add CSS (scroll Down) and add some modified tag (shown in my post here)
    http://ldunham.blogspot.com/2011/11/html-and-css.html
    Hope that helps ya!

    ReplyDelete
    Replies
    1. Hey Lee!

      Thanks for the brilliant wee bit of CSS there! As you might be able to see, I've modified my post to include it and tweaked with the code a little. I doubt I was much help with that original thread (at least my own contribution - my bird had it's root joint in the head for a start...) but it's nice to see you gave a little back! Haha!

      Cheers again,

      Sophie.

      Delete