Blender V4.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
7#include "BLI_string.h"
8
9#include "BKE_instances.hh"
10#include "BKE_mesh.hh"
11#include "BKE_report.hh"
12
13#include "IO_ply.hh"
14
16
18{
19 b.add_input<decl::String>("Path")
20 .subtype(PROP_FILEPATH)
21 .hide_label()
22 .description("Path to a PLY file");
23
24 b.add_output<decl::Geometry>("Mesh");
25}
26
28{
29#ifdef WITH_IO_PLY
30 const std::string path = params.extract_input<std::string>("Path");
31 if (path.empty()) {
32 params.set_default_remaining_outputs();
33 return;
34 }
35
36 PLYImportParams import_params{};
37 STRNCPY(import_params.filepath, path.c_str());
38 import_params.import_attributes = true;
39
40 ReportList reports;
41 BKE_reports_init(&reports, RPT_STORE);
42 BLI_SCOPED_DEFER([&]() { BKE_reports_free(&reports); })
43 import_params.reports = &reports;
44
45 Mesh *mesh = PLY_import_mesh(&import_params);
46
47 LISTBASE_FOREACH (Report *, report, &(import_params.reports)->list) {
48 NodeWarningType type;
49 switch (report->type) {
50 case RPT_ERROR:
51 type = NodeWarningType::Error;
52 break;
53 default:
54 type = NodeWarningType::Info;
55 break;
56 }
57 params.error_message_add(type, TIP_(report->message));
58 }
59
60 params.set_output("Mesh", GeometrySet::from_mesh(mesh));
61
62#else
63 params.error_message_add(NodeWarningType::Error,
64 TIP_("Disabled, Blender was compiled without PLY I/O"));
65 params.set_default_remaining_outputs();
66#endif
67}
68
69static void node_register()
70{
71 static blender::bke::bNodeType ntype;
72
73 geo_node_type_base(&ntype, GEO_NODE_IMPORT_PLY, "Import PLY", NODE_CLASS_INPUT);
74
76 ntype.declare = node_declare;
78
80}
82
83} // namespace blender::nodes::nodes_geo_import_ply
#define NODE_CLASS_INPUT
Definition BKE_node.hh:404
void BKE_reports_free(ReportList *reports)
Definition report.cc:69
void BKE_reports_init(ReportList *reports, int flag)
Definition report.cc:54
#define LISTBASE_FOREACH(type, var, list)
#define BLI_SCOPED_DEFER(function_to_defer)
#define STRNCPY(dst, src)
Definition BLI_string.h:593
#define TIP_(msgid)
Mesh * PLY_import_mesh(const PLYImportParams *import_params)
Definition IO_ply.cc:42
#define NOD_REGISTER_NODE(REGISTER_FUNC)
@ PROP_FILEPATH
Definition RNA_types.hh:139
local_group_size(16, 16) .push_constant(Type b
uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH]
void node_register_type(bNodeType *ntype)
Definition node.cc:1708
static void node_declare(NodeDeclarationBuilder &b)
static void node_geo_exec(GeoNodeExecParams params)
void search_link_ops_for_import_node(GatherLinkSearchOpParams &params)
void geo_node_type_base(blender::bke::bNodeType *ntype, int type, const char *name, short nclass)
static GeometrySet from_mesh(Mesh *mesh, GeometryOwnershipType ownership=GeometryOwnershipType::Owned)
Defines a node type.
Definition BKE_node.hh:218
NodeGeometryExecFunction geometry_node_execute
Definition BKE_node.hh:339
NodeGatherSocketLinkOperationsFunction gather_link_search_ops
Definition BKE_node.hh:363
NodeDeclareFunction declare
Definition BKE_node.hh:347