AcademySoftwareFoundation / openvdb

OpenVDB - Sparse volume data structure and tools
http://www.openvdb.org/
Mozilla Public License 2.0
2.62k stars 647 forks source link

[REQUEST] SDF Xor operation #1748

Open MysteryPancake opened 8 months ago

MysteryPancake commented 8 months ago

Currently OpenVDB supports the following SDF operations:

SDF Union: min(d1, d2)

SDF Intersection: max(d1, d2)

SDF Difference (usually named SDF Subtraction): max(-d1, d2)

However, it doesn't support the XOR operation described by Inigo Quilez: max(min(d1, d2), -max(d1, d2))

This operation finds regions where the sign mismatches.

image

It would be nice to include all standard SDF operations in OpenVDB.

ghurstunither commented 7 months ago

As a workaround you can find the symmetric difference with

csgUnionCopy(csgDifferenceCopy(grid1, grid2), csgDifferenceCopy(grid2, grid1))

or

csgDifferenceCopy(csgUnionCopy(grid1, grid2), csgIntersectionCopy(grid1, grid2))

For an in-place workaround, this might be the most efficient:

gridint = csgIntersectionCopy(grid1, grid2);
csgUnion(grid1, grid2);
csgDifference(grid1, gridint);