Blender V5.3
node_geo_import_ply.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
8#include "BLI_listbase.hh"
10#include "BLI_string.hh"
11
12#include "BKE_report.hh"
13
14#include "IO_ply.hh"
15
17
19{
20 b.add_input<decl::String>("Path"_ustr)
21 .subtype(PROP_FILEPATH)
22 .path_filter("*.ply")
23 .optional_label()
24 .description("Path to a PLY file");
25
26 /* The socket used to be called mesh, so keep "Mesh" as identifier to support forward and
27 * backward compatibility. */
28 b.add_output<decl::Geometry>("Geometry"_ustr, "Mesh"_ustr);
29}
30
32 public:
35
36 void count_memory(MemoryCounter &counter) const override
37 {
38 this->geometry.count_memory(counter);
39 }
40};
41
43{
44#ifdef WITH_IO_PLY
45 const std::optional<std::string> path = params.ensure_absolute_path(
46 params.extract_input<std::string>("Path"_ustr));
47 if (!path) {
49 return;
50 }
51
52 std::shared_ptr<const LoadPlyCache> cached_value = memory_cache::get_loaded<LoadPlyCache>(
53 GenericStringKey{"import_ply_node"}, {StringRefNull(*path)}, [&]() {
54 PLYImportParams import_params;
55 STRNCPY(import_params.filepath, path->c_str());
56 import_params.import_attributes = true;
57
58 ReportList reports;
59 BKE_reports_init(&reports, RPT_STORE);
60 BLI_SCOPED_DEFER([&]() { BKE_reports_free(&reports); });
61 import_params.reports = &reports;
62
63 auto cached_value = std::make_unique<LoadPlyCache>();
64 cached_value->geometry = PLY_import_geometry_set(import_params);
65
66 for (Report &report : (import_params.reports)->list) {
67 cached_value->warnings.append_as(report);
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("Mesh"_ustr, cached_value->geometry);
77
78#else
80 TIP_("Disabled, Blender was compiled without PLY I/O"));
82#endif
83}
84
85static void node_register()
86{
87 static bke::bNodeType ntype;
88
89 geo_node_type_base(&ntype, "GeometryNodeImportPLY"_ustr, GEO_NODE_IMPORT_PLY);
90 ntype.ui_name = "Import PLY";
91 ntype.ui_description = "Import a point cloud from a PLY file";
92 ntype.enum_name_legacy = "IMPORT_PLY";
95 ntype.declare = node_declare;
96
98}
100
101} // namespace blender::nodes::nodes_geo_import_ply
#define NODE_CLASS_INPUT
Definition BKE_node.hh:478
#define GEO_NODE_IMPORT_PLY
#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)
char * STRNCPY(char(&dst)[N], const char *src)
void BKE_reports_free(ReportList *reports)
Definition report.cc:106
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:91
bke::GeometrySet PLY_import_geometry_set(const PLYImportParams &params)
Definition IO_ply.cc:56
@ PROP_FILEPATH
Definition RNA_types.hh:284
void geo_node_type_base(bke::bNodeType *ntype, UString idname, const std::optional< int16_t > legacy_type)
ReportList * reports
Definition IO_ply.hh:76
char filepath[FILE_MAX]
Definition IO_ply.hh:67
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
const char * enum_name_legacy
Definition BKE_node.hh:274
NodeDeclareFunction declare
Definition BKE_node.hh:393