Blender V5.0
node_geo_grid_voxelize.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"
7
8#include "NOD_rna_define.hh"
10
11#include "RNA_enum_types.hh"
12
14#include "UI_resources.hh"
15
16#include "node_geometry_util.hh"
17
19
21{
22 b.use_custom_socket_order();
23 b.allow_any_socket_order();
24 b.add_default_layout();
25 const bNode *node = b.node_or_null();
26 if (!node) {
27 return;
28 }
29 const eNodeSocketDatatype data_type = eNodeSocketDatatype(node->custom1);
30 b.add_input(data_type, "Grid").hide_value().structure_type(StructureType::Grid);
31 b.add_output(data_type, "Grid").structure_type(StructureType::Grid).align_with_previous();
32}
33
34static void node_layout(uiLayout *layout, bContext * /*C*/, PointerRNA *ptr)
35{
36 layout->prop(ptr, "data_type", UI_ITEM_NONE, "", ICON_NONE);
37}
38
39static std::optional<eNodeSocketDatatype> node_type_for_socket_type(const bNodeSocket &socket)
40{
41 switch (socket.type) {
42 case SOCK_FLOAT:
43 return SOCK_FLOAT;
44 case SOCK_BOOLEAN:
45 return SOCK_BOOLEAN;
46 case SOCK_INT:
47 return SOCK_INT;
48 case SOCK_VECTOR:
49 case SOCK_RGBA:
50 return SOCK_VECTOR;
51 default:
52 return std::nullopt;
53 }
54}
55
57{
58 const std::optional<eNodeSocketDatatype> data_type = node_type_for_socket_type(
59 params.other_socket());
60 if (!data_type) {
61 return;
62 }
63 params.add_item(IFACE_("Grid"), [data_type](LinkSearchOpParams &params) {
64 bNode &node = params.add_node("GeometryNodeGridVoxelize");
65 node.custom1 = *data_type;
66 params.update_and_connect_available_socket(node, "Grid");
67 });
68}
69
71{
72#ifdef WITH_OPENVDB
73 bke::GVolumeGrid grid = params.extract_input<bke::GVolumeGrid>("Grid");
74 if (!grid) {
75 params.set_default_remaining_outputs();
76 return;
77 }
78 bke::VolumeTreeAccessToken tree_token;
79 openvdb::GridBase &vdb_grid = grid.get_for_write().grid_for_write(tree_token);
80 bke::volume_grid::to_typed_grid(vdb_grid,
81 [&](auto &grid) { grid.tree().voxelizeActiveTiles(); });
82 params.set_output("Grid", std::move(grid));
83#else
85#endif
86}
87
88static void node_init(bNodeTree * /*tree*/, bNode *node)
89{
90 node->custom1 = SOCK_FLOAT;
91}
92
93static void node_rna(StructRNA *srna)
94{
96 "data_type",
97 "Data Type",
98 "Node socket data type",
103}
104
105static void node_register()
106{
107 static blender::bke::bNodeType ntype;
108 geo_node_type_base(&ntype, "GeometryNodeGridVoxelize");
109 ntype.ui_name = "Voxelize Grid";
110 ntype.ui_description =
111 "Remove sparseness from a volume grid by making the active tiles into voxels";
113 ntype.declare = node_declare;
115 ntype.initfunc = node_init;
119 node_rna(ntype.rna_ext.srna);
120}
122
123} // namespace blender::nodes::node_geo_grid_voxelize_cc
#define NODE_CLASS_GEOMETRY
Definition BKE_node.hh:461
#define IFACE_(msgid)
eNodeSocketDatatype
@ SOCK_INT
@ SOCK_VECTOR
@ SOCK_BOOLEAN
@ SOCK_FLOAT
@ SOCK_RGBA
#define NOD_REGISTER_NODE(REGISTER_FUNC)
#define NOD_inline_enum_accessors(member)
#define UI_ITEM_NONE
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_gather_link_search_ops(GatherLinkSearchOpParams &params)
static void node_layout(uiLayout *layout, bContext *, PointerRNA *ptr)
static void node_init(bNodeTree *, bNode *node)
static void node_geo_exec(GeoNodeExecParams params)
static std::optional< eNodeSocketDatatype > node_type_for_socket_type(const bNodeSocket &socket)
static void node_declare(NodeDeclarationBuilder &b)
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 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
int16_t custom1
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
void(* initfunc)(bNodeTree *ntree, bNode *node)
Definition BKE_node.hh:289
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
void(* draw_buttons)(uiLayout *, bContext *C, PointerRNA *ptr)
Definition BKE_node.hh:259
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:378
NodeDeclareFunction declare
Definition BKE_node.hh:362
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:4238