Blender V5.3
node_geo_grid_gradient.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/GridOperators.h"
11#endif
12
14
16{
17 b.add_input<decl::Float>("Grid"_ustr).hide_value().structure_type(StructureType::Grid);
18 b.add_output<decl::Vector>("Gradient"_ustr).structure_type(StructureType::Grid);
19}
20
22{
23#ifdef WITH_OPENVDB
24 const bke::VolumeGrid<float> grid = params.extract_input<bke::VolumeGrid<float>>("Grid"_ustr);
25 if (!grid) {
27 return;
28 }
29 bke::VolumeTreeAccessToken tree_token;
30 const openvdb::FloatGrid &vdb_grid = grid.grid(tree_token);
31 openvdb::Vec3SGrid::Ptr gradient_vdb_grid = openvdb::tools::gradient(vdb_grid);
32 params.set_output("Gradient"_ustr, bke::VolumeGrid<float3>(std::move(gradient_vdb_grid)));
33#else
35#endif
36}
37
38static void node_register()
39{
40 static bke::bNodeType ntype;
41 geo_node_type_base(&ntype, "GeometryNodeGridGradient"_ustr);
42 ntype.ui_name = "Grid Gradient";
43 ntype.ui_description =
44 "Calculate the direction and magnitude of the change in values of a scalar grid";
46 ntype.declare = node_declare;
49}
51
52} // namespace blender::nodes::node_geo_grid_gradient_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)
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_exec_with_missing_openvdb(GeoNodeExecParams &params)
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