PointCache2
An overhauled version of the PointCache modifier that ships with Max4.
Features that are different from the original:
- Adjustable playback ranges and a playback graph, to animate which cache frame is played back. Allows you to load a cache, then animate it slowing down, stoping, reversing, etc.
- Nth frame sampling, so you can sample every few frames so you can save disk space if sampling every frame is not necessary.
- The "strength" is adjustable in Absolute mode, so you can easily blend the cache with what is below in the stack.
- Improved cache file management in the UI.
- If 10 cache files are missing in a scene, you only get one error message with all the files listed, instead of 10 separate error messages.
- Pre-loaded caches to speed up playback.
- Bug fixes.
Options:
- Cache File Group:
- Filename
An editable text box that displays the currently loaded cache file.
- Force UNC Path
This will force any picked filename to be a UNC style path, if possible (as opposed to using a drive-letter style path).
- New.../Load...
Prompts for a new filename or an existing filename to be used for the cache.
- Unload
Temporarily frees the current cache file, so it can be edited or deleted externally.
- Reload
Re-opens the current cache file, if previously unloaded.
- Browse Cache Dir...
Opens an Explorer window at the location of the current cache file.
If you want to move/delete/rename the current cache file, make sure you hit "Unload" first, to free the file for modification.
- Cache Info Group:
This area simply gives information about the currently loaded cache, or whether there's any current errors.
- Record Group:
- Start/End:
Sets the time range to record.
- Sample Rate:
Sets how often the object is sampled when recording. A value of 1.0 records once every frame, 0.1 will record ten samples per frame, and 10 will record every ten frames.
- Record:
Records to the current cache file, or prompts for a filename and then records if there is no current cache file specified.
- Enable/Disable Modifiers Below:
Does what is says... make sure you disable modifiers below the cache after recording to gain any benifit from using the cache in the first place.
- Playback Options Group:
- Strength:
Sets the effect of the cache. At 1.0, the cache plays back what it originally recorded. Less than 1.0 will reduce the effect.
- Use Relative Offsets:
When on, only the differences from the first frame of the cache are used to distort the current object. When off, the point positions in the cache file explicitly set the point positions of the current object.
- PreLoad Cache:
When on, loads the entire PointCache file into RAM for fast access. Specifically useful for networks, or when a few caches are used by many objects in one scene (in which case, turning this on will prevent each object from thrashing the disk on playback).
Be conservative in usage of this, as it can eat up RAM fast (though if one cache file is used by several objects, the cache will only be loaded into RAM once). See pointCacheMan.GetUsedMemory() below.
- Playback Type Group:
- Original Range:
This will always play back the cache over the range it was originally recorded (so the animation will always be the same as the original).
- Custom Start:
This will play back the cache from a custom start time, but the animation length/playback speed will be the same as the original animation).
- Custom Range:
This allows you to set a start and end frames that the current cache plays back within. Using a range that is smaller than the original record range will play the cache back faster, a larger range plays the cache back slower.
- Playback Graph:
Allows you to animate which cache frame is played at any given time.
For example, if you record a cache from frame 0 to 100, set this parameter to 0 at frame 0, and animate it to 100 at frame 100. The function curve of this parameter in trackview shows how the cache is played back. Animating this lets you do funky things like slowly slow a cache down over time, or ping pong the cache playback, etc.
- Clamp Graph:
Controls what gets loaded when the playback graph frame is out of the original recorded range.
Take for example if the playback frame is set to 105, but the original cache was recorded over frames 0 - 100. With Clamp Graph on, the loaded frame will be 100. If it's off (the default now), the cache will "wrap around" and load frame 5.
This way, you can loop caches more easily. In the example above, you could simply have a two key playback graph. Key 1 would be at frame 0 with a value of 0, and key 2 would be at frame 100 with a value of 100. Then you would set the out-of-range type for the graph to "linear extrapolate", and the cache would smoothly loop back to the beginning at frame 101.
Back To Top...
MaxScript:
There are two global structs available for use with the modifier: cacheOps and pointCacheMan.
pointCacheMan has a single function: GetUsedMemory(). This will return the amount of memory (in bytes) used by all the preloaded cache files. Caches that aren't pre-loaded aren't taken into consideration.
For cacheOps, the first argument of all the functions is an instance of the PointCache2 modifier that you want to act on, and that modifier must be active in the modifier panel. ie:
obj = Sphere()
AddModifier obj (NoiseModifier scale:20 strength:[20,20,20] animate:true)
pcMod = PointCache2()
pcMod.cachefile = "c:\\temp\\foobar.pc2"
AddModifier obj pcMod
SetCommandPanelTaskMode mode:#modify
modPanel.SetCurrentObject pcMod
cacheOps.RecordCache pcMod
cacheOps.DisableBelow pcMod
The available functions are:
- cacheOps.RecordCache <PointCache2Modifier>
- Records a cache file. A valid cache filename must be assigned for this to work. Returns true on success or false on failure.
- cacheOps.EnableBelow <PointCache2Modifier>
- Enables all the modifiers below the specified cache modifier.
- cacheOps.DisableBelow <PointCache2Modifier>
- Disables all the modifiers below the specified cache modifier.
- cacheOps.Unload <PointCache2Modifier>
- Frees the current cache file, so it can be edited or deleted externally.
- cacheOps.Reload <PointCache2Modifier>
- Re-opens the current cache file, if previously unloaded.
Back To Top...
.PC2 File Format:
You can create or modify PointCache2 files by hand using the following file format. The start of the file is a header containing:
char cacheSignature[12]; // Will be 'POINTCACHE2' followed by a trailing null character.
int fileVersion; // Currently 1
int numPoints; // Number of points per sample
float startFrame; // Corresponds to the UI value of the same name.
float sampleRate; // Corresponds to the UI value of the same name.
int numSamples; // Defines how many samples are stored in the file.
Be sure to check the version number. If it isn't 1, then don't mess with the file, as the format will change in the future.
Following the header, there is a straight dump of all the cache samples (which are snapshots of all the point positions for an object). Each sample is stored one after the other as a flat array of x/y/z floats for each point (so each sample is (numPoints * sizeof(float) * 3) bytes).
See the included "PointCacheWriter.ms" script as an example.
Back To Top...
Known Bugs/Limitations:
- .PC2 files aren't compatible with the original .PNT PointCache files, and visa versa. Just re-record the cache to switch between the two.
- There are "interpolationType" and "OutOfRange" parameters available via Maxscript. Don't use them, they're not fully working :P.
Back To Top...
History:
2000.12.13 - Created.
2001.01.25 - Released.
2001.01.29 - Added "Apply To Spline".
2001.04.25 - For convenience, the object name is now the default cache name when creating a new cache.
- Replaced "Delete Cache File" button with safer "Browse Cache Dir".
- Reduced cache file locking problems (can usually delete cache now without exiting Max).
- Cache header is no longer read on cache overwrite.
2001.05.10 - Unload/Reload
- Default to current cache dir when hit "Load..."
2002.12.11 - Added playback_original and playback_start playback types
- Removed notification of missing pointcache files in R5 (covered by Missing Map dialog in R5)
2002.12.12 - Speedup: Only reads the two extra cubic samples when using cubic interpolation now (duh)
(not cubic interpolation is still fairly unsupported and possibly broken)
- Should be better at catching when to close cache files.
- Removed "Apply To Spline" from UI (not too useful anymore).
2002.12.13 - Added Cache PreLoading
- Fixed bug with caches simply not loading when large numbers of caches were active.
2002.12.14 - Sped up recording to network again
- Fixed UI flickering issue in R5
2002.12.19 - Added "Clamp Graph" to support looping playback better.
2003.01.15 - Check for invalid characters when basing initial cache filename after node name.
2003.02.12 - Bugfixes.
2003.03.07 - Bugfixes.
2003.06.04 - Added "Force UNC Path" option.
Back To Top...
Bug reports/comments/suggestions: foo@footools.com