global float $ctPreviousFrameVertexTranslationArray[]; global float $ctRandomDirection[]; /* Generates and stores a random offset direction for each vertex during initialization*/ global string $ctSelectedVertexNames[]; global int $ctVertexCount; proc ctWobbleInitialize() { // Redeclare global variables to create access to global variables global float $ctPreviousFrameVertexTranslationArray[]; global float $ctRandomDirection[]; /* Generates and stores a random offset direction for each vertex during initialization*/ global string $ctSelectedVertexNames[]; global int $ctVertexCount; string $ctSelectedVertices1[]; // Get the list of selected vertices $ctSelectedVertices1=`filterExpand -sm 46`; string $ctCurrentVertexName; // Get the vertex count $ctVertexCount =size($ctSelectedVertices1); int $cti=0; // Process and store each of the selected vertices for($cti=0;$cti<$ctVertexCount;$cti++) { // Initialize the previous frame translation values to zero $ctPreviousFrameVertexTranslationArray[3*$cti]=0.0; $ctPreviousFrameVertexTranslationArray[(3*$cti)+1]=0.0; $ctPreviousFrameVertexTranslationArray[(3*$cti)+2]=0.0; // Get and store the name of the current vertex $ctSelectedVertexNames[$cti]=$ctSelectedVertices1[$cti]; //print $ctSelectedVertexNames[$cti]; //print "\n"; // Generate a random offset direction for this vector and store it in the ctRandomDirectionArray[] vector $ctRandomVector=`rand <<1.0,1.0,1.0>>`; // Normalize the random direction float $ctTempVectorHolder[3]; $ctTempVectorHolder[0]=($ctRandomVector.x); $ctTempVectorHolder[1]=($ctRandomVector.y); $ctTempVectorHolder[2]=($ctRandomVector.z); normalize($ctTempVectorHolder); // Store the normalized random direction in the ctRandomDirectionArray[] $ctRandomDirection[(3*$cti)]=$ctTempVectorHolder[0]; $ctRandomDirection[(3*$cti)+1]=$ctTempVectorHolder[1]; $ctRandomDirection[(3*$cti)+2]=$ctTempVectorHolder[2]; } } //////////////// Main Function ///////////////// global proc ctWobbleMain() { global float $ctPreviousFrameVertexTranslationArray[]; global float $ctRandomDirection[]; /* Generates and stores a random offset direction for each vertex during initialization*/ global string $ctSelectedVertexNames[]; global int $ctVertexCount; global int $ctCurrentFrameCount1; // Read the current frame count $ctCurrentFrameCount1=`currentTime -q`; if($ctCurrentFrameCount1 == 1) { // If the list of vertices has not been read already then read it ctWobbleInitialize(); } // Update the vertex positions for this frame int $cti=0; for($cti=0;$cti<$ctVertexCount;$cti++) { // Move the vertex back to it’s original position, by reverse translating based on the previous frame translation values stored in the $ctPreviousFrameVertexTranslationArray[] // Reset the vertex to the original position move -r (-$ctPreviousFrameVertexTranslationArray[3*$cti]) (-$ctPreviousFrameVertexTranslationArray[(3*$cti)+1]) (-$ctPreviousFrameVertexTranslationArray[(3*$cti)+2]) $ctSelectedVertexNames[$cti]; float $ctOffset; float $ctScaledOffset; // Read into the three dimensional noise field for a offset magnitude $ctOffset=`noise <<$cti,$cti,($ctCurrentFrameCount1 * 0.04 /* Controls the speed of the oscillation*/)>>`; $ctScaledOffset=$ctOffset * 1.0; /* Controls the magnitude of the displacement */ global float $ctCurrentFrameXDisplacement; global float $ctCurrentFrameYDisplacement; global float $ctCurrentFrameZDisplacement; $ctCurrentFrameXDisplacement=$ctRandomDirection[3*$cti] * $ctScaledOffset; $ctCurrentFrameYDisplacement=$ctRandomDirection[(3*$cti)+1] * $ctScaledOffset; $ctCurrentFrameZDisplacement=$ctRandomDirection[(3*$cti)+2] * $ctScaledOffset; // Offset the vertex in the current frame move -r $ctCurrentFrameXDisplacement $ctCurrentFrameYDisplacement $ctCurrentFrameZDisplacement $ctSelectedVertexNames[$cti]; // Store the current frame displacement in the array $ctPreviousFrameVertexTranslationArray[3*$cti]=$ctCurrentFrameXDisplacement; $ctPreviousFrameVertexTranslationArray[(3*$cti)+1]=$ctCurrentFrameYDisplacement; $ctPreviousFrameVertexTranslationArray[(3*$cti)+2]=$ctCurrentFrameZDisplacement; } }