Blender V5.0
node_geo_sdf_grid_offset.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::Float>("Distance")
22 .subtype(PROP_DISTANCE)
23 .default_value(0.1f)
24 .description("Object-space distance to offset the SDF surface");
25}
26
28{
29#ifdef WITH_OPENVDB
30 auto grid = params.extract_input<bke::VolumeGrid<float>>("Grid");
31 if (!grid) {
32 params.set_default_remaining_outputs();
33 return;
34 }
35
36 const float distance = params.extract_input<float>("Distance");
37
38 bke::VolumeTreeAccessToken tree_token;
39 openvdb::FloatGrid &vdb_grid = grid.grid_for_write(tree_token);
40
41 try {
42 openvdb::tools::LevelSetFilter<openvdb::FloatGrid> filter(vdb_grid);
43 filter.offset(-distance);
44 }
45 catch (const openvdb::RuntimeError & /*e*/) {
47 return;
48 }
49
50 params.set_output("Grid", std::move(grid));
51#else
53#endif
54}
55
56static void node_register()
57{
58 static blender::bke::bNodeType ntype;
59 geo_node_type_base(&ntype, "GeometryNodeSDFGridOffset");
60 ntype.ui_name = "SDF Grid Offset";
61 ntype.ui_description =
62 "Offset a signed distance field surface by a world-space distance. Dilates (positive) or "
63 "erodes (negative) while maintaining the signed distance property";
65 ntype.declare = node_declare;
68}
70
71} // namespace blender::nodes::node_geo_sdf_grid_offset_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_DISTANCE
Definition RNA_types.hh:256
#define filter
float distance(VecOp< float, D >, VecOp< float, D >) RET
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 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