Open VDB
Calculate collision with VDB
vector product;vector sum;float volumevalue;volumevalue = volumesample(1, 0, @P);product = @N * volumevalue;@P = @P + product;
Push out from VDB
Example how to push out points from VDB which is used as a collision primitive.
float volsample = volumesample(1, 0, @P);vector volumegrad = volumegradient(1, 0, @P);vector push_out = volumegrad * -volsample;@P += push_out;
Delete SDF parts by Voxel count
Some of my friends asked how we can remove small SDF parts, similar to how we do it with geometry by calculating the area of connected parts. Yes, we can convert the SDF to polygons, measure the parts, delete them, and convert it back to SDF - but that’s quite an expensive operation.
So, as a solution, we can use the VDB Fracture SOP node, which splits the SDF by connectivity. Then, in a Primitive Wrangle, we can get the voxel count of each primitive - each primitive is a separate SDF container. As long as we know the voxel count range, we can simply say: if the voxel-count is less than N-voxel, remove the primitive - and that’s it.
int prim = @primnum;
int vxcount = primintrinsic(0, "activevoxelcount", prim);if (vxcount < 500 ) removeprim(0, prim, 1);