Skip to content

Instantly share code, notes, and snippets.

@andrewerf
Last active February 6, 2025 09:15
Show Gist options
  • Save andrewerf/bfd49db3c69572f27435a059b34cd541 to your computer and use it in GitHub Desktop.
Save andrewerf/bfd49db3c69572f27435a059b34cd541 to your computer and use it in GitHub Desktop.
Correct Voxel Operations in MeshLib
VdbVolume vol1 = obj1_->vdbVolume();
VdbVolume vol2 = obj2_->vdbVolume();
const float iso1 = obj1_->getIsoValue();
const float iso2 = obj2_->getIsoValue();
float resIso = iso1;
// select the smallest object. In case of a not identity transformations, it will be transformed to the space of the largest object
auto xf = obj1_->xf().inverse() * obj2_->xf();
auto postXf = xf;
if ( xf != AffineXf3f() )
{
if ( vol1.data->activeVoxelCount() < vol2.data->activeVoxelCount() )
{
vol1 = transformVdbVolume( vol1, xf.inverse() ).volume;
postXf = obj2_->xf();
}
else
{
vol2 = transformVdbVolume( vol2, xf ).volume;
postXf = obj1_->xf();
}
}
auto& grid1 = *vol1.data;
auto& grid2 = *vol2.data;
auto resGrid = openvdb::tools::csgDifferenceCopy(ovdb(grid1), ovdb(grid2));
std::shared_ptr<ObjectVoxels> newObj = std::make_shared<ObjectVoxels>();
newObj->setName(operationNames[int(op)]);
newObj->construct( MakeFloatGrid( std::move( resGrid ) ), obj1_->vdbVolume().voxelSize );
newObj->setXf( postXf );
newObj->setIsoValue( resIso );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment