19# include "openvdb/tools/Prune.h"
32 b.use_custom_socket_order();
33 b.allow_any_socket_order();
34 b.add_default_layout();
35 const bNode *node =
b.node_or_null();
40 b.add_input(data_type,
"Grid").hide_value().structure_type(StructureType::Grid);
41 b.add_output(data_type,
"Grid").structure_type(StructureType::Grid).align_with_previous();
47 N_(
"Turn inactive voxels and tiles into inactive background tiles")},
52 N_(
"Turn regions where all voxels have the same value and active state (within a tolerance "
53 "threshold) into inactive background tiles")},
58 N_(
"Replace inactive tiles with inactive nodes. Faster than tolerance-based pruning, "
59 "useful for cases like narrow-band SDF grids with only inside or outside background "
61 {0,
nullptr, 0,
nullptr,
nullptr},
64 .static_items(mode_items)
66 .structure_type(StructureType::Single)
69 auto &threshold =
b.add_input(data_type,
"Threshold")
70 .structure_type(StructureType::Single)
101 switch (socket.
type) {
124 bNode &node =
params.add_node(
"GeometryNodeGridPrune");
126 params.update_and_connect_available_socket(node,
"Grid");
133 bke::GVolumeGrid grid =
params.extract_input<bke::GVolumeGrid>(
"Grid");
135 params.set_default_remaining_outputs();
138 bke::VolumeTreeAccessToken tree_token;
139 openvdb::GridBase &grid_base = grid.get_for_write().grid_for_write(tree_token);
142 bke::volume_grid::prune_inactive(grid_base);
149 auto &grid =
static_cast<openvdb::BoolGrid &
>(grid_base);
150 openvdb::tools::prune(grid.tree());
154 auto &grid =
static_cast<openvdb::MaskGrid &
>(grid_base);
155 openvdb::tools::prune(grid.tree());
159 auto &grid =
static_cast<openvdb::FloatGrid &
>(grid_base);
160 const float threshold =
params.extract_input<
float>(
"Threshold");
161 openvdb::tools::prune(grid.tree(), threshold);
165 auto &grid =
static_cast<openvdb::Int32Grid &
>(grid_base);
166 const int threshold =
params.extract_input<
int>(
"Threshold");
167 openvdb::tools::prune(grid.tree(), threshold);
171 auto &grid =
static_cast<openvdb::Vec3fGrid &
>(grid_base);
173 openvdb::tools::prune(grid.tree(),
174 openvdb::Vec3s(threshold.x, threshold.y, threshold.z));
191 BKE_volume_grid_type_to_static_type(grid_type, [&](
auto type_tag) {
192 using GridT =
typename decltype(type_tag)::type;
193 if constexpr (bke::volume_grid::is_supported_grid_type<GridT>) {
194 if constexpr (std::is_scalar_v<typename GridT::ValueType>) {
195 GridT &grid =
static_cast<GridT &
>(grid_base);
196 openvdb::tools::pruneLevelSet(grid.tree());
206 params.set_output(
"Grid", std::move(grid));
222 "Node socket data type",
235 "Make the storage of a volume grid more efficient by collapsing data into tiles or inner "
#define NODE_CLASS_GEOMETRY
@ VOLUME_GRID_VECTOR_FLOAT
@ VOLUME_GRID_VECTOR_DOUBLE
#define BLI_assert_unreachable()
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
FloatBuilder & default_value(float value)
FloatBuilder & min(float value)
IntBuilder & default_value(int value)
IntBuilder & min(int value)
VectorBuilder & default_value(const float2 value)
VectorBuilder & min(float min)
VolumeGridType get_type(const VolumeGridData &grid)
void node_register_type(bNodeType &ntype)
static std::optional< eNodeSocketDatatype > node_type_for_socket_type(const bNodeSocket &socket)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_declare(NodeDeclarationBuilder &b)
static void node_gather_link_search_ops(GatherLinkSearchOpParams ¶ms)
static void node_rna(StructRNA *srna)
static void node_register()
static void node_geo_exec(GeoNodeExecParams params)
static void node_init(bNodeTree *, bNode *node)
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)
const EnumPropertyItem * grid_socket_type_items_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams ¶ms)
VecBase< float, 3 > float3
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
std::string ui_description
void(* initfunc)(bNodeTree *ntree, bNode *node)
NodeGeometryExecFunction geometry_node_execute
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)