43 "When combined with each voxel's value, determines the number of points "
44 "to sample per unit volume");
46 "Seed used by the random number generator to generate random points");
48 .default_value({0.3, 0.3, 0.3})
51 .description(
"Spacing between grid points");
56 .
description(
"Minimum density of a voxel to contain a grid point");
59 const bNode *node =
b.node_or_null();
60 if (node !=
nullptr) {
82class PositionsVDBWrapper {
89 : offset_fix_(offset_fix), vector_(
vector)
92 PositionsVDBWrapper(
const PositionsVDBWrapper &wrapper) =
default;
94 void add(
const openvdb::Vec3R &
pos)
102using RNGType = std::mt19937;
104using NonUniformPointScatterVDB =
105 openvdb::tools::NonUniformPointScatter<PositionsVDBWrapper, RNGType>;
107static void point_scatter_density_random(
const openvdb::FloatGrid &grid,
110 Vector<float3> &r_positions)
113 const float3 offset_fix = {0.5f *
float(grid.voxelSize().x()),
114 0.5f *
float(grid.voxelSize().y()),
115 0.5f *
float(grid.voxelSize().z())};
117 PositionsVDBWrapper vdb_position_wrapper(r_positions, offset_fix);
118 RNGType random_generator(
seed);
119 NonUniformPointScatterVDB point_scatter(vdb_position_wrapper, density, random_generator);
123static void point_scatter_density_grid(
const openvdb::FloatGrid &grid,
125 const float threshold,
126 Vector<float3> &r_positions)
128 const openvdb::Vec3d half_voxel(0.5, 0.5, 0.5);
129 const openvdb::Vec3d voxel_spacing(
double(spacing.
x) / grid.voxelSize().x(),
130 double(spacing.
y) / grid.voxelSize().y(),
131 double(spacing.
z) / grid.voxelSize().z());
134 const double min_spacing = std::min(voxel_spacing.x(),
135 std::min(voxel_spacing.y(), voxel_spacing.z()));
136 if (std::abs(min_spacing) < 0.0001) {
141 for (openvdb::FloatGrid::ValueOnCIter cell = grid.cbeginValueOn(); cell; ++cell) {
143 if (cell.getValue() < threshold) {
147 const openvdb::CoordBBox bbox = cell.getBoundingBox();
148 const openvdb::Vec3d box_min = bbox.min().asVec3d() - half_voxel;
149 const openvdb::Vec3d box_max = bbox.max().asVec3d() + half_voxel;
152 double abs_spacing_x = std::abs(voxel_spacing.x());
153 double abs_spacing_y = std::abs(voxel_spacing.y());
154 double abs_spacing_z = std::abs(voxel_spacing.z());
155 const openvdb::Vec3d start(
ceil(box_min.x() / abs_spacing_x) * abs_spacing_x,
156 ceil(box_min.y() / abs_spacing_y) * abs_spacing_y,
157 ceil(box_min.z() / abs_spacing_z) * abs_spacing_z);
160 for (
double x = start.x(); x < box_max.x(); x += abs_spacing_x) {
161 for (
double y = start.y(); y < box_max.y(); y += abs_spacing_y) {
162 for (
double z = start.z();
z < box_max.z();
z += abs_spacing_z) {
164 const openvdb::Vec3d idx_pos(x, y,
z);
165 const openvdb::Vec3d local_pos = grid.indexToWorld(idx_pos + half_voxel);
166 r_positions.append({
float(local_pos.x()),
float(local_pos.y()),
float(local_pos.z())});
180 params.set_default_remaining_outputs();
184 bke::VolumeTreeAccessToken tree_token;
185 const openvdb::GridBase &base_grid = volume_grid.grid(tree_token);
186 if (!base_grid.isType<openvdb::FloatGrid>()) {
187 params.set_default_remaining_outputs();
190 const openvdb::FloatGrid &grid =
static_cast<const openvdb::FloatGrid &
>(base_grid);
199 density =
params.extract_input<
float>(
"Density");
204 threshold =
params.extract_input<
float>(
"Threshold");
210 point_scatter_density_random(grid, density,
seed, positions);
213 point_scatter_density_grid(grid, spacing, threshold, positions);
218 pointcloud->positions_for_write().copy_from(positions);
235 "Distribute points randomly inside of the volume"},
240 "Distribute the points in a grid pattern inside of the volume"},
241 {0,
nullptr, 0,
nullptr,
nullptr},
246 "Distribution Method",
247 "Method to use for scattering points",
257 GEO_NODE_DISTRIBUTE_POINTS_IN_GRID,
258 "Distribute Points in Grid",
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
static unsigned long seed
draw_view push_constant(Type::INT, "radiance_src") .push_constant(Type capture_info_buf storage_buf(1, Qualifier::READ, "ObjectBounds", "bounds_buf[]") .push_constant(Type draw_view int
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)