Skip to content

Commit

Permalink
FIX : worldBound
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldresser-ie committed Jun 28, 2024
1 parent dd57c91 commit 7f0610c
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/IECoreVDB/VDBObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,23 @@ namespace
template<typename T>
Imath::Box<Imath::Vec3<T> > worldBound( const openvdb::GridBase *grid, float padding = 0.50f )
{
openvdb::Vec3i min = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN );
openvdb::Vec3i max = grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX );
openvdb::CoordBBox vdbBbox;
try
{
vdbBbox.min() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MIN ) );
vdbBbox.max() = openvdb::Coord( grid->metaValue<openvdb::Vec3i>( grid->META_FILE_BBOX_MAX ) );
}
catch( ... )
{
// If we don't have metadata available, then hopefully it's because the vdb was freshly created and
// hasn't been saved to file yet, which should mean it's fully loaded, and we can call
// evalActiveVoxelBoundingBox.
// \todo : Can we guarantee that every VDB either is loaded, or has metadata?
vdbBbox = grid->evalActiveVoxelBoundingBox();
}

openvdb::Vec3d offset = openvdb::Vec3d( padding );
openvdb::BBoxd indexBounds = openvdb::BBoxd( min - offset, max + offset );
openvdb::BBoxd indexBounds = openvdb::BBoxd( vdbBbox.min() - offset, vdbBbox.max() + offset );
openvdb::BBoxd worldBounds = grid->transform().indexToWorld( indexBounds );
openvdb::Vec3d minBB = worldBounds.min();
openvdb::Vec3d maxBB = worldBounds.max();
Expand Down

0 comments on commit 7f0610c

Please sign in to comment.