19# include "openvdb/tools/Prune.h"
32 b.use_custom_socket_order();
33 b.allow_any_socket_order();
34 b.add_default_layout();
40 b.add_input(data_type,
"Grid"_ustr).hide_value().structure_type(StructureType::Grid);
41 b.add_output(data_type,
"Grid"_ustr).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"_ustr)
70 .structure_type(StructureType::Single)
101 switch (socket.
type) {
124 bNode &
node = params.add_node(
"GeometryNodeGridPrune"_ustr);
125 node.custom1 = *data_type;
126 params.update_and_connect_available_socket(
node,
"Grid"_ustr);
133 bke::GVolumeGrid grid = params.
extract_input<bke::GVolumeGrid>(
"Grid"_ustr);
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"_ustr);
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"_ustr);
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(
192 grid_type, [&]<std::derived_from<openvdb::GridBase> GridT>() {
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"_ustr, 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
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define BLI_assert_unreachable()
void add_item(std::string socket_name, SocketLinkOperation::LinkSocketFn fn, int weight=0)
const bNodeSocket & other_socket() const
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
void set_default_remaining_outputs()
void set_output(const UString identifier, T &&value)
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_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)
static void node_layout(ui::Layout &layout, bContext *, PointerRNA *ptr)
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)
@ VOLUME_GRID_VECTOR_FLOAT
@ VOLUME_GRID_VECTOR_DOUBLE
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
VecBase< float, 3 > float3
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
void(*) draw_buttons(ui::Layout &, bContext *C, PointerRNA *ptr)
std::string ui_description
NodeGeometryExecFunction geometry_node_execute
void(*) initfunc(bNodeTree *ntree, bNode *node)
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
NodeDeclareFunction declare
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< StringRef > name_opt, int icon, std::optional< StringRef > placeholder=std::nullopt)