Blender V5.0
node_geo_sdf_grid_fillet.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2025 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_volume_grid.hh"
6
8
9#ifdef WITH_OPENVDB
10# include "openvdb/tools/LevelSetFilter.h"
11#endif
12
14
16{
17 b.use_custom_socket_order();
18 b.allow_any_socket_order();
19 b.add_input<decl::Float>("Grid").hide_value().structure_type(StructureType::Grid);
20 b.add_output<decl::Float>("Grid").structure_type(StructureType::Grid).align_with_previous();
21 b.add_input<decl::Int>("Iterations")
22 .default_value(1)
23 .min(0)
24 .description("Number of iterations to apply the filter");
25}
26
28{
29 /* The fillet method was only introduced in OpenVDB 12. Since we don't presently require 12,
30 disable this node when building against older versions. */
31#ifdef WITH_OPENVDB
32# if OPENVDB_ABI_VERSION_NUMBER >= 12
33 auto grid = params.extract_input<bke::VolumeGrid<float>>("Grid");
34 if (!grid) {
35 params.set_default_remaining_outputs();
36 return;
37 }
38
39 const int iterations = params.extract_input<int>("Iterations");
40 if (iterations <= 0) {
41 params.set_output("Grid", std::move(grid));
42 return;
43 }
44
45 bke::VolumeTreeAccessToken tree_token;
46 openvdb::FloatGrid &vdb_grid = grid.grid_for_write(tree_token);
47
48 try {
49 openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(vdb_grid);
50 for (int i = 0; i < iterations; i++) {
51 filter.fillet();
52 }
53 }
54 catch (const openvdb::RuntimeError & /*e*/) {
56 return;
57 }
58
59 params.set_output("Grid", std::move(grid));
60# else
62# endif
63#else
65#endif
66}
67
68static void node_register()
69{
70 static blender::bke::bNodeType ntype;
71 geo_node_type_base(&ntype, "GeometryNodeSDFGridFillet");
72 ntype.ui_name = "SDF Grid Fillet";
73 ntype.ui_description =
74 "Round off concave internal corners in a signed distance field. Only affects areas with "
75 "negative principal curvature, creating smoother transitions between surfaces";
77 ntype.declare = node_declare;
80}
82
83} // namespace blender::nodes::node_geo_sdf_grid_fillet_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define filter
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
void node_geo_sdf_grid_error_not_levelset(GeoNodeExecParams &params)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams &params)
void node_geo_exec_with_too_old_openvdb(GeoNodeExecParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
NodeDeclareFunction declare
Definition BKE_node.hh:362
i
Definition text_draw.cc:230