Blender V5.3
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"_ustr).hide_value().structure_type(StructureType::Grid);
20 b.add_output<decl::Float>("Grid"_ustr).structure_type(StructureType::Grid).align_with_previous();
21 b.add_input<decl::Float>("Distance"_ustr)
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"_ustr);
31 if (!grid) {
33 return;
34 }
35
36 const float distance = params.extract_input<float>("Distance"_ustr);
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"_ustr, std::move(grid));
51#else
53#endif
54}
55
56static void node_register()
57{
58 static bke::bNodeType ntype;
59 geo_node_type_base(&ntype, "GeometryNodeSDFGridOffset"_ustr);
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:492
#define NOD_REGISTER_NODE(REGISTER_FUNC)
T extract_input(const UString identifier)
void set_output(const UString identifier, T &&value)
float distance(float, float) RET
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
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)
@ PROP_DISTANCE
Definition RNA_types.hh:313
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393