// =========================================================================== // 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. // =========================================================================== // // // Cloning Date: Nov 2001 // // Description: Helper procs for processing of / operations on // fluids playback caches. // global proc string[] fluidPlaybackCaches_disableUnselected() // // Description: // For any fluid playback cache whose fluid isn't currently // selected, disable it and return the list of caches disabled. // { if( !`exists getActiveFluidShapes` ) { source "getFluidShape.mel"; } string $activeFluids[] = `getActiveFluidShapes`; string $caches[] = `ls -type diskCache`; string $changedCaches[] = {}; if( size( $activeFluids ) == 0 ) { error (uiRes("m_fluidPlaybackCaches.kFluidCacheFailureError")); return $changedCaches; } // Disable any any nodes for unselected fluids // for( $cache in $caches ) { int $activeCache = false; int $isEnabled = eval( "getAttr \"" + $cache + ".enable\"" ); int $isPB = (eval("getAttr \"" + $cache + ".cacheType\"") == "mcfp"); if( !$isEnabled || !$isPB ) { continue; } for( $fluid in $activeFluids ) { string $connections[] = eval( "listConnections \"" + $fluid + ".diskCache\"" ); for( $connectedCache in $connections ) { if( $connectedCache == $cache ) { $activeCache = true; break; } } if( $activeCache ) { break; } } if( !$activeCache ) { eval( "setAttr \"" + $cache + ".enable\" false" ); $changedCaches[ size($changedCaches) ] = $cache; } } return $changedCaches; } global proc fluidPlaybackCaches_enable( string $cachesToEnable[] ) // Enable any diskCache nodes passed in via $cachesToEnable // { // Restore the "enabled" state of any nodes you changed // for( $cache in $cachesToEnable ) { eval( "setAttr \"" + $cache + ".enable\" true" ); } } proc int fluidPlaybackCaches_appendConfirmBox( float $start, float $end ) // // Description: // Helper proc to post a confirm box in the case // where we're appending and the new End Time is // less then the previous End Time. In this case, // the user may not expect that the newly "appended" // cache will end at the new End Time. (Append // really just does a truncate at start, and append until // the end.) // { int $result = true; string $fluids[] = getActiveFluidShapes(); string $yes = (uiRes("m_fluidPlaybackCaches.kYes")); string $no = (uiRes("m_fluidPlaybackCaches.kNo")); for( $f in $fluids ) { if( `fluidCacheInfo -q -hc -pb $f` == 0 ) { continue; } float $oldEnd = `fluidCacheInfo -q -ef -pb $f`; if( $end >= $oldEnd ) { continue; } // The user will lose the data from $newEnd to $end. // Make sure he knows this. // string $message = (uiRes("m_fluidPlaybackCaches.kAppendMessage")); $message = `format -s $end $message`; string $lastChance = `confirmDialog -title (uiRes("m_fluidPlaybackCaches.kWarning")) -message $message -button $yes -button $no -defaultButton $no -cancelButton $no -dismissString $no`; if( $lastChance == $no ) { $result = false; } // Only need one confirm box... // break; } // If the currentTime isn't the same as the // append startTime, the resulting cache might // not look like it's continuous. Pop up a // warning... // if( $result ) { float $currTime = `currentTime -q`; if( !equivalent( $start, $currTime ) ) { string $title = (uiRes("m_fluidPlaybackCaches.kAppendStartTimeWarning")); string $message = (uiRes("m_fluidPlaybackCaches.kFluidStateMessage")); $message = `format -s $start $message`; string $lastChance = `confirmDialog -title $title -message $message -messageAlign "left" -button $yes -button $no -defaultButton $no -cancelButton $no -dismissString $no`; if( $lastChance == $no ) { $result = false; } } } return $result; } global proc fluidPlaybackCaches_append( float $startTime, float $endTime, string $overSample, int $sampleRate ) // // Description: // Preprocessing before calling the "diskCache -append" cmd. // { if( fluidPlaybackCaches_appendConfirmBox( $startTime, $endTime ) ) { string $disabledCaches[] = `fluidPlaybackCaches_disableUnselected`; int $oldEnable = `getAttr globalCacheControl.writeEnable`; setAttr globalCacheControl.writeEnable 1; // Figure out how much before the current time we // want to truncate, so "append" will happen at the // right position. // float $interval = $sampleRate; if( !equivalent( $sampleRate, 0.0 ) ) { $interval = 1.0 / $interval; } // Truncate leaves the data at the currentTime in // the cache. If we're appending, we want to overwrite // the currentTime with what we're seeing in the fluid, // so we need to keep everything *before* the current time. // currentTime -update false ( $startTime - $interval ); truncateFluidCache; currentTime -update false $startTime ; setAttr globalCacheControl.writeEnable $oldEnable; // currentTime $currTime; evalEcho( "diskCache -append -enabledCachesOnly " + " -startTime " + $startTime + " -endTime " + $endTime + " " + $overSample + " -samplingRate " + $sampleRate + "; " ); fluidPlaybackCaches_enable( $disabledCaches ); } }