Blender V5.0
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.h"
10#include "BLI_string.h"
11
12#include "BKE_report.hh"
13
14#include "IO_ply.hh"
15
17
19{
20 b.add_input<decl::String>("Path")
21 .subtype(PROP_FILEPATH)
22 .path_filter("*.ply")
23 .optional_label()
24 .description("Path to a PLY file");
25
26 b.add_output<decl::Geometry>("Mesh");
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_PLY
43 const std::optional<std::string> path = params.ensure_absolute_path(
44 params.extract_input<std::string>("Path"));
45 if (!path) {
46 params.set_default_remaining_outputs();
47 return;
48 }
49
50 std::shared_ptr<const LoadPlyCache> cached_value = memory_cache::get_loaded<LoadPlyCache>(
51 GenericStringKey{"import_ply_node"}, {StringRefNull(*path)}, [&]() {
52 PLYImportParams import_params;
53 STRNCPY(import_params.filepath, path->c_str());
54 import_params.import_attributes = true;
55
56 ReportList reports;
57 BKE_reports_init(&reports, RPT_STORE);
58 BLI_SCOPED_DEFER([&]() { BKE_reports_free(&reports); });
59 import_params.reports = &reports;
60
61 Mesh *mesh = PLY_import_mesh(import_params);
62
63 auto cached_value = std::make_unique<LoadPlyCache>();
64 cached_value->geometry = GeometrySet::from_mesh(mesh);
65
66 LISTBASE_FOREACH (Report *, report, &(import_params.reports)->list) {
67 cached_value->warnings.append_as(*report);
68 }
69 return cached_value;
70 });
71
72 for (const geo_eval_log::NodeWarning &warning : cached_value->warnings) {
73 params.error_message_add(warning.type, warning.message);
74 }
75
76 params.set_output("Mesh", cached_value->geometry);
77
78#else
79 params.error_message_add(NodeWarningType::Error,
80 TIP_("Disabled, Blender was compiled without PLY I/O"));
81 params.set_default_remaining_outputs();
82#endif
83}
84
85static void node_register()
86{
87 static blender::bke::bNodeType ntype;
88
89 geo_node_type_base(&ntype, "GeometryNodeImportPLY", 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:447
#define GEO_NODE_IMPORT_PLY
@ RPT_STORE
Definition BKE_report.hh:56
void BKE_reports_free(ReportList *reports)
Definition report.cc:97
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:82
#define LISTBASE_FOREACH(type, var, list)
#define BLI_SCOPED_DEFER(function_to_defer)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
#define TIP_(msgid)
Mesh * PLY_import_mesh(const PLYImportParams &params)
Definition IO_ply.cc:44
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FILEPATH
Definition RNA_types.hh:236
std::optional< std::string > path_filter
void count_memory(MemoryCounter &counter) const override
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType &ntype)
Definition node.cc:2416
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 geo_node_type_base(blender::bke::bNodeType *ntype, std::string idname, const std::optional< int16_t > legacy_type)
ReportList * reports
Definition IO_ply.hh:68
char filepath[FILE_MAX]
Definition IO_ply.hh:59
bool import_attributes
Definition IO_ply.hh:65
void count_memory(MemoryCounter &memory) const
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
const char * enum_name_legacy
Definition BKE_node.hh:247
NodeDeclareFunction declare
Definition BKE_node.hh:362
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)