Script Overview: The script I made randomises vertices's on a mesh and places them at random co-ordinates each time it is run. I choose to go with this script as I didn't want to go to complex and cause myself frustration.
Development Process: The first thing I did was create the 'for' statement that would grab all the verts on the mesh and move them to a random co-ordinate within a delegated range. When I had that all working I put the 'For' statement within a proc and created a window for it to pop up in and allow a button for the user to press to run the script at anytime. Below is the script as I made it.
//select the mesh you desire to randomise the verts on and run scriptReflection: Being my first experience with programming I am quite happy with the script I have created. The course, along with the text book MEL Scripting for Maya Animators by Mark R. Wilkins, Chris Kazmier and Stephan Osterburg , gave me a basic understanding of MEL programming which I believe will be extremely valuable in the future.
//Click button with mesh selected and BAM the verts randomise
if(`window -exists rVerts`)//Checks to see if window exists
deleteUI -window rVerts;//If the window exists it is closed
window -title "Randomize Verts" //Puts a title on the window
-widthHeight 100 100 //Width and Height of window
rVerts;
columnLayout;//The type of layout of the window
button -label "Randomize" -command randomVerts;//the button name and command it will execute
showWindow rVerts; //shows the window
proc randomVerts()
{
$Selected = `ls -sl`; // this line lists the selceted objects and defines what $selected will do
$myVerts = `getVerts`; // this line grabs all the vertices of selected objects and puts them into a string array represtented by $myVets
for ($vert in $myVerts) // this line says for every Vertice selected in the array of $myVerts to run the following commands
{
float $randNumX = rand ( -0.5, 0.5 );//this line defines how many units the verts will randomly move vertices in the X axis
float $randNumY = rand ( -0.5, 0.5 );//this line defines how many units the verts will randomly move vertices in the Y axis
float $randNumZ = rand ( -0.5, 0.5 );//this line defines how many units the verts will randomly move vertices in the Z axis
select -r $vert ;//this line replaces the mesh selection with the selection of the vertices within the selcted mesh
move -r $randNumX $randNumY $randNumZ ;//this line moves the verts randomly according to the values defined above
select -r $Selected; // returns or reselectes the previously selected object
}
}
Stay Frosty
No comments:
Post a Comment