// =========================================================================== // 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: 1998 // global proc makeBrushSpring( float $defStiff, float $defDamp, float $defTravel, int $startFrame ) { int $i; string $brushes[]; $brushes = getSelectedBrushes(); int $numBrushes = size( $brushes ); if( $numBrushes == 0 ) { warning( uiRes("m_bakeBrushSpringAnim.kNoBrushSelected") ); return; } for( $i = 0; $i < $numBrushes; $i++ ) { string $brush = $brushes[$i]; string $strokeCon[] = `listConnections ( $brush + ".outBrush")`; if( size( $strokeCon ) > 0 ) { string $stroke = $strokeCon[0]; if ( !objExists( $stroke + ".lastWX" ) ) { addAttr -sn lwx -ln lastWX -dv 0 $stroke; } else { string $expNode[] = `listConnections ($stroke + ".lastWX")`; if( size( $expNode ) > 0 ) { // This should be another spring expression Node // We delete it to make way for the new one delete $expNode[0]; } } if ( !objExists( $stroke + ".lastWY" ) ) { addAttr -sn lwy -ln lastWY -dv 0 $stroke; } if ( !objExists( $stroke + ".lastWZ" ) ) { addAttr -sn lwz -ln lastWZ -dv 0 $stroke; } if ( !objExists( $stroke + ".lastVX" ) ) { addAttr -sn lvx -ln lastVX -dv 0 $stroke; } if ( !objExists( $stroke + ".lastVY" ) ) { addAttr -sn lvy -ln lastVY -dv 0 $stroke; } if ( !objExists( $stroke + ".lastVZ" ) ) { addAttr -sn lvz -ln lastVZ -dv 0 $stroke; } if ( !objExists( $brush + ".springStiffness" ) ) { addAttr -sn sst -ln springStiffness -dv $defStiff -min 0 -max 1 $brush; } else { setAttr ($brush + ".springStiffness") $defStiff; } if ( !objExists( $brush + ".springDamp" ) ) { addAttr -sn sdp -ln springDamp -dv $defDamp -min 0 -max 1 $brush; } else { setAttr ($brush + ".springDamp") $defDamp; } if ( !objExists( $brush + ".springTravel" ) ) { addAttr -sn spt -ln springTravel -dv $defTravel -min 0 -max 100 $brush; } else { setAttr ($brush + ".springTravel") $defTravel; } string $expStr = ""; // find the vertex nearest the middle of the stroke int $numStrokePoints = `getAttr -size ($stroke + ".outPoint")`; int $midVert = $numStrokePoints/2; string $strokePoint = ($stroke + ".outPoint[" + $midVert + "]"); $expStr = $expStr + ( "float $px = " + $strokePoint + ".outPointX;\n" + "float $py = " + $strokePoint + ".outPointY;\n" + "float $pz = " + $strokePoint + ".outPointZ;\n" + "float $wx = " + $stroke + ".lastWX;\n" + "float $wy = " + $stroke + ".lastWY;\n" + "float $wz = " + $stroke + ".lastWZ;\n" + "float $vx = " + $stroke + ".lastVX;\n" + "float $vy = " + $stroke + ".lastVY;\n" + "float $vz = " + $stroke + ".lastVZ;\n" + "float $stiff = " + $brush + ".springStiffness;\n" + "float $istiff = 1-$stiff;\n" + "float $damp = 1 - " + $brush + ".springDamp;\n" + "float $travel = " + $brush + ".springTravel;\n" + "float $fx = 0; float $fy = 0; float $fz = 0;\n" + "if( frame > " + ($startFrame + 1) + " ){\n" + " $fx = " + $brush + ".uniformForceX * $istiff + $stiff * ($wx - $px) * $travel + $vx;\n" + " $fy = " + $brush + ".uniformForceY * $istiff + $stiff * ($wy - $py) * $travel + $vy;\n" + " $fz = " + $brush + ".uniformForceZ * $istiff + $stiff * ($wz - $pz) * $travel + $vz;\n" + " " + $stroke +".lastVX = $vx * $damp -$fx * $stiff;\n" + " " + $stroke +".lastVY = $vy * $damp -$fy * $stiff;\n" + " " + $stroke +".lastVZ = $vz * $damp -$fz * $stiff;\n" + "}else{\n" + " " + $stroke +".lastVX = 0;\n" + " " + $stroke +".lastVY = 0;\n" + " " + $stroke +".lastVZ = 0;\n" + "}\n" + $brush + ".uniformForceX = $fx;\n" + $brush + ".uniformForceY = $fy;\n" + $brush + ".uniformForceZ = $fz;\n" + $stroke +".lastWX = $px;\n" + $stroke +".lastWY = $py;\n" + $stroke +".lastWZ = $pz;\n" ); expression -s $expStr; } } }