Blender V4.3
node_geo_store_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_lib_id.hh"
8#include "BKE_volume.hh"
9#include "BKE_volume_grid.hh"
10
11#include "RNA_enum_types.hh"
12
13#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_output<decl::Geometry>("Volume");
26
27 const bNode *node = b.node_or_null();
28 if (!node) {
29 return;
30 }
31
32 b.add_input(eCustomDataType(node->custom1), "Grid").hide_value();
33}
34
36{
37 if (!U.experimental.use_new_volume_nodes) {
38 return;
39 }
40 if (params.other_socket().type == SOCK_GEOMETRY) {
41 params.add_item(IFACE_("Volume"), [](LinkSearchOpParams &params) {
42 bNode &node = params.add_node("GeometryNodeStoreNamedGrid");
43 params.update_and_connect_available_socket(node, "Volume");
44 });
45 }
46 if (params.in_out() == SOCK_IN) {
47 if (params.other_socket().type == SOCK_STRING) {
48 params.add_item(IFACE_("Name"), [](LinkSearchOpParams &params) {
49 bNode &node = params.add_node("GeometryNodeStoreNamedGrid");
50 params.update_and_connect_available_socket(node, "Name");
51 });
52 }
53 if (const std::optional<eCustomDataType> data_type = bke::socket_type_to_custom_data_type(
54 eNodeSocketDatatype(params.other_socket().type)))
55 {
56 if (custom_data_type_supports_grids(*data_type)) {
57 params.add_item(IFACE_("Grid"), [data_type](LinkSearchOpParams &params) {
58 bNode &node = params.add_node("GeometryNodeStoreNamedGrid");
59 node.custom1 = *data_type;
60 params.update_and_connect_available_socket(node, "Grid");
61 });
62 }
63 }
64 }
65}
66
67static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
68{
69 uiLayoutSetPropSep(layout, true);
70 uiLayoutSetPropDecorate(layout, false);
71 uiItemR(layout, ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
72}
73
74static void node_init(bNodeTree * /*tree*/, bNode *node)
75{
76 node->custom1 = CD_PROP_FLOAT;
77}
78
79#ifdef WITH_OPENVDB
80
81static void try_store_grid(GeoNodeExecParams params, Volume &volume)
82{
83 const std::string grid_name = params.extract_input<std::string>("Name");
84
85 bke::GVolumeGrid grid = params.extract_input<bke::GVolumeGrid>("Grid");
86 if (!grid) {
87 return;
88 }
89
90 if (const bke::VolumeGridData *existing_grid = BKE_volume_grid_find(&volume, grid_name.data())) {
91 BKE_volume_grid_remove(&volume, existing_grid);
92 }
93 grid.get_for_write().set_name(grid_name);
94 grid->add_user();
95 BKE_volume_grid_add(&volume, grid.get());
96}
97
98static void node_geo_exec(GeoNodeExecParams params)
99{
100 GeometrySet geometry_set = params.extract_input<GeometrySet>("Volume");
101 Volume *volume = geometry_set.get_volume_for_write();
102 if (!volume) {
103 volume = static_cast<Volume *>(BKE_id_new_nomain(ID_VO, "Store Named Grid Output"));
104 geometry_set.replace_volume(volume);
105 }
106
107 try_store_grid(params, *volume);
108
109 params.set_output("Volume", geometry_set);
110}
111
112#else /* WITH_OPENVDB */
113
118
119#endif /* WITH_OPENVDB */
120
121static void node_rna(StructRNA *srna)
122{
124 "data_type",
125 "Data Type",
126 "Type of grid data",
131}
132
133static void node_register()
134{
135 static blender::bke::bNodeType ntype;
136
137 geo_node_type_base(&ntype, GEO_NODE_STORE_NAMED_GRID, "Store Named Grid", NODE_CLASS_GEOMETRY);
138
139 ntype.declare = node_declare;
142 ntype.initfunc = node_init;
145
146 node_rna(ntype.rna_ext.srna);
147}
149
150} // namespace blender::nodes::node_geo_store_named_grid_cc
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1487
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:418
Volume data-block.
void BKE_volume_grid_add(Volume *volume, const blender::bke::VolumeGridData &grid)
void BKE_volume_grid_remove(Volume *volume, const blender::bke::VolumeGridData *grid)
const blender::bke::VolumeGridData * BKE_volume_grid_find(const Volume *volume, const char *name)
#define IFACE_(msgid)
@ ID_VO
@ CD_PROP_FLOAT
@ SOCK_IN
eNodeSocketDatatype
@ SOCK_GEOMETRY
@ SOCK_STRING
#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)
void uiItemR(uiLayout *layout, PointerRNA *ptr, const char *propname, eUI_Item_Flag flag, const char *name, int icon)
unsigned int U
Definition btGjkEpa3.h:78
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
std::optional< eCustomDataType > socket_type_to_custom_data_type(eNodeSocketDatatype type)
Definition node.cc:4379
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void search_link_ops(GatherLinkSearchOpParams &params)
static void node_init(bNodeTree *, bNode *node)
bool custom_data_type_supports_grids(const eCustomDataType data_type)
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_custom_data_type_items_filter_fn(bContext *, PointerRNA *, PropertyRNA *, bool *r_free)
void node_geo_exec_with_missing_openvdb(GeoNodeExecParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
const EnumPropertyItem rna_enum_attribute_type_items[]
StructRNA * srna
Definition RNA_types.hh:780
Defines a node type.
Definition BKE_node.hh:218
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:267
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:238
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347
PointerRNA * ptr
Definition wm_files.cc:4126