Blender V5.3
node_geo_get_grid_names.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#include "BKE_volume.hh"
6#include "BKE_volume_grid.hh"
7
9
10#include "node_geometry_util.hh"
11
13
15{
16 b.add_input<decl::Geometry>("Volume"_ustr).description("Volume to list the grid names of");
17 b.add_output<decl::String>("Names"_ustr)
18 .structure_type(StructureType::List)
19 .description("Names of all grids stored in the volume");
20}
21
23{
24#ifdef WITH_OPENVDB
25 const GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume"_ustr);
27 if (const Volume *volume = geometry_set.get_volume()) {
28 const int grids_num = BKE_volume_num_grids(volume);
29 names.reserve(grids_num);
30 for (const int i : IndexRange(grids_num)) {
31 if (const bke::VolumeGridData *grid = BKE_volume_grid_get(volume, i)) {
32 names.append(grid->name());
33 }
34 }
35 std::ranges::sort(names);
36 }
37 params.set_output("Names"_ustr, GList::from_container(std::move(names)));
38#else
40#endif
41}
42
43static void node_register()
44{
45 static bke::bNodeType ntype;
46
47 geo_node_type_base(&ntype, "GeometryNodeGetGridNames"_ustr);
48 ntype.ui_name = "Get Grid Names";
49 ntype.ui_description =
50 "Retrieves the names of all grids stored in a volume as a list of strings";
52 ntype.declare = node_declare;
55}
57
58} // namespace blender::nodes::node_geo_get_grid_names_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:492
Volume data-block.
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr IndexRange()=default
static GListPtr from_container(ContainerT &&container)
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)
int BKE_volume_num_grids(const Volume *volume)
const bke::VolumeGridData * BKE_volume_grid_get(const Volume *volume, int grid_index)
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
const Volume * get_volume() const
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