Fix #147465: Distribute Points in Volume node has inaccurate offset

Account for recent changes in how volumes are offset from
blender/blender@12f0bc7736

Pull Request: https://projects.blender.org/blender/blender/pulls/147495
This commit is contained in:
Jesse Yurkovich
2025-10-07 20:38:23 +02:00
committed by Jesse Yurkovich
parent 8a99ab4463
commit 60325c7a9c
3 changed files with 10 additions and 26 deletions

View File

@@ -82,19 +82,15 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
/* Implements the interface required by #openvdb::tools::NonUniformPointScatter. */
class PositionsVDBWrapper {
private:
float3 offset_fix_;
Vector<float3> &vector_;
public:
PositionsVDBWrapper(Vector<float3> &vector, const float3 &offset_fix)
: offset_fix_(offset_fix), vector_(vector)
{
}
PositionsVDBWrapper(Vector<float3> &vector) : vector_(vector) {}
PositionsVDBWrapper(const PositionsVDBWrapper &wrapper) = default;
void add(const openvdb::Vec3R &pos)
{
vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])) + offset_fix_);
vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])));
}
};
@@ -110,12 +106,8 @@ static void point_scatter_density_random(const openvdb::FloatGrid &grid,
const int seed,
Vector<float3> &r_positions)
{
/* Offset points by half a voxel so that grid points are aligned with world grid points. */
const float3 offset_fix = {0.5f * float(grid.voxelSize().x()),
0.5f * float(grid.voxelSize().y()),
0.5f * float(grid.voxelSize().z())};
/* Setup and call into OpenVDB's point scatter API. */
PositionsVDBWrapper vdb_position_wrapper(r_positions, offset_fix);
PositionsVDBWrapper vdb_position_wrapper(r_positions);
RNGType random_generator(seed);
NonUniformPointScatterVDB point_scatter(vdb_position_wrapper, density, random_generator);
point_scatter(grid);
@@ -162,7 +154,7 @@ static void point_scatter_density_grid(const openvdb::FloatGrid &grid,
for (double z = start.z(); z < box_max.z(); z += abs_spacing_z) {
/* Transform with grid matrix and add point. */
const openvdb::Vec3d idx_pos(x, y, z);
const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos + half_voxel);
const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos);
r_positions.append({float(local_pos.x()), float(local_pos.y()), float(local_pos.z())});
}
}

View File

@@ -87,19 +87,15 @@ static void node_init(bNodeTree * /*tree*/, bNode *node)
/* Implements the interface required by #openvdb::tools::NonUniformPointScatter. */
class PositionsVDBWrapper {
private:
float3 offset_fix_;
Vector<float3> &vector_;
public:
PositionsVDBWrapper(Vector<float3> &vector, const float3 offset_fix)
: offset_fix_(offset_fix), vector_(vector)
{
}
PositionsVDBWrapper(Vector<float3> &vector) : vector_(vector) {}
PositionsVDBWrapper(const PositionsVDBWrapper &wrapper) = default;
void add(const openvdb::Vec3R &pos)
{
vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])) + offset_fix_);
vector_.append(float3(float(pos[0]), float(pos[1]), float(pos[2])));
}
};
@@ -116,12 +112,8 @@ static void point_scatter_density_random(const openvdb::FloatGrid &grid,
const int seed,
Vector<float3> &r_positions)
{
/* Offset points by half a voxel so that grid points are aligned with world grid points. */
const float3 offset_fix = {0.5f * float(grid.voxelSize().x()),
0.5f * float(grid.voxelSize().y()),
0.5f * float(grid.voxelSize().z())};
/* Setup and call into OpenVDB's point scatter API. */
PositionsVDBWrapper vdb_position_wrapper = PositionsVDBWrapper(r_positions, offset_fix);
PositionsVDBWrapper vdb_position_wrapper = PositionsVDBWrapper(r_positions);
RNGType random_generator(seed);
NonUniformPointScatterVDB point_scatter(vdb_position_wrapper, density, random_generator);
point_scatter(grid);
@@ -168,7 +160,7 @@ static void point_scatter_density_grid(const openvdb::FloatGrid &grid,
for (double z = start.z(); z < box_max.z(); z += abs_spacing_z) {
/* Transform with grid matrix and add point. */
const openvdb::Vec3d idx_pos(x, y, z);
const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos + half_voxel);
const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos);
r_positions.append({float(local_pos.x()), float(local_pos.y()), float(local_pos.z())});
}
}

Binary file not shown.