Blender V5.3
node_geo_import_spz.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2026 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
8#include "BLI_listbase.hh"
10#include "BLI_string.hh"
11
12#include "BKE_report.hh"
13
14#include "IO_spz.hh"
15
17
19{
20 b.add_input<decl::String>("Path"_ustr)
21 .subtype(PROP_FILEPATH)
22 .path_filter("*.spz")
23 .optional_label()
24 .description("Path to a SPZ file");
25
26 b.add_output<decl::Geometry>("Points"_ustr);
27}
28
30 public:
33
34 void count_memory(MemoryCounter &counter) const override
35 {
36 this->geometry.count_memory(counter);
37 }
38};
39
41{
42#ifdef WITH_IO_SPZ
43 const std::optional<std::string> path = params.ensure_absolute_path(
44 params.extract_input<std::string>("Path"_ustr));
45 if (!path) {
47 return;
48 }
49
50 std::shared_ptr<const LoadSpzCache> cached_value = memory_cache::get_loaded<LoadSpzCache>(
51 GenericStringKey{"import_spz_node"}, {StringRefNull(*path)}, [&]() {
52 SPZImportParams import_params;
53 import_params.filepath = *path;
54
55 ReportList reports;
56 BKE_reports_init(&reports, RPT_STORE);
57 BLI_SCOPED_DEFER([&]() { BKE_reports_free(&reports); })
58 import_params.reports = &reports;
59
60 PointCloud *point_cloud = SPZ_import_point_cloud(&import_params);
61
62 auto cached_value = std::make_unique<LoadSpzCache>();
63 cached_value->geometry = GeometrySet::from_pointcloud(point_cloud);
64
65 for (Report &report : (import_params.reports)->list) {
66 cached_value->warnings.append_as(report);
67 }
68
69 return cached_value;
70 });
71
72 for (const NodeWarning &warning : cached_value->warnings) {
73 params.error_message_add(warning.type, warning.message);
74 }
75
76 params.set_output("Points"_ustr, cached_value->geometry);
77
78#else
80 TIP_("Disabled, Blender was compiled without SPZ I/O"));
82#endif
83}
84
85static void node_register()
86{
87 static bke::bNodeType ntype;
88
89 geo_node_type_base(&ntype, "GeometryNodeImportSPZ"_ustr);
90 ntype.ui_name = "Import SPZ";
91 ntype.ui_description =
92 "Import a point cloud object that is rendered as gaussian splat from an SPZ file";
95 ntype.declare = node_declare;
96
98}
100
101} // namespace blender::nodes::node_geo_import_spz
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define BLI_SCOPED_DEFER(function_to_defer)
#define TIP_(msgid)
#define NOD_REGISTER_NODE(REGISTER_FUNC)
constexpr StringRefNull()
void error_message_add(const NodeWarningType type, StringRef message) const
T extract_input(const UString identifier)
std::optional< std::string > ensure_absolute_path(StringRefNull path) const
void set_output(const UString identifier, T &&value)
std::optional< std::string > path_filter
void count_memory(MemoryCounter &counter) const override
void node_register_type(bNodeType &ntype)
Definition node.cc:2920
std::shared_ptr< const T > get_loaded(const GenericKey &loader_key, Span< StringRefNull > file_paths, FunctionRef< std::unique_ptr< T >()> load_fn)
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
@ PROP_FILEPATH
Definition RNA_types.hh:284
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
PointCloud * SPZ_import_point_cloud(const SPZImportParams *import_params)
Definition IO_spz.cc:20
std::string filepath
Definition IO_spz.hh:21
ReportList * reports
Definition IO_spz.hh:23
void count_memory(MemoryCounter &memory) const
Defines a node type.
Definition BKE_node.hh:265
std::string ui_description
Definition BKE_node.hh:271
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:385
NodeDeclareFunction declare
Definition BKE_node.hh:393
static GeometrySet from_pointcloud(PointCloud *pointcloud, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)