Point Cache Doctor script

This is a little standalone python script written for the Tube project to solve some issues with cloth simulation. (code in attachments)

It implements reading/writing of the binary point cache format of Blender point caches to manipulate cached simulation data outside of Blender. The primary function is a low-pass filter being applied to cloth simulation to smooth out small-scale jittering artifacts.

I don’t intend to spend much more time on this, but thought it might be useful if others want to implement their own functionality. With the basic read/write methods in place it is fairly straightforward to add more actions to the script.

Note: The script only supports uncompressed point caches so far - it may be possible to support compression, but i’d rather not invest more time in it. Disk space is cheap!

Usage:
The script is a standalone python script (no bpy imports), which can be run directly in a python interpreter or from a terminal after making it executable (“chmod +x” on *nix). Running it will give you an over view of the command line options.

Note: I recommend making a backup of the point cache files, then go to the backup folder and run the script from there, using the --output argument to make it write back to the original directory where Blender expects the cache data. That way you don’t risk losing baked point cache data and can play around with the settings. The script asks for permission first if you try to overwrite cache files in the same folder.

usage: pointcache_doctor.py [-h] [-i [INPUT]] [-o [OUTPUT]] [-n [INDEX]]                            [--lowpass_factor [LOWPASS_FACTOR]]
                            {show,copy,lowpass}


Examine and fix Blender point cache data.


positional arguments:
  {show,copy,lowpass}   Action to perform on the point cache


optional arguments:
  -h, --help            show this help message and exit
  -i [INPUT], --input [INPUT]
                        Input directory containing physics point cache files
  -o [OUTPUT], --output [OUTPUT]
                        Output directory for modified point cache files
  -n [INDEX], --index [INDEX]
                        Index of the cache if multiple caches exist in the
                        directory (default=0)
  --lowpass_factor [LOWPASS_FACTOR]
                        Smoothing factor for the lowpass action

The “lowpass” action can be used to smooth out cloth movement over a few frames:

python pointcache_doctor.py lowpass --lowpass_factor=0.8

It uses exponential smoothing, i.e. the influence of a frame decreases exponentially over time. After N frames the influence of a past frame will mixed in with lowpass_factor^N (check the wikipedia article for in-depth info).

Attachments

pointcache_doctor.py.zip (3.84 KB)

2 Likes

awesome Lukas!!! testing now :slight_smile:

Hey Lukas, trying it right now and there is one small problem; I’ll see if I can figure it out, but it isn’t a deal breaker for me: it is that pinned points also get smoothed.
For me this is no problem since the cloth is actually used to move a rig so I can just not use the pinned points and use the hook directly instead.

I don’t think the information about pinned points is stored in the cache. Cloth has an attribute called “XCONST” and i have no idea what this is :confused: (it’s a vector though, so unlikely it’s pin booleans). We could just export a list of pinning true/false values and pass that to the script, or run it directly inside Blender to access that data via bpy.

Well, for me this is a non-issue, since I can simply reverse the stack order after I bake and the cache is good for the non pinned verts. It could be an issue for some people, but probably not worth ‘fixing’ quite yet.

Ok I can confirm that the script is working brilliantly I’ll make a post with some video about it soon :smiley: