// =========================================================================== // 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: May 2000 // // // // Procedure Name: // fluidsVerifyGrid // // Description: // Verifies that selected fluids have either static or // dynamic (as appropriate) grids for the $current // property. Values of $current are expected to be UI // names of paintable fluid attributes, such as those // listed in the $paintProperties array below. We do // it this way, since it's also ok to pass in // combinations of these attributes, as in // "colorAndDensity". // // Return Value: // "true" if property $current is set to either static or // dynamic grid. $makeGridCmd is unchanged. // // "false" if property $current is not set to either static or // dynamic grid. $makeGridCmd[0] contains the MEL command // to set active fluids to dynamic grid. $makeGridCmd[1] is // the MEL command to make them static. // global proc int activeFluidsVerifyGrid( string $current, string $makeGridCmd[] ) // // Description: // For active fluids, call fluidsVerifyGrid. // { int $result = true; string $selectedFluids[] = `getActiveFluidShapes`; if( size( $selectedFluids ) > 0 ) { for( $fluid in $selectedFluids ) { if( !fluidsVerifyGrid( $fluid, $current, $makeGridCmd ) ) { $result = false; } } } return $result; } global proc int fluidsVerifyGrid( string $fluid, string $current, string $makeGridCmd[] ) { $current = tolower( $current ); string $ctx = `currentCtx`; int $ok = true; // These are the settings for the artFluidAttrCtx cmd. // Note that we don't worry about combinations of properties // (like "colorAndDensity" since we'll test those individually // based on matching the single property name. // // When adding a paint property here, make sure the lengths of // all four arrays are kept in sync. // string $paintProperties[] = { "density", "color", "temperature", "fuel", "velocity", "textureCoordinates", "falloff" }; // These are the fluid attribute names to check for grid status for // the above corresponding paint context properties. // string $fluidAttributes[] = { ".densityMethod", ".colorMethod", ".temperatureMethod", ".fuelMethod", ".velocityMethod", ".coordinateMethod", ".falloffMethod" }; // The min/max numeric value for each of the above fluid attributes // that corresponds to a Grid valued-attribute. Notice for // attributes that don't support static grids (fuel and textureCoords) // we're just using a value that's the same as the dynamic value. // int $staticValues[] = { 1, // densityMethod 1, // colorMethod 1, // temperatureMethod 2, // fuelMethod 1, // velocityMethod 1, // textureCoordinates 1 }; // falloffMethod int $dynamicValues[] = { 2, // densityMethod 2, // colorMethod 2, // temperatureMethod 2, // fuelMethod 2, // velocityMethod 1, // textureCoordinates 1 }; // falloffMethod (no dynamic, just static) // Keep track of the commands we might need to // execute for static/dynamic grids individually. (We'll // need one or the other depending on the response from // the confirm box below.) // string $createDynamic; string $createStatic; int $i = 0; int $numMatches = 0; for( ; $i < size( $paintProperties ); $i++ ) { if( size( match( tolower($paintProperties[$i]), tolower($current) ) ) ) { int $method = eval( "getAttr " + $fluid + $fluidAttributes[$i] ); $numMatches++; // This property is already set to grid. // if(( $method == $staticValues[$i] ) || ( $method == $dynamicValues[$i] )) { continue; } $ok = false; // The static value is the same as the dynamic value -- // only show "Dynamic Grid" option // if(( $staticValues[$i] != $dynamicValues[$i] )) { $createStatic = $createStatic + ( "setAttr " + $fluid + $fluidAttributes[$i] + " " + $staticValues[$i] + "; " ); } $createDynamic = $createDynamic + ( "setAttr " + $fluid + $fluidAttributes[$i] + " " + $dynamicValues[$i] + "; " ); } } // If they're painting combinations (color + density, // for instance) then we're just going to make it easier // on ourselves and forget about the fact that color doesn't // really have a "static grid" mode by removing the "set static" // option from the confirm box. // if( $numMatches > 1 ) { $createStatic = ""; } $makeGridCmd[0] = $makeGridCmd[0] + $createDynamic; $makeGridCmd[1] = $makeGridCmd[1] + $createStatic; return $ok; }