File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff line change @@ -57,11 +57,23 @@ namespace
57
57
template <typename T>
58
58
Imath::Box<Imath::Vec3<T> > worldBound ( const openvdb::GridBase *grid, float padding = 0 .50f )
59
59
{
60
- openvdb::Vec3i min = grid->metaValue <openvdb::Vec3i>( grid->META_FILE_BBOX_MIN );
61
- openvdb::Vec3i max = grid->metaValue <openvdb::Vec3i>( grid->META_FILE_BBOX_MAX );
60
+ openvdb::CoordBBox vdbBbox;
61
+ try
62
+ {
63
+ vdbBbox.min () = openvdb::Coord ( grid->metaValue <openvdb::Vec3i>( grid->META_FILE_BBOX_MIN ) );
64
+ vdbBbox.max () = openvdb::Coord ( grid->metaValue <openvdb::Vec3i>( grid->META_FILE_BBOX_MAX ) );
65
+ }
66
+ catch ( ... )
67
+ {
68
+ // If we don't have metadata available, then hopefully it's because the vdb was freshly created and
69
+ // hasn't been saved to file yet, which should mean it's fully loaded, and we can call
70
+ // evalActiveVoxelBoundingBox.
71
+ // \todo : Can we guarantee that every VDB either is loaded, or has metadata?
72
+ vdbBbox = grid->evalActiveVoxelBoundingBox ();
73
+ }
62
74
63
75
openvdb::Vec3d offset = openvdb::Vec3d ( padding );
64
- openvdb::BBoxd indexBounds = openvdb::BBoxd ( min - offset, max + offset );
76
+ openvdb::BBoxd indexBounds = openvdb::BBoxd ( vdbBbox. min () - offset, vdbBbox. max () + offset );
65
77
openvdb::BBoxd worldBounds = grid->transform ().indexToWorld ( indexBounds );
66
78
openvdb::Vec3d minBB = worldBounds.min ();
67
79
openvdb::Vec3d maxBB = worldBounds.max ();
You can’t perform that action at this time.
0 commit comments