// =========================================================================== // 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. // =========================================================================== // // // Date: March 2004 // // Description: // Procedure for creating and attaching a diskCache // node to the fluidShape passed in. Fluid disk caches // come in two varieties: Playback caches (with an // "mcfp" extension) and Initial State caches (with an // "mcfi" extension). Furthermore, all diskCaches have // a ".cacheName" attribute which must eventually be set // with a string value representing the path to the physical // file containing the cache data for your fluid. // // Is is the value of $cacheTypeOrFilePath that // determines which type of fluid diskCache is created // by this procedure. The value passed in can be // either a cacheType (like "mcfi" or "mcfp") or a path // to the cache data file (like // "C:/myScene.mb_fluidShape1.mcfi"). (It is up to the // caller to ensure that the data in the specified // cache file is compatible with the specified fluid's // resolution.) If a path is specified, the new // diskCache's .cacheName attribute will be updated // with the location of the cache data file. // Otherwise, it is assumed that the .cacheName // attribute will be set properly elsewhere. // // Some examples: // // // Create a new Playback cache and attach it to fluidShape1. // // There is no data file yet for this cache. // // // createAndAttachFluidDiskCache( "fluidShape1", "mcfp" ); // // // Create a new Initial State cache and attach it to fluidShape1. // // There is no data file yet for this cache. (Note that // // it doesn't make a difference whether the "." is specified // // before the file extension/cache type or not.) // // // createAndAttachFluidDiskCache( "fluidShape1", ".mcfi" ); // // // Create a new Initial State cache and attach it to fluidShape1. // // The fluid's Initial State data comes from the absolute path // // specified. // // // createAndAttachFluidDiskCache( "fluidShape1", "C:/bug.mb_fluid1_fred.mcfi" ); // // // Create a new Playback cache and attach it to fluidShape1. // // The fluid's Playback data comes from the project-relative // // path specified. // // // createAndAttachFluidDiskCache( "fluidShape1", "data/bug.mb_fluid1_fred.mcfp" ); // // proc debugPrint( string $printThis ) { // print( " DEBUG: " + $printThis + "\n" ); } global proc string createAndAttachFluidDiskCache( string $fluid, string $cacheTypeOrFilePath ) { // Find out what cacheType we're working with: mcfi or mcfp? // string $nameBits[]; int $isFilePath = false; int $numTokens = tokenize( $cacheTypeOrFilePath, ".", $nameBits ); if( $numTokens > 1 ) { $isFilePath = true; } string $extension = $nameBits[$numTokens - 1]; // Based on extension/cacheType, we know which fluid attribute to // connect it to. // string $fluidAttr; string $nodeNamePrefix; if( $extension == "mcfi" ) { $fluidAttr = ".diskCacheIC"; $nodeNamePrefix = "initialState_"; debugPrint( "createAndAttachFluidDiskCache: mcfi -- " + $cacheTypeOrFilePath ); } else if( $extension == "mcfp" ) { $fluidAttr = ".diskCache"; $nodeNamePrefix = "cache_"; debugPrint( "createAndAttachFluidDiskCache: mcfp -- " + $cacheTypeOrFilePath ); } else { debugPrint( "createAndAttachFluidDiskCache: wrong type" ); if( $isFilePath ) { string $fmt = (uiRes("m_createAndAttachFluidDiskCache.kInvalidExtension")); error( `format -s $cacheTypeOrFilePath $fmt`); } else { error((uiRes("m_createAndAttachFluidDiskCache.kInvalidType"))); } return ""; } // Find a unique name, create the cache node, setup its attributes // and connect it to the fluid. // string $cacheName = uniqueCacheName($fluid, ("." + $extension)); string $diskCache = `createNode -n ($nodeNamePrefix+$fluid) diskCache`; setAttr -type "string" ($diskCache + ".hiddenCacheName") $cacheName; setAttr -type "string" ($diskCache + ".cacheType") $extension; debugPrint( "$cacheName = " + $cacheName ); debugPrint( "$diskCache = " + $diskCache ); debugPrint( "$extension = " + $extension ); debugPrint( "$isFilePath = " + $isFilePath ); debugPrint( "$fluidAttr = " + $fluidAttr ); // Only set this attribute value if we got a real filename passed // in as our cache's data file. // if( $isFilePath ) { setAttr -type "string" ($diskCache + ".cacheName") $cacheTypeOrFilePath; } // Connect the diskCache node to the appropriate attribute on the // fluid shape. (The attribute depends on the cacheType.) // connectAttr ($diskCache + ".diskCache") ($fluid + $fluidAttr ); return $diskCache; }