Blender V4.5
node_geo_get_named_grid.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include "BKE_volume.hh"
8#include "BKE_volume_grid.hh"
9
10#include "BLT_translation.hh"
11
12#include "RNA_enum_types.hh"
13
14#include "NOD_rna_define.hh"
15
16#include "UI_interface.hh"
17#include "UI_resources.hh"
18
20
22{
23 b.add_input<decl::Geometry>("Volume");
24 b.add_input<decl::String>("Name").hide_label();
25 b.add_input<decl::Bool>("Remove").default_value(true).translation_context(
27
28 b.add_output<decl::Geometry>("Volume");
29
30 const bNode *node = b.node_or_null();
31 if (!node) {
32
33 return;
34 }
35
36 b.add_output(eNodeSocketDatatype(node->custom1), "Grid").structure_type(StructureType::Grid);
37}
38
39static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
40{
41 uiLayoutSetPropSep(layout, true);
42 uiLayoutSetPropDecorate(layout, false);
43 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
44}
45
46static void node_init(bNodeTree * /*tree*/, bNode *node)
47{
48 node->custom1 = SOCK_FLOAT;
49}
50
52{
53#ifdef WITH_OPENVDB
54 const bNode &node = params.node();
55 GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume");
56 const std::string grid_name = params.extract_input<std::string>("Name");
57 const bool remove_grid = params.extract_input<bool>("Remove");
60
61 if (Volume *volume = geometry_set.get_volume_for_write()) {
62 if (const bke::VolumeGridData *grid = BKE_volume_grid_find(volume, grid_name)) {
63 /* Increment user count before removing from volume. */
64 grid->add_user();
65 if (remove_grid) {
66 BKE_volume_grid_remove(volume, grid);
67 }
68
69 params.set_output("Grid", bke::GVolumeGrid(grid));
70 params.set_output("Volume", geometry_set);
71 return;
72 }
73 }
74
75 params.set_output("Grid", bke::GVolumeGrid(grid_type));
76 params.set_output("Volume", geometry_set);
77#else
79#endif
80}
81
82static void node_rna(StructRNA *srna)
83{
85 "data_type",
86 "Data Type",
87 "Type of grid data",
92}
93
94static void node_register()
95{
96 static blender::bke::bNodeType ntype;
97
98 geo_node_type_base(&ntype, "GeometryNodeGetNamedGrid", GEO_NODE_GET_NAMED_GRID);
99 ntype.ui_name = "Get Named Grid";
100 ntype.ui_description = "Get volume grid from a volume geometry with the specified name";
101 ntype.enum_name_legacy = "GET_NAMED_GRID";
103 ntype.declare = node_declare;
106 ntype.initfunc = node_init;
109
110 node_rna(ntype.rna_ext.srna);
111}
113
114} // namespace blender::nodes::node_geo_get_named_grid_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:447
#define GEO_NODE_GET_NAMED_GRID
Volume data-block.
const blender::bke::VolumeGridData * BKE_volume_grid_find(const Volume *volume, blender::StringRef name)
void BKE_volume_grid_remove(Volume *volume, const blender::bke::VolumeGridData *grid)
VolumeGridType
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
eNodeSocketDatatype
@ SOCK_FLOAT
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
void uiLayoutSetPropSep(uiLayout *layout, bool is_sep)
#define UI_ITEM_NONE
void uiLayoutSetPropDecorate(uiLayout *layout, bool is_sep)
std::optional< std::string > translation_context
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
std::optional< VolumeGridType > socket_type_to_grid_type(eNodeSocketDatatype type)
Definition node.cc:5487
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_init(bNodeTree *, bNode *node)
PropertyRNA * RNA_def_node_enum(StructRNA *srna, const char *identifier, const char *ui_name, const char *ui_description, const EnumPropertyItem *static_items, const EnumRNAAccessors accessors, std::optional< int > default_value, const EnumPropertyItemFunc item_func, const bool allow_animation)
const EnumPropertyItem * grid_socket_type_items_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void search_link_ops_for_volume_grid_node(GatherLinkSearchOpParams &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)
const EnumPropertyItem rna_enum_node_socket_data_type_items[]
StructRNA * srna
Definition RNA_types.hh:909
int16_t custom1
Defines a node type.
Definition BKE_node.hh:226
std::string ui_description
Definition BKE_node.hh:232
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:277
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:347
const char * enum_name_legacy
Definition BKE_node.hh:235
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:371
NodeDeclareFunction declare
Definition BKE_node.hh:355
void prop(PointerRNA *ptr, PropertyRNA *prop, int index, int value, eUI_Item_Flag flag, std::optional< blender::StringRef > name_opt, int icon, std::optional< blender::StringRef > placeholder=std::nullopt)
PointerRNA * ptr
Definition wm_files.cc:4227