Blender V5.0
node_geo_import_vdb.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_lib_id.hh"
6#include "BKE_volume.hh"
9
10#include "DNA_volume_types.h"
11
12#include "node_geometry_util.hh"
13
15
17{
18 b.add_input<decl::String>("Path")
19 .subtype(PROP_FILEPATH)
20 .path_filter("*.vdb")
21 .optional_label()
22 .description("Path to a OpenVDB file");
23
24 b.add_output<decl::Geometry>("Volume");
25}
26
28{
29#ifdef WITH_OPENVDB
30 const std::optional<std::string> path = params.ensure_absolute_path(
31 params.extract_input<std::string>("Path"));
32 if (!path) {
33 params.set_default_remaining_outputs();
34 return;
35 }
36
37 bke::volume_grid::file_cache::GridsFromFile grids_from_file =
38 bke::volume_grid::file_cache::get_all_grids_from_file(*path);
39 if (!grids_from_file.error_message.empty()) {
40 params.error_message_add(NodeWarningType::Error, grids_from_file.error_message);
41 params.set_default_remaining_outputs();
42 return;
43 }
44
45 Volume *volume = static_cast<Volume *>(BKE_id_new_nomain(ID_VO, "Volume"));
46 BKE_volume_metadata_set(*volume, grids_from_file.file_meta_data);
47 for (bke::GVolumeGrid &grid : grids_from_file.grids) {
48 grid->add_user();
49 BKE_volume_grid_add(volume, grid.get());
50 }
51
52 params.set_output("Volume", GeometrySet::from_volume(volume));
53#else
55#endif
56}
57
58static void node_register()
59{
60 static blender::bke::bNodeType ntype;
61
62 geo_node_type_base(&ntype, "GeometryNodeImportVDB");
63 ntype.ui_name = "Import VDB";
64 ntype.ui_description = "Import volume data from a .vdb file";
67 ntype.declare = node_declare;
68
70}
72
73} // namespace blender::nodes::node_geo_import_vdb
void * BKE_id_new_nomain(short type, const char *name)
Definition lib_id.cc:1519
#define NODE_CLASS_INPUT
Definition BKE_node.hh:447
Volume data-block.
void BKE_volume_grid_add(Volume *volume, const blender::bke::VolumeGridData &grid)
@ ID_VO
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FILEPATH
Definition RNA_types.hh:236
std::optional< std::string > path_filter
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams 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)
Defines a node type.
Definition BKE_node.hh:238
std::string ui_description
Definition BKE_node.hh:244
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:354
NodeDeclareFunction declare
Definition BKE_node.hh:362
static GeometrySet from_volume(Volume *volume, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)