diff --git a/intern/cycles/render/volume.cpp b/intern/cycles/render/volume.cpp index fcf33a5e50a..7c70d7af372 100644 --- a/intern/cycles/render/volume.cpp +++ b/intern/cycles/render/volume.cpp @@ -307,58 +307,31 @@ void VolumeMeshBuilder::generate_vertices_and_quads(vector &vertices_ unordered_map used_verts; - for (auto iter = tree.cbeginLeaf(); iter; ++iter) { - openvdb::CoordBBox leaf_bbox = iter->getNodeBoundingBox(); - /* +1 to convert from exclusive to include bounds. */ - leaf_bbox.max() = leaf_bbox.max().offsetBy(1); - - int3 min = make_int3(leaf_bbox.min().x(), leaf_bbox.min().y(), leaf_bbox.min().z()); - int3 max = make_int3(leaf_bbox.max().x(), leaf_bbox.max().y(), leaf_bbox.max().z()); - - int3 corners[8] = { - make_int3(min[0], min[1], min[2]), - make_int3(max[0], min[1], min[2]), - make_int3(max[0], max[1], min[2]), - make_int3(min[0], max[1], min[2]), - make_int3(min[0], min[1], max[2]), - make_int3(max[0], min[1], max[2]), - make_int3(max[0], max[1], max[2]), - make_int3(min[0], max[1], max[2]), - }; - - /* Only create a quad if on the border between an active and an inactive leaf. - * - * We verify that a leaf exists by probing a coordinate that is at its center, - * to do so we compute the center of the current leaf and offset this coordinate - * by the size of a leaf in each direction. - */ - static const int LEAF_DIM = openvdb::MaskGrid::TreeType::LeafNodeType::DIM; - auto center = leaf_bbox.min() + openvdb::Coord(LEAF_DIM / 2); - - if (!tree.probeLeaf(openvdb::Coord(center.x() - LEAF_DIM, center.y(), center.z()))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MIN); - } - - if (!tree.probeLeaf(openvdb::Coord(center.x() + LEAF_DIM, center.y(), center.z()))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MAX); - } - - if (!tree.probeLeaf(openvdb::Coord(center.x(), center.y() - LEAF_DIM, center.z()))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MIN); - } - - if (!tree.probeLeaf(openvdb::Coord(center.x(), center.y() + LEAF_DIM, center.z()))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MAX); - } - - if (!tree.probeLeaf(openvdb::Coord(center.x(), center.y(), center.z() - LEAF_DIM))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MIN); - } + openvdb::CoordBBox bbox; + tree.evalLeafBoundingBox(bbox); + bbox.max() = bbox.max().offsetBy(1); + + int3 min = make_int3(bbox.min().x(), bbox.min().y(), bbox.min().z()); + int3 max = make_int3(bbox.max().x(), bbox.max().y(), bbox.max().z()); + + int3 corners[8] = { + make_int3(min[0], min[1], min[2]), + make_int3(max[0], min[1], min[2]), + make_int3(max[0], max[1], min[2]), + make_int3(min[0], max[1], min[2]), + make_int3(min[0], min[1], max[2]), + make_int3(max[0], min[1], max[2]), + make_int3(max[0], max[1], max[2]), + make_int3(min[0], max[1], max[2]), + }; + + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MIN); + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_X_MAX); + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MIN); + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Y_MAX); + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MIN); + create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MAX); - if (!tree.probeLeaf(openvdb::Coord(center.x(), center.y(), center.z() + LEAF_DIM))) { - create_quad(corners, vertices_is, quads, resolution, used_verts, QUAD_Z_MAX); - } - } #else (void)vertices_is; (void)quads;