// =========================================================================== // Copyright 2018 Autodesk, Inc. All rights reserved. // // Use of this software is subject to the terms of the Autodesk license // agreement provided at the time of installation or download, or which // otherwise accompanies this software in either electronic or hard copy form. // =========================================================================== // // // Creation Date: 2005 // // // // // // // randomizeFollicles range // // // None. // // // This mel procedure randomizes the positions of selected follicles in uv space. // The passed in range value controls the scale of the randomization applied in // normalized uv space. // // // None. // // // // randomizeFollicles 0.1; // // global proc randomizeFollicles( float $range ) { string $follicles[] = `ls -sl -dag -type follicle`; int $numSelectedFollicles = size($follicles); if( $numSelectedFollicles > 0 ){ string $follicle; for( $follicle in $follicles ){ float $oldU = getAttr( $follicle + ".parameterU" ); float $oldV = getAttr( $follicle + ".parameterV" ); int $valid = false; int $tries = /*max tries*/8; while ($tries > 0) { float $u = $oldU + rand( $range ) - ($range*0.5); float $v = $oldV + rand( $range ) - ($range*0.5); setAttr ($follicle + ".parameterU") $u; setAttr ($follicle + ".parameterV") $v; if (getAttr($follicle + ".validUv")) { $valid = true; break; } $tries--; // roll again... } if (!$valid) { // reset the UV if we didn't find a valid one setAttr ($follicle + ".parameterU") $oldU; setAttr ($follicle + ".parameterV") $oldV; } } } else { warning((uiRes("m_randomizeFollicles.kNoFollicles")) ); } }