Files
workinf_Blender_Wasm/blender-5.2.0/extern/mantaflow/patches/import-openvdb-empty-cubes-fix.patch
2026-08-12 04:47:48 -04:00

47 lines
2.1 KiB
Diff

commit 725df6eb883dadf2225938baecf97c005da5b549
Author: Bartosz Kosiorek <gang65@poczta.onet.pl>
Date: Wed May 21 22:44:01 2025 +0200
Physics: Fix OpenVDB import visual glitches, by copying full 8x8x8 nodes
If grid has 8x8x8 block with the same value, it is stored as Tile with single value.
We need to iterate over the bounding box and copy such value to all voxels in 8x8x8 node.
Fixes: #91174 #124064
diff --git a/extern/mantaflow/preprocessed/fileio/iovdb.cpp b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
index 4b7463782da..85ab3781e5a 100644
--- a/extern/mantaflow/preprocessed/fileio/iovdb.cpp
+++ b/extern/mantaflow/preprocessed/fileio/iovdb.cpp
@@ -54,14 +54,28 @@ template<class GridType, class T> void importVDB(typename GridType::Ptr from, Gr
using ValueT = typename GridType::ValueType;
// Check if current grid is to be read as a sparse grid, active voxels (only) will be copied
+
if (to->saveSparse()) {
to->clear(); // Ensure that destination grid is empty before writing
for (typename GridType::ValueOnCIter iter = from->cbeginValueOn(); iter.test(); ++iter) {
ValueT vdbValue = *iter;
- openvdb::Coord coord = iter.getCoord();
T toMantaValue;
convertFrom(vdbValue, &toMantaValue);
- to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ // #91174 #124064 - Check if iteration is Voxel or Tile
+ if (iter.isVoxelValue()) {
+ openvdb::Coord coord = iter.getCoord();
+ to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ }
+ else {
+ openvdb::CoordBBox bbox;
+ iter.getBoundingBox(bbox);
+ // If grid has 8x8x8 block with the same value, it is stored as Tile with single value.
+ // We need to iterate over the bounding box and copy such value to all voxels in 8x8x8 node.
+ for (openvdb::CoordBBox::Iterator<true> ijk(bbox); ijk; ++ijk) {
+ openvdb::Coord coord = *ijk;
+ to->set(coord.x(), coord.y(), coord.z(), toMantaValue);
+ }
+ }
}
}
// When importing all grid cells, using a grid accessor is usually faster than a value iterator