Blender V4.5
node_geo_grid_info.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 "BLI_math_matrix.hh"
8
10#include "BKE_volume_grid.hh"
11#include "BKE_volume_openvdb.hh"
12
13#include "NOD_rna_define.hh"
14#include "NOD_socket.hh"
15
16#include "UI_interface.hh"
17#include "UI_resources.hh"
18
19#include "RNA_enum_types.hh"
20
22
24{
25 const bNode *node = b.node_or_null();
26 if (!node) {
27 return;
28 }
29
30 const eNodeSocketDatatype data_type = eNodeSocketDatatype(node->custom1);
31
32 b.add_input(data_type, "Grid").hide_value();
33
34 b.add_output<decl::Matrix>("Transform")
35 .description("Transform from grid index space to object space");
36 b.add_output(data_type, "Background Value").description("Default value outside of grid voxels");
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
47{
48#ifdef WITH_OPENVDB
49 const eNodeSocketDatatype data_type = eNodeSocketDatatype(params.node().custom1);
50
51 const auto grid = params.extract_input<bke::GVolumeGrid>("Grid");
52 if (!grid) {
53 params.set_default_remaining_outputs();
54 return;
55 }
56
57 bke::VolumeTreeAccessToken tree_token;
58 const std::shared_ptr<const openvdb::GridBase> vdb_grid = grid->grid_ptr(tree_token);
59 params.set_output("Transform", BKE_volume_transform_to_blender(vdb_grid->transform()));
60
62 *bke::socket_type_to_geo_nodes_base_cpp_type(data_type), [&](auto type_tag) {
63 using ValueT = decltype(type_tag);
64 using type_traits = typename bke::VolumeGridTraits<ValueT>;
65 using TreeType = typename type_traits::TreeType;
66 using GridType = openvdb::Grid<TreeType>;
67
68 if constexpr (!std::is_same_v<typename type_traits::BlenderType, void>) {
69 const std::shared_ptr<const GridType> vdb_typed_grid = openvdb::GridBase::grid<GridType>(
70 vdb_grid);
71 params.set_output("Background Value",
72 type_traits::to_blender(vdb_typed_grid->background()));
73 }
74 });
75#else
76 params.set_default_remaining_outputs();
77 params.error_message_add(NodeWarningType::Error,
78 TIP_("Disabled, Blender was compiled without OpenVDB"));
79#endif
80}
81
82static void node_init(bNodeTree * /*tree*/, bNode *node)
83{
84 node->custom1 = SOCK_FLOAT;
85}
86
87static void node_rna(StructRNA *srna)
88{
90 "data_type",
91 "Data Type",
92 "Type of grid data",
97}
98
99static void node_register()
100{
101 static blender::bke::bNodeType ntype;
102
103 geo_node_type_base(&ntype, "GeometryNodeGridInfo");
104 ntype.ui_name = "Grid Info";
105 ntype.ui_description = "Retrieve information about a volume grid";
106 ntype.nclass = NODE_CLASS_INPUT;
107 ntype.initfunc = node_init;
110 ntype.declare = node_declare;
112
113 node_rna(ntype.rna_ext.srna);
114}
116
117} // namespace blender::nodes::node_geo_grid_info_cc
#define NODE_CLASS_INPUT
Definition BKE_node.hh:433
#define TIP_(msgid)
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)
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void convert_to_static_type(const CPPType &cpp_type, const Func &func)
void node_register_type(bNodeType &ntype)
Definition node.cc:2748
const CPPType * socket_type_to_geo_nodes_base_cpp_type(eNodeSocketDatatype type)
Definition node.cc:5413
static void node_geo_exec(GeoNodeExecParams params)
static void node_declare(NodeDeclarationBuilder &b)
static void node_init(bNodeTree *, bNode *node)
static void node_rna(StructRNA *srna)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
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 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
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:247
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:4226